Merge branch 'dev' into test-pool

This commit is contained in:
DCFApixels 2025-03-13 15:06:45 +08:00
commit 5c013c77f0
5 changed files with 34 additions and 26 deletions

View File

@ -232,16 +232,17 @@ namespace DCFApixels.DragonECS
{
this.colorCode = withoutAlpha ? colorCode | 255 : colorCode;
}
public MetaColor(string stringCode) : this()
public static MetaColor FromHashCode(int hash)
{
return FromHashCode(hash, false);
}
public static MetaColor FromHashCode(int hash, bool withoutAlpha)
{
unchecked
{
const uint MAGIC_CONST = 0xA638_783E;
uint colorCode = (uint)stringCode.GetHashCode();
colorCode ^= MAGIC_CONST;
uint colorCode = (uint)hash;
colorCode = BitsUtility.NextXorShiftState(colorCode);
this.colorCode = (uint)colorCode | 255;
this.colorCode = UpContrast().colorCode;
return new MetaColor(colorCode, withoutAlpha);
}
}
#endregion

View File

@ -6,8 +6,6 @@ using System.Text.RegularExpressions;
namespace DCFApixels.DragonECS
{
using static MetaGroupAttribute;
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
public sealed class MetaGroupAttribute : EcsMetaAttribute
{
@ -22,6 +20,7 @@ namespace DCFApixels.DragonECS
[DebuggerDisplay("{Name}")]
public class MetaGroup
{
public const char SEPARATOR = MetaGroupAttribute.SEPARATOR;
public const string UNGROUPED = "<UNGROUPED>";
private const string PATTERN = @"Module(?=/)";
public static readonly MetaGroup Empty = new MetaGroup(UNGROUPED);
@ -39,6 +38,10 @@ namespace DCFApixels.DragonECS
return _path;
}
}
public bool IsEmpty
{
get { return this == Empty; }
}
public MetaGroup(string name)
{
if (string.IsNullOrEmpty(name))

View File

@ -153,7 +153,7 @@ namespace DCFApixels.DragonECS
{
if (_initFlags.HasFlag(InitFlag.Color) == false)
{
(_color, _isCustomColor) = MetaGenerator.GetColor(_type);
(_color, _isCustomColor) = MetaGenerator.GetColor(this);
_initFlags |= InitFlag.Color;
}
}
@ -406,15 +406,6 @@ namespace DCFApixels.DragonECS
{
private const int GENERIC_NAME_DEPTH = 3;
//private static HashSet<Type> _;
//#region GetMemberType
//public static EcsMemberType GetMemberType(Type type)
//{
// throw new NotImplementedException();
//}
//#endregion
#region GetMetaName/GetTypeName
public static string GetTypeName(Type type)
{
@ -448,15 +439,25 @@ namespace DCFApixels.DragonECS
#endregion
#region GetColor
private static MetaColor AutoColor(Type type)
private static MetaColor AutoColor(TypeMeta meta)
{
return new MetaColor(type.Name).UpContrast();//.Desaturate(0.48f) / 1.18f;
int hash;
if (meta.Group.IsEmpty)
{
hash = meta.Type.Name.GetHashCode();
}
public static (MetaColor, bool) GetColor(Type type)
else
{
hash = meta.Group.Name.GetHashCode();
}
return MetaColor.FromHashCode(hash).UpContrast();
}
public static (MetaColor, bool) GetColor(TypeMeta meta)
{
#if (DEBUG && !DISABLE_DEBUG) || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает
bool isCustom = type.TryGetAttribute(out MetaColorAttribute atr);
return (isCustom ? atr.color : AutoColor(type), isCustom);
bool isCustom = meta.Type.TryGetAttribute(out MetaColorAttribute atr);
return (isCustom ? atr.color : AutoColor(meta), isCustom);
#else
EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetColor)} method does not work.");
return (AutoColor(type), false);

View File

@ -225,13 +225,14 @@ namespace DCFApixels.DragonECS
//Building
TAspect newAspect = new TAspect();
object newAspectObj = newAspect;
EcsAspect builtinAspect = newAspect as EcsAspect;
if (builtinAspect != null)
{
builtinAspect._source = world;
builtinAspect.Init(builder);
}
OnInit(newAspect, builder);
OnInit(newAspectObj, builder);
//Build Mask
if (staticMask == null)
@ -254,9 +255,9 @@ namespace DCFApixels.DragonECS
_constructorBuildersStackIndex--;
OnAfterInit(newAspect, mask);
OnAfterInit(newAspectObj, mask);
return (newAspect, mask);
return ((TAspect)newAspectObj, mask);
}
#endregion

View File

@ -75,6 +75,8 @@ namespace DCFApixels.DragonECS
EcsProcessRaw ProcessRaw { get; }
bool IsEmpty { get; }
}
//TODO инъекция в раннеры
//TODO добавить функцию фильтрации систем по string, за счет создания отдельных ранеров для отдельных string
[MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.OTHER_GROUP)]