🚑 independent buffers in properties

This commit is contained in:
2023-07-01 08:12:40 +03:00
parent 105457ffa0
commit 1406b17d62
2 changed files with 25 additions and 10 deletions
+24 -9
View File
@@ -29,6 +29,7 @@ namespace Ragon.Client
public bool IsFixed => _fixed; public bool IsFixed => _fixed;
public int Size => _size; public int Size => _size;
private RagonBuffer _propertyBuffer;
private RagonEntity _entity; private RagonEntity _entity;
private bool _dirty; private bool _dirty;
private int _size; private int _size;
@@ -44,6 +45,7 @@ namespace Ragon.Client
_size = 0; _size = 0;
_priority = priority; _priority = priority;
_fixed = false; _fixed = false;
_propertyBuffer = new RagonBuffer();
InvokeLocal = invokeLocal; InvokeLocal = invokeLocal;
} }
@@ -98,25 +100,38 @@ namespace Ragon.Client
internal void Write(RagonBuffer buffer) internal void Write(RagonBuffer buffer)
{ {
_propertyBuffer.Clear();
if (_fixed) if (_fixed)
{ {
Serialize(buffer); Serialize(_propertyBuffer);
buffer.FromBuffer(_propertyBuffer, _size);
return; return;
} }
var sizeOffset = buffer.WriteOffset; Serialize(_propertyBuffer);
buffer.Write(0, 16);
var propOffset = buffer.WriteOffset;
Serialize(buffer); var propertySize = (ushort) _propertyBuffer.WriteOffset;
buffer.WriteUShort(propertySize);;
var propSize = (uint)(buffer.WriteOffset - propOffset); buffer.FromBuffer(_propertyBuffer, propertySize);
buffer.Write(propSize, 16, sizeOffset);
} }
internal void Read(RagonBuffer buffer) internal void Read(RagonBuffer buffer)
{ {
Deserialize(buffer); _propertyBuffer.Clear();
if (_fixed)
{
buffer.ToBuffer(_propertyBuffer, _size);
Deserialize(_propertyBuffer);
return;
}
var propSize = buffer.ReadUShort();
buffer.ToBuffer(_propertyBuffer, propSize);
Deserialize(_propertyBuffer);
} }
public virtual void Serialize(RagonBuffer buffer) public virtual void Serialize(RagonBuffer buffer)
+1 -1
View File
@@ -154,7 +154,7 @@ public class RagonRoom : IRagonRoom, IRagonAction
Writer.Clear(); Writer.Clear();
Writer.WriteOperation(RagonOperation.OWNERSHIP_ENTITY_CHANGED); Writer.WriteOperation(RagonOperation.OWNERSHIP_ENTITY_CHANGED);
Writer.WriteString(Owner.Id); Writer.WriteUShort(Owner.Connection.Id);
Writer.WriteUShort((ushort)entitiesToUpdate.Count); Writer.WriteUShort((ushort)entitiesToUpdate.Count);
foreach (var entity in entitiesToUpdate) foreach (var entity in entitiesToUpdate)