Polyphase Game Engine
Loading...
Searching...
No Matches
PolyphaseBuildTargetAPI.h
Go to the documentation of this file.
1#pragma once
2
24#include <stdint.h>
25#include <stddef.h>
26
27#if EDITOR
28
30#define POLYPHASE_BUILD_TARGET_API_VERSION 1
31
32/* ===== Forward-declared opaque pointers ================================== */
33/* Addons receive these as void* and pass them back unchanged; the engine
34 * downcasts. Keeping them opaque keeps the ABI independent of engine STL. */
35typedef struct PolyphaseBuildTargetDesc PolyphaseBuildTargetDesc;
36typedef struct PolyphaseBuildContext PolyphaseBuildContext;
37
38/* ===== Severity values forwarded to Log() trampoline ===================== */
39/* Match LogSeverity in SystemTypes.h. */
40#define POLYPHASE_BT_LOG_DEBUG 0
41#define POLYPHASE_BT_LOG_WARNING 1
42#define POLYPHASE_BT_LOG_ERROR 2
43
44/* ===== Build context passed to every callback ============================ */
45/*
46 * Lifetime: valid for the duration of a single callback invocation only.
47 * Do not store the pointer or any of its const char* fields past the call
48 * — the engine reuses the memory for subsequent callbacks.
49 */
50struct PolyphaseBuildContext
51{
52 uint32_t structVersion; /* equals POLYPHASE_BUILD_TARGET_API_VERSION at call time */
53
54 /* Identity */
55 const char* targetId; /* the targetId you registered with */
56 const char* projectName; /* logical project name (e.g. "MyGame") */
57 const char* projectDir; /* absolute path to project root */
58 const char* packageOutputDir; /* Packaged/<targetId>/ — engine creates this */
59 const char* engineDir; /* absolute path to engine root */
60 const char* compiledBinaryDir; /* hint: where the engine expects your toolchain output */
61
62 /* Cooking compatibility */
63 int32_t basePlatform; /* Platform enum value (Windows/Linux/etc.) for asset cook fallback */
64
65 /* Build settings */
66 int32_t embedded; /* non-zero if assets are embedded in the binary */
67 int32_t runAfterBuild; /* non-zero if user pressed Build & Run */
68 int32_t runOnDevice; /* non-zero if user wants real-hardware run */
69 int32_t forceRebuild; /* non-zero when "Force Rebuild" was checked.
70 Addons should clean their per-target build
71 artifacts (e.g. `make clean`, delete .o files)
72 inside GetCompileCommand or PreCook before
73 kicking off their toolchain. */
74
75 /* Addon-owned per-build state. The engine never touches this. */
76 void* userData;
77
78 /* Engine-owned opaque pointer. Cast and use at your own risk. */
79 void* opaqueEngineState;
80
81 /* ===== Helper trampolines ============================================
82 * Provided so addons don't have to re-link engine symbols. All function
83 * pointers are non-null when the context is passed to a callback. */
84
86 void (*Log)(int32_t severity, const char* msg);
87
89 void (*WriteOutputLine)(const char* line);
90
95 int32_t (*GetProfileSetting)(const char* key, char* outVal, size_t cap);
96
98 void (*SetProfileSetting)(const char* key, const char* val);
99
104 int32_t (*ResolvePath)(const char* relative, char* outAbs, size_t cap);
105};
106
107/* ===== Build target descriptor ============================================
108 *
109 * Fill one of these inside RegisterEditorUI and pass to RegisterBuildTarget.
110 *
111 * REQUIRED fields: apiVersion, targetId, displayName, basePlatform,
112 * binaryExtension, GetCompileCommand.
113 *
114 * All function-pointer callbacks may be set to NULL except GetCompileCommand.
115 * Convention: a callback that returns int32_t returns non-zero on success.
116 */
117struct PolyphaseBuildTargetDesc
118{
119 /* ----- Identity / metadata --------------------------------------------- */
120 uint32_t apiVersion; /* must equal POLYPHASE_BUILD_TARGET_API_VERSION */
121 const char* targetId; /* stable reverse-DNS id, e.g. "homebrew.dreamcast" */
122 const char* displayName; /* human label, e.g. "Dreamcast (KallistiOS)" */
123 const char* iconText; /* optional ImGui glyph/short text */
124 const char* category; /* grouping in the UI dropdown ("Retro Consoles", etc.) */
125
126 /* ----- Cook compatibility ---------------------------------------------- */
127 int32_t basePlatform; /* Platform enum value to use for default asset cook */
128
129 /* ----- Output ---------------------------------------------------------- */
130 const char* binaryExtension; /* ".elf", ".cdi", ".xbe", ".nds", ... */
131
132 /* ----- Capability flags ------------------------------------------------ */
133 int32_t requiresDocker; /* non-zero if Docker build is required */
134 int32_t supportsRunOnDevice; /* non-zero if RunOnDevice callback is meaningful */
135 int32_t supportsEmulator; /* non-zero if RunInEmulator callback is meaningful */
136
137 /* ----- Lifecycle callbacks (all nullable except GetCompileCommand) ----- */
138
145 int32_t (*Validate)(char* outReason, size_t reasonCap);
146
152 int32_t (*PreCook)(const PolyphaseBuildContext* ctx);
153
167 int32_t (*CookAsset)(const PolyphaseBuildContext* ctx,
168 const char* assetTypeName, void* assetPtr, void* streamPtr);
169
176 int32_t (*GetCompileCommand)(const PolyphaseBuildContext* ctx, char* outCmd, size_t cmdCap);
177
185 int32_t (*GetCompiledBinaryPath)(const PolyphaseBuildContext* ctx, char* outPath, size_t pathCap);
186
192 int32_t (*PostPackage)(const PolyphaseBuildContext* ctx);
193
198 int32_t (*RunOnDevice)(const PolyphaseBuildContext* ctx, char* outCmd, size_t cmdCap);
199
204 int32_t (*RunInEmulator)(const PolyphaseBuildContext* ctx, char* outCmd, size_t cmdCap);
205
206 /* ----- Editor UI integration (all optional) ---------------------------- */
207
219 void (*DrawProfileOptions)(const PolyphaseBuildContext* ctx);
220
222 void (*SerializeProfileOptions)(const PolyphaseBuildContext* ctx, void* rapidJsonValuePtr);
223
225 void (*DeserializeProfileOptions)(const PolyphaseBuildContext* ctx, const void* rapidJsonValuePtr);
226
227 /* ----- Variant-2 platform extension (optional) ------------------------
228 *
229 * Used by addons that ship an engine runtime (Graphics/Input/Audio/etc.
230 * implementations) for the target platform — i.e. real new-platform
231 * support, not just packaging.
232 *
233 * platformExtensionDir is an addon-relative directory containing well-
234 * known files that supply the platform-specific halves of engine fork
235 * headers:
236 *
237 * <addonRoot>/<platformExtensionDir>/
238 * SystemTypes_Platform.h (required)
239 * InputTypes_Platform.h (required)
240 * AudioTypes_Platform.h (required)
241 * NetworkTypes_Platform.h (optional — falls back to stub)
242 *
243 * When set, ActionManager writes bridge headers to
244 * <projectDir>/Generated/PolyphasePlatform_*.h that forward to these
245 * files via absolute path. The engine's fork headers detect this via
246 * `#if defined(POLYPHASE_PLATFORM_ADDON)` and prefer the bridge over
247 * the legacy PLATFORM_* arms.
248 *
249 * Leave NULL if your addon only does packaging (asset cook + EBOOT
250 * wrap) and reuses the engine's existing built-in platform runtime
251 * (e.g. cross-builds a Linux .elf for the basePlatform).
252 */
253 const char* platformExtensionDir;
254
255 /* ----- Reserved for ABI growth (always zero-initialise) --------------- */
256 void* reserved[7];
257};
258
259#endif /* EDITOR */