Skip to content
Snippets Groups Projects
Commit cf42040f authored by Florian Burgener's avatar Florian Burgener
Browse files

Update drawing timing

parent dc0f2b69
No related branches found
No related tags found
No related merge requests found
......@@ -21,41 +21,31 @@ int main() {
return EXIT_FAILURE;
}
int32_t time_elapsing_per_second = 3600 * 24 * 365;
int32_t update_per_second = 1000;
printf("%d\n", time_elapsing_per_second / update_per_second);
SolarSystem *solar_system = solar_system_create(time_elapsing_per_second / update_per_second);
int32_t hz = 240;
int32_t a = 0;
int32_t b = 0;
int32_t elapsed_seconds = 0;
int32_t time_elapsing_per_second = 3600 * 24 * 100;
int32_t refresh_rate = 240;
int32_t elapsed_time = 0;
double sleep_duration = 1.0 / refresh_rate * 1E9;
SolarSystem *solar_system = solar_system_create(time_elapsing_per_second / refresh_rate);
int64_t tmp = time(NULL) % 1000;
while (true) {
solar_system_update(solar_system);
b += 1;
if ((double)b >= (double)update_per_second / hz * (a + 1)) {
a += 1;
gfx_present(context);
solar_system_draw(solar_system, context);
if (b >= update_per_second) {
b = 0;
elapsed_seconds += 1;
if (elapsed_time % refresh_rate == 0) {
char title[100];
sprintf(title, "Solar System (%d)", elapsed_seconds);
sprintf(title, "Solar System (%d : %ld)", elapsed_time / refresh_rate, (time(NULL) - tmp) % 1000);
SDL_SetWindowTitle(context->window, title);
}
if (a % hz == 0)
a = 0;
}
if (gfx_keypressed() == SDLK_ESCAPE)
break;
struct timespec t = {.tv_sec = 0, .tv_nsec = 1.0 / update_per_second * 1E9};
struct timespec t = {.tv_sec = 0, .tv_nsec = sleep_duration};
nanosleep(&t, NULL);
elapsed_time += 1;
}
gfx_destroy(context);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment