annotate src/zamikongine/thing.nim @ 499:3f1111f3b9f8

did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
author Sam <sam@basx.dev>
date Wed, 18 Jan 2023 09:52:03 +0700
parents 0c18638c7217
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
480
14e5151f68d1 did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
1 {.experimental: "codeReordering".}
14e5151f68d1 did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
2
14e5151f68d1 did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
3 type
14e5151f68d1 did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
4 Part* = object of RootObj
14e5151f68d1 did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
5 thing: ref Thing
14e5151f68d1 did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
6
14e5151f68d1 did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
7 Thing* = object of RootObj
14e5151f68d1 did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
8 parent*: ref Thing
14e5151f68d1 did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
9 children*: seq[ref Thing]
14e5151f68d1 did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
10 parts*: seq[ref Part]
14e5151f68d1 did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
11
493
680c4b8ca28a add: working implementation of uniforms
Sam <sam@basx.dev>
parents: 489
diff changeset
12 method update*(thing: ref Thing, dt: float32) {.base.} = discard
489
54a1f8ee208e big refactoring, part1
Sam <sam@basx.dev>
parents: 480
diff changeset
13
480
14e5151f68d1 did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
14 iterator partsOfType*[T: ref Part](root: ref Thing): T =
14e5151f68d1 did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
15 var queue = @[root]
14e5151f68d1 did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
16 while queue.len > 0:
14e5151f68d1 did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
17 let thing = queue.pop
14e5151f68d1 did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
18 for part in thing.parts:
14e5151f68d1 did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
19 if part of T:
14e5151f68d1 did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
20 yield T(part)
14e5151f68d1 did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
21 for child in thing.children:
14e5151f68d1 did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
22 queue.insert(child, 0)
489
54a1f8ee208e big refactoring, part1
Sam <sam@basx.dev>
parents: 480
diff changeset
23
54a1f8ee208e big refactoring, part1
Sam <sam@basx.dev>
parents: 480
diff changeset
24 iterator allEntities*(root: ref Thing): ref Thing =
54a1f8ee208e big refactoring, part1
Sam <sam@basx.dev>
parents: 480
diff changeset
25 var queue = @[root]
54a1f8ee208e big refactoring, part1
Sam <sam@basx.dev>
parents: 480
diff changeset
26 while queue.len > 0:
54a1f8ee208e big refactoring, part1
Sam <sam@basx.dev>
parents: 480
diff changeset
27 let next = queue.pop
54a1f8ee208e big refactoring, part1
Sam <sam@basx.dev>
parents: 480
diff changeset
28 for child in next.children:
54a1f8ee208e big refactoring, part1
Sam <sam@basx.dev>
parents: 480
diff changeset
29 queue.add child
54a1f8ee208e big refactoring, part1
Sam <sam@basx.dev>
parents: 480
diff changeset
30 yield next