summaryrefslogtreecommitdiff
path: root/game/src/plugins/plugin.h
blob: f7219c6a1e897c14be71196336bf7416a2729661 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * Game plugin.
 */
#pragma once

#include "../game.h"

#include <gfx/gfx.h>
#include <gfx/scene.h>

#include <stdbool.h>

typedef struct State State;

/// 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. 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(Game*, State*, double t, double dt);

/// Render hook.
void render(const Game*, const State*);

/// Called when the game's window is resized.
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);