Object Pooling
create everything up front, then recycle instead of allocate
Pre-allocate bullets, effects and enemies once, then hand out and return them. No allocation or GC spikes mid-fight, and a hard cap on live objects.
Code patterns most games need for objects, effects, simulation and collision.
5 cheat sheets · 3 subcategories
Reusable runtime patterns for many short-lived objects.
create everything up front, then recycle instead of allocate
Pre-allocate bullets, effects and enemies once, then hand out and return them. No allocation or GC spikes mid-fight, and a hard cap on live objects.
thousands of short-lived points, one draw call
An emitter spawns particles at a rate, each lives for a set time under simple forces, and all of them render in a single instanced draw call.
Stepping a world forward deterministically.
physics ticks at a steady rate, rendering just blends between ticks
Run physics in constant dt slices from an accumulator, clamp long frames, and interpolate between the last two states for smooth, repeatable motion.
Deciding what touched what, and when.
attacks carry hitboxes, bodies carry hurtboxes, and they only meet on active frames
Attacks own hitboxes that exist only during active frames; characters own hurtboxes. An overlap is a hit, registered once per swing per target.
fast objects skip over thin walls between two ticks
A fast object can be on one side of a thin wall at one tick and past it at the next. Swept tests (CCD) check the whole path between positions.