Esempio n. 1
0
        /// <summary>
        /// Infinitely calls the Render task until the overlay closes.
        /// </summary>
        private async Task RunInfiniteLoop(CancellationToken cancellationToken)
        {
            var stopwatch = Stopwatch.StartNew();

            while (window.Exists && !cancellationToken.IsCancellationRequested)
            {
                InputSnapshot snapshot = window.PumpEvents();
                if (!window.Exists)
                {
                    break;
                }

                var deltaSeconds = (float)stopwatch.ElapsedTicks / Stopwatch.Frequency;
                stopwatch.Restart();
                imController.Update(deltaSeconds, snapshot, window.Handle);

                await Render();

                commandList.Begin();
                commandList.SetFramebuffer(graphicsDevice.MainSwapchain.Framebuffer);
                commandList.ClearColorTarget(0, new RgbaFloat(0.00f, 0.00f, 0.00f, 0.00f));
                imController.Render(graphicsDevice, commandList);
                commandList.End();
                graphicsDevice.SubmitCommands(commandList);
                graphicsDevice.SwapBuffers(graphicsDevice.MainSwapchain);
            }

            if (window.Exists)
            {
                window.Close();
            }
        }
        /// <summary>
        /// Infinitely renders the over (and execute co-routines) till it's closed.
        /// </summary>
        public static void RunInfiniteLoop()
        {
            DateTime previous = DateTime.Now;
            DateTime current;
            TimeSpan interval;
            float    sec;

            while (window.Exists && !Close)
            {
                InputSnapshot snapshot = window.PumpEvents();
                if (!window.Exists)
                {
                    break;
                }
                current  = DateTime.Now;
                interval = current - previous;
                sec      = (float)interval.TotalSeconds;
                previous = current;
                imController.Update(sec > 0 ? sec : 0.001f, snapshot, window.Handle);
                CoroutineHandler.Tick(interval.TotalSeconds);
                if (Visible)
                {
                    CoroutineHandler.RaiseEvent(OnRender);
                }

                commandList.Begin();
                commandList.SetFramebuffer(graphicsDevice.MainSwapchain.Framebuffer);
                commandList.ClearColorTarget(0, new RgbaFloat(clearColor.X, clearColor.Y, clearColor.Z, clearColor.W));
                imController.Render(graphicsDevice, commandList);
                commandList.End();
                graphicsDevice.SubmitCommands(commandList);
                graphicsDevice.SwapBuffers(graphicsDevice.MainSwapchain);
            }

            Dispose();
        }