Scalar Select Anti-Pattern

68 points by matklad


hc

this sort of thing comes up in gamedev

you’ll have a scalar select, and then when the queue is empty it’ll update and render. but, the scalar select is usually lightweight, and just puts the relevant parts of the event somewhere for the update function to deal with

like, a keyboard event will get grouped by key, and the presses/releases get counted (coalescing). the actual “make the character jump” part happens in the update function, usually in a specified order. if the character is mid-attack, you’ll often discard button presses

danthegoodman1

potentially obvious caveat: you should have some limit to the batch size, otherwise you can get stuck with a never-ending incoming stream and just obliterate memory >.<