fix(gameplay): escape pause menu + block placement collision + perf optim render_distance/throttling
This commit is contained in:
@@ -3,7 +3,7 @@ class_name ChunkManager
|
||||
|
||||
const CHUNK_SIZE: int = 16
|
||||
|
||||
@export var render_distance: int = 4
|
||||
@export var render_distance: int = 2
|
||||
@export var world_seed: int = 12345
|
||||
|
||||
var chunks: Dictionary = {}
|
||||
@@ -36,6 +36,26 @@ func update_player_position(pos: Vector3) -> void:
|
||||
if not chunks.has(coord):
|
||||
_load_chunk(coord)
|
||||
|
||||
func _regen_border_neighbors(chunk_coord: Vector3i, local: Vector3i) -> void:
|
||||
# Regen adjacent chunk only if block is on the border face
|
||||
var offsets: Array[Vector3i] = []
|
||||
if local.x == 0:
|
||||
offsets.append(Vector3i(-1, 0, 0))
|
||||
elif local.x == CHUNK_SIZE - 1:
|
||||
offsets.append(Vector3i(1, 0, 0))
|
||||
if local.y == 0:
|
||||
offsets.append(Vector3i(0, -1, 0))
|
||||
elif local.y == CHUNK_SIZE - 1:
|
||||
offsets.append(Vector3i(0, 1, 0))
|
||||
if local.z == 0:
|
||||
offsets.append(Vector3i(0, 0, -1))
|
||||
elif local.z == CHUNK_SIZE - 1:
|
||||
offsets.append(Vector3i(0, 0, 1))
|
||||
for offset: Vector3i in offsets:
|
||||
var neighbor: Vector3i = chunk_coord + offset
|
||||
if chunks.has(neighbor):
|
||||
chunks[neighbor].generate_mesh()
|
||||
|
||||
func break_block(world_pos: Vector3) -> int:
|
||||
var chunk_coord: Vector3i = world_to_chunk_coord(world_pos)
|
||||
if not chunks.has(chunk_coord):
|
||||
@@ -47,6 +67,7 @@ func break_block(world_pos: Vector3) -> int:
|
||||
return 0
|
||||
chunk.set_block(local.x, local.y, local.z, BlockDatabase.BlockType.AIR)
|
||||
chunk.generate_mesh()
|
||||
_regen_border_neighbors(chunk_coord, local)
|
||||
return old_id
|
||||
|
||||
func place_block(world_pos: Vector3, block_id: int) -> bool:
|
||||
@@ -60,6 +81,7 @@ func place_block(world_pos: Vector3, block_id: int) -> bool:
|
||||
return false
|
||||
chunk.set_block(local.x, local.y, local.z, block_id)
|
||||
chunk.generate_mesh()
|
||||
_regen_border_neighbors(chunk_coord, local)
|
||||
return true
|
||||
|
||||
func get_block(world_pos: Vector3) -> int:
|
||||
|
||||
Reference in New Issue
Block a user