diff options
Diffstat (limited to 'world/World.gd')
-rw-r--r-- | world/World.gd | 37 |
1 files changed, 13 insertions, 24 deletions
diff --git a/world/World.gd b/world/World.gd index 2c8d822..04c3ef1 100644 --- a/world/World.gd +++ b/world/World.gd @@ -4,11 +4,13 @@ export(NodePath) var traveler = null onready var _traveler = get_node(traveler) export var acceleration = 10.0 -onready var lod_distance = $"ChunkRenderDistance" -onready var lod_mid = $"ChunkRenderMid" -onready var lod_close = $"ChunkRenderClose" +onready var chunk_render_distance = $"ChunkRenderDistance" +onready var chunk_render_mid = $"ChunkRenderMid" +onready var chunk_render_close = $"ChunkRenderClose" -onready var chunk_render_distance = lod_distance.get_node("Radius").shape.radius +onready var lod_distance = chunk_render_distance.get_node("Radius").shape.radius +onready var lod_mid = chunk_render_mid.get_node("Radius").shape.radius +onready var lod_close = chunk_render_close.get_node("Radius").shape.radius onready var chunk_half_size = $"Chunks/Chunk/Size".shape.radius onready var chunk_size = chunk_half_size * 2.0 @@ -33,7 +35,7 @@ func _on_ChunkRenderClose_area_entered(area:Area): area.lod_update() func _on_ChunkRenderDistance_area_exited(area:Area): - ChunkLoader.free_chunk(chunk_coords(v2_coords(area.transform.origin))) + free_chunk(area) func _on_ChunkRenderMid_area_exited(area:Area): area.lod = area.LOD.DISTANCE @@ -52,26 +54,13 @@ func travel(direction:Vector3): $"Chunks".add_central_force(direction*acceleration) func _physics_process(_state): - chunk_process() + ChunkLoader.chunk_update() var stick = Input.get_axis("ship_down","ship_up") if stick != 0.0: self.travel(Vector3.FORWARD*stick) -func v2_coords(coords:Vector3): - return Vector2(coords.x,coords.z) - -func chunk_coords(coords:Vector2): - return coords.snapped(Vector2(chunk_size,chunk_size)) - -func chunk_process(): - var gen_center = -v2_coords($"Chunks".transform.origin) - var gen_radius = chunk_render_distance - var gen_radius_rounded = stepify(gen_radius, chunk_size) - for x in range(-gen_radius_rounded, gen_radius_rounded+chunk_size, chunk_size): - for y in range(-gen_radius_rounded, gen_radius_rounded+chunk_size, chunk_size): - var gen_coords = Vector2(x,y) - if gen_coords.length() > gen_radius: - continue - var coords = chunk_coords(gen_coords + gen_center) - ChunkLoader.add_chunk(coords) - ChunkLoader.chunk_update() +func free_chunk(chunk): + var coords = chunk.transform.origin + coords = Vector2(coords.x,coords.z) + coords = coords.snapped(Vector2(chunk_size,chunk_size)) + ChunkLoader.free_chunk(coords) |