Exemplo n.º 1
0
        public void MainLoop()
        {
            _Run = true;
            int delay = 0;

            this.Show();

            if (CConfig.FullScreen == EOffOn.TR_CONFIG_ON)
            {
                CSettings.bFullScreen = true;
                Maximize(this);
            }

            while (_Run)
            {
                Application.DoEvents();

                if (_Run)
                {
                    _Run = _Run && CGraphics.Draw();
                    _Run = CGraphics.UpdateGameLogic(_Keys, _Mouse);
                    FlipBuffer();

                    if ((CSettings.bFullScreen && !_fullscreen) || (!CSettings.bFullScreen && _fullscreen))
                    {
                        ToggleFullScreen();
                    }

                    if (CTime.IsRunning())
                    {
                        delay = (int)Math.Floor(CConfig.CalcCycleTime() - CTime.GetMilliseconds());
                    }

                    if (delay >= 1)
                    {
                        System.Threading.Thread.Sleep(delay);
                    }

                    CTime.CalculateFPS();
                    CTime.Restart();
                }
                else
                {
                    this.Close();
                }
            }
        }
Exemplo n.º 2
0
        public void MainLoop()
        {
            _Run = true;
            int delay = 0;

            Show();

            if (CConfig.Config.Graphics.FullScreen == EOffOn.TR_CONFIG_ON)
            {
                _Maximize(this);
            }

            while (_Run)
            {
                Application.DoEvents();

                if (_Run)
                {
                    ClearScreen();
                    _Run = _Run && CGraphics.Draw();
                    _Run = CGraphics.UpdateGameLogic(_Keys, _Mouse);
                    _FlipBuffer();

                    if ((CConfig.Config.Graphics.FullScreen == EOffOn.TR_CONFIG_ON) != _Fullscreen)
                    {
                        _ToggleFullScreen();
                    }

                    if (CTime.IsRunning())
                    {
                        delay = (int)Math.Floor(CConfig.CalcCycleTime() - CTime.GetMilliseconds());
                    }

                    if (delay >= 1)
                    {
                        Thread.Sleep(delay);
                    }

                    CTime.CalculateFPS();
                    CTime.Restart();
                }
            }
            Close();
        }
Exemplo n.º 3
0
        // Resharper doesn't get that this is used -.-
        // ReSharper disable UnusedMemberHiearchy.Global
        /// <summary>
        ///     Starts the rendering
        /// </summary>
        public virtual void MainLoop()
        {
            // ReSharper restore UnusedMemberHiearchy.Global
            _EnsureMainThread();
            _Run = true;

            _Fullscreen = false;
            if (CConfig.Config.Graphics.FullScreen == EOffOn.TR_CONFIG_ON)
            {
                _EnterFullScreen();
            }
            else
            {
                _DoResize(); //Resize window if aspect ratio is incorrect
            }
            while (_Run)
            {
                _CheckQueue();
                CVocaluxeServer.ProcessServerTasks();

                //We want to begin drawing
                _OnBeforeDraw();

                //Clear the previous Frame
                _ClearScreen();
                if (!CGraphics.Draw())
                {
                    _Run = false;
                }
                _OnAfterDraw();

                if (!CGraphics.UpdateGameLogic(_Keys, _Mouse))
                {
                    _Run = false;
                }

                //Apply fullscreen mode
                if ((CConfig.Config.Graphics.FullScreen == EOffOn.TR_CONFIG_ON) != _Fullscreen)
                {
                    _ToggleFullScreen();
                }

                //Apply border changes
                if (_BorderLeft != CConfig.Config.Graphics.BorderLeft || _BorderRight != CConfig.Config.Graphics.BorderRight || _BorderTop != CConfig.Config.Graphics.BorderTop ||
                    _BorderBottom != CConfig.Config.Graphics.BorderBottom)
                {
                    _BorderLeft   = CConfig.Config.Graphics.BorderLeft;
                    _BorderRight  = CConfig.Config.Graphics.BorderRight;
                    _BorderTop    = CConfig.Config.Graphics.BorderTop;
                    _BorderBottom = CConfig.Config.Graphics.BorderBottom;

                    _AdjustNewBorders();
                }

                if (_CurrentAlignment != CConfig.Config.Graphics.ScreenAlignment)
                {
                    _DoResize();
                }

                if (CConfig.Config.Graphics.VSync == EOffOn.TR_CONFIG_OFF)
                {
                    if (CTime.IsRunning())
                    {
                        int delay = (int)Math.Floor(CConfig.CalcCycleTime() - CTime.GetMilliseconds());

                        if (delay >= 1 && delay < 500)
                        {
                            Thread.Sleep(delay);
                        }
                    }
                }
                //Calculate the FPS Rate and restart the timer after a frame
                CTime.CalculateFPS();
                CTime.Restart();
            }
        }