Moved all time() calls in AGOS to a single new method AGOSEngine::getTime(); also replaced an evil function-static variable by a member variable (lastMinute)

svn-id: r29908
This commit is contained in:
Max Horn 2007-12-20 09:43:46 +00:00
parent 15a94b7c0c
commit f44a196087
10 changed files with 49 additions and 57 deletions

View file

@ -275,6 +275,7 @@ AGOSEngine::AGOSEngine(OSystem *syst)
_gameStoppedClock = 0; _gameStoppedClock = 0;
_gameTime = 0; _gameTime = 0;
_lastTime = 0; _lastTime = 0;
_lastMinute = 0;
_firstTimeStruct = 0; _firstTimeStruct = 0;
_pendingDeleteTimeEvent = 0; _pendingDeleteTimeEvent = 0;
@ -1051,4 +1052,9 @@ void AGOSEngine::shutdown() {
_system->quit(); _system->quit();
} }
uint32 AGOSEngine::getTime() const {
// FIXME: calling time() is not portable, use OSystem::getMillis instead
return (uint32)time(NULL);
}
} // End of namespace AGOS } // End of namespace AGOS

View file

@ -362,9 +362,12 @@ protected:
uint _numTextBoxes; uint _numTextBoxes;
uint _lastTime; uint32 getTime() const;
uint32 _lastMinute; // Used in processSpecialKeys()
uint32 _lastTime;
uint32 _clockStopped, _gameStoppedClock, _gameTime; uint32 _clockStopped, _gameStoppedClock, _gameTime;
time_t _timeStore; uint32 _timeStore;
TimeEvent *_firstTimeStruct, *_pendingDeleteTimeEvent; TimeEvent *_firstTimeStruct, *_pendingDeleteTimeEvent;

View file

