diff options
Diffstat (limited to 'gltfview/src/plugins/plugin.h')
-rw-r--r-- | gltfview/src/plugins/plugin.h | 59 |
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 | ||
29 | typedef struct State State; | 13 | typedef struct State State; |
30 | 14 | ||
31 | /// Initialize the plugin's state. | 15 | /// Initialize the plugin, which may optionally return a state object. |
32 | State* 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.) | ||
22 | bool 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. | ||
30 | void 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. |
37 | bool boot(State*, Game*); | 35 | bool 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. |
40 | void update(State*, Game*, double t, double dt); | 38 | void update(Game*, State*, double t, double dt); |
41 | 39 | ||
42 | /// Optional plugin rendering hook. | 40 | /// Render hook. |
43 | void render(State*, const Game*); | 41 | void render(const Game*, const State*); |
42 | |||
43 | /// Called when the game's window is resized. | ||
44 | void 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. |
46 | typedef void* (*plugin_init)(Game*); | 47 | typedef bool (*plugin_init)(Game*, State**); |
47 | typedef bool (*plugin_boot)(State*, Game*); | 48 | typedef bool (*plugin_shutdown)(Game*, State*); |
48 | typedef void (*plugin_update)(State*, Game*, double t, double dt); | 49 | typedef bool (*plugin_boot)(Game*, State*); |
49 | typedef void (*plugin_render)(State*, const Game*); | 50 | typedef void (*plugin_update)(Game*, State*, double t, double dt); |
51 | typedef void (*plugin_render)(const Game*, const State*); | ||
52 | typedef void (*plugin_resize)(Game* game, State* state, int width, int height); | ||