WIP checkpoint: Implement chunk streaming system in GDScript
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://main_scene"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/chunk_stream_manager.gd" id="1_chunk_stream"]
|
||||
|
||||
[node name="Main" type="Node3D"]
|
||||
script = ExtResource("1_chunk_stream")
|
||||
@@ -77,18 +77,32 @@ var _server_rpc: Object = null
|
||||
## Internal: track which chunks are currently being loaded (to avoid duplicates).
|
||||
var _loading_in_progress: Dictionary = {}
|
||||
|
||||
## Internal: time accumulator for throttled streaming updates.
|
||||
var _update_accumulator: float = 0.0
|
||||
|
||||
## Internal: interval between streaming updates (seconds).
|
||||
const UPDATE_INTERVAL: float = 0.1
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_process_thread = Thread.create(_streaming_loop, Thread.PRIORITY_LOW)
|
||||
# Streaming is driven from _process (main thread) so we can safely
|
||||
# manipulate the scene tree. No background thread is used.
|
||||
set_process(true)
|
||||
|
||||
|
||||
func _streaming_loop() -> void:
|
||||
while is_inside_tree():
|
||||
func _process(delta: float) -> void:
|
||||
if not is_active or player == null:
|
||||
return
|
||||
|
||||
_update_accumulator += delta
|
||||
if _update_accumulator < UPDATE_INTERVAL:
|
||||
return
|
||||
_update_accumulator = 0.0
|
||||
|
||||
_update_streaming()
|
||||
_process_load_queue()
|
||||
_process_unload_queue()
|
||||
streaming_updated.emit()
|
||||
await get_tree().create_timer(0.1).timeout # Check every 100ms
|
||||
|
||||
|
||||
func _update_streaming() -> void:
|
||||
@@ -132,7 +146,7 @@ func _compute_target_chunks() -> Dictionary:
|
||||
var half := streaming_radius
|
||||
for dx in range(-half, half + 1):
|
||||
for dy in range(-half, half + 1):
|
||||
for dz in range(-Chunk.CHUNK_SIZE_Z, Chunk.CHUNK_SIZE_Z + 1):
|
||||
for dz in range(-half, half + 1):
|
||||
var coord := Vector3i(
|
||||
_player_chunk_coord.x + dx,
|
||||
_player_chunk_coord.y + dy,
|
||||
|
||||
Reference in New Issue
Block a user