Repository navigation
Reflection Polymorphism Refactoring Plan
Audience: Programmers
Thread Context: Reflection registration happens at startup (TypeRegistry, ComponentFactory). Field get/set runs on whichever thread calls it (inspector = main thread; replication = network thread). No special threading guarantees beyond the subsystems that consume reflection.
Platform/Backend Scope: Cross-platform. The reflection core (
Core/Reflection.h,Core/ReflectionSerializer.h) is pure CPU and compiles everywhere.
SparkEngine has a solid hand-rolled reflection foundation in Core/Reflection.h (TypeRegistry, TypeInfo, FieldInfo, ComponentFactory, SPARK_REFLECT_* macros). The goal of this plan was to eliminate manual per-type boilerplate across eight subsystems — inspector rendering, scene serialization, save/load, network replication, materials, AngelScript binding, settings, and assorted polymorphism cleanup — by expanding reflection coverage toward ~95%, with no external library and full backward compatibility.
Overall: Substantially Completed. Most phases Done; a few Partial/Deferred items remain.
| Phase | Status | Evidence |
|---|---|---|
| 1 — Inspector | Done |
FieldInfo carries tooltip, category, isAssetPath, replicated, serialized, enumNames, visibleWhenField (confirmed in Reflection.h); RenderReflectedFields migrated many renderers |
| 2 — Scene serialization | Done |
Core/ReflectionSerializer.h exists; data-driven type map replaces switch cases |
| 3 — Save/Load | Done (practical) | Hand-written serializers removed for the common components; a few with custom key formats intentionally kept |
| 4 — Network replication | Prep done |
FieldInfo::replicated exists (Reflection.h:95) and is consumed (Reflection.h:171); existing ReplicatedField<T> system kept |
| 5 — Materials | Partial |
PBRProperties + render state registered; [Advanced]/[Textures]/[Variants] sections stay manual |
| 6 — AngelScript | Done |
AutoRegisterReflectedTypes() + generic getComponentField/setComponentField/hasComponent in AngelScriptEngine.cpp
|
| 7 — Settings | Done | Settings groups migrated to reflection-driven read/write |
| 8B — UI bindings | Done | Templated UITypedBinding<T> replaces the four concrete classes |
| 8C — Physics backend | Deferred |
IPhysicsBackend.h exists but PhysicsSystem does not inherit it (confirmed in the header doc); raw-ID vs. named-body API mismatch |
| 8D — Editor panels | Done |
PanelCategory enum + GetCategory(); View menu groups by category |
| Components | Done | ~73 SPARK_REFLECT_TYPE registrations in ComponentReflection.cpp (up from 32) |
| Conditional visibility | Done |
FieldInfo::visibleWhenField/visibleWhenValue + macro |
| Live editing / undo | Done | Reflected edits push LambdaCommand through CommandHistory
|
Scene _properties block |
Done |
ComponentToJSON/JSONToComponent emit/consume named-field JSON |
Only Phase 5 (Materials) is genuinely partial and Phase 8C (Physics backend) is genuinely deferred; everything else is functionally complete.
| Component | File | Status |
|---|---|---|
TypeRegistry singleton |
Core/Reflection.h |
Production |
TypeInfo (name, size, alignment, base, fields, version) |
Core/Reflection.h |
Complete |
FieldInfo (name, type, offset, size, range, attributes) |
Core/Reflection.h |
Complete with attributes |
ComponentFactory (add/has/remove by string) |
Core/Reflection.h |
Production |
SPARK_REFLECT_TYPE/FIELD/END macros |
Core/Reflection.h |
Production |
SetFieldFromString / GetFieldAsString
|
Core/ComponentReflection.cpp |
Production |
ReflectionSerializer |
Core/ReflectionSerializer.h |
Production (the Phase 2 artifact) |
CheckedCast<To>(From) |
Core/SafeCast.h |
Production |
EventBus type dispatch |
Utils/EventBus.h |
Uses std::type_index
|
FieldInfo was extended with the editor/serialization attributes; RenderReflectedFields() handles category grouping, tooltips, enum dropdowns, vec2/3/4, asset pickers (isAssetPath), and conditional visibility. Reflected edits flow through CommandHistory for automatic undo/redo.
ReflectionSerializer.h iterates TypeInfo.fields to serialize/deserialize any reflected type. The per-component switch(ComponentType) cases were replaced by data-driven TypeRegistry iteration shared by both JSON and binary paths.
Reflected serializers cover the common components; four hand-written ones (MeshRenderer, Camera, ActiveComponent, AudioSourceComponent) were removed. Components with custom short-key/comma-vector formats were intentionally kept.
FieldInfo::replicated exists and is consumed during field iteration. The plan to fully replace EntityReplicator's manual indices was de-scoped because the existing ReplicatedField<T> system is already well-designed.
PBRProperties and the render-state struct are reflection-driven. [Advanced], [Textures], and [Variants] sections (maps, not flat structs) remain manual.
AutoRegisterReflectedTypes() runs at script-engine init; generic getComponentField/setComponentField/hasComponent let scripts reach any reflected component by name. Manual bindings kept for complex APIs (math, physics queries, input).
Settings groups migrated to a reflection-driven read/write loop, collapsing hundreds of manual read/write lines into one-liners plus registrations.
-
8B (UI bindings): Done —
UITypedBinding<T>with backward-compatible aliases. -
8C (Physics backend): Deferred —
IPhysicsBackend(rawuint32_tIDs) mismatchesPhysicsSystem's higher-level named-body /PhysicsBody*API; would need an adapter layer, not simple inheritance.PhysicsSystemstill does not inheritIPhysicsBackend. -
8D (Editor panels): Done —
PanelCategoryenum,GetCategory(), dynamic View-menu grouping.
-
Original entry date: 2026-04-12 (
reflection-polymorphism-refactoring-plan-2026-04-12.md, type: Plan) - Verified against codebase 2026-06-08.
- Status bullets:
-
Foundation confirmed —
Core/Reflection.handCore/ReflectionSerializer.hboth present;FieldInfo::replicatedatReflection.h:95, consumed at:171. -
~73
SPARK_REFLECT_TYPEregistrations inComponentReflection.cpp(plan started near 32–40). -
AngelScript auto-registration confirmed —
AutoRegisterReflectedTypes/getComponentField/setComponentFieldpresent inAngelScriptEngine.cpp. -
Phase 8C still deferred —
IPhysicsBackend.hself-documents thatPhysicsSystemuses it directly but does not inherit it. -
Phase 5 still partial — material
[Advanced]/[Textures]/[Variants]sections remain manual.
-
Foundation confirmed —
-
Jolt Physics Integration — Phase 8C context (
IPhysicsBackend) - GPU/CPU Separation Plan
Published from 2b03dc797148. Edit the canonical source in wiki/.
- Documentation
- Docs route
- Wiki index
- Guides
- Tutorials
- Samples
- Examples
- API Reference
- API route
- Reference
- Build Guide
- Dependencies
- FAQ
- Changelog
- Roadmap
- Contributing
- Code of Conduct
- Home
- FAQ
- Getting Started
- Quick-Start Tutorial
- Making Your First Game
- Making Your First Multiplayer Game
- Artist Workflow Guide
- Editor Walkthrough
- Migration Guide
- How SparkEngine Works
- Architecture Overview
- Engine Architecture Flowchart
- Creating a Game Module
- Game Modules (catalog)
- Entity Component System
- Rendering and Graphics
- Physics
- Cloth Simulation
- Audio
- Input System
- Camera System
- Scripting with AngelScript
- Visual Scripting
- AI and Navigation
- Animation
- 2D Systems
- Networking
- Dedicated Server
- Multiplayer Quick Start
- Area Server Architecture
- Scene Management
- Large World Support
- Collaborative Editing
- Coroutine System
- Event System
- Event Response System
- Job System
- UI System
- UI Layout Extensions
- Localization
- Dialogue System
- Destruction System
- Replay System
- Achievement System
- Loading System
- Mod System
- Content Delivery
- Tween System
- Memory Integrity
- Gameplay Systems
- Terrain and Procedural Generation
- Save System
- Persistence System
- Day Night Cycle and Weather
- Cinematic Sequencer
- Runtime Prefabs
- SparkEditor
- Editor Tutorials
- SparkConsole
- SparkDaemon
- Shader Pipeline
- Asset Pipeline
- Asset Validation
- Asset Migration
- Game Packaging
- Online Services
- DataTable System
- Loot and Crafting System
- CSG System
- Font System
- Timer Manager
- Movie Render Pipeline
- HLOD and World Partition
- Remote Debug System
- Selection Manager
- Asset Dependency Graph
- Editor Automation
- File Watcher
- Project Templates
- System Requirements
- VR Support
- Mobile Platform
- Accessibility
- Platform Input
- Platform Certification
- Cross-Compilation: Wine Testing
- RHI Abstraction Layer
- D3D11 Backend
- D3D12 Backend
- Vulkan Backend
- OpenGL Backend
- Metal Backend
- DXR Raytracing
- Hybrid Ray Tracing
- Upscaling (DLSS/FSR)
- Render Graph
- Shader Graph
- GPU Particles
- GPU-Driven Rendering
- Volumetric Fog
- Volumetric Clouds
- Global Illumination
- Virtual Texturing
- Water Rendering
- Clustered Lighting
- Material System
- Post-Processing
- Shadow System
- Particle System
- Decal System
- Sky and Atmosphere
- Foliage System
- Mesh Shaders
- Neural Rendering
- Configuration Reference
- Performance Tips
- Benchmark Framework
- Threading Model
- Fuzz Policy and Parser Security
- Memory Safety
- Memory Management Patterns
- Build System and CMake Modules
- Profiler and Debugging
- Performance Profiling Guide
- Telemetry System
- Crash Reporting
- Golden Image Testing
- Utilities
- Testing
- Fuzz Policy and Parser Security
- Codebase Statistics
- Codebase Health
- Error Handling Patterns
- Hot Reload Overview
- Troubleshooting
- Contributing
- Workflow Patterns
- Build Optimizations
- CI Reproducible Builds
- GitHub API and PR Checks
- Git Rebase Conflicts
- Clang-Format
- Code Quality Violations
- AI Bloat Pattern
- MinGW + Wine Cross-Compilation
- Live Editor Testing
- Engine & Renderer Landscape
- DuetOS Portability Catalog
- Five-Engine Analysis
- Eleven-Engine Analysis
- ThorVG / Unity Graphics Analysis
- Advanced Techniques Catalog
- Third-Party Library Evaluation
- Engine Viability Evaluation
- Engine Feature Recommendations
- Project Recommendations
- Mac Compatibility Analysis
- Codebase Observations
- Codebase Bloat Audit
- Test Suite Audit
- Documentation Coverage Audit
- ThirdParty Dependencies Audit
- Load Test Baseline
- Gameplay Systems Status
- SparkGame Module Status
- Stub and Abandoned Features
- Memory Integrity System
- Memory Safety Evaluation
- Hardware Acceleration Systems
- Jolt Physics Integration
- GPU/CPU Separation Plan
- Daemon Services Architecture
- Reflection & Polymorphism Refactoring Plan
- SparkBuild In-Tree
- Wine No-JobSystem Breakthrough
- Wine Role and Fallback Tiers