Plain C++ Structs and Loops: Build the Baseline¶
Begin with a vector of records and a direct loop. This is a complete solution to the initial requirements, not a deliberately broken design waiting for ECS.
Simulation Contract¶
A positive finite dt moves live moving bodies, ages expiring bodies, then removes expired bodies. Rendering selects visible survivors. Visibility never gates movement.
Position and velocity must be finite at construction; remaining lifetime must be finite when enabled. Initially expired bodies are omitted. Inactive velocity and lifetime are normalised in observations so irrelevant stored values do not affect comparisons.
Snapshots own their values. Do not infer identity from snapshot order or keep pointers into internal vectors.
Build the Downloadable Project¶
Use a C++17 compiler and CMake. The examples use only the standard library and do not require Raspberry Pi hardware.
Download these files into one directory:
Later scenarios are in the same project; optional experiments are off by default. From the source repository:
For a downloaded directory, replace the -S path with that directory. Expected output:
Read Only the Baseline First¶
In baseline.hpp, inspect BasicSeed, validate_basic, Baseline::step, and Baseline::states. The record contains position, velocity, three capability flags, and remaining lifetime.
Here is the actual step method inside Baseline:
auto& updates the owned record, not a copy. remove_if gathers survivors at the beginning of the vector; erase removes the trailing range. Deletion follows traversal so the loop does not retain an iterator to an element it just erased.
The motion equation is:
At x=0 with vx=2, dt=0.25 produces x=0.5. A stationary body's position stays unchanged even if stored velocity is nonzero.
Expiration follows movement: remaining=0.5 receives two dt=0.25 updates before removal. Reversing the order changes behaviour.
Test Before Refactoring¶
Run design_tests baseline. It covers eight combinations of movement, visibility, and lifetime, initial expiration, calculated motion, and rejection of invalid time steps.
Invalid-time checks include zero, negative values, infinity, and NaN. Later groups repeat them across alternative worlds. Test checks throw; they are not assertions removed by Release builds.
Finite inputs do not promise protection from floating-point overflow under arbitrarily large repeated updates. Our fixtures stay within ordinary finite ranges; a production numeric policy would be another requirement.
What This Design Makes Easy¶
To follow one body, read one record and one loop. Ownership and deletion are local. The costs are mixed-purpose fields and capability branches; those may be acceptable for a small fixed simulation.
No benchmark establishes a speed advantage or disadvantage.
Exercise¶
Make a moving baseline body invisible: its trajectory should not change. Then give it a lifetime ending exactly at the step boundary and confirm its final movement.
Next: add a real requirement before comparing architectures.