diff --git a/src/gaemstone/ECS/Attributes.cs b/src/gaemstone/ECS/Attributes.cs index a2114d0..f2fa1f1 100644 --- a/src/gaemstone/ECS/Attributes.cs +++ b/src/gaemstone/ECS/Attributes.cs @@ -16,7 +16,7 @@ public interface ICreateEntityAttribute { } /// (a globally unique identifier) set equal to their name. If they /// are also marked with this attribute, the symbol won't be set. /// -[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)] +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum)] public class PrivateAttribute : Attribute { } /// @@ -51,15 +51,15 @@ public class TagAttribute : AddAttribute, ICreateEntityAttribute { } /// the "relation" in a pair. However, this attribute is purely informational. /// /// -/// The relationship may have component data associated with -/// it when added to an entity under these circumstances: -/// -/// If marked as a , does not carry data. -/// If marked as a , carries the relation's data. -/// If marked with neither, will carry the target's data, if it's a component. -/// +/// The relationship may have component data associated with +/// it when added to an entity under these circumstances: +/// +/// If marked as a , does not carry data. +/// If marked as a , carries the relation's data. +/// If marked with neither, will carry the target's data, if it's a component. +/// /// -[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)] +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum)] public class RelationAttribute : Attribute, ICreateEntityAttribute { } @@ -67,7 +67,7 @@ public class RelationAttribute : Attribute, ICreateEntityAttribute { } public class IsAAttribute : AddAttribute { } /// -[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)] +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum)] public class ChildOfAttribute : AddAttribute { } /// @@ -90,14 +90,14 @@ public class ProxyAttribute : Attribute internal ProxyAttribute(Type type) => Type = type; } -[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = true)] +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum, AllowMultiple = true)] public class AddEntityAttribute : Attribute { public Type Entity { get; } internal AddEntityAttribute(Type entity) => Entity = entity; } -[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = true)] +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum, AllowMultiple = true)] public class AddRelationAttribute : Attribute { public Type Relation { get; } diff --git a/src/gaemstone/ECS/Component.cs b/src/gaemstone/ECS/Component.cs index 9119d80..5dcc260 100644 --- a/src/gaemstone/ECS/Component.cs +++ b/src/gaemstone/ECS/Component.cs @@ -5,7 +5,7 @@ using static flecs_hub.flecs; namespace gaemstone.ECS; -[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)] +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum)] public class ComponentAttribute : EntityAttribute { } public static class ComponentExtensions @@ -17,7 +17,13 @@ public static class ComponentExtensions // TODO: Do some additional sanity checking for this type. var typeInfo = default(ecs_type_info_t); - if (type.IsValueType) { + if (type.IsPrimitive) throw new ArgumentException( + "Must not be primitive", nameof(type)); + else if (type.IsEnum) { + var wrapper = TypeWrapper.For(type); + typeInfo.size = wrapper.Size; + typeInfo.alignment = wrapper.Size; + } else if (type.IsValueType) { var wrapper = TypeWrapper.For(type); if (!wrapper.IsUnmanaged) throw new Exception( "Struct component must satisfy the unmanaged constraint. " + diff --git a/src/gaemstone/ECS/Entity.cs b/src/gaemstone/ECS/Entity.cs index c602785..f974882 100644 --- a/src/gaemstone/ECS/Entity.cs +++ b/src/gaemstone/ECS/Entity.cs @@ -12,6 +12,7 @@ public class EntityAttribute : Attribute, ICreateEntityAttribute /// without explicitly specifying an entity in a query, where it is equivalent /// to with itself as the generic type parameter. /// +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum)] public class SingletonAttribute : EntityAttribute { } public readonly struct Entity