summaryrefslogtreecommitdiff
path: root/gltfview/src/plugins/plugin.h
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2024-01-19 07:21:45 -0800
committer3gg <3gg@shellblade.net>2024-01-19 07:21:45 -0800
commit4212e57d06afac8a19b09fdebc24bad10b78f1ac (patch)
tree322b2e5cc2764ebd1855565bb8d871d9df33d704 /gltfview/src/plugins/plugin.h
parentfc883e0b0449509ba2e1c5d14d187feee098ab34 (diff)
Plugin refactor, moving scene from game to plugin.
Diffstat (limited to 'gltfview/src/plugins/plugin.h')
-rw-r--r--gltfview/src/plugins/plugin.h59
1 files changed, 31 insertions, 28 deletions
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 @@
1/* 1/*
2 * Game plugin. 2 * Game plugin.
3 *
4 * A game plugin exposes three functions:
5 * - boot(): called once when the plugin is first loaded during the lifetime of
6 * the game.
7 * - init() -> state: creates and returns the plugin's state.
8 * - update(state): takes and updates the state, possibly with side effects.
9 * - render(): performs custom rendering.
10 *
11 * boot() is convenient for one-time initialization of the scene.
12 *
13 * init() is called every time the plugin is loaded. It is assumed that the
14 * plugin's state is encapsulated in the object returned.
15 *
16 * update() updates the plugin state and has side effects on the scene. It is
17 * assumed that update does not reference any global, mutable state outside of
18 * the scene and the plugin state returned by init().
19 */ 3 */
20#pragma once 4#pragma once
21 5
@@ -28,22 +12,41 @@
28 12
29typedef struct State State; 13typedef struct State State;
30 14
31/// Initialize the plugin's state. 15/// Initialize the plugin, which may optionally return a state object.
32State* init(Game*); 16///
17/// This function is called every time the plugin is (re)loaded.
18///
19/// It is assumed that the plugin's state is fully encapsulated in the returned
20/// state object. The plugin should not store any (mutable) state outside of the
21/// returned state object (e.g., no mutable global variables.)
22bool init(Game*, State**);
23
24/// Shut down the plugin.
25///
26/// This function is called before the plugin is unloaded.
27///
28/// The plugin should perform any destruction needed, but not free the state
29/// object; freeing the state object's memory is handled by the caller.
30void shutdown(Game*, State*);
33 31
34/// Function called the first time the plugin is loaded throughout the 32/// Function called the first time the plugin is loaded throughout the
35/// application's lifetime. Allows the plugin to do one-time initialization of 33/// application's lifetime. This allows the plugin to do one-time initialization
36/// the game state. 34/// of the game state.
37bool boot(State*, Game*); 35bool boot(Game*, State*);
38 36
39/// Update the plugin's and the game's state. 37/// Update the plugin's and the game's state.
40void update(State*, Game*, double t, double dt); 38void update(Game*, State*, double t, double dt);
41 39
42/// Optional plugin rendering hook. 40/// Render hook.
43void render(State*, const Game*); 41void render(const Game*, const State*);
42
43/// Called when the game's window is resized.
44void resize(Game* game, State* state, int width, int height);
44 45
45// Signatures for the plugin's exposed functions. 46// Signatures for the plugin's exposed functions.
46typedef void* (*plugin_init)(Game*); 47typedef bool (*plugin_init)(Game*, State**);
47typedef bool (*plugin_boot)(State*, Game*); 48typedef bool (*plugin_shutdown)(Game*, State*);
48typedef void (*plugin_update)(State*, Game*, double t, double dt); 49typedef bool (*plugin_boot)(Game*, State*);
49typedef void (*plugin_render)(State*, const Game*); 50typedef void (*plugin_update)(Game*, State*, double t, double dt);
51typedef void (*plugin_render)(const Game*, const State*);
52typedef void (*plugin_resize)(Game* game, State* state, int width, int height);