slab.nv
· 1.2 KiB · Text
原始文件
Playground
|| :@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
| 1 | || :@include: lib/math.nv |
| 2 | |
| 3 | || :entity.slab.id: 1 |
| 4 | :entity.slab.free: (1 2 3 4 5) |
| 5 | :entity.slab.pool: |
| 6 | . 1 0 0 0 |
| 7 | . 2 0 0 0 |
| 8 | . 3 0 0 0 |
| 9 | . 4 0 0 0 |
| 10 | . 5 0 0 0 |
| 11 | |
| 12 | |:: create entity at $x $y| |
| 13 | :entity.slab.x: $x |
| 14 | :entity.slab.y: $y |
| 15 | :: allocate entity |
| 16 | |
| 17 | |:: allocate entity |
| 18 | :entity.slab.free: $ptr |
| 19 | :entity.slab.id: $id |
| 20 | :entity.slab.x: $x |
| 21 | :entity.slab.y: $y |
| 22 | :entity.slab.pool: $ptr $oldId $oldX $oldY| |
| 23 | :entity.slab.pool: $ptr $id $x $y |
| 24 | :: restore entity pool |
| 25 | :: next entity id from $id |
| 26 | |
| 27 | |:: allocate entity? |
| 28 | :entity.slab.free: $ptr? |
| 29 | :entity.slab.pool: $0 $1 $2 $3| |
| 30 | :entity.slab.pool.retained: $0 $1 $2 $3 |
| 31 | |
| 32 | |:: allocate entity |
| 33 | :entity.slab.x: $0 |
| 34 | :entity.slab.y: $1| |
| 35 | :failed: create entity at $0 $1 |
| 36 | :: entity allocator out of space |
| 37 | |
| 38 | |:: restore entity pool? :entity.slab.pool.retained: $0 $1 $2 $3| |
| 39 | :entity.slab.pool: $0 $1 $2 $3 |
| 40 | |
| 41 | |:: restore entity pool| |
| 42 | |
| 43 | |:: free entity $ptr| |
| 44 | :entity.slab.free: $ptr |
| 45 | |
| 46 | |:: next entity id from $id| |
| 47 | :@math: add $id 1 |
| 48 | :: set entity id |
| 49 | |
| 50 | |:: set entity id :@math: $id| |
| 51 | :entity.slab.id: $id |
| 52 | |
| 53 | || :: |
| 54 | . create entity at 10 20 |
| 55 | . create entity at 45 30 |
| 56 | . create entity at 50 12 |
| 57 | . create entity at 23 43 |
| 58 | . create entity at 49 87 |
| 59 | . free entity 3 |
| 60 | . free entity 5 |
| 61 | . create entity at 31 33 |