Mercurial > games > semicongine
diff src/zamikongine/thing.nim @ 28:b1b05d4efb52
big refactoring, part1
author | Sam <sam@basx.dev> |
---|---|
date | Sat, 14 Jan 2023 14:08:00 +0700 |
parents | b55d6ecde79d |
children | 9edca5dc4e93 |
line wrap: on
line diff
--- a/src/zamikongine/thing.nim Wed Jan 11 11:55:54 2023 +0700 +++ b/src/zamikongine/thing.nim Sat Jan 14 14:08:00 2023 +0700 @@ -1,4 +1,5 @@ {.experimental: "codeReordering".} +import std/times type Part* = object of RootObj @@ -9,6 +10,8 @@ children*: seq[ref Thing] parts*: seq[ref Part] +method update*(thing: ref Thing, dt: Duration) {.base.} = discard + iterator partsOfType*[T: ref Part](root: ref Thing): T = var queue = @[root] while queue.len > 0: @@ -18,3 +21,11 @@ yield T(part) for child in thing.children: queue.insert(child, 0) + +iterator allEntities*(root: ref Thing): ref Thing = + var queue = @[root] + while queue.len > 0: + let next = queue.pop + for child in next.children: + queue.add child + yield next