oecs-sharp/OECS/WorldSnapshot.cs

39 lines
1.0 KiB
C#
Raw Normal View History

using MessagePack;
namespace OECS;
/// <summary>
/// Serializable snapshot of the entire world state.
/// </summary>
[MessagePackObject]
public class WorldSnapshot
{
[Key(0)] public EntitySnapshot[] Entities { get; set; } = [];
}
/// <summary>
/// A single entity and all its components, serialized as name/data pairs.
/// Entity ID and Version are stored separately to avoid issues with
/// MessagePack deserialization of the opaque Entity struct.
/// </summary>
[MessagePackObject]
public class EntitySnapshot
{
[Key(0)] public uint Id { get; set; }
[Key(1)] public uint Version { get; set; }
[Key(2)] public ComponentEntry[] Components { get; set; } = [];
[IgnoreMember]
public Entity Entity => new(Id, Version);
}
/// <summary>
/// A single component, identified by its fully-qualified type name and
/// serialized as a MessagePack byte blob.
/// </summary>
[MessagePackObject]
public class ComponentEntry
{
[Key(0)] public string TypeName { get; set; } = "";
[Key(1)] public byte[] Data { get; set; } = [];
}