NeedleField.component
README.md
NeedleField
The mechanic of THE LAST STRAW. Attaches to the NeedleField director entity in
scenes/main.scene. It needs nothing from another slice: it reads and writes
game.shared.game's state and event bus, and the HUD, the hands and the audio
listen to it there.
What it draws
All 5600 needles are one mesh in one instanced draw
(renderer.mesh.drawInstanced) placed by a GPU buffer of mat4s
(substrate.createBuffer, type = "mat4", len = 5600). Nothing here is an
entity per needle. Two further one-instance draws reuse the same mesh: a golden
sleeve marking the needle under the crosshair, and the Last Straw itself.
A needle moves by rewriting the 16 floats that belong to it; the buffer is only
written when something actually changed, so a still field costs no copy per
frame (renderer.uploadStats() stays flat while nothing moves).
The needle mesh is generated in game.field.field (six-sided shaft, ground
point, pierced eye) rather than with mesh_gen: a needle has no detail a
generator would add, and 5600 copies of a cheap mesh is what keeps the draw
inside its budget.
What it decides
- Target — one ray from the player camera, intersected with each bale's face
plane, resolved to a
(col, row)cell with a 9 cm aim tolerance, then walked from the front layer inward to the first needle still seated. Ten cheap tests a frame, no physics. Written toGAME.state.target. - Grip — LMB pulls the target along its axis over 0.3 s, then it is in the
hand (
GAME.state.held,"needle.held"). Release drops it to a resting place on the floor that is deterministic in the needle's index (so a save restores every one exactly), emits"needle.dropped"and"needle.pulled", and raisesGAME.state.moved. - Codex — a witness needle unlocks its fragment on the pull that removes it
(
"codex.unlocked"). - Proximity — camera distance to
GAME.strawSite(seed), smoothed intoGAME.state.attunement. Nothing is emitted per frame; the HUD polls. - The straw — seated at the far layer of its cell, so the needles in front
of it must come out before it shows. Pulling it sets
found,phase = "found"and fires"straw.found". - Save —
runtime_data.player(runtime_data.localId())undersave/seed,save/moved,save/found,save/codex,save/removed(run-length encoded) andsave/at. Written on every eighth pull, onstraw.found, and on the way out of the world, so a needle pulled in a short session is still a needle pulled."save.changed"tells the HUD to blink SAVED.
Input is accepted only while GAME.state.phase == "playing".
How it reads the player
The camera is camera.main() (falling back to the entity named CameraRig),
whose pose gives the ray. LMB is Zin.state.mouseButtonPressed("left") /
mouseButtonReleased("left"), the documented per-frame snapshot read. It never
activates an input map of its own, so it cannot take the pointer from the
camera controller.
A note on GAME.strawSite
strawSite(seed) names the bale and cell the straw is buried in and returns the
cell's front layer. This component keeps the cell and seats the straw at the
far layer of it through the module's own needleSeat, which is what the spec
asks for ("buried", "every needle in front of it must come out first"). If
strawSite itself starts returning the back layer, game.field.field's
strawSeat is the one place to change.