summaryrefslogtreecommitdiff
path: root/gfx-app/include
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2024-03-09 08:43:26 -0800
committer3gg <3gg@shellblade.net>2024-03-09 08:43:26 -0800
commitadbd2511beec8f1caa1752bdfd755cc2f62ba425 (patch)
tree8fde167e9d9951b43e571a2417ae55f9572bea28 /gfx-app/include
parent4bc4ca2796bd434880b77d3c4bcbb56107456777 (diff)
Make isogfx a library instead of an executable.
Diffstat (limited to 'gfx-app/include')
-rw-r--r--gfx-app/include/gfx/gfx_app.h53
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
5typedef struct GfxAppState GfxAppState;
6
5/// Application settings. 7/// Application settings.
6typedef struct GfxAppDesc { 8typedef 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
16typedef bool (*GfxAppInit)(const GfxAppDesc*, void** app_state); 19typedef bool (*GfxAppInit)(GfxAppState*, int argc, const char** argv);
17typedef void (*GfxAppUpdate)(void* app_state, double t, double dt); 20typedef void (*GfxAppShutdown)(GfxAppState*);
18typedef void (*GfxAppRender)(void* app_state); 21typedef void (*GfxAppUpdate)(GfxAppState*, double t, double dt);
19typedef void (*GfxAppResize)(void* app_state, int width, int height); 22typedef void (*GfxAppRender)(GfxAppState*);
20typedef void (*GfxAppShutdown)(void* app_state); 23typedef void (*GfxAppResize)(GfxAppState*, int width, int height);
21 24
22/// Application callback functions. 25/// Application callback functions.
23typedef struct GfxAppCallbacks { 26typedef 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
31typedef enum Key { 34typedef 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 }