fix(gameplay): escape pause menu + block placement collision + perf optim render_distance/throttling
This commit is contained in:
@@ -7,6 +7,9 @@ extends Node3D
|
||||
|
||||
var inventory: Inventory = Inventory.new()
|
||||
var _inventory_ui: CanvasLayer = null
|
||||
var _pause_menu: Control = null
|
||||
|
||||
var _last_chunk_update_pos: Vector3 = Vector3(99999, 99999, 99999)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -29,6 +32,12 @@ func _ready() -> void:
|
||||
else:
|
||||
push_error("Main: could not load InventoryUI.tscn")
|
||||
|
||||
# Load and attach PauseMenu
|
||||
var pause_scene: PackedScene = preload("res://scenes/PauseMenu.tscn")
|
||||
_pause_menu = pause_scene.instantiate() as Control
|
||||
add_child(_pause_menu)
|
||||
_pause_menu.hide()
|
||||
|
||||
AudioManager.play_ambient_loop("underwater_ambient")
|
||||
AudioManager.play_music("underwater_theme")
|
||||
AudioManager.play_whale_call_random()
|
||||
@@ -51,10 +60,30 @@ func _ready() -> void:
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
world.update_player_position(dolphin.global_position)
|
||||
# Throttle chunk updates: only when dolphin moved > 4m
|
||||
if dolphin.global_position.distance_to(_last_chunk_update_pos) > 4.0:
|
||||
world.update_player_position(dolphin.global_position)
|
||||
_last_chunk_update_pos = dolphin.global_position
|
||||
plankton_follower.global_position = dolphin.global_position
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if not event.is_action_pressed("escape"):
|
||||
return
|
||||
# Priority: close inventory first if open
|
||||
if _inventory_ui != null and _inventory_ui.get("_is_open"):
|
||||
_inventory_ui.call("_toggle_inventory")
|
||||
get_viewport().set_input_as_handled()
|
||||
return
|
||||
# Toggle pause menu
|
||||
if is_instance_valid(_pause_menu):
|
||||
if _pause_menu.visible:
|
||||
_pause_menu.hide_pause()
|
||||
else:
|
||||
_pause_menu.show_pause()
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
|
||||
func _on_block_break(hit_position: Vector3, _normal: Vector3) -> void:
|
||||
var broken_id: int = world.break_block(hit_position)
|
||||
if broken_id > 0:
|
||||
@@ -68,7 +97,17 @@ func _on_block_place(hit_position: Vector3, normal: Vector3) -> void:
|
||||
return
|
||||
if not ItemDatabase.is_placeable(selected["item_id"]):
|
||||
return
|
||||
|
||||
var place_pos := hit_position + normal * 0.5
|
||||
var block_coord := Vector3(floor(place_pos.x), floor(place_pos.y), floor(place_pos.z))
|
||||
var block_center := block_coord + Vector3(0.5, 0.5, 0.5)
|
||||
|
||||
# Refuse if bloc overlaps player AABB (CapsuleShape3D r=0.4 h=2.0)
|
||||
var dolphin_pos: Vector3 = dolphin.global_position
|
||||
var dist := block_center - dolphin_pos
|
||||
if abs(dist.x) < 1.0 and abs(dist.y) < 1.8 and abs(dist.z) < 1.0:
|
||||
return # too close to player, silent refuse
|
||||
|
||||
if world.place_block(place_pos, selected["item_id"]):
|
||||
inventory.remove_item_from_slot(inventory.selected_hotbar, 1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user