SLUDGE: Objectify Timing

This commit is contained in:
Simei Yin 2017-07-17 12:14:40 +02:00
parent 4c4690a1e3
commit 5d554d36ed
5 changed files with 34 additions and 27 deletions

View File

@ -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 File

@ -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();

View File

@ -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 File

@ -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 File

@ -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