Permalink
Browse files

SLUDGE: Objectify Timing

  • Loading branch information...
yinsimei committed Jul 17, 2017
1 parent 4c4690a commit 5d554d36edff3b2cc03e72625f707208f5d54a3c
Showing with 34 additions and 27 deletions.
  1. +2 −2 engines/sludge/main_loop.cpp
  2. +4 −0 engines/sludge/sludge.h
  3. +1 −2 engines/sludge/sludger.cpp
  4. +13 −18 engines/sludge/timing.cpp
  5. +14 −5 engines/sludge/timing.h
@@ -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();
View
@@ -29,6 +29,7 @@
#include "gui/debugger.h"
#include "sludge/console.h"
#include "sludge/timing.h"
namespace Sludge {
@@ -62,6 +63,9 @@ class SludgeEngine: public Engine {
Common::String fatalMessage;
Common::String fatalInfo;
// timer
Timer _timer;
SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc);
virtual ~SludgeEngine();
@@ -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.
View
@@ -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
View
@@ -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

0 comments on commit 5d554d3

Please sign in to comment.