From adbd2511beec8f1caa1752bdfd755cc2f62ba425 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 9 Mar 2024 08:43:26 -0800 Subject: Make isogfx a library instead of an executable. --- gfx-app/include/gfx/gfx_app.h | 53 ++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 23 deletions(-) (limited to 'gfx-app/include') diff --git a/gfx-app/include/gfx/gfx_app.h b/gfx-app/include/gfx/gfx_app.h index 86c502a..ffff4bc 100644 --- a/gfx-app/include/gfx/gfx_app.h +++ b/gfx-app/include/gfx/gfx_app.h @@ -2,6 +2,8 @@ #include +typedef struct GfxAppState GfxAppState; + /// Application settings. typedef struct GfxAppDesc { int argc; // Number of application arguments. @@ -11,21 +13,22 @@ typedef struct GfxAppDesc { int max_fps; // Desired maximum display framerate. 0 to disable. double update_delta_time; // Desired delta time between frame updates. const char* title; // Window title. + GfxAppState* app_state; } GfxAppDesc; -typedef bool (*GfxAppInit)(const GfxAppDesc*, void** app_state); -typedef void (*GfxAppUpdate)(void* app_state, double t, double dt); -typedef void (*GfxAppRender)(void* app_state); -typedef void (*GfxAppResize)(void* app_state, int width, int height); -typedef void (*GfxAppShutdown)(void* app_state); +typedef bool (*GfxAppInit)(GfxAppState*, int argc, const char** argv); +typedef void (*GfxAppShutdown)(GfxAppState*); +typedef void (*GfxAppUpdate)(GfxAppState*, double t, double dt); +typedef void (*GfxAppRender)(GfxAppState*); +typedef void (*GfxAppResize)(GfxAppState*, int width, int height); /// Application callback functions. typedef struct GfxAppCallbacks { GfxAppInit init; + GfxAppShutdown shutdown; GfxAppUpdate update; GfxAppRender render; GfxAppResize resize; - GfxAppShutdown shutdown; } GfxAppCallbacks; typedef enum Key { @@ -68,21 +71,25 @@ bool gfx_is_key_pressed(Key); /// Define a main function that initializes and puts the application in a loop. /// See also: gfx_app_run(). -#define GFX_APP_MAIN(WIDTH, HEIGHT, MAX_FPS) \ - int main(int argc, const char** argv) { \ - gfx_app_run( \ - &(GfxAppDesc){ \ - .argc = argc, \ - .argv = argv, \ - .width = WIDTH, \ - .height = HEIGHT, \ - .max_fps = MAX_FPS, \ - .update_delta_time = MAX_FPS > 0 ? 1.0 / (double)MAX_FPS : 0.0}, \ - &(GfxAppCallbacks){ \ - .init = (GfxAppInit)app_init, \ - .update = (GfxAppUpdate)app_update, \ - .render = (GfxAppRender)app_render, \ - .resize = (GfxAppResize)app_resize, \ - .shutdown = (GfxAppShutdown)app_end}); \ - return 0; \ +#define GFX_APP_MAIN(WIDTH, HEIGHT, MAX_FPS, TITLE) \ + int main(int argc, const char** argv) { \ + GfxAppState app_state = {0}; \ + gfx_app_run( \ + &(GfxAppDesc){ \ + .argc = argc, \ + .argv = argv, \ + .width = WIDTH, \ + .height = HEIGHT, \ + .max_fps = MAX_FPS, \ + .update_delta_time = MAX_FPS > 0 ? 1.0 / (double)MAX_FPS : 0.0, \ + .title = TITLE, \ + .app_state = &app_state, \ + }, \ + &(GfxAppCallbacks){ \ + .init = (GfxAppInit)app_init, \ + .update = (GfxAppUpdate)app_update, \ + .render = (GfxAppRender)app_render, \ + .resize = (GfxAppResize)app_resize, \ + .shutdown = (GfxAppShutdown)app_end}); \ + return 0; \ } -- cgit v1.2.3