fix: restoring properties

This commit is contained in:
2022-08-27 10:51:57 +04:00
parent 6a71fe5fe0
commit 568a3282c3
+16 -11
View File
@@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using NLog; using NLog;
using Ragon.Common; using Ragon.Common;
@@ -481,6 +480,11 @@ namespace Ragon.Core
{ {
_scheduler.Tick(deltaTime); _scheduler.Tick(deltaTime);
ReplicateProperties();
}
private void ReplicateProperties()
{
if (_entitiesDirty.Count > 0) if (_entitiesDirty.Count > 0)
{ {
_serializer.Clear(); _serializer.Clear();
@@ -532,12 +536,19 @@ namespace Ragon.Core
for (int propertyIndex = 0; propertyIndex < entity.Properties.Length; propertyIndex++) for (int propertyIndex = 0; propertyIndex < entity.Properties.Length; propertyIndex++)
{ {
var property = entity.Properties[propertyIndex]; var property = entity.Properties[propertyIndex];
var hasPayload = property.IsFixed || property.Size > 0 && !property.IsFixed;
if (hasPayload)
{
_serializer.WriteBool(true); _serializer.WriteBool(true);
var span = _serializer.GetWritableData(property.Size); var span = _serializer.GetWritableData(property.Size);
var data = property.Read(); var data = property.Read();
data.CopyTo(span); data.CopyTo(span);
} }
else
{
_serializer.WriteBool(false);
}
}
} }
var sendData = _serializer.ToArray(); var sendData = _serializer.ToArray();
@@ -568,19 +579,13 @@ namespace Ragon.Core
public IScheduler GetScheduler() => _scheduler; public IScheduler GetScheduler() => _scheduler;
public void Send(uint peerId, byte[] rawData, DeliveryType deliveryType = DeliveryType.Unreliable) public void Send(uint peerId, byte[] rawData, DeliveryType deliveryType = DeliveryType.Unreliable) =>
{
_gameThread.Server.Send(peerId, rawData, deliveryType); _gameThread.Server.Send(peerId, rawData, deliveryType);
}
public void Broadcast(uint[] peersIds, byte[] rawData, DeliveryType deliveryType = DeliveryType.Unreliable) public void Broadcast(uint[] peersIds, byte[] rawData, DeliveryType deliveryType = DeliveryType.Unreliable) =>
{
_gameThread.Server.Broadcast(peersIds, rawData, deliveryType); _gameThread.Server.Broadcast(peersIds, rawData, deliveryType);
}
public void Broadcast(byte[] rawData, DeliveryType deliveryType = DeliveryType.Unreliable) public void Broadcast(byte[] rawData, DeliveryType deliveryType = DeliveryType.Unreliable) =>
{
_gameThread.Server.Broadcast(_allPlayers, rawData, deliveryType); _gameThread.Server.Broadcast(_allPlayers, rawData, deliveryType);
} }
} }
}