From 4212e57d06afac8a19b09fdebc24bad10b78f1ac Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Fri, 19 Jan 2024 07:21:45 -0800 Subject: Plugin refactor, moving scene from game to plugin. --- gltfview/src/plugins/plugin.h | 59 +++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 28 deletions(-) (limited to 'gltfview/src/plugins/plugin.h') diff --git a/gltfview/src/plugins/plugin.h b/gltfview/src/plugins/plugin.h index 0e0e12c..a2632cd 100644 --- a/gltfview/src/plugins/plugin.h +++ b/gltfview/src/plugins/plugin.h @@ -1,21 +1,5 @@ /* * Game plugin. - * - * A game plugin exposes three functions: - * - boot(): called once when the plugin is first loaded during the lifetime of - * the game. - * - init() -> state: creates and returns the plugin's state. - * - update(state): takes and updates the state, possibly with side effects. - * - render(): performs custom rendering. - * - * boot() is convenient for one-time initialization of the scene. - * - * init() is called every time the plugin is loaded. It is assumed that the - * plugin's state is encapsulated in the object returned. - * - * update() updates the plugin state and has side effects on the scene. It is - * assumed that update does not reference any global, mutable state outside of - * the scene and the plugin state returned by init(). */ #pragma once @@ -28,22 +12,41 @@ typedef struct State State; -/// Initialize the plugin's state. -State* init(Game*); +/// Initialize the plugin, which may optionally return a state object. +/// +/// This function is called every time the plugin is (re)loaded. +/// +/// It is assumed that the plugin's state is fully encapsulated in the returned +/// state object. The plugin should not store any (mutable) state outside of the +/// returned state object (e.g., no mutable global variables.) +bool init(Game*, State**); + +/// Shut down the plugin. +/// +/// This function is called before the plugin is unloaded. +/// +/// The plugin should perform any destruction needed, but not free the state +/// object; freeing the state object's memory is handled by the caller. +void shutdown(Game*, State*); /// Function called the first time the plugin is loaded throughout the -/// application's lifetime. Allows the plugin to do one-time initialization of -/// the game state. -bool boot(State*, Game*); +/// application's lifetime. This allows the plugin to do one-time initialization +/// of the game state. +bool boot(Game*, State*); /// Update the plugin's and the game's state. -void update(State*, Game*, double t, double dt); +void update(Game*, State*, double t, double dt); -/// Optional plugin rendering hook. -void render(State*, const Game*); +/// Render hook. +void render(const Game*, const State*); + +/// Called when the game's window is resized. +void resize(Game* game, State* state, int width, int height); // Signatures for the plugin's exposed functions. -typedef void* (*plugin_init)(Game*); -typedef bool (*plugin_boot)(State*, Game*); -typedef void (*plugin_update)(State*, Game*, double t, double dt); -typedef void (*plugin_render)(State*, const Game*); +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); -- cgit v1.2.3