mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 18:14:37 +08:00
api polishing/add world name
This commit is contained in:
parent
c23e3ce621
commit
0182614819
@ -10,8 +10,9 @@ namespace DCFApixels.DragonECS
|
||||
[MetaID("4EE3527C92015BAB0299CB7B4E2663D1")]
|
||||
public sealed class EcsDefaultWorld : EcsWorld, IInjectionUnit
|
||||
{
|
||||
public EcsDefaultWorld(EcsWorldConfig config, short worldID = -1) : base(config, worldID) { }
|
||||
public EcsDefaultWorld(IConfigContainer configs = null, short worldID = -1) : base(configs, worldID) { }
|
||||
public EcsDefaultWorld() : base() { }
|
||||
public EcsDefaultWorld(EcsWorldConfig config = null, string name = null, short worldID = -1) : base(config, name == null ? "Default" : name, worldID) { }
|
||||
public EcsDefaultWorld(IConfigContainer configs, string name = null, short worldID = -1) : base(configs, name == null ? "Default" : name, worldID) { }
|
||||
void IInjectionUnit.InitInjectionNode(InjectionGraph nodes) { nodes.AddNode(this); }
|
||||
}
|
||||
/// <summary> EcsWrold for store event entities. </summary>
|
||||
@ -22,8 +23,9 @@ namespace DCFApixels.DragonECS
|
||||
[MetaID("D7CE527C920160BCD765EFA72DBF8B89")]
|
||||
public sealed class EcsEventWorld : EcsWorld, IInjectionUnit
|
||||
{
|
||||
public EcsEventWorld(EcsWorldConfig config, short worldID = -1) : base(config, worldID) { }
|
||||
public EcsEventWorld(IConfigContainer configs = null, short worldID = -1) : base(configs, worldID) { }
|
||||
public EcsEventWorld() : base() { }
|
||||
public EcsEventWorld(EcsWorldConfig config = null, string name = null, short worldID = -1) : base(config, name == null ? "Events" : name, worldID) { }
|
||||
public EcsEventWorld(IConfigContainer configs, string name = null, short worldID = -1) : base(configs, name == null ? "Events" : name, worldID) { }
|
||||
void IInjectionUnit.InitInjectionNode(InjectionGraph nodes) { nodes.AddNode(this); }
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,10 @@ using static DCFApixels.DragonECS.EcsConsts;
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
public interface IEcsMember { }
|
||||
public interface INamedMember
|
||||
{
|
||||
string Name { get; }
|
||||
}
|
||||
|
||||
[MetaColor(MetaColor.DragonRose)]
|
||||
[MetaGroup(PACK_GROUP, OTHER_GROUP)]
|
||||
|
@ -6,11 +6,13 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
#if ENABLE_IL2CPP
|
||||
using Unity.IL2CPP.CompilerServices;
|
||||
#endif
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
#if ENABLE_IL2CPP
|
||||
using Unity.IL2CPP.CompilerServices;
|
||||
[Il2CppSetOption(Option.NullChecks, false)]
|
||||
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
|
||||
#endif
|
||||
@ -41,10 +43,11 @@ namespace DCFApixels.DragonECS
|
||||
[MetaDescription(EcsConsts.AUTHOR, "It is a container for entities and components.")]
|
||||
[MetaID("AEF3557C92019C976FC48F90E95A9DA6")]
|
||||
[DebuggerTypeProxy(typeof(DebuggerProxy))]
|
||||
public partial class EcsWorld : IEntityStorage, IEcsMember
|
||||
public partial class EcsWorld : IEntityStorage, IEcsMember, INamedMember
|
||||
{
|
||||
public readonly short ID;
|
||||
private IConfigContainer _configs;
|
||||
private readonly IConfigContainer _configs;
|
||||
private readonly string _name;
|
||||
|
||||
private bool _isDestroyed = false;
|
||||
|
||||
@ -73,6 +76,7 @@ namespace DCFApixels.DragonECS
|
||||
#region Properties
|
||||
EcsWorld IEntityStorage.World
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get { return this; }
|
||||
}
|
||||
public IConfigContainer Configs
|
||||
@ -80,6 +84,11 @@ namespace DCFApixels.DragonECS
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get { return _configs; }
|
||||
}
|
||||
public string Name
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get { return _name; }
|
||||
}
|
||||
public long Version
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@ -134,12 +143,15 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
|
||||
#region Constructors/Destroy
|
||||
public EcsWorld(EcsWorldConfig config, short worldID = -1) : this(config == null ? ConfigContainer.Empty : new ConfigContainer().Set(config), worldID) { }
|
||||
public EcsWorld(IConfigContainer configs = null, short worldID = -1)
|
||||
public EcsWorld() : this(ConfigContainer.Empty, null, -1) { }
|
||||
public EcsWorld(EcsWorldConfig config = null, string name = null, short worldID = -1) : this(config == null ? ConfigContainer.Empty : new ConfigContainer().Set(config), name, worldID) { }
|
||||
public EcsWorld(IConfigContainer configs, string name = null, short worldID = -1)
|
||||
{
|
||||
lock (_worldLock)
|
||||
{
|
||||
if (configs == null) { configs = ConfigContainer.Empty; }
|
||||
if (name == null) { name = string.Empty; }
|
||||
_name = name;
|
||||
bool nullWorld = this is NullWorld;
|
||||
if (nullWorld == false && worldID == NULL_WORLD_ID)
|
||||
{
|
||||
@ -264,6 +276,18 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
#region New/Del
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public entlong NewEntityLong()
|
||||
{
|
||||
int entityID = NewEntity();
|
||||
return GetEntityLong(entityID);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public entlong NewEntityLong(int entityID)
|
||||
{
|
||||
NewEntity(entityID);
|
||||
return GetEntityLong(entityID);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int NewEntity()
|
||||
{
|
||||
int entityID = _entityDispenser.UseFree();
|
||||
@ -294,24 +318,26 @@ namespace DCFApixels.DragonECS
|
||||
_entityListeners.InvokeOnNewEntity(entityID);
|
||||
}
|
||||
|
||||
public entlong NewEntityLong()
|
||||
{
|
||||
int entityID = NewEntity();
|
||||
return GetEntityLong(entityID);
|
||||
}
|
||||
public entlong NewEntityLong(int entityID)
|
||||
{
|
||||
NewEntity(entityID);
|
||||
return GetEntityLong(entityID);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void TryDelEntity(int entityID)
|
||||
public bool TryDelEntity(entlong entity)
|
||||
{
|
||||
if (entity.TryGetID(out int entityID))
|
||||
{
|
||||
TryDelEntity(entityID);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool TryDelEntity(int entityID)
|
||||
{
|
||||
if (IsUsed(entityID))
|
||||
{
|
||||
DelEntity(entityID);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void DelEntity(entlong entity)
|
||||
@ -360,6 +386,15 @@ namespace DCFApixels.DragonECS
|
||||
return slot.gen == gen && slot.isUsed;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool IsAlive(entlong entity)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (entity.GetWorldIDUnchecked() != ID) { Throw.World_MaskDoesntBelongWorld(); }
|
||||
#endif
|
||||
ref var slot = ref _entities[entity.GetIDUnchecked()];
|
||||
return slot.gen == entity.GetIDUnchecked() && slot.isUsed;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool IsUsed(int entityID)
|
||||
{
|
||||
return _entities[entityID].isUsed;
|
||||
|
@ -94,6 +94,10 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return DeclareOrGetComponentTypeID(EcsTypeCodeManager.Get(componentType));
|
||||
}
|
||||
public Type GetComponentType(int componentTypeID)
|
||||
{
|
||||
return _pools[componentTypeID].ComponentType;
|
||||
}
|
||||
public bool IsComponentTypeDeclared<TComponent>()
|
||||
{
|
||||
return _cmpTypeCode_2_CmpTypeIDs.Contains((int)EcsTypeCodeManager.Get<TComponent>());
|
||||
@ -102,6 +106,7 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return _cmpTypeCode_2_CmpTypeIDs.Contains((int)EcsTypeCodeManager.Get(componentType));
|
||||
}
|
||||
//TODO пересмотреть нейминг или функцию
|
||||
public bool IsComponentTypeDeclared(int componentTypeID)
|
||||
{
|
||||
if (componentTypeID >= 0 && componentTypeID < _pools.Length)
|
||||
@ -110,10 +115,6 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public Type GetComponentType(int componentTypeID)
|
||||
{
|
||||
return _pools[componentTypeID].ComponentType;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Declare
|
||||
@ -364,10 +365,10 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
|
||||
#region LockPool/UnLockPool
|
||||
public void LockPool_Debug(int ComponentTypeID)
|
||||
public void LockPool_Debug(int componentTypeID)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
ref var slot = ref _poolSlots[ComponentTypeID];
|
||||
ref var slot = ref _poolSlots[componentTypeID];
|
||||
if (slot.locked == false)
|
||||
{
|
||||
slot.locked = true;
|
||||
@ -376,14 +377,14 @@ namespace DCFApixels.DragonECS
|
||||
ReleaseDelEntityBufferAll();
|
||||
}
|
||||
_lockedPoolCount++;
|
||||
_pools[ComponentTypeID].OnLockedChanged_Debug(true);
|
||||
_pools[componentTypeID].OnLockedChanged_Debug(true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
public void UnlockPool_Debug(int ComponentTypeID)
|
||||
public void UnlockPool_Debug(int componentTypeID)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
ref var slot = ref _poolSlots[ComponentTypeID];
|
||||
ref var slot = ref _poolSlots[componentTypeID];
|
||||
if (slot.locked == true)
|
||||
{
|
||||
slot.locked = false;
|
||||
@ -394,21 +395,21 @@ namespace DCFApixels.DragonECS
|
||||
_lockedPoolCount = 0;
|
||||
Throw.OpeningClosingMethodsBalanceError();
|
||||
}
|
||||
_pools[ComponentTypeID].OnLockedChanged_Debug(false);
|
||||
_pools[componentTypeID].OnLockedChanged_Debug(false);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
public bool CheckPoolLocked_Debug(int ComponentTypeID)
|
||||
public bool CheckPoolLocked_Debug(int componentTypeID)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
return _poolSlots[ComponentTypeID].locked;
|
||||
return _poolSlots[componentTypeID].locked;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PoolSlot
|
||||
#region Utils
|
||||
internal struct PoolSlot
|
||||
{
|
||||
public int count;
|
||||
|
@ -163,7 +163,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
private sealed class NullWorld : EcsWorld
|
||||
{
|
||||
internal NullWorld() : base(new EcsWorldConfig(4, 4, 4, 4, 4), 0) { }
|
||||
internal NullWorld() : base(new EcsWorldConfig(4, 4, 4, 4, 4), null, 0) { }
|
||||
}
|
||||
|
||||
#region Obsolete
|
||||
|
@ -3,6 +3,7 @@ using DCFApixels.DragonECS.PoolsCore;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
#if ENABLE_IL2CPP
|
||||
using Unity.IL2CPP.CompilerServices;
|
||||
@ -25,6 +26,7 @@ namespace DCFApixels.DragonECS
|
||||
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.POOLS_GROUP)]
|
||||
[MetaDescription(EcsConsts.AUTHOR, "Pool for IEcsComponent components.")]
|
||||
[MetaID("C501547C9201A4B03FC25632E4FAAFD7")]
|
||||
[DebuggerDisplay("Count: {Count}")]
|
||||
public sealed class EcsPool<T> : IEcsPoolImplementation<T>, IEcsStructPool<T>, IEnumerable<T> //IEnumerable<T> - IntelliSense hack
|
||||
where T : struct, IEcsComponent
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
using DCFApixels.DragonECS.PoolsCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace DCFApixels.DragonECS.PoolsCore
|
||||
@ -58,6 +59,7 @@ namespace DCFApixels.DragonECS.Internal
|
||||
[MetaDescription(EcsConsts.AUTHOR, "A placeholder type, an instance of this type replaces the null ref.")]
|
||||
[MetaTags(MetaTags.HIDDEN)]
|
||||
[MetaID("460E547C9201227A4956AC297F67B484")]
|
||||
[DebuggerDisplay("-")]
|
||||
public sealed class EcsNullPool : IEcsPoolImplementation<NullComponent>
|
||||
{
|
||||
public static readonly EcsNullPool instance = new EcsNullPool();
|
||||
|
@ -3,6 +3,8 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Diagnostics;
|
||||
|
||||
#if (DEBUG && !DISABLE_DEBUG)
|
||||
using System.Reflection;
|
||||
#endif
|
||||
@ -27,6 +29,7 @@ namespace DCFApixels.DragonECS
|
||||
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.POOLS_GROUP)]
|
||||
[MetaDescription(EcsConsts.AUTHOR, "Pool for IEcsTagComponent components. EcsTagPool is optimized for storing tag components or components without data.")]
|
||||
[MetaID("9D80547C9201E852E4F17324EAC1E15A")]
|
||||
[DebuggerDisplay("Count: {Count}")]
|
||||
public sealed class EcsTagPool<T> : IEcsPoolImplementation<T>, IEcsStructPool<T>, IEnumerable<T> //IEnumerable<T> - IntelliSense hack
|
||||
where T : struct, IEcsTagComponent
|
||||
{
|
||||
|
@ -6,6 +6,16 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
public static class ITemplateNodeExtensions
|
||||
{
|
||||
public static int ApplyAndReturn(this ITemplateNode self, short worldID, int entityID)
|
||||
{
|
||||
self.Apply(worldID, entityID);
|
||||
return entityID;
|
||||
}
|
||||
public static entlong ApplyAndReturnLong(this ITemplateNode self, short worldID, int entityID)
|
||||
{
|
||||
self.Apply(worldID, entityID);
|
||||
return (EcsWorld.GetWorld(worldID), entityID);
|
||||
}
|
||||
public static int NewEntity(this EcsWorld world, ITemplateNode template)
|
||||
{
|
||||
int e = world.NewEntity();
|
||||
@ -18,5 +28,18 @@ namespace DCFApixels.DragonECS
|
||||
template.Apply(world.ID, e.ID);
|
||||
return e;
|
||||
}
|
||||
|
||||
public static int NewEntity(this EcsWorld world, int entityID, ITemplateNode template)
|
||||
{
|
||||
int e = world.NewEntity(entityID);
|
||||
template.Apply(world.ID, e);
|
||||
return e;
|
||||
}
|
||||
public static entlong NewEntityLong(this EcsWorld world, int entityID, ITemplateNode template)
|
||||
{
|
||||
entlong e = world.NewEntityLong(entityID);
|
||||
template.Apply(world.ID, e.ID);
|
||||
return e;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user