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
feat(eht): a component had nowhere to say what is true of the component
esengine93f0124d62b9
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1a84ed94c..c24c4dfb6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,6 +12,21 @@ Version numbers here track the **Estella release** — the engine + editor + SDKshipped together, matching the Git tags and GitHub Releases. The SDK is notpublished separately; it ships inside the editor.+## [Unreleased]++### Added++- **A component says whether it draws, where it is defined.** Field metadata has+ been authored at the field for a while (`ES_PROPERTY(min=…, tooltip=…)`); the+ component itself had no such place, so anything true of a whole component was+ re-stated wherever it was needed. `ES_COMPONENT` now takes annotations too —+ `renderable=<field>` naming the bool that gates its drawing, and `transient` for+ state a scene must not save — and a project's own component declares the same+ thing as `renderableField` / `transient` in `defineComponent`'s metadata. Declare+ it and the entity's eye, `setEntityVisible` and scene sleep/wake all reach your+ component and restore it afterwards. A name that matches no bool field on the+ component fails the build rather than reading as "draws nothing".+## [0.45.0] - 2026-08-07### Addeddiff --git a/src/esengine/core/Reflection.hpp b/src/esengine/core/Reflection.hppindex b536229be..5c2cbd6fb 100644--- a/src/esengine/core/Reflection.hpp+++ b/src/esengine/core/Reflection.hpp@@ -26,15 +26,20 @@* to automatically create JavaScript/TypeScript bindings. Place this* macro immediately before the struct/class definition.*+ * `ES_COMPONENT(renderable=<field>, transient)` states what is true of+ * the COMPONENT, as ES_PROPERTY does for a field; both realms read it out+ * of the generated `COMPONENT_META`. `renderable` names the bool gating+ * this component's drawing — a hard EHT error unless that bool exists.+ ** @code- * ES_COMPONENT()- * struct Transform {+ * ES_COMPONENT(renderable=enabled)+ * struct Sprite {* ES_PROPERTY()- * glm::vec3 position{0.0f};+ * bool enabled{true};* };* @endcode*/-#define ES_COMPONENT()+#define ES_COMPONENT(...)/*** @brief Mark a field as a property that should be exposed to scriptsdiff --git a/tools/eht/data.py b/tools/eht/data.pyindex 9ddf968e0..c31b95687 100644--- a/tools/eht/data.py+++ b/tools/eht/data.py@@ -20,6 +20,9 @@ class Component:namespace: strproperties: List[Property] = field(default_factory=list)header_path: str = ""+ #: ES_COMPONENT(...) annotations — metadata about the component itself, as+ #: `Property.annotations` is about one field.+ annotations: Dict[str, str] = field(default_factory=dict)# A C++ method every JS read of the component must run first. Transform's worlddiff --git a/tools/eht/generators/metadata.py b/tools/eht/generators/metadata.pyindex 15653fdca..4a9858816 100644--- a/tools/eht/generators/metadata.py+++ b/tools/eht/generators/metadata.py@@ -316,6 +316,19 @@ class MetadataGenerator:' * these over `defaults`; `defaults` alone is the runtime ctor truth.',' */',' editorDefaults?: Record<string, unknown>;',+ ' /**',+ ' * The bool field that gates this component\'s part in the entity\'s',+ ' * visibility, authored `renderable=<field>` at the C++ ES_COMPONENT',+ ' * site. Absent = nothing of this component is hidden by hiding its',+ ' * entity. ONE answer for both realms: the runtime folds visibility',+ ' * onto these fields, and the editor\'s eye reaches exactly them.',+ ' */',+ ' renderableField?: string;',+ ' /**',+ ' * Runtime-only state that must never persist, authored `transient` at',+ ' * the C++ ES_COMPONENT site — scene serialization omits it.',+ ' */',+ ' transient?: boolean;',' assetFields: AssetFieldMeta[];',' skeletal?: SkeletalFieldMeta;',' entityFields: string[];',@@ -368,6 +381,12 @@ class MetadataGenerator:lines.append(f' {fname}: {val},')lines.append(' },')+ renderable_field = comp.annotations.get('renderable')+ if renderable_field:+ lines.append(f" renderableField: '{renderable_field}',")+ if 'transient' in comp.annotations:+ lines.append(' transient: true,')+if asset_fields:parts = ', '.join(f"{{ field: '{f['field']}', type: '{f['type']}' as AssetFieldType }}"diff --git a/tools/eht/parser.py b/tools/eht/parser.pyindex e8b9cc947..1f1c61714 100644--- a/tools/eht/parser.py+++ b/tools/eht/parser.py@@ -19,7 +19,11 @@ class CppParser:"""Parses C++ headers and extracts component/enum definitions."""RE_NAMESPACE = re.compile(r'namespace\s+([\w:]+)\s*\{')- RE_COMPONENT = re.compile(r'ES_COMPONENT\s*\(\s*\)\s*struct\s+(\w+)')+ # Same annotation group as RE_PROPERTY (see below), so ES_COMPONENT takes+ # component-level metadata by the same grammar its fields take theirs.+ RE_COMPONENT = re.compile(+ r'ES_COMPONENT\s*\(\s*((?:[^)"]|"[^"]*")*?)\s*\)\s*struct\s+(\w+)'+ )RE_ENUM = re.compile(r'ES_ENUM\s*\(\s*\)\s*enum\s+class\s+(\w+)(?:\s*:\s*(\w+))?')# The annotation group `(?:[^)"]|"[^"]*")*?` accepts runs of non-paren chars# OR whole quoted strings, so a `)` or `,` *inside quotes* (e.g. a tooltip) does@@ -61,6 +65,12 @@ class CppParser:'editor_default',})NUMERIC_ANNOTATIONS = frozenset({'min', 'max', 'step'})++ # ES_COMPONENT annotation vocabulary — metadata about the component itself,+ # validated by the same rules (unknown key = warning, malformed known key =+ # hard error). See Reflection.hpp for what each one means.+ COMPONENT_FLAG_ANNOTATIONS = frozenset({'transient'})+ COMPONENT_KV_ANNOTATIONS = frozenset({'renderable'})VALID_ASSET_TYPES = frozenset({'texture', 'material', 'font', 'audio',# A skeletal runtime's two halves. Recognised as a PAIR (see@@ -117,7 +127,8 @@ class CppParser:def _parse_components(self, content: str, namespace: str, filepath: Path) -> None:for match in self.RE_COMPONENT.finditer(content):- comp_name = match.group(1)+ comp_annotations = self._parse_annotations(match.group(1))+ comp_name = match.group(2)body_start = content.find('{', match.end())if body_start == -1:continue@@ -134,7 +145,8 @@ class CppParser:body = content[body_start:body_end]component = Component(name=comp_name, namespace=namespace,- header_path=str(filepath.as_posix())+ header_path=str(filepath.as_posix()),+ annotations=comp_annotations)for prop_match in self.RE_PROPERTY.finditer(body):@@ -158,6 +170,7 @@ class CppParser:)self._validate_component_refs(component, filepath)+ self._validate_component_annotations(component, filepath)self.components.append(component)def _validate_annotations(self, comp_name: str, prop_name: str,@@ -187,6 +200,37 @@ class CppParser:known = ', '.join(sorted(self.VALID_ASSET_TYPES))self.warnings.append(f"{loc}: unknown asset type '{asset_type}' (known: {known})")+ def _validate_component_annotations(self, component: Component, filepath: Path) -> None:+ """Validate ES_COMPONENT annotations against the component's own fields.++ `renderable=<field>` must name a bool field on this struct. A name that+ matched nothing would make the component read as not-renderable — it would+ stay drawn when its entity is hidden or its scene sleeps, which is the+ silent failure the annotation exists to end.+ """+ loc = f"{filepath}:{component.name}"+ bool_fields = {p.name for p in component.properties if p.cpp_type == 'bool'}++ for key, value in component.annotations.items():+ if key in self.COMPONENT_FLAG_ANNOTATIONS:+ continue+ if key not in self.COMPONENT_KV_ANNOTATIONS:+ known = ', '.join(sorted(+ self.COMPONENT_FLAG_ANNOTATIONS | self.COMPONENT_KV_ANNOTATIONS+ ))+ self.warnings.append(+ f"{loc}: unknown ES_COMPONENT annotation '{key}' (known: {known})"+ )+ continue+ # A kv annotation written as a bare flag parses as the string 'true',+ # which names no field — say what it needs rather than what it got.+ if value == 'true':+ self.errors.append(f"{loc}: {key} needs a field — {key}=<bool field>")+ elif value not in bool_fields:+ self.errors.append(+ f"{loc}: {key}='{value}' names no bool field on this component"+ )+def _validate_component_refs(self, component: Component, filepath: Path) -> None:"""Component-level checks that need the full field set — currently`invalidates=<field>` must name a sibling property (else the generateddiff --git a/tools/eht/test_validation.py b/tools/eht/test_validation.pyindex 73307f81a..9e4da95f7 100644--- a/tools/eht/test_validation.py+++ b/tools/eht/test_validation.py@@ -1,4 +1,4 @@-"""Plain-python tests for ES_PROPERTY annotation validation (RC9-1 P0).+"""Plain-python tests for ES_PROPERTY / ES_COMPONENT annotation validation.No pytest dependency — run: python3 tools/eht/test_validation.pyExits non-zero on the first failing case.@@ -13,7 +13,7 @@ from eht.parser import CppParser # noqa: E402HEADER = """namespace esengine::ecs {{-ES_COMPONENT()+ES_COMPONENT({comp})struct C {{{body}}};@@ -23,18 +23,18 @@ struct C {{_failures = 0-def _parse(body: str) -> CppParser:+def _parse(body: str, comp: str = '') -> CppParser:p = CppParser()with tempfile.TemporaryDirectory() as d:f = Path(d) / 'C.hpp'- f.write_text(HEADER.format(body=body), encoding='utf-8')+ f.write_text(HEADER.format(body=body, comp=comp), encoding='utf-8')p.parse_file(f)return p-def expect(name: str, body: str, *, errors: int, warnings_at_least: int = 0) -> None:+def expect(name: str, body: str, *, errors: int, warnings_at_least: int = 0, comp: str = '') -> None:global _failures- p = _parse(body)+ p = _parse(body, comp)problems = []if len(p.errors) != errors:problems.append(f"errors: got {len(p.errors)} want {errors} -> {p.errors}")@@ -191,6 +191,46 @@ number_is('negative', '-3', '-3')number_is('nothing', '', '0')number_is('not a number', 'junk', '0')+# ── ES_COMPONENT annotations: metadata about the component itself ──+FLAG = 'ES_PROPERTY()\n bool enabled = true;'++expect('renderable names a bool field',+ FLAG, errors=0, comp='renderable=enabled')+expect('renderable naming no field is an error',+ FLAG, errors=1, comp='renderable=nope')+expect('renderable naming a non-bool field is an error',+ 'ES_PROPERTY()\n float layer = 0.0f;', errors=1, comp='renderable=layer')+expect('bare renderable is an error (the gating field is the point)',+ FLAG, errors=1, comp='renderable')+expect('transient is a flag, not a kv',+ FLAG, errors=0, comp='transient')+expect('both annotations on one component',+ FLAG, errors=0, comp='renderable=enabled, transient')+expect('unknown component annotation is a warning, not an error',+ FLAG, errors=0, warnings_at_least=1, comp='bogus')+expect('no annotations still parses (every component before this change)',+ FLAG, errors=0)+++def component_meta_emits(name: str, comp: str, body: str, expect_snippet: str) -> None:+ global _failures+ p = _parse(body, comp)+ from eht.generators.metadata import MetadataGenerator+ out = MetadataGenerator(p.components, []).generate()+ if expect_snippet not in out:+ _failures += 1+ print(f"FAIL {name}")+ print(f" {expect_snippet!r} not found in output")+ else:+ print(f"ok {name}")+++component_meta_emits('renderable reaches COMPONENT_META',+ 'renderable=visible', 'ES_PROPERTY()\n bool visible = true;',+ "renderableField: 'visible',")+component_meta_emits('transient reaches COMPONENT_META',+ 'transient', FLAG, 'transient: true,')+if _failures:print(f"\n{_failures} case(s) failed")raise SystemExit(1)