Ticket #3542: scumm-timers.patch
File scumm-timers.patch, 4.2 KB (added by , 15 years ago) |
---|
-
engines/scumm/scumm.cpp
1700 1700 #pragma mark --- Main loop --- 1701 1701 #pragma mark - 1702 1702 1703 enum {1704 kTickDuration = 15 // Corresponds to a tick frequency of 1000/15 = 66.6 Hz1705 };1706 1707 1703 int ScummEngine::go() { 1708 1704 _engineStartTime = _system->getMillis() / 1000; 1709 1705 … … 1715 1711 _saveLoadFlag = 0; 1716 1712 } 1717 1713 1718 int delta = 0; 1719 int diff = _system->getMillis(); 1714 int diff = 0; // Duration of one loop iteration 1720 1715 1721 1716 while (!_quit) { 1722 1717 … … 1727 1722 // that it will be in a different state each time you run the program. 1728 1723 _rnd.getRandomNumber(2); 1729 1724 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; 1734 1730 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; 1735 1733 if (delta < 1) // Ensure we don't get into an endless loop 1736 1734 delta = 1; // by not decreasing sleepers. 1737 1735 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 1738 1749 if (_quit) { 1739 1750 // TODO: Maybe perform an autosave on exit? 1740 1751 } … … 1763 1774 } 1764 1775 } 1765 1776 1766 intScummEngine::scummLoop(int delta) {1777 void ScummEngine::scummLoop(int delta) { 1767 1778 if (_game.version >= 3) { 1768 1779 VAR(VAR_TMR_1) += delta; 1769 1780 VAR(VAR_TMR_2) += delta; … … 1777 1788 VAR(41) += delta; 1778 1789 } 1779 1790 } 1780 if (VAR_TIMER_TOTAL != 0xFF)1781 VAR(VAR_TIMER_TOTAL) += delta;1782 1791 1783 1792 if (delta > 15) 1784 1793 delta = 15; … … 1816 1825 // to get it correct for all games. Without the ability to watch/listen to the 1817 1826 // original games, I can't do that myself. 1818 1827 const int MUSIC_DELAY = 350; 1819 _tempMusic += delta * kTickDuration; // Convert delta to milliseconds1828 _tempMusic += delta * 1000 / 60; // Convert delta to milliseconds 1820 1829 if (_tempMusic >= MUSIC_DELAY) { 1821 1830 _tempMusic -= MUSIC_DELAY; 1822 1831 VAR(VAR_MUSIC_TIMER) += 1; … … 1879 1888 checkAndRunSentenceScript(); 1880 1889 1881 1890 if (_quit) 1882 return 0;1891 return; 1883 1892 1884 1893 // HACK: If a load was requested, immediately perform it. This avoids 1885 1894 // drawing the current room right after the load is request but before … … 1935 1944 1936 1945 /* show or hide mouse */ 1937 1946 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 1943 1947 } 1944 1948 1945 1949 #ifndef DISABLE_HE 1946 intScummEngine_v90he::scummLoop(int delta) {1950 void ScummEngine_v90he::scummLoop(int delta) { 1947 1951 _moviePlay->handleNextFrame(); 1948 1952 if (_game.heversion >= 98) { 1949 1953 _logicHE->startOfFrame(); 1950 1954 } 1951 1955 1952 int ret =ScummEngine::scummLoop(delta);1956 ScummEngine::scummLoop(delta); 1953 1957 1954 1958 _sprite->updateImages(); 1955 1959 if (_game.heversion >= 98) { 1956 1960 _logicHE->endOfFrame(); 1957 1961 } 1958 1959 return ret;1960 1962 } 1961 1963 #endif 1962 1964 -
engines/scumm/scumm.h
467 467 int getTalkspeed(); 468 468 469 469 // Scumm main loop & helper functions. 470 virtual intscummLoop(int delta);470 virtual void scummLoop(int delta); 471 471 virtual void scummLoop_updateScummVars(); 472 472 virtual void scummLoop_handleSaveLoad(); 473 473 virtual void scummLoop_handleDrawing(); -
engines/scumm/he/intern_he.h
485 485 virtual void setupScummVars(); 486 486 virtual void resetScummVars(); 487 487 488 virtual intscummLoop(int delta);488 virtual void scummLoop(int delta); 489 489 virtual void scummLoop_handleDrawing(); 490 490 virtual void runBootscript(); 491 491