Esempio n. 1
0
        private byte MainLoop()
        {
            byte retCode = 0;

            System.InputManager.ResetKeys();

            while ((retCode == 0) && !ShouldQuit)
            {
                // do we need the section45-hack from sword.c here?
                CheckCd();

                _screen.NewScreen(Logic.ScriptVars[(int)ScriptVariableNames.NEW_SCREEN]);
                _logic.NewScreen(Logic.ScriptVars[(int)ScriptVariableNames.NEW_SCREEN]);
                _sound.NewScreen(Logic.ScriptVars[(int)ScriptVariableNames.NEW_SCREEN]);
                Logic.ScriptVars[(int)ScriptVariableNames.SCREEN] = Logic.ScriptVars[(int)ScriptVariableNames.NEW_SCREEN];

                do
                {
                    int  newTime;
                    bool scrollFrameShown = false;

                    int frameTime = Environment.TickCount;
                    _logic.Engine();
                    _logic.UpdateScreenParams(); // sets scrolling

                    _screen.Draw();
                    _mouse.Animate();
                    _sound.Engine();
                    _menu.Refresh(Menu.MENU_TOP);
                    _menu.Refresh(Menu.MENU_BOT);

                    newTime = Environment.TickCount;
                    if (newTime - frameTime < 1000 / FRAME_RATE)
                    {
                        scrollFrameShown = _screen.ShowScrollFrame();
                        Delay(1000 / (FRAME_RATE * 2) - (Environment.TickCount - frameTime));
                    }

                    newTime = Environment.TickCount;
                    if ((newTime - frameTime < 1000 / FRAME_RATE) || !scrollFrameShown)
                    {
                        _screen.UpdateScreen();
                    }
                    Delay(1000 / FRAME_RATE - (Environment.TickCount - frameTime));

                    _mouse.Engine((ushort)_mouseCoord.X, (ushort)_mouseCoord.Y, _mouseState);

                    if (SystemVars.ForceRestart)
                    {
                        retCode = Control.CONTROL_RESTART_GAME;
                    }

                    // The control panel is triggered by F5 or ESC.
                    else if (((_keyPressed.IsKeyDown(KeyCode.F5) || _keyPressed.IsKeyDown(KeyCode.Escape)) &&
                              (Logic.ScriptVars[(int)ScriptVariableNames.MOUSE_STATUS] & 1) != 0) ||
                             (SystemVars.ControlPanelMode != 0))
                    {
                        retCode = _control.RunPanel();
                        if (retCode == Control.CONTROL_NOTHING_DONE)
                        {
                            _screen.FullRefresh();
                        }
                    }

                    // TODO: Check for Debugger Activation
                    //if (_keyPressed.hasFlags(Common::KBD_CTRL) && _keyPressed.keycode == Common::KEYCODE_d)
                    //{
                    //    this.getDebugger().attach();
                    //    this.getDebugger().onFrame();
                    //}

                    _mouseState = 0;
                    _keyPressed = new ScummInputState();
                } while ((Logic.ScriptVars[(int)ScriptVariableNames.SCREEN] == Logic.ScriptVars[(int)ScriptVariableNames.NEW_SCREEN]) && (retCode == 0) && !ShouldQuit);

                if ((retCode == 0) && (Logic.ScriptVars[(int)ScriptVariableNames.SCREEN] != 53) && SystemVars.WantFade && !ShouldQuit)
                {
                    _screen.FadeDownPalette();
                    int relDelay = Environment.TickCount;
                    while (_screen.StillFading())
                    {
                        relDelay += 1000 / FRAME_RATE;
                        _screen.UpdateScreen();
                        Delay(relDelay - Environment.TickCount);
                    }
                }

                _sound.QuitScreen();
                _screen.QuitScreen();                                                       // close graphic resources
                _objectMan.CloseSection(Logic.ScriptVars[(int)ScriptVariableNames.SCREEN]); // close the section that PLAYER has just left, if it's empty now
            }
            return(retCode);
        }