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(particle): ParticleEasing single-sourced from a C++ ES_ENUM
yhh541bba18adf9
diff --git a/sdk/src/component.generated.ts b/sdk/src/component.generated.tsindex cd46b8493..0ce690c13 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 = '1bd58a735ff10d7f';+export const ABI_LAYOUT_HASH = '2139ae73f765c1ed';export interface AssetFieldMeta {field: string;@@ -321,10 +321,10 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {startSizeMax: { min: 0, category: "Size" },endSizeMin: { min: 0, category: "Size" },endSizeMax: { min: 0, category: "Size" },- sizeEasing: { category: "Size" },+ sizeEasing: { enum: [{ label: 'Linear', value: 0 }, { label: 'EaseIn', value: 1 }, { label: 'EaseOut', value: 2 }, { label: 'EaseInOut', value: 3 }], category: "Size" },startColor: { category: "Color" },endColor: { category: "Color" },- colorEasing: { category: "Color" },+ colorEasing: { enum: [{ label: 'Linear', value: 0 }, { label: 'EaseIn', value: 1 }, { label: 'EaseOut', value: 2 }, { label: 'EaseInOut', value: 3 }], category: "Color" },rotationMin: { unit: "°", category: "Rotation" },rotationMax: { unit: "°", category: "Rotation" },angularVelocityMin: { category: "Rotation" },diff --git a/sdk/src/component.ts b/sdk/src/component.tsindex 2a0ebc808..bb49eb2d2 100644--- a/sdk/src/component.ts+++ b/sdk/src/component.ts@@ -19,11 +19,10 @@ import type {} 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-// one remaining hand-written enum (ParticleEasing) has no matching C++ enum yet, so-// it stays local; ScaleMode's canonical values come from CanvasScaleMode-// (only its Cocos-compat aliases ShowAll/NoBorder are TS-side).-import { ProjectionType, ClearFlags, EmitterShape, SimulationSpace, Light2DType, CanvasScaleMode, ShapeType } from './wasm.generated';+// C++ enum and the editor dropdowns derive from the same values. ScaleMode's+// canonical values come from CanvasScaleMode (only its Cocos-compat aliases+// ShowAll/NoBorder are TS-side).+import { ProjectionType, ClearFlags, EmitterShape, SimulationSpace, Light2DType, CanvasScaleMode, ShapeType, ParticleEasing } from './wasm.generated';import { BlendMode } from './blend';import { getDefaultContext } from './context';import type {@@ -701,16 +700,10 @@ export const TilemapLayer = defineBuiltin<TilemapLayerData>('TilemapLayer',// ParticleEmitter Enums// =============================================================================-// 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,- EaseOut: 2,- EaseInOut: 3,-} as const;--export type ParticleEasing = (typeof ParticleEasing)[keyof typeof ParticleEasing];+// EmitterShape, SimulationSpace and ParticleEasing are re-exported from the+// generated module (see the import at the top) — single-sourced from their C+++// ES_ENUMs beside the component fields that serialize them.+export { ParticleEasing };// =============================================================================// ParticleEmitter Component@@ -736,13 +729,11 @@ export const ParticleEmitter = defineBuiltin<ParticleEmitterData>('ParticleEmittmetaDefaults<ParticleEmitterData>('ParticleEmitter', { colorGradient: { stops: [] }, sizeCurve: { keys: [] } }),{// Most field metadata is authored at the C++ ES_PROPERTY site (categories,- // min/step, and the shape/simulationSpace enum dropdowns via `enum=`). Only- // what an annotation can't express stays here: enums built from a TS-only- // constant (ParticleEasing / BlendMode have no component ES_ENUM), and the two+ // min/step, and the shape/simulationSpace/easing enum dropdowns via `enum=`).+ // Only what an annotation can't express stays here: the blendMode dropdown+ // (BlendMode is a renderer enum with no component ES_ENUM), and the two// TS-only editor fields (sizeCurve / colorGradient have no C++ member).fields: {- sizeEasing: { enum: enumOptions(ParticleEasing) },- colorEasing: { enum: enumOptions(ParticleEasing) },blendMode: { enum: enumOptions(BlendMode) },sizeCurve: { curve: true, category: 'Size' },colorGradient: { gradient: true, category: 'Color' },diff --git a/sdk/src/wasm.generated.ts b/sdk/src/wasm.generated.tsindex a8029e32c..9b004e987 100644--- a/sdk/src/wasm.generated.ts+++ b/sdk/src/wasm.generated.ts@@ -109,6 +109,13 @@ export enum MaskMode {Stencil = 1,}+export enum ParticleEasing {+ Linear = 0,+ EaseIn = 1,+ EaseOut = 2,+ EaseInOut = 3,+}+export enum ProjectionType {Perspective = 0,Orthographic = 1,diff --git a/sdk/tests/cpp-contract.test.ts b/sdk/tests/cpp-contract.test.tsindex 7841e0919..c0336c4b7 100644--- a/sdk/tests/cpp-contract.test.ts+++ b/sdk/tests/cpp-contract.test.ts@@ -35,6 +35,7 @@ import * as gen from '../src/wasm.generated';import { BodyType } from '../src/physics/PhysicsComponents';import { UIPositionType, AlignSelf } from '../src/ui/core/ui-node';import { UIVisualType, FillMethod, FillOrigin } from '../src/ui/core/ui-visual';+import { ParticleEasing } from '../src/component';// Repo root is two levels up from sdk/tests/ (mirrors the spine integration tests).const CPP = resolve(__dirname, '../../src/esengine');@@ -195,6 +196,7 @@ describe('C++ contract: module-published enums ARE their EHT-generated twin', ()['UIVisualType', UIVisualType, gen.UIVisualType],['FillMethod', FillMethod, gen.UIFillMethod],['FillOrigin', FillOrigin, gen.UIFillOrigin],+ ['ParticleEasing', ParticleEasing, gen.ParticleEasing],];for (const [label, published, generated] of cases) {it(`${label} is a re-export of the generated enum`, () => {diff --git a/src/esengine/bindings/EditorAPI.generated.cpp b/src/esengine/bindings/EditorAPI.generated.cppindex f093c80b4..42a3bc0ea 100644--- a/src/esengine/bindings/EditorAPI.generated.cpp+++ b/src/esengine/bindings/EditorAPI.generated.cpp@@ -2,10 +2,10 @@* @file EditorAPI.generated.cpp* @brief Auto-generated editor API with string-dispatched component access* @details Generated by EHT - DO NOT EDIT- * @schema_hash 9a8aa5c2786aab04+ * @schema_hash a4a54cbd50da0aef*/-#define ES_EDITOR_API_SCHEMA_HASH "9a8aa5c2786aab04"+#define ES_EDITOR_API_SCHEMA_HASH "a4a54cbd50da0aef"#include <emscripten/bind.h>#include <string>diff --git a/src/esengine/bindings/WebBindings.generated.cpp b/src/esengine/bindings/WebBindings.generated.cppindex 3fc9e4541..fb4f027dd 100644--- a/src/esengine/bindings/WebBindings.generated.cpp+++ b/src/esengine/bindings/WebBindings.generated.cpp@@ -167,6 +167,12 @@ EMSCRIPTEN_BINDINGS(esengine_enums) {.value("Scissor", esengine::ecs::MaskMode::Scissor).value("Stencil", esengine::ecs::MaskMode::Stencil);+ enum_<esengine::ecs::ParticleEasing>("ParticleEasing")+ .value("Linear", esengine::ecs::ParticleEasing::Linear)+ .value("EaseIn", esengine::ecs::ParticleEasing::EaseIn)+ .value("EaseOut", esengine::ecs::ParticleEasing::EaseOut)+ .value("EaseInOut", esengine::ecs::ParticleEasing::EaseInOut);+enum_<esengine::ecs::ProjectionType>("ProjectionType").value("Perspective", esengine::ecs::ProjectionType::Perspective).value("Orthographic", esengine::ecs::ProjectionType::Orthographic);@@ -1956,7 +1962,7 @@ static_assert(offsetof(esengine::ecs::Velocity, angular) == 12, "ABI offset drif// ABI Hash -- runtime handshake against the SDK bundle// =============================================================================-static const char* kEsAbiLayoutHash = "1bd58a735ff10d7f";+static const char* kEsAbiLayoutHash = "2139ae73f765c1ed";std::string esengineGetAbiLayoutHash() {return std::string(kEsAbiLayoutHash);diff --git a/src/esengine/ecs/components/ParticleEmitter.hpp b/src/esengine/ecs/components/ParticleEmitter.hppindex e73d5746a..c2333ea15 100644--- a/src/esengine/ecs/components/ParticleEmitter.hpp+++ b/src/esengine/ecs/components/ParticleEmitter.hpp@@ -6,7 +6,6 @@#include "../../core/Reflection.hpp"#include "../../math/Math.hpp"#include "../../resource/Handle.hpp"-#include "../../particle/ParticleEasing.hpp"namespace esengine::ecs {@@ -18,6 +17,17 @@ enum class EmitterShape : i32 {Cone = 3,};+// Single source of the easing choice serialized by sizeEasing/colorEasing; the+// particle sim consumes it as particle::EasingType (alias) and the editor+// dropdown + TS const are EHT-generated from here.+ES_ENUM()+enum class ParticleEasing : i32 {+ Linear = 0,+ EaseIn = 1,+ EaseOut = 2,+ EaseInOut = 3,+};+ES_ENUM()enum class SimulationSpace : i32 {World = 0,@@ -94,8 +104,9 @@ struct ParticleEmitter {ES_PROPERTY(min=0, category=Size)f32 endSizeMax{100.0f};- ES_PROPERTY(category=Size)- i32 sizeEasing{static_cast<i32>(particle::EasingType::Linear)};+ // Easing — i32 storage, dropdown generated from the ParticleEasing enum.+ ES_PROPERTY(enum=ParticleEasing, category=Size)+ i32 sizeEasing{static_cast<i32>(ParticleEasing::Linear)};// ColorES_PROPERTY(category=Color)@@ -104,8 +115,8 @@ struct ParticleEmitter {ES_PROPERTY(category=Color)glm::vec4 endColor{1.0f, 1.0f, 1.0f, 0.0f};- ES_PROPERTY(category=Color)- i32 colorEasing{static_cast<i32>(particle::EasingType::Linear)};+ ES_PROPERTY(enum=ParticleEasing, category=Color)+ i32 colorEasing{static_cast<i32>(ParticleEasing::Linear)};// RotationES_PROPERTY(unit="°", category=Rotation)diff --git a/src/esengine/particle/ParticleEasing.hpp b/src/esengine/particle/ParticleEasing.hppindex b9fe00aec..dd33e18dc 100644--- a/src/esengine/particle/ParticleEasing.hpp+++ b/src/esengine/particle/ParticleEasing.hpp@@ -4,15 +4,14 @@#include "../core/Types.hpp"#include "../animation/EasingFunctions.hpp"+#include "../ecs/components/ParticleEmitter.hpp"namespace esengine::particle {-enum class EasingType : i32 {- Linear = 0,- EaseIn = 1,- EaseOut = 2,- EaseInOut = 3,-};+// The enum's single source is the ES_ENUM ParticleEasing beside the component+// fields that serialize it (EHT generates the TS const + editor dropdown from+// there); the sim keeps its historical local name.+using EasingType = ecs::ParticleEasing;// Delegates to the shared easing library so the math lives in ONE place// (easing consolidation). Particle keeps its own 4-value