From ff08e6e4f9b7a51f725d9163ce5c51f7cb23867e Mon Sep 17 00:00:00 2001 From: Rendo Date: Wed, 3 Dec 2025 22:19:44 +0500 Subject: [PATCH] Compressed states --- scenes/molikman.tscn | 3 +++ scripts/multiplayer/player_input.gd | 31 +++++++++++++++++------------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/scenes/molikman.tscn b/scenes/molikman.tscn index 60905eb..c782b2f 100644 --- a/scenes/molikman.tscn +++ b/scenes/molikman.tscn @@ -7620,6 +7620,9 @@ height = 3.7087402 properties/0/path = NodePath("PlayerInput:direction") properties/0/spawn = true properties/0/replication_mode = 1 +properties/1/path = NodePath("PlayerInput:compressed_states") +properties/1/spawn = true +properties/1/replication_mode = 1 [node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("weapon_models")] collision_layer = 2 diff --git a/scripts/multiplayer/player_input.gd b/scripts/multiplayer/player_input.gd index ad3aeb6..b234210 100644 --- a/scripts/multiplayer/player_input.gd +++ b/scripts/multiplayer/player_input.gd @@ -2,14 +2,15 @@ extends MultiplayerSynchronizer class_name PlayerInput +const SCOPE: int = 0b1 +const CROUCH: int = 0b10 +const WALK: int = 0b100 + #region SYNC @export var direction: Vector2 +@export var compressed_states: int #endregion -var crouching: bool = false -var scoping: bool = false -var walking: bool = false - signal jumped signal drop signal switch_weapon(to_slot: StringName) @@ -62,37 +63,41 @@ func _input(event: InputEvent) -> void: if event.is_action_pressed("plr_drop"): drop_on_server.rpc_id(1) + var crouching: bool = compressed_states & CROUCH + var walking: bool = compressed_states & WALK + var scoping: bool = compressed_states & SCOPE + if event.is_action_pressed("plr_crouch"): if ClientSettings.TOGGLE_CROUCH: crouch_on_server.rpc_id(1,crouching) - crouching = not crouching + compressed_states ^= CROUCH elif not crouching: - crouching = true + compressed_states |= CROUCH crouch_on_server.rpc_id(1,false) if event.is_action_released("plr_crouch") and not ClientSettings.TOGGLE_CROUCH and crouching: - crouching = false + compressed_states &= ~CROUCH crouch_on_server.rpc_id(1,true) if event.is_action_pressed("plr_walk"): if ClientSettings.TOGGLE_WALK: walk_on_server.rpc_id(1,walking) - walking = not walking + compressed_states ^= WALK elif not walking: - walking = true + compressed_states |= WALK walk_on_server.rpc_id(1,false) if event.is_action_released("plr_walk") and not ClientSettings.TOGGLE_WALK and walking: - walking = false + compressed_states &= ~WALK walk_on_server.rpc_id(1,true) if event.is_action_pressed("plr_scope"): if ClientSettings.TOGGLE_SCOPE: scope_on_server.rpc_id(1,scoping) - scoping = not scoping + compressed_states ^= SCOPE elif not scoping: - scoping = true + compressed_states |= SCOPE scope_on_server.rpc_id(1,false) if event.is_action_released("plr_scope") and not ClientSettings.TOGGLE_SCOPE and scoping: - scoping = false + compressed_states &= ~SCOPE scope_on_server.rpc_id(1,true) if event.is_action_pressed("plr_reload"):