Skip to content

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.

fix(abi): the tween enums are generated, and an enum may live anywhere

yhh1ad527de2c22
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2e3efc55d..82061685a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -49,6 +49,34 @@ published separately; it ships inside the editor.
### Fixed
+- **The tween enums are generated now, and an enum may live outside the reflected
+ directory.** Easing curves, tween state, loop mode and tween target were each
+ written once in C++ and again in TypeScript, tied only by a test. They cross as
+ bare numbers, so a drift is a different curve or a tween reported in the wrong
+ state — never an error.
+
+ EHT parsed enums only under `src/esengine/ecs/components`, which is why these
+ were hand-copied: they live in `animation/TweenData.hpp`. It scans for `ES_ENUM`
+ across the engine now, the same way it scans for `ES_CONST` — enum-only, because
+ a component outside the reflected directory would need its bindings, storage and
+ editor surface too, and that decision must not be made quietly. Enum values were
+ already in the ABI layout hash, so marking them was enough to put them behind
+ the `connect()` handshake. `ABI_LAYOUT_HASH` changes: rebuild the engine.
+
+ Two things had to be fixed for an enum to live anywhere. The generated binding
+ derived its `#include` list from **components**, so an enum declared away from
+ one was registered by a C++ type the translation unit could not name — a latent
+ build break for any such enum, now that one exists. And `TweenTarget`'s C++
+ members were renamed to the SDK's shorter spelling (`PositionX`, not
+ `TransformPositionX`) so one vocabulary serves both sides; the values, which are
+ the contract, are unchanged. The dead `COUNT` sentinels went with it — nothing
+ in C++ read them, and a generated member that is not a target is a value the
+ boundary invites you to send.
+
+ The pins in `cpp-contract.test.ts` become identity pins, the idiom the other
+ fifteen generated enums already use: same-values-different-object is the drift a
+ re-export eliminates, and only `toBe` sees it.
+
- **A recursive delete on Windows now retries, so the temp-tree flake is gone.**
Deleting on Windows is not synchronous at the filesystem level: an unlinked file
sits in a pending-delete state with its directory entry still there, so the
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index 35de63b0e..160961442 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -5,7 +5,7 @@ Symbols: 113 public · 84 beta · 1514 experimental · 3 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
-"9bc45f6f2153c7c6"
+"e59728e2336b5b14"
```
## ANCHOR_AXES — const @experimental
@@ -2873,9 +2873,24 @@ world: World
readonly ["texture-compression-astc", "texture-compression-bc", "texture-compression-etc2", "timestamp-query"]
```
-## EasingType — type @experimental
-```
-(typeof EasingType)[keyof typeof EasingType]
+## EasingType — enum @experimental
+```
+CubicBezier = 14
+EaseInBack = 7
+EaseInCubic = 4
+EaseInElastic = 10
+EaseInOutBack = 9
+EaseInOutCubic = 6
+EaseInOutElastic = 12
+EaseInOutQuad = 3
+EaseInQuad = 1
+EaseOutBack = 8
+EaseOutBounce = 13
+EaseOutCubic = 5
+EaseOutElastic = 11
+EaseOutQuad = 2
+Linear = 0
+Step = 15
```
## EditorAssetType — type @experimental
@@ -4423,9 +4438,11 @@ static prototype: Logger
code: string
```
-## LoopMode — type @experimental
+## LoopMode — enum @experimental
```
-(typeof LoopMode)[keyof typeof LoopMode]
+None = 0
+PingPong = 2
+Restart = 1
```
## MATERIAL_FORMAT_VERSION — const @experimental
@@ -8813,14 +8830,29 @@ static new (factories: TweenFactory[]): TweenSequence
static prototype: TweenSequence
```
-## TweenState — type @experimental
+## TweenState — enum @experimental
```
-(typeof TweenState)[keyof typeof TweenState]
+Cancelled = 3
+Completed = 2
+Paused = 1
+Running = 0
```
-## TweenTarget — type @experimental
+## TweenTarget — enum @experimental
```
-(typeof TweenTarget)[keyof typeof TweenTarget]
+CameraOrthoSize = 12
+ColorA = 9
+ColorB = 8
+ColorG = 7
+ColorR = 6
+PositionX = 0
+PositionY = 1
+PositionZ = 2
+RotationZ = 5
+ScaleX = 3
+ScaleY = 4
+SizeX = 10
+SizeY = 11
```
## UICameraData — interface @beta
diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.md
index af86839e4..7659cb35f 100644
--- a/sdk/etc/index.native.api.md
+++ b/sdk/etc/index.native.api.md
@@ -5,7 +5,7 @@ Symbols: 113 public · 89 beta · 1533 experimental · 3 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
-"9bc45f6f2153c7c6"
+"e59728e2336b5b14"
```
## ANCHOR_AXES — const @experimental
@@ -2881,9 +2881,24 @@ world: World
readonly ["texture-compression-astc", "texture-compression-bc", "texture-compression-etc2", "timestamp-query"]
```
-## EasingType — type @experimental
-```
-(typeof EasingType)[keyof typeof EasingType]
+## EasingType — enum @experimental
+```
+CubicBezier = 14
+EaseInBack = 7
+EaseInCubic = 4
+EaseInElastic = 10
+EaseInOutBack = 9
+EaseInOutCubic = 6
+EaseInOutElastic = 12
+EaseInOutQuad = 3
+EaseInQuad = 1
+EaseOutBack = 8
+EaseOutBounce = 13
+EaseOutCubic = 5
+EaseOutElastic = 11
+EaseOutQuad = 2
+Linear = 0
+Step = 15
```
## EditorAssetType — type @experimental
@@ -4431,9 +4446,11 @@ static prototype: Logger
code: string
```
-## LoopMode — type @experimental
+## LoopMode — enum @experimental
```
-(typeof LoopMode)[keyof typeof LoopMode]
+None = 0
+PingPong = 2
+Restart = 1
```
## MATERIAL_FORMAT_VERSION — const @experimental
@@ -9006,14 +9023,29 @@ static new (factories: TweenFactory[]): TweenSequence
static prototype: TweenSequence
```
-## TweenState — type @experimental
+## TweenState — enum @experimental
```
-(typeof TweenState)[keyof typeof TweenState]
+Cancelled = 3
+Completed = 2
+Paused = 1
+Running = 0
```
-## TweenTarget — type @experimental
+## TweenTarget — enum @experimental
```
-(typeof TweenTarget)[keyof typeof TweenTarget]
+CameraOrthoSize = 12
+ColorA = 9
+ColorB = 8
+ColorG = 7
+ColorR = 6
+PositionX = 0
+PositionY = 1
+PositionZ = 2
+RotationZ = 5
+ScaleX = 3
+ScaleY = 4
+SizeX = 10
+SizeY = 11
```
## UICameraData — interface @beta
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index 567d1907e..f4b239d2b 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -2868,9 +2868,24 @@ world: World
readonly ["texture-compression-astc", "texture-compression-bc", "texture-compression-etc2", "timestamp-query"]
```
-## EasingType — type @experimental
-```
-(typeof EasingType)[keyof typeof EasingType]
+## EasingType — enum @experimental
+```
+CubicBezier = 14
+EaseInBack = 7
+EaseInCubic = 4
+EaseInElastic = 10
+EaseInOutBack = 9
+EaseInOutCubic = 6
+EaseInOutElastic = 12
+EaseInOutQuad = 3
+EaseInQuad = 1
+EaseOutBack = 8
+EaseOutBounce = 13
+EaseOutCubic = 5
+EaseOutElastic = 11
+EaseOutQuad = 2
+Linear = 0
+Step = 15
```
## EditorAssetType — type @experimental
@@ -4418,9 +4433,11 @@ static prototype: Logger
code: string
```
-## LoopMode — type @experimental
+## LoopMode — enum @experimental
```
-(typeof LoopMode)[keyof typeof LoopMode]
+None = 0
+PingPong = 2
+Restart = 1
```
## MATERIAL_FORMAT_VERSION — const @experimental
@@ -8808,14 +8825,29 @@ static new (factories: TweenFactory[]): TweenSequence
static prototype: TweenSequence
```
-## TweenState — type @experimental
+## TweenState — enum @experimental
```
-(typeof TweenState)[keyof typeof TweenState]
+Cancelled = 3
+Completed = 2
+Paused = 1
+Running = 0
```
-## TweenTarget — type @experimental
+## TweenTarget — enum @experimental
```
-(typeof TweenTarget)[keyof typeof TweenTarget]
+CameraOrthoSize = 12
+ColorA = 9
+ColorB = 8
+ColorG = 7
+ColorR = 6
+PositionX = 0
+PositionY = 1
+PositionZ = 2
+RotationZ = 5
+ScaleX = 3
+ScaleY = 4
+SizeX = 10
+SizeY = 11
```
## UICameraData — interface @beta
diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.md
index 393ed57b4..2b2d4c05e 100644
--- a/sdk/etc/minigame.api.md
+++ b/sdk/etc/minigame.api.md
@@ -2868,9 +2868,24 @@ world: World
readonly ["texture-compression-astc", "texture-compression-bc", "texture-compression-etc2", "timestamp-query"]
```
-## EasingType — type @experimental
-```
-(typeof EasingType)[keyof typeof EasingType]
+## EasingType — enum @experimental
+```
+CubicBezier = 14
+EaseInBack = 7
+EaseInCubic = 4
+EaseInElastic = 10
+EaseInOutBack = 9
+EaseInOutCubic = 6
+EaseInOutElastic = 12
+EaseInOutQuad = 3
+EaseInQuad = 1
+EaseOutBack = 8
+EaseOutBounce = 13
+EaseOutCubic = 5
+EaseOutElastic = 11
+EaseOutQuad = 2
+Linear = 0
+Step = 15
```
## EditorAssetType — type @experimental
@@ -4418,9 +4433,11 @@ static prototype: Logger
code: string
```
-## LoopMode — type @experimental
+## LoopMode — enum @experimental
```
-(typeof LoopMode)[keyof typeof LoopMode]
+None = 0
+PingPong = 2
+Restart = 1
```
## MATERIAL_FORMAT_VERSION — const @experimental
@@ -9054,14 +9071,29 @@ static new (factories: TweenFactory[]): TweenSequence
static prototype: TweenSequence
```
-## TweenState — type @experimental
+## TweenState — enum @experimental
```
-(typeof TweenState)[keyof typeof TweenState]
+Cancelled = 3
+Completed = 2
+Paused = 1
+Running = 0
```
-## TweenTarget — type @experimental
+## TweenTarget — enum @experimental
```
-(typeof TweenTarget)[keyof typeof TweenTarget]
+CameraOrthoSize = 12
+ColorA = 9
+ColorB = 8
+ColorG = 7
+ColorR = 6
+PositionX = 0
+PositionY = 1
+PositionZ = 2
+RotationZ = 5
+ScaleX = 3
+ScaleY = 4
+SizeX = 10
+SizeY = 11
```
## UICameraData — interface @beta
diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.md
index be5ffb466..efd196df0 100644
--- a/sdk/etc/wechat.api.md
+++ b/sdk/etc/wechat.api.md
@@ -2868,9 +2868,24 @@ world: World
readonly ["texture-compression-astc", "texture-compression-bc", "texture-compression-etc2", "timestamp-query"]
```
-## EasingType — type @experimental
-```
-(typeof EasingType)[keyof typeof EasingType]
+## EasingType — enum @experimental
+```
+CubicBezier = 14
+EaseInBack = 7
+EaseInCubic = 4
+EaseInElastic = 10
+EaseInOutBack = 9
+EaseInOutCubic = 6
+EaseInOutElastic = 12
+EaseInOutQuad = 3
+EaseInQuad = 1
+EaseOutBack = 8
+EaseOutBounce = 13
+EaseOutCubic = 5
+EaseOutElastic = 11
+EaseOutQuad = 2
+Linear = 0
+Step = 15
```
## EditorAssetType — type @experimental
@@ -4425,9 +4440,11 @@ static prototype: Logger
code: string
```
-## LoopMode — type @experimental
+## LoopMode — enum @experimental
```
-(typeof LoopMode)[keyof typeof LoopMode]
+None = 0
+PingPong = 2
+Restart = 1
```
## MATERIAL_FORMAT_VERSION — const @experimental
@@ -8815,14 +8832,29 @@ static new (factories: TweenFactory[]): TweenSequence
static prototype: TweenSequence
```
-## TweenState — type @experimental
+## TweenState — enum @experimental
```
-(typeof TweenState)[keyof typeof TweenState]
+Cancelled = 3
+Completed = 2
+Paused = 1
+Running = 0
```
-## TweenTarget — type @experimental
+## TweenTarget — enum @experimental
```
-(typeof TweenTarget)[keyof typeof TweenTarget]
+CameraOrthoSize = 12
+ColorA = 9
+ColorB = 8
+ColorG = 7
+ColorR = 6
+PositionX = 0
+PositionY = 1
+PositionZ = 2
+RotationZ = 5
+ScaleX = 3
+ScaleY = 4
+SizeX = 10
+SizeY = 11
```
## UICameraData — interface @beta
diff --git a/sdk/src/animation/Easing.ts b/sdk/src/animation/Easing.ts
index acd70f668..72feaf02b 100644
--- a/sdk/src/animation/Easing.ts
+++ b/sdk/src/animation/Easing.ts
@@ -8,30 +8,19 @@
* in lock-step with src/esengine/animation/TweenData.hpp::EasingType.
*/
+import { EasingType } from '../wasm/wasm.generated';
+
// =============================================================================
-// EasingType (wire protocol — must match C++ TweenData.hpp)
+// EasingType (wire protocol — generated from C++ TweenData.hpp)
// =============================================================================
-export const EasingType = {
- Linear: 0,
- EaseInQuad: 1,
- EaseOutQuad: 2,
- EaseInOutQuad: 3,
- EaseInCubic: 4,
- EaseOutCubic: 5,
- EaseInOutCubic: 6,
- EaseInBack: 7,
- EaseOutBack: 8,
- EaseInOutBack: 9,
- EaseInElastic: 10,
- EaseOutElastic: 11,
- EaseInOutElastic: 12,
- EaseOutBounce: 13,
- CubicBezier: 14,
- Step: 15,
-} as const;
-
-export type EasingType = (typeof EasingType)[keyof typeof EasingType];
+/**
+ * The easing curves the C++ `TweenSystem` can drive, from the enum that owns
+ * them. Generated, so this is not a second answer, and the values are in the
+ * ABI layout hash — they cross as bare numbers, where a drift is a different
+ * curve rather than an error.
+ */
+export { EasingType } from '../wasm/wasm.generated';
export interface BezierPoints {
p1x: number;
diff --git a/sdk/src/animation/Tween.ts b/sdk/src/animation/Tween.ts
index 721c6f160..fdc9b974f 100644
--- a/sdk/src/animation/Tween.ts
+++ b/sdk/src/animation/Tween.ts
@@ -9,6 +9,8 @@
* `app.getResource(Tween)` outside ECS code.
*/
+import { TweenTarget } from '../wasm/wasm.generated';
+
import type { Entity } from '../types';
import type { CppRegistry } from '../wasm';
import type { EngineApi } from '../ecs/bridge/engineApi';
@@ -30,9 +32,9 @@ export { TweenState, LoopMode, type TweenOptions } from './TweenTypes';
export { ValueTweenHandle } from './ValueTween';
// =============================================================================
-// Tween Target (wire protocol — must stay in lock-step with
-// src/esengine/animation/TweenData.hpp::TweenTarget — both the order
-// and the numeric values are the WASM boundary contract).
+// Tween Target (wire protocol — generated from
+// src/esengine/animation/TweenData.hpp::TweenTarget, whose order and
+// numeric values are the boundary contract).
// =============================================================================
/**
@@ -52,23 +54,7 @@ export { ValueTweenHandle } from './ValueTween';
* use `tween.value(...)` with a callback that writes the field yourself,
* or drive it via Timeline.
*/
-export const TweenTarget = {
- PositionX: 0,
- PositionY: 1,
- PositionZ: 2,
- ScaleX: 3,
- ScaleY: 4,
- RotationZ: 5,
- ColorR: 6,
- ColorG: 7,
- ColorB: 8,
- ColorA: 9,
- SizeX: 10,
- SizeY: 11,
- CameraOrthoSize: 12,
-} as const;
-
-export type TweenTarget = (typeof TweenTarget)[keyof typeof TweenTarget];
+export { TweenTarget };
// =============================================================================
// Tween Handle (fluent builder)
diff --git a/sdk/src/animation/TweenTypes.ts b/sdk/src/animation/TweenTypes.ts
index 3d92e415b..af1256208 100644
--- a/sdk/src/animation/TweenTypes.ts
+++ b/sdk/src/animation/TweenTypes.ts
@@ -4,28 +4,18 @@
* @file TweenTypes.ts
* @brief Shared tween enums/types — WASM boundary contract
*
- * TweenState and LoopMode numeric values must match
- * src/esengine/animation/TweenData.hpp.
+ * TweenState and LoopMode are generated from src/esengine/animation/TweenData.hpp.
*/
import type { EasingType } from './Easing';
+import type { LoopMode } from '../wasm/wasm.generated';
-export const TweenState = {
- Running: 0,
- Paused: 1,
- Completed: 2,
- Cancelled: 3,
-} as const;
-
-export type TweenState = (typeof TweenState)[keyof typeof TweenState];
-
-export const LoopMode = {
- None: 0,
- Restart: 1,
- PingPong: 2,
-} as const;
-
-export type LoopMode = (typeof LoopMode)[keyof typeof LoopMode];
+/**
+ * The tween lifecycle and loop modes, from the C++ enums that own them. They
+ * cross as bare numbers, so a second answer here is a tween reported in the
+ * wrong state rather than an error.
+ */
+export { TweenState, LoopMode } from '../wasm/wasm.generated';
export interface TweenOptions {
easing?: EasingType;
diff --git a/sdk/src/ecs/component.generated.ts b/sdk/src/ecs/component.generated.ts
index ba296656c..4a84f05b9 100644
--- a/sdk/src/ecs/component.generated.ts
+++ b/sdk/src/ecs/component.generated.ts
@@ -15,7 +15,7 @@ import type { AlignContent, AlignItems, AlignSelf, BodyType, CanvasScaleMode, Cl
* getAbiLayoutHash(); BuiltinBridge.connect() compares them and refuses to
* run on mismatch, because mismatched offsets read the wrong heap bytes.
*/
-export const ABI_LAYOUT_HASH = '9bc45f6f2153c7c6';
+export const ABI_LAYOUT_HASH = 'e59728e2336b5b14';
/**
* One asset-valued field of a component: which field, and what kind of
diff --git a/sdk/src/wasm/wasm.generated.ts b/sdk/src/wasm/wasm.generated.ts
index 466e7df2c..9b2568767 100644
--- a/sdk/src/wasm/wasm.generated.ts
+++ b/sdk/src/wasm/wasm.generated.ts
@@ -73,6 +73,30 @@ export enum ClearFlags {
ColorAndDepth = 3,
}
+/**
+ * The engine's `EasingType`, generated from the C++ enum.
+ *
+ * @experimental
+ */
+export enum EasingType {
+ Linear = 0,
+ EaseInQuad = 1,
+ EaseOutQuad = 2,
+ EaseInOutQuad = 3,
+ EaseInCubic = 4,
+ EaseOutCubic = 5,
+ EaseInOutCubic = 6,
+ EaseInBack = 7,
+ EaseOutBack = 8,
+ EaseInOutBack = 9,
+ EaseInElastic = 10,
+ EaseOutElastic = 11,
+ EaseInOutElastic = 12,
+ EaseOutBounce = 13,
+ CubicBezier = 14,
+ Step = 15,
+}
+
/**
* The engine's `EmitterShape`, generated from the C++ enum.
*
@@ -120,6 +144,17 @@ export enum LightType {
Spot = 3,
}
+/**
+ * The engine's `LoopMode`, generated from the C++ enum.
+ *
+ * @experimental
+ */
+export enum LoopMode {
+ None = 0,
+ Restart = 1,
+ PingPong = 2,
+}
+
export enum MaskMode {
Scissor = 0,
Stencil = 1,
@@ -216,6 +251,39 @@ export enum TilemapStaggerIndex {
Even = 1,
}
+/**
+ * The engine's `TweenState`, generated from the C++ enum.
+ *
+ * @experimental
+ */
+export enum TweenState {
+ Running = 0,
+ Paused = 1,
+ Completed = 2,
+ Cancelled = 3,
+}
+
+/**
+ * The engine's `TweenTarget`, generated from the C++ enum.
+ *
+ * @experimental
+ */
+export enum TweenTarget {
+ PositionX = 0,
+ PositionY = 1,
+ PositionZ = 2,
+ ScaleX = 3,
+ ScaleY = 4,
+ RotationZ = 5,
+ ColorR = 6,
+ ColorG = 7,
+ ColorB = 8,
+ ColorA = 9,
+ SizeX = 10,
+ SizeY = 11,
+ CameraOrthoSize = 12,
+}
+
export enum UIDisplay {
Flex = 0,
None = 1,
diff --git a/sdk/tests/cpp-contract.test.ts b/sdk/tests/cpp-contract.test.ts
index a4fd0ce32..e61040d50 100644
--- a/sdk/tests/cpp-contract.test.ts
+++ b/sdk/tests/cpp-contract.test.ts
@@ -109,33 +109,20 @@ function enumForward(e: Record<string, string | number>): Map<string, number> {
}
describe('C++ contract: animation tween enums (animation/TweenData.hpp)', () => {
- const src = readCpp('animation/TweenData.hpp');
-
- it('EasingType matches (same names + values, minus COUNT sentinel)', () => {
- // The TS easing dispatcher switches on these values; they are the wire
- // protocol for anim_createTween's easing byte.
- expect(sortedEntries(new Map(Object.entries(EasingType))))
- .toEqual(sortedEntries(byName(parseEnum(src, 'EasingType'))));
- });
-
- it('TweenState matches', () => {
- expect(sortedEntries(new Map(Object.entries(TweenState))))
- .toEqual(sortedEntries(byName(parseEnum(src, 'TweenState'))));
- });
-
- it('LoopMode matches', () => {
- expect(sortedEntries(new Map(Object.entries(LoopMode))))
- .toEqual(sortedEntries(byName(parseEnum(src, 'LoopMode'))));
- });
-
- it('TweenTarget matches by value sequence (TS uses abbreviated names)', () => {
- // TS abbreviates the names (PositionX vs C++ TransformPositionX) but the
- // ordered numeric values ARE the boundary contract, so guard those.
- const cppValues = parseEnum(src, 'TweenTarget')
- .filter((e) => e.name !== 'COUNT')
- .map((e) => e.value);
- expect(Object.values(TweenTarget)).toEqual(cppValues);
- });
+ // Generated from that header now, so the pin is IDENTITY: same-values-
+ // different-object is the drift a re-export eliminates, and only `toBe`
+ // sees it. The values are in the ABI layout hash.
+ const cases: Array<[string, unknown, unknown]> = [
+ ['EasingType', EasingType, gen.EasingType],
+ ['TweenState', TweenState, gen.TweenState],
+ ['LoopMode', LoopMode, gen.LoopMode],
+ ['TweenTarget', TweenTarget, gen.TweenTarget],
+ ];
+ for (const [label, published, generated] of cases) {
+ it(`${label} is a re-export of the generated enum`, () => {
+ expect(published).toBe(generated);
+ });
+ }
});
describe('C++ contract: particle color LUT (particle/ParticleSystem.hpp)', () => {
diff --git a/src/esengine/animation/TweenData.hpp b/src/esengine/animation/TweenData.hpp
index 9f55506f6..e7e957f97 100644
--- a/src/esengine/animation/TweenData.hpp
+++ b/src/esengine/animation/TweenData.hpp
@@ -3,9 +3,11 @@
#pragma once
#include "../core/Types.hpp"
+#include "../core/Reflection.hpp"
namespace esengine::animation {
+ES_ENUM(stability=experimental)
enum class EasingType : u8 {
Linear = 0,
EaseInQuad,
@@ -22,27 +24,27 @@ enum class EasingType : u8 {
EaseInOutElastic,
EaseOutBounce,
CubicBezier,
- Step,
- COUNT
+ Step
};
+ES_ENUM(stability=experimental)
enum class TweenTarget : u8 {
- TransformPositionX = 0,
- TransformPositionY,
- TransformPositionZ,
- TransformScaleX,
- TransformScaleY,
- TransformRotationZ,
- SpriteColorR,
- SpriteColorG,
- SpriteColorB,
- SpriteColorA,
- SpriteSizeX,
- SpriteSizeY,
- CameraOrthoSize,
- COUNT
+ PositionX = 0,
+ PositionY,
+ PositionZ,
+ ScaleX,
+ ScaleY,
+ RotationZ,
+ ColorR,
+ ColorG,
+ ColorB,
+ ColorA,
+ SizeX,
+ SizeY,
+ CameraOrthoSize
};
+ES_ENUM(stability=experimental)
enum class TweenState : u8 {
Running = 0,
Paused,
@@ -50,6 +52,7 @@ enum class TweenState : u8 {
Cancelled
};
+ES_ENUM(stability=experimental)
enum class LoopMode : u8 {
None = 0,
Restart,
@@ -58,7 +61,7 @@ enum class LoopMode : u8 {
struct TweenData {
Entity target_entity{INVALID_ENTITY};
- TweenTarget target_property{TweenTarget::TransformPositionX};
+ TweenTarget target_property{TweenTarget::PositionX};
f32 from_value{0.0f};
f32 to_value{0.0f};
diff --git a/src/esengine/animation/TweenSystem.cpp b/src/esengine/animation/TweenSystem.cpp
index 360647866..b26218819 100644
--- a/src/esengine/animation/TweenSystem.cpp
+++ b/src/esengine/animation/TweenSystem.cpp
@@ -162,56 +162,56 @@ static void markUIAnimOverride(ecs::Registry& registry, Entity entity, u8 flag,
static void applyTweenValue(ecs::Registry& registry, Entity entity, TweenTarget target, f32 value,
std::vector<Entity>& flagged) {
switch (target) {
- case TweenTarget::TransformPositionX:
+ case TweenTarget::PositionX:
if (auto* c = registry.tryGet<ecs::Transform>(entity)) {
c->position.x = value;
markUIAnimOverride(registry, entity, ecs::UINode::ANIM_POS_X, flagged);
}
break;
- case TweenTarget::TransformPositionY:
+ case TweenTarget::PositionY:
if (auto* c = registry.tryGet<ecs::Transform>(entity)) {
c->position.y = value;
markUIAnimOverride(registry, entity, ecs::UINode::ANIM_POS_Y, flagged);
}
break;
- case TweenTarget::TransformPositionZ:
+ case TweenTarget::PositionZ:
if (auto* c = registry.tryGet<ecs::Transform>(entity)) c->position.z = value;
break;
- case TweenTarget::TransformScaleX:
+ case TweenTarget::ScaleX:
if (auto* c = registry.tryGet<ecs::Transform>(entity)) {
c->scale.x = value;
markUIAnimOverride(registry, entity, ecs::UINode::ANIM_SCALE_X, flagged);
}
break;
- case TweenTarget::TransformScaleY:
+ case TweenTarget::ScaleY:
if (auto* c = registry.tryGet<ecs::Transform>(entity)) {
c->scale.y = value;
markUIAnimOverride(registry, entity, ecs::UINode::ANIM_SCALE_Y, flagged);
}
break;
- case TweenTarget::TransformRotationZ:
+ case TweenTarget::RotationZ:
if (auto* c = registry.tryGet<ecs::Transform>(entity)) {
f32 h = value * 0.5f;
c->rotation = glm::quat(std::cos(h), 0.0f, 0.0f, std::sin(h));
markUIAnimOverride(registry, entity, ecs::UINode::ANIM_ROT_Z, flagged);
}
break;
- case TweenTarget::SpriteColorR:
+ case TweenTarget::ColorR:
if (auto* c = registry.tryGet<ecs::Sprite>(entity)) c->color.r = value;
break;
- case TweenTarget::SpriteColorG:
+ case TweenTarget::ColorG:
if (auto* c = registry.tryGet<ecs::Sprite>(entity)) c->color.g = value;
break;
- case TweenTarget::SpriteColorB:
+ case TweenTarget::ColorB:
if (auto* c = registry.tryGet<ecs::Sprite>(entity)) c->color.b = value;
break;
- case TweenTarget::SpriteColorA:
+ case TweenTarget::ColorA:
if (auto* c = registry.tryGet<ecs::Sprite>(entity)) c->color.a = value;
break;
- case TweenTarget::SpriteSizeX:
+ case TweenTarget::SizeX:
if (auto* c = registry.tryGet<ecs::Sprite>(entity)) c->size.x = value;
break;
- case TweenTarget::SpriteSizeY:
+ case TweenTarget::SizeY:
if (auto* c = registry.tryGet<ecs::Sprite>(entity)) c->size.y = value;
break;
case TweenTarget::CameraOrthoSize:
diff --git a/src/esengine/bindings/EditorAPI.generated.cpp b/src/esengine/bindings/EditorAPI.generated.cpp
index 6d06c46c5..f58064be2 100644
--- a/src/esengine/bindings/EditorAPI.generated.cpp
+++ b/src/esengine/bindings/EditorAPI.generated.cpp
@@ -11,7 +11,9 @@
#include <string>
#include <vector>
#include "../ecs/Registry.hpp"
+#include "../animation/TweenData.hpp"
#include "../ecs/components/BitmapText.hpp"
+#include "../ecs/components/BodyType.hpp"
#include "../ecs/components/Camera.hpp"
#include "../ecs/components/Canvas.hpp"
#include "../ecs/components/Collider2D.hpp"
diff --git a/src/esengine/bindings/WebBindings.generated.cpp b/src/esengine/bindings/WebBindings.generated.cpp
index a8fa8ce09..0c8dcfcda 100644
--- a/src/esengine/bindings/WebBindings.generated.cpp
+++ b/src/esengine/bindings/WebBindings.generated.cpp
@@ -10,8 +10,10 @@
#include "../ecs/Registry.hpp"
#include "../math/Math.hpp"
#include "../ui/UITypes.hpp"
+#include "../animation/TweenData.hpp"
#include "../ecs/TransformSystem.hpp"
#include "../ecs/components/BitmapText.hpp"
+#include "../ecs/components/BodyType.hpp"
#include "../ecs/components/Camera.hpp"
#include "../ecs/components/Canvas.hpp"
#include "../ecs/components/Collider2D.hpp"
@@ -129,6 +131,24 @@ EMSCRIPTEN_BINDINGS(esengine_enums) {
.value("Depth", esengine::ecs::ClearFlags::Depth)
.value("ColorAndDepth", esengine::ecs::ClearFlags::ColorAndDepth);
+ enum_<esengine::animation::EasingType>("EasingType")
+ .value("Linear", esengine::animation::EasingType::Linear)
+ .value("EaseInQuad", esengine::animation::EasingType::EaseInQuad)
+ .value("EaseOutQuad", esengine::animation::EasingType::EaseOutQuad)
+ .value("EaseInOutQuad", esengine::animation::EasingType::EaseInOutQuad)
+ .value("EaseInCubic", esengine::animation::EasingType::EaseInCubic)
+ .value("EaseOutCubic", esengine::animation::EasingType::EaseOutCubic)
+ .value("EaseInOutCubic", esengine::animation::EasingType::EaseInOutCubic)
+ .value("EaseInBack", esengine::animation::EasingType::EaseInBack)
+ .value("EaseOutBack", esengine::animation::EasingType::EaseOutBack)
+ .value("EaseInOutBack", esengine::animation::EasingType::EaseInOutBack)
+ .value("EaseInElastic", esengine::animation::EasingType::EaseInElastic)
+ .value("EaseOutElastic", esengine::animation::EasingType::EaseOutElastic)
+ .value("EaseInOutElastic", esengine::animation::EasingType::EaseInOutElastic)
+ .value("EaseOutBounce", esengine::animation::EasingType::EaseOutBounce)
+ .value("CubicBezier", esengine::animation::EasingType::CubicBezier)
+ .value("Step", esengine::animation::EasingType::Step);
+
enum_<esengine::ecs::EmitterShape>("EmitterShape")
.value("Point", esengine::ecs::EmitterShape::Point)
.value("Circle", esengine::ecs::EmitterShape::Circle)
@@ -165,6 +185,11 @@ EMSCRIPTEN_BINDINGS(esengine_enums) {
.value("Ambient", esengine::ecs::LightType::Ambient)
.value("Spot", esengine::ecs::LightType::Spot);
+ enum_<esengine::animation::LoopMode>("LoopMode")
+ .value("None", esengine::animation::LoopMode::None)
+ .value("Restart", esengine::animation::LoopMode::Restart)
+ .value("PingPong", esengine::animation::LoopMode::PingPong);
+
enum_<esengine::ecs::MaskMode>("MaskMode")
.value("Scissor", esengine::ecs::MaskMode::Scissor)
.value("Stencil", esengine::ecs::MaskMode::Stencil);
@@ -215,6 +240,27 @@ EMSCRIPTEN_BINDINGS(esengine_enums) {
.value("Odd", esengine::ecs::TilemapStaggerIndex::Odd)
.value("Even", esengine::ecs::TilemapStaggerIndex::Even);
+ enum_<esengine::animation::TweenState>("TweenState")
+ .value("Running", esengine::animation::TweenState::Running)
+ .value("Paused", esengine::animation::TweenState::Paused)
+ .value("Completed", esengine::animation::TweenState::Completed)
+ .value("Cancelled", esengine::animation::TweenState::Cancelled);
+
+ enum_<esengine::animation::TweenTarget>("TweenTarget")
+ .value("PositionX", esengine::animation::TweenTarget::PositionX)
+ .value("PositionY", esengine::animation::TweenTarget::PositionY)
+ .value("PositionZ", esengine::animation::TweenTarget::PositionZ)
+ .value("ScaleX", esengine::animation::TweenTarget::ScaleX)
+ .value("ScaleY", esengine::animation::TweenTarget::ScaleY)
+ .value("RotationZ", esengine::animation::TweenTarget::RotationZ)
+ .value("ColorR", esengine::animation::TweenTarget::ColorR)
+ .value("ColorG", esengine::animation::TweenTarget::ColorG)
+ .value("ColorB", esengine::animation::TweenTarget::ColorB)
+ .value("ColorA", esengine::animation::TweenTarget::ColorA)
+ .value("SizeX", esengine::animation::TweenTarget::SizeX)
+ .value("SizeY", esengine::animation::TweenTarget::SizeY)
+ .value("CameraOrthoSize", esengine::animation::TweenTarget::CameraOrthoSize);
+
enum_<esengine::ecs::UIDisplay>("UIDisplay")
.value("Flex", esengine::ecs::UIDisplay::Flex)
.value("None", esengine::ecs::UIDisplay::None);
@@ -3070,7 +3116,7 @@ static_assert(offsetof(esengine::ecs::Velocity, angular) == 12, "ABI offset drif
// ABI Hash -- runtime handshake against the SDK bundle
// =============================================================================
-static const char* kEsAbiLayoutHash = "9bc45f6f2153c7c6";
+static const char* kEsAbiLayoutHash = "e59728e2336b5b14";
std::string esengineGetAbiLayoutHash() {
return std::string(kEsAbiLayoutHash);
diff --git a/tools/eht/__main__.py b/tools/eht/__main__.py
index 8aa996974..5b6be8bb7 100644
--- a/tools/eht/__main__.py
+++ b/tools/eht/__main__.py
@@ -84,7 +84,7 @@ def main() -> int:
help='Header declaring Entity::Layout = PackedId<index, gen>')
parser.add_argument('--const-root', type=Path, nargs='+',
default=[Path('src/esengine')],
- help='Roots scanned for ES_CONST boundary constants')
+ help='Roots scanned for ES_CONST and for ES_ENUM outside --input')
parser.add_argument('--verbose', '-v', action='store_true')
# Opt-in native (QuickJS) bindings. Off by default so the standard EHT run and
# its committed *.generated.* files are unchanged; a native build passes this
@@ -129,6 +129,10 @@ def main() -> int:
print(f"Parsing: {input_dir}")
cpp_parser.parse_directory(input_dir)
+ # An enum that crosses says so at its declaration; where it is declared is
+ # not the boundary's business. Scanned rather than listed, as ES_CONST is.
+ cpp_parser.parse_enums_outside(args.const_root, args.input)
+
if cpp_parser.warnings:
cpp_parser.print_warnings()
diff --git a/tools/eht/data.py b/tools/eht/data.py
index 51b056272..9c1c5fd99 100644
--- a/tools/eht/data.py
+++ b/tools/eht/data.py
@@ -48,3 +48,7 @@ class Enum:
values: List[str] = field(default_factory=list)
underlying_type: str = "int"
annotations: Dict[str, str] = field(default_factory=dict)
+ #: Where it was declared. embind registers the enum by its C++ type, so the
+ #: generated TU has to include this — deriving the include from COMPONENTS
+ #: alone worked only while every enum shared a header with one.
+ header_path: str = ""
diff --git a/tools/eht/generators/editor_api.py b/tools/eht/generators/editor_api.py
index 76682e6bb..94b724292 100644
--- a/tools/eht/generators/editor_api.py
+++ b/tools/eht/generators/editor_api.py
@@ -82,6 +82,12 @@ class EditorAPIGenerator:
if comp.header_path and 'src/esengine/' in comp.header_path:
rel = '../' + comp.header_path.replace('\\', '/').split('src/esengine/')[-1]
headers.add(f'#include "{rel}"')
+ # Enums too: one declared away from any component is registered by
+ # its C++ type all the same, and without this the TU cannot name it.
+ for enum in self.enums:
+ if enum.header_path and 'src/esengine/' in enum.header_path:
+ rel = '../' + enum.header_path.replace('\\', '/').split('src/esengine/')[-1]
+ headers.add(f'#include "{rel}"')
lines.extend(sorted(headers))
lines.extend([
diff --git a/tools/eht/generators/embind.py b/tools/eht/generators/embind.py
index 0ca383f4f..dbcdf3dcb 100644
--- a/tools/eht/generators/embind.py
+++ b/tools/eht/generators/embind.py
@@ -79,6 +79,12 @@ class EmbindGenerator:
if comp.header_path and 'src/esengine/' in comp.header_path:
rel = '../' + comp.header_path.replace('\\', '/').split('src/esengine/')[-1]
headers.add(f'#include "{rel}"')
+ # Enums too: one declared away from any component is registered by
+ # its C++ type all the same, and without this the TU cannot name it.
+ for enum in self.enums:
+ if enum.header_path and 'src/esengine/' in enum.header_path:
+ rel = '../' + enum.header_path.replace('\\', '/').split('src/esengine/')[-1]
+ headers.add(f'#include "{rel}"')
headers.add('#include "../ecs/TransformSystem.hpp"')
lines = sorted(headers)
lines.extend([
diff --git a/tools/eht/parser.py b/tools/eht/parser.py
index 09b83c363..e61196d41 100644
--- a/tools/eht/parser.py
+++ b/tools/eht/parser.py
@@ -108,7 +108,7 @@ class CppParser:
content = filepath.read_text(encoding='utf-8')
ns_match = self.RE_NAMESPACE.search(content)
namespace = ns_match.group(1) if ns_match else ""
- self._parse_enums(content, namespace)
+ self._parse_enums(content, namespace, filepath)
self._parse_components(content, namespace, filepath)
RE_COMMENT = re.compile(r'/\*.*?\*/|//[^\n]*', re.DOTALL)
@@ -118,7 +118,7 @@ class CppParser:
"""Blank out C and C++ comments, keeping the text's length and lines."""
return cls.RE_COMMENT.sub(lambda m: re.sub(r'[^\n]', ' ', m.group(0)), text)
- def _parse_enums(self, content: str, namespace: str) -> None:
+ def _parse_enums(self, content: str, namespace: str, filepath: Path) -> None:
for match in self.RE_ENUM.finditer(content):
enum_annotations = self._parse_annotations(match.group(1))
enum_name = match.group(2)
@@ -142,7 +142,8 @@ class CppParser:
self.enums.append(Enum(
name=enum_name, namespace=namespace,
values=values, underlying_type=underlying,
- annotations=enum_annotations
+ annotations=enum_annotations,
+ header_path=str(filepath.as_posix()),
))
def _parse_components(self, content: str, namespace: str, filepath: Path) -> None:
@@ -351,6 +352,31 @@ class CppParser:
except Exception as e:
self.warnings.append(f"Failed to parse {filepath}: {e}")
+ def parse_enums_outside(self, roots, skip) -> None:
+ """`ES_ENUM` in headers that declare no component.
+
+ Where an enum is declared is not the boundary's business: it crosses if
+ it says so. Enum-only, because a component outside the reflected
+ directory would need its bindings, storage and editor surface too —
+ that is a different decision, and this one must not make it quietly.
+ """
+ skipped = {Path(s).resolve() for s in skip}
+ for root in roots:
+ if not Path(root).is_dir():
+ raise SystemExit(f"[FAIL] ES_ENUM scan: no such directory: {root}")
+ for filepath in sorted(Path(root).rglob('*.hpp')):
+ if any(filepath.resolve().is_relative_to(s) for s in skipped):
+ continue
+ try:
+ content = filepath.read_text(encoding='utf-8')
+ except Exception as e:
+ self.warnings.append(f"Failed to read {filepath}: {e}")
+ continue
+ if 'ES_ENUM(' not in content or '#define ES_ENUM' in content:
+ continue
+ ns_match = self.RE_NAMESPACE.search(content)
+ self._parse_enums(content, ns_match.group(1) if ns_match else "", filepath)
+
def print_warnings(self) -> None:
"""Print all accumulated warnings to stderr."""
for w in self.warnings:
diff --git a/tools/lib/contractFacts.mjs b/tools/lib/contractFacts.mjs
index da19895d3..463be08d6 100644
--- a/tools/lib/contractFacts.mjs
+++ b/tools/lib/contractFacts.mjs
@@ -162,18 +162,14 @@ export const FACTS = [
what: 'The tween easing/state/loop/target enums, which cross the boundary as bare numbers.',
surface: 'runtime-wasm-abi',
authors: [
- { path: 'src/esengine/animation/TweenData.hpp', probe: /enum class/, kind: 'semantic' },
- { path: 'sdk/src/animation/TweenTypes.ts', probe: /TweenState/, kind: 'semantic' },
+ { path: 'src/esengine/animation/TweenData.hpp', probe: /ES_ENUM\(stability=/, kind: 'semantic' },
],
- projections: [],
+ projections: ['sdk/src/wasm/wasm.generated.ts'],
verification: [
{ path: 'sdk/tests/cpp-contract.test.ts', how: 'test', probe: /animation tween enums/ },
{ path: 'tools/check-enum-twins.mjs', how: 'test', probe: /owes a pin/ },
],
- digest: null,
- owed: 'hand-copied, outside the directory EHT parses. The pin is a test, not a'
- + ' handshake: a drift ships if the suite is not run.',
- owedUntil: 'digest',
+ digest: { name: 'eht-abi-layout-hash', path: 'tools/eht/abi.py', probe: /ENUM \{enum\.name\}/ },
},
{
id: 'particleColorLut',