From c731c3c5abda2a04be02968710e09a053c98c2e4 Mon Sep 17 00:00:00 2001 From: Alberto Torres Date: Thu, 29 Aug 2024 00:09:34 +0200 Subject: [PATCH] Add `new_scenes` to prevent modifying the currently iterated scenes. --- src/myou_engine.nim | 6 ++++++ src/scene.nim | 2 +- src/types.nim | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/myou_engine.nim b/src/myou_engine.nim index 8d67198..70ed184 100644 --- a/src/myou_engine.nim +++ b/src/myou_engine.nim @@ -165,6 +165,12 @@ proc myou_main_loop*(self: MyouEngine) = ## ## You usually don't need to call this. Use `run <#run,MyouEngine>`_ ## 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 delta_seconds = time - last_time for _,scene in self.scenes.pairs: diff --git a/src/scene.nim b/src/scene.nim index 663d457..fc5fe6b 100644 --- a/src/scene.nim +++ b/src/scene.nim @@ -95,7 +95,7 @@ proc initScene*(self: Scene, engine: MyouEngine, name: string = "Scene", while self.name in engine.scenes: collision_seq += 1 self.name = name & "$" & $collision_seq - engine.scenes[self.name] = self + engine.new_scenes[self.name] = self self.mesh_passes.setLen 3 self.world = newWorld(self) self.background_color = vec4(0, 0, 0, 1) diff --git a/src/types.nim b/src/types.nim index d6e19d0..290439a 100644 --- a/src/types.nim +++ b/src/types.nim @@ -85,6 +85,7 @@ type loaders_by_ext*: Table[string, seq[proc(e: MyouEngine): Loader]] glsl_version*: string all_framebuffers*: seq[Framebuffer] ## private + new_scenes*: Table[string, Scene] ## private # gameobject.nim