mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 09:54:35 +08:00
update type code
This commit is contained in:
parent
4e54be72bf
commit
ab06cbce58
@ -452,7 +452,7 @@ namespace DCFApixels.DragonECS
|
||||
private static string CreateLogString(EcsTypeCode[] inc, EcsTypeCode[] exc)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG)
|
||||
string converter(EcsTypeCode o) { return EcsDebugUtility.GetGenericTypeName(EcsTypeCodeManager.FindTypeOfCode(o), 1); }
|
||||
string converter(EcsTypeCode o) { return EcsTypeCodeManager.FindTypeOfCode(o).ToString(); }
|
||||
return $"Inc({string.Join(", ", inc.Select(converter))}) Exc({string.Join(", ", exc.Select(converter))})";
|
||||
#else
|
||||
return $"Inc({string.Join(", ", inc)}) Exc({string.Join(", ", exc)})"; // Release optimization
|
||||
@ -478,7 +478,7 @@ namespace DCFApixels.DragonECS
|
||||
ID = mask.ID;
|
||||
included = mask._incs;
|
||||
excluded = mask._excs;
|
||||
Type converter(EcsTypeCode o) { return EcsTypeCodeManager.FindTypeOfCode(o); }
|
||||
Type converter(EcsTypeCode o) { return EcsTypeCodeManager.FindTypeOfCode(o).Type; }
|
||||
includedTypes = included.Select(converter).ToArray();
|
||||
excludedTypes = excluded.Select(converter).ToArray();
|
||||
}
|
||||
|
@ -73,34 +73,6 @@ namespace DCFApixels.DragonECS
|
||||
private List<IEcsWorldEventListener> _listeners = new List<IEcsWorldEventListener>();
|
||||
private List<IEcsEntityEventListener> _entityListeners = new List<IEcsEntityEventListener>();
|
||||
|
||||
|
||||
private static Stack<EcsWorldConfig> _configInitOnlynStack = new Stack<EcsWorldConfig>(4);
|
||||
protected internal static EcsWorldConfig Config_InitOnly
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_configInitOnlynStack.TryPeek(out EcsWorldConfig result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
Throw.UndefinedException();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private readonly ref struct ConfigInitOnlyScope
|
||||
{
|
||||
private readonly Stack<EcsWorldConfig> _stack;
|
||||
public ConfigInitOnlyScope(Stack<EcsWorldConfig> stack, EcsWorldConfig config)
|
||||
{
|
||||
_stack = stack;
|
||||
_stack.Push(config);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_stack.Peek();
|
||||
}
|
||||
}
|
||||
|
||||
#region Properties
|
||||
EcsWorld IEntityStorage.World
|
||||
{
|
||||
@ -171,8 +143,6 @@ namespace DCFApixels.DragonECS
|
||||
lock (_worldLock)
|
||||
{
|
||||
if (configs == null) { configs = ConfigContainer.Empty; }
|
||||
_configInitOnlynStack.Push(configs.GetWorldConfigOrDefault());
|
||||
|
||||
bool nullWorld = this is NullWorld;
|
||||
if (nullWorld == false && worldID == NULL_WORLD_ID)
|
||||
{
|
||||
@ -194,7 +164,6 @@ namespace DCFApixels.DragonECS
|
||||
if (_worlds[worldID] != null)
|
||||
{
|
||||
_worldIdDispenser.Release(worldID);
|
||||
_configInitOnlynStack.Pop();
|
||||
Throw.Exception("The world with the specified ID has already been created\r\n");
|
||||
}
|
||||
}
|
||||
@ -211,9 +180,9 @@ namespace DCFApixels.DragonECS
|
||||
int entitiesCapacity = ArrayUtility.NormalizeSizeToPowerOfTwo(config.EntitiesCapacity);
|
||||
_entityDispenser = new IdDispenser(entitiesCapacity, 0, OnEntityDispenserResized);
|
||||
|
||||
GetComponentTypeID<NullComponent>();
|
||||
_executorCoures = new Dictionary<(Type, object), IQueryExecutorImplementation>(config.PoolComponentsCapacity);
|
||||
|
||||
_configInitOnlynStack.Pop();
|
||||
GetComponentTypeID<NullComponent>();
|
||||
}
|
||||
}
|
||||
public void Destroy()
|
||||
|
@ -8,7 +8,7 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
public partial class EcsWorld
|
||||
{
|
||||
private readonly Dictionary<(Type, object), IQueryExecutorImplementation> _executorCoures = new Dictionary<(Type, object), IQueryExecutorImplementation>(Config_InitOnly.PoolComponentsCapacity);
|
||||
private readonly Dictionary<(Type, object), IQueryExecutorImplementation> _executorCoures;
|
||||
public TExecutor GetExecutorForMask<TExecutor>(IComponentMask gmask)
|
||||
where TExecutor : MaskQueryExecutor, new()
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
#if ENABLE_IL2CPP
|
||||
@ -8,6 +9,46 @@ using Unity.IL2CPP.CompilerServices;
|
||||
|
||||
namespace DCFApixels.DragonECS.Internal
|
||||
{
|
||||
#if ENABLE_IL2CPP
|
||||
[Il2CppSetOption(Option.NullChecks, false)]
|
||||
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
|
||||
#endif
|
||||
[DebuggerDisplay("{" + nameof(GetDebuggerDisplay) + "(),nq}")]
|
||||
internal readonly struct EcsTypeCodeKey : IEquatable<EcsTypeCodeKey>
|
||||
{
|
||||
public readonly Type Type;
|
||||
public readonly string NameKey;
|
||||
public EcsTypeCodeKey(Type type, string nameKey)
|
||||
{
|
||||
Type = type;
|
||||
NameKey = nameKey;
|
||||
}
|
||||
public bool Equals(EcsTypeCodeKey other)
|
||||
{
|
||||
return Type == other.Type && NameKey == other.NameKey;
|
||||
}
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is EcsTypeCodeKey other && Equals(other);
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(Type, NameKey);
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
if (string.IsNullOrEmpty(NameKey))
|
||||
{
|
||||
return Type.ToString();
|
||||
}
|
||||
return $"{Type} {NameKey}";
|
||||
}
|
||||
public static implicit operator EcsTypeCodeKey(Type type) { return new EcsTypeCodeKey(type, string.Empty); }
|
||||
private string GetDebuggerDisplay()
|
||||
{
|
||||
return ToString();
|
||||
}
|
||||
}
|
||||
//TODO разработать возможность ручного устанавливания ID типам.
|
||||
//это может быть полезно как детерминированность для сети
|
||||
#if ENABLE_IL2CPP
|
||||
@ -16,7 +57,7 @@ namespace DCFApixels.DragonECS.Internal
|
||||
#endif
|
||||
internal static class EcsTypeCodeManager
|
||||
{
|
||||
private static readonly Dictionary<Type, EcsTypeCode> _codes = new Dictionary<Type, EcsTypeCode>();
|
||||
private static readonly Dictionary<EcsTypeCodeKey, EcsTypeCode> _codes = new Dictionary<EcsTypeCodeKey, EcsTypeCode>();
|
||||
private static int _increment = 1;
|
||||
private static object _lock = new object();
|
||||
public static int Count
|
||||
@ -40,7 +81,7 @@ namespace DCFApixels.DragonECS.Internal
|
||||
public static EcsTypeCode Get<T>() { return EcsTypeCodeCache<T>.code; }
|
||||
public static bool Has(Type type) { return _codes.ContainsKey(type); }
|
||||
public static bool Has<T>() { return _codes.ContainsKey(typeof(T)); }
|
||||
public static Type FindTypeOfCode(EcsTypeCode typeCode)
|
||||
public static EcsTypeCodeKey FindTypeOfCode(EcsTypeCode typeCode)
|
||||
{
|
||||
foreach (var item in _codes)
|
||||
{
|
||||
@ -67,9 +108,9 @@ namespace DCFApixels.DragonECS.Internal
|
||||
#endif
|
||||
internal struct TypeCodeInfo
|
||||
{
|
||||
public Type type;
|
||||
public EcsTypeCodeKey type;
|
||||
public EcsTypeCode code;
|
||||
public TypeCodeInfo(Type type, EcsTypeCode code)
|
||||
public TypeCodeInfo(EcsTypeCodeKey type, EcsTypeCode code)
|
||||
{
|
||||
this.type = type;
|
||||
this.code = code;
|
||||
|
Loading…
Reference in New Issue
Block a user