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;
|
Scenery scenery;
|
||||||
|
|
||||||
int main(int argc, char * args[]){
|
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");
|
Uint32 fps_lasttime = SDL_GetTicks(); // the last recorded time.
|
||||||
// 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_current; // the current FPS.
|
||||||
|
Uint32 fps_frames = 0; // frames passed since the last recorded fps.
|
||||||
|
|
||||||
INITIALIZE();
|
INITIALIZE();
|
||||||
while (running) { // Gameloop
|
while (running) { // Gameloop
|
||||||
HandleSDLEvents();
|
HandleSDLEvents();
|
||||||
@ -60,6 +62,13 @@ int main(int argc, char * args[]){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
SDL_RenderPresent(renderer);
|
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();
|
QUIT();
|
||||||
return 0;
|
return 0;
|
||||||
@ -197,28 +206,3 @@ void QUIT(){
|
|||||||
printf("Quitting SDL finished!\n");
|
printf("Quitting SDL finished!\n");
|
||||||
printf("De-initializing finished!\n");
|
printf("De-initializing finished!\n");
|
||||||
} /* QUIT */
|
} /* 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 */
|
|
||||||
|
1
main.h
1
main.h
@ -36,7 +36,6 @@ void windowChanged(SDL_WindowEvent b);
|
|||||||
void DrawBackground(SDL_Renderer * renderer);
|
void DrawBackground(SDL_Renderer * renderer);
|
||||||
void INITIALIZE();
|
void INITIALIZE();
|
||||||
void QUIT();
|
void QUIT();
|
||||||
int readIntFromIO(char * m1, char * m2, char * m3, int min, int max);
|
|
||||||
// End Prototypes
|
// End Prototypes
|
||||||
|
|
||||||
#endif // __main_h__
|
#endif // __main_h__
|
||||||
|
Loading…
Reference in New Issue
Block a user