🐛 use 8-bit integer for synced health, damage scaling and display updates

This commit is contained in:
anyreso 2024-05-14 10:20:45 -04:00
parent f1df203a76
commit 547c97bfba
10 changed files with 107 additions and 101 deletions

View file

@ -17,7 +17,6 @@ class_name Player extends RigidBody3D
enum PlayerState { PLAYER_ALIVE, PLAYER_DEAD }
signal died(player : Player, killer_id : int)
signal energy_changed(energy : float)
@export var iff : IFF
@export var health_component : HealthComponent
@ -67,8 +66,8 @@ func _ready() -> void:
match_participant.player_id_changed.connect(input.update_multiplayer_authority)
match_participant.username_changed.connect(iff._on_username_changed)
health_component.health_changed.connect(hud._on_health_changed)
health_component.health_changed.connect(iff._on_health_changed)
health_component.health_changed.connect(hud.health_bar.set_value)
health_component.health_changed.connect(iff.health_bar.set_value)
health_component.health_changed.emit(health_component.health)
health_component.health_zeroed.connect(die)
@ -153,11 +152,10 @@ func _update_jetpack_energy(delta : float) -> void:
energy -= energy_drain_rate * delta
else:
energy += energy_charge_rate * delta
energy = clamp(energy, 0, energy_max)
energy_changed.emit(energy)
hud.energy_bar.value = energy
func _handle_movement() -> void:
func _integrate_forces(_state : PhysicsDirectBodyState3D) -> void:
# retrieve user's direction vector
var _input_dir : Vector2 = input.direction
# compute direction in local space
@ -199,9 +197,6 @@ func _handle_movement() -> void:
_jumping = false
func _integrate_forces(_state : PhysicsDirectBodyState3D) -> void:
_handle_movement()
func _update_third_person_animations() -> void:
if _is_pawn():
return

View file

@ -4,7 +4,6 @@
[ext_resource type="PackedScene" uid="uid://bbeecp3jusppn" path="res://interfaces/hud/iffs/IFF.tscn" id="2_s5wgp"]
[ext_resource type="PackedScene" uid="uid://bcv81ku26xo" path="res://interfaces/hud/hud.tscn" id="3_ccety"]
[ext_resource type="Shape3D" uid="uid://cb8esdlnottdn" path="res://entities/player/resources/collider.tres" id="4_8kvcy"]
[ext_resource type="Script" path="res://entities/components/match_participant.gd" id="6_lrose"]
[ext_resource type="Script" path="res://entities/components/inventory.gd" id="8_768qh"]
[ext_resource type="PackedScene" uid="uid://drbefw6akui2v" path="res://entities/player/vanguard.tscn" id="8_eiy7q"]
[ext_resource type="Script" path="res://entities/components/flag_carry_component.gd" id="8_pdfbn"]
@ -17,6 +16,7 @@
[ext_resource type="PackedScene" uid="uid://b0xql5hi0b52y" path="res://entities/weapons/chaingun/chaingun.tscn" id="15_io0a3"]
[ext_resource type="PackedScene" uid="uid://cstl7yxc75572" path="res://entities/weapons/grenade_launcher/grenade_launcher.tscn" id="16_4xs2j"]
[ext_resource type="PackedScene" uid="uid://d3l7fvbdg6m5g" path="res://entities/flag/assets/flag.glb" id="18_7nkei"]
[ext_resource type="Script" path="res://entities/components/match_participant.gd" id="18_t2jrs"]
[ext_resource type="Script" path="res://entities/player/inputs_sync.gd" id="18_v4iu1"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_clur0"]
@ -374,7 +374,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.692504, 1.30946)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.692504, 1.30946)
[node name="Barrels" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun" index="3"]
transform = Transform3D(-1, -1.49012e-08, 8.801e-08, 8.19564e-08, -3.72529e-09, 1, 0, 1, -7.45058e-09, 5.96046e-08, 0, -0.55315)
transform = Transform3D(-1, 0, 8.9407e-08, 8.47504e-08, 0, 1, 0, 1, -3.72529e-09, -5.96046e-08, 0, -0.55315)
[node name="Skeleton3D" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature" index="0"]
bones/0/rotation = Quaternion(0, 0.707107, 0.707107, 0)
@ -436,13 +436,11 @@ script = ExtResource("18_v4iu1")
replication_config = SubResource("SceneReplicationConfig_5j4ew")
[node name="MatchParticipant" type="Node" parent="."]
script = ExtResource("6_lrose")
script = ExtResource("18_t2jrs")
[node name="MatchParticipantSync" type="MultiplayerSynchronizer" parent="MatchParticipant"]
replication_config = SubResource("SceneReplicationConfig_7na0c")
[connection signal="energy_changed" from="." to="HUD" method="_on_player_energy_changed"]
[editable path="ThirdPerson/Mesh"]
[editable path="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/SpaceGun"]
[editable path="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/SpaceGun/Mesh"]