From 9bc2a0767e15d4dde7fd6231b07882d6456af71e Mon Sep 17 00:00:00 2001 From: dusoleil Date: Mon, 19 Sep 2022 06:28:21 -0400 Subject: Use MultiMesh to dramatically increase performance of generated world --- world/chunk/ChunkLoader.gd | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'world/chunk/ChunkLoader.gd') 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(): -- cgit v1.2.3