#include "common.h" #include #include char *va(const char *fmt, ...) { va_list vl; static char buffer[4096]; va_start(vl, fmt); vsnprintf(buffer, sizeof(buffer), fmt, vl); va_end(vl); return buffer; } int64_t get_time(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); return ts.tv_sec * 1000000000 + ts.tv_nsec; } int main(void) { int rv = 0; r_window *first_window; phy_sim sim; SDL_Thread *sim_thread; if (r_init()) { con_printf("fatal error: renderer initialization failed\n"); rv = 1; goto quit; } if (ui_init()) { con_printf("fatal error: UI initialization failed\n"); rv = 1; goto quit; } signal(SIGINT, SIG_DFL); signal(SIGTERM, SIG_DFL); first_window = r_window_create(); if (!first_window) { con_printf("fatal error: couldn't open first window\n"); rv = 1; goto quit; } ui_renderer_window_register(first_window); if (phy_sim_create(&sim)) { con_printf("fatal error: phy_sim_create failed\n"); rv = 1; goto quit; } sim_thread = SDL_CreateThread((SDL_ThreadFunction)phy_thread, "phy_thread", &sim); if (!sim_thread) { con_printf("fatal error: SDL_CreateThread failed: %s\n", SDL_GetError()); rv = 1; goto quit; } while (1) { SDL_Event event; while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) goto quit; else ui_event(&event); } ui_draw(&sim); } quit: con_printf("main: exitting, rv=%i\n", rv); phy_sim_destroy(&sim); ui_quit(); r_quit(); SDL_Quit(); return rv; }