Proper frametimes handling
This commit is contained in:
parent
374cc9fa9a
commit
5d630b66f0
|
@ -13,6 +13,7 @@
|
||||||
#define ScreenBits 16
|
#define ScreenBits 16
|
||||||
int ScreenWidth = 512;
|
int ScreenWidth = 512;
|
||||||
int ScreenHeight = 512;
|
int ScreenHeight = 512;
|
||||||
|
#define GameTick 30
|
||||||
|
|
||||||
SDL_Surface * Screen = NULL;
|
SDL_Surface * Screen = NULL;
|
||||||
SDL_Event Event;
|
SDL_Event Event;
|
||||||
|
@ -29,6 +30,18 @@ SDL_Color DebugTextColor = { 80, 80, 80 };
|
||||||
|
|
||||||
bool Quit, Redraw, DebugMode;
|
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 {
|
struct UsedKeys {
|
||||||
bool Up, Down, Left, Right, Above, Below;
|
bool Up, Down, Left, Right, Above, Below;
|
||||||
bool Place, Break;
|
bool Place, Break;
|
||||||
|
@ -259,6 +272,7 @@ int main( int argc, char* args[] ) {
|
||||||
Redraw = true;
|
Redraw = true;
|
||||||
|
|
||||||
while ( !Quit ) {
|
while ( !Quit ) {
|
||||||
|
NextTime = SDL_GetTicks() + GameTick;
|
||||||
while ( SDL_PollEvent( & Event ) ) {
|
while ( SDL_PollEvent( & Event ) ) {
|
||||||
Redraw = true;
|
Redraw = true;
|
||||||
if ( Event.type == SDL_QUIT ) {
|
if ( Event.type == SDL_QUIT ) {
|
||||||
|
@ -321,7 +335,8 @@ int main( int argc, char* args[] ) {
|
||||||
}
|
}
|
||||||
Redraw = false;
|
Redraw = false;
|
||||||
}
|
}
|
||||||
SDL_Delay( 16 ); // TODO: proper framerate management
|
SDL_Delay( TimeLeft() );
|
||||||
|
NextTime += GameTick;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("[I] Exiting!\n");
|
printf("[I] Exiting!\n");
|
||||||
|
|
|
@ -10,8 +10,7 @@ struct xyz {
|
||||||
int x, y, z;
|
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 OrthoToIso ( int x, int y, int z, int Multiply ) {
|
||||||
struct xyz xyz;
|
struct xyz xyz;
|
||||||
xyz.x = x * 1 * 0.5 * Multiply + z * -1 * 0.5 * Multiply;
|
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;
|
return xyz;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** ******************************************************************************************** ***/
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue