diff options
Diffstat (limited to 'world/chunk/ChunkLoader.gd')
-rw-r--r-- | world/chunk/ChunkLoader.gd | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/world/chunk/ChunkLoader.gd b/world/chunk/ChunkLoader.gd index 9f1d9b3..2e01bca 100644 --- a/world/chunk/ChunkLoader.gd +++ b/world/chunk/ChunkLoader.gd @@ -24,6 +24,14 @@ func _exit_tree(): func add_chunk(coords:Vector2): chunks[coords] = coords.length() +func free_chunk(coords:Vector2): + if !loaded_chunks.has(coords): + return + var c = loaded_chunks[coords].get_ref() + if c != null: + c.queue_free() + loaded_chunks.erase(coords) + func chunk_update(): var closest_unloaded_chunk = null var closest_len = 0.0 @@ -40,10 +48,7 @@ func chunk_update(): mtx.unlock() for chunk in loaded_chunks.keys(): if !chunks.has(chunk): - var c = loaded_chunks[chunk].get_ref() - if c != null: - c.queue_free() - loaded_chunks.erase(chunk) + free_chunk(chunk) chunks = {} func chunk_loader(): |