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:
parent
15a94b7c0c
commit
f44a196087
10 changed files with 49 additions and 57 deletions
|
@ -275,6 +275,7 @@ AGOSEngine::AGOSEngine(OSystem *syst)
|
|||
_gameStoppedClock = 0;
|
||||
_gameTime = 0;
|
||||
_lastTime = 0;
|
||||
_lastMinute = 0;
|
||||
|
||||
_firstTimeStruct = 0;
|
||||
_pendingDeleteTimeEvent = 0;
|
||||
|
@ -1051,4 +1052,9 @@ void AGOSEngine::shutdown() {
|
|||
_system->quit();
|
||||
}
|
||||
|
||||
uint32 AGOSEngine::getTime() const {
|
||||
// FIXME: calling time() is not portable, use OSystem::getMillis instead
|
||||
return (uint32)time(NULL);
|
||||
}
|
||||
|
||||
} // End of namespace AGOS
|
||||
|
|
|
@ -362,9 +362,12 @@ protected:
|
|||
|
||||
uint _numTextBoxes;
|
||||
|
||||
uint _lastTime;
|
||||
uint32 getTime() const;
|
||||
|
||||
uint32 _lastMinute; // Used in processSpecialKeys()
|
||||
uint32 _lastTime;
|
||||
uint32 _clockStopped, _gameStoppedClock, _gameTime;
|
||||
time_t _timeStore;
|
||||
uint32 _timeStore;
|
||||
|
||||
TimeEvent *_firstTimeStruct, *_pendingDeleteTimeEvent;
|
||||
|
||||
|
|
|
@ -42,9 +42,7 @@ namespace AGOS {
|
|||
|
||||
void AGOSEngine::addTimeEvent(uint16 timeout, uint16 subroutine_id) {
|
||||
TimeEvent *te = (TimeEvent *)malloc(sizeof(TimeEvent)), *first, *last = NULL;
|
||||
time_t cur_time;
|
||||
|
||||
time(&cur_time);
|
||||
uint32 cur_time = getTime();
|
||||
|
||||
if (getGameId() == GID_DIMP) {
|
||||
timeout /= 2;
|
||||
|
@ -52,7 +50,7 @@ void AGOSEngine::addTimeEvent(uint16 timeout, uint16 subroutine_id) {
|
|||
|
||||
te->time = cur_time + timeout - _gameStoppedClock;
|
||||
if (getGameType() == GType_FF && _clockStopped)
|
||||
te->time -= ((uint32)time(NULL) - _clockStopped);
|
||||
te->time -= (getTime() - _clockStopped);
|
||||
te->subroutine_id = subroutine_id;
|
||||
|
||||
first = _firstTimeStruct;
|
||||
|
@ -135,17 +133,16 @@ void AGOSEngine::killAllTimers() {
|
|||
}
|
||||
|
||||
bool AGOSEngine::kickoffTimeEvents() {
|
||||
time_t cur_time;
|
||||
uint32 cur_time;
|
||||
TimeEvent *te;
|
||||
bool result = false;
|
||||
|
||||
if (getGameType() == GType_FF && _clockStopped)
|
||||
return result;
|
||||
|
||||
time(&cur_time);
|
||||
cur_time -= _gameStoppedClock;
|
||||
cur_time = getTime() - _gameStoppedClock;
|
||||
|
||||
while ((te = _firstTimeStruct) != NULL && te->time <= (uint32)cur_time) {
|
||||
while ((te = _firstTimeStruct) != NULL && te->time <= cur_time) {
|
||||
result = true;
|
||||
_pendingDeleteTimeEvent = te;
|
||||
invokeTimeEvent(te);
|
||||
|
|
|
@ -362,8 +362,6 @@ out_of_here:
|
|||
}
|
||||
|
||||
void AGOSEngine::hitarea_stuff_helper() {
|
||||
time_t cur_time;
|
||||
|
||||
if (getGameType() == GType_SIMON2 || getGameType() == GType_FF ||
|
||||
getGameType() == GType_PP) {
|
||||
if (_variableArray[254] || _variableArray[249]) {
|
||||
|
@ -383,8 +381,8 @@ void AGOSEngine::hitarea_stuff_helper() {
|
|||
}
|
||||
}
|
||||
|
||||
time(&cur_time);
|
||||
if ((uint) cur_time != _lastTime) {
|
||||
uint32 cur_time = getTime();
|
||||
if (cur_time != _lastTime) {
|
||||
_lastTime = cur_time;
|
||||
if (kickoffTimeEvents())
|
||||
permitInput();
|
||||
|
@ -459,16 +457,12 @@ bool AGOSEngine::processSpecialKeys() {
|
|||
bool verbCode = false;
|
||||
|
||||
if (getGameId() == GID_DIMP) {
|
||||
static time_t lastMinute = 0;
|
||||
time_t t;
|
||||
time_t t1;
|
||||
t = time(&t);
|
||||
t1 = t / 30;
|
||||
if (!lastMinute)
|
||||
lastMinute = t1;
|
||||
if (t1 - lastMinute) {
|
||||
_variableArray[120] += (t1 - lastMinute);
|
||||
lastMinute = t1;
|
||||
uint32 t1 = getTime() / 30;
|
||||
if (!_lastMinute)
|
||||
_lastMinute = t1;
|
||||
if (t1 - _lastMinute) {
|
||||
_variableArray[120] += (t1 - _lastMinute);
|
||||
_lastMinute = t1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -250,7 +250,7 @@ void AGOSEngine::userGame(bool load) {
|
|||
|
||||
numSaveGames = countSaveGames();
|
||||
|
||||
time_t saveTime = time(NULL);
|
||||
uint32 saveTime = getTime();
|
||||
haltAnimation();
|
||||
|
||||
restart:
|
||||
|
@ -331,7 +331,7 @@ restart:
|
|||
}
|
||||
|
||||
restartAnimation();
|
||||
_gameStoppedClock = time(NULL) - saveTime + _gameStoppedClock;
|
||||
_gameStoppedClock = getTime() - saveTime + _gameStoppedClock;
|
||||
}
|
||||
|
||||
void AGOSEngine_Elvira2::listSaveGames(char *dst) {
|
||||
|
@ -415,7 +415,7 @@ void AGOSEngine_Elvira2::listSaveGames(char *dst) {
|
|||
}
|
||||
|
||||
void AGOSEngine_Elvira2::userGame(bool load) {
|
||||
time_t saveTime;
|
||||
uint32 saveTime;
|
||||
int i, numSaveGames;
|
||||
char *name;
|
||||
bool b;
|
||||
|
@ -423,7 +423,7 @@ void AGOSEngine_Elvira2::userGame(bool load) {
|
|||
|
||||
_saveOrLoad = load;
|
||||
|
||||
saveTime = time(NULL);
|
||||
saveTime = getTime();
|
||||
|
||||
if (getGameType() == GType_ELVIRA2)
|
||||
haltAnimation();
|
||||
|
@ -504,7 +504,7 @@ void AGOSEngine_Elvira2::userGame(bool load) {
|
|||
get_out:;
|
||||
disableFileBoxes();
|
||||
|
||||
_gameStoppedClock = time(NULL) - saveTime + _gameStoppedClock;
|
||||
_gameStoppedClock = getTime() - saveTime + _gameStoppedClock;
|
||||
|
||||
if (getGameType() == GType_ELVIRA2)
|
||||
restartAnimation();
|
||||
|
@ -624,7 +624,7 @@ const byte hebrewKeyTable[96] = {
|
|||
};
|
||||
|
||||
void AGOSEngine_Simon1::userGame(bool load) {
|
||||
time_t saveTime;
|
||||
uint32 saveTime;
|
||||
int i, numSaveGames, result;
|
||||
WindowBlock *window;
|
||||
char *name;
|
||||
|
@ -634,7 +634,7 @@ void AGOSEngine_Simon1::userGame(bool load) {
|
|||
|
||||
_saveOrLoad = load;
|
||||
|
||||
saveTime = time(NULL);
|
||||
saveTime = getTime();
|
||||
|
||||
numSaveGames = countSaveGames();
|
||||
if (!load)
|
||||
|
@ -772,7 +772,7 @@ restart:;
|
|||
get_out:;
|
||||
disableFileBoxes();
|
||||
|
||||
_gameStoppedClock = time(NULL) - saveTime + _gameStoppedClock;
|
||||
_gameStoppedClock = getTime() - saveTime + _gameStoppedClock;
|
||||
}
|
||||
|
||||
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;
|
||||
if (getGameType() != GType_SIMON1 && getGameType() != GType_SIMON2)
|
||||
curTime = time(NULL);
|
||||
curTime = getTime();
|
||||
|
||||
_lockWord |= 0x100;
|
||||
|
||||
|
@ -1347,7 +1347,7 @@ bool AGOSEngine_Elvira2::saveGame(uint slot, const char *caption) {
|
|||
f->writeUint32BE(i);
|
||||
|
||||
if (getGameType() == GType_FF && _clockStopped)
|
||||
gsc += ((uint32)time(NULL) - _clockStopped);
|
||||
gsc += (getTime() - _clockStopped);
|
||||
for (te = _firstTimeStruct; te; te = te->next) {
|
||||
f->writeUint32BE(te->time - curTime + gsc);
|
||||
f->writeUint16BE(te->subroutine_id);
|
||||
|
|
|
@ -825,16 +825,13 @@ void AGOSEngine_Elvira1::oe1_enableInput() {
|
|||
|
||||
void AGOSEngine_Elvira1::oe1_setTime() {
|
||||
// 259: set time
|
||||
time(&_timeStore);
|
||||
_timeStore = getTime();
|
||||
}
|
||||
|
||||
void AGOSEngine_Elvira1::oe1_ifTime() {
|
||||
// 260: if time
|
||||
time_t t;
|
||||
|
||||
uint a = getVarOrWord();
|
||||
time(&t);
|
||||
t -= a;
|
||||
uint32 t = getTime() - a;
|
||||
if (t >= _timeStore)
|
||||
setScriptCondition(true);
|
||||
else
|
||||
|
@ -897,7 +894,7 @@ void AGOSEngine_Elvira1::oe1_pauseGame() {
|
|||
WindowBlock *window = _windowArray[4];
|
||||
const char *message1, *message2;
|
||||
|
||||
time_t pauseTime = time(NULL);
|
||||
uint32 pauseTime = getTime();
|
||||
haltAnimation();
|
||||
|
||||
restart:
|
||||
|
@ -970,7 +967,7 @@ restart:
|
|||
}
|
||||
|
||||
restartAnimation();
|
||||
_gameStoppedClock = time(NULL) - pauseTime + _gameStoppedClock;
|
||||
_gameStoppedClock = getTime() - pauseTime + _gameStoppedClock;
|
||||
}
|
||||
|
||||
void AGOSEngine_Elvira1::oe1_printPlayerHit() {
|
||||
|
|
|
@ -378,7 +378,7 @@ void AGOSEngine_Elvira2::oe2_pauseGame() {
|
|||
// 135: pause game
|
||||
HitArea *ha;
|
||||
|
||||
time_t pauseTime = time(NULL);
|
||||
uint32 pauseTime = getTime();
|
||||
haltAnimation();
|
||||
|
||||
for (;;) {
|
||||
|
@ -400,7 +400,7 @@ void AGOSEngine_Elvira2::oe2_pauseGame() {
|
|||
}
|
||||
|
||||
restartAnimation();
|
||||
_gameStoppedClock = time(NULL) - pauseTime + _gameStoppedClock;
|
||||
_gameStoppedClock = getTime() - pauseTime + _gameStoppedClock;
|
||||
}
|
||||
|
||||
void AGOSEngine_Elvira2::oe2_setDoorOpen() {
|
||||
|
|
|
@ -397,12 +397,8 @@ void AGOSEngine_Feeble::off_oracleTextUp() {
|
|||
|
||||
void AGOSEngine_Feeble::off_ifTime() {
|
||||
// 124: if time
|
||||
time_t t;
|
||||
|
||||
uint a = getVarOrWord();
|
||||
time(&t);
|
||||
t -= _gameStoppedClock;
|
||||
t -= a;
|
||||
uint32 t = getTime() - _gameStoppedClock - a;
|
||||
if (t >= _timeStore)
|
||||
setScriptCondition(true);
|
||||
else
|
||||
|
@ -411,8 +407,7 @@ void AGOSEngine_Feeble::off_ifTime() {
|
|||
|
||||
void AGOSEngine_Feeble::off_setTime() {
|
||||
// 131
|
||||
time(&_timeStore);
|
||||
_timeStore -= _gameStoppedClock;
|
||||
_timeStore = getTime() - _gameStoppedClock;
|
||||
}
|
||||
|
||||
void AGOSEngine_Feeble::off_saveUserGame() {
|
||||
|
@ -612,13 +607,13 @@ void AGOSEngine_Feeble::off_setPathValues() {
|
|||
|
||||
void AGOSEngine_Feeble::off_stopClock() {
|
||||
// 193: pause clock
|
||||
_clockStopped = time(NULL);
|
||||
_clockStopped = getTime();
|
||||
}
|
||||
|
||||
void AGOSEngine_Feeble::off_restartClock() {
|
||||
// 194: resume clock
|
||||
if (_clockStopped != 0)
|
||||
_gameStoppedClock += time(NULL) - _clockStopped;
|
||||
_gameStoppedClock += getTime() - _clockStopped;
|
||||
_clockStopped = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -299,7 +299,7 @@ void AGOSEngine_PuzzlePack::opp_iconifyWindow() {
|
|||
// 30
|
||||
getNextWord();
|
||||
if (_clockStopped != 0)
|
||||
_gameTime += time(NULL) - _clockStopped;
|
||||
_gameTime += getTime() - _clockStopped;
|
||||
_clockStopped = 0;
|
||||
_system->setFeatureState(OSystem::kFeatureIconifyWindow, true);
|
||||
}
|
||||
|
@ -379,7 +379,7 @@ void AGOSEngine_PuzzlePack::opp_sync() {
|
|||
void AGOSEngine_PuzzlePack::opp_saveUserGame() {
|
||||
// 132: save game
|
||||
if (_clockStopped != 0)
|
||||
_gameTime += time(NULL) - _clockStopped;
|
||||
_gameTime += getTime() - _clockStopped;
|
||||
_clockStopped = 0;
|
||||
|
||||
if (getGameId() == GID_DIMP) {
|
||||
|
@ -452,7 +452,7 @@ void AGOSEngine_PuzzlePack::opp_setPathValues() {
|
|||
void AGOSEngine_PuzzlePack::opp_restartClock() {
|
||||
// 194: resume clock
|
||||
if (_clockStopped != 0)
|
||||
_gameTime += time(NULL) - _clockStopped;
|
||||
_gameTime += getTime() - _clockStopped;
|
||||
_clockStopped = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -365,7 +365,7 @@ void AGOSEngine_Waxworks::oww_pauseGame() {
|
|||
// 135: pause game
|
||||
HitArea *ha;
|
||||
|
||||
time_t pauseTime = time(NULL);
|
||||
uint32 pauseTime = getTime();
|
||||
haltAnimation();
|
||||
|
||||
for (;;) {
|
||||
|
@ -389,7 +389,7 @@ void AGOSEngine_Waxworks::oww_pauseGame() {
|
|||
}
|
||||
|
||||
restartAnimation();
|
||||
_gameStoppedClock = time(NULL) - pauseTime + _gameStoppedClock;
|
||||
_gameStoppedClock = getTime() - pauseTime + _gameStoppedClock;
|
||||
}
|
||||
|
||||
void AGOSEngine_Waxworks::oww_boxMessage() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue