refactor: entity structure changes
This commit is contained in:
@@ -6,6 +6,7 @@ public class Loop
|
|||||||
|
|
||||||
public Loop()
|
public Loop()
|
||||||
{
|
{
|
||||||
|
|
||||||
_tasks = new List<IAction>(35);
|
_tasks = new List<IAction>(35);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class Entity
|
|||||||
writer.Clear();
|
writer.Clear();
|
||||||
writer.WriteOperation(RagonOperation.REPLICATE_ENTITY_EVENT);
|
writer.WriteOperation(RagonOperation.REPLICATE_ENTITY_EVENT);
|
||||||
writer.WriteUShort(bufferedEvent.EventId);
|
writer.WriteUShort(bufferedEvent.EventId);
|
||||||
writer.WriteUShort(bufferedEvent.PeerId);
|
writer.WriteUShort(bufferedEvent.Invoker.Connection.Id);
|
||||||
writer.WriteByte((byte)RagonReplicationMode.Server);
|
writer.WriteByte((byte)RagonReplicationMode.Server);
|
||||||
writer.WriteUShort(Id);
|
writer.WriteUShort(Id);
|
||||||
|
|
||||||
@@ -134,13 +134,7 @@ public class Entity
|
|||||||
|
|
||||||
if (eventMode == RagonReplicationMode.Buffered && targetMode != RagonTarget.Owner)
|
if (eventMode == RagonReplicationMode.Buffered && targetMode != RagonTarget.Owner)
|
||||||
{
|
{
|
||||||
var bufferedEvent = new EntityEvent()
|
var bufferedEvent = new EntityEvent(caller, eventId, payload.ToArray(), targetMode);
|
||||||
{
|
|
||||||
EventData = payload.ToArray(),
|
|
||||||
Target = targetMode,
|
|
||||||
EventId = eventId,
|
|
||||||
PeerId = caller.Connection.Id,
|
|
||||||
};
|
|
||||||
_bufferedEvents.Add(bufferedEvent);
|
_bufferedEvents.Add(bufferedEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,21 @@ namespace Ragon.Core.Game;
|
|||||||
|
|
||||||
public class EntityEvent
|
public class EntityEvent
|
||||||
{
|
{
|
||||||
public ushort PeerId { get; set; }
|
public RoomPlayer Invoker { get; private set; }
|
||||||
public ushort EventId { get; set; }
|
public ushort EventId { get; private set; }
|
||||||
public byte[] EventData { get; set; }
|
public byte[] EventData { get; private set; }
|
||||||
public RagonTarget Target { set; get; }
|
public RagonTarget Target { set; private get; }
|
||||||
|
|
||||||
|
public EntityEvent(
|
||||||
|
RoomPlayer invoker,
|
||||||
|
ushort eventId,
|
||||||
|
byte[] payload,
|
||||||
|
RagonTarget target
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Invoker = invoker;
|
||||||
|
EventId = eventId;
|
||||||
|
EventData = payload;
|
||||||
|
Target = target;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,18 +2,18 @@ namespace Ragon.Core.Game;
|
|||||||
|
|
||||||
public class EntityList
|
public class EntityList
|
||||||
{
|
{
|
||||||
private List<Entity> _dynamicEntitiesList = new List<Entity>();
|
private readonly List<Entity> _dynamicEntitiesList = new List<Entity>();
|
||||||
private List<Entity> _staticEntitesList = new List<Entity>();
|
private readonly List<Entity> _staticEntitiesList = new List<Entity>();
|
||||||
private Dictionary<ushort, Entity> _entitiesMap = new Dictionary<ushort, Entity>();
|
private readonly Dictionary<ushort, Entity> _entitiesMap = new Dictionary<ushort, Entity>();
|
||||||
|
|
||||||
public IReadOnlyList<Entity> StaticList => _staticEntitesList;
|
public IReadOnlyList<Entity> StaticList => _staticEntitiesList;
|
||||||
public IReadOnlyList<Entity> DynamicList => _dynamicEntitiesList;
|
public IReadOnlyList<Entity> DynamicList => _dynamicEntitiesList;
|
||||||
public IReadOnlyDictionary<ushort, Entity> Map => _entitiesMap;
|
public IReadOnlyDictionary<ushort, Entity> Map => _entitiesMap;
|
||||||
|
|
||||||
public void Add(Entity entity)
|
public void Add(Entity entity)
|
||||||
{
|
{
|
||||||
if (entity.StaticId != 0)
|
if (entity.StaticId != 0)
|
||||||
_staticEntitesList.Add(entity);
|
_staticEntitiesList.Add(entity);
|
||||||
else
|
else
|
||||||
_dynamicEntitiesList.Add(entity);
|
_dynamicEntitiesList.Add(entity);
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ public class EntityList
|
|||||||
{
|
{
|
||||||
if (_entitiesMap.Remove(entity.Id, out var existEntity))
|
if (_entitiesMap.Remove(entity.Id, out var existEntity))
|
||||||
{
|
{
|
||||||
_staticEntitesList.Remove(entity);
|
_staticEntitiesList.Remove(entity);
|
||||||
_dynamicEntitiesList.Remove(entity);
|
_dynamicEntitiesList.Remove(entity);
|
||||||
|
|
||||||
return existEntity;
|
return existEntity;
|
||||||
|
|||||||
Reference in New Issue
Block a user