️ Headless optimizations

This commit is contained in:
anyreso 2024-04-29 15:12:56 +00:00
parent 42c2cef6b1
commit da01d7da36
8 changed files with 48 additions and 49 deletions

View file

@ -43,4 +43,3 @@ func drop(dropper : Player) -> void:
_mesh.show()
flag_state = FlagState.FLAG_STATE_DROPPED
dropped.emit(dropper)

View file

@ -24,6 +24,12 @@ func _ready() -> void:
Vector3(0, flag.get_node("CollisionShape3D").shape.size.y, 0))
func _process(_delta : float) -> void:
# disable waypoint repositioning when running headless
if DisplayServer.get_name() == "headless":
set_process(false)
return
# repositon iff on viewport
var camera : Camera3D = get_viewport().get_camera_3d()
var viewport_rect : Rect2 = get_viewport_rect()
# if the player is NOT infront of the camera or camera does NOT have LOS to player
@ -32,15 +38,12 @@ func _process(_delta : float) -> void:
return
else:
_iff_container.show() # display the IFF
# get the screen location of the players head
var new_iff_position : Vector2 = camera.unproject_position(attach_point.global_position)
# check if the unprojected point lies inside the viewport
if !Rect2(Vector2(0, 0), viewport_rect.size).has_point(new_iff_position):
_iff_container.hide() # hide the IFF and exit function
return
# move the IFF up so the bottom of it is at the players head
new_iff_position.y -= _iff_container.size.y
# move the IFF left so it's centered horizontally above players head