diff --git a/Ragon.Client/Sources/Entity/RagonProperty.cs b/Ragon.Client/Sources/Entity/RagonProperty.cs index c0b9376..df2ddec 100644 --- a/Ragon.Client/Sources/Entity/RagonProperty.cs +++ b/Ragon.Client/Sources/Entity/RagonProperty.cs @@ -106,7 +106,7 @@ namespace Ragon.Client { Serialize(_propertyBuffer); - buffer.FromBuffer(_propertyBuffer, _size); + buffer.CopyFrom(_propertyBuffer, _size); return; } @@ -114,7 +114,7 @@ namespace Ragon.Client var propertySize = (ushort) _propertyBuffer.WriteOffset; buffer.WriteUShort(propertySize);; - buffer.FromBuffer(_propertyBuffer, propertySize); + buffer.CopyFrom(_propertyBuffer, propertySize); } internal void Read(RagonBuffer buffer) diff --git a/Ragon.Protocol/Sources/RagonBuffer.cs b/Ragon.Protocol/Sources/RagonBuffer.cs index 5280758..b23a0f1 100644 --- a/Ragon.Protocol/Sources/RagonBuffer.cs +++ b/Ragon.Protocol/Sources/RagonBuffer.cs @@ -236,9 +236,6 @@ namespace Ragon.Protocol [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Write(uint value, int numBits = 16) { - Debug.Assert(!(numBits < 0)); - Debug.Assert(!(numBits > 32)); - var currentBucketIndex = _write >> 5; var used = _write & 0x0000001F; var mask = (1UL << used) - 1; @@ -357,7 +354,7 @@ namespace Ragon.Protocol } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void FromBuffer(RagonBuffer buffer, int size) + public void CopyFrom(RagonBuffer buffer, int size) { WriteArray(buffer._buckets, size); } @@ -406,7 +403,7 @@ namespace Ragon.Protocol public byte[] ToArray() { Write(1, 1); - + var data = new byte[Length]; int bucketsCount = (_write >> 5) + 1; int length = data.Length; @@ -431,11 +428,11 @@ namespace Ragon.Protocol return data; } - + public void ToArray(byte[] outData) { - Debug.Assert(outData.Length >= Length); - + Write(1, 1); + var bucketsCount = (_write >> 5) + 1; var length = Length; diff --git a/Ragon.Server/Sources/Entity/RagonEntityState.cs b/Ragon.Server/Sources/Entity/RagonEntityState.cs index 5543755..91e1773 100644 --- a/Ragon.Server/Sources/Entity/RagonEntityState.cs +++ b/Ragon.Server/Sources/Entity/RagonEntityState.cs @@ -14,7 +14,6 @@ * limitations under the License. */ - using Ragon.Protocol; namespace Ragon.Server.Entity; diff --git a/Ragon.Server/Sources/Entity/RagonPayload.cs b/Ragon.Server/Sources/Entity/RagonPayload.cs index d073273..ee7232e 100644 --- a/Ragon.Server/Sources/Entity/RagonPayload.cs +++ b/Ragon.Server/Sources/Entity/RagonPayload.cs @@ -28,7 +28,7 @@ public class RagonPayload public void Read(RagonBuffer buffer) { - _size = buffer.Capacity; + _size = buffer.Capacity - 1; buffer.ReadArray(_data, _size); } diff --git a/Ragon.Server/Sources/Entity/RagonProperty.cs b/Ragon.Server/Sources/Entity/RagonProperty.cs index ec18b08..2cd4519 100644 --- a/Ragon.Server/Sources/Entity/RagonProperty.cs +++ b/Ragon.Server/Sources/Entity/RagonProperty.cs @@ -54,6 +54,13 @@ public class RagonProperty : RagonPayload public void Write(RagonBuffer buffer) { + if (IsFixed) + { + buffer.WriteArray(_data, Size); + return; + } + + buffer.Write((ushort) Size); buffer.WriteArray(_data, Size); } diff --git a/Ragon.Server/Sources/RagonServer.cs b/Ragon.Server/Sources/RagonServer.cs index a5b1a54..2b3e1e0 100644 --- a/Ragon.Server/Sources/RagonServer.cs +++ b/Ragon.Server/Sources/RagonServer.cs @@ -99,6 +99,11 @@ public class RagonServer : IRagonServer, INetworkListener _timer.Start(); while (true) { + if (_timer.ElapsedMilliseconds > _tickRate * 2) + { + _logger.Warn($"Slow perfomance: {_timer.ElapsedMilliseconds}"); + } + if (_timer.ElapsedMilliseconds > _tickRate) { _timer.Restart(); @@ -197,7 +202,7 @@ public class RagonServer : IRagonServer, INetworkListener _reader.FromArray(data); var operation = _reader.ReadByte(); - _handlers[operation].Handle(context, channel); + _handlers[operation]?.Handle(context, channel); } } catch (Exception ex)