Prey flee, and what it costs
S3 of the actor-interaction epic · commit 763673440853 ·
crates/microverse_shell/examples/demo.rs
The rule, one prey at a time
Each frame, flee measures one distance per prey: to the player,
flat across the field, from last frame's resolved matrices. Inside the notice
radius the prey gets a velocity straight away from the player. Outside it gets zero.
It writes only a velocity, so step_actors moves it, as it moves the chasers.
At the edge (dashed, the outermost squares at ±10), an axis whose step would cross the edge outward is dropped, and the other axis is kept. So a prey slides along an edge and stops in a corner. It isn't clamped, because a clamp snaps a prey that is already outside the field back in within one frame.
Where it runs in the frame
It reads world matrices and writes only velocities, so it goes before anything that writes a local, the same rule as the chasers.
Brute force at the actor cap
targeting_and_fleeing_at_actor_capacity_cost_a_sliver_of_a_frame fills
the actor pool (ACTOR_CAPACITY = 48) with prey, all in range and all in notice:
the most work either loop can be given. Best of 1000 runs:
| build | targeting / press | fleeing / frame | of a 60 fps frame |
|---|---|---|---|
| debug | 3.2–3.5 µs | 3.6–3.8 µs | 0.04 % |
| release | 0.26–0.32 µs | 0.41–0.49 µs | 0.005 % |
Against the test's 1 % bar (167 µs), debug's worst case, drawn to scale:
So no spatial grid. The test is what would say when one is needed.
What the tests hold, and what they leave free
At jb55's request, the flee test pins no tuning. It runs the player through a prey by the edge and asserts two things: the prey ran, and no prey left the field. Speed, direction and notice radius can change and the test still passes.
| change | result |
|---|---|
| no edge check | fails: off the field at x = 10.000006 |
zero speed, or flee not called | fails: the prey ran |
200 µs spin in flee | fails: the cost test |
| ungated write of the player | fails: idle-frame test |
| prey at 14 u/s (faster than the player) | passes, as tuning should |
| notice radius 6 | passes; the idle-frame test now counts the prey running that frame |
- Not played in a window: there's no display here.
- A notice radius of 12 sends every prey running at boot, which breaks S2's frostbolt flight timing and the chaser test. Both assume the prey stand still. This is flagged on the epic and not fixed here.
- Idle prey stand. They don't wander, and chill doesn't slow them yet (S4).
- The timings are from one machine. Only the 1 % bar is asserted.
- miri was skipped (
arena.rsuntouched), and so was the meter-feature run.