From f7fb996ffccf5c61525bfca3f36fc90fcb02087b Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Sat, 8 Jun 2024 02:08:20 +0800 Subject: [PATCH] udpate typemeta add docs --- src/Debug/DragonDocs/DragonDocs.cs | 50 ++++++++++++++++++- src/Debug/DragonDocs/DragonDocsMeta.cs | 8 ++- src/Debug/EcsDebug.cs | 4 ++ .../MetaAttributes/MetaGroupAttribute.cs | 15 +++--- src/Debug/MetaAttributes/MetaTagsAttribute.cs | 15 ++++-- src/Debug/TypeMeta.cs | 17 +++++-- 6 files changed, 90 insertions(+), 19 deletions(-) diff --git a/src/Debug/DragonDocs/DragonDocs.cs b/src/Debug/DragonDocs/DragonDocs.cs index 15965d7..6ff1040 100644 --- a/src/Debug/DragonDocs/DragonDocs.cs +++ b/src/Debug/DragonDocs/DragonDocs.cs @@ -9,13 +9,48 @@ namespace DCFApixels.DragonECS.Docs [DataContract] public class DragonDocs { - [DataMember] + [DataMember] private readonly DragonDocsMeta[] _metas; + [NonSerialized] + private DragonDocsMetaGroup[] _mapping = null; + public ReadOnlySpan Meta { get { return new ReadOnlySpan(_metas); } } + public ReadOnlySpan Mapping + { + get + { + Init(); + return new ReadOnlySpan(_mapping); ; + } + } + private bool _isInit = false; + private void Init() + { + if (_isInit) { return; } + if (_metas.Length < 0) + { + _mapping = Array.Empty(); + } + List groups = new List(); + string name = _metas[0].Name; + int startIndex = 0; + for (int i = 1; i < _metas.Length; i++) + { + var meta = _metas[i]; + if (name != meta.Name) + { + groups.Add(new DragonDocsMetaGroup(name, startIndex, i - startIndex)); + name = meta.Name; + startIndex = i; + } + } + groups.Add(new DragonDocsMetaGroup(name, startIndex, _metas.Length - startIndex)); + _mapping = groups.ToArray(); + } private DragonDocs(DragonDocsMeta[] metas) { _metas = metas; @@ -50,4 +85,17 @@ namespace DCFApixels.DragonECS.Docs return result; } } + public struct DragonDocsMetaGroup + { + public readonly string Name; + public readonly int StartIndex; + public readonly int Length; + public DragonDocsMetaGroup(string name, int startIndex, int length) + { + Name = name; + StartIndex = startIndex; + Length = length; + } + } + } \ No newline at end of file diff --git a/src/Debug/DragonDocs/DragonDocsMeta.cs b/src/Debug/DragonDocs/DragonDocsMeta.cs index 0f9ab74..1764a70 100644 --- a/src/Debug/DragonDocs/DragonDocsMeta.cs +++ b/src/Debug/DragonDocs/DragonDocsMeta.cs @@ -20,7 +20,7 @@ namespace DCFApixels.DragonECS.Docs [DataMember] public readonly string Description = string.Empty; [DataMember] public readonly string Group = string.Empty; - [DataMember] public readonly string Tags = string.Empty; + [DataMember] public readonly string[] Tags = Array.Empty(); public DragonDocsMeta(TypeMeta meta) { @@ -35,7 +35,11 @@ namespace DCFApixels.DragonECS.Docs Description = meta.Description.Text; Group = meta.Group.Name; - Tags = string.Join(", ", meta.Tags); + Tags = new string[meta.Tags.Count]; + for (int i = 0, n = meta.Tags.Count; i < n; i++) + { + Tags[i] = meta.Tags[i]; + } } public bool TryGetSourceType(out Type type) diff --git a/src/Debug/EcsDebug.cs b/src/Debug/EcsDebug.cs index 6624830..2b84ba9 100644 --- a/src/Debug/EcsDebug.cs +++ b/src/Debug/EcsDebug.cs @@ -20,16 +20,20 @@ namespace DCFApixels.DragonECS public readonly ref struct AutoScope { private readonly int _id; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public AutoScope(int id) { _id = id; DebugService.Instance.ProfilerMarkBegin(id); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Dispose() { DebugService.Instance.ProfilerMarkEnd(_id); } } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static explicit operator EcsProfilerMarker(string markerName) { return new EcsProfilerMarker(markerName); } } public static class EcsDebug diff --git a/src/Debug/MetaAttributes/MetaGroupAttribute.cs b/src/Debug/MetaAttributes/MetaGroupAttribute.cs index 5b98129..609525b 100644 --- a/src/Debug/MetaAttributes/MetaGroupAttribute.cs +++ b/src/Debug/MetaAttributes/MetaGroupAttribute.cs @@ -23,20 +23,20 @@ namespace DCFApixels.DragonECS public class MetaGroup { public static readonly MetaGroup Empty = new MetaGroup(""); - private static string pattern = @"Module(?=/)"; - private static char[] separatpor = new char[] { '/' }; + private static string _pattern = @"Module(?=/)"; + private static char[] _separatpor = new char[] { '/' }; public readonly string Name; - private string[] path = null; + private string[] _path = null; public IReadOnlyCollection Splited { get { - if (path == null) + if (_path == null) { - path = Name.Split(separatpor, StringSplitOptions.RemoveEmptyEntries); + _path = Name.Split(_separatpor, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); } - return path; + return _path; } } public MetaGroup(string name) @@ -51,7 +51,8 @@ namespace DCFApixels.DragonECS { name += '/'; } - Name = Regex.Replace(name, pattern, ""); ; + Name = Regex.Replace(name, _pattern, ""); + Name = string.Intern(Name); } public override string ToString() { return Name; } } diff --git a/src/Debug/MetaAttributes/MetaTagsAttribute.cs b/src/Debug/MetaAttributes/MetaTagsAttribute.cs index 3922c77..f05cec9 100644 --- a/src/Debug/MetaAttributes/MetaTagsAttribute.cs +++ b/src/Debug/MetaAttributes/MetaTagsAttribute.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; namespace DCFApixels.DragonECS { @@ -8,20 +7,28 @@ namespace DCFApixels.DragonECS public sealed class MetaTagsAttribute : EcsMetaAttribute { private readonly string[] _tags = Array.Empty(); - public IReadOnlyCollection Tags + private static char[] _separatpor = new char[] { ',' }; + public IReadOnlyList Tags { get { return _tags; } } [Obsolete("With empty parameters, this attribute makes no sense.")] public MetaTagsAttribute() { } - public MetaTagsAttribute(params string[] tags) + public MetaTagsAttribute(string tags) { - _tags = tags.Where(o => !string.IsNullOrEmpty(o)).ToArray(); + _tags = tags.Split(_separatpor, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + for (int i = 0; i < _tags.Length; i++) + { + _tags[i] = string.Intern(_tags[i]); + } } + public MetaTagsAttribute(params string[] tags) : this(string.Join(',', 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/Debug/TypeMeta.cs b/src/Debug/TypeMeta.cs index 0c98b93..ac3c5c3 100644 --- a/src/Debug/TypeMeta.cs +++ b/src/Debug/TypeMeta.cs @@ -14,9 +14,12 @@ namespace DCFApixels.DragonECS MetaColor Color { get; } MetaDescription Description { get; } MetaGroup Group { get; } - IReadOnlyCollection Tags { get; } + IReadOnlyList Tags { get; } } + [MetaGroup(EcsConsts.FRAMEWORK_NAME)] + [MetaColor(MetaColor.DragonRose)] + [MetaDescription(EcsConsts.AUTHOR, "Basic class of the framework, intended for extending meta information of types, for customization of type display in the editor.")] [DebuggerTypeProxy(typeof(DebuggerProxy))] public sealed class TypeMeta : ITypeMeta { @@ -32,7 +35,7 @@ namespace DCFApixels.DragonECS private MetaColor _color; private MetaDescription _description; private MetaGroup _group; - private IReadOnlyCollection _tags; + private IReadOnlyList _tags; private int _typeCode; private InitFlag _initFlags = InitFlag.None; @@ -154,7 +157,7 @@ namespace DCFApixels.DragonECS _isHidden = _tags.Contains(MetaTags.HIDDEN); } } - public IReadOnlyCollection Tags + public IReadOnlyList Tags { get { @@ -224,6 +227,10 @@ namespace DCFApixels.DragonECS { return Name; } + public override int GetHashCode() + { + return _color.GetHashCode() ^ _name[0].GetHashCode() ^ _name[_name.Length - 1].GetHashCode(); + } private class DebuggerProxy : ITypeMeta { private readonly TypeMeta _meta; @@ -247,7 +254,7 @@ namespace DCFApixels.DragonECS { get { return _meta.Group; } } - public IReadOnlyCollection Tags + public IReadOnlyList Tags { get { return _meta.Tags; } } @@ -314,7 +321,7 @@ namespace DCFApixels.DragonECS #endregion #region GetTags - public static IReadOnlyCollection GetTags(Type type) + public static IReadOnlyList GetTags(Type type) { var atr = type.GetCustomAttribute(); return atr != null ? atr.Tags : Array.Empty();