[STAThread] // Needed for ASIOOutput.StartDriver method static void Main(string[] args) { // Create window, GraphicsDevice, and all resources necessary for the demo. VeldridStartup.CreateWindowAndGraphicsDevice( new WindowCreateInfo(50, 50, 3600, 2000, WindowState.Normal, "Vector Engine Editor"), new GraphicsDeviceOptions(true, null, true), out _window, out _gd); _gd.MainSwapchain.SyncToVerticalBlank = false; _window.Resized += () => { _gd.MainSwapchain.Resize((uint)_window.Width, (uint)_window.Height); _controller.WindowResized(_window.Width, _window.Height); }; _cl = _gd.ResourceFactory.CreateCommandList(); _controller = new ImGuiController(_gd, _gd.MainSwapchain.Framebuffer.OutputDescription, _window.Width, _window.Height); string assetsPath = HostHelper.AssetsPath; FileLoader.Init(assetsPath); FileLoader.LoadAllComponentGroups(); if (_showEditor) { HostHelper.StopGame(true); } else { HostHelper.PlayGame(true); } // Main application loop while (_window.Exists) { GameLoop.Tick(); InputSnapshot snapshot = _window.PumpEvents(); if (!_window.Exists) { break; } foreach (var keypress in snapshot.KeyEvents) { if (keypress.Key == Key.E && keypress.Down && keypress.Modifiers == ModifierKeys.Control) { _showEditor = !_showEditor; } if (keypress.Key == Key.S && keypress.Down && keypress.Modifiers == ModifierKeys.Control) { HostHelper.SaveScene(); } if (keypress.Key == Key.D && keypress.Down && keypress.Modifiers == ModifierKeys.Control) { HostHelper.Duplicate(); } } if (_showEditor) { if (EditorCamera == null) { foreach (var component in EntityAdmin.Instance.Components) { if (component.Entity.Name == EmptyScene.EDITOR_CAM_ENTITY_NAME) { EditorCamera = component.Entity; break; } } } if (midi == null) { midi = new MIDI(); midi.SetupWatchersAndPorts(); while (!midi.SetupComplete) { Thread.Sleep(1); } } IMidiMessage midiMessage; while (midi.MidiMessageQueue.TryDequeue(out midiMessage)) { MidiState.UpdateState(midiMessage); } // TODO: figure out why LastFrameTime makes ImGui run stupid fast... (for things like key repeats) _controller.Update(GameTime.LastFrameTime / 10f, snapshot); // Feed the input events to our ImGui controller, which passes them through to ImGui. EditorUI.SubmitUI(EntityAdmin.Instance); _cl.Begin(); _cl.SetFramebuffer(_gd.MainSwapchain.Framebuffer); _cl.ClearColorTarget(0, new RgbaFloat(ClearColor.X, ClearColor.Y, ClearColor.Z, 1f)); _controller.Render(_gd, _cl); _cl.End(); _gd.SubmitCommands(_cl); _gd.SwapBuffers(_gd.MainSwapchain); } } if (!HostHelper.PlayingGame) { HostHelper.SaveScene(); } // Clean up Veldrid resources _gd.WaitForIdle(); _controller.Dispose(); _cl.Dispose(); _gd.Dispose(); }