mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 01:44:35 +08:00
update
add IEcsDebugName add EcsDebugUtility.GetNameForObject fix warning add GC.Collect to EcsPipeline.Builder.Init fix bit shifts in SparseArray etc
This commit is contained in:
parent
0c06d971aa
commit
f858529325
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
@ -57,8 +58,24 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
|
||||
#region GetName
|
||||
public static string GetNameForObject(IEcsDebugName obj) => obj.DebugName;
|
||||
public static string GetNameForObject(object obj) => obj is IEcsDebugName dn ? dn.DebugName : GetName(obj.GetType());
|
||||
public static string GetName<T>() => GetName(typeof(T));
|
||||
public static string GetName(Type type) => type.TryGetCustomAttribute(out DebugNameAttribute atr) ? atr.name : GetGenericTypeName(type);
|
||||
public static bool TryGetCustomNameForObject(IEcsDebugName obj, out string name)
|
||||
{
|
||||
name = obj.DebugName;
|
||||
return true;
|
||||
}
|
||||
public static bool TryGetCustomNameForObject(object obj, out string name)
|
||||
{
|
||||
if (obj is IEcsDebugName dn)
|
||||
{
|
||||
name = dn.DebugName;
|
||||
return true;
|
||||
}
|
||||
return TryGetCustomName(obj.GetType(), out name);
|
||||
}
|
||||
public static bool TryGetCustomName<T>(out string name) => TryGetCustomName(typeof(T), out name);
|
||||
public static bool TryGetCustomName(Type type, out string name)
|
||||
{
|
||||
@ -230,11 +247,13 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
|
||||
#region ReflectionExtensions
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static bool TryGetCustomAttribute<T>(this Type self, out T attribute) where T : Attribute
|
||||
{
|
||||
attribute = self.GetCustomAttribute<T>();
|
||||
return attribute != null;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static bool TryGetCustomAttribute<T>(this MemberInfo self, out T attribute) where T : Attribute
|
||||
{
|
||||
attribute = self.GetCustomAttribute<T>();
|
||||
|
8
src/Debug/Interfaces.meta
Normal file
8
src/Debug/Interfaces.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 50bc53c3762bf6b4ea127004a89a894e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
7
src/Debug/Interfaces/IEcsDebugName.cs
Normal file
7
src/Debug/Interfaces/IEcsDebugName.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
public interface IEcsDebugName
|
||||
{
|
||||
string DebugName { get; }
|
||||
}
|
||||
}
|
11
src/Debug/Interfaces/IEcsDebugName.cs.meta
Normal file
11
src/Debug/Interfaces/IEcsDebugName.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 170270e2ac54ab54a9dab57f58e25a9c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -75,6 +75,7 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
_runRunnerCache = GetRunner<IEcsRunProcess>();
|
||||
_isInit = true;
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
@ -71,6 +71,7 @@ namespace DCFApixels.DragonECS
|
||||
Type interfaceType = item.BaseType.GenericTypeArguments[0];
|
||||
_runnerHandlerTypes.Add(interfaceType.IsGenericType ? interfaceType.GetGenericTypeDefinition() : interfaceType, item);
|
||||
}
|
||||
|
||||
if (delayedExceptions.Count > 0)
|
||||
{
|
||||
throw new AggregateException(delayedExceptions);
|
||||
|
@ -181,7 +181,7 @@ namespace DCFApixels.DragonECS
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe entlong GetEntityLong(int entityID)
|
||||
{
|
||||
long x = ((long)id << 48 | (long)_gens[entityID] << 32 | entityID);
|
||||
long x = (long)id << 48 | (long)_gens[entityID] << 32 | (long)entityID;
|
||||
return *(entlong*)&x;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
@ -1,3 +1,4 @@
|
||||
using DCFApixels.DragonECS.Utils;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@ -5,7 +6,7 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
/// <summary>Pool for IEcsComponent components</summary>
|
||||
/// <summary>Pool for IEcsHybridComponent components</summary>
|
||||
public sealed class EcsHybridPool<T> : IEcsPoolImplementation<T>, IEcsHybridPool<T>, IEnumerable<T> //IEnumerable<T> - IntelliSense hack
|
||||
where T : IEcsHybridComponent
|
||||
{
|
||||
@ -217,6 +218,11 @@ namespace DCFApixels.DragonECS
|
||||
void OnAddToPool(entlong entity);
|
||||
void OnDelFromPool(entlong entity);
|
||||
}
|
||||
public static class IEcsHybridComponentExtensions
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsNullOrNotAlive(this IEcsHybridComponent self) => self == null || self.IsAlive;
|
||||
}
|
||||
public static class EcsHybridPoolExt
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
@ -27,8 +27,8 @@ namespace DCFApixels.DragonECS.Utils
|
||||
#region Properties
|
||||
public TValue this[int keyX, int keyY]
|
||||
{
|
||||
get => _entries[FindEntry((keyX << 32) | keyY)].value;
|
||||
set => Insert(keyX + (keyY << 32), value);
|
||||
get => _entries[FindEntry((keyX << 16) | keyY)].value;
|
||||
set => Insert(keyX + (keyY << 16), value);
|
||||
}
|
||||
public TValue this[int key]
|
||||
{
|
||||
@ -52,7 +52,7 @@ namespace DCFApixels.DragonECS.Utils
|
||||
|
||||
#region Add/Contains/Remove
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Add(int keyX, int keyY, TValue value) => Add((keyX << 32) | keyY, value);
|
||||
public void Add(int keyX, int keyY, TValue value) => Add((keyX << 16) | keyY, value);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Add(int key, TValue value)
|
||||
{
|
||||
@ -63,11 +63,11 @@ namespace DCFApixels.DragonECS.Utils
|
||||
Insert(key, value);
|
||||
}
|
||||
|
||||
public bool Contains(int keyX, int keyY) => FindEntry((keyX << 32) | keyY) >= 0;
|
||||
public bool Contains(int keyX, int keyY) => FindEntry((keyX << 16) | keyY) >= 0;
|
||||
public bool Contains(int key) => FindEntry(key) >= 0;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Remove(int keyX, int keyY) => Remove((keyX << 32) | keyY);
|
||||
public bool Remove(int keyX, int keyY) => Remove((keyX << 16) | keyY);
|
||||
public bool Remove(int key)
|
||||
{
|
||||
int bucket = key & _modBitMask;
|
||||
@ -144,7 +144,7 @@ namespace DCFApixels.DragonECS.Utils
|
||||
#region TryGetValue
|
||||
public bool TryGetValue(int keyX, int keyY, out TValue value)
|
||||
{
|
||||
int index = FindEntry((keyX << 32) | keyY);
|
||||
int index = FindEntry((keyX << 16) | keyY);
|
||||
if (index < 0)
|
||||
{
|
||||
value = default;
|
||||
|
Loading…
Reference in New Issue
Block a user