diff options
author | 3gg <3gg@shellblade.net> | 2025-08-22 07:59:47 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2025-08-22 07:59:47 -0700 |
commit | 4b340ab0db3898b36a7e975690359eef3747284d (patch) | |
tree | 943f31cd133b9c815992bef7af072bdc90af7bb7 /src/game.c | |
parent | a82c2bbf3f80697b38706d288deecd100ef95a61 (diff) |
Diffstat (limited to 'src/game.c')
-rw-r--r-- | src/game.c | 62 |
1 files changed, 41 insertions, 21 deletions
@@ -44,9 +44,9 @@ static bool init_plugin(Game* game) { | |||
44 | assert(game->plugin); | 44 | assert(game->plugin); |
45 | // Plugin state is allowed to be null, either when the plugin does not | 45 | // Plugin state is allowed to be null, either when the plugin does not |
46 | // expose an init() or when init() does not initialize a state. | 46 | // expose an init() or when init() does not initialize a state. |
47 | if (plugin_resolve(game->plugin, plugin_init, "init")) { | 47 | if (plugin_resolve(game->plugin, PluginInit, "init")) { |
48 | State* plugin_state = 0; | 48 | State* plugin_state = 0; |
49 | if (!plugin_call(game->plugin, plugin_init, "init", game, &plugin_state)) { | 49 | if (!plugin_call(game->plugin, PluginInit, "init", game, &plugin_state)) { |
50 | return false; | 50 | return false; |
51 | } | 51 | } |
52 | set_plugin_state(game->plugin, plugin_state); | 52 | set_plugin_state(game->plugin, plugin_state); |
@@ -59,9 +59,9 @@ static bool init_plugin(Game* game) { | |||
59 | static void shutdown_plugin(Game* game) { | 59 | static void shutdown_plugin(Game* game) { |
60 | assert(game); | 60 | assert(game); |
61 | if (game->plugin && | 61 | if (game->plugin && |
62 | (plugin_resolve(game->plugin, plugin_shutdown, "shutdown"))) { | 62 | (plugin_resolve(game->plugin, PluginShutdown, "shutdown"))) { |
63 | void* plugin_state = get_plugin_state(game->plugin); | 63 | void* plugin_state = get_plugin_state(game->plugin); |
64 | plugin_call(game->plugin, plugin_shutdown, "shutdown", game, plugin_state); | 64 | plugin_call(game->plugin, PluginShutdown, "shutdown", game, plugin_state); |
65 | set_plugin_state(game->plugin, 0); | 65 | set_plugin_state(game->plugin, 0); |
66 | } | 66 | } |
67 | } | 67 | } |
@@ -70,9 +70,9 @@ static void shutdown_plugin(Game* game) { | |||
70 | static bool boot_plugin(Game* game) { | 70 | static bool boot_plugin(Game* game) { |
71 | assert(game); | 71 | assert(game); |
72 | assert(game->plugin); | 72 | assert(game->plugin); |
73 | if (plugin_resolve(game->plugin, plugin_boot, "boot")) { | 73 | if (plugin_resolve(game->plugin, PluginBoot, "boot")) { |
74 | void* plugin_state = get_plugin_state(game->plugin); | 74 | void* plugin_state = get_plugin_state(game->plugin); |
75 | return plugin_call(game->plugin, plugin_boot, "boot", game, plugin_state); | 75 | return plugin_call(game->plugin, PluginBoot, "boot", game, plugin_state); |
76 | } | 76 | } |
77 | return true; // Plugin does not need to expose a boot(). | 77 | return true; // Plugin does not need to expose a boot(). |
78 | } | 78 | } |
@@ -81,10 +81,10 @@ static bool boot_plugin(Game* game) { | |||
81 | static void update_plugin(Game* game, double t, double dt) { | 81 | static void update_plugin(Game* game, double t, double dt) { |
82 | assert(game); | 82 | assert(game); |
83 | assert(game->plugin); | 83 | assert(game->plugin); |
84 | if (plugin_resolve(game->plugin, plugin_update, "update")) { | 84 | if (plugin_resolve(game->plugin, PluginUpdate, "update")) { |
85 | void* plugin_state = get_plugin_state(game->plugin); | 85 | void* plugin_state = get_plugin_state(game->plugin); |
86 | plugin_call( | 86 | plugin_call( |
87 | game->plugin, plugin_update, "update", game, plugin_state, t, dt); | 87 | game->plugin, PluginUpdate, "update", game, plugin_state, t, dt); |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
@@ -92,9 +92,9 @@ static void update_plugin(Game* game, double t, double dt) { | |||
92 | static void render_plugin(const Game* game) { | 92 | static void render_plugin(const Game* game) { |
93 | assert(game); | 93 | assert(game); |
94 | assert(game->plugin); | 94 | assert(game->plugin); |
95 | if (plugin_resolve(game->plugin, plugin_render, "render")) { | 95 | if (plugin_resolve(game->plugin, PluginRender, "render")) { |
96 | void* plugin_state = get_plugin_state(game->plugin); | 96 | void* plugin_state = get_plugin_state(game->plugin); |
97 | plugin_call(game->plugin, plugin_render, "render", game, plugin_state); | 97 | plugin_call(game->plugin, PluginRender, "render", game, plugin_state); |
98 | } | 98 | } |
99 | } | 99 | } |
100 | 100 | ||
@@ -102,24 +102,29 @@ static void render_plugin(const Game* game) { | |||
102 | static void resize_plugin(Game* game, int width, int height) { | 102 | static void resize_plugin(Game* game, int width, int height) { |
103 | assert(game); | 103 | assert(game); |
104 | assert(game->plugin); | 104 | assert(game->plugin); |
105 | if (plugin_resolve(game->plugin, plugin_resize, "resize")) { | 105 | if (plugin_resolve(game->plugin, PluginResize, "resize")) { |
106 | void* plugin_state = get_plugin_state(game->plugin); | 106 | void* plugin_state = get_plugin_state(game->plugin); |
107 | plugin_call( | 107 | plugin_call( |
108 | game->plugin, plugin_resize, "resize", game, plugin_state, width, | 108 | game->plugin, PluginResize, "resize", game, plugin_state, width, |
109 | height); | 109 | height); |
110 | } | 110 | } |
111 | } | 111 | } |
112 | 112 | ||
113 | static void Shutdown(Game* game); | 113 | static void Shutdown(GfxApp* app, GfxAppState* app_state); |
114 | 114 | ||
115 | static bool Init(Game* game, int argc, const char** argv) { | 115 | static bool Init( |
116 | assert(game); | 116 | GfxApp* app, GfxAppState* app_state, int argc, const char** argv) { |
117 | assert(app); | ||
118 | assert(app_state); | ||
117 | 119 | ||
118 | if (argc <= 1) { | 120 | if (argc <= 1) { |
119 | LOGE("Usage: %s <plugin> [plugin args]", argv[0]); | 121 | LOGE("Usage: %s <plugin> [plugin args]", argv[0]); |
120 | return false; | 122 | return false; |
121 | } | 123 | } |
122 | 124 | ||
125 | Game* game = &app_state->game; | ||
126 | game->app = app; | ||
127 | |||
123 | // Syntax: game <plugin> [plugin args] | 128 | // Syntax: game <plugin> [plugin args] |
124 | // | 129 | // |
125 | // Here we consume the <plugin> arg so that plugins receive the remainder | 130 | // Here we consume the <plugin> arg so that plugins receive the remainder |
@@ -165,12 +170,15 @@ static bool Init(Game* game, int argc, const char** argv) { | |||
165 | 170 | ||
166 | cleanup: | 171 | cleanup: |
167 | LOGE("Gfx error: %s", get_error()); | 172 | LOGE("Gfx error: %s", get_error()); |
168 | Shutdown(game); | 173 | Shutdown(app, app_state); |
169 | return false; | 174 | return false; |
170 | } | 175 | } |
171 | 176 | ||
172 | static void Shutdown(Game* game) { | 177 | static void Shutdown(GfxApp* app, GfxAppState* app_state) { |
173 | assert(game); | 178 | assert(app); |
179 | assert(app_state); | ||
180 | Game* game = &app_state->game; | ||
181 | |||
174 | shutdown_plugin(game); | 182 | shutdown_plugin(game); |
175 | if (game->gfx) { | 183 | if (game->gfx) { |
176 | gfx_destroy(&game->gfx); | 184 | gfx_destroy(&game->gfx); |
@@ -183,7 +191,11 @@ static void Shutdown(Game* game) { | |||
183 | } | 191 | } |
184 | } | 192 | } |
185 | 193 | ||
186 | static void Update(Game* game, double t, double dt) { | 194 | static void Update(GfxApp* app, GfxAppState* app_state, double t, double dt) { |
195 | assert(app); | ||
196 | assert(app_state); | ||
197 | Game* game = &app_state->game; | ||
198 | |||
187 | plugin_engine_update(game->plugin_engine); | 199 | plugin_engine_update(game->plugin_engine); |
188 | if (plugin_reloaded(game->plugin)) { | 200 | if (plugin_reloaded(game->plugin)) { |
189 | shutdown_plugin(game); | 201 | shutdown_plugin(game); |
@@ -198,14 +210,22 @@ static void Update(Game* game, double t, double dt) { | |||
198 | update_plugin(game, t, dt); | 210 | update_plugin(game, t, dt); |
199 | } | 211 | } |
200 | 212 | ||
201 | static void Render(const Game* game) { | 213 | static void Render(const GfxApp* app, GfxAppState* app_state) { |
214 | assert(app); | ||
215 | assert(app_state); | ||
216 | Game* game = &app_state->game; | ||
217 | |||
202 | GfxCore* gfxcore = gfx_get_core(game->gfx); | 218 | GfxCore* gfxcore = gfx_get_core(game->gfx); |
203 | gfx_start_frame(gfxcore); | 219 | gfx_start_frame(gfxcore); |
204 | render_plugin(game); | 220 | render_plugin(game); |
205 | gfx_end_frame(gfxcore); | 221 | gfx_end_frame(gfxcore); |
206 | } | 222 | } |
207 | 223 | ||
208 | static void Resize(Game* game, int width, int height) { | 224 | static void Resize(GfxApp* app, GfxAppState* app_state, int width, int height) { |
225 | assert(app); | ||
226 | assert(app_state); | ||
227 | Game* game = &app_state->game; | ||
228 | |||
209 | game->width = width; | 229 | game->width = width; |
210 | game->height = height; | 230 | game->height = height; |
211 | 231 | ||