Networking

This commit is contained in:
2023-01-17 22:30:12 +01:00
parent 9893bc45b4
commit ce7b74c832
8 changed files with 116 additions and 48 deletions

View File

@@ -1,5 +1,24 @@
extends Node
###SYNC PLAYER###
const PLAYER_STATE_SIZE = 13
var player_state:
get:
var buf = PackedByteArray()
buf.resize(PLAYER_STATE_SIZE)
buf.encode_half(0, sync_position.x)
buf.encode_half(2, sync_position.y)
buf.encode_half(4, sync_position.z)
buf.encode_half(6, sync_velocity.x)
buf.encode_half(8, sync_velocity.y)
buf.encode_half(10, sync_velocity.z)
return buf
set(value):
assert(typeof(value) == TYPE_PACKED_BYTE_ARRAY and value.size() == PLAYER_STATE_SIZE,
"Invalid `player_state` array type or size (must be TYPE_PACKED_BYTE_ARRAY of size 11).")
sync_position = Vector3(value.decode_half(0), value.decode_half(2), value.decode_half(4))
sync_velocity = Vector3(value.decode_half(6), value.decode_half(8), value.decode_half(10))
var sync_position : Vector3:
set(value):
sync_position = value
@@ -8,3 +27,5 @@ var sync_velocity : Vector3
var sync_is_jumping : bool
var processed_position : bool