udpate typemeta add docs

This commit is contained in:
Mikhail 2024-06-08 02:08:20 +08:00
parent 56bc701e01
commit f7fb996ffc
6 changed files with 90 additions and 19 deletions

View File

@ -11,11 +11,46 @@ namespace DCFApixels.DragonECS.Docs
{ {
[DataMember] [DataMember]
private readonly DragonDocsMeta[] _metas; private readonly DragonDocsMeta[] _metas;
[NonSerialized]
private DragonDocsMetaGroup[] _mapping = null;
public ReadOnlySpan<DragonDocsMeta> Meta public ReadOnlySpan<DragonDocsMeta> Meta
{ {
get { return new ReadOnlySpan<DragonDocsMeta>(_metas); } get { return new ReadOnlySpan<DragonDocsMeta>(_metas); }
} }
public ReadOnlySpan<DragonDocsMetaGroup> Mapping
{
get
{
Init();
return new ReadOnlySpan<DragonDocsMetaGroup>(_mapping); ;
}
}
private bool _isInit = false;
private void Init()
{
if (_isInit) { return; }
if (_metas.Length < 0)
{
_mapping = Array.Empty<DragonDocsMetaGroup>();
}
List<DragonDocsMetaGroup> groups = new List<DragonDocsMetaGroup>();
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) private DragonDocs(DragonDocsMeta[] metas)
{ {
_metas = metas; _metas = metas;
@ -50,4 +85,17 @@ namespace DCFApixels.DragonECS.Docs
return result; 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;
}
}
} }

View File

@ -20,7 +20,7 @@ namespace DCFApixels.DragonECS.Docs
[DataMember] public readonly string Description = string.Empty; [DataMember] public readonly string Description = string.Empty;
[DataMember] public readonly string Group = string.Empty; [DataMember] public readonly string Group = string.Empty;
[DataMember] public readonly string Tags = string.Empty; [DataMember] public readonly string[] Tags = Array.Empty<string>();
public DragonDocsMeta(TypeMeta meta) public DragonDocsMeta(TypeMeta meta)
{ {
@ -35,7 +35,11 @@ namespace DCFApixels.DragonECS.Docs
Description = meta.Description.Text; Description = meta.Description.Text;
Group = meta.Group.Name; 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) public bool TryGetSourceType(out Type type)

View File

@ -20,16 +20,20 @@ namespace DCFApixels.DragonECS
public readonly ref struct AutoScope public readonly ref struct AutoScope
{ {
private readonly int _id; private readonly int _id;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public AutoScope(int id) public AutoScope(int id)
{ {
_id = id; _id = id;
DebugService.Instance.ProfilerMarkBegin(id); DebugService.Instance.ProfilerMarkBegin(id);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dispose() public void Dispose()
{ {
DebugService.Instance.ProfilerMarkEnd(_id); DebugService.Instance.ProfilerMarkEnd(_id);
} }
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator EcsProfilerMarker(string markerName) { return new EcsProfilerMarker(markerName); }
} }
public static class EcsDebug public static class EcsDebug

View File

@ -23,20 +23,20 @@ namespace DCFApixels.DragonECS
public class MetaGroup public class MetaGroup
{ {
public static readonly MetaGroup Empty = new MetaGroup(""); public static readonly MetaGroup Empty = new MetaGroup("");
private static string pattern = @"Module(?=/)"; private static string _pattern = @"Module(?=/)";
private static char[] separatpor = new char[] { '/' }; private static char[] _separatpor = new char[] { '/' };
public readonly string Name; public readonly string Name;
private string[] path = null; private string[] _path = null;
public IReadOnlyCollection<string> Splited public IReadOnlyCollection<string> Splited
{ {
get 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) public MetaGroup(string name)
@ -51,7 +51,8 @@ namespace DCFApixels.DragonECS
{ {
name += '/'; name += '/';
} }
Name = Regex.Replace(name, pattern, ""); ; Name = Regex.Replace(name, _pattern, "");
Name = string.Intern(Name);
} }
public override string ToString() { return Name; } public override string ToString() { return Name; }
} }

View File

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {
@ -8,20 +7,28 @@ namespace DCFApixels.DragonECS
public sealed class MetaTagsAttribute : EcsMetaAttribute public sealed class MetaTagsAttribute : EcsMetaAttribute
{ {
private readonly string[] _tags = Array.Empty<string>(); private readonly string[] _tags = Array.Empty<string>();
public IReadOnlyCollection<string> Tags private static char[] _separatpor = new char[] { ',' };
public IReadOnlyList<string> Tags
{ {
get { return _tags; } get { return _tags; }
} }
[Obsolete("With empty parameters, this attribute makes no sense.")] [Obsolete("With empty parameters, this attribute makes no sense.")]
public MetaTagsAttribute() { } 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 readonly ref struct MetaTags
{ {
public const string HIDDEN = EcsConsts.META_HIDDEN_TAG; public const string HIDDEN = EcsConsts.META_HIDDEN_TAG;
private static string[] _tags = new string[64];
} }
} }

View File

@ -14,9 +14,12 @@ namespace DCFApixels.DragonECS
MetaColor Color { get; } MetaColor Color { get; }
MetaDescription Description { get; } MetaDescription Description { get; }
MetaGroup Group { get; } MetaGroup Group { get; }
IReadOnlyCollection<string> Tags { get; } IReadOnlyList<string> 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))] [DebuggerTypeProxy(typeof(DebuggerProxy))]
public sealed class TypeMeta : ITypeMeta public sealed class TypeMeta : ITypeMeta
{ {
@ -32,7 +35,7 @@ namespace DCFApixels.DragonECS
private MetaColor _color; private MetaColor _color;
private MetaDescription _description; private MetaDescription _description;
private MetaGroup _group; private MetaGroup _group;
private IReadOnlyCollection<string> _tags; private IReadOnlyList<string> _tags;
private int _typeCode; private int _typeCode;
private InitFlag _initFlags = InitFlag.None; private InitFlag _initFlags = InitFlag.None;
@ -154,7 +157,7 @@ namespace DCFApixels.DragonECS
_isHidden = _tags.Contains(MetaTags.HIDDEN); _isHidden = _tags.Contains(MetaTags.HIDDEN);
} }
} }
public IReadOnlyCollection<string> Tags public IReadOnlyList<string> Tags
{ {
get get
{ {
@ -224,6 +227,10 @@ namespace DCFApixels.DragonECS
{ {
return Name; return Name;
} }
public override int GetHashCode()
{
return _color.GetHashCode() ^ _name[0].GetHashCode() ^ _name[_name.Length - 1].GetHashCode();
}
private class DebuggerProxy : ITypeMeta private class DebuggerProxy : ITypeMeta
{ {
private readonly TypeMeta _meta; private readonly TypeMeta _meta;
@ -247,7 +254,7 @@ namespace DCFApixels.DragonECS
{ {
get { return _meta.Group; } get { return _meta.Group; }
} }
public IReadOnlyCollection<string> Tags public IReadOnlyList<string> Tags
{ {
get { return _meta.Tags; } get { return _meta.Tags; }
} }
@ -314,7 +321,7 @@ namespace DCFApixels.DragonECS
#endregion #endregion
#region GetTags #region GetTags
public static IReadOnlyCollection<string> GetTags(Type type) public static IReadOnlyList<string> GetTags(Type type)
{ {
var atr = type.GetCustomAttribute<MetaTagsAttribute>(); var atr = type.GetCustomAttribute<MetaTagsAttribute>();
return atr != null ? atr.Tags : Array.Empty<string>(); return atr != null ? atr.Tags : Array.Empty<string>();