A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
refactor(eht): single-source builtin enums from C++ ES_ENUMs (phase 2)
yhh7c34a7e36ffc
diff --git a/sdk/src/component.generated.ts b/sdk/src/component.generated.tsindex 86e507d38..2a74a7d5d 100644--- a/sdk/src/component.generated.ts+++ b/sdk/src/component.generated.ts@@ -15,7 +15,7 @@ import type { Dimension, Padding, VisualState } from './wasm.generated';* getAbiLayoutHash(); BuiltinBridge.connect() compares them and refuses to* run on mismatch, because mismatched offsets read the wrong heap bytes.*/-export const ABI_LAYOUT_HASH = 'b77fc377a67f3228';+export const ABI_LAYOUT_HASH = '124c9c3f323b74f1';export interface AssetFieldMeta {field: string;diff --git a/sdk/src/component.ts b/sdk/src/component.tsindex 3a5f0d7ef..f3b72e0eb 100644--- a/sdk/src/component.ts+++ b/sdk/src/component.ts@@ -18,6 +18,12 @@ import type {TilemapLayerData, BitmapTextData,CameraData as CameraDataCpp, ParticleEmitterData as ParticleEmitterDataCpp,} from './component.generated';+// Builtin enums whose values come from C++ ES_ENUMs — imported from the generated+// module (single source) and re-exported below, so a TS const cannot drift from the+// C++ enum and the editor dropdowns (enumOptions) derive from the same values. The+// remaining hand-written enums (ScaleMode aliases, ShapeType, ParticleEasing) have no+// matching C++ enum yet, so they stay local.+import { ProjectionType, ClearFlags, EmitterShape, SimulationSpace, Light2DType } from './wasm.generated';import { BlendMode } from './blend';import { getDefaultContext } from './context';import type {@@ -496,21 +502,10 @@ export function ensureBuiltinComponentsRegistered(): void {// Camera / Canvas Enums// =============================================================================-export const ProjectionType = {- Perspective: 0,- Orthographic: 1,-} as const;--export type ProjectionType = (typeof ProjectionType)[keyof typeof ProjectionType];--export const ClearFlags = {- None: 0,- ColorOnly: 1,- DepthOnly: 2,- ColorAndDepth: 3,-} as const;--export type ClearFlags = (typeof ClearFlags)[keyof typeof ClearFlags];+// Single-sourced from C++ ES_ENUMs (see import above). ProjectionType, ClearFlags,+// EmitterShape, SimulationSpace and Light2DType are re-exported from the generated+// module; their values and the editor dropdowns built from them now have one source.+export { ProjectionType, ClearFlags, EmitterShape, SimulationSpace, Light2DType };export const ScaleMode = {FixedWidth: 0,@@ -548,15 +543,6 @@ export const ShapeType = {export type ShapeType = (typeof ShapeType)[keyof typeof ShapeType];-export const Light2DType = {- Point: 0,- Directional: 1,- Ambient: 2,- Spot: 3,-} as const;--export type Light2DType = (typeof Light2DType)[keyof typeof Light2DType];-// Camera = the generated C++ field shape + one editor-only field. `showFrustum`// drives gizmo rendering and has no C++ Camera member, so it is added here rather// than in the generated interface (the only hand-written Camera field).@@ -674,22 +660,8 @@ export const TilemapLayer = defineBuiltin<TilemapLayerData>('TilemapLayer',// ParticleEmitter Enums// =============================================================================-export const EmitterShape = {- Point: 0,- Circle: 1,- Rectangle: 2,- Cone: 3,-} as const;--export type EmitterShape = (typeof EmitterShape)[keyof typeof EmitterShape];--export const SimulationSpace = {- World: 0,- Local: 1,-} as const;--export type SimulationSpace = (typeof SimulationSpace)[keyof typeof SimulationSpace];-+// EmitterShape + SimulationSpace are re-exported from the generated module (see the+// import at the top). ParticleEasing has no C++ ES_ENUM yet, so it stays local.export const ParticleEasing = {Linear: 0,EaseIn: 1,diff --git a/sdk/src/wasm.generated.ts b/sdk/src/wasm.generated.tsindex 17684cf0e..be548c91b 100644--- a/sdk/src/wasm.generated.ts+++ b/sdk/src/wasm.generated.ts@@ -97,6 +97,13 @@ export enum JustifyContent {SpaceEvenly = 5,}+export enum Light2DType {+ Point = 0,+ Directional = 1,+ Ambient = 2,+ Spot = 3,+}+export enum MaskMode {Scissor = 0,Stencil = 1,diff --git a/src/esengine/bindings/WebBindings.generated.cpp b/src/esengine/bindings/WebBindings.generated.cppindex bfc10316e..58928ec9a 100644--- a/src/esengine/bindings/WebBindings.generated.cpp+++ b/src/esengine/bindings/WebBindings.generated.cpp@@ -157,6 +157,12 @@ EMSCRIPTEN_BINDINGS(esengine_enums) {.value("SpaceAround", esengine::ecs::JustifyContent::SpaceAround).value("SpaceEvenly", esengine::ecs::JustifyContent::SpaceEvenly);+ enum_<esengine::ecs::Light2DType>("Light2DType")+ .value("Point", esengine::ecs::Light2DType::Point)+ .value("Directional", esengine::ecs::Light2DType::Directional)+ .value("Ambient", esengine::ecs::Light2DType::Ambient)+ .value("Spot", esengine::ecs::Light2DType::Spot);+enum_<esengine::ecs::MaskMode>("MaskMode").value("Scissor", esengine::ecs::MaskMode::Scissor).value("Stencil", esengine::ecs::MaskMode::Stencil);@@ -1927,7 +1933,7 @@ static_assert(offsetof(esengine::ecs::Velocity, angular) == 12, "ABI offset drif// ABI Hash -- runtime handshake against the SDK bundle// =============================================================================-static const char* kEsAbiLayoutHash = "b77fc377a67f3228";+static const char* kEsAbiLayoutHash = "124c9c3f323b74f1";std::string esengineGetAbiLayoutHash() {return std::string(kEsAbiLayoutHash);diff --git a/src/esengine/ecs/components/Light2D.hpp b/src/esengine/ecs/components/Light2D.hppindex 64d9c2964..69e8a4a17 100644--- a/src/esengine/ecs/components/Light2D.hpp+++ b/src/esengine/ecs/components/Light2D.hpp@@ -27,6 +27,7 @@ namespace esengine::ecs {* @brief 2D light kind. Point uses the Transform position + radius falloff; Directional uses* `direction` with no attenuation; Ambient adds a flat term independent of normal/position.*/+ES_ENUM()enum class Light2DType : i32 {Point = 0,Directional = 1,