Polyphase Game Engine
Loading...
Searching...
No Matches
PolyphaseEngineAPI.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdint.h>
4#include <stddef.h>
5
14struct lua_State;
15struct EditorUIHooks;
16struct ImGuiPluginContext;
17
18// Forward declarations for engine types
19class Node;
20class Node3D;
21class World;
22class Asset;
23class SoundWave;
24
32{
33 // ===== Logging =====
34
39 void (*LogDebug)(const char* fmt, ...);
40
45 void (*LogWarning)(const char* fmt, ...);
46
51 void (*LogError)(const char* fmt, ...);
52
53 // ===== Lua Access =====
54
59 lua_State* (*GetLua)();
60
61 // ===== Lua Wrappers =====
62 // These wrap Lua C API functions so plugins don't need to link against Lua.
63 // Names use "Lua_" prefix to avoid conflicts with Lua macros.
64 // Example: Use sEngineAPI->Lua_pushnumber() instead of lua_pushnumber()
65
66 // Stack manipulation
67 void (*Lua_settop)(lua_State* L, int idx);
68 void (*Lua_pushvalue)(lua_State* L, int idx);
69 void (*Lua_pop)(lua_State* L, int n);
70 int (*Lua_gettop)(lua_State* L);
71
72 // Type checking
73 int (*Lua_type)(lua_State* L, int idx);
74 int (*Lua_isfunction)(lua_State* L, int idx);
75 int (*Lua_istable)(lua_State* L, int idx);
76 int (*Lua_isuserdata)(lua_State* L, int idx);
77 int (*Lua_isnil)(lua_State* L, int idx);
78
79 // Get values
80 int (*Lua_toboolean)(lua_State* L, int idx);
81 double (*Lua_tonumber)(lua_State* L, int idx);
82 const char* (*Lua_tostring)(lua_State* L, int idx);
83 void* (*Lua_touserdata)(lua_State* L, int idx);
84
85 // Push values
86 void (*Lua_pushnil)(lua_State* L);
87 void (*Lua_pushboolean)(lua_State* L, int b);
88 void (*Lua_pushnumber)(lua_State* L, double n);
89 void (*Lua_pushstring)(lua_State* L, const char* s);
90 void (*Lua_pushinteger)(lua_State* L, long long n);
91
92 // Userdata
93 void* (*Lua_newuserdata)(lua_State* L, size_t sz);
94
95 // Tables and fields
96 void (*Lua_createtable)(lua_State* L, int narr, int nrec);
97 void (*Lua_setfield)(lua_State* L, int idx, const char* k);
98 void (*Lua_getfield)(lua_State* L, int idx, const char* k);
99 void (*Lua_setglobal)(lua_State* L, const char* name);
100 void (*Lua_getglobal)(lua_State* L, const char* name);
101 void (*Lua_rawset)(lua_State* L, int idx);
102 void (*Lua_rawget)(lua_State* L, int idx);
103 void (*Lua_settable)(lua_State* L, int idx);
104 void (*Lua_gettable)(lua_State* L, int idx);
105
106 // Metatables
107 int (*Lua_setmetatable)(lua_State* L, int objindex);
108 int (*Lua_getmetatable)(lua_State* L, int objindex);
109
110 // Auxiliary library functions (LuaL_ prefix to avoid macro conflicts)
111 int (*LuaL_newmetatable)(lua_State* L, const char* tname);
112 void (*LuaL_setmetatable)(lua_State* L, const char* tname);
113 void* (*LuaL_checkudata)(lua_State* L, int ud, const char* tname);
114 double (*LuaL_checknumber)(lua_State* L, int arg);
115 long long (*LuaL_checkinteger)(lua_State* L, int arg);
116 const char* (*LuaL_checkstring)(lua_State* L, int arg);
117 void (*LuaL_setfuncs)(lua_State* L, const void* l, int nup); // luaL_Reg*
118 void (*LuaL_getmetatable)(lua_State* L, const char* tname);
119
120 // ===== World Management =====
121
127 World* (*GetWorld)(int32_t index);
128
133 int32_t (*GetNumWorlds)();
134
135 // ===== Node Operations =====
136
143 Node* (*SpawnNode)(World* world, const char* typeName);
144
149 void (*DestroyNode)(Node* node);
150
157 Node* (*FindNode)(World* world, const char* name);
158
159 // ===== Node3D Operations =====
160
168 void (*Node3D_GetRotation)(Node3D* node, float* outX, float* outY, float* outZ);
169
177 void (*Node3D_SetRotation)(Node3D* node, float x, float y, float z);
178
186 void (*Node3D_AddRotation)(Node3D* node, float x, float y, float z);
187
195 void (*Node3D_GetPosition)(Node3D* node, float* outX, float* outY, float* outZ);
196
204 void (*Node3D_SetPosition)(Node3D* node, float x, float y, float z);
205
213 void (*Node3D_GetScale)(Node3D* node, float* outX, float* outY, float* outZ);
214
222 void (*Node3D_SetScale)(Node3D* node, float x, float y, float z);
223
224 // ===== Asset System =====
225
231 Asset* (*LoadAsset)(const char* name);
232
238 Asset* (*FetchAsset)(const char* name);
239
244 void (*UnloadAsset)(const char* name);
245
246 // ===== TinyLLM =====
247
258 int32_t (*TinyLLM_Encode)(Asset* model, const char* text, bool addBos, bool addEos,
259 int32_t* outTokens, int32_t maxTokens);
260
270 int32_t (*TinyLLM_Decode)(Asset* model, int32_t prevToken, int32_t token,
271 char* outStr, int32_t maxLen);
272
273 // ===== Audio =====
274
281 void (*PlaySound2D)(SoundWave* sound, float volume, float pitch);
282
286 void (*StopAllSounds)();
287
292 void (*SetMasterVolume)(float volume);
293
298 float (*GetMasterVolume)();
299
300 // ===== Streaming audio =====
301 //
302 // Push-based PCM output for addons that decode audio at runtime (e.g. VideoPlayer).
303 // See Audio.h for the underlying AUD_* primitives; these are thin forwarders so addons
304 // don't have to link the engine's audio symbols directly.
305 //
306 // Not implemented on all platforms — Audio_OpenStream returns 0 on Linux / 3DS / Android /
307 // Dolphin, and addons must treat 0 as "streaming audio unavailable; play video-only".
308
309 uint32_t (*Audio_OpenStream)(uint32_t sampleRate, uint32_t numChannels, uint32_t bitsPerSample);
310 void (*Audio_CloseStream)(uint32_t streamId);
311 int32_t (*Audio_SubmitStreamBuffer)(uint32_t streamId, const uint8_t* data, uint32_t byteSize);
312 uint64_t (*Audio_GetStreamPlayedSamples)(uint32_t streamId);
313 void (*Audio_SetStreamVolume)(uint32_t streamId, float volume);
314 void (*Audio_SetStreamPaused)(uint32_t streamId, bool paused);
315 // Discard any queued buffers without waiting for playback to finish. Use on seek/loop
316 // so stale audio doesn't keep playing while new decoded audio catches up.
317 // SamplesPlayed does NOT reset (XAudio2 limitation); the addon is expected to snapshot
318 // it right after Flush and treat subsequent readings as deltas.
319 void (*Audio_FlushStream)(uint32_t streamId);
320
321 // ===== Input =====
322
328 bool (*IsKeyDown)(int32_t key);
329
335 bool (*IsKeyJustPressed)(int32_t key);
336
342 bool (*IsKeyJustReleased)(int32_t key);
343
349 bool (*IsMouseButtonDown)(int32_t button);
350
356 bool (*IsMouseButtonJustPressed)(int32_t button);
357
363 void (*GetMousePosition)(int32_t* x, int32_t* y);
364
370 void (*GetMouseDelta)(int32_t* deltaX, int32_t* deltaY);
371
377
378 // ===== Time =====
379
384 float (*GetDeltaTime)();
385
390 float (*GetElapsedTime)();
391
392 // ===== Gizmos =====
393
401 void (*Gizmos_SetColor)(float r, float g, float b, float a);
402
407 void (*Gizmos_SetMatrix)(const float* matrix16);
408
413
423 void (*Gizmos_DrawCube)(float cx, float cy, float cz, float sx, float sy, float sz);
424
428 void (*Gizmos_DrawWireCube)(float cx, float cy, float cz, float sx, float sy, float sz);
429
437 void (*Gizmos_DrawSphere)(float cx, float cy, float cz, float radius);
438
442 void (*Gizmos_DrawWireSphere)(float cx, float cy, float cz, float radius);
443
453 void (*Gizmos_DrawLine)(float x0, float y0, float z0, float x1, float y1, float z1);
454
464 void (*Gizmos_DrawRay)(float ox, float oy, float oz, float dx, float dy, float dz);
465
466 // ===== Editor UI Hooks (Editor builds only) =====
467
474 EditorUIHooks* editorUI;
475
484 void (*GetImGuiContext)(ImGuiPluginContext* outCtx);
485};
Definition Asset.h:113
Definition Node3d.h:14
Definition Node.h:67
Definition SoundWave.h:6
Definition World.h:24
Engine API provided to plugins during OnLoad.
Definition PolyphaseEngineAPI.h:32
void(* LuaL_setfuncs)(lua_State *L, const void *l, int nup)
Definition PolyphaseEngineAPI.h:117
void(* Node3D_SetScale)(Node3D *node, float x, float y, float z)
Set the local scale of a Node3D.
Definition PolyphaseEngineAPI.h:222
void(* Lua_pushnil)(lua_State *L)
Definition PolyphaseEngineAPI.h:86
void(* Lua_pushstring)(lua_State *L, const char *s)
Definition PolyphaseEngineAPI.h:89
uint32_t(* Audio_OpenStream)(uint32_t sampleRate, uint32_t numChannels, uint32_t bitsPerSample)
Definition PolyphaseEngineAPI.h:309
void(* Node3D_AddRotation)(Node3D *node, float x, float y, float z)
Add rotation to a Node3D in euler angles (degrees).
Definition PolyphaseEngineAPI.h:186
void(* Gizmos_DrawRay)(float ox, float oy, float oz, float dx, float dy, float dz)
Draw a ray gizmo (from origin along direction).
Definition PolyphaseEngineAPI.h:464
void(* Node3D_SetPosition)(Node3D *node, float x, float y, float z)
Set the local position of a Node3D.
Definition PolyphaseEngineAPI.h:204
void(* Node3D_GetRotation)(Node3D *node, float *outX, float *outY, float *outZ)
Get the local rotation of a Node3D in euler angles (degrees).
Definition PolyphaseEngineAPI.h:168
int32_t(* Audio_SubmitStreamBuffer)(uint32_t streamId, const uint8_t *data, uint32_t byteSize)
Definition PolyphaseEngineAPI.h:311
int(* Lua_isfunction)(lua_State *L, int idx)
Definition PolyphaseEngineAPI.h:74
void(* Lua_setfield)(lua_State *L, int idx, const char *k)
Definition PolyphaseEngineAPI.h:97
int(* Lua_getmetatable)(lua_State *L, int objindex)
Definition PolyphaseEngineAPI.h:108
void(* Gizmos_DrawWireSphere)(float cx, float cy, float cz, float radius)
Draw a wireframe sphere gizmo.
Definition PolyphaseEngineAPI.h:442
void(* Lua_rawget)(lua_State *L, int idx)
Definition PolyphaseEngineAPI.h:102
bool(* IsMouseButtonJustPressed)(int32_t button)
Check if a mouse button was just pressed this frame.
Definition PolyphaseEngineAPI.h:356
void(* Lua_pop)(lua_State *L, int n)
Definition PolyphaseEngineAPI.h:69
void(* Lua_settable)(lua_State *L, int idx)
Definition PolyphaseEngineAPI.h:103
void(* Node3D_GetPosition)(Node3D *node, float *outX, float *outY, float *outZ)
Get the local position of a Node3D.
Definition PolyphaseEngineAPI.h:195
double(* Lua_tonumber)(lua_State *L, int idx)
Definition PolyphaseEngineAPI.h:81
void(* Lua_gettable)(lua_State *L, int idx)
Definition PolyphaseEngineAPI.h:104
int(* Lua_toboolean)(lua_State *L, int idx)
Definition PolyphaseEngineAPI.h:80
void(* Lua_rawset)(lua_State *L, int idx)
Definition PolyphaseEngineAPI.h:101
void(* PlaySound2D)(SoundWave *sound, float volume, float pitch)
Play a 2D sound (non-positional).
Definition PolyphaseEngineAPI.h:281
void(* Audio_SetStreamVolume)(uint32_t streamId, float volume)
Definition PolyphaseEngineAPI.h:313
float(* GetDeltaTime)()
Get the time elapsed since last frame (in seconds).
Definition PolyphaseEngineAPI.h:384
void(* Node3D_GetScale)(Node3D *node, float *outX, float *outY, float *outZ)
Get the local scale of a Node3D.
Definition PolyphaseEngineAPI.h:213
int32_t(* GetNumWorlds)()
Get the number of active worlds.
Definition PolyphaseEngineAPI.h:133
int(* Lua_istable)(lua_State *L, int idx)
Definition PolyphaseEngineAPI.h:75
void(* Audio_FlushStream)(uint32_t streamId)
Definition PolyphaseEngineAPI.h:319
uint64_t(* Audio_GetStreamPlayedSamples)(uint32_t streamId)
Definition PolyphaseEngineAPI.h:312
int(* Lua_setmetatable)(lua_State *L, int objindex)
Definition PolyphaseEngineAPI.h:107
void(* GetMousePosition)(int32_t *x, int32_t *y)
Get the current mouse position.
Definition PolyphaseEngineAPI.h:363
void(* LogError)(const char *fmt,...)
Log an error message.
Definition PolyphaseEngineAPI.h:51
void(* Gizmos_ResetState)()
Reset gizmo state to default (white color, identity matrix).
Definition PolyphaseEngineAPI.h:412
long long(* LuaL_checkinteger)(lua_State *L, int arg)
Definition PolyphaseEngineAPI.h:115
void(* Lua_pushnumber)(lua_State *L, double n)
Definition PolyphaseEngineAPI.h:88
void(* UnloadAsset)(const char *name)
Unload an asset by name.
Definition PolyphaseEngineAPI.h:244
void(* DestroyNode)(Node *node)
Destroy a node.
Definition PolyphaseEngineAPI.h:149
int(* Lua_gettop)(lua_State *L)
Definition PolyphaseEngineAPI.h:70
void(* Gizmos_DrawCube)(float cx, float cy, float cz, float sx, float sy, float sz)
Draw a solid cube gizmo.
Definition PolyphaseEngineAPI.h:423
void(* GetImGuiContext)(ImGuiPluginContext *outCtx)
Get ImGui context for plugin use (Editor builds only).
Definition PolyphaseEngineAPI.h:484
void(* LuaL_getmetatable)(lua_State *L, const char *tname)
Definition PolyphaseEngineAPI.h:118
int(* Lua_isnil)(lua_State *L, int idx)
Definition PolyphaseEngineAPI.h:77
void(* Gizmos_DrawLine)(float x0, float y0, float z0, float x1, float y1, float z1)
Draw a line gizmo.
Definition PolyphaseEngineAPI.h:453
float(* GetElapsedTime)()
Get the total time elapsed since engine start (in seconds).
Definition PolyphaseEngineAPI.h:390
void(* Audio_SetStreamPaused)(uint32_t streamId, bool paused)
Definition PolyphaseEngineAPI.h:314
void(* LogDebug)(const char *fmt,...)
Log a debug message.
Definition PolyphaseEngineAPI.h:39
void(* StopAllSounds)()
Stop all currently playing sounds.
Definition PolyphaseEngineAPI.h:286
EditorUIHooks * editorUI
Pointer to editor UI hooks struct.
Definition PolyphaseEngineAPI.h:474
bool(* IsKeyDown)(int32_t key)
Check if a key is currently held down.
Definition PolyphaseEngineAPI.h:328
void(* Node3D_SetRotation)(Node3D *node, float x, float y, float z)
Set the local rotation of a Node3D in euler angles (degrees).
Definition PolyphaseEngineAPI.h:177
int(* Lua_type)(lua_State *L, int idx)
Definition PolyphaseEngineAPI.h:73
bool(* IsKeyJustPressed)(int32_t key)
Check if a key was just pressed this frame.
Definition PolyphaseEngineAPI.h:335
float(* GetMasterVolume)()
Get the master audio volume.
Definition PolyphaseEngineAPI.h:298
void(* Lua_pushboolean)(lua_State *L, int b)
Definition PolyphaseEngineAPI.h:87
void(* Lua_setglobal)(lua_State *L, const char *name)
Definition PolyphaseEngineAPI.h:99
bool(* IsKeyJustReleased)(int32_t key)
Check if a key was just released this frame.
Definition PolyphaseEngineAPI.h:342
void(* LogWarning)(const char *fmt,...)
Log a warning message.
Definition PolyphaseEngineAPI.h:45
void(* LuaL_setmetatable)(lua_State *L, const char *tname)
Definition PolyphaseEngineAPI.h:112
void(* SetMasterVolume)(float volume)
Set the master audio volume.
Definition PolyphaseEngineAPI.h:292
double(* LuaL_checknumber)(lua_State *L, int arg)
Definition PolyphaseEngineAPI.h:114
void(* Gizmos_SetMatrix)(const float *matrix16)
Set the gizmo transformation matrix (column-major, 16 floats).
Definition PolyphaseEngineAPI.h:407
int32_t(* GetScrollWheelDelta)()
Get the scroll wheel delta.
Definition PolyphaseEngineAPI.h:376
void(* Lua_settop)(lua_State *L, int idx)
Definition PolyphaseEngineAPI.h:67
void(* Lua_getglobal)(lua_State *L, const char *name)
Definition PolyphaseEngineAPI.h:100
void(* Lua_pushvalue)(lua_State *L, int idx)
Definition PolyphaseEngineAPI.h:68
int(* LuaL_newmetatable)(lua_State *L, const char *tname)
Definition PolyphaseEngineAPI.h:111
void(* GetMouseDelta)(int32_t *deltaX, int32_t *deltaY)
Get the mouse movement since last frame.
Definition PolyphaseEngineAPI.h:370
int(* Lua_isuserdata)(lua_State *L, int idx)
Definition PolyphaseEngineAPI.h:76
void(* Lua_getfield)(lua_State *L, int idx, const char *k)
Definition PolyphaseEngineAPI.h:98
void(* Audio_CloseStream)(uint32_t streamId)
Definition PolyphaseEngineAPI.h:310
void(* Lua_pushinteger)(lua_State *L, long long n)
Definition PolyphaseEngineAPI.h:90
void(* Gizmos_SetColor)(float r, float g, float b, float a)
Set the gizmo drawing color.
Definition PolyphaseEngineAPI.h:401
void(* Gizmos_DrawSphere)(float cx, float cy, float cz, float radius)
Draw a solid sphere gizmo.
Definition PolyphaseEngineAPI.h:437
int32_t(* TinyLLM_Encode)(Asset *model, const char *text, bool addBos, bool addEos, int32_t *outTokens, int32_t maxTokens)
Encode text to tokens using a TinyLLMAsset's tokenizer.
Definition PolyphaseEngineAPI.h:258
int32_t(* TinyLLM_Decode)(Asset *model, int32_t prevToken, int32_t token, char *outStr, int32_t maxLen)
Decode a token to string using a TinyLLMAsset's tokenizer.
Definition PolyphaseEngineAPI.h:270
bool(* IsMouseButtonDown)(int32_t button)
Check if a mouse button is currently held down.
Definition PolyphaseEngineAPI.h:349
void(* Lua_createtable)(lua_State *L, int narr, int nrec)
Definition PolyphaseEngineAPI.h:96
void(* Gizmos_DrawWireCube)(float cx, float cy, float cz, float sx, float sy, float sz)
Draw a wireframe cube gizmo.
Definition PolyphaseEngineAPI.h:428