diff --git a/Makefile b/Makefile index feece84..9febfe0 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ all: - clang src/*.c -g3 `sdl-config --cflags --libs` -lSDL_mixer -lm -Wall -Wextra -o hyper_rotagon + clang src/*.c -g3 `sdl-config --cflags --libs` -lSDL_mixer -lSDL_ttf -lm -Wall -Wextra -o hyper_rotagon clean: rm hyper_rotagon diff --git a/src/game.c b/src/game.c index 70a5f8a..4cad3a9 100644 --- a/src/game.c +++ b/src/game.c @@ -167,3 +167,15 @@ init_game(struct s_game *g) { //{{{ init_obs(g); } //}}} + +void +update_game_time(struct s_game *g) { + struct timespec actual_time; + + clock_gettime(CLOCK_REALTIME, &actual_time); + + float secs_passed = actual_time.tv_sec - g->start_time.tv_sec + + (actual_time.tv_nsec - g->start_time.tv_nsec) / 1e9; + + g->elapsed_time = secs_passed; +} diff --git a/src/game.h b/src/game.h index 11bea63..7ce1fcd 100644 --- a/src/game.h +++ b/src/game.h @@ -79,6 +79,7 @@ struct s_game { struct timespec start_time; + float elapsed_time; struct { int avail_musics; @@ -119,6 +120,9 @@ change_game_color(struct s_game *g); void init_random_color(struct s_game *g); +void +update_game_time(struct s_game *g); + #endif /* ndef GAME_H */ diff --git a/src/main.c b/src/main.c index c8e956a..635efd5 100644 --- a/src/main.c +++ b/src/main.c @@ -37,6 +37,8 @@ start: //clear the screen SDL_FillRect(ga.screen, NULL, 0); + update_game_time(&ga); + if(did_have_beat(&ga)) { ga.sexual_pulsation = 40; diff --git a/src/music.c b/src/music.c index 01a68af..c7fadd9 100644 --- a/src/music.c +++ b/src/music.c @@ -115,11 +115,7 @@ did_have_beat(struct s_game *g) { if(music == -1) return 0; - struct timespec actual_time; - clock_gettime(CLOCK_REALTIME, &actual_time); - - float secs_passed = actual_time.tv_sec - g->start_time.tv_sec + - (actual_time.tv_nsec - g->start_time.tv_nsec) / 1e9; + float secs_passed = g->elapsed_time; if(g->audio.num_beats[music] > g->audio.beat_already_done) { if(g->audio.beats[music][g->audio.beat_already_done] < secs_passed) { diff --git a/src/sdl.c b/src/sdl.c index 032ec12..6840f53 100644 --- a/src/sdl.c +++ b/src/sdl.c @@ -7,17 +7,30 @@ #include #include #include "SDL/SDL.h" +#include "SDL2/SDL_ttf.h" #include "game.h" void init_SDL(struct s_game *g) { /* initialize SDL */ - SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); + if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) { + perror("Could not init SDL !"); + exit(EXIT_FAILURE); + } /* set the title bar */ SDL_WM_SetCaption("SDL Move", "SDL Move"); /* create window */ g->screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0); + if(!g->screen) { + perror("Could not grab screen !"); + exit(EXIT_FAILURE); + } + + if(TTF_Init() < 0) { + perror("Could not load SDL TTF"); + exit(EXIT_FAILURE); + } }