@ -42,9 +42,7 @@ namespace AGOS {
void AGOSEngine::addTimeEvent(uint16 timeout, uint16 subroutine_id) { void AGOSEngine::addTimeEvent(uint16 timeout, uint16 subroutine_id) {
TimeEvent *te = (TimeEvent *)malloc(sizeof(TimeEvent)), *first, *last = NULL; TimeEvent *te = (TimeEvent *)malloc(sizeof(TimeEvent)), *first, *last = NULL;
time_t cur_time; uint32 cur_time = getTime();
time(&cur_time);
if (getGameId() == GID_DIMP) { if (getGameId() == GID_DIMP) {
timeout /= 2; timeout /= 2;
@ -52,7 +50,7 @@ void AGOSEngine::addTimeEvent(uint16 timeout, uint16 subroutine_id) {
te->time = cur_time + timeout - _gameStoppedClock; te->time = cur_time + timeout - _gameStoppedClock;
if (getGameType() == GType_FF && _clockStopped) if (getGameType() == GType_FF && _clockStopped)
te->time -= ((uint32)time(NULL) - _clockStopped); te->time -= (getTime() - _clockStopped);
te->subroutine_id = subroutine_id; te->subroutine_id = subroutine_id;
first = _firstTimeStruct; first = _firstTimeStruct;
@ -135,17 +133,16 @@ void AGOSEngine::killAllTimers() {
} }
bool AGOSEngine::kickoffTimeEvents() { bool AGOSEngine::kickoffTimeEvents() {
time_t cur_time; uint32 cur_time;
TimeEvent *te; TimeEvent *te;
bool result = false; bool result = false;
if (getGameType() == GType_FF && _clockStopped) if (getGameType() == GType_FF && _clockStopped)
return result; return result;
time(&cur_time); cur_time = getTime() - _gameStoppedClock;
cur_time -= _gameStoppedClock;
while ((te = _firstTimeStruct) != NULL && te->time <= (uint32)cur_time) { while ((te = _firstTimeStruct) != NULL && te->time <= cur_time) {
result = true; result = true;
_pendingDeleteTimeEvent = te; _pendingDeleteTimeEvent = te;
invokeTimeEvent(te); invokeTimeEvent(te);

View file

@ -362,8 +362,6 @@ out_of_here:
} }
void AGOSEngine::hitarea_stuff_helper() { void AGOSEngine::hitarea_stuff_helper() {
time_t cur_time;
if (getGameType() == GType_SIMON2 || getGameType() == GType_FF || if (getGameType() == GType_SIMON2 || getGameType() == GType_FF ||
getGameType() == GType_PP) { getGameType() == GType_PP) {
if (_variableArray[254] || _variableArray[249]) { if (_variableArray[254] || _variableArray[249]) {
@ -383,8 +381,8 @@ void AGOSEngine::hitarea_stuff_helper() {
} }
} }
time(&cur_time); uint32 cur_time = getTime();
if ((uint) cur_time != _lastTime) { if (cur_time != _lastTime) {
_lastTime = cur_time; _lastTime = cur_time;
if (kickoffTimeEvents()) if (kickoffTimeEvents())
permitInput(); permitInput();
@ -459,16 +457,12 @@ bool AGOSEngine::processSpecialKeys() {
bool verbCode = false; bool verbCode = false;
if (getGameId() == GID_DIMP) { if (getGameId() == GID_DIMP) {
static time_t lastMinute = 0; uint32 t1 = getTime() / 30;
time_t t; if (!_lastMinute)
time_t t1; _lastMinute = t1;
t = time(&t); if (t1 - _lastMinute) {
t1 = t / 30; _variableArray[120] += (t1 - _lastMinute);
if (!lastMinute) _lastMinute = t1;
lastMinute = t1;
if (t1 - lastMinute) {
_variableArray[120] += (t1 - lastMinute);
lastMinute = t1;
} }
} }

View file

@ -250,7 +250,7 @@ void AGOSEngine::userGame(bool load) {
numSaveGames = countSaveGames(); numSaveGames = countSaveGames();
time_t saveTime = time(NULL); uint32 saveTime = getTime();
haltAnimation(); haltAnimation();
restart: restart:
@ -331,7 +331,7 @@ restart:
} }
restartAnimation(); restartAnimation();
_gameStoppedClock = time(NULL) - saveTime + _gameStoppedClock; _gameStoppedClock = getTime() - saveTime + _gameStoppedClock;
} }
void AGOSEngine_Elvira2::listSaveGames(char *dst) { void AGOSEngine_Elvira2::listSaveGames(char *dst) {
@ -415,7 +415,7 @@ void AGOSEngine_Elvira2::listSaveGames(char *dst) {
} }
void AGOSEngine_Elvira2::userGame(bool load) { void AGOSEngine_Elvira2::userGame(bool load) {
time_t saveTime; uint32 saveTime;
int i, numSaveGames; int i, numSaveGames;
char *name; char *name;
bool b; bool b;
@ -423,7 +423,7 @@ void AGOSEngine_Elvira2::userGame(bool load) {
_saveOrLoad = load; _saveOrLoad = load;
saveTime = time(NULL); saveTime = getTime();
if (getGameType() == GType_ELVIRA2) if (getGameType() == GType_ELVIRA2)
haltAnimation(); haltAnimation();
@ -504,7 +504,7 @@ void AGOSEngine_Elvira2::userGame(bool load) {
get_out:; get_out:;
disableFileBoxes(); disableFileBoxes();
_gameStoppedClock = time(NULL) - saveTime + _gameStoppedClock; _gameStoppedClock = getTime() - saveTime + _gameStoppedClock;
if (getGameType() == GType_ELVIRA2) if (getGameType() == GType_ELVIRA2)
restartAnimation(); restartAnimation();
@ -624,7 +624,7 @@ const byte hebrewKeyTable[96] = {
}; };
void AGOSEngine_Simon1::userGame(bool load) { void AGOSEngine_Simon1::userGame(bool load) {
time_t saveTime; uint32 saveTime;
int i, numSaveGames, result; int i, numSaveGames, result;
WindowBlock *window; WindowBlock *window;
char *name; char *name;
@ -634,7 +634,7 @@ void AGOSEngine_Simon1::userGame(bool load) {
_saveOrLoad = load; _saveOrLoad = load;
saveTime = time(NULL); saveTime = getTime();
numSaveGames = countSaveGames(); numSaveGames = countSaveGames();
if (!load) if (!load)
@ -772,7 +772,7 @@ restart:;
get_out:; get_out:;
disableFileBoxes(); disableFileBoxes();
_gameStoppedClock = time(NULL) - saveTime + _gameStoppedClock; _gameStoppedClock = getTime() - saveTime + _gameStoppedClock;
} }
int AGOSEngine_Simon1::userGameGetKey(bool *b, char *buf, uint maxChar) { int AGOSEngine_Simon1::userGameGetKey(bool *b, char *buf, uint maxChar) {
@ -1316,7 +1316,7 @@ bool AGOSEngine_Elvira2::saveGame(uint slot, const char *caption) {
uint32 curTime = 0; uint32 curTime = 0;
if (getGameType() != GType_SIMON1 && getGameType() != GType_SIMON2) if (getGameType() != GType_SIMON1 && getGameType() != GType_SIMON2)
curTime = time(NULL); curTime = getTime();
_lockWord |= 0x100; _lockWord |= 0x100;
@ -1347,7 +1347,7 @@ bool AGOSEngine_Elvira2::saveGame(uint slot, const char *caption) {
f->writeUint32BE(i); f->writeUint32BE(i);
if (getGameType() == GType_FF && _clockStopped) if (getGameType() == GType_FF && _clockStopped)
gsc += ((uint32)time(NULL) - _clockStopped); gsc += (getTime() - _clockStopped);
for (te = _firstTimeStruct; te; te = te->next) { for (te = _firstTimeStruct; te; te = te->next) {
f->writeUint32BE(te->time - curTime + gsc); f->writeUint32BE(te->time - curTime + gsc);
f->writeUint16BE(te->subroutine_id); f->writeUint16BE(te->subroutine_id);

View file

@ -825,16 +825,13 @@ void AGOSEngine_Elvira1::oe1_enableInput() {
void AGOSEngine_Elvira1::oe1_setTime() { void AGOSEngine_Elvira1::oe1_setTime() {
// 259: set time // 259: set time
time(&_timeStore); _timeStore = getTime();
} }
void AGOSEngine_Elvira1::oe1_ifTime() { void AGOSEngine_Elvira1::oe1_ifTime() {
// 260: if time // 260: if time
time_t t;
uint a = getVarOrWord(); uint a = getVarOrWord();
time(&t); uint32 t = getTime() - a;
t -= a;
if (t >= _timeStore) if (t >= _timeStore)
setScriptCondition(true); setScriptCondition(true);
else else
@ -897,7 +894,7 @@ void AGOSEngine_Elvira1::oe1_pauseGame() {
WindowBlock *window = _windowArray[4]; WindowBlock *window = _windowArray[4];
const char *message1, *message2; const char *message1, *message2;
time_t pauseTime = time(NULL); uint32 pauseTime = getTime();
haltAnimation(); haltAnimation();
restart: restart:
@ -970,7 +967,7 @@ restart:
} }
restartAnimation(); restartAnimation();
_gameStoppedClock = time(NULL) - pauseTime + _gameStoppedClock; _gameStoppedClock = getTime() - pauseTime + _gameStoppedClock;
} }
void AGOSEngine_Elvira1::oe1_printPlayerHit() { void AGOSEngine_Elvira1::oe1_printPlayerHit() {

View file

@ -378,7 +378,7 @@ void AGOSEngine_Elvira2::oe2_pauseGame() {
// 135: pause game // 135: pause game
HitArea *ha; HitArea *ha;
time_t pauseTime = time(NULL); uint32 pauseTime = getTime();
haltAnimation(); haltAnimation();
for (;;) { for (;;) {
@ -400,7 +400,7 @@ void AGOSEngine_Elvira2::oe2_pauseGame() {
} }
restartAnimation(); restartAnimation();
_gameStoppedClock = time(NULL) - pauseTime + _gameStoppedClock; _gameStoppedClock = getTime() - pauseTime + _gameStoppedClock;
} }
void AGOSEngine_Elvira2::oe2_setDoorOpen() { void AGOSEngine_Elvira2::oe2_setDoorOpen() {

View file

@ -397,12 +397,8 @@ void AGOSEngine_Feeble::off_oracleTextUp() {
void AGOSEngine_Feeble::off_ifTime() { void AGOSEngine_Feeble::off_ifTime() {
// 124: if time // 124: if time
time_t t;
uint a = getVarOrWord(); uint a = getVarOrWord();
time(&t); uint32 t = getTime() - _gameStoppedClock - a;
t -= _gameStoppedClock;
t -= a;
if (t >= _timeStore) if (t >= _timeStore)
setScriptCondition(true); setScriptCondition(true);
else else
@ -411,8 +407,7 @@ void AGOSEngine_Feeble::off_ifTime() {
void AGOSEngine_Feeble::off_setTime() { void AGOSEngine_Feeble::off_setTime() {
// 131 // 131
time(&_timeStore); _timeStore = getTime() - _gameStoppedClock;
_timeStore -= _gameStoppedClock;
} }
void AGOSEngine_Feeble::off_saveUserGame() { void AGOSEngine_Feeble::off_saveUserGame() {
@ -612,13 +607,13 @@ void AGOSEngine_Feeble::off_setPathValues() {
void AGOSEngine_Feeble::off_stopClock() { void AGOSEngine_Feeble::off_stopClock() {
// 193: pause clock // 193: pause clock
_clockStopped = time(NULL); _clockStopped = getTime();
} }
void AGOSEngine_Feeble::off_restartClock() { void AGOSEngine_Feeble::off_restartClock() {
// 194: resume clock // 194: resume clock
if (_clockStopped != 0) if (_clockStopped != 0)
_gameStoppedClock += time(NULL) - _clockStopped; _gameStoppedClock += getTime() - _clockStopped;
_clockStopped = 0; _clockStopped = 0;
} }

View file

@ -299,7 +299,7 @@ void AGOSEngine_PuzzlePack::opp_iconifyWindow() {
// 30 // 30
getNextWord(); getNextWord();
if (_clockStopped != 0) if (_clockStopped != 0)
_gameTime += time(NULL) - _clockStopped; _gameTime += getTime() - _clockStopped;
_clockStopped = 0; _clockStopped = 0;
_system->setFeatureState(OSystem::kFeatureIconifyWindow, true); _system->setFeatureState(OSystem::kFeatureIconifyWindow, true);
} }
@ -379,7 +379,7 @@ void AGOSEngine_PuzzlePack::opp_sync() {
void AGOSEngine_PuzzlePack::opp_saveUserGame() { void AGOSEngine_PuzzlePack::opp_saveUserGame() {
// 132: save game // 132: save game
if (_clockStopped != 0) if (_clockStopped != 0)
_gameTime += time(NULL) - _clockStopped; _gameTime += getTime() - _clockStopped;
_clockStopped = 0; _clockStopped = 0;
if (getGameId() == GID_DIMP) { if (getGameId() == GID_DIMP) {
@ -452,7 +452,7 @@ void AGOSEngine_PuzzlePack::opp_setPathValues() {
void AGOSEngine_PuzzlePack::opp_restartClock() { void AGOSEngine_PuzzlePack::opp_restartClock() {
// 194: resume clock // 194: resume clock
if (_clockStopped != 0) if (_clockStopped != 0)
_gameTime += time(NULL) - _clockStopped; _gameTime += getTime() - _clockStopped;
_clockStopped = 0; _clockStopped = 0;
} }

View file

@ -365,7 +365,7 @@ void AGOSEngine_Waxworks::oww_pauseGame() {
// 135: pause game // 135: pause game
HitArea *ha; HitArea *ha;
time_t pauseTime = time(NULL); uint32 pauseTime = getTime();
haltAnimation(); haltAnimation();
for (;;) { for (;;) {
@ -389,7 +389,7 @@ void AGOSEngine_Waxworks::oww_pauseGame() {
} }
restartAnimation(); restartAnimation();
_gameStoppedClock = time(NULL) - pauseTime + _gameStoppedClock; _gameStoppedClock = getTime() - pauseTime + _gameStoppedClock;
} }
void AGOSEngine_Waxworks::oww_boxMessage() { void AGOSEngine_Waxworks::oww_boxMessage() {