Ejemplo n.º 1
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)
                {
                    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 (!exitCompleted)
                    {
                        InputThread.RunUpdate();
                    }
                }
            }
            catch (OutOfMemoryException)
            {
            }
        }