aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorStrangerke2015-12-12 19:38:00 +0100
committerWillem Jan Palenstijn2015-12-23 21:34:01 +0100
commit7bb45a8eaaf663cca9d0765d84b38967c3cc3275 (patch)
treee044d20af588b81a96776004bfc3bbb037086ed0 /engines
parent0c0b2da235bfbbc3a11ef9677137d5a77f5b35a2 (diff)
downloadscummvm-rg350-7bb45a8eaaf663cca9d0765d84b38967c3cc3275.tar.gz
scummvm-rg350-7bb45a8eaaf663cca9d0765d84b38967c3cc3275.tar.bz2
scummvm-rg350-7bb45a8eaaf663cca9d0765d84b38967c3cc3275.zip
LAB: Move timing functions to the utility class
Diffstat (limited to 'engines')
-rw-r--r--engines/lab/anim.cpp4
-rw-r--r--engines/lab/engine.cpp8
-rw-r--r--engines/lab/intro.cpp7
-rw-r--r--engines/lab/lab.h8
-rw-r--r--engines/lab/module.mk1
-rw-r--r--engines/lab/processroom.cpp4
-rw-r--r--engines/lab/timing.cpp127
-rw-r--r--engines/lab/utils.cpp93
-rw-r--r--engines/lab/utils.h6
9 files changed, 110 insertions, 148 deletions
diff --git a/engines/lab/anim.cpp b/engines/lab/anim.cpp
index a461996e4a..3bed3656d3 100644
--- a/engines/lab/anim.cpp
+++ b/engines/lab/anim.cpp
@@ -98,8 +98,8 @@ void Anim::diffNextFrame(bool onlyDiffData) {
if (!onlyDiffData) {
if (_headerdata._fps) {
- _vm->waitForTime(_waitSec, _waitMicros);
- _vm->addCurTime(0L, _delayMicros, &_waitSec, &_waitMicros);
+ _vm->_utils->waitForTime(_waitSec, _waitMicros);
+ _vm->_utils->addCurTime(0L, _delayMicros, &_waitSec, &_waitMicros);
}
if (_isPal && !_noPalChange) {
diff --git a/engines/lab/engine.cpp b/engines/lab/engine.cpp
index 17518fb750..f0d3ab7a5b 100644
--- a/engines/lab/engine.cpp
+++ b/engines/lab/engine.cpp
@@ -609,7 +609,7 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo
_followCrumbsFast = (code == 'r' || code == 'R');
_isCrumbTurning = false;
_isCrumbWaiting = false;
- getTime(&_crumbSecs, &_crumbMicros);
+ _utils->getTime(&_crumbSecs, &_crumbMicros);
if (_alternate) {
eatMessages();
@@ -930,7 +930,7 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo
_followCrumbsFast = false;
_isCrumbTurning = false;
_isCrumbWaiting = false;
- getTime(&_crumbSecs, &_crumbMicros);
+ _utils->getTime(&_crumbSecs, &_crumbMicros);
eatMessages();
_alternate = false;
@@ -1144,7 +1144,7 @@ int LabEngine::followCrumbs() {
uint32 Secs;
uint32 Micros;
- timeDiff(_crumbSecs, _crumbMicros, &Secs, &Micros);
+ _utils->timeDiff(_crumbSecs, _crumbMicros, &Secs, &Micros);
if (Secs != 0 || Micros != 0)
return 0;
@@ -1189,7 +1189,7 @@ int LabEngine::followCrumbs() {
_isCrumbTurning = (moveDir != VKEY_UPARROW);
_isCrumbWaiting = true;
- addCurTime(theDelay / ONESECOND, theDelay % ONESECOND, &_crumbSecs, &_crumbMicros);
+ _utils->addCurTime(theDelay / ONESECOND, theDelay % ONESECOND, &_crumbSecs, &_crumbMicros);
}
return moveDir;
diff --git a/engines/lab/intro.cpp b/engines/lab/intro.cpp
index d0406bc192..633691c820 100644
--- a/engines/lab/intro.cpp
+++ b/engines/lab/intro.cpp
@@ -36,6 +36,7 @@
#include "lab/intro.h"
#include "lab/music.h"
#include "lab/resource.h"
+#include "lab/utils.h"
namespace Lab {
@@ -131,7 +132,7 @@ void Intro::doPictText(const char *filename, TextFont *msgFont, bool isScreen) {
return;
}
- _vm->getTime(&lastSecs, &lastMicros);
+ _vm->_utils->getTime(&lastSecs, &lastMicros);
}
msg = _vm->getMsg();
@@ -139,8 +140,8 @@ void Intro::doPictText(const char *filename, TextFont *msgFont, bool isScreen) {
if (msg == NULL) {
_vm->_music->updateMusic();
_vm->_anim->diffNextFrame();
- _vm->getTime(&secs, &micros);
- _vm->anyTimeDiff(lastSecs, lastMicros, secs, micros, &secs, &micros);
+ _vm->_utils->getTime(&secs, &micros);
+ _vm->_utils->anyTimeDiff(lastSecs, lastMicros, secs, micros, &secs, &micros);
if (secs > timeDelay) {
if (end) {
diff --git a/engines/lab/lab.h b/engines/lab/lab.h
index 639983b55e..d9f59f0c0e 100644
--- a/engines/lab/lab.h
+++ b/engines/lab/lab.h
@@ -103,13 +103,6 @@ public:
LargeSet *_conditions, *_roomsFound;
- // timing.cpp
- void getTime(uint32 *secs, uint32 *micros);
- void addCurTime(uint32 sec, uint32 micros, uint32 *timeSec, uint32 *timeMicros);
- 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 waitForTime(uint32 sec, uint32 micros);
-
private:
uint32 _extraGameFeatures;
bool _interfaceOff;
@@ -117,7 +110,6 @@ private:
bool _quitLab;
bool _mainDisplay;
// timing.cpp
- void microDelay(uint32 secs, uint32 micros);
public:
EventManager *_event;
diff --git a/engines/lab/module.mk b/engines/lab/module.mk
index 0d05de275e..a0dcfde512 100644
--- a/engines/lab/module.mk
+++ b/engines/lab/module.mk
@@ -18,7 +18,6 @@ MODULE_OBJS := \
savegame.o \
special.o \
tilepuzzle.o \
- timing.o \
transitions.o \
utils.o
diff --git a/engines/lab/processroom.cpp b/engines/lab/processroom.cpp
index 49287aeeba..b997942879 100644
--- a/engines/lab/processroom.cpp
+++ b/engines/lab/processroom.cpp
@@ -425,14 +425,14 @@ void LabEngine::doActions(Action *actionList, CloseDataPtr *closePtrList) {
case WAITSECS: {
uint32 startSecs, startMicros, curSecs, curMicros;
- addCurTime(actionList->_param1, 0, &startSecs, &startMicros);
+ _utils->addCurTime(actionList->_param1, 0, &startSecs, &startMicros);
_graphics->screenUpdate();
while (1) {
_music->updateMusic();
_anim->diffNextFrame();
- getTime(&curSecs, &curMicros);
+ _utils->getTime(&curSecs, &curMicros);
if ((curSecs > startSecs) || ((curSecs == startSecs) && (curMicros >= startMicros)))
break;
diff --git a/engines/lab/timing.cpp b/engines/lab/timing.cpp
deleted file mode 100644
index 1cbe6d328a..0000000000
--- a/engines/lab/timing.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-/*
- * This code is based on Labyrinth of Time code with assistance of
- *
- * Copyright (c) 1993 Terra Nova Development
- * Copyright (c) 2004 The Wyrmkeep Entertainment Co.
- *
- */
-
-#include "lab/lab.h"
-
-namespace Lab {
-
-/**
- * Waits for for Secs seconds and Micros microseconds to pass.
- */
-void LabEngine::microDelay(uint32 secs, uint32 micros) {
- uint32 waitSecs, waitMicros;
- addCurTime(secs, micros, &waitSecs, &waitMicros);
-
- while (1) {
- getTime(&secs, &micros);
-
- if ((secs > waitSecs) || ((secs == waitSecs) && (micros >= waitMicros)))
- return;
-
- g_system->delayMillis(10);
- }
-}
-
-/**
- * Gets the current system time.
- */
-void LabEngine::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 LabEngine::addCurTime(uint32 sec, uint32 micros, uint32 *timeSec, uint32 *timeMicros) {
- getTime(timeSec, timeMicros);
-
- (*timeSec) += sec;
- (*timeMicros) += micros;
-
- if (*timeMicros >= ONESECOND) {
- (*timeSec)++;
- (*timeMicros) -= ONESECOND;
- }
-}
-
-/**
- * Finds the difference between time1 and time2. If time1 is later than
- * time2, returns 0.
- */
-void LabEngine::anyTimeDiff(uint32 sec1, uint32 micros1, uint32 sec2, uint32 micros2, uint32 *diffSecs, uint32 *diffMicros) {
- *diffSecs = 0;
- *diffMicros = 0;
-
- if (sec1 > sec2)
- return;
- else if ((sec1 == sec2) && (micros1 >= micros2))
- return;
-
- if (micros1 > micros2) {
- *diffSecs = sec2 - sec1 - 1;
- *diffMicros = (ONESECOND - micros1) + micros2;
- } else {
- *diffSecs = sec2 - sec1;
- *diffMicros = micros2 - micros1;
- }
-}
-
-/**
- * Finds the difference between the current time, and a future time. Returns
- * 0 if the future time is actually before the current time.
- */
-void LabEngine::timeDiff(uint32 sec, uint32 micros, uint32 *diffSec, uint32 *diffMicros) {
- uint32 curSec, curMicros;
- getTime(&curSec, &curMicros);
- anyTimeDiff(curSec, curMicros, sec, micros, diffSec, diffMicros);
-}
-
-/**
- * Waits for a specified time to occur.
- */
-void LabEngine::waitForTime(uint32 sec, uint32 micros) {
- uint32 curSec, curMicros;
- getTime(&curSec, &curMicros);
-
- if (curSec > sec)
- return;
- else if ((curSec == sec) && (curMicros >= micros))
- return;
-
- if (curMicros > micros)
- microDelay(sec - curSec - 1, (ONESECOND - curMicros) + micros - 1);
- else
- microDelay(sec - curSec, micros - curMicros - 1);
-}
-
-} // End of namespace Lab
diff --git a/engines/lab/utils.cpp b/engines/lab/utils.cpp
index f9a6656174..1ac083790e 100644
--- a/engines/lab/utils.cpp
+++ b/engines/lab/utils.cpp
@@ -433,7 +433,7 @@ void Utils::setBytesPerRow(int num) {
uint16 Utils::getRandom(uint16 max) {
uint32 secs, micros;
- _vm->getTime(&secs, &micros);
+ getTime(&secs, &micros);
return ((micros + secs) % max);
}
@@ -442,4 +442,95 @@ void Utils::readBlock(void *Buffer, uint32 Size, byte **File) {
(*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, &micros);
+
+ 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;
+
+ if (*timeMicros >= ONESECOND) {
+ (*timeSec)++;
+ (*timeMicros) -= ONESECOND;
+ }
+}
+
+/**
+ * Finds the difference between time1 and time2. If time1 is later than
+ * time2, returns 0.
+ */
+void Utils::anyTimeDiff(uint32 sec1, uint32 micros1, uint32 sec2, uint32 micros2, uint32 *diffSecs, uint32 *diffMicros) {
+ *diffSecs = 0;
+ *diffMicros = 0;
+
+ if (sec1 > sec2)
+ return;
+ else if ((sec1 == sec2) && (micros1 >= micros2))
+ return;
+
+ if (micros1 > micros2) {
+ *diffSecs = sec2 - sec1 - 1;
+ *diffMicros = (ONESECOND - micros1) + micros2;
+ } else {
+ *diffSecs = sec2 - sec1;
+ *diffMicros = micros2 - micros1;
+ }
+}
+
+/**
+ * Finds the difference between the current time, and a future time. Returns
+ * 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);
+ anyTimeDiff(curSec, curMicros, sec, micros, diffSec, diffMicros);
+}
+
+/**
+ * Waits for a specified time to occur.
+ */
+void Utils::waitForTime(uint32 sec, uint32 micros) {
+ uint32 curSec, curMicros;
+ getTime(&curSec, &curMicros);
+
+ if (curSec > sec)
+ return;
+ else if ((curSec == sec) && (curMicros >= micros))
+ return;
+
+ if (curMicros > micros)
+ microDelay(sec - curSec - 1, (ONESECOND - curMicros) + micros - 1);
+ else
+ microDelay(sec - curSec, micros - curMicros - 1);
+}
} // End of namespace Lab
diff --git a/engines/lab/utils.h b/engines/lab/utils.h
index da1f89af7d..9d6e1872d4 100644
--- a/engines/lab/utils.h
+++ b/engines/lab/utils.h
@@ -43,6 +43,7 @@ private:
void VUnDiffByteByte(byte *Dest, byte *diff, uint16 bytesperrow);
void VUnDiffByteWord(uint16 *Dest, uint16 *diff, uint16 bytesperrow);
void VUnDiffByteLong(uint32 *Dest, uint32 *diff, uint16 bytesperrow);
+ void microDelay(uint32 secs, uint32 micros);
public:
Utils(LabEngine *vm);
@@ -61,6 +62,11 @@ public:
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);
};