fix(world): correct 3D chunk coordinate mapping and streaming proximity
checkpoint / checkpoint (push) Successful in 5m55s
checkpoint / checkpoint (push) Successful in 5m55s
This commit is contained in:
@@ -58,6 +58,7 @@ var player: Node3D = null
|
||||
|
||||
## The current player chunk coordinate.
|
||||
var _player_chunk_coord: Vector3i = Vector3i.ZERO
|
||||
var _has_player_coord: bool = false
|
||||
|
||||
## Map of loaded chunk coordinates to their scene nodes.
|
||||
var _loaded_chunks: Dictionary = {}
|
||||
@@ -95,7 +96,7 @@ func _process(delta: float) -> void:
|
||||
return
|
||||
|
||||
_update_accumulator += delta
|
||||
if _update_accumulator < UPDATE_INTERVAL:
|
||||
if _has_player_coord and _update_accumulator < UPDATE_INTERVAL:
|
||||
return
|
||||
_update_accumulator = 0.0
|
||||
|
||||
@@ -110,9 +111,10 @@ func _update_streaming() -> void:
|
||||
return
|
||||
|
||||
var current_coord: Vector3i = Chunk.coord_for_position(player.global_position)
|
||||
if current_coord == _player_chunk_coord:
|
||||
if _has_player_coord and current_coord == _player_chunk_coord:
|
||||
return
|
||||
|
||||
_has_player_coord = true
|
||||
_player_chunk_coord = current_coord
|
||||
_rebuild_queues()
|
||||
|
||||
@@ -144,9 +146,11 @@ func _compute_target_chunks() -> Dictionary:
|
||||
"""Compute the set of chunk coordinates that should be loaded."""
|
||||
var target: Dictionary = {}
|
||||
var half: int = streaming_radius
|
||||
var z_min: int = -half if Chunk.CHUNK_SIZE_Z > 1 else 0
|
||||
var z_max: int = half if Chunk.CHUNK_SIZE_Z > 1 else 0
|
||||
for dx in range(-half, half + 1):
|
||||
for dy in range(-half, half + 1):
|
||||
for dz in range(-half, half + 1):
|
||||
for dz in range(z_min, z_max + 1):
|
||||
var coord: Vector3i = Vector3i(
|
||||
_player_chunk_coord.x + dx,
|
||||
_player_chunk_coord.y + dy,
|
||||
|
||||
Reference in New Issue
Block a user