Example #1
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();
            }
        }
Example #2
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)
            {
            }
        }