diff options
author | 3gg <3gg@shellblade.net> | 2024-03-09 08:43:26 -0800 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2024-03-09 08:43:26 -0800 |
commit | adbd2511beec8f1caa1752bdfd755cc2f62ba425 (patch) | |
tree | 8fde167e9d9951b43e571a2417ae55f9572bea28 /gfx-app/include | |
parent | 4bc4ca2796bd434880b77d3c4bcbb56107456777 (diff) |
Make isogfx a library instead of an executable.
Diffstat (limited to 'gfx-app/include')
-rw-r--r-- | gfx-app/include/gfx/gfx_app.h | 53 |
1 files changed, 30 insertions, 23 deletions
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 @@ | |||
2 | 2 | ||
3 | #include <stdbool.h> | 3 | #include <stdbool.h> |
4 | 4 | ||
5 | typedef struct GfxAppState GfxAppState; | ||
6 | |||
5 | /// Application settings. | 7 | /// Application settings. |
6 | typedef struct GfxAppDesc { | 8 | typedef struct GfxAppDesc { |
7 | int argc; // Number of application arguments. | 9 | int argc; // Number of application arguments. |
@@ -11,21 +13,22 @@ typedef struct GfxAppDesc { | |||
11 | int max_fps; // Desired maximum display framerate. 0 to disable. | 13 | int max_fps; // Desired maximum display framerate. 0 to disable. |
12 | double update_delta_time; // Desired delta time between frame updates. | 14 | double update_delta_time; // Desired delta time between frame updates. |
13 | const char* title; // Window title. | 15 | const char* title; // Window title. |
16 | GfxAppState* app_state; | ||
14 | } GfxAppDesc; | 17 | } GfxAppDesc; |
15 | 18 | ||
16 | typedef bool (*GfxAppInit)(const GfxAppDesc*, void** app_state); | 19 | typedef bool (*GfxAppInit)(GfxAppState*, int argc, const char** argv); |
17 | typedef void (*GfxAppUpdate)(void* app_state, double t, double dt); | 20 | typedef void (*GfxAppShutdown)(GfxAppState*); |
18 | typedef void (*GfxAppRender)(void* app_state); | 21 | typedef void (*GfxAppUpdate)(GfxAppState*, double t, double dt); |
19 | typedef void (*GfxAppResize)(void* app_state, int width, int height); | 22 | typedef void (*GfxAppRender)(GfxAppState*); |
20 | typedef void (*GfxAppShutdown)(void* app_state); | 23 | typedef void (*GfxAppResize)(GfxAppState*, int width, int height); |
21 | 24 | ||
22 | /// Application callback functions. | 25 | /// Application callback functions. |
23 | typedef struct GfxAppCallbacks { | 26 | typedef struct GfxAppCallbacks { |
24 | GfxAppInit init; | 27 | GfxAppInit init; |
28 | GfxAppShutdown shutdown; | ||
25 | GfxAppUpdate update; | 29 | GfxAppUpdate update; |
26 | GfxAppRender render; | 30 | GfxAppRender render; |
27 | GfxAppResize resize; | 31 | GfxAppResize resize; |
28 | GfxAppShutdown shutdown; | ||
29 | } GfxAppCallbacks; | 32 | } GfxAppCallbacks; |
30 | 33 | ||
31 | typedef enum Key { | 34 | typedef enum Key { |
@@ -68,21 +71,25 @@ bool gfx_is_key_pressed(Key); | |||
68 | 71 | ||
69 | /// Define a main function that initializes and puts the application in a loop. | 72 | /// Define a main function that initializes and puts the application in a loop. |
70 | /// See also: gfx_app_run(). | 73 | /// See also: gfx_app_run(). |
71 | #define GFX_APP_MAIN(WIDTH, HEIGHT, MAX_FPS) \ | 74 | #define GFX_APP_MAIN(WIDTH, HEIGHT, MAX_FPS, TITLE) \ |
72 | int main(int argc, const char** argv) { \ | 75 | int main(int argc, const char** argv) { \ |
73 | gfx_app_run( \ | 76 | GfxAppState app_state = {0}; \ |
74 | &(GfxAppDesc){ \ | 77 | gfx_app_run( \ |
75 | .argc = argc, \ | 78 | &(GfxAppDesc){ \ |
76 | .argv = argv, \ | 79 | .argc = argc, \ |
77 | .width = WIDTH, \ | 80 | .argv = argv, \ |
78 | .height = HEIGHT, \ | 81 | .width = WIDTH, \ |
79 | .max_fps = MAX_FPS, \ | 82 | .height = HEIGHT, \ |
80 | .update_delta_time = MAX_FPS > 0 ? 1.0 / (double)MAX_FPS : 0.0}, \ | 83 | .max_fps = MAX_FPS, \ |
81 | &(GfxAppCallbacks){ \ | 84 | .update_delta_time = MAX_FPS > 0 ? 1.0 / (double)MAX_FPS : 0.0, \ |
82 | .init = (GfxAppInit)app_init, \ | 85 | .title = TITLE, \ |
83 | .update = (GfxAppUpdate)app_update, \ | 86 | .app_state = &app_state, \ |
84 | .render = (GfxAppRender)app_render, \ | 87 | }, \ |
85 | .resize = (GfxAppResize)app_resize, \ | 88 | &(GfxAppCallbacks){ \ |
86 | .shutdown = (GfxAppShutdown)app_end}); \ | 89 | .init = (GfxAppInit)app_init, \ |
87 | return 0; \ | 90 | .update = (GfxAppUpdate)app_update, \ |
91 | .render = (GfxAppRender)app_render, \ | ||
92 | .resize = (GfxAppResize)app_resize, \ | ||
93 | .shutdown = (GfxAppShutdown)app_end}); \ | ||
94 | return 0; \ | ||
88 | } | 95 | } |