diff options
Diffstat (limited to 'world/chunk/ChunkGen.gd')
-rw-r--r-- | world/chunk/ChunkGen.gd | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/world/chunk/ChunkGen.gd b/world/chunk/ChunkGen.gd index e71cc57..994d624 100644 --- a/world/chunk/ChunkGen.gd +++ b/world/chunk/ChunkGen.gd @@ -1,16 +1,11 @@ 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() onready var rng = RandomNumberGenerator.new() var _seed +var monuments = [] + func _ready(): #randomize() #self._seed = randi() @@ -21,13 +16,36 @@ func _ready(): self.noise.persistence = 0 self.rng.seed = self._seed +func setup_monuments(): + monuments.push_back(DockMonument.new(Transform(Basis().rotated(Vector3.UP,0.0),Vector3(0.0,0.0,-600.0)))) + monuments.push_back(DockMonument.new(Transform(Basis().rotated(Vector3.UP,PI),Vector3(0.0,0.0,600.0)))) + func rng_2dv(coords:Vector2): self.rng.seed = hash(coords) -func gen_chunk(chunk): - gen_distance(chunk,chunk.get_node("gen_tree/lod_distance")) - gen_mid(chunk,chunk.get_node("gen_tree/lod_mid")) - gen_close(chunk,chunk.get_node("gen_tree/lod_close")) +func gen_chunk(chunk,dummy=false): + if dummy: + return + var monument = get_monument_at_chunk(ChunkLoader.v2_coords(chunk.transform.origin)) + if monument != null: + gen_monument(chunk, monument) + else: + gen_distance(chunk,chunk.get_node("gen_tree/lod_distance")) + gen_mid(chunk,chunk.get_node("gen_tree/lod_mid")) + gen_close(chunk,chunk.get_node("gen_tree/lod_close")) + +func get_monument_at_chunk(chunk_coords:Vector2): + for monument in monuments: + if monument.is_chunk_in_monument(chunk_coords): + return monument + return null + +func gen_monument(chunk, monument): + var offset_to_origin = monument.origin_chunk - ChunkLoader.v2_coords(chunk.transform.origin) + var inst = monument.scene.instance() + inst.transform.origin = ChunkLoader.v3_coords(offset_to_origin) + inst.transform.basis = monument.xform.basis + chunk.add_child(inst) func gen_distance(chunk,tree): gen_lowres_rocks(chunk,tree) @@ -38,13 +56,8 @@ func gen_mid(chunk,tree): func gen_close(chunk,tree): gen_rock_hitboxes(chunk,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,tree,step:Vector2,cb:FuncRef,data): + var chunk_half_size = ChunkLoader.world.chunk_half_size 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): @@ -81,9 +94,9 @@ func gen_rock_hitboxes(chunk,tree): iterate_chunk(chunk, tree, Vector2(20.0,20.0), funcref(self,"rock_rng"), [0.4,0.6,1.0,4.0,1.0,funcref(self,"make_rock_hitbox")]) func rock_rng(chunk,rocks,chunk_coords:Vector2,data): - var coords = v3_coords(chunk_coords) + var coords = ChunkLoader.v3_coords(chunk_coords) var basis = Basis() - var world_coords = chunk_coords + v2_coords(chunk.transform.origin) + var world_coords = chunk_coords + ChunkLoader.v2_coords(chunk.transform.origin) self.rng_2dv(world_coords) var rng_val = self.rng.randf_range(0.0,TAU) basis = Basis(Vector3.UP,rng_val) * basis |