From 4b0d188955a93a3b8b416304f24bf7744304298a Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Wed, 20 Dec 2023 23:16:57 +0800 Subject: [PATCH] update debug attributes rename DebugName attributes to MetaName attributes rework DebugHide to MetaTags --- src/Builtin/BaseProcesses.cs | 16 ++- src/Builtin/InjectSystem.cs | 18 ++- src/Builtin/Systems.cs | 9 +- src/Consts.cs | 2 + .../Attributes/DebugDescriptionAttribute.cs | 11 -- src/Debug/Attributes/DebugHideAttribute.cs | 7 -- src/Debug/Attributes/DebugNameAttribute.cs | 11 -- src/Debug/EcsDebugUtility.cs | 113 ++++++++++++------ .../{Attributes.meta => MetaAttributes.meta} | 0 .../MetaColorAttribute.cs} | 39 +++--- .../MetaColorAttribute.cs.meta} | 0 .../MetaDescriptionAttribute.cs | 11 ++ .../MetaDescriptionAttribute.cs.meta} | 0 .../MetaGroupAttribute.cs} | 18 +-- .../MetaGroupAttribute.cs.meta} | 0 src/Debug/MetaAttributes/MetaNameAttribute.cs | 11 ++ .../MetaNameAttribute.cs.meta} | 0 src/Debug/MetaAttributes/MetaTagsAttribute.cs | 24 ++++ .../MetaTagsAttribute.cs.meta} | 0 src/EcsRunner.cs | 5 +- src/EcsWorld.cs | 2 - src/Utils/ReflectionExtensions.cs | 14 --- 22 files changed, 183 insertions(+), 128 deletions(-) delete mode 100644 src/Debug/Attributes/DebugDescriptionAttribute.cs delete mode 100644 src/Debug/Attributes/DebugHideAttribute.cs delete mode 100644 src/Debug/Attributes/DebugNameAttribute.cs rename src/Debug/{Attributes.meta => MetaAttributes.meta} (100%) rename src/Debug/{Attributes/DebugColorAttribute.cs => MetaAttributes/MetaColorAttribute.cs} (74%) rename src/Debug/{Attributes/DebugColorAttribute.cs.meta => MetaAttributes/MetaColorAttribute.cs.meta} (100%) create mode 100644 src/Debug/MetaAttributes/MetaDescriptionAttribute.cs rename src/Debug/{Attributes/DebugDescriptionAttribute.cs.meta => MetaAttributes/MetaDescriptionAttribute.cs.meta} (100%) rename src/Debug/{Attributes/DebugGroupAttribute.cs => MetaAttributes/MetaGroupAttribute.cs} (51%) rename src/Debug/{Attributes/DebugGroupAttribute.cs.meta => MetaAttributes/MetaGroupAttribute.cs.meta} (100%) create mode 100644 src/Debug/MetaAttributes/MetaNameAttribute.cs rename src/Debug/{Attributes/DebugNameAttribute.cs.meta => MetaAttributes/MetaNameAttribute.cs.meta} (100%) create mode 100644 src/Debug/MetaAttributes/MetaTagsAttribute.cs rename src/Debug/{Attributes/DebugHideAttribute.cs.meta => MetaAttributes/MetaTagsAttribute.cs.meta} (100%) delete mode 100644 src/Utils/ReflectionExtensions.cs diff --git a/src/Builtin/BaseProcesses.cs b/src/Builtin/BaseProcesses.cs index 1277d7b..6176df0 100644 --- a/src/Builtin/BaseProcesses.cs +++ b/src/Builtin/BaseProcesses.cs @@ -6,21 +6,25 @@ using System; namespace DCFApixels.DragonECS { #region Interfaces + [MetaName(nameof(PreInit))] [BindWithEcsRunner(typeof(EcsPreInitProcessRunner))] public interface IEcsPreInitProcess : IEcsProcess { void PreInit(); } + [MetaName(nameof(Init))] [BindWithEcsRunner(typeof(EcsInitProcessRunner))] public interface IEcsInitProcess : IEcsProcess { void Init(); } + [MetaName(nameof(Run))] [BindWithEcsRunner(typeof(EcsRunProcessRunner))] public interface IEcsRunProcess : IEcsProcess { void Run(); } + [MetaName(nameof(Destroy))] [BindWithEcsRunner(typeof(EcsDestroyProcessRunner))] public interface IEcsDestroyProcess : IEcsProcess { @@ -31,7 +35,7 @@ namespace DCFApixels.DragonECS namespace Internal { - [DebugColor(DebugColor.Orange)] + [MetaColor(MetaColor.Orange)] public sealed class EcsPreInitProcessRunner : EcsRunner, IEcsPreInitProcess { #if DEBUG && !DISABLE_DEBUG @@ -79,7 +83,7 @@ namespace DCFApixels.DragonECS #endif } } - [DebugColor(DebugColor.Orange)] + [MetaColor(MetaColor.Orange)] public sealed class EcsInitProcessRunner : EcsRunner, IEcsInitProcess { #if DEBUG && !DISABLE_DEBUG @@ -127,7 +131,7 @@ namespace DCFApixels.DragonECS #endif } } - [DebugColor(DebugColor.Orange)] + [MetaColor(MetaColor.Orange)] public sealed class EcsRunProcessRunner : EcsRunner, IEcsRunProcess { #if DEBUG && !DISABLE_DEBUG @@ -175,7 +179,7 @@ namespace DCFApixels.DragonECS #endif } } - [DebugColor(DebugColor.Orange)] + [MetaColor(MetaColor.Orange)] public sealed class EcsDestroyProcessRunner : EcsRunner, IEcsDestroyProcess { #if DEBUG && !DISABLE_DEBUG @@ -185,11 +189,11 @@ namespace DCFApixels.DragonECS _markers = new EcsProfilerMarker[targets.Length]; for (int i = 0; i < targets.Length; i++) { - _markers[i] = new EcsProfilerMarker($"{targets[i].GetType().Name}.{nameof(Destroy)}"); + _markers[i] = new EcsProfilerMarker($"{targets[i].GetType().Name}.{nameof(IEcsDestroyProcess.Destroy)}"); } } #endif - public void Destroy() + void IEcsDestroyProcess.Destroy() { #if DEBUG && !DISABLE_DEBUG for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++) diff --git a/src/Builtin/InjectSystem.cs b/src/Builtin/InjectSystem.cs index 50673e1..cc5c391 100644 --- a/src/Builtin/InjectSystem.cs +++ b/src/Builtin/InjectSystem.cs @@ -5,16 +5,19 @@ using System.Linq; namespace DCFApixels.DragonECS { + [MetaName(nameof(PreInject))] [BindWithEcsRunner(typeof(EcsPreInjectRunner))] public interface IEcsPreInject : IEcsProcess { void PreInject(object obj); } + [MetaName(nameof(Inject))] [BindWithEcsRunner(typeof(EcsInjectRunner<>))] public interface IEcsInject : IEcsProcess { void Inject(T obj); } + [MetaName("PreInitInject")] [BindWithEcsRunner(typeof(EcsPreInitInjectProcessRunner))] public interface IEcsPreInitInjectProcess : IEcsProcess { @@ -47,7 +50,8 @@ namespace DCFApixels.DragonECS _injectSystems = null; } } - [DebugHide, DebugColor(DebugColor.Gray)] + [MetaTags(MetaTags.HIDDEN)] + [MetaColor(MetaColor.Gray)] public sealed class EcsPreInjectRunner : EcsRunner, IEcsPreInject { void IEcsPreInject.PreInject(object obj) @@ -55,7 +59,8 @@ namespace DCFApixels.DragonECS foreach (var item in targets) item.PreInject(obj); } } - [DebugHide, DebugColor(DebugColor.Gray)] + [MetaTags(MetaTags.HIDDEN)] + [MetaColor(MetaColor.Gray)] public sealed class EcsInjectRunner : EcsRunner>, IEcsInject { private EcsBaseTypeInjectRunner _baseTypeInjectRunner; @@ -91,7 +96,8 @@ namespace DCFApixels.DragonECS public override void Inject(object obj) => _runner.PreInject(obj); } - [DebugHide, DebugColor(DebugColor.Gray)] + [MetaTags(MetaTags.HIDDEN)] + [MetaColor(MetaColor.Gray)] public sealed class EcsPreInitInjectProcessRunner : EcsRunner, IEcsPreInitInjectProcess { public void OnPreInitInjectionAfter() @@ -103,8 +109,10 @@ namespace DCFApixels.DragonECS foreach (var item in targets) item.OnPreInitInjectionBefore(); } } - public class InjectSystemBase { } - [DebugHide, DebugColor(DebugColor.Gray)] + public abstract class InjectSystemBase { } + + [MetaTags(MetaTags.HIDDEN)] + [MetaColor(MetaColor.Gray)] public class InjectSystem : InjectSystemBase, IEcsInject, IEcsPreInitProcess, IEcsInject, IEcsPreInitInjectProcess { private EcsPipeline _pipeline; diff --git a/src/Builtin/Systems.cs b/src/Builtin/Systems.cs index d8f908f..7f1e2ca 100644 --- a/src/Builtin/Systems.cs +++ b/src/Builtin/Systems.cs @@ -5,13 +5,15 @@ namespace DCFApixels.DragonECS { namespace Internal { - [DebugHide, DebugColor(DebugColor.Black)] + [MetaTags(MetaTags.HIDDEN)] + [MetaColor(MetaColor.Black)] public class SystemsLayerMarkerSystem : IEcsProcess { public readonly string name; public SystemsLayerMarkerSystem(string name) => this.name = name; } - [DebugHide, DebugColor(DebugColor.Grey)] + [MetaTags(MetaTags.HIDDEN)] + [MetaColor(MetaColor.Grey)] public class EndFrameSystem : IEcsRunProcess, IEcsInject { private readonly List _worlds = new List(); @@ -25,7 +27,8 @@ namespace DCFApixels.DragonECS } } } - [DebugHide, DebugColor(DebugColor.Grey)] + [MetaTags(MetaTags.HIDDEN)] + [MetaColor(MetaColor.Grey)] public class DeleteOneFrameComponentSystem : IEcsRunProcess, IEcsInject where TComponent : struct, IEcsComponent { diff --git a/src/Consts.cs b/src/Consts.cs index 41bfb71..307b30a 100644 --- a/src/Consts.cs +++ b/src/Consts.cs @@ -14,5 +14,7 @@ public const string BASIC_LAYER = nameof(BASIC_LAYER); public const string END_LAYER = nameof(END_LAYER); public const string POST_END_LAYER = nameof(POST_END_LAYER); + + public const string META_HIDDEN_TAG = "HiddenInDebagging"; } } diff --git a/src/Debug/Attributes/DebugDescriptionAttribute.cs b/src/Debug/Attributes/DebugDescriptionAttribute.cs deleted file mode 100644 index 1a7aacd..0000000 --- a/src/Debug/Attributes/DebugDescriptionAttribute.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace DCFApixels.DragonECS -{ - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - public sealed class DebugDescriptionAttribute : Attribute - { - public readonly string description; - public DebugDescriptionAttribute(string description) => this.description = description; - } -} diff --git a/src/Debug/Attributes/DebugHideAttribute.cs b/src/Debug/Attributes/DebugHideAttribute.cs deleted file mode 100644 index 38d7419..0000000 --- a/src/Debug/Attributes/DebugHideAttribute.cs +++ /dev/null @@ -1,7 +0,0 @@ -using System; - -namespace DCFApixels.DragonECS -{ - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - public sealed class DebugHideAttribute : Attribute { } -} diff --git a/src/Debug/Attributes/DebugNameAttribute.cs b/src/Debug/Attributes/DebugNameAttribute.cs deleted file mode 100644 index 01f6fda..0000000 --- a/src/Debug/Attributes/DebugNameAttribute.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace DCFApixels.DragonECS -{ - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - public sealed class DebugNameAttribute : Attribute - { - public readonly string name; - public DebugNameAttribute(string name) => this.name = name; - } -} diff --git a/src/Debug/EcsDebugUtility.cs b/src/Debug/EcsDebugUtility.cs index 0b2a083..4777e50 100644 --- a/src/Debug/EcsDebugUtility.cs +++ b/src/Debug/EcsDebugUtility.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; @@ -67,7 +68,7 @@ namespace DCFApixels.DragonECS GetName(type: obj.GetType(), maxGenericDepth); } public static string GetName(int maxGenericDepth = 2) => GetName(typeof(T), maxGenericDepth); - public static string GetName(Type type, int maxGenericDepth = 2) => type.TryGetCustomAttribute(out DebugNameAttribute atr) ? atr.name : GetGenericTypeName(type, maxGenericDepth); + public static string GetName(Type type, int maxGenericDepth = 2) => type.TryGetCustomAttribute(out MetaNameAttribute atr) ? atr.name : GetGenericTypeName(type, maxGenericDepth); public static bool TryGetCustomName(object obj, out string name) { return obj is IEcsDebugMetaProvider intr ? @@ -77,7 +78,7 @@ namespace DCFApixels.DragonECS public static bool TryGetCustomName(out string name) => TryGetCustomName(type: typeof(T), out name); public static bool TryGetCustomName(Type type, out string name) { - if (type.TryGetCustomAttribute(out DebugNameAttribute atr)) + if (type.TryGetCustomAttribute(out MetaNameAttribute atr)) { name = atr.name; return true; @@ -88,29 +89,29 @@ namespace DCFApixels.DragonECS #endregion #region GetGroup - public static DebugGroup GetGroup(object obj) + public static MetaGroup GetGroup(object obj) { return obj is IEcsDebugMetaProvider intr ? GetGroup(intr.DebugMetaSource) : GetGroup(type: obj.GetType()); } - public static DebugGroup GetGroup() => GetGroup(typeof(T)); - public static DebugGroup GetGroup(Type type) => type.TryGetCustomAttribute(out DebugGroupAttribute atr) ? atr.GetData() : DebugGroup.Empty; - public static bool TryGetGroup(object obj, out DebugGroup group) + public static MetaGroup GetGroup() => GetGroup(typeof(T)); + public static MetaGroup GetGroup(Type type) => type.TryGetCustomAttribute(out MetaGroupAttribute atr) ? atr.GetData() : MetaGroup.Empty; + public static bool TryGetGroup(object obj, out MetaGroup group) { return obj is IEcsDebugMetaProvider intr ? TryGetGroup(intr.DebugMetaSource, out group) : TryGetGroup(type: obj.GetType(), out group); } - public static bool TryGetGroup(out DebugGroup text) => TryGetGroup(typeof(T), out text); - public static bool TryGetGroup(Type type, out DebugGroup group) + public static bool TryGetGroup(out MetaGroup text) => TryGetGroup(typeof(T), out text); + public static bool TryGetGroup(Type type, out MetaGroup group) { - if (type.TryGetCustomAttribute(out DebugGroupAttribute atr)) + if (type.TryGetCustomAttribute(out MetaGroupAttribute atr)) { group = atr.GetData(); return true; } - group = DebugGroup.Empty; + group = MetaGroup.Empty; return false; } #endregion @@ -123,7 +124,7 @@ namespace DCFApixels.DragonECS GetDescription(type: obj.GetType()); } public static string GetDescription() => GetDescription(typeof(T)); - public static string GetDescription(Type type) => type.TryGetCustomAttribute(out DebugDescriptionAttribute atr) ? atr.description : string.Empty; + public static string GetDescription(Type type) => type.TryGetCustomAttribute(out MetaDescriptionAttribute atr) ? atr.description : string.Empty; public static bool TryGetDescription(object obj, out string text) { return obj is IEcsDebugMetaProvider intr ? @@ -133,7 +134,7 @@ namespace DCFApixels.DragonECS public static bool TryGetDescription(out string text) => TryGetDescription(typeof(T), out text); public static bool TryGetDescription(Type type, out string text) { - if (type.TryGetCustomAttribute(out DebugDescriptionAttribute atr)) + if (type.TryGetCustomAttribute(out MetaDescriptionAttribute atr)) { text = atr.description; return true; @@ -149,7 +150,7 @@ namespace DCFApixels.DragonECS private class WordColor { public int wordsCount; - public DebugColor color; + public MetaColor color; } private class NameColor { @@ -162,7 +163,7 @@ namespace DCFApixels.DragonECS { color = new WordColor(); _words.Add(word, color); - color.color = new DebugColor((byte)random.Next(), (byte)random.Next(), (byte)random.Next()).UpContrastColor() / 2; + color.color = new MetaColor((byte)random.Next(), (byte)random.Next(), (byte)random.Next()).UpContrastColor() / 2; } color.wordsCount++; colors.Add(color); @@ -177,7 +178,7 @@ namespace DCFApixels.DragonECS } return result; } - public DebugColor CalcColor() + public MetaColor CalcColor() { float r = 0, g = 0, b = 0; int totalWordsCount = CalcTotalWordsColor(); @@ -189,11 +190,11 @@ namespace DCFApixels.DragonECS g += m * color.color.g; b += m * color.color.b; } - return new DebugColor((byte)r, (byte)g, (byte)b); + return new MetaColor((byte)r, (byte)g, (byte)b); } } private static Dictionary _names = new Dictionary(); - private static DebugColor CalcNameColorFor(Type type) + private static MetaColor CalcNameColorFor(Type type) { Type targetType = type.IsGenericType ? type.GetGenericTypeDefinition() : type; if (!_names.TryGetValue(targetType, out NameColor nameColor)) @@ -224,39 +225,73 @@ namespace DCFApixels.DragonECS return words; } - public static DebugColor GetColor(object obj) + public static MetaColor GetColor(object obj) { return obj is IEcsDebugMetaProvider intr ? GetColor(intr.DebugMetaSource) : GetColor(type: obj.GetType()); } - public static DebugColor GetColor() => GetColor(typeof(T)); - public static DebugColor GetColor(Type type) + public static MetaColor GetColor() => GetColor(typeof(T)); + public static MetaColor GetColor(Type type) { - var atr = type.GetCustomAttribute(); + var atr = type.GetCustomAttribute(); return atr != null ? atr.color #if DEBUG //optimization for release build : CalcNameColorFor(type); #else - : DebugColor.BlackColor; + : MetaColor.BlackColor; #endif } - public static bool TryGetColor(object obj, out DebugColor color) + public static bool TryGetColor(object obj, out MetaColor color) { return obj is IEcsDebugMetaProvider intr ? TryGetColor(intr.DebugMetaSource, out color) : TryGetColor(type: obj.GetType(), out color); } - public static bool TryGetColor(out DebugColor color) => TryGetColor(typeof(T), out color); - public static bool TryGetColor(Type type, out DebugColor color) + public static bool TryGetColor(out MetaColor color) => TryGetColor(typeof(T), out color); + public static bool TryGetColor(Type type, out MetaColor color) { - var atr = type.GetCustomAttribute(); + var atr = type.GetCustomAttribute(); if (atr != null) { color = atr.color; return true; } - color = DebugColor.BlackColor; + color = MetaColor.BlackColor; + return false; + } + #endregion + + #region GetTags + public static IReadOnlyCollection GetTags(object obj) + { + return obj is IEcsDebugMetaProvider intr ? + GetTags(intr.DebugMetaSource) : + GetTags(type: obj.GetType()); + } + public static IReadOnlyCollection GetTags() => GetTags(typeof(T)); + public static IReadOnlyCollection GetTags(Type type) + { + var atr = type.GetCustomAttribute(); + return atr != null ? atr.Tags : Array.Empty(); + } + + public static bool TryGetTags(object obj, out IReadOnlyCollection tags) + { + return obj is IEcsDebugMetaProvider intr ? + TryGetTags(intr.DebugMetaSource, out tags) : + TryGetTags(type: obj.GetType(), out tags); + } + public static bool TryGetTags(out IReadOnlyCollection tags) => TryGetTags(typeof(T), out tags); + public static bool TryGetTags(Type type, out IReadOnlyCollection tags) + { + var atr = type.GetCustomAttribute(); + if (atr != null) + { + tags = atr.Tags; + return true; + } + tags = Array.Empty(); return false; } #endregion @@ -269,7 +304,7 @@ namespace DCFApixels.DragonECS IsHidden(type: obj.GetType()); } public static bool IsHidden() => IsHidden(typeof(T)); - public static bool IsHidden(Type type) => type.TryGetCustomAttribute(out DebugHideAttribute _); + public static bool IsHidden(Type type) => type.TryGetCustomAttribute(out MetaTagsAttribute atr) && atr.Tags.Contains(MetaTags.HIDDEN); #endregion #region MetaSource @@ -284,22 +319,22 @@ namespace DCFApixels.DragonECS #endregion #region GenerateTypeDebugData - public static TypeDebugData GenerateTypeDebugData(object obj) + public static TypeMetaData GenerateTypeDebugData(object obj) { return obj is IEcsDebugMetaProvider intr ? GenerateTypeDebugData(intr.DebugMetaSource) : GenerateTypeDebugData(type: obj.GetType()); } - public static TypeDebugData GenerateTypeDebugData() => GenerateTypeDebugData(typeof(T)); - public static TypeDebugData GenerateTypeDebugData(Type type) + public static TypeMetaData GenerateTypeDebugData() => GenerateTypeDebugData(typeof(T)); + public static TypeMetaData GenerateTypeDebugData(Type type) { - return new TypeDebugData( + return new TypeMetaData( type, GetName(type), GetGroup(type), GetColor(type), GetDescription(type), - IsHidden(type)); + GetTags(type).ToArray()); } #endregion @@ -320,22 +355,22 @@ namespace DCFApixels.DragonECS } [Serializable] - public sealed class TypeDebugData + public sealed class TypeMetaData { public readonly Type type; public readonly string name; - public readonly DebugGroup group; - public readonly DebugColor color; + public readonly MetaGroup group; + public readonly MetaColor color; public readonly string description; - public readonly bool isHidden; - public TypeDebugData(Type type, string name, DebugGroup group, DebugColor color, string description, bool isHidden) + public readonly string[] tags; + public TypeMetaData(Type type, string name, MetaGroup group, MetaColor color, string description, string[] tags) { this.type = type; this.name = name; this.group = group; this.color = color; this.description = description; - this.isHidden = isHidden; + this.tags = tags; } } } diff --git a/src/Debug/Attributes.meta b/src/Debug/MetaAttributes.meta similarity index 100% rename from src/Debug/Attributes.meta rename to src/Debug/MetaAttributes.meta diff --git a/src/Debug/Attributes/DebugColorAttribute.cs b/src/Debug/MetaAttributes/MetaColorAttribute.cs similarity index 74% rename from src/Debug/Attributes/DebugColorAttribute.cs rename to src/Debug/MetaAttributes/MetaColorAttribute.cs index fda3aa5..ea0bd90 100644 --- a/src/Debug/Attributes/DebugColorAttribute.cs +++ b/src/Debug/MetaAttributes/MetaColorAttribute.cs @@ -3,20 +3,23 @@ using System.Runtime.InteropServices; namespace DCFApixels.DragonECS { - [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class, Inherited = false, AllowMultiple = false)] - public sealed class DebugColorAttribute : Attribute + [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)] + public sealed class MetaColorAttribute : Attribute { - public readonly DebugColor color; - public byte r => color.r; - public byte g => color.g; - public byte b => color.b; - public DebugColorAttribute(byte r, byte g, byte b) => color = new DebugColor(r, g, b, 255); - public DebugColorAttribute(int colorCode) => color = new DebugColor(colorCode, true); + public readonly MetaColor color; + public byte R => color.r; + public byte G => color.g; + public byte B => color.b; + public float FloatT => R / (float)byte.MaxValue; + public float FloatG => G / (float)byte.MaxValue; + public float FloatB => B / (float)byte.MaxValue; + public MetaColorAttribute(byte r, byte g, byte b) => color = new MetaColor(r, g, b, 255); + public MetaColorAttribute(int colorCode) => color = new MetaColor(colorCode, true); } [StructLayout(LayoutKind.Explicit, Pack = 1, Size = 4)] - public readonly struct DebugColor + public readonly struct MetaColor { - public static readonly DebugColor BlackColor = new DebugColor(Black); + public static readonly MetaColor BlackColor = new MetaColor(Black); /// color code Red. RGB is (255, 0, 0) public const int Red = (255 << 24) | (000 << 16) | (000 << 8) | 255; /// color code Green. RGB is (0, 255, 0) @@ -66,37 +69,37 @@ namespace DCFApixels.DragonECS [FieldOffset(2)] public readonly byte g; [FieldOffset(1)] public readonly byte b; [FieldOffset(0)] public readonly byte a; - public DebugColor(byte r, byte g, byte b) : this() + public MetaColor(byte r, byte g, byte b) : this() { this.r = r; this.g = g; this.b = b; a = 255; } - public DebugColor(byte r, byte g, byte b, byte a) : this() + public MetaColor(byte r, byte g, byte b, byte a) : this() { this.r = r; this.g = g; this.b = b; this.a = a; } - public DebugColor(int colorCode) : this() => this.colorCode = colorCode; - public DebugColor(int colorCode, bool withoutAlpha) : this() => this.colorCode = withoutAlpha ? colorCode | 255 : colorCode; + public MetaColor(int colorCode) : this() => this.colorCode = colorCode; + public MetaColor(int colorCode, bool withoutAlpha) : this() => this.colorCode = withoutAlpha ? colorCode | 255 : colorCode; public (byte, byte, byte) ToTupleRGB() => (r, g, b); public (byte, byte, byte, byte) ToTupleRGBA() => (r, g, b, a); - public DebugColor UpContrastColor() + public MetaColor UpContrastColor() { byte minChannel = Math.Min(Math.Min(r, g), b); byte maxChannel = Math.Max(Math.Max(r, g), b); if (maxChannel == minChannel) return default; float factor = 255f / (maxChannel - minChannel); - return new DebugColor((byte)((r - minChannel) * factor), (byte)((g - minChannel) * factor), (byte)((b - minChannel) * factor)); + return new MetaColor((byte)((r - minChannel) * factor), (byte)((g - minChannel) * factor), (byte)((b - minChannel) * factor)); } - public static DebugColor operator /(DebugColor a, float b) + public static MetaColor operator /(MetaColor a, float b) { - return new DebugColor((byte)(a.r / b), (byte)(a.g / b), (byte)(a.b / b)); + return new MetaColor((byte)(a.r / b), (byte)(a.g / b), (byte)(a.b / b)); } } } \ No newline at end of file diff --git a/src/Debug/Attributes/DebugColorAttribute.cs.meta b/src/Debug/MetaAttributes/MetaColorAttribute.cs.meta similarity index 100% rename from src/Debug/Attributes/DebugColorAttribute.cs.meta rename to src/Debug/MetaAttributes/MetaColorAttribute.cs.meta diff --git a/src/Debug/MetaAttributes/MetaDescriptionAttribute.cs b/src/Debug/MetaAttributes/MetaDescriptionAttribute.cs new file mode 100644 index 0000000..38b4f16 --- /dev/null +++ b/src/Debug/MetaAttributes/MetaDescriptionAttribute.cs @@ -0,0 +1,11 @@ +using System; + +namespace DCFApixels.DragonECS +{ + [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)] + public sealed class MetaDescriptionAttribute : Attribute + { + public readonly string description; + public MetaDescriptionAttribute(string description) => this.description = description; + } +} diff --git a/src/Debug/Attributes/DebugDescriptionAttribute.cs.meta b/src/Debug/MetaAttributes/MetaDescriptionAttribute.cs.meta similarity index 100% rename from src/Debug/Attributes/DebugDescriptionAttribute.cs.meta rename to src/Debug/MetaAttributes/MetaDescriptionAttribute.cs.meta diff --git a/src/Debug/Attributes/DebugGroupAttribute.cs b/src/Debug/MetaAttributes/MetaGroupAttribute.cs similarity index 51% rename from src/Debug/Attributes/DebugGroupAttribute.cs rename to src/Debug/MetaAttributes/MetaGroupAttribute.cs index e0c7567..455877e 100644 --- a/src/Debug/Attributes/DebugGroupAttribute.cs +++ b/src/Debug/MetaAttributes/MetaGroupAttribute.cs @@ -3,13 +3,13 @@ using System.Text.RegularExpressions; namespace DCFApixels.DragonECS { - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - public sealed class DebugGroupAttribute : Attribute + [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)] + public sealed class MetaGroupAttribute : Attribute { - public static readonly DebugGroupAttribute Empty = new DebugGroupAttribute(""); + public static readonly MetaGroupAttribute Empty = new MetaGroupAttribute(""); public readonly string name; public readonly string rootCategory; - public DebugGroupAttribute(string name) + public MetaGroupAttribute(string name) { name = Regex.Replace(name, @"^[/|\\]+|[/|\\]+$", ""); rootCategory = Regex.Match(name, @"^(.*?)[/\\]").Groups[1].Value; @@ -19,15 +19,15 @@ namespace DCFApixels.DragonECS { return Regex.Split(name, @"[/|\\]"); } - public DebugGroup GetData() => new DebugGroup(this); + public MetaGroup GetData() => new MetaGroup(this); } - public readonly struct DebugGroup + public readonly struct MetaGroup { - public static readonly DebugGroup Empty = new DebugGroup(DebugGroupAttribute.Empty); - private readonly DebugGroupAttribute _source; + public static readonly MetaGroup Empty = new MetaGroup(MetaGroupAttribute.Empty); + private readonly MetaGroupAttribute _source; public string Name => _source.name; public string RootCategory => _source.rootCategory; - public DebugGroup(DebugGroupAttribute source) => _source = source; + public MetaGroup(MetaGroupAttribute source) => _source = source; public string[] SplitCategories() => _source.SplitCategories(); } } diff --git a/src/Debug/Attributes/DebugGroupAttribute.cs.meta b/src/Debug/MetaAttributes/MetaGroupAttribute.cs.meta similarity index 100% rename from src/Debug/Attributes/DebugGroupAttribute.cs.meta rename to src/Debug/MetaAttributes/MetaGroupAttribute.cs.meta diff --git a/src/Debug/MetaAttributes/MetaNameAttribute.cs b/src/Debug/MetaAttributes/MetaNameAttribute.cs new file mode 100644 index 0000000..c4c8acd --- /dev/null +++ b/src/Debug/MetaAttributes/MetaNameAttribute.cs @@ -0,0 +1,11 @@ +using System; + +namespace DCFApixels.DragonECS +{ + [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)] + public sealed class MetaNameAttribute : Attribute + { + public readonly string name; + public MetaNameAttribute(string name) => this.name = name; + } +} diff --git a/src/Debug/Attributes/DebugNameAttribute.cs.meta b/src/Debug/MetaAttributes/MetaNameAttribute.cs.meta similarity index 100% rename from src/Debug/Attributes/DebugNameAttribute.cs.meta rename to src/Debug/MetaAttributes/MetaNameAttribute.cs.meta diff --git a/src/Debug/MetaAttributes/MetaTagsAttribute.cs b/src/Debug/MetaAttributes/MetaTagsAttribute.cs new file mode 100644 index 0000000..1dbf92a --- /dev/null +++ b/src/Debug/MetaAttributes/MetaTagsAttribute.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace DCFApixels.DragonECS +{ + [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)] + public sealed class MetaTagsAttribute : Attribute + { + private readonly string[] _tags; + public IReadOnlyCollection Tags => _tags; + + [Obsolete("With empty parameters, this attribute makes no sense.", true)] + public MetaTagsAttribute() { } + public MetaTagsAttribute(params string[] tags) + { + _tags = tags.Where(o => !string.IsNullOrEmpty(o)).ToArray(); + } + } + public readonly ref struct MetaTags + { + public const string HIDDEN = EcsConsts.META_HIDDEN_TAG; + } +} diff --git a/src/Debug/Attributes/DebugHideAttribute.cs.meta b/src/Debug/MetaAttributes/MetaTagsAttribute.cs.meta similarity index 100% rename from src/Debug/Attributes/DebugHideAttribute.cs.meta rename to src/Debug/MetaAttributes/MetaTagsAttribute.cs.meta diff --git a/src/EcsRunner.cs b/src/EcsRunner.cs index 107cdd0..89008d6 100644 --- a/src/EcsRunner.cs +++ b/src/EcsRunner.cs @@ -1,5 +1,4 @@ -using DCFApixels.DragonECS.Internal; -using DCFApixels.DragonECS.RunnersCore; +using DCFApixels.DragonECS.RunnersCore; using System; using System.Collections; using System.Collections.Generic; @@ -166,7 +165,7 @@ namespace DCFApixels.DragonECS if(_subclass == null) { Type interfaceType = typeof(TInterface); - if (interfaceType.TryGetAttribute(out BindWithEcsRunnerAttribute atr)) + if (interfaceType.TryGetCustomAttribute(out BindWithEcsRunnerAttribute atr)) { Type runnerType = atr.runnerType; if (interfaceType.IsGenericType) diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index bd6ecef..c15d3ff 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -2,9 +2,7 @@ using DCFApixels.DragonECS.Utils; using System; using System.Collections.Generic; -using System.Diagnostics.Metrics; using System.Runtime.CompilerServices; -using static DCFApixels.DragonECS.EcsWorld; namespace DCFApixels.DragonECS { diff --git a/src/Utils/ReflectionExtensions.cs b/src/Utils/ReflectionExtensions.cs deleted file mode 100644 index 2af1c51..0000000 --- a/src/Utils/ReflectionExtensions.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Reflection; - -namespace DCFApixels.DragonECS.Internal -{ - internal static class ReflectionExtensions - { - public static bool TryGetAttribute(this MemberInfo self, out T attribute) where T : Attribute - { - attribute = self.GetCustomAttribute(); - return attribute != null; - } - } -}