From b868716844cc48311e69e70572f1fd7c0bc52091 Mon Sep 17 00:00:00 2001 From: Scott Wadden Date: Tue, 17 Oct 2023 21:37:35 -0300 Subject: [PATCH] Fixed shared edits --- enu.nimble | 2 +- src/controllers/script_controllers/worker.nim | 1 + src/models/builds.nim | 2 +- src/models/units.nim | 14 ++++---------- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/enu.nimble b/enu.nimble index 916153ba..34224ba9 100644 --- a/enu.nimble +++ b/enu.nimble @@ -31,7 +31,7 @@ else: requires "nim >= 1.6.10", "https://github.com/arnetheduck/nim-results#f3c666a", "https://github.com/dsrw/godot-nim#892c482", - "https://github.com/dsrw/model_citizen 0.18.9", + "https://github.com/dsrw/model_citizen 0.18.10", "https://github.com/dsrw/nanoid.nim 0.2.1", "cligen 1.6.0", "https://github.com/treeform/pretty", diff --git a/src/controllers/script_controllers/worker.nim b/src/controllers/script_controllers/worker.nim index 85a3d3bc..cf4736de 100644 --- a/src/controllers/script_controllers/worker.nim +++ b/src/controllers/script_controllers/worker.nim @@ -97,6 +97,7 @@ proc watch_code(self: Worker, unit: Unit) = unit.code_value.changes: if added or touched: if change.item.owner == "" or change.item.owner == Zen.thread_ctx.id: + save_world(state.config.world_dir) self.change_code(unit, change.item) elif Server in state.local_flags: if change.item.nim == "": diff --git a/src/models/builds.nim b/src/models/builds.nim index 50e458e8..6dc51146 100644 --- a/src/models/builds.nim +++ b/src/models/builds.nim @@ -145,7 +145,6 @@ proc restore_edits*(self: Build) = var locations = self.shared.edits[self.id] locations[loc] = info self.shared.edits[self.id] = locations - self.chunks[buffer].destroy self.chunks[buffer].del loc proc draw*(self: Build, position: Vector3, voxel: VoxelInfo) {.gcsafe.} = @@ -335,6 +334,7 @@ method on_begin_turn*(self: Build, self.draw_transform = self.draw_transform.orthonormalized() proc reset_state*(self: Build) = + self.init_shared self.draw_transform = Transform.init self.transform = self.start_transform diff --git a/src/models/units.nim b/src/models/units.nim index 37da0d63..c43537fc 100644 --- a/src/models/units.nim +++ b/src/models/units.nim @@ -142,19 +142,13 @@ proc destroy_impl*(self: Bot | Build | Sign) = if self.parent == nil: let shared = self.shared + for _, edit in shared.edits: + edit.destroy shared.edits.destroy self.shared = nil - self.shared_value.destroy - if Zen.thread_ctx.can_free(shared).freeable: - Zen.thread_ctx.free(shared) - else: - fail \"can't free shared {shared.id} for unit {self.id}" + Zen.thread_ctx.free(shared) else: - if self.id in self.shared.edits: - let edit = self.shared.edits[self.id] - self.shared.edits.del(self.id) - edit.destroy - self.shared = nil + self.shared = nil self.parent = nil for field in self[].fields: