From 4b340ab0db3898b36a7e975690359eef3747284d Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Fri, 22 Aug 2025 07:59:47 -0700 Subject: Fix issue with global GfxApp instance across plugins --- src/plugins/plugin.h | 17 ++++++----------- src/plugins/viewer.c | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 19 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/plugin.h b/src/plugins/plugin.h index f7219c6..2831045 100644 --- a/src/plugins/plugin.h +++ b/src/plugins/plugin.h @@ -5,11 +5,6 @@ #include "../game.h" -#include -#include - -#include - typedef struct State State; /// Initialize the plugin, which may optionally return a state object. @@ -44,9 +39,9 @@ void render(const Game*, const State*); void resize(Game*, State*, int width, int height); // Signatures for the plugin's exposed functions. -typedef bool (*plugin_init)(Game*, State**); -typedef bool (*plugin_shutdown)(Game*, State*); -typedef bool (*plugin_boot)(Game*, State*); -typedef void (*plugin_update)(Game*, State*, double t, double dt); -typedef void (*plugin_render)(const Game*, const State*); -typedef void (*plugin_resize)(Game* game, State* state, int width, int height); +typedef bool (*PluginInit)(Game*, State**); +typedef bool (*PluginShutdown)(Game*, State*); +typedef bool (*PluginBoot)(Game*, State*); +typedef void (*PluginUpdate)(Game*, State*, double t, double dt); +typedef void (*PluginRender)(const Game*, const State*); +typedef void (*PluginResize)(Game* game, State* state, int width, int height); diff --git a/src/plugins/viewer.c b/src/plugins/viewer.c index 97c718e..83c7320 100644 --- a/src/plugins/viewer.c +++ b/src/plugins/viewer.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -204,13 +205,13 @@ void shutdown(Game* game, State* state) { } } -static CameraCommand make_camera_command_from_input() { +static CameraCommand make_camera_command_from_input(GfxApp* app) { return (CameraCommand){ - .CameraMoveLeft = gfx_app_is_key_pressed(KeyA), - .CameraMoveRight = gfx_app_is_key_pressed(KeyD), - .CameraMoveForward = gfx_app_is_key_pressed(KeyW), - .CameraMoveBackward = gfx_app_is_key_pressed(KeyS), - .CameraIsRotating = gfx_app_is_mouse_button_pressed(LMB), + .CameraMoveLeft = gfx_app_is_key_pressed(app, KeyA), + .CameraMoveRight = gfx_app_is_key_pressed(app, KeyD), + .CameraMoveForward = gfx_app_is_key_pressed(app, KeyW), + .CameraMoveBackward = gfx_app_is_key_pressed(app, KeyS), + .CameraIsRotating = gfx_app_is_mouse_button_pressed(app, LMB), }; } @@ -248,15 +249,17 @@ static void update_camera( void update(Game* game, State* state, double t, double dt) { assert(game); + assert(game->app); assert(state); assert(state->scene); assert(state->camera); double mouse_x, mouse_y; - gfx_app_get_mouse_position(&mouse_x, &mouse_y); + gfx_app_get_mouse_position(game->app, &mouse_x, &mouse_y); const vec2 mouse_position = {(R)mouse_x, (R)mouse_y}; - const CameraCommand camera_command = make_camera_command_from_input(); + const CameraCommand camera_command = + make_camera_command_from_input(game->app); update_camera( &state->camera_controller, (R)dt, mouse_position, camera_command, &gfx_get_camera_camera(state->camera)->spatial); -- cgit v1.2.3