Polyphase Game Engine
Loading...
Searching...
No Matches
PolyphasePluginAPI.h
Go to the documentation of this file.
1#pragma once
2
11#include <stdint.h>
12
13// Platform-specific export/import macros.
14// Legacy scaffolds ship with OCTAVE_PLUGIN_EXPORT defined (the pre-rename alias);
15// accept either name here so those projects select dllexport correctly. Without this,
16// the plugin entry point is treated as dllimport and its definition hits C2491.
17#if defined(OCTAVE_PLUGIN_EXPORT) && !defined(POLYPHASE_PLUGIN_EXPORT)
18 #define POLYPHASE_PLUGIN_EXPORT
19#endif
20
21#ifdef _WIN32
22 #ifdef POLYPHASE_PLUGIN_EXPORT
23 #define POLYPHASE_PLUGIN_API __declspec(dllexport)
24 #else
25 #define POLYPHASE_PLUGIN_API __declspec(dllimport)
26 #endif
27#else
28 #define POLYPHASE_PLUGIN_API __attribute__((visibility("default")))
29#endif
30
31// Plugin API version - increment when breaking changes are made
32// v4: added EditorUIHooks::RegisterBuildTarget / UnregisterBuildTarget
33// (ABI-additive; old plugins still load and just don't see the new ptrs)
34// v5: added EditorUIHooks::Viewport_RaycastUnderMouse / Viewport_GetMouseState
35// (ABI-additive; old plugins still load and just don't see the new ptrs)
36// v6: added PolyphaseEngineAPI::EditorAction_Push / _BeginGroup / _EndGroup
37// (ABI-additive; lets native addons push undo-able actions into the
38// editor's ActionManager. Old plugins still load and just don't see the
39// new ptrs.)
40// v7: added EditorUIHooks::ShowOpenFileDialog / ShowSaveFileDialog /
41// ShowSelectFolderDialog (thin wrappers over SYS_*Dialog) and
42// RegisterFileDropHandler / UnregisterFileDropHandler (plugin-side
43// OS file-drop subscription, dispatched alongside the built-in
44// FileDropImportModal). All ABI-additive — appended to the END of
45// the struct. Old plugins still load; new plugins null-check the
46// function pointers before calling for forward/backward compat.
47// v8: added EditorUIHooks::Viewport_GetMouseWorldRay (mouse → world
48// origin/dir for plugin transform gizmos, arbitrary plane
49// intersections, etc) and Viewport_WorldToScreen (project a
50// world-space point into the editor viewport's window-space
51// pixels, for overlaying ImGui labels on top of scene objects).
52// Both ABI-additive at the end of EditorUIHooks.
53#define POLYPHASE_PLUGIN_API_VERSION 8
54
55// Forward declarations
57struct EditorUIHooks;
58struct lua_State;
59
67{
68 // Plugin metadata
69 uint32_t apiVersion; // Must match POLYPHASE_PLUGIN_API_VERSION
70 const char* pluginName; // Human-readable plugin name
71 const char* pluginVersion; // Plugin version string (e.g., "1.0.0")
72
73 // Lifecycle callbacks
74 int (*OnLoad)(PolyphaseEngineAPI* api); // Called when plugin is loaded, return 0 on success
75 void (*OnUnload)(); // Called before plugin is unloaded
76
77 // Tick callbacks (set to nullptr if not needed)
78 void (*Tick)(float deltaTime); // Called during gameplay (PIE or built game)
79 void (*TickEditor)(float deltaTime); // Called in editor regardless of play state (editor builds only)
80
81 // Registration callbacks (called after OnLoad)
82 void (*RegisterTypes)(void* nodeFactory); // Register custom node types
83 void (*RegisterScriptFuncs)(struct lua_State* L); // Register Lua bindings
84
85 // Editor UI extension (editor builds only, set to nullptr for game-only plugins)
86 void (*RegisterEditorUI)(EditorUIHooks* hooks, uint64_t hookId);
87
97 void (*OnEditorPreInit)();
98
108 void (*OnEditorReady)();
109};
110
121
122// Macro for declaring the plugin entry point
123#define POLYPHASE_PLUGIN_ENTRY() \
124 extern "C" POLYPHASE_PLUGIN_API int PolyphasePlugin_GetDesc(PolyphasePluginDesc* outDesc)
125
126// Backwards-compatibility aliases (deprecated, will be removed in a future version)
127#ifndef POLYPHASE_NO_LEGACY_MACROS
128 #define OCTAVE_PLUGIN_API POLYPHASE_PLUGIN_API
129 #ifndef OCTAVE_PLUGIN_EXPORT
130 #define OCTAVE_PLUGIN_EXPORT POLYPHASE_PLUGIN_EXPORT
131 #endif
132 #define OCTAVE_PLUGIN_API_VERSION POLYPHASE_PLUGIN_API_VERSION
133 #define OCTAVE_PLUGIN_ENTRY POLYPHASE_PLUGIN_ENTRY
134 #define OctavePluginDesc PolyphasePluginDesc
135 #define OctavePlugin_GetDescFunc PolyphasePlugin_GetDescFunc
136 #define OctavePlugin_GetDesc PolyphasePlugin_GetDesc
137 #define OctaveEngineAPI PolyphaseEngineAPI
138#endif
int(* PolyphasePlugin_GetDescFunc)(PolyphasePluginDesc *outDesc)
Plugin entry point function signature.
Definition PolyphasePluginAPI.h:120
Engine API provided to plugins during OnLoad.
Definition PolyphaseEngineAPI.h:32
Plugin descriptor returned by PolyphasePlugin_GetDesc.
Definition PolyphasePluginAPI.h:67
void(* TickEditor)(float deltaTime)
Definition PolyphasePluginAPI.h:79
const char * pluginVersion
Definition PolyphasePluginAPI.h:71
const char * pluginName
Definition PolyphasePluginAPI.h:70
uint32_t apiVersion
Definition PolyphasePluginAPI.h:69
void(* RegisterTypes)(void *nodeFactory)
Definition PolyphasePluginAPI.h:82
void(* OnUnload)()
Definition PolyphasePluginAPI.h:75
void(* Tick)(float deltaTime)
Definition PolyphasePluginAPI.h:78
void(* OnEditorPreInit)()
Called before the editor ImGui context is fully initialized.
Definition PolyphasePluginAPI.h:97
void(* RegisterScriptFuncs)(struct lua_State *L)
Definition PolyphasePluginAPI.h:83
void(* RegisterEditorUI)(EditorUIHooks *hooks, uint64_t hookId)
Definition PolyphasePluginAPI.h:86
void(* OnEditorReady)()
Called after the editor is fully initialized, before the main loop starts.
Definition PolyphasePluginAPI.h:108
int(* OnLoad)(PolyphaseEngineAPI *api)
Definition PolyphasePluginAPI.h:74