diff options
author | dusoleil <howcansocksbereal@gmail.com> | 2022-09-18 07:45:13 -0400 |
---|---|---|
committer | dusoleil <howcansocksbereal@gmail.com> | 2022-09-18 07:45:13 -0400 |
commit | 3ac2fb62b67b6446ab31b2455a4cb74069f1c54f (patch) | |
tree | 4764fa39466d7fd0d4ac9133e5a237dd1576a487 /ChunkGen.gd | |
parent | 5923cd97dfafd7fee2784a91e81d7d55ed28448e (diff) | |
download | godot_wildjam_49-3ac2fb62b67b6446ab31b2455a4cb74069f1c54f.tar.gz godot_wildjam_49-3ac2fb62b67b6446ab31b2455a4cb74069f1c54f.zip |
Add ChunkLoader to World Generation
Break up world gen into chunk and offload generating them to a Chunk Loader.
The World figures out which chunks should be loaded and gives this to the Chunk Loader.
The Chunk Loader frees any chunks out of render distance.
It also picks an unloaded chunk and gives it to a worker thread to generate it.
Diffstat (limited to 'ChunkGen.gd')
-rw-r--r-- | ChunkGen.gd | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/ChunkGen.gd b/ChunkGen.gd new file mode 100644 index 0000000..6e1f0eb --- /dev/null +++ b/ChunkGen.gd @@ -0,0 +1,35 @@ +extends Node + +var chunk_half_size setget _set_chunk_size +var chunk_size + +func _set_chunk_size(val): + chunk_half_size = val + chunk_size = val * 2.0 + +onready var noise = OpenSimplexNoise.new() + +func _ready(): + randomize() + noise.seed = randi() + noise.octaves = 4 + noise.period = 64 + noise.persistence = 0.001 + noise.lacunarity = 2.0 + +func gen_chunk(chunk): + var gen_tree = Spatial.new() + gen_tree.name = "gen_tree" + chunk.add_child(gen_tree) + +func v2_coords(coords:Vector3): + return Vector2(coords.x,coords.z) + +func v3_coords(coords:Vector2): + return Vector3(coords.x,0.0,coords.y) + +func iterate_chunk(chunk,step:Vector2,cb:FuncRef): + var chunk_size_rounded = Vector2(chunk_half_size,chunk_half_size).snapped(step) + for x in range(-chunk_size_rounded.x,chunk_size_rounded.x,step.x): + for y in range(-chunk_size_rounded.y,chunk_size_rounded.y,step.y): + cb.call_func(chunk,Vector2(x,y)) |