2026-07-18 23:41:28 +08:00
|
|
|
namespace OECS;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Describes a component type discovered at compile time by the source generator.
|
|
|
|
|
/// Used by <see cref="WorldSerializer"/> to save/load components without reflection.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class ComponentDescriptor
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The assembly-qualified name of the component type, for stable serialization
|
|
|
|
|
/// across assemblies.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string TypeName { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The <see cref="System.Type"/> of the component.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Type Type { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Serializes a boxed component instance to a MessagePack byte array.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Func<object, byte[]> Serialize { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2026-07-18 23:44:10 +08:00
|
|
|
/// Deserializes a MessagePack byte array and adds the component to the entity
|
|
|
|
|
/// via the typed <see cref="World.AddComponent{T}"/> method. No reflection.
|
2026-07-18 23:41:28 +08:00
|
|
|
/// </summary>
|
2026-07-18 23:44:10 +08:00
|
|
|
public Action<World, Entity, byte[]> DeserializeAndAdd { get; }
|
2026-07-18 23:41:28 +08:00
|
|
|
|
|
|
|
|
public ComponentDescriptor(
|
|
|
|
|
string typeName,
|
|
|
|
|
Type type,
|
|
|
|
|
Func<object, byte[]> serialize,
|
2026-07-18 23:44:10 +08:00
|
|
|
Action<World, Entity, byte[]> deserializeAndAdd)
|
2026-07-18 23:41:28 +08:00
|
|
|
{
|
|
|
|
|
TypeName = typeName;
|
|
|
|
|
Type = type;
|
|
|
|
|
Serialize = serialize;
|
2026-07-18 23:44:10 +08:00
|
|
|
DeserializeAndAdd = deserializeAndAdd;
|
2026-07-18 23:41:28 +08:00
|
|
|
}
|
|
|
|
|
}
|