annotate src/zamikongine/thing.nim @ 32:9edca5dc4e93

add: working implementation of uniforms
author Sam <sam@basx.dev>
date Sat, 14 Jan 2023 23:34:50 +0700
parents b1b05d4efb52
children 94c38e4b5782
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
1 {.experimental: "codeReordering".}
28
b1b05d4efb52 big refactoring, part1
Sam <sam@basx.dev>
parents: 19
diff changeset
2 import std/times
19
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
3
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
4 type
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
5 Part* = object of RootObj
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
6 thing: ref Thing
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
7
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
8 Thing* = object of RootObj
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
9 parent*: ref Thing
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
10 children*: seq[ref Thing]
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
11 parts*: seq[ref Part]
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
12
32
9edca5dc4e93 add: working implementation of uniforms
Sam <sam@basx.dev>
parents: 28
diff changeset
13 method update*(thing: ref Thing, dt: float32) {.base.} = discard
28
b1b05d4efb52 big refactoring, part1
Sam <sam@basx.dev>
parents: 19
diff changeset
14
19
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
15 iterator partsOfType*[T: ref Part](root: ref Thing): T =
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
16 var queue = @[root]
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
17 while queue.len > 0:
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
18 let thing = queue.pop
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
19 for part in thing.parts:
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
20 if part of T:
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
21 yield T(part)
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
22 for child in thing.children:
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff changeset
23 queue.insert(child, 0)
28
b1b05d4efb52 big refactoring, part1
Sam <sam@basx.dev>
parents: 19
diff changeset
24
b1b05d4efb52 big refactoring, part1
Sam <sam@basx.dev>
parents: 19
diff changeset
25 iterator allEntities*(root: ref Thing): ref Thing =
b1b05d4efb52 big refactoring, part1
Sam <sam@basx.dev>
parents: 19
diff changeset
26 var queue = @[root]
b1b05d4efb52 big refactoring, part1
Sam <sam@basx.dev>
parents: 19
diff changeset
27 while queue.len > 0:
b1b05d4efb52 big refactoring, part1
Sam <sam@basx.dev>
parents: 19
diff changeset
28 let next = queue.pop
b1b05d4efb52 big refactoring, part1
Sam <sam@basx.dev>
parents: 19
diff changeset
29 for child in next.children:
b1b05d4efb52 big refactoring, part1
Sam <sam@basx.dev>
parents: 19
diff changeset
30 queue.add child
b1b05d4efb52 big refactoring, part1
Sam <sam@basx.dev>
parents: 19
diff changeset
31 yield next