Select Git revision
main.c 1.39 KiB
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "SolarSystem.h"
#include "Vector2.h"
// #include "gfx/gfx.h"
#define SCREEN_WIDTH 1000
#define SCREEN_HEIGHT 1000
int main() {
// srand(time(NULL));
srand(0);
struct gfx_context_t *context = gfx_create("Solar System", SCREEN_WIDTH, SCREEN_HEIGHT);
if (!context) {
fprintf(stderr, "Graphics initialization failed!\n");
return EXIT_FAILURE;
}
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);
gfx_present(context);
solar_system_draw(solar_system, context);
if (elapsed_time % refresh_rate == 0) {
char title[100];
sprintf(title, "Solar System (%d : %ld)", elapsed_time / refresh_rate, (time(NULL) - tmp) % 1000);
SDL_SetWindowTitle(context->window, title);
}
if (gfx_keypressed() == SDLK_ESCAPE)
break;
struct timespec t = {.tv_sec = 0, .tv_nsec = sleep_duration};
nanosleep(&t, NULL);
elapsed_time += 1;
}
gfx_destroy(context);
return EXIT_SUCCESS;
}