LAB: Get rid of getTime(), readBlock() and getRandom()
Also, simplify some time-related functions
This commit is contained in:
parent
a01f068969
commit
1b0a7db0b6
8 changed files with 48 additions and 74 deletions
|
@ -141,18 +141,20 @@ void Anim::diffNextFrame(bool onlyDiffData) {
|
||||||
|
|
||||||
switch (_header) {
|
switch (_header) {
|
||||||
case 8:
|
case 8:
|
||||||
_vm->_utils->readBlock(_diffPalette, _size, &_diffFile);
|
memcpy(_diffPalette, _diffFile, _size);
|
||||||
|
_diffFile += _size;
|
||||||
_isPal = true;
|
_isPal = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 10:
|
case 10:
|
||||||
_rawDiffBM._planes[_curBit] = _diffFile;
|
_rawDiffBM._planes[_curBit] = _diffFile;
|
||||||
|
|
||||||
if (onlyDiffData)
|
if (onlyDiffData) {
|
||||||
_diffFile += _size;
|
_diffFile += _size;
|
||||||
else
|
} else {
|
||||||
_vm->_utils->readBlock(DrawBitMap->_planes[_curBit], _size, &_diffFile);
|
memcpy(DrawBitMap->_planes[_curBit], _diffFile, _size);
|
||||||
|
_diffFile += _size;
|
||||||
|
}
|
||||||
_curBit++;
|
_curBit++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -609,7 +609,9 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo
|
||||||
_followCrumbsFast = (code == 'r' || code == 'R');
|
_followCrumbsFast = (code == 'r' || code == 'R');
|
||||||
_isCrumbTurning = false;
|
_isCrumbTurning = false;
|
||||||
_isCrumbWaiting = false;
|
_isCrumbWaiting = false;
|
||||||
_utils->getTime(&_crumbSecs, &_crumbMicros);
|
uint32 t = g_system->getMillis();
|
||||||
|
_crumbSecs = t / 1000;
|
||||||
|
_crumbMicros = t % 1000;
|
||||||
|
|
||||||
if (_alternate) {
|
if (_alternate) {
|
||||||
eatMessages();
|
eatMessages();
|
||||||
|
@ -930,7 +932,9 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo
|
||||||
_followCrumbsFast = false;
|
_followCrumbsFast = false;
|
||||||
_isCrumbTurning = false;
|
_isCrumbTurning = false;
|
||||||
_isCrumbWaiting = false;
|
_isCrumbWaiting = false;
|
||||||
_utils->getTime(&_crumbSecs, &_crumbMicros);
|
uint32 t = g_system->getMillis();
|
||||||
|
_crumbSecs = t / 1000;
|
||||||
|
_crumbMicros = t % 1000;
|
||||||
|
|
||||||
eatMessages();
|
eatMessages();
|
||||||
_alternate = false;
|
_alternate = false;
|
||||||
|
|
|
@ -132,7 +132,9 @@ void Intro::doPictText(const char *filename, TextFont *msgFont, bool isScreen) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_vm->_utils->getTime(&lastSecs, &lastMicros);
|
uint32 t = g_system->getMillis();
|
||||||
|
lastSecs = t / 1000;
|
||||||
|
lastMicros = t % 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = _vm->getMsg();
|
msg = _vm->getMsg();
|
||||||
|
@ -140,7 +142,10 @@ void Intro::doPictText(const char *filename, TextFont *msgFont, bool isScreen) {
|
||||||
if (msg == NULL) {
|
if (msg == NULL) {
|
||||||
_vm->_music->updateMusic();
|
_vm->_music->updateMusic();
|
||||||
_vm->_anim->diffNextFrame();
|
_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);
|
_vm->_utils->anyTimeDiff(lastSecs, lastMicros, secs, micros, &secs, µs);
|
||||||
|
|
||||||
if (secs > timeDelay) {
|
if (secs > timeDelay) {
|
||||||
|
|
|
@ -51,7 +51,7 @@ namespace Lab {
|
||||||
LabEngine *g_lab;
|
LabEngine *g_lab;
|
||||||
|
|
||||||
LabEngine::LabEngine(OSystem *syst, const ADGameDescription *gameDesc)
|
LabEngine::LabEngine(OSystem *syst, const ADGameDescription *gameDesc)
|
||||||
: Engine(syst), _gameDescription(gameDesc), _extraGameFeatures(0) {
|
: Engine(syst), _gameDescription(gameDesc), _extraGameFeatures(0), _rnd("lab") {
|
||||||
g_lab = this;
|
g_lab = this;
|
||||||
|
|
||||||
_lastWaitTOFTicks = 0;
|
_lastWaitTOFTicks = 0;
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#define LAB_H
|
#define LAB_H
|
||||||
|
|
||||||
#include "common/system.h"
|
#include "common/system.h"
|
||||||
|
#include "common/random.h"
|
||||||
#include "common/rect.h"
|
#include "common/rect.h"
|
||||||
|
|
||||||
#include "engines/engine.h"
|
#include "engines/engine.h"
|
||||||
|
@ -114,6 +115,8 @@ private:
|
||||||
InventoryData *_inventory;
|
InventoryData *_inventory;
|
||||||
MapData *_maps;
|
MapData *_maps;
|
||||||
|
|
||||||
|
Common::RandomSource _rnd;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool _alternate;
|
bool _alternate;
|
||||||
bool _droppingCrumbs;
|
bool _droppingCrumbs;
|
||||||
|
|
|
@ -370,7 +370,7 @@ void LabEngine::doActions(Action *actionList, CloseDataPtr *closePtrList) {
|
||||||
case SHOWMESSAGES: {
|
case SHOWMESSAGES: {
|
||||||
char **str = (char **)actionList->_data;
|
char **str = (char **)actionList->_data;
|
||||||
_graphics->_doNotDrawMessage = false;
|
_graphics->_doNotDrawMessage = false;
|
||||||
_graphics->drawMessage(str[_utils->getRandom(actionList->_param1)]);
|
_graphics->drawMessage(str[_rnd.getRandomNumber(actionList->_param1)]);
|
||||||
_graphics->_doNotDrawMessage = true;
|
_graphics->_doNotDrawMessage = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -424,18 +424,13 @@ void LabEngine::doActions(Action *actionList, CloseDataPtr *closePtrList) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WAITSECS: {
|
case WAITSECS: {
|
||||||
uint32 startSecs, startMicros, curSecs, curMicros;
|
uint32 targetMillis = g_system->getMillis() + actionList->_param1 * 1000;
|
||||||
_utils->addCurTime(actionList->_param1, 0, &startSecs, &startMicros);
|
|
||||||
|
|
||||||
_graphics->screenUpdate();
|
_graphics->screenUpdate();
|
||||||
|
|
||||||
while (1) {
|
while (g_system->getMillis() < targetMillis) {
|
||||||
_music->updateMusic();
|
_music->updateMusic();
|
||||||
_anim->diffNextFrame();
|
_anim->diffNextFrame();
|
||||||
_utils->getTime(&curSecs, &curMicros);
|
|
||||||
|
|
||||||
if ((curSecs > startSecs) || ((curSecs == startSecs) && (curMicros >= startMicros)))
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -427,56 +427,13 @@ void Utils::setBytesPerRow(int num) {
|
||||||
_dataBytesPerRow = num;
|
_dataBytesPerRow = 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.
|
* Adds seconds and microseconds to current time to get a new time.
|
||||||
*/
|
*/
|
||||||
void Utils::addCurTime(uint32 sec, uint32 micros, uint32 *timeSec, uint32 *timeMicros) {
|
void Utils::addCurTime(uint32 sec, uint32 micros, uint32 *timeSec, uint32 *timeMicros) {
|
||||||
getTime(timeSec, timeMicros);
|
uint32 t = g_system->getMillis();
|
||||||
|
*timeSec = (t / 1000) + sec;
|
||||||
(*timeSec) += sec;
|
*timeMicros = (t % 1000) + micros;
|
||||||
(*timeMicros) += micros;
|
|
||||||
|
|
||||||
if (*timeMicros >= ONESECOND) {
|
if (*timeMicros >= ONESECOND) {
|
||||||
(*timeSec)++;
|
(*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.
|
* 0 if the future time is actually before the current time.
|
||||||
*/
|
*/
|
||||||
void Utils::timeDiff(uint32 sec, uint32 micros, uint32 *diffSec, uint32 *diffMicros) {
|
void Utils::timeDiff(uint32 sec, uint32 micros, uint32 *diffSec, uint32 *diffMicros) {
|
||||||
uint32 curSec, curMicros;
|
uint32 t = g_system->getMillis();
|
||||||
getTime(&curSec, &curMicros);
|
uint32 curSec = t / 1000;
|
||||||
|
uint32 curMicros = t % 1000;
|
||||||
|
|
||||||
anyTimeDiff(curSec, curMicros, sec, micros, diffSec, diffMicros);
|
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.
|
* Waits for a specified time to occur.
|
||||||
*/
|
*/
|
||||||
void Utils::waitForTime(uint32 sec, uint32 micros) {
|
void Utils::waitForTime(uint32 sec, uint32 micros) {
|
||||||
uint32 curSec, curMicros;
|
uint32 targetMillis = sec * 1000 + micros;
|
||||||
getTime(&curSec, &curMicros);
|
uint32 t = g_system->getMillis();
|
||||||
|
uint32 curSec = t / 1000;
|
||||||
|
uint32 curMicros = t % 1000;
|
||||||
|
|
||||||
if (curSec > sec)
|
if (t >= targetMillis)
|
||||||
return;
|
|
||||||
else if ((curSec == sec) && (curMicros >= micros))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (curMicros > micros)
|
if (curMicros > micros)
|
||||||
|
|
|
@ -60,10 +60,7 @@ public:
|
||||||
void runLengthDecode(byte *dest, byte *source);
|
void runLengthDecode(byte *dest, byte *source);
|
||||||
void VRunLengthDecode(byte *dest, byte *source, uint16 bytesPerRow);
|
void VRunLengthDecode(byte *dest, byte *source, uint16 bytesPerRow);
|
||||||
void setBytesPerRow(int num);
|
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 addCurTime(uint32 sec, uint32 micros, uint32 *timeSec, uint32 *timeMicros);
|
||||||
void getTime(uint32 *secs, uint32 *micros);
|
|
||||||
void waitForTime(uint32 sec, uint32 micros);
|
void waitForTime(uint32 sec, uint32 micros);
|
||||||
void anyTimeDiff(uint32 sec1, uint32 micros1, uint32 sec2, uint32 micros2, uint32 *diffSecs, uint32 *diffMicros);
|
void anyTimeDiff(uint32 sec1, uint32 micros1, uint32 sec2, uint32 micros2, uint32 *diffSecs, uint32 *diffMicros);
|
||||||
void timeDiff(uint32 sec, uint32 micros, uint32 *diffSec, uint32 *diffMicros);
|
void timeDiff(uint32 sec, uint32 micros, uint32 *diffSec, uint32 *diffMicros);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue