From c970111f77d21c63b4c3fcda86dfa8e9bd6b6733 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Mon, 16 Sep 2024 12:24:52 +0800 Subject: [PATCH] update meta attributes / add MetaID attribute --- .../MetaAttributes/MetaIDAttribute.cs | 27 ++++++++ .../MetaAttributes/MetaIDAttribute.cs.meta | 11 ++++ .../MetaAttributes/MetaTagsAttribute.cs | 13 ++-- src/DebugUtils/TypeMeta.cs | 63 +++++++++++++++---- src/Utils/Exceptions.cs | 6 +- 5 files changed, 101 insertions(+), 19 deletions(-) create mode 100644 src/DebugUtils/MetaAttributes/MetaIDAttribute.cs create mode 100644 src/DebugUtils/MetaAttributes/MetaIDAttribute.cs.meta diff --git a/src/DebugUtils/MetaAttributes/MetaIDAttribute.cs b/src/DebugUtils/MetaAttributes/MetaIDAttribute.cs new file mode 100644 index 0000000..944a54f --- /dev/null +++ b/src/DebugUtils/MetaAttributes/MetaIDAttribute.cs @@ -0,0 +1,27 @@ +using DCFApixels.DragonECS.Internal; +using System; +using System.Collections.Generic; + +namespace DCFApixels.DragonECS +{ + [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)] + public sealed class MetaIDAttribute : EcsMetaAttribute + { + private static HashSet _ids; + + public readonly string ID; + public MetaIDAttribute(string id) + { + if (string.IsNullOrEmpty(id)) + { + Throw.ArgumentNull(nameof(id)); + } + if (_ids.Add(id)) + { + //TODO перевести ексепшен + Throw.ArgumentException($"Дублирование MetaID: {ID}"); + } + ID = id; + } + } +} diff --git a/src/DebugUtils/MetaAttributes/MetaIDAttribute.cs.meta b/src/DebugUtils/MetaAttributes/MetaIDAttribute.cs.meta new file mode 100644 index 0000000..a484b95 --- /dev/null +++ b/src/DebugUtils/MetaAttributes/MetaIDAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 145ce3aab9f970b4a8c936e1adf5de95 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/DebugUtils/MetaAttributes/MetaTagsAttribute.cs b/src/DebugUtils/MetaAttributes/MetaTagsAttribute.cs index 1f1600f..afdc764 100644 --- a/src/DebugUtils/MetaAttributes/MetaTagsAttribute.cs +++ b/src/DebugUtils/MetaAttributes/MetaTagsAttribute.cs @@ -23,16 +23,17 @@ namespace DCFApixels.DragonECS _tags[i] = string.Intern(_tags[i]); } } - //public MetaTagsAttribute(string tag0, string tag1) : this($"{tag0},{tag1}") { } - //public MetaTagsAttribute(string tag0, string tag1, string tag2) : this($"{tag0},{tag1},{tag2}") { } - //public MetaTagsAttribute(string tag0, string tag1, string tag2, string tag3) : this($"{tag0},{tag1},{tag2},{tag3}") { } - //public MetaTagsAttribute(string tag0, string tag1, string tag2, string tag3, string tag4) : this($"{tag0},{tag1},{tag2},{tag3},{tag4}") { } - //public MetaTagsAttribute(string tag0, string tag1, string tag2, string tag3, string tag4, string tag5) : this($"{tag0},{tag1},{tag2},{tag3},{tag4},{tag5}") { } + public MetaTagsAttribute(string tag0, string tag1) : this($"{tag0},{tag1}") { } + public MetaTagsAttribute(string tag0, string tag1, string tag2) : this($"{tag0},{tag1},{tag2}") { } + public MetaTagsAttribute(string tag0, string tag1, string tag2, string tag3) : this($"{tag0},{tag1},{tag2},{tag3}") { } + public MetaTagsAttribute(string tag0, string tag1, string tag2, string tag3, string tag4) : this($"{tag0},{tag1},{tag2},{tag3},{tag4}") { } + public MetaTagsAttribute(string tag0, string tag1, string tag2, string tag3, string tag4, string tag5) : this($"{tag0},{tag1},{tag2},{tag3},{tag4},{tag5}") { } + public MetaTagsAttribute(string tag0, string tag1, string tag2, string tag3, string tag4, string tag5, string tag6) : this($"{tag0},{tag1},{tag2},{tag3},{tag4},{tag5},{tag6}") { } + public MetaTagsAttribute(string tag0, string tag1, string tag2, string tag3, string tag4, string tag5, string tag6, string tag7) : this($"{tag0},{tag1},{tag2},{tag3},{tag4},{tag5},{tag6},{tag7}") { } public MetaTagsAttribute(params string[] tags) : this(string.Join(SEPARATOR, tags)) { } } public readonly ref struct MetaTags { public const string HIDDEN = EcsConsts.META_HIDDEN_TAG; - //private static string[] _tags = new string[64]; } } diff --git a/src/DebugUtils/TypeMeta.cs b/src/DebugUtils/TypeMeta.cs index 3ad1263..c1fd04b 100644 --- a/src/DebugUtils/TypeMeta.cs +++ b/src/DebugUtils/TypeMeta.cs @@ -17,7 +17,7 @@ namespace DCFApixels.DragonECS MetaDescription Description { get; } MetaGroup Group { get; } IReadOnlyList Tags { get; } - + //string MetaID { get; } ITypeMeta BaseMeta { get; } } public static class ITypeMetaExstensions @@ -51,6 +51,7 @@ namespace DCFApixels.DragonECS private MetaDescription _description; private MetaGroup _group; private IReadOnlyList _tags; + private string _metaID; private int _typeCode; private InitFlag _initFlags = InitFlag.None; @@ -218,6 +219,25 @@ namespace DCFApixels.DragonECS } #endregion + #region MetaID + private void InitMetaID() + { + if (_initFlags.HasFlag(InitFlag.MetaID) == false) + { + _metaID = MetaGenerator.GetMetaID(_type); + _initFlags |= InitFlag.MetaID; + } + } + public string MetaID + { + get + { + InitMetaID(); + return _metaID; + } + } + #endregion + #region TypeCode public int TypeCode { @@ -243,6 +263,7 @@ namespace DCFApixels.DragonECS _ = Color; _ = Description; _ = Tags; + _ = MetaID; _ = TypeCode; } return this; @@ -259,10 +280,11 @@ namespace DCFApixels.DragonECS Color = 1 << 2, Description = 1 << 3, Tags = 1 << 4, - TypeCode = 1 << 5, - MemberType = 1 << 6, + MetaID = 1 << 5, + TypeCode = 1 << 6, + //MemberType = 1 << 7, - All = Name | Group | Color | Description | Tags | TypeCode | MemberType + All = Name | Group | Color | Description | Tags | TypeCode | MetaID //| MemberType } #endregion @@ -307,6 +329,10 @@ namespace DCFApixels.DragonECS { get { return _meta.Tags; } } + public string MetaID + { + get { return _meta.MetaID; } + } public DebuggerProxy(TypeMeta meta) { _meta = meta; @@ -411,6 +437,19 @@ namespace DCFApixels.DragonECS #else EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetTags)} method does not work."); return Array.Empty(); +#endif + } + #endregion + + #region GetMetaID + public static string GetMetaID(Type type) + { +#if (DEBUG && !DISABLE_DEBUG) || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает + var atr = type.GetCustomAttribute(); + return atr != null ? atr.ID : string.Empty; +#else + EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetTags)} method does not work."); + return string.Empty; #endif } #endregion @@ -418,12 +457,12 @@ namespace DCFApixels.DragonECS #endregion } - public enum EcsMemberType : byte - { - Undefined = 0, - - Component = 1, - System = 2, - Other = 3, - } + //public enum EcsMemberType : byte + //{ + // Undefined = 0, + // + // Component = 1, + // System = 2, + // Other = 3, + //} } \ No newline at end of file diff --git a/src/Utils/Exceptions.cs b/src/Utils/Exceptions.cs index 4530c56..881ddfb 100644 --- a/src/Utils/Exceptions.cs +++ b/src/Utils/Exceptions.cs @@ -154,7 +154,11 @@ namespace DCFApixels.DragonECS.Internal { throw new Exception(message); } - + [MethodImpl(MethodImplOptions.NoInlining)] + internal static void ArgumentException(string message) + { + throw new ArgumentException(message); + } [MethodImpl(MethodImplOptions.NoInlining)] internal static void Aspect_CanOnlyBeUsedDuringInitialization(string methodName)