Ejemplo n.º 1
0
        public virtual void Run()
        {
            GCSettings.LatencyMode = GCLatencyMode.SustainedLowLatency;

            DrawThread.Start();
            UpdateThread.Start();

            if (Window != null)
            {
                Window.KeyDown        += window_KeyDown;
                Window.Resize         += window_ClientSizeChanged;
                Window.ExitRequested  += OnExitRequested;
                Window.Exited         += OnExited;
                Window.FocusedChanged += delegate { setActive(Window.Focused); };
                window_ClientSizeChanged(null, null);

                try
                {
                    Window.UpdateFrame += delegate
                    {
                        inputPerformanceCollectionPeriod?.Dispose();
                        InputThread.RunUpdate();
                        inputPerformanceCollectionPeriod = InputMonitor.BeginCollecting(PerformanceCollectionType.WndProc);
                    };
                    Window.Run();
                }
                catch (OutOfMemoryException)
                {
                }
            }
            else
            {
                while (!ExitRequested)
                {
                    InputThread.RunUpdate();
                }
            }
        }
        public BackgroundStackTraceCollector(Thread targetThread, StopwatchClock clock)
        {
            if (Debugger.IsAttached)
            {
                return;
            }

            logger = Logger.GetLogger($"performance-{targetThread.Name?.ToLower() ?? "unknown"}");
            logger.OutputToListeners = false;

            this.clock        = clock;
            this.targetThread = targetThread;

            thread = new GameThread(() =>
            {
                if (Enabled && targetThread.IsAlive && clock.ElapsedMilliseconds - LastConsumptionTime > spikeRecordThreshold / 2 && backgroundMonitorStackTrace == null)
                {
                    backgroundMonitorStackTrace = getStackTrace(targetThread);
                }
            }, $"{targetThread}-StackTraceCollector", false);

            thread.Start();
        }
Ejemplo n.º 3
0
        public void Run(Game game)
        {
            if (executionState != ExecutionState.Idle)
            {
                throw new InvalidOperationException("A game that has already been run cannot be restarted.");
            }

            try
            {
                executionState = ExecutionState.Running;

                setupConfig();

                if (Window != null)
                {
                    Window.SetupWindow(config);
                    Window.Title = $@"osu!framework (running ""{Name}"")";
                }

                resetInputHandlers();

                DrawThread.Start();
                UpdateThread.Start();

                DrawThread.WaitUntilInitialized();
                bootstrapSceneGraph(game);

                frameSyncMode.TriggerChange();
                enabledInputHandlers.TriggerChange();

                try
                {
                    if (Window != null)
                    {
                        setActive(Window.Focused);

                        Window.KeyDown += window_KeyDown;

                        Window.ExitRequested  += OnExitRequested;
                        Window.Exited         += OnExited;
                        Window.FocusedChanged += delegate { setActive(Window.Focused); };

                        Window.UpdateFrame += delegate
                        {
                            inputPerformanceCollectionPeriod?.Dispose();
                            InputThread.RunUpdate();
                            inputPerformanceCollectionPeriod = inputMonitor.BeginCollecting(PerformanceCollectionType.WndProc);
                        };
                        Window.Closed += delegate
                        {
                            //we need to ensure all threads have stopped before the window is closed (mainly the draw thread
                            //to avoid GL operations running post-cleanup).
                            stopAllThreads();
                        };

                        Window.Run();
                    }
                    else
                    {
                        while (executionState != ExecutionState.Stopped)
                        {
                            InputThread.RunUpdate();
                        }
                    }
                }
                catch (OutOfMemoryException)
                {
                }
            }
            finally
            {
                // Close the window and stop all threads
                exit();
            }
        }
Ejemplo n.º 4
0
 private static void LaunchGameThread()
 {
     gameThread.Start();
 }
Ejemplo n.º 5
0
        public void Run(Game game)
        {
            setupConfig();

            if (Window != null)
            {
                Window.SetupWindow(config);
                Window.Title = $@"osu!framework (running ""{Name}"")";
            }

            resetInputHandlers();

            DrawThread.Start();
            UpdateThread.Start();

            DrawThread.WaitUntilInitialized();
            bootstrapSceneGraph(game);

            frameSyncMode.TriggerChange();
            enabledInputHandlers.TriggerChange();

            try
            {
                if (Window != null)
                {
                    Window.KeyDown += window_KeyDown;

                    Window.ExitRequested += OnExitRequested;
                    Window.Exited        += OnExited;

                    EventHandler <EventArgs> setActiveHandler = delegate { setActive(Window.Focused); };
                    Window.Load           += setActiveHandler;
                    Window.FocusedChanged += setActiveHandler;

                    Window.UpdateFrame += delegate
                    {
                        inputPerformanceCollectionPeriod?.Dispose();
                        InputThread.RunUpdate();
                        inputPerformanceCollectionPeriod = inputMonitor.BeginCollecting(PerformanceCollectionType.WndProc);
                    };
                    Window.Closed += delegate
                    {
                        //we need to ensure all threads have stopped before the window is closed (mainly the draw thread
                        //to avoid GL operations running post-cleanup).
                        stopAllThreads();
                    };

                    Window.Run();
                }
                else
                {
                    while (!exitCompleted)
                    {
                        InputThread.RunUpdate();
                    }
                }
            }
            catch (OutOfMemoryException)
            {
            }
        }