Mercurial > games > semicongine
annotate src/semicongine/scene.nim @ 263:d1ee2a815fa1
add: some api improvments, preparing for font-loading
author | Sam <sam@basx.dev> |
---|---|
date | Sat, 27 May 2023 13:44:02 +0700 |
parents | 0fab53ca30b7 |
children | fd1a95f433d1 |
rev | line source |
---|---|
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
1 import std/strformat |
247 | 2 import std/strutils |
189
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
142
diff
changeset
|
3 import std/tables |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
4 import std/hashes |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
5 import std/typetraits |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
6 |
206
7f921d7d0a2b
did: small refactoring of module structure
Sam <sam@basx.dev>
parents:
201
diff
changeset
|
7 import ./core |
19
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff
changeset
|
8 |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff
changeset
|
9 type |
108 | 10 Component* = ref object of RootObj |
109 | 11 entity*: Entity |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
12 |
189
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
142
diff
changeset
|
13 Scene* = object |
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
142
diff
changeset
|
14 name*: string |
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
142
diff
changeset
|
15 root*: Entity |
229
7741bca03e7c
add: support for struct members to be array
Sam <sam@basx.dev>
parents:
211
diff
changeset
|
16 shaderGlobals*: Table[string, DataList] |
243
3b388986c7fd
did: refactor texture data structures, add more complete (untested) material import
Sam <sam@basx.dev>
parents:
229
diff
changeset
|
17 textures*: Table[string, seq[Texture]] |
189
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
142
diff
changeset
|
18 |
108 | 19 Entity* = ref object of RootObj |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
20 name*: string |
121
dfaddaf96f09
did: refactor GPU data types, more generic, prepare to use for decriptors/uniforms
Sam <sam@basx.dev>
parents:
112
diff
changeset
|
21 transform*: Mat4 # todo: cache transform + only update VBO when transform changed |
108 | 22 parent*: Entity |
23 children*: seq[Entity] | |
109 | 24 components*: seq[Component] |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
25 |
247 | 26 func getModelTransform*(entity: Entity): Mat4 = |
27 result = Unit4 | |
28 var currentEntity = entity | |
29 while currentEntity != nil: | |
30 result = currentEntity.transform * result | |
31 currentEntity = currentEntity.parent | |
32 | |
189
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
142
diff
changeset
|
33 func addShaderGlobal*[T](scene: var Scene, name: string, data: T) = |
229
7741bca03e7c
add: support for struct members to be array
Sam <sam@basx.dev>
parents:
211
diff
changeset
|
34 scene.shaderGlobals[name] = newDataList(thetype=getDataType[T]()) |
7741bca03e7c
add: support for struct members to be array
Sam <sam@basx.dev>
parents:
211
diff
changeset
|
35 setValues(scene.shaderGlobals[name], @[data]) |
7741bca03e7c
add: support for struct members to be array
Sam <sam@basx.dev>
parents:
211
diff
changeset
|
36 |
7741bca03e7c
add: support for struct members to be array
Sam <sam@basx.dev>
parents:
211
diff
changeset
|
37 func addShaderGlobalArray*[T](scene: var Scene, name: string, data: seq[T]) = |
7741bca03e7c
add: support for struct members to be array
Sam <sam@basx.dev>
parents:
211
diff
changeset
|
38 scene.shaderGlobals[name] = newDataList(thetype=getDataType[T]()) |
7741bca03e7c
add: support for struct members to be array
Sam <sam@basx.dev>
parents:
211
diff
changeset
|
39 setValues(scene.shaderGlobals[name], data) |
189
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
142
diff
changeset
|
40 |
190
8f2eaf0d2808
add: uncomment some of the prepared texture code, nice interface for scene-global shader values (aka uniforms
Sam <sam@basx.dev>
parents:
189
diff
changeset
|
41 func getShaderGlobal*[T](scene: Scene, name: string): T = |
229
7741bca03e7c
add: support for struct members to be array
Sam <sam@basx.dev>
parents:
211
diff
changeset
|
42 getValues[T](scene.shaderGlobals[name])[0] |
7741bca03e7c
add: support for struct members to be array
Sam <sam@basx.dev>
parents:
211
diff
changeset
|
43 |
7741bca03e7c
add: support for struct members to be array
Sam <sam@basx.dev>
parents:
211
diff
changeset
|
44 func getShaderGlobalArray*[T](scene: Scene, name: string): seq[T] = |
7741bca03e7c
add: support for struct members to be array
Sam <sam@basx.dev>
parents:
211
diff
changeset
|
45 getValues[T](scene.shaderGlobals[name]) |
190
8f2eaf0d2808
add: uncomment some of the prepared texture code, nice interface for scene-global shader values (aka uniforms
Sam <sam@basx.dev>
parents:
189
diff
changeset
|
46 |
8f2eaf0d2808
add: uncomment some of the prepared texture code, nice interface for scene-global shader values (aka uniforms
Sam <sam@basx.dev>
parents:
189
diff
changeset
|
47 func setShaderGlobal*[T](scene: var Scene, name: string, value: T) = |
229
7741bca03e7c
add: support for struct members to be array
Sam <sam@basx.dev>
parents:
211
diff
changeset
|
48 setValues[T](scene.shaderGlobals[name], @[value]) |
7741bca03e7c
add: support for struct members to be array
Sam <sam@basx.dev>
parents:
211
diff
changeset
|
49 |
7741bca03e7c
add: support for struct members to be array
Sam <sam@basx.dev>
parents:
211
diff
changeset
|
50 func setShaderGlobalArray*[T](scene: var Scene, name: string, value: seq[T]) = |
7741bca03e7c
add: support for struct members to be array
Sam <sam@basx.dev>
parents:
211
diff
changeset
|
51 setValues[T](scene.shaderGlobals[name], value) |
189
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
142
diff
changeset
|
52 |
243
3b388986c7fd
did: refactor texture data structures, add more complete (untested) material import
Sam <sam@basx.dev>
parents:
229
diff
changeset
|
53 func addTextures*(scene: var Scene, name: string, textures: seq[Texture], interpolation=VK_FILTER_LINEAR) = |
3b388986c7fd
did: refactor texture data structures, add more complete (untested) material import
Sam <sam@basx.dev>
parents:
229
diff
changeset
|
54 scene.textures[name] = textures |
201 | 55 |
243
3b388986c7fd
did: refactor texture data structures, add more complete (untested) material import
Sam <sam@basx.dev>
parents:
229
diff
changeset
|
56 func addTexture*(scene: var Scene, name: string, texture: Texture) = |
3b388986c7fd
did: refactor texture data structures, add more complete (untested) material import
Sam <sam@basx.dev>
parents:
229
diff
changeset
|
57 scene.textures[name] = @[texture] |
189
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
142
diff
changeset
|
58 |
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
142
diff
changeset
|
59 func newScene*(name: string, root: Entity): Scene = |
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
142
diff
changeset
|
60 Scene(name: name, root: root) |
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
142
diff
changeset
|
61 |
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
142
diff
changeset
|
62 func hash*(scene: Scene): Hash = |
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
142
diff
changeset
|
63 hash(scene.name) |
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
142
diff
changeset
|
64 |
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
142
diff
changeset
|
65 func `==`*(a, b: Scene): bool = |
df92519d4d68
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
142
diff
changeset
|
66 a.name == b.name |
127 | 67 |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
68 func hash*(entity: Entity): Hash = |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
69 hash(cast[pointer](entity)) |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
70 |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
128
diff
changeset
|
71 func hash*(component: Component): Hash = |
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
128
diff
changeset
|
72 hash(cast[pointer](component)) |
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
128
diff
changeset
|
73 |
112
0c5a74885796
did: real implementation of buffer and memory, getting closer to collect shit for drawing per pipeline
Sam <sam@basx.dev>
parents:
109
diff
changeset
|
74 method `$`*(entity: Entity): string {.base.} = entity.name |
122
506090173619
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
121
diff
changeset
|
75 method `$`*(component: Component): string {.base.} = |
112
0c5a74885796
did: real implementation of buffer and memory, getting closer to collect shit for drawing per pipeline
Sam <sam@basx.dev>
parents:
109
diff
changeset
|
76 "Unknown Component" |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
77 |
247 | 78 proc prettyRecursive*(entity: Entity): seq[string] = |
79 var compList: seq[string] | |
80 for comp in entity.components: | |
81 compList.add $comp | |
82 | |
83 var trans = entity.transform.col(3) | |
84 var pos = entity.getModelTransform().col(3) | |
85 result.add "- " & $entity & " [" & $trans.x & ", " & $trans.y & ", " & $trans.z & "] -> [" & $pos.x & ", " & $pos.y & ", " & $pos.z & "]" | |
86 if compList.len > 0: | |
87 result.add " [" & compList.join(", ") & "]" | |
88 | |
89 for child in entity.children: | |
90 for childLine in child.prettyRecursive: | |
91 result.add " " & childLine | |
92 | |
93 proc pretty*(entity: Entity): string = | |
94 entity.prettyRecursive.join("\n") | |
95 | |
109 | 96 proc add*(entity: Entity, child: Entity) = |
97 child.parent = entity | |
98 entity.children.add child | |
122
506090173619
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
121
diff
changeset
|
99 proc add*(entity: Entity, component: Component) = |
506090173619
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
121
diff
changeset
|
100 component.entity = entity |
506090173619
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
121
diff
changeset
|
101 entity.components.add component |
109 | 102 proc add*(entity: Entity, children: seq[Entity]) = |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
103 for child in children: |
109 | 104 child.parent = entity |
105 entity.children.add child | |
106 proc add*(entity: Entity, components: seq[Component]) = | |
122
506090173619
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
121
diff
changeset
|
107 for component in components: |
506090173619
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
121
diff
changeset
|
108 component.entity = entity |
506090173619
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
121
diff
changeset
|
109 entity.components.add component |
19
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff
changeset
|
110 |
109 | 111 func newEntity*(name: string = ""): Entity = |
108 | 112 result = new Entity |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
113 result.name = name |
121
dfaddaf96f09
did: refactor GPU data types, more generic, prepare to use for decriptors/uniforms
Sam <sam@basx.dev>
parents:
112
diff
changeset
|
114 result.transform = Unit4 |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
115 if result.name == "": |
108 | 116 result.name = &"Entity[{$(cast[ByteAddress](result))}]" |
117 | |
112
0c5a74885796
did: real implementation of buffer and memory, getting closer to collect shit for drawing per pipeline
Sam <sam@basx.dev>
parents:
109
diff
changeset
|
118 func newEntity*(name: string, firstChild: Entity, children: varargs[Entity]): Entity = |
108 | 119 result = new Entity |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
120 result.add firstChild |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
121 for child in children: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
122 result.add child |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
123 result.name = name |
121
dfaddaf96f09
did: refactor GPU data types, more generic, prepare to use for decriptors/uniforms
Sam <sam@basx.dev>
parents:
112
diff
changeset
|
124 result.transform = Unit4 |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
125 if result.name == "": |
108 | 126 result.name = &"Entity[{$(cast[ByteAddress](result))}]" |
127 | |
122
506090173619
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
121
diff
changeset
|
128 proc newEntity*(name: string, firstComponent: Component, components: varargs[Component]): Entity = |
108 | 129 result = new Entity |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
130 result.name = name |
122
506090173619
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
121
diff
changeset
|
131 result.add firstComponent |
506090173619
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
121
diff
changeset
|
132 for component in components: |
506090173619
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
121
diff
changeset
|
133 result.add component |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
134 if result.name == "": |
108 | 135 result.name = &"Entity[{$(cast[ByteAddress](result))}]" |
121
dfaddaf96f09
did: refactor GPU data types, more generic, prepare to use for decriptors/uniforms
Sam <sam@basx.dev>
parents:
112
diff
changeset
|
136 result.transform = Unit4 |
28 | 137 |
263
d1ee2a815fa1
add: some api improvments, preparing for font-loading
Sam <sam@basx.dev>
parents:
254
diff
changeset
|
138 iterator allEntitiesOfType*[T: Entity](root: Entity): T = |
d1ee2a815fa1
add: some api improvments, preparing for font-loading
Sam <sam@basx.dev>
parents:
254
diff
changeset
|
139 var queue = @[root] |
d1ee2a815fa1
add: some api improvments, preparing for font-loading
Sam <sam@basx.dev>
parents:
254
diff
changeset
|
140 while queue.len > 0: |
d1ee2a815fa1
add: some api improvments, preparing for font-loading
Sam <sam@basx.dev>
parents:
254
diff
changeset
|
141 let entity = queue.pop |
d1ee2a815fa1
add: some api improvments, preparing for font-loading
Sam <sam@basx.dev>
parents:
254
diff
changeset
|
142 if entity of T: |
d1ee2a815fa1
add: some api improvments, preparing for font-loading
Sam <sam@basx.dev>
parents:
254
diff
changeset
|
143 yield T(entity) |
d1ee2a815fa1
add: some api improvments, preparing for font-loading
Sam <sam@basx.dev>
parents:
254
diff
changeset
|
144 for i in countdown(entity.children.len - 1, 0): |
d1ee2a815fa1
add: some api improvments, preparing for font-loading
Sam <sam@basx.dev>
parents:
254
diff
changeset
|
145 queue.add entity.children[i] |
d1ee2a815fa1
add: some api improvments, preparing for font-loading
Sam <sam@basx.dev>
parents:
254
diff
changeset
|
146 |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
147 iterator allComponentsOfType*[T: Component](root: Entity): var T = |
19
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff
changeset
|
148 var queue = @[root] |
b55d6ecde79d
did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents:
diff
changeset
|
149 while queue.len > 0: |
109 | 150 let entity = queue.pop |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
151 for component in entity.components.mitems: |
122
506090173619
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
121
diff
changeset
|
152 if component of T: |
506090173619
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
121
diff
changeset
|
153 yield T(component) |
109 | 154 for i in countdown(entity.children.len - 1, 0): |
155 queue.add entity.children[i] | |
28 | 156 |
108 | 157 func firstWithName*(root: Entity, name: string): Entity = |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
158 var queue = @[root] |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
159 while queue.len > 0: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
160 let next = queue.pop |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
161 for child in next.children: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
162 if child.name == name: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
163 return child |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
164 queue.add child |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
165 |
254 | 166 func `[]`*(scene: Scene, name: string): Entity = |
167 return scene.root.firstWithName(name) | |
168 | |
122
506090173619
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
121
diff
changeset
|
169 func firstComponentWithName*[T: Component](root: Entity, name: string): T = |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
170 var queue = @[root] |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
171 while queue.len > 0: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
172 let next = queue.pop |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
173 for child in next.children: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
174 if child.name == name: |
122
506090173619
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
121
diff
changeset
|
175 for component in child.components: |
506090173619
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
121
diff
changeset
|
176 if component of T: |
506090173619
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
121
diff
changeset
|
177 return T(component) |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
178 queue.add child |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
179 |
108 | 180 func allWithName*(root: Entity, name: string): seq[Entity] = |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
181 var queue = @[root] |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
182 while queue.len > 0: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
183 let next = queue.pop |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
184 for child in next.children: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
185 if child.name == name: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
186 result.add child |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
187 queue.add child |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
188 |
122
506090173619
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
121
diff
changeset
|
189 func allComponentsWithName*[T: Component](root: Entity, name: string): seq[T] = |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
190 var queue = @[root] |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
191 while queue.len > 0: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
192 let next = queue.pop |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
193 for child in next.children: |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
194 if child.name == name: |
122
506090173619
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
121
diff
changeset
|
195 for component in child.components: |
506090173619
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
121
diff
changeset
|
196 if component of T: |
506090173619
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
121
diff
changeset
|
197 result.add T(component) |
60
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
198 queue.add child |
c57285d292b6
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
40
diff
changeset
|
199 |
109 | 200 iterator allEntities*(root: Entity): Entity = |
28 | 201 var queue = @[root] |
202 while queue.len > 0: | |
203 let next = queue.pop | |
204 for child in next.children: | |
205 queue.add child | |
206 yield next |