Mercurial > games > semicongine
view src/zamikongine/thing.nim @ 38:c3c963e7c1a6
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 | 94c38e4b5782 |
children |
line wrap: on
line source
{.experimental: "codeReordering".} type Part* = object of RootObj thing: ref Thing Thing* = object of RootObj parent*: ref Thing children*: seq[ref Thing] parts*: seq[ref Part] method update*(thing: ref Thing, dt: float32) {.base.} = discard iterator partsOfType*[T: ref Part](root: ref Thing): T = var queue = @[root] while queue.len > 0: let thing = queue.pop for part in thing.parts: if part of T: 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