|| :@include: lib/math.nv || :entity.slab.id: 1 :entity.slab.free: (1 2 3 4 5) :entity.slab.pool: . 1 0 0 0 . 2 0 0 0 . 3 0 0 0 . 4 0 0 0 . 5 0 0 0 |:: create entity at $x $y| :entity.slab.x: $x :entity.slab.y: $y :: allocate entity |:: allocate entity :entity.slab.free: $ptr :entity.slab.id: $id :entity.slab.x: $x :entity.slab.y: $y :entity.slab.pool: $ptr $oldId $oldX $oldY| :entity.slab.pool: $ptr $id $x $y :: restore entity pool :: next entity id from $id |:: allocate entity? :entity.slab.free: $ptr? :entity.slab.pool: $0 $1 $2 $3| :entity.slab.pool.retained: $0 $1 $2 $3 |:: allocate entity :entity.slab.x: $0 :entity.slab.y: $1| :failed: create entity at $0 $1 :: entity allocator out of space |:: restore entity pool? :entity.slab.pool.retained: $0 $1 $2 $3| :entity.slab.pool: $0 $1 $2 $3 |:: restore entity pool| |:: free entity $ptr| :entity.slab.free: $ptr |:: next entity id from $id| :@math: add $id 1 :: set entity id |:: set entity id :@math: $id| :entity.slab.id: $id || :: . create entity at 10 20 . create entity at 45 30 . create entity at 50 12 . create entity at 23 43 . create entity at 49 87 . free entity 3 . free entity 5 . create entity at 31 33