Пример #1
0
        private static void GameLoop()
        {
            float tsClient = 1.0f / ScriptingInterface.GetCvarValue <int>("cl_fps");
            float tsServer = 1.0f / ScriptingInterface.GetCvarValue <int>("sv_fps");
            float tsDebug  = 1.0f;

            clientTimer = new DeltaTimer(Timer, tsClient);
            serverTimer = new DeltaTimer(Timer, tsServer);
            debugTimer  = new DeltaTimer(Timer, tsDebug);

            while (!ShutdownRequested)
            {
                if (HasServer)
                {
                    ServerFrame();
                }

                if (HasClient)
                {
                    ClientFrame();
                }

                DebugFrame();
            }
        }
Пример #2
0
 private void UpdateTimer()
 {
     if (_deltaTimer == null)
     {
         _deltaTimer = new DeltaTimer();
         _deltaTimer.Start();
     }
     else
     {
         _deltaTimer.Update();
     }
 }
 public static void SlowMethodUnique()
 {
     Thread.Sleep(500);
     Output.Log(Math.Round(DeltaTimer.GetDeltaTime("FastMethodUnique"), 5));
     DeltaTimer.RestartDeltaTimer("SlowMethodUnique");
 }
 public static void PredictableMethodUnique()
 {
     Output.Log(Math.Round(DeltaTimer.GetDeltaTime("FastMethodUnique"), 5));
     DeltaTimer.RestartDeltaTimer("PredictableMethodUnique");
 }
Пример #5
0
        static string?Launcher()
        {
            var createInfo = new WindowCreateInfo
            {
                X                  = 100,
                Y                  = 100,
                WindowWidth        = 400,
                WindowHeight       = 150,
                WindowInitialState = WindowState.Normal,
                WindowTitle        = "OpenSAGE Apt Editor"
            };

            VeldridStartup.CreateWindowAndGraphicsDevice(createInfo, out var window, out var outGraphicsDevice);
            using var graphicsDevice           = outGraphicsDevice;
            graphicsDevice.SyncToVerticalBlank = true;
            using var commandList   = graphicsDevice.ResourceFactory.CreateCommandList();
            using var imGuiRenderer = new ImGuiRenderer(graphicsDevice,
                                                        graphicsDevice.MainSwapchain.Framebuffer.OutputDescription,
                                                        window.Width,
                                                        window.Height);
            using var gameTimer = new DeltaTimer();
            string?rootPath      = null;
            var    rootPathInput = new ImGuiTextBox(1024);

            void OnWindowResized()
            {
                graphicsDevice.ResizeMainWindow((uint)window.Width, (uint)window.Height);
                imGuiRenderer.WindowResized(window.Width, window.Height);
            }

            window.Resized += OnWindowResized;
            try
            {
                gameTimer.Start();
                while (rootPath == null)
                {
                    if (!window.Exists)
                    {
                        return(null);
                    }

                    gameTimer.Update();
                    var inputSnapshot = window.PumpEvents();
                    imGuiRenderer.Update((float)gameTimer.CurrentGameTime.DeltaTime.TotalSeconds, inputSnapshot);

                    commandList.Begin();
                    commandList.SetFramebuffer(graphicsDevice.MainSwapchain.Framebuffer);
                    commandList.ClearColorTarget(0, RgbaFloat.Clear);

                    ImGui.SetNextWindowPos(Vector2.Zero);
                    ImGui.SetNextWindowSize(new Vector2(window.Width, window.Height));
                    var open = true;
                    if (ImGui.Begin("Launcher", ref open, ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoResize))
                    {
                        ImGui.TextWrapped("Start OpenSage Apt Editor by providing a root path.");
                        ImGui.TextWrapped("It's recommended that you set it to " +
                                          "the RA3SDK_UI_ScreensPack folder so you could load apt files more easily.");
                        rootPathInput.InputText("##rootPath", out var inputRootPath);
                        if (ImGui.Button("Load"))
                        {
                            rootPath = inputRootPath;
                            window.Close();
                        }
                    }
                    ImGui.End();

                    imGuiRenderer.Render(graphicsDevice, commandList);
                    commandList.End();
                    graphicsDevice.SubmitCommands(commandList);
                    graphicsDevice.SwapBuffers();
                }
                return(rootPath);
            }
            finally
            {
                window.Resized -= OnWindowResized;
            }
        }
Пример #6
0
        static void Main(string[] args)
        {
            Platform.Start();

            const int initialWidth  = 1024;
            const int initialHeight = 768;

            VeldridStartup.CreateWindowAndGraphicsDevice(
                new WindowCreateInfo(100, 100, initialWidth, initialHeight, WindowState.Normal, "OpenSAGE Big Editor"),
                out var window,
                out var graphicsDevice);

            graphicsDevice.SyncToVerticalBlank = true;

            using (var commandList = graphicsDevice.ResourceFactory.CreateCommandList())
                using (var imGuiRenderer = new ImGuiRenderer(graphicsDevice, graphicsDevice.MainSwapchain.Framebuffer.OutputDescription, initialWidth, initialHeight))
                    using (var gameTimer = new DeltaTimer())
                    {
                        window.Resized += () =>
                        {
                            graphicsDevice.ResizeMainWindow((uint)window.Width, (uint)window.Height);
                            imGuiRenderer.WindowResized(window.Width, window.Height);
                        };

                        var windowOpen = true;
                        window.Closed += () => windowOpen = false;

                        gameTimer.Start();

                        using (var mainForm = new MainForm())
                        {
                            while (windowOpen)
                            {
                                commandList.Begin();

                                gameTimer.Update();

                                var inputSnapshot = window.PumpEvents();

                                commandList.SetFramebuffer(graphicsDevice.MainSwapchain.Framebuffer);

                                commandList.ClearColorTarget(0, RgbaFloat.Clear);

                                imGuiRenderer.Update(
                                    (float)gameTimer.CurrentGameTime.DeltaTime.TotalSeconds,
                                    inputSnapshot);

                                mainForm.Draw(window);

                                imGuiRenderer.Render(graphicsDevice, commandList);

                                commandList.End();

                                graphicsDevice.SubmitCommands(commandList);

                                graphicsDevice.SwapBuffers();
                            }
                        }
                    }

            graphicsDevice.Dispose();

            Platform.Stop();
        }