Proper frametimes handling
This commit is contained in:
parent
374cc9fa9a
commit
5d630b66f0
|
@ -13,6 +13,7 @@
|
|||
#define ScreenBits 16
|
||||
int ScreenWidth = 512;
|
||||
int ScreenHeight = 512;
|
||||
#define GameTick 30
|
||||
|
||||
SDL_Surface * Screen = NULL;
|
||||
SDL_Event Event;
|
||||
|
@ -29,6 +30,18 @@ SDL_Color DebugTextColor = { 80, 80, 80 };
|
|||
|
||||
bool Quit, Redraw, DebugMode;
|
||||
|
||||
// <https://www.libsdl.org/release/SDL-1.2.15/docs/html/guidetimeexamples.html>
|
||||
static Uint32 NextTime;
|
||||
Uint32 TimeLeft() {
|
||||
Uint32 Now;
|
||||
Now = SDL_GetTicks();
|
||||
if ( NextTime <= Now ) {
|
||||
return 0;
|
||||
} else {
|
||||
return NextTime - Now;
|
||||
}
|
||||
}
|
||||
|
||||
struct UsedKeys {
|
||||
bool Up, Down, Left, Right, Above, Below;
|
||||
bool Place, Break;
|
||||
|
@ -259,6 +272,7 @@ int main( int argc, char* args[] ) {
|
|||
Redraw = true;
|
||||
|
||||
while ( !Quit ) {
|
||||
NextTime = SDL_GetTicks() + GameTick;
|
||||
while ( SDL_PollEvent( & Event ) ) {
|
||||
Redraw = true;
|
||||
if ( Event.type == SDL_QUIT ) {
|
||||
|
@ -321,7 +335,8 @@ int main( int argc, char* args[] ) {
|
|||
}
|
||||
Redraw = false;
|
||||
}
|
||||
SDL_Delay( 16 ); // TODO: proper framerate management
|
||||
SDL_Delay( TimeLeft() );
|
||||
NextTime += GameTick;
|
||||
}
|
||||
|
||||
printf("[I] Exiting!\n");
|
||||
|
|
|
@ -10,8 +10,7 @@ struct xyz {
|
|||
int x, y, z;
|
||||
};
|
||||
|
||||
/*** Thanks to <https://gist.github.com/jordwest/8a12196436ebcf8df98a2745251915b5> for the maths! ***/
|
||||
|
||||
// <https://gist.github.com/jordwest/8a12196436ebcf8df98a2745251915b5>
|
||||
struct xyz OrthoToIso ( int x, int y, int z, int Multiply ) {
|
||||
struct xyz xyz;
|
||||
xyz.x = x * 1 * 0.5 * Multiply + z * -1 * 0.5 * Multiply;
|
||||
|
@ -20,5 +19,3 @@ struct xyz OrthoToIso ( int x, int y, int z, int Multiply ) {
|
|||
return xyz;
|
||||
}
|
||||
|
||||
/*** ******************************************************************************************** ***/
|
||||
|
||||
|
|
Loading…
Reference in New Issue