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 /game/src | |
parent | 4bc4ca2796bd434880b77d3c4bcbb56107456777 (diff) |
Make isogfx a library instead of an executable.
Diffstat (limited to 'game/src')
-rw-r--r-- | game/src/game.c | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/game/src/game.c b/game/src/game.c index c720656..dc4ab84 100644 --- a/game/src/game.c +++ b/game/src/game.c | |||
@@ -39,6 +39,10 @@ static const int WIDTH = 1350; | |||
39 | static const int HEIGHT = 900; | 39 | static const int HEIGHT = 900; |
40 | static const int MAX_FPS = 60; | 40 | static const int MAX_FPS = 60; |
41 | 41 | ||
42 | typedef struct GfxAppState { | ||
43 | Game game; | ||
44 | } GfxAppState; | ||
45 | |||
42 | /// Initialize the game's plugin. | 46 | /// Initialize the game's plugin. |
43 | static bool init_plugin(Game* game) { | 47 | static bool init_plugin(Game* game) { |
44 | assert(game); | 48 | assert(game); |
@@ -113,17 +117,11 @@ static void resize_plugin(Game* game, int width, int height) { | |||
113 | 117 | ||
114 | void app_end(Game* game); | 118 | void app_end(Game* game); |
115 | 119 | ||
116 | bool app_init(const GfxAppDesc* desc, void** app_state) { | 120 | bool app_init(Game* game, int argc, const char** argv) { |
117 | assert(desc); | 121 | assert(game); |
118 | |||
119 | if (desc->argc <= 1) { | ||
120 | LOGE("Usage: %s <plugin> [plugin args]", desc->argv[0]); | ||
121 | return false; | ||
122 | } | ||
123 | 122 | ||
124 | Game* game = calloc(1, sizeof(Game)); | 123 | if (argc <= 1) { |
125 | if (!game) { | 124 | LOGE("Usage: %s <plugin> [plugin args]", argv[0]); |
126 | LOGE("Failed to allocate game state"); | ||
127 | return false; | 125 | return false; |
128 | } | 126 | } |
129 | 127 | ||
@@ -131,8 +129,8 @@ bool app_init(const GfxAppDesc* desc, void** app_state) { | |||
131 | // | 129 | // |
132 | // 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 |
133 | // args starting from 0. | 131 | // args starting from 0. |
134 | game->argc = desc->argc - 1; | 132 | game->argc = argc - 1; |
135 | game->argv = desc->argv + 1; | 133 | game->argv = argv + 1; |
136 | 134 | ||
137 | char exe_path_buf[NAME_MAX] = {0}; | 135 | char exe_path_buf[NAME_MAX] = {0}; |
138 | if (readlink("/proc/self/exe", exe_path_buf, sizeof(exe_path_buf)) == -1) { | 136 | if (readlink("/proc/self/exe", exe_path_buf, sizeof(exe_path_buf)) == -1) { |
@@ -152,7 +150,7 @@ bool app_init(const GfxAppDesc* desc, void** app_state) { | |||
152 | goto cleanup; | 150 | goto cleanup; |
153 | } | 151 | } |
154 | 152 | ||
155 | const char* plugin = desc->argv[1]; | 153 | const char* plugin = argv[1]; |
156 | if (!(game->plugin = load_plugin(game->plugin_engine, plugin))) { | 154 | if (!(game->plugin = load_plugin(game->plugin_engine, plugin))) { |
157 | goto cleanup; | 155 | goto cleanup; |
158 | } | 156 | } |
@@ -168,7 +166,6 @@ bool app_init(const GfxAppDesc* desc, void** app_state) { | |||
168 | goto cleanup; | 166 | goto cleanup; |
169 | } | 167 | } |
170 | 168 | ||
171 | *app_state = game; | ||
172 | return true; | 169 | return true; |
173 | 170 | ||
174 | cleanup: | 171 | cleanup: |
@@ -223,4 +220,4 @@ void app_resize(Game* game, int width, int height) { | |||
223 | resize_plugin(game, width, height); | 220 | resize_plugin(game, width, height); |
224 | } | 221 | } |
225 | 222 | ||
226 | GFX_APP_MAIN(WIDTH, HEIGHT, MAX_FPS); | 223 | GFX_APP_MAIN(WIDTH, HEIGHT, MAX_FPS, "Game"); |