🚑 fixed empty state values

This commit is contained in:
2023-07-30 17:44:51 +03:00
parent cd9304e63a
commit 4a8aae11e3
3 changed files with 7 additions and 9 deletions
@@ -66,7 +66,6 @@ internal class SnapshotHandler : Handler
var entityId = buffer.ReadUShort(); var entityId = buffer.ReadUShort();
var ownerPeerId = buffer.ReadUShort(); var ownerPeerId = buffer.ReadUShort();
var payloadSize = buffer.ReadUShort(); var payloadSize = buffer.ReadUShort();
RagonLog.Trace("Read offset: " + buffer.ReadOffset);
var player = _playerCache.GetPlayerByPeer(ownerPeerId); var player = _playerCache.GetPlayerByPeer(ownerPeerId);
if (player == null) if (player == null)
@@ -21,14 +21,12 @@ namespace Ragon.Server.Entity;
public class RagonEntityState: IRagonEntityState public class RagonEntityState: IRagonEntityState
{ {
private List<RagonProperty> _properties; private readonly List<RagonProperty> _properties;
private RagonEntity _entity; private readonly RagonEntity _entity;
private RagonBuffer _buffer;
public RagonEntityState(RagonEntity entity, int capacity = 10) public RagonEntityState(RagonEntity entity, int capacity = 10)
{ {
_entity = entity; _entity = entity;
_buffer = new RagonBuffer(8);
_properties = new List<RagonProperty>(capacity); _properties = new List<RagonProperty>(capacity);
} }
@@ -67,8 +65,7 @@ public class RagonEntityState: IRagonEntityState
{ {
foreach (var property in _properties) foreach (var property in _properties)
{ {
var hasPayloadOrFixed = property.IsFixed || property is { IsFixed: false, Size: > 0 }; if (property.HasData)
if (hasPayloadOrFixed)
{ {
buffer.WriteBool(true); buffer.WriteBool(true);
property.Write(buffer); property.Write(buffer);
@@ -23,6 +23,7 @@ public class RagonProperty : RagonPayload
public int Size { get; set; } public int Size { get; set; }
public bool IsDirty { get; private set; } public bool IsDirty { get; private set; }
public bool IsFixed { get; private set; } public bool IsFixed { get; private set; }
public bool HasData { get; private set; }
private uint[] _data; private uint[] _data;
@@ -47,6 +48,7 @@ public class RagonProperty : RagonPayload
buffer.ReadArray(_data, Size); buffer.ReadArray(_data, Size);
} }
HasData = true;
IsDirty = true; IsDirty = true;
} }