Permalink
Browse files

SLUDGE: add game timing

  • Loading branch information...
yinsimei committed Jul 4, 2017
1 parent 0cb10da commit e574f22cd0ae565e604c7e4053c75bfb66872512
Showing with 12 additions and 19 deletions.
  1. +0 −7 engines/sludge/main_loop.cpp
  2. +12 −12 engines/sludge/timing.cpp
@@ -319,23 +319,16 @@ int main_loop(const char *filename)
startNewFunctionNum(0, 0, NULL, noStack);
#if 0
Init_Timer();
SDL_EnableUNICODE(1);
#endif
renderSurface.create(g_system->getWidth(), g_system->getHeight(), g_system->getScreenFormat());
weAreDoneSoQuit = 0;
while (!weAreDoneSoQuit) {
checkInput();
walkAllPeople();
handleInput();
sludgeDisplay();
handleSoundLists();
g_system->delayMillis(1000 / desiredfps);
#if 0
Wait_Frame();
#endif
}
debugOut("Bye!\n\n");
View
@@ -20,41 +20,41 @@
*
*/
#include "sludge/allfiles.h"
#include "sludge/timing.h"
namespace Sludge {
int desiredfps = 300; //holds desired frames per second
#if 0
Uint32 starttime, endtime;
Uint32 desired_frame_time;
uint32 starttime, endtime;
uint32 desired_frame_time;
void Init_Timer(void) {
desired_frame_time = 1000 / desiredfps;
starttime = SDL_GetTicks();
starttime = g_system->getMillis();
}
void Init_Special_Timer(int t) {
desired_frame_time = 1000 / t;
starttime = SDL_GetTicks();
starttime = g_system->getMillis();
}
void Wait_Frame(void) {
static Uint32 addNextTime = 0;
Uint32 timetaken;
static uint32 addNextTime = 0;
uint32 timetaken;
for (;;) {
endtime = SDL_GetTicks();
endtime = g_system->getMillis();
timetaken = addNextTime + endtime - starttime;
if (timetaken >= desired_frame_time) break;
SDL_Delay(1);
g_system->delayMillis(1);
}
addNextTime = timetaken - desired_frame_time;
if (addNextTime > desired_frame_time) addNextTime = desired_frame_time;
starttime = endtime;
}
#endif
}
// End of namespace Sludge
} // End of namespace Sludge

0 comments on commit e574f22

Please sign in to comment.