feat: added spawn payload in snapshot, reduce allocations in entity state
This commit is contained in:
@@ -10,6 +10,7 @@ public class Entity
|
|||||||
public ushort EntityType { get; private set; }
|
public ushort EntityType { get; private set; }
|
||||||
public RagonAuthority Authority { get; private set; }
|
public RagonAuthority Authority { get; private set; }
|
||||||
public EntityState State { get; private set; }
|
public EntityState State { get; private set; }
|
||||||
|
public EntityState Payload { get; private set; }
|
||||||
|
|
||||||
public Entity(uint ownerId, ushort entityType, RagonAuthority stateAuthority, RagonAuthority eventAuthority)
|
public Entity(uint ownerId, ushort entityType, RagonAuthority stateAuthority, RagonAuthority eventAuthority)
|
||||||
{
|
{
|
||||||
@@ -17,6 +18,7 @@ public class Entity
|
|||||||
EntityType = entityType;
|
EntityType = entityType;
|
||||||
EntityId = _idGenerator++;
|
EntityId = _idGenerator++;
|
||||||
State = new EntityState(stateAuthority);
|
State = new EntityState(stateAuthority);
|
||||||
|
Payload = new EntityState(stateAuthority);
|
||||||
Authority = eventAuthority;
|
Authority = eventAuthority;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,27 +8,31 @@ public class EntityState
|
|||||||
{
|
{
|
||||||
public bool isDirty { get; private set; }
|
public bool isDirty { get; private set; }
|
||||||
public RagonAuthority Authority { get; private set; }
|
public RagonAuthority Authority { get; private set; }
|
||||||
|
public int Size => _size;
|
||||||
public byte[] Data
|
|
||||||
{
|
private int _size = 0;
|
||||||
get => _data;
|
private byte[] _data = new byte[2048];
|
||||||
set
|
|
||||||
{
|
|
||||||
_data = value;
|
|
||||||
isDirty = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte[] _data = Array.Empty<byte>();
|
|
||||||
|
|
||||||
public EntityState(RagonAuthority ragonAuthority)
|
public EntityState(RagonAuthority ragonAuthority)
|
||||||
{
|
{
|
||||||
Authority = ragonAuthority;
|
Authority = ragonAuthority;
|
||||||
isDirty = true;
|
isDirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Clear()
|
public ReadOnlySpan<byte> Read()
|
||||||
{
|
{
|
||||||
|
return _data.AsSpan().Slice(0, _size);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Write(ref ReadOnlySpan<byte> src)
|
||||||
|
{
|
||||||
|
src.CopyTo(_data);
|
||||||
|
_size = src.Length;
|
||||||
isDirty = true;
|
isDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
isDirty = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user