summaryrefslogtreecommitdiffstats
path: root/ChunkLoader.gd
diff options
context:
space:
mode:
authordusoleil <howcansocksbereal@gmail.com>2022-09-18 19:38:35 -0400
committerdusoleil <howcansocksbereal@gmail.com>2022-09-18 19:42:01 -0400
commit32bf9d2024362d45dc351c8f1d0b3b301caf1131 (patch)
treefb6540bce94cb55c6123ecfe1327abeabea2925f /ChunkLoader.gd
parentffc92ed12c6e680776d355ff9fcef70e5e28d7c8 (diff)
downloadgodot_wildjam_49-32bf9d2024362d45dc351c8f1d0b3b301caf1131.tar.gz
godot_wildjam_49-32bf9d2024362d45dc351c8f1d0b3b301caf1131.zip
Organize World Gen Stuff
Diffstat (limited to 'ChunkLoader.gd')
-rw-r--r--ChunkLoader.gd66
1 files changed, 0 insertions, 66 deletions
diff --git a/ChunkLoader.gd b/ChunkLoader.gd
deleted file mode 100644
index 90cac4f..0000000
--- a/ChunkLoader.gd
+++ /dev/null
@@ -1,66 +0,0 @@
-extends Node
-
-var world = null
-
-var Chunk = preload("res://Chunk.tscn")
-var chunks = {}
-var loaded_chunks = {}
-var chunk_thread = Thread.new()
-var mtx = Mutex.new()
-var sgnl = Semaphore.new()
-var exit = false
-var chunk_to_load = null
-
-func _ready():
- chunk_thread.start(self, "chunk_loader")
-
-func _exit_tree():
- mtx.lock()
- exit = true
- sgnl.post()
- mtx.unlock()
- chunk_thread.wait_to_finish()
-
-func add_chunk(coords:Vector2):
- chunks[coords] = coords.length()
-
-func chunk_update():
- var closest_unloaded_chunk = null
- var closest_len = 0.0
- for chunk in chunks.keys():
- if !loaded_chunks.has(chunk):
- if closest_unloaded_chunk == null || closest_len > chunks[chunk]:
- closest_unloaded_chunk = chunk
- closest_len = chunks[chunk]
- if closest_unloaded_chunk != null:
- mtx.lock()
- if chunk_to_load == null:
- chunk_to_load = closest_unloaded_chunk
- sgnl.post()
- 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)
- chunks = {}
-
-func chunk_loader():
- while true:
- sgnl.wait()
- mtx.lock()
- var x = exit
- var coords = chunk_to_load
- chunk_to_load = null
- mtx.unlock()
- if x:
- break
- var chunk = Chunk.instance()
- chunk.transform.origin = Vector3(coords.x,0.0,coords.y)
- ChunkGen.gen_chunk(chunk)
- self.call_deferred("finish_chunk", chunk)
-
-func finish_chunk(chunk):
- world.get_node("Chunks").add_child(chunk)
- loaded_chunks[Vector2(chunk.transform.origin.x,chunk.transform.origin.z)] = weakref(chunk)