diff options
Diffstat (limited to 'gltfview/src/plugins/plugin.h')
-rw-r--r-- | gltfview/src/plugins/plugin.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/gltfview/src/plugins/plugin.h b/gltfview/src/plugins/plugin.h new file mode 100644 index 0000000..0e0e12c --- /dev/null +++ b/gltfview/src/plugins/plugin.h | |||
@@ -0,0 +1,49 @@ | |||
1 | /* | ||
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 | */ | ||
20 | #pragma once | ||
21 | |||
22 | #include "../game.h" | ||
23 | |||
24 | #include <gfx/gfx.h> | ||
25 | #include <gfx/scene.h> | ||
26 | |||
27 | #include <stdbool.h> | ||
28 | |||
29 | typedef struct State State; | ||
30 | |||
31 | /// Initialize the plugin's state. | ||
32 | State* init(Game*); | ||
33 | |||
34 | /// Function called the first time the plugin is loaded throughout the | ||
35 | /// application's lifetime. Allows the plugin to do one-time initialization of | ||
36 | /// the game state. | ||
37 | bool boot(State*, Game*); | ||
38 | |||
39 | /// Update the plugin's and the game's state. | ||
40 | void update(State*, Game*, double t, double dt); | ||
41 | |||
42 | /// Optional plugin rendering hook. | ||
43 | void render(State*, const Game*); | ||
44 | |||
45 | // Signatures for the plugin's exposed functions. | ||
46 | typedef void* (*plugin_init)(Game*); | ||
47 | typedef bool (*plugin_boot)(State*, Game*); | ||
48 | typedef void (*plugin_update)(State*, Game*, double t, double dt); | ||
49 | typedef void (*plugin_render)(State*, const Game*); | ||