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.

Drag the player (blue).

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

camera_controls→follow_the_view→fight→flee→behave→step_actors→markers, field

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:

buildtargeting / pressfleeing / frameof a 60 fps frame
debug3.2–3.5 µs3.6–3.8 µs0.04 %
release0.26–0.32 µs0.41–0.49 µs0.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.

changeresult
no edge checkfails: off the field at x = 10.000006
zero speed, or flee not calledfails: the prey ran
200 µs spin in fleefails: the cost test
ungated write of the playerfails: idle-frame test
prey at 14 u/s (faster than the player)passes, as tuning should
notice radius 6passes; the idle-frame test now counts the prey running that frame
Not verified