From 520e4e67cd9ff53f3c3512c80d07193625e07e3e Mon Sep 17 00:00:00 2001
From: 3gg <3gg@shellblade.net>
Date: Fri, 16 Jun 2023 09:38:15 -0700
Subject: New plugin architecture.

---
 gltfview/src/plugins/plugin.h | 49 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 gltfview/src/plugins/plugin.h

(limited to 'gltfview/src/plugins/plugin.h')

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 @@
+/*
+ * 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
+
+#include "../game.h"
+
+#include <gfx/gfx.h>
+#include <gfx/scene.h>
+
+#include <stdbool.h>
+
+typedef struct State State;
+
+/// Initialize the plugin's state.
+State* init(Game*);
+
+/// 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*);
+
+/// Update the plugin's and the game's state.
+void update(State*, Game*, double t, double dt);
+
+/// Optional plugin rendering hook.
+void render(State*, const Game*);
+
+// 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*);
-- 
cgit v1.2.3