Last active 2 weeks ago

june's Avatar june revised this gist 2 weeks ago. Go to revision

1 file changed, 61 insertions

slab.nv(file created)

@@ -0,0 +1,61 @@
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
Newer Older