From 1406b17d62025bf5917e5f19f6b4bfc75cbafcad Mon Sep 17 00:00:00 2001 From: edmand45 Date: Sat, 1 Jul 2023 08:12:40 +0300 Subject: [PATCH] :ambulance: independent buffers in properties --- Ragon.Client/Sources/Entity/RagonProperty.cs | 33 ++++++++++++++------ Ragon.Server/Sources/Room/RagonRoom.cs | 2 +- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Ragon.Client/Sources/Entity/RagonProperty.cs b/Ragon.Client/Sources/Entity/RagonProperty.cs index b629a40..c0b9376 100644 --- a/Ragon.Client/Sources/Entity/RagonProperty.cs +++ b/Ragon.Client/Sources/Entity/RagonProperty.cs @@ -29,6 +29,7 @@ namespace Ragon.Client public bool IsFixed => _fixed; public int Size => _size; + private RagonBuffer _propertyBuffer; private RagonEntity _entity; private bool _dirty; private int _size; @@ -44,6 +45,7 @@ namespace Ragon.Client _size = 0; _priority = priority; _fixed = false; + _propertyBuffer = new RagonBuffer(); InvokeLocal = invokeLocal; } @@ -98,25 +100,38 @@ namespace Ragon.Client internal void Write(RagonBuffer buffer) { + _propertyBuffer.Clear(); + if (_fixed) { - Serialize(buffer); + Serialize(_propertyBuffer); + + buffer.FromBuffer(_propertyBuffer, _size); return; } - var sizeOffset = buffer.WriteOffset; - buffer.Write(0, 16); - var propOffset = buffer.WriteOffset; + Serialize(_propertyBuffer); - Serialize(buffer); - - var propSize = (uint)(buffer.WriteOffset - propOffset); - buffer.Write(propSize, 16, sizeOffset); + var propertySize = (ushort) _propertyBuffer.WriteOffset; + buffer.WriteUShort(propertySize);; + buffer.FromBuffer(_propertyBuffer, propertySize); } 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) diff --git a/Ragon.Server/Sources/Room/RagonRoom.cs b/Ragon.Server/Sources/Room/RagonRoom.cs index f90c513..e0ab00c 100644 --- a/Ragon.Server/Sources/Room/RagonRoom.cs +++ b/Ragon.Server/Sources/Room/RagonRoom.cs @@ -154,7 +154,7 @@ public class RagonRoom : IRagonRoom, IRagonAction Writer.Clear(); Writer.WriteOperation(RagonOperation.OWNERSHIP_ENTITY_CHANGED); - Writer.WriteString(Owner.Id); + Writer.WriteUShort(Owner.Connection.Id); Writer.WriteUShort((ushort)entitiesToUpdate.Count); foreach (var entity in entitiesToUpdate)