Ticket #3542: scumm-timers.patch

File scumm-timers.patch, 4.2 KB (added by fingolfin, 17 years ago)
  • engines/scumm/scumm.cpp

     
    17001700#pragma mark --- Main loop ---
    17011701#pragma mark -
    17021702
    1703 enum {
    1704         kTickDuration = 15      // Corresponds to a tick frequency of 1000/15 = 66.6 Hz
    1705 };
    1706 
    17071703int ScummEngine::go() {
    17081704        _engineStartTime = _system->getMillis() / 1000;
    17091705
     
    17151711                _saveLoadFlag = 0;
    17161712        }
    17171713
    1718         int delta = 0;
    1719         int diff = _system->getMillis();
     1714        int diff = 0;   // Duration of one loop iteration
    17201715
    17211716        while (!_quit) {
    17221717
     
    17271722                // that it will be in a different state each time you run the program.
    17281723                _rnd.getRandomNumber(2);
    17291724
    1730                 diff -= _system->getMillis();
    1731                 waitForTimer(delta * kTickDuration + diff);
    1732                 diff = _system->getMillis();
    1733                 delta = scummLoop(delta);
     1725                // Notify the script about how much time has passed, in ticks (60 ticks per second)
     1726                if (VAR_TIMER != 0xFF)
     1727                        VAR(VAR_TIMER) = diff * 60 / 1000;
     1728                if (VAR_TIMER_TOTAL != 0xFF)
     1729                        VAR(VAR_TIMER_TOTAL) += diff * 60 / 1000;
    17341730
     1731                // Determine how long to wait before the next loop iteration should start
     1732                int delta = (VAR_TIMER_NEXT != 0xFF) ? VAR(VAR_TIMER_NEXT) : 4;
    17351733                if (delta < 1)  // Ensure we don't get into an endless loop
    17361734                        delta = 1;  // by not decreasing sleepers.
    17371735
     1736                // Wait...
     1737                waitForTimer(delta * 1000 / 60 - diff);
     1738
     1739                // Start the stop watch!
     1740                diff = _system->getMillis();
     1741
     1742                // Run the main loop
     1743                scummLoop(delta);
     1744
     1745                // Halt the stop watch and compute how much time this iteration took.
     1746                diff = _system->getMillis() - diff;
     1747
     1748
    17381749                if (_quit) {
    17391750                        // TODO: Maybe perform an autosave on exit?
    17401751                }
     
    17631774        }
    17641775}
    17651776
    1766 int ScummEngine::scummLoop(int delta) {
     1777void ScummEngine::scummLoop(int delta) {
    17671778        if (_game.version >= 3) {
    17681779                VAR(VAR_TMR_1) += delta;
    17691780                VAR(VAR_TMR_2) += delta;
     
    17771788                        VAR(41) += delta;
    17781789                }
    17791790        }
    1780         if (VAR_TIMER_TOTAL != 0xFF)
    1781                 VAR(VAR_TIMER_TOTAL) += delta;
    17821791
    17831792        if (delta > 15)
    17841793                delta = 15;
     
    18161825                        // to get it correct for all games. Without the ability to watch/listen to the
    18171826                        // original games, I can't do that myself.
    18181827                        const int MUSIC_DELAY = 350;
    1819                         _tempMusic += delta * kTickDuration;    // Convert delta to milliseconds
     1828                        _tempMusic += delta * 1000 / 60;        // Convert delta to milliseconds
    18201829                        if (_tempMusic >= MUSIC_DELAY) {
    18211830                                _tempMusic -= MUSIC_DELAY;
    18221831                                VAR(VAR_MUSIC_TIMER) += 1;
     
    18791888        checkAndRunSentenceScript();
    18801889
    18811890        if (_quit)
    1882                 return 0;
     1891                return;
    18831892
    18841893        // HACK: If a load was requested, immediately perform it. This avoids
    18851894        // drawing the current room right after the load is request but before
     
    19351944
    19361945        /* show or hide mouse */
    19371946        CursorMan.showMouse(_cursor.state > 0);
    1938 
    1939         if (VAR_TIMER != 0xFF)
    1940                 VAR(VAR_TIMER) = 0;
    1941         return (VAR_TIMER_NEXT != 0xFF) ? VAR(VAR_TIMER_NEXT) : 4;
    1942 
    19431947}
    19441948
    19451949#ifndef DISABLE_HE
    1946 int ScummEngine_v90he::scummLoop(int delta) {
     1950void ScummEngine_v90he::scummLoop(int delta) {
    19471951        _moviePlay->handleNextFrame();
    19481952        if (_game.heversion >= 98) {
    19491953                _logicHE->startOfFrame();
    19501954        }
    19511955
    1952         int ret = ScummEngine::scummLoop(delta);
     1956        ScummEngine::scummLoop(delta);
    19531957
    19541958        _sprite->updateImages();
    19551959        if (_game.heversion >= 98) {
    19561960                _logicHE->endOfFrame();
    19571961        }
    1958 
    1959         return ret;
    19601962}
    19611963#endif
    19621964
  • engines/scumm/scumm.h

     
    467467        int getTalkspeed();
    468468
    469469        // Scumm main loop & helper functions.
    470         virtual int scummLoop(int delta);
     470        virtual void scummLoop(int delta);
    471471        virtual void scummLoop_updateScummVars();
    472472        virtual void scummLoop_handleSaveLoad();
    473473        virtual void scummLoop_handleDrawing();
  • engines/scumm/he/intern_he.h

     
    485485        virtual void setupScummVars();
    486486        virtual void resetScummVars();
    487487
    488         virtual int scummLoop(int delta);
     488        virtual void scummLoop(int delta);
    489489        virtual void scummLoop_handleDrawing();
    490490        virtual void runBootscript();
    491491