Add new_scenes to prevent modifying the currently iterated scenes.

This commit is contained in:
Alberto Torres 2024-08-29 00:09:34 +02:00
parent 3ff1d663a2
commit c731c3c5ab
3 changed files with 8 additions and 1 deletions

View file

@ -165,6 +165,12 @@ proc myou_main_loop*(self: MyouEngine) =
## ##
## You usually don't need to call this. Use `run <#run,MyouEngine>`_ ## You usually don't need to call this. Use `run <#run,MyouEngine>`_
## instead. ## instead.
# TODO: make a table object that can be iterated while changing, e.g. with a
# seq and a dirty flag to update the seq
if self.new_scenes.len != 0:
for name,scene in self.new_scenes.pairs:
self.scenes[name] = scene
self.new_scenes.clear()
let time = getmonotime().ticks.float/1000000000 let time = getmonotime().ticks.float/1000000000
let delta_seconds = time - last_time let delta_seconds = time - last_time
for _,scene in self.scenes.pairs: for _,scene in self.scenes.pairs:

View file

@ -95,7 +95,7 @@ proc initScene*(self: Scene, engine: MyouEngine, name: string = "Scene",
while self.name in engine.scenes: while self.name in engine.scenes:
collision_seq += 1 collision_seq += 1
self.name = name & "$" & $collision_seq self.name = name & "$" & $collision_seq
engine.scenes[self.name] = self engine.new_scenes[self.name] = self
self.mesh_passes.setLen 3 self.mesh_passes.setLen 3
self.world = newWorld(self) self.world = newWorld(self)
self.background_color = vec4(0, 0, 0, 1) self.background_color = vec4(0, 0, 0, 1)

View file

@ -85,6 +85,7 @@ type
loaders_by_ext*: Table[string, seq[proc(e: MyouEngine): Loader]] loaders_by_ext*: Table[string, seq[proc(e: MyouEngine): Loader]]
glsl_version*: string glsl_version*: string
all_framebuffers*: seq[Framebuffer] ## private all_framebuffers*: seq[Framebuffer] ## private
new_scenes*: Table[string, Scene] ## private
# gameobject.nim # gameobject.nim