All field notes

When does one asteroid become two?

A hole in an asteroid changes its shape. A cut all the way through changes something more fundamental: the material no longer belongs to one connected body.

That distinction turns a drawing problem into a connectivity problem.

Start with material, not just an image

Fenrir represents asteroid material with a 32 × 32 occupancy grid. A cell either contains material or it does not. Visible damage and collision refer to the same mask, so a hole can be meaningful to both the sprite and the simulation.

After damage, there is a new question: which occupied cells can still reach one another?

Define what counts as connected

The partition uses four-neighbour connectivity. A cell can connect through the cells immediately above, below, left, and right. Merely touching at a corner does not connect two regions under this rule.

Start with one occupied cell, visit its occupied neighbours, and keep going until there are no more reachable cells. That gives one connected component. Repeat from any occupied cell that has not been visited.

remaining = all occupied cells
while remaining is not empty:
    start at one remaining cell
    visit every cell reachable through shared edges
    record that connected component

The useful invariant is that every retained cell belongs to exactly one component. Splitting should not duplicate material or silently assign the same cell to two bodies.

A component is not yet a moving fragment

Finding the pieces is the geometry step. Turning them into independent game entities adds position, rotation, velocity, lifetime, and resource limits.

Fenrir keeps the largest region as the original body. Other eligible regions become fragments, subject to size and spawn budgets. These bounds matter because repeated damage can otherwise create more simulation work than the scene was designed to handle.

Try cutting through the grid

The material study uses a smaller grid to make connectivity visible. Carve a path through the material and watch the connected-piece count. Lighter cells mark regions disconnected from the largest piece.

The browser study stops at partitioning. The Rust game also handles fragment motion and collision. The geometry implementation and project overview describe that larger system.

One useful way to inspect a split is to ask two questions separately: which cells belong together, and what should each resulting body do next?

Explore a related projectTry the Fenrir material study Discuss the idea
Continue readingConcurrency needs a budget.