Skip to content

feat(codegen): generate SceneSerializer blocks for trivial components (#380) - #450

Merged
drsnuggles8 merged 1 commit into
masterfrom
feature/codegen-scene-serializer
Jun 29, 2026
Merged

drsnuggles8 merged 1 commit into
masterfrom
feature/codegen-scene-serializer

Conversation

@drsnuggles8

Copy link
Copy Markdown
Owner

Summary

Extends OloHeaderTool to generate the per-component scene-YAML serialize/deserialize blocks, collapsing the last big unguarded hand-maintained ECS touch-point (Scene/SceneSerializer.cpp). A component whose field you forgot to hand-serialize used to round-trip through nothing — silent scene-data loss that the old name-only ComponentSerializerCoverageTest couldn't catch. Codegen now prevents the miss.

Fourth slice of the #380 epic (after AllComponents tuple #386, SaveGame lists #405, OnComponentAdded/Removed #413).

Scope — the safe 13 of 99

The generator drives off a new full data-member scan (CollectComponentFields), not the OLO_PROPERTY scan — the serializer persists every field, not just script-exposed ones (e.g. DirectionalLightComponent serializes 9 fields but annotates only 3).

A component is auto-generated iff every data member is a primitive / glm::vec* / std::string and it isn't in the new kComponentsCustomSerialize exclusion set. Anything with a non-trivial field (enum, AssetHandle, Ref<T>, std::vector, nested struct, glm::quat/mat/ivec) is classified non-trivial and skipped automatically — no exclusion entry needed.

The 13 migrated components: CharacterController3D, CircleRenderer, DirectionalLight, PointLight, SpotLight, LocalizedText, LuaScript, Nameplate, NetworkInterest, Perceptible, UICheckbox, UIRectTransform, UIToggle.

Each was verified to be a plain round-trip (parsed-field set == hand-written YAML-key set) before migration. That check also correctly rejected VehicleComponent (a runtime-only RuntimeVehicleToken field the serializer deliberately omits) and ScriptComponent (writes the external C# ScriptField map, not just its ClassName member) — both stay hand-written.

What changed

  • tools/OloHeaderTool/main.cpp — field scanner + classifier (SceneSerType), two emitters, kComponentsCustomSerialize exclusion set, and an empty-output guard (refuses to overwrite with 0 components).
  • Scene/Generated/Scene{Serialize,Deserialize}Components.Generated.inl (new, tracked) — #included at the end of SerializeEntity / DeserializeEntityComponents. Floats validated via TryReadFiniteF32 / glm Decode; a missing key keeps the constructor default.
  • SceneSerializer.cpp — 26 hand-written blocks removed, 2 includes added.
  • ComponentSerializerCoverageTest.cpp — existence check now spans SceneSerializer.cpp ∪ the generated .inl; new NoComponentIsBothHandWrittenAndGenerated disjointness test fails loudly on a double-emit.
  • ComponentRoundTripTest.cpp — 3 new tests (LuaScript/string, Perceptible/i32, Nameplate/mixed-vec); the other 10 migrated components already had round-trip tests.
  • CLAUDE.md — touch-point + OloHeaderTool docs updated.

Contract / safety

Every component is handled by exactly one of the hand-written serializer or the generated .inl:

  • drop → existence check fails (name in neither corpus)
  • double-emit → disjointness check fails (duplicate YAML key on write / AddComponent<T> twice on read)

A new trivial component is auto-serialized with zero edits; a new complex one fails the coverage test until hand-written.

Testing

⚠️ This worktree's environment cannot link the full OloEngine-Tests binary (pre-existing: ffmpeg source-build + assimp .rc-under-clang-cl both fail), so the GoogleTest run is left to CI.

Validated locally with the real clang-cl C++23 toolchain:

  • All four changed/new translation units compile cleanly.
  • OloHeaderTool builds, runs, and emits exactly the intended 13-component output (other generated files unchanged).
  • Both generated .inl are clang-format-stable.

Deferred (follow-up)

Complex-field serialization (asset handles, Ref<T>, enums, std::vector, nested structs, setter-only SceneCamera, and trivial components needing custom range-clamp/Sanitize validation) remains hand-written. A follow-up issue will track the rest of #380's SceneSerializer work.

🤖 Generated with Claude Code

- Implemented unit tests for LuaScriptComponent, PerceptibleComponent, and NameplateComponent to ensure they survive YAML serialization and deserialization.
- Updated ComponentSerializerCoverageTest to include checks for generated serialization and deserialization blocks, ensuring all components are handled correctly.
- Introduced a disjointness test to verify that components are serialized by either the hand-written serializer or the generated code, but not both.
- Enhanced OloHeaderTool to generate serialization and deserialization blocks for trivial components, ensuring proper handling of all component fields.
- Added a set of components to be kept hand-written despite being trivial, to maintain specific serialization logic.
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@drsnuggles8, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 58 minutes and 33 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 166ec219-f311-4cbe-bec7-7236b987a2fe

📥 Commits

Reviewing files that changed from the base of the PR and between 5e485c3 and e5af2a1.

⛔ Files ignored due to path filters (2)
  • OloEngine/src/OloEngine/Scene/Generated/SceneDeserializeComponents.Generated.inl is excluded by !**/generated/**
  • OloEngine/src/OloEngine/Scene/Generated/SceneSerializeComponents.Generated.inl is excluded by !**/generated/**
📒 Files selected for processing (5)
  • CLAUDE.md
  • OloEngine/src/OloEngine/Scene/SceneSerializer.cpp
  • OloEngine/tests/ComponentRoundTripTest.cpp
  • OloEngine/tests/ComponentSerializerCoverageTest.cpp
  • tools/OloHeaderTool/main.cpp

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@drsnuggles8

Copy link
Copy Markdown
Owner Author

Deferred complex-field SceneSerializer codegen is now tracked in #451. Source issue #380 commented (umbrella, not closed).

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@drsnuggles8
drsnuggles8 merged commit 5b65abc into master Jun 29, 2026
9 of 10 checks passed
@drsnuggles8
drsnuggles8 deleted the feature/codegen-scene-serializer branch June 29, 2026 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant