From 4a8aae11e3adbedd6297dc05c6940f42015441a9 Mon Sep 17 00:00:00 2001 From: edmand45 Date: Sun, 30 Jul 2023 17:44:51 +0300 Subject: [PATCH] :ambulance: fixed empty state values --- Ragon.Client/Sources/Handler/SnapshotHandler.cs | 3 +-- Ragon.Server/Sources/Entity/RagonEntityState.cs | 11 ++++------- Ragon.Server/Sources/Entity/RagonProperty.cs | 2 ++ 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Ragon.Client/Sources/Handler/SnapshotHandler.cs b/Ragon.Client/Sources/Handler/SnapshotHandler.cs index 09611a5..a9d46c7 100644 --- a/Ragon.Client/Sources/Handler/SnapshotHandler.cs +++ b/Ragon.Client/Sources/Handler/SnapshotHandler.cs @@ -66,8 +66,7 @@ internal class SnapshotHandler : Handler var entityId = buffer.ReadUShort(); var ownerPeerId = buffer.ReadUShort(); var payloadSize = buffer.ReadUShort(); - RagonLog.Trace("Read offset: " + buffer.ReadOffset); - + var player = _playerCache.GetPlayerByPeer(ownerPeerId); if (player == null) { diff --git a/Ragon.Server/Sources/Entity/RagonEntityState.cs b/Ragon.Server/Sources/Entity/RagonEntityState.cs index 8df9dab..5543755 100644 --- a/Ragon.Server/Sources/Entity/RagonEntityState.cs +++ b/Ragon.Server/Sources/Entity/RagonEntityState.cs @@ -21,14 +21,12 @@ namespace Ragon.Server.Entity; public class RagonEntityState: IRagonEntityState { - private List _properties; - private RagonEntity _entity; - private RagonBuffer _buffer; - + private readonly List _properties; + private readonly RagonEntity _entity; + public RagonEntityState(RagonEntity entity, int capacity = 10) { _entity = entity; - _buffer = new RagonBuffer(8); _properties = new List(capacity); } @@ -67,8 +65,7 @@ public class RagonEntityState: IRagonEntityState { foreach (var property in _properties) { - var hasPayloadOrFixed = property.IsFixed || property is { IsFixed: false, Size: > 0 }; - if (hasPayloadOrFixed) + if (property.HasData) { buffer.WriteBool(true); property.Write(buffer); diff --git a/Ragon.Server/Sources/Entity/RagonProperty.cs b/Ragon.Server/Sources/Entity/RagonProperty.cs index b01509f..ec18b08 100644 --- a/Ragon.Server/Sources/Entity/RagonProperty.cs +++ b/Ragon.Server/Sources/Entity/RagonProperty.cs @@ -23,6 +23,7 @@ public class RagonProperty : RagonPayload public int Size { get; set; } public bool IsDirty { get; private set; } public bool IsFixed { get; private set; } + public bool HasData { get; private set; } private uint[] _data; @@ -47,6 +48,7 @@ public class RagonProperty : RagonPayload buffer.ReadArray(_data, Size); } + HasData = true; IsDirty = true; }