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// v9: added EditorUIHooks::EditorImage_Load / EditorImage_GetSize /
54// EditorImage_Invalidate — an engine-owned, path-keyed image → ImGui
55// texture cache. Lets addons show thumbnails without linking class
56// Image / DestroyQueue / GetDestroyQueue / DeviceWaitIdle, none of
57// which are exported from Polyphase.lib. Also annotated
58// GFX_GetVulkanAddonHandles with POLYPHASE_API so addons that drive
59// their own Vulkan passes can actually link it (declaration-only
60// change; no ABI impact). ABI-additive at the end of EditorUIHooks.
61#define POLYPHASE_PLUGIN_API_VERSION 9
62
63// Forward declarations
65struct EditorUIHooks;
66struct lua_State;
67
75{
76 // Plugin metadata
77 uint32_t apiVersion; // Must match POLYPHASE_PLUGIN_API_VERSION
78 const char* pluginName; // Human-readable plugin name
79 const char* pluginVersion; // Plugin version string (e.g., "1.0.0")
80
81 // Lifecycle callbacks
82 int (*OnLoad)(PolyphaseEngineAPI* api); // Called when plugin is loaded, return 0 on success
83 void (*OnUnload)(); // Called before plugin is unloaded
84
85 // Tick callbacks (set to nullptr if not needed)
86 void (*Tick)(float deltaTime); // Called during gameplay (PIE or built game)
87 void (*TickEditor)(float deltaTime); // Called in editor regardless of play state (editor builds only)
88
89 // Registration callbacks (called after OnLoad)
90 void (*RegisterTypes)(void* nodeFactory); // Register custom node types
91 void (*RegisterScriptFuncs)(struct lua_State* L); // Register Lua bindings
92
93 // Editor UI extension (editor builds only, set to nullptr for game-only plugins)
94 void (*RegisterEditorUI)(EditorUIHooks* hooks, uint64_t hookId);
95
106
116 void (*OnEditorReady)();
117};
118
129
130// Macro for declaring the plugin entry point
131#define POLYPHASE_PLUGIN_ENTRY() \
132 extern "C" POLYPHASE_PLUGIN_API int PolyphasePlugin_GetDesc(PolyphasePluginDesc* outDesc)
133
134// Backwards-compatibility aliases (deprecated, will be removed in a future version)
135#ifndef POLYPHASE_NO_LEGACY_MACROS
136 #define OCTAVE_PLUGIN_API POLYPHASE_PLUGIN_API
137 #ifndef OCTAVE_PLUGIN_EXPORT
138 #define OCTAVE_PLUGIN_EXPORT POLYPHASE_PLUGIN_EXPORT
139 #endif
140 #define OCTAVE_PLUGIN_API_VERSION POLYPHASE_PLUGIN_API_VERSION
141 #define OCTAVE_PLUGIN_ENTRY POLYPHASE_PLUGIN_ENTRY
142 #define OctavePluginDesc PolyphasePluginDesc
143 #define OctavePlugin_GetDescFunc PolyphasePlugin_GetDescFunc
144 #define OctavePlugin_GetDesc PolyphasePlugin_GetDesc
145 #define OctaveEngineAPI PolyphaseEngineAPI
146#endif
int(* PolyphasePlugin_GetDescFunc)(PolyphasePluginDesc *outDesc)
Plugin entry point function signature.
Definition PolyphasePluginAPI.h:128
Engine API provided to plugins during OnLoad.
Definition PolyphaseEngineAPI.h:32
Plugin descriptor returned by PolyphasePlugin_GetDesc.
Definition PolyphasePluginAPI.h:75
void(* TickEditor)(float deltaTime)
Definition PolyphasePluginAPI.h:87
const char * pluginVersion
Definition PolyphasePluginAPI.h:79
const char * pluginName
Definition PolyphasePluginAPI.h:78
uint32_t apiVersion
Definition PolyphasePluginAPI.h:77
void(* RegisterTypes)(void *nodeFactory)
Definition PolyphasePluginAPI.h:90
void(* OnUnload)()
Definition PolyphasePluginAPI.h:83
void(* Tick)(float deltaTime)
Definition PolyphasePluginAPI.h:86
void(* OnEditorPreInit)()
Called before the editor ImGui context is fully initialized.
Definition PolyphasePluginAPI.h:105
void(* RegisterScriptFuncs)(struct lua_State *L)
Definition PolyphasePluginAPI.h:91
void(* RegisterEditorUI)(EditorUIHooks *hooks, uint64_t hookId)
Definition PolyphasePluginAPI.h:94
void(* OnEditorReady)()
Called after the editor is fully initialized, before the main loop starts.
Definition PolyphasePluginAPI.h:116
int(* OnLoad)(PolyphaseEngineAPI *api)
Definition PolyphasePluginAPI.h:82