Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        sequencer.UpdateNotePositions();
        sequencer.UpdateRenderer();
        //sr.size.Set(sr.size.x + count, sr.size.y + count);
        int noteIndex = 0;

        foreach (var bar in BarPool.bars)
        {
            bar.SetActive(false);
        }

        var notesArray = sequencer.NoteManager.Notes.ToArray();

        foreach (var n in notesArray)
        {
            var   noteOffset = 0;
            var   noteCount  = 88;
            float keywidth   = 3f;
            float scale      = 0.001f;
            float yoffset    = 5f;
            float xspacing   = 30f;
            if (n.Key >= noteOffset && n.Key < noteOffset + noteCount && n.Length > 0 && n.Velocity > 0)
            {
                float left     = n.Key * keywidth + (xspacing * n.Key);
                float x        = left;
                float y        = 100f - n.Position;
                float width    = keywidth;
                float height   = n.Length * 1f;
                var   bar      = BarPool.bars[noteIndex];
                var   renderer = bar.GetComponentInChildren <SpriteRenderer>();
                renderer.transform.position = new Vector3(x * scale, (y - (height / 2)) * scale);
                renderer.size = new Vector3(width * 0.01f, height * scale);
                bar.SetActive(true);
            }
            noteIndex++;
        }


        //renderer.sprite.bounds.size.Set(count, count, 1);



        //      var sprite = GetComponentInChildren<Sprite>();
        //var obj = GetComponentInParent<GameObject>();

        //        var newSprite = Component.Instantiate(sprite);
        //SpriteRenderer rend = obj.AddComponent<Sprite>();
        //rend.sprite = sprites[0];
    }
Beispiel #2
0
        public void Init()
        {
            #region init_gfx
            Form = new RenderForm("Kazedan");
            var   factory = new FactoryD2D();
            SizeF dpi     = factory.DesktopDpi;

            var swapChainDesc = new SwapChainDescription()
            {
                BufferCount       = 2,
                Usage             = Usage.RenderTargetOutput,
                OutputHandle      = Form.Handle,
                IsWindowed        = true,
                ModeDescription   = new ModeDescription((int)(GFXResources.Bounds.Width * (dpi.Width / 96f)), (int)(GFXResources.Bounds.Height * (dpi.Height / 96f)), new Rational(60, 1), Format.R8G8B8A8_UNorm),
                SampleDescription = new SampleDescription(1, 0),
                Flags             = SwapChainFlags.AllowModeSwitch,
                SwapEffect        = SwapEffect.Discard,
            };

            Device    device;
            SwapChain swapChain;
            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, swapChainDesc, out device, out swapChain);

            Surface backBuffer = Surface.FromSwapChain(swapChain, 0);

            renderTarget = RenderTarget.FromDXGI(factory, backBuffer, new RenderTargetProperties()
            {
                HorizontalDpi       = dpi.Width,
                VerticalDpi         = dpi.Height,
                MinimumFeatureLevel = SlimDX.Direct2D.FeatureLevel.Default,
                PixelFormat         = new PixelFormat(Format.R8G8B8A8_UNorm, AlphaMode.Ignore),
                Type  = RenderTargetType.Default,
                Usage = RenderTargetUsage.None
            });
            factory.Dispose();

            // Freaking antialiasing lagging up my programs
            renderTarget.AntialiasMode     = AntialiasMode.Aliased;
            renderTarget.TextAntialiasMode = TextAntialiasMode.Grayscale;

            using (var DXGIFactory = swapChain.GetParent <FactoryDXGI>())
                DXGIFactory.SetWindowAssociation(Form.Handle, WindowAssociationFlags.IgnoreAltEnter);

            Form.ClientSize   = GFXResources.Bounds;
            Form.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            Form.Icon         = Properties.Resources.KazedanIcon;
            #endregion

            GFXResources.Init(renderTarget);

            Form.KeyDown += (o, e) =>
            {
                Keys key = e.KeyCode;
                switch (key)
                {
                case Keys.F11:
                    swapChain.IsFullScreen = !swapChain.IsFullScreen;
                    break;

                case Keys.F:
                    Sequencer.NoteManager.UserEnabledFancy = !Sequencer.NoteManager.UserEnabledFancy;
                    Sequencer.NoteManager.RenderFancy      = Sequencer.NoteManager.UserEnabledFancy;
                    break;

                case Keys.Up:
                    Sequencer.Delay += 100;
                    Sequencer.Reset();
                    break;

                case Keys.Down:
                    if (Sequencer.Delay >= 100)
                    {
                        Sequencer.Delay -= 100;
                        Sequencer.Reset();
                    }
                    break;

                case Keys.Left:
                    if (GFXResources.NoteOffset > 0)
                    {
                        GFXResources.NoteOffset--;
                    }
                    break;

                case Keys.Right:
                    if (GFXResources.NoteOffset < 128 - GFXResources.NoteCount)
                    {
                        GFXResources.NoteOffset++;
                    }
                    break;

                case Keys.D:
                    Sequencer.ShowDebug = !Sequencer.ShowDebug;
                    break;

                case Keys.Space:
                    if (Sequencer.Stopped)
                    {
                        Sequencer.Start();
                    }
                    else
                    {
                        Sequencer.Stop();
                    }
                    break;
                }
            };

            // Start loading thread
            Thread loadThread = new Thread(Load);
            loadThread.Start();

            // Show controller window
            Thread controlThread = new Thread(() =>
            {
                loadThread.Join();
                Application.EnableVisualStyles();
                ControlForm = new KZControl(Sequencer);
                Application.Run(ControlForm);
            });
            controlThread.SetApartmentState(ApartmentState.STA);
            controlThread.Start();

            // Make sure the control form closes when the main form does
            Form.Disposed += (o, e) =>
            {
                ControlForm?.BeginInvoke((MethodInvoker) delegate
                {
                    ControlForm.Close();
                });
            };

            MessagePump.Run(Form, () =>
            {
                // Do sequencer tick
                if (!Sequencer.Stopped)
                {
                    Sequencer.UpdateNotePositions();
                    Sequencer.UpdateRenderer();
                }
                Paint(renderTarget);

                // Calculate profiling information
                long tick = Environment.TickCount;
                if (tick - LastSample >= SampleRate)
                {
                    Elapsed    = tick - LastTick;
                    LastSample = tick;
                }
                LastTick = tick;
                swapChain.Present(1, PresentFlags.None);
            });

            renderTarget.Dispose();
            swapChain.Dispose();
            device.Dispose();
            Sequencer.Dispose();
        }