diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/lab/anim.cpp | 12 | ||||
-rw-r--r-- | engines/lab/engine.cpp | 8 | ||||
-rw-r--r-- | engines/lab/intro.cpp | 9 | ||||
-rw-r--r-- | engines/lab/lab.cpp | 2 | ||||
-rw-r--r-- | engines/lab/lab.h | 3 | ||||
-rw-r--r-- | engines/lab/processroom.cpp | 11 | ||||
-rw-r--r-- | engines/lab/utils.cpp | 74 | ||||
-rw-r--r-- | engines/lab/utils.h | 3 |
8 files changed, 48 insertions, 74 deletions
diff --git a/engines/lab/anim.cpp b/engines/lab/anim.cpp index 3bed3656d3..ac51860ed7 100644 --- a/engines/lab/anim.cpp +++ b/engines/lab/anim.cpp @@ -141,18 +141,20 @@ void Anim::diffNextFrame(bool onlyDiffData) { switch (_header) { case 8: - _vm->_utils->readBlock(_diffPalette, _size, &_diffFile); + memcpy(_diffPalette, _diffFile, _size); + _diffFile += _size; _isPal = true; break; case 10: _rawDiffBM._planes[_curBit] = _diffFile; - if (onlyDiffData) + if (onlyDiffData) { _diffFile += _size; - else - _vm->_utils->readBlock(DrawBitMap->_planes[_curBit], _size, &_diffFile); - + } else { + memcpy(DrawBitMap->_planes[_curBit], _diffFile, _size); + _diffFile += _size; + } _curBit++; break; diff --git a/engines/lab/engine.cpp b/engines/lab/engine.cpp index f0d3ab7a5b..1b77d04459 100644 --- a/engines/lab/engine.cpp +++ b/engines/lab/engine.cpp @@ -609,7 +609,9 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo _followCrumbsFast = (code == 'r' || code == 'R'); _isCrumbTurning = false; _isCrumbWaiting = false; - _utils->getTime(&_crumbSecs, &_crumbMicros); + uint32 t = g_system->getMillis(); + _crumbSecs = t / 1000; + _crumbMicros = t % 1000; if (_alternate) { eatMessages(); @@ -930,7 +932,9 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo _followCrumbsFast = false; _isCrumbTurning = false; _isCrumbWaiting = false; - _utils->getTime(&_crumbSecs, &_crumbMicros); + uint32 t = g_system->getMillis(); + _crumbSecs = t / 1000; + _crumbMicros = t % 1000; eatMessages(); _alternate = false; diff --git a/engines/lab/intro.cpp b/engines/lab/intro.cpp index 633691c820..0165116b00 100644 --- a/engines/lab/intro.cpp +++ b/engines/lab/intro.cpp @@ -132,7 +132,9 @@ void Intro::doPictText(const char *filename, TextFont *msgFont, bool isScreen) { return; } - _vm->_utils->getTime(&lastSecs, &lastMicros); + uint32 t = g_system->getMillis(); + lastSecs = t / 1000; + lastMicros = t % 1000; } msg = _vm->getMsg(); @@ -140,7 +142,10 @@ void Intro::doPictText(const char *filename, TextFont *msgFont, bool isScreen) { if (msg == NULL) { _vm->_music->updateMusic(); _vm->_anim->diffNextFrame(); - _vm->_utils->getTime(&secs, µs); + + uint32 t = g_system->getMillis(); + secs = t / 1000; + micros = t % 1000; _vm->_utils->anyTimeDiff(lastSecs, lastMicros, secs, micros, &secs, µs); if (secs > timeDelay) { diff --git a/engines/lab/lab.cpp b/engines/lab/lab.cpp index be5b9556e1..e33c443ee2 100644 --- a/engines/lab/lab.cpp +++ b/engines/lab/lab.cpp @@ -51,7 +51,7 @@ namespace Lab { LabEngine *g_lab; LabEngine::LabEngine(OSystem *syst, const ADGameDescription *gameDesc) - : Engine(syst), _gameDescription(gameDesc), _extraGameFeatures(0) { + : Engine(syst), _gameDescription(gameDesc), _extraGameFeatures(0), _rnd("lab") { g_lab = this; _lastWaitTOFTicks = 0; diff --git a/engines/lab/lab.h b/engines/lab/lab.h index 970ca3512b..b03b4b3605 100644 --- a/engines/lab/lab.h +++ b/engines/lab/lab.h @@ -32,6 +32,7 @@ #define LAB_H #include "common/system.h" +#include "common/random.h" #include "common/rect.h" #include "engines/engine.h" @@ -114,6 +115,8 @@ private: InventoryData *_inventory; MapData *_maps; + Common::RandomSource _rnd; + public: bool _alternate; bool _droppingCrumbs; diff --git a/engines/lab/processroom.cpp b/engines/lab/processroom.cpp index b997942879..bd9d02ef8c 100644 --- a/engines/lab/processroom.cpp +++ b/engines/lab/processroom.cpp @@ -370,7 +370,7 @@ void LabEngine::doActions(Action *actionList, CloseDataPtr *closePtrList) { case SHOWMESSAGES: { char **str = (char **)actionList->_data; _graphics->_doNotDrawMessage = false; - _graphics->drawMessage(str[_utils->getRandom(actionList->_param1)]); + _graphics->drawMessage(str[_rnd.getRandomNumber(actionList->_param1)]); _graphics->_doNotDrawMessage = true; } break; @@ -424,18 +424,13 @@ void LabEngine::doActions(Action *actionList, CloseDataPtr *closePtrList) { break; case WAITSECS: { - uint32 startSecs, startMicros, curSecs, curMicros; - _utils->addCurTime(actionList->_param1, 0, &startSecs, &startMicros); + uint32 targetMillis = g_system->getMillis() + actionList->_param1 * 1000; _graphics->screenUpdate(); - while (1) { + while (g_system->getMillis() < targetMillis) { _music->updateMusic(); _anim->diffNextFrame(); - _utils->getTime(&curSecs, &curMicros); - - if ((curSecs > startSecs) || ((curSecs == startSecs) && (curMicros >= startMicros))) - break; } } break; diff --git a/engines/lab/utils.cpp b/engines/lab/utils.cpp index 1ac083790e..3adcc954c9 100644 --- a/engines/lab/utils.cpp +++ b/engines/lab/utils.cpp @@ -428,55 +428,12 @@ void Utils::setBytesPerRow(int num) { } /** - * Generates a random number. - */ -uint16 Utils::getRandom(uint16 max) { - uint32 secs, micros; - - getTime(&secs, µs); - return ((micros + secs) % max); -} - -void Utils::readBlock(void *Buffer, uint32 Size, byte **File) { - memcpy(Buffer, *File, (size_t)Size); - (*File) += Size; -} - -/** - * Waits for for Secs seconds and Micros microseconds to pass. - */ -void Utils::microDelay(uint32 secs, uint32 micros) { - uint32 waitSecs, waitMicros; - addCurTime(secs, micros, &waitSecs, &waitMicros); - - while (1) { - getTime(&secs, µs); - - if ((secs > waitSecs) || ((secs == waitSecs) && (micros >= waitMicros))) - return; - - g_system->delayMillis(10); - } -} - -/** - * Gets the current system time. - */ -void Utils::getTime(uint32 *secs, uint32 *micros) { - uint32 t = g_system->getMillis(); - - *secs = t / 1000; - *micros = t % 1000; -} - -/** * Adds seconds and microseconds to current time to get a new time. */ void Utils::addCurTime(uint32 sec, uint32 micros, uint32 *timeSec, uint32 *timeMicros) { - getTime(timeSec, timeMicros); - - (*timeSec) += sec; - (*timeMicros) += micros; + uint32 t = g_system->getMillis(); + *timeSec = (t / 1000) + sec; + *timeMicros = (t % 1000) + micros; if (*timeMicros >= ONESECOND) { (*timeSec)++; @@ -511,21 +468,32 @@ void Utils::anyTimeDiff(uint32 sec1, uint32 micros1, uint32 sec2, uint32 micros2 * 0 if the future time is actually before the current time. */ void Utils::timeDiff(uint32 sec, uint32 micros, uint32 *diffSec, uint32 *diffMicros) { - uint32 curSec, curMicros; - getTime(&curSec, &curMicros); + uint32 t = g_system->getMillis(); + uint32 curSec = t / 1000; + uint32 curMicros = t % 1000; + anyTimeDiff(curSec, curMicros, sec, micros, diffSec, diffMicros); } /** +* Waits for Secs seconds and Micros microseconds to pass. +*/ +void Utils::microDelay(uint32 secs, uint32 micros) { + uint32 targetMillis = g_system->getMillis() + secs * 1000 + micros; + while (g_system->getMillis() < targetMillis) + g_system->delayMillis(10); +} + +/** * Waits for a specified time to occur. */ void Utils::waitForTime(uint32 sec, uint32 micros) { - uint32 curSec, curMicros; - getTime(&curSec, &curMicros); + uint32 targetMillis = sec * 1000 + micros; + uint32 t = g_system->getMillis(); + uint32 curSec = t / 1000; + uint32 curMicros = t % 1000; - if (curSec > sec) - return; - else if ((curSec == sec) && (curMicros >= micros)) + if (t >= targetMillis) return; if (curMicros > micros) diff --git a/engines/lab/utils.h b/engines/lab/utils.h index 9d6e1872d4..65c00a3eec 100644 --- a/engines/lab/utils.h +++ b/engines/lab/utils.h @@ -60,10 +60,7 @@ public: void runLengthDecode(byte *dest, byte *source); void VRunLengthDecode(byte *dest, byte *source, uint16 bytesPerRow); void setBytesPerRow(int num); - uint16 getRandom(uint16 max); - void readBlock(void *Buffer, uint32 Size, byte **File); void addCurTime(uint32 sec, uint32 micros, uint32 *timeSec, uint32 *timeMicros); - void getTime(uint32 *secs, uint32 *micros); void waitForTime(uint32 sec, uint32 micros); void anyTimeDiff(uint32 sec1, uint32 micros1, uint32 sec2, uint32 micros2, uint32 *diffSecs, uint32 *diffMicros); void timeDiff(uint32 sec, uint32 micros, uint32 *diffSec, uint32 *diffMicros); |