fix: static in snapshot

This commit is contained in:
2022-08-14 12:36:12 +04:00
parent 81879d4fe2
commit f2934bc8ee
4 changed files with 14 additions and 17 deletions
+2 -2
View File
@@ -8,12 +8,12 @@ public class Entity
public ushort EntityId { get; private set; } public ushort EntityId { get; private set; }
public ushort StaticId { get; private set; } public ushort StaticId { get; private set; }
public ushort EntityType { get; private set; } public ushort EntityType { get; private set; }
public uint OwnerId { get; private set; } public ushort OwnerId { get; private set; }
public RagonAuthority Authority { get; private set; } public RagonAuthority Authority { get; private set; }
public EntityProperty[] Properties { get; private set; } public EntityProperty[] Properties { get; private set; }
public byte[] Payload { get; set; } public byte[] Payload { get; set; }
public Entity(uint ownerId, ushort entityType, ushort staticId, RagonAuthority stateAuthority, RagonAuthority eventAuthority, int props) public Entity(ushort ownerId, ushort entityType, ushort staticId, RagonAuthority stateAuthority, RagonAuthority eventAuthority, int props)
{ {
OwnerId = ownerId; OwnerId = ownerId;
StaticId = staticId; StaticId = staticId;
+10 -13
View File
@@ -120,11 +120,11 @@ namespace Ragon.Core
} }
} }
public void ProcessEvent(uint peerId, RagonOperation operation, ReadOnlySpan<byte> payloadRawData) public void ProcessEvent(ushort peerId, RagonOperation operation, ReadOnlySpan<byte> payloadRawData)
{ {
_serializer.Clear(); _serializer.Clear();
_serializer.FromSpan(ref payloadRawData); _serializer.FromSpan(ref payloadRawData);
switch (operation) switch (operation)
{ {
case RagonOperation.REPLICATE_ENTITY_STATE: case RagonOperation.REPLICATE_ENTITY_STATE:
@@ -137,7 +137,7 @@ namespace Ragon.Core
_logger.Warn($"Not owner can't change properties of object {entityId}"); _logger.Warn($"Not owner can't change properties of object {entityId}");
return; return;
} }
var mask = _serializer.ReadLong(); var mask = _serializer.ReadLong();
for (var i = 0; i < ent.Properties.Length; i++) for (var i = 0; i < ent.Properties.Length; i++)
{ {
@@ -145,9 +145,9 @@ namespace Ragon.Core
{ {
var propertyPayload = _serializer.ReadData(ent.Properties[i].Size); var propertyPayload = _serializer.ReadData(ent.Properties[i].Size);
ent.Properties[i].Write(ref propertyPayload); ent.Properties[i].Write(ref propertyPayload);
} }
} }
if (_entitiesDirtySet.Add(ent)) if (_entitiesDirtySet.Add(ent))
_entitiesDirty.Add(ent); _entitiesDirty.Add(ent);
} }
@@ -260,7 +260,7 @@ namespace Ragon.Core
foreach (var playerPeerId in _readyPlayers) foreach (var playerPeerId in _readyPlayers)
if (playerPeerId != _owner) if (playerPeerId != _owner)
_peersCache.Add(playerPeerId); _peersCache.Add(playerPeerId);
Broadcast(_peersCache.ToArray(), sendData, DeliveryType.Reliable); Broadcast(_peersCache.ToArray(), sendData, DeliveryType.Reliable);
break; break;
} }
@@ -270,6 +270,7 @@ namespace Ragon.Core
break; break;
} }
} }
break; break;
} }
case RagonOperation.CREATE_STATIC_ENTITY: case RagonOperation.CREATE_STATIC_ENTITY:
@@ -282,7 +283,6 @@ namespace Ragon.Core
{ {
var propertySize = _serializer.ReadUShort(); var propertySize = _serializer.ReadUShort();
entity.Properties[i] = new EntityProperty(propertySize); entity.Properties[i] = new EntityProperty(propertySize);
_logger.Trace($"Static Property: {i} {propertySize}");
} }
{ {
@@ -326,11 +326,8 @@ namespace Ragon.Core
{ {
var propertySize = _serializer.ReadUShort(); var propertySize = _serializer.ReadUShort();
entity.Properties[i] = new EntityProperty(propertySize); entity.Properties[i] = new EntityProperty(propertySize);
_logger.Trace($"Property: {i} {propertySize}");
} }
_logger.Trace($"Created object with type: {entityType} {propertiesCount}");
{ {
var entityPayload = _serializer.ReadData(_serializer.Size); var entityPayload = _serializer.ReadData(_serializer.Size);
entity.Payload = entityPayload.ToArray(); entity.Payload = entityPayload.ToArray();
@@ -425,9 +422,9 @@ namespace Ragon.Core
ReadOnlySpan<byte> payload = entity.Payload.AsSpan(); ReadOnlySpan<byte> payload = entity.Payload.AsSpan();
_serializer.WriteUShort(entity.EntityType); _serializer.WriteUShort(entity.EntityType);
_serializer.WriteInt(entity.EntityId); _serializer.WriteUShort(entity.EntityId);
_serializer.WriteUShort((ushort) entity.StaticId); _serializer.WriteUShort(entity.StaticId);
_serializer.WriteUShort((ushort) entity.OwnerId); _serializer.WriteUShort(entity.OwnerId);
_serializer.WriteUShort((ushort) payload.Length); _serializer.WriteUShort((ushort) payload.Length);
_serializer.WriteData(ref payload); _serializer.WriteData(ref payload);
} }
+1 -1
View File
@@ -104,7 +104,7 @@ namespace Ragon.Core
{ {
try try
{ {
var peerId = evnt.Peer.ID; var peerId = (ushort) evnt.Peer.ID;
var dataRaw = new byte[evnt.Packet.Length]; var dataRaw = new byte[evnt.Packet.Length];
evnt.Packet.CopyTo(dataRaw); evnt.Packet.CopyTo(dataRaw);
+1 -1
View File
@@ -23,7 +23,7 @@ public class Lobby : ILobby
_authorizationManager = new AuthorizationManager(provider, gameThread, this, _serializer); _authorizationManager = new AuthorizationManager(provider, gameThread, this, _serializer);
} }
public void ProcessEvent(uint peerId, RagonOperation op, ReadOnlySpan<byte> payload) public void ProcessEvent(ushort peerId, RagonOperation op, ReadOnlySpan<byte> payload)
{ {
_serializer.Clear(); _serializer.Clear();
_serializer.FromSpan(ref payload); _serializer.FromSpan(ref payload);