aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorSimei Yin2017-07-17 12:14:40 +0200
committerSimei Yin2017-07-18 19:05:04 +0200
commit5d554d36edff3b2cc03e72625f707208f5d54a3c (patch)
tree310392cbcd2710d195e4c0d93f1a715b32b696da /engines
parent4c4690a1e35eda0041a4ee81ab6f89c56ff96981 (diff)
downloadscummvm-rg350-5d554d36edff3b2cc03e72625f707208f5d54a3c.tar.gz
scummvm-rg350-5d554d36edff3b2cc03e72625f707208f5d54a3c.tar.bz2
scummvm-rg350-5d554d36edff3b2cc03e72625f707208f5d54a3c.zip
SLUDGE: Objectify Timing
Diffstat (limited to 'engines')
-rw-r--r--engines/sludge/main_loop.cpp4
-rw-r--r--engines/sludge/sludge.h4
-rw-r--r--engines/sludge/sludger.cpp3
-rw-r--r--engines/sludge/timing.cpp31
-rw-r--r--engines/sludge/timing.h19
5 files changed, 34 insertions, 27 deletions
diff --git a/engines/sludge/main_loop.cpp b/engines/sludge/main_loop.cpp
index d2dcd8e975..29bbcd0f02 100644
--- a/engines/sludge/main_loop.cpp
+++ b/engines/sludge/main_loop.cpp
@@ -188,7 +188,7 @@ int main_loop(const char *filename)
startNewFunctionNum(0, 0, NULL, noStack);
- Init_Timer();
+ g_sludge->_timer.init();
weAreDoneSoQuit = 0;
while (!weAreDoneSoQuit) {
@@ -197,7 +197,7 @@ int main_loop(const char *filename)
handleInput();
sludgeDisplay();
handleSoundLists();
- Wait_Frame();
+ g_sludge->_timer.waitFrame();
}
killSoundStuff();
diff --git a/engines/sludge/sludge.h b/engines/sludge/sludge.h
index e419b85f0e..556dc94e74 100644
--- a/engines/sludge/sludge.h
+++ b/engines/sludge/sludge.h
@@ -29,6 +29,7 @@
#include "gui/debugger.h"
#include "sludge/console.h"
+#include "sludge/timing.h"
namespace Sludge {
@@ -62,6 +63,9 @@ public:
Common::String fatalMessage;
Common::String fatalInfo;
+ // timer
+ Timer _timer;
+
SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc);
virtual ~SludgeEngine();
diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp
index e57710213f..aed5fab9d8 100644
--- a/engines/sludge/sludger.cpp
+++ b/engines/sludge/sludger.cpp
@@ -71,7 +71,6 @@ int languageNum = -1;
int gameVersion;
int specialSettings;
FILETIME fileTime;
-extern int desiredfps;
bool captureAllKeys = false;
byte brightnessLevel = 255;
@@ -221,7 +220,7 @@ bool initSludge(const Common::String &filename) {
debug(kSludgeDebugDataLoad, "winHeight : %i", winHeight);
specialSettings = fp->readByte();
debug(kSludgeDebugDataLoad, "specialSettings : %i", specialSettings);
- desiredfps = 1000 / fp->readByte();
+ g_sludge->_timer.setDesiredfps(1000 / fp->readByte());
readString(fp); // Unused - was used for registration purposes.
diff --git a/engines/sludge/timing.cpp b/engines/sludge/timing.cpp
index 2e83e1d0b5..2e3865498a 100644
--- a/engines/sludge/timing.cpp
+++ b/engines/sludge/timing.cpp
@@ -25,36 +25,31 @@
namespace Sludge {
-int desiredfps = 300; //holds desired frames per second
-
-uint32 starttime, endtime;
-uint32 desired_frame_time;
-
-void Init_Timer(void) {
- desired_frame_time = 1000 / desiredfps;
- starttime = g_system->getMillis();
+void Timer::init(void) {
+ _desired_frame_time = 1000 / _desiredfps;
+ _starttime = g_system->getMillis();
}
-void Init_Special_Timer(int t) {
- desired_frame_time = 1000 / t;
- starttime = g_system->getMillis();
+void Timer::initSpecial(int t) {
+ _desired_frame_time = 1000 / t;
+ _starttime = g_system->getMillis();
}
-void Wait_Frame(void) {
+void Timer::waitFrame(void) {
static uint32 addNextTime = 0;
uint32 timetaken;
for (;;) {
- endtime = g_system->getMillis();
- timetaken = addNextTime + endtime - starttime;
- if (timetaken >= desired_frame_time) break;
+ _endtime = g_system->getMillis();
+ timetaken = addNextTime + _endtime - _starttime;
+ if (timetaken >= _desired_frame_time) break;
g_system->delayMillis(1);
}
- addNextTime = timetaken - desired_frame_time;
- if (addNextTime > desired_frame_time) addNextTime = desired_frame_time;
+ addNextTime = timetaken - _desired_frame_time;
+ if (addNextTime > _desired_frame_time) addNextTime = _desired_frame_time;
- starttime = endtime;
+ _starttime = _endtime;
}
} // End of namespace Sludge
diff --git a/engines/sludge/timing.h b/engines/sludge/timing.h
index 16f406bac0..0d7ffece8d 100644
--- a/engines/sludge/timing.h
+++ b/engines/sludge/timing.h
@@ -24,11 +24,20 @@
namespace Sludge {
-void Init_Timer(void);
-void Init_Special_Timer(int t);
-void Get_Start_Time(void);
-void Get_End_Time(void);
-void Wait_Frame(void);
+class Timer {
+private:
+ int _desiredfps; // desired frames per second
+ uint32 _starttime, _endtime;
+ uint32 _desired_frame_time;
+
+public:
+ void setDesiredfps(int t) { _desiredfps = t; }
+ void init(void);
+ void initSpecial(int t);
+ void waitFrame(void);
+
+ Timer():_desiredfps(300), _starttime(0), _endtime(0), _desired_frame_time(0){}
+};
} // End of namespace Sludge