Split The code is public; the app answers only to the crew.
A click shorter than a frame still fires: latch input edges instead of sampling them #9
Sign in to join this conversation.
Split The code is public; the app answers only to the crew.
Make a press count even when it starts and ends between two frames, so firing, jumping and using feel immediate rather than occasionally ignored.
createControlsinsrc/client/input.tsmutatescontrols.inputon every key or pointer event, andsrc/client/main.tsreads that object once a frame. A press that begins and ends inside one frame is therefore invisible:fireis set true and back to false before the loop looks. That is a real lost shot on a fast tap with a pistol, and on touch it is the common case —attachButtonsalready works around it forjump,reloadandbuywith a 120 mssetTimeout, and does nothing forfireanduse, which are exactly the two that matter. The workaround should go; the loop should be told what was pressed, not what is held.Keep the shape: the latch is its own concept, so put it in a small headless module (
src/client/press.tsis the obvious name) that takes edges in and gives a frame's worth of intent out, and test that module —input.tsitself needs a DOM and is one of the modules the README says is untested.Done looks like
walkandduckare level-triggered, not edge-triggered.fire,jump,useandreloadgo through the latch; thesetTimeoutworkaround inattachButtonsis gone and the touch buttons still work.main.tsconsumes the latch once a frame, before the fixed steps, and a frame that runs several 64 Hz steps does not repeat an edge across all of them.bun testhas a test per rule above that fails without the change: a down+up inside one frame yields one firing tick; a held control yields firing ticks for as long as it is held; releasing clears it.bun run scripts/build.tsrun and the rebuiltstatic/app.<hash>.jscommitted.Files I expect to change
src/client/press.ts(new),src/client/press.test.ts(new),src/client/input.ts,src/client/main.ts,static/app.<hash>.js.Risks
Latching too long turns a tap into a burst on an automatic weapon; the test for "one tap, one bullet" is the guard. Edge state consumed inside the
while (accumulator >= TICK)loop rather than outside it would fire once per step on a slow frame — consume before the loop and pass the same input down.Who
A builder with the client loop in hand. Small, self-contained, and it unblocks the frame-loop work in the render-scale issue.