Added fps counter
This commit is contained in:
parent
3fc18843b3
commit
73e777f98a
38
main.c
38
main.c
@ -33,8 +33,10 @@ GameState gameState = MainMenu;
|
||||
Scenery scenery;
|
||||
|
||||
int main(int argc, char * args[]){
|
||||
// printf("Spielbereiche\n\t- 1: Hauptmen"ue "\n\t- 2: Spiel\n\t- 3: Level Select\n\t- 4: Settings\n\t- 5: Highscores\n");
|
||||
// GAME_ChangeState(readIntFromIO("W"ae "hle einen Spielbereich aus, den du testen m"oe "chtest:", "Fehlerhafte Eingabe!\n", "%d ist kein g"ue "ltiger Spielbereich!\n", 1, 5));
|
||||
Uint32 fps_lasttime = SDL_GetTicks(); // the last recorded time.
|
||||
Uint32 fps_current; // the current FPS.
|
||||
Uint32 fps_frames = 0; // frames passed since the last recorded fps.
|
||||
|
||||
INITIALIZE();
|
||||
while (running) { // Gameloop
|
||||
HandleSDLEvents();
|
||||
@ -60,6 +62,13 @@ int main(int argc, char * args[]){
|
||||
break;
|
||||
}
|
||||
SDL_RenderPresent(renderer);
|
||||
fps_frames++;
|
||||
if (fps_lasttime < SDL_GetTicks() - 1000) {
|
||||
fps_lasttime = SDL_GetTicks();
|
||||
fps_current = fps_frames;
|
||||
fps_frames = 0;
|
||||
printf("Frames/s: %u\n", fps_current);
|
||||
}
|
||||
}
|
||||
QUIT();
|
||||
return 0;
|
||||
@ -197,28 +206,3 @@ void QUIT(){
|
||||
printf("Quitting SDL finished!\n");
|
||||
printf("De-initializing finished!\n");
|
||||
} /* QUIT */
|
||||
|
||||
int readIntFromIO(char * m1, char * m2, char * m3, int min, int max){
|
||||
int nitems, num;
|
||||
|
||||
while (1) {
|
||||
while (1) {
|
||||
printf(m1);
|
||||
nitems = scanf("%d", &num);
|
||||
if (nitems == 0) {
|
||||
printf(m2);
|
||||
fflush(stdin);
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((num < min) || (num > max)) {
|
||||
printf(m3, num);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
fflush(stdin);
|
||||
return(num);
|
||||
} /* readIntFromIO */
|
||||
|
Loading…
Reference in New Issue
Block a user