Files
Ragon/Ragon.Core/Game/EntityStateProperty.cs
T

41 lines
832 B
C#
Raw Normal View History

2022-08-13 18:54:02 +04:00
using System;
2022-08-20 12:27:04 +04:00
using Ragon.Common;
2022-08-13 18:54:02 +04:00
2022-12-16 00:05:46 +04:00
namespace Ragon.Core.Game;
2022-08-13 18:54:02 +04:00
2022-12-16 00:05:46 +04:00
public class EntityStateProperty
2022-08-13 18:54:02 +04:00
{
2022-08-20 12:27:04 +04:00
public int Size { get; set; }
2022-08-27 11:21:51 +04:00
public int Capacity { get; set; }
2022-08-20 12:27:04 +04:00
public bool IsDirty { get; private set; }
public bool IsFixed { get; private set; }
2022-08-13 18:54:02 +04:00
private byte[] _data;
2022-08-20 12:27:04 +04:00
2022-12-16 00:05:46 +04:00
public EntityStateProperty(int size, bool isFixed)
2022-08-13 18:54:02 +04:00
{
2022-08-27 11:21:51 +04:00
Capacity = 512;
2022-08-20 12:27:04 +04:00
Size = size;
IsFixed = isFixed;
IsDirty = true;
2022-08-27 11:21:51 +04:00
_data = new byte[Capacity];
2022-08-13 18:54:02 +04:00
}
public ReadOnlySpan<byte> Read()
{
2022-08-20 12:27:04 +04:00
var dataSpan = _data.AsSpan();
var src = dataSpan.Slice(0, Size);
return src;
2022-08-13 18:54:02 +04:00
}
public void Write(ref ReadOnlySpan<byte> src)
{
src.CopyTo(_data);
2022-08-20 12:27:04 +04:00
IsDirty = true;
2022-08-13 18:54:02 +04:00
}
public void Clear()
{
2022-08-20 12:27:04 +04:00
IsDirty = false;
2022-08-13 18:54:02 +04:00
}
}