mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-19 02:24:37 +08:00
add PoolsCore namespace, add IEcsComponentType
This commit is contained in:
parent
d87e0fa948
commit
d2f761a884
@ -1,4 +1,6 @@
|
|||||||
namespace DCFApixels.DragonECS
|
using DCFApixels.DragonECS.PoolsCore;
|
||||||
|
|
||||||
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
public sealed class EmptyAspect : EcsAspect { }
|
public sealed class EmptyAspect : EcsAspect { }
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using DCFApixels.DragonECS.Internal;
|
using DCFApixels.DragonECS.Internal;
|
||||||
|
using DCFApixels.DragonECS.PoolsCore;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
namespace DCFApixels.DragonECS
|
using DCFApixels.DragonECS.PoolsCore;
|
||||||
|
|
||||||
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
public partial class EcsWorld
|
public partial class EcsWorld
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using DCFApixels.DragonECS.Internal;
|
using DCFApixels.DragonECS.Internal;
|
||||||
|
using DCFApixels.DragonECS.PoolsCore;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using DCFApixels.DragonECS.Internal;
|
using DCFApixels.DragonECS.Internal;
|
||||||
|
using DCFApixels.DragonECS.PoolsCore;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using DCFApixels.DragonECS.Internal;
|
using DCFApixels.DragonECS.Internal;
|
||||||
|
using DCFApixels.DragonECS.PoolsCore;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -6,6 +7,8 @@ using System.Runtime.CompilerServices;
|
|||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
|
/// <summary>Standard component</summary>
|
||||||
|
public interface IEcsComponent : IEcsComponentType { }
|
||||||
#if ENABLE_IL2CPP
|
#if ENABLE_IL2CPP
|
||||||
using Unity.IL2CPP.CompilerServices;
|
using Unity.IL2CPP.CompilerServices;
|
||||||
[Il2CppSetOption (Option.NullChecks, false)]
|
[Il2CppSetOption (Option.NullChecks, false)]
|
||||||
@ -297,8 +300,6 @@ namespace DCFApixels.DragonECS
|
|||||||
public static implicit operator EcsPool<T>(OptionalMarker a) { return a.GetInstance<EcsPool<T>>(); }
|
public static implicit operator EcsPool<T>(OptionalMarker a) { return a.GetInstance<EcsPool<T>>(); }
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
/// <summary>Standard component</summary>
|
|
||||||
public interface IEcsComponent { }
|
|
||||||
public static class EcsPoolExt
|
public static class EcsPoolExt
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
@ -1,10 +1,144 @@
|
|||||||
using DCFApixels.DragonECS.Internal;
|
using DCFApixels.DragonECS.Internal;
|
||||||
|
using DCFApixels.DragonECS.PoolsCore;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
namespace DCFApixels.DragonECS.PoolsCore
|
||||||
|
{
|
||||||
|
public interface IEcsComponentType { }
|
||||||
|
/// <summary>Only used to implement a custom pool. In other contexts use IEcsPool or IEcsPool<T>.</summary>
|
||||||
|
public interface IEcsPoolImplementation : IEcsPool
|
||||||
|
{
|
||||||
|
#region Methods
|
||||||
|
void OnInit(EcsWorld world, EcsWorld.PoolsMediator mediator, int componentTypeID);
|
||||||
|
void OnWorldResize(int newSize);
|
||||||
|
void OnReleaseDelEntityBuffer(ReadOnlySpan<int> buffer);
|
||||||
|
void OnWorldDestroy();
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
/// <summary>Only used to implement a custom pool. In other contexts use IEcsPool or IEcsPool<T>.</summary>
|
||||||
|
/// <typeparam name="T">Component type</typeparam>
|
||||||
|
public interface IEcsPoolImplementation<T> : IEcsPoolImplementation { }
|
||||||
|
|
||||||
|
public static class EcsPoolThrowHalper
|
||||||
|
{
|
||||||
|
public static void ThrowAlreadyHasComponent<T>(int entityID)
|
||||||
|
{
|
||||||
|
throw new EcsFrameworkException($"Entity({entityID}) already has component {EcsDebugUtility.GetGenericTypeName<T>()}.");
|
||||||
|
}
|
||||||
|
public static void ThrowNotHaveComponent<T>(int entityID)
|
||||||
|
{
|
||||||
|
throw new EcsFrameworkException($"Entity({entityID}) has no component {EcsDebugUtility.GetGenericTypeName<T>()}.");
|
||||||
|
}
|
||||||
|
public static void ThrowAlreadyHasComponent(Type type, int entityID)
|
||||||
|
{
|
||||||
|
throw new EcsFrameworkException($"Entity({entityID}) already has component {EcsDebugUtility.GetGenericTypeName(type)}.");
|
||||||
|
}
|
||||||
|
public static void ThrowNotHaveComponent(Type type, int entityID)
|
||||||
|
{
|
||||||
|
throw new EcsFrameworkException($"Entity({entityID}) has no component {EcsDebugUtility.GetGenericTypeName(type)}.");
|
||||||
|
}
|
||||||
|
public static void ThrowNullListener()
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("listener is null");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace DCFApixels.DragonECS.Internal
|
||||||
|
{
|
||||||
|
public struct NullComponent { }
|
||||||
|
public sealed class EcsNullPool : IEcsPoolImplementation<NullComponent>
|
||||||
|
{
|
||||||
|
public static readonly EcsNullPool instance = new EcsNullPool();
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
int IEcsReadonlyPool.ComponentTypeID { get { return 0; } }//TODO Првоерить что NullComponent всегда имеет id 0
|
||||||
|
Type IEcsReadonlyPool.ComponentType { get { return typeof(NullComponent); } }
|
||||||
|
EcsWorld IEcsReadonlyPool.World
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
#if (DEBUG && !DISABLE_DEBUG)
|
||||||
|
throw new NullInstanceException();
|
||||||
|
#else
|
||||||
|
return EcsWorld.GetWorld(0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int Count { get { return 0; } }
|
||||||
|
public bool IsReadOnly { get { return true; } }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
bool IEcsReadonlyPool.Has(int index)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
void IEcsPool.Del(int entityID)
|
||||||
|
{
|
||||||
|
#if (DEBUG && !DISABLE_DEBUG)
|
||||||
|
throw new NullInstanceException();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
void IEcsPool.AddRaw(int entityID, object dataRaw)
|
||||||
|
{
|
||||||
|
#if (DEBUG && !DISABLE_DEBUG)
|
||||||
|
throw new NullInstanceException();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
object IEcsReadonlyPool.GetRaw(int entityID)
|
||||||
|
{
|
||||||
|
#if (DEBUG && !DISABLE_DEBUG)
|
||||||
|
throw new NullInstanceException();
|
||||||
|
#else
|
||||||
|
return null;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
void IEcsPool.SetRaw(int entity, object dataRaw)
|
||||||
|
{
|
||||||
|
#if (DEBUG && !DISABLE_DEBUG)
|
||||||
|
throw new NullInstanceException();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
void IEcsReadonlyPool.Copy(int fromEntityID, int toEntityID)
|
||||||
|
{
|
||||||
|
#if (DEBUG && !DISABLE_DEBUG)
|
||||||
|
throw new NullInstanceException();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
void IEcsReadonlyPool.Copy(int fromEntityID, EcsWorld toWorld, int toEntityID)
|
||||||
|
{
|
||||||
|
#if (DEBUG && !DISABLE_DEBUG)
|
||||||
|
throw new NullInstanceException();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
void IEcsPool.ClearAll()
|
||||||
|
{
|
||||||
|
#if (DEBUG && !DISABLE_DEBUG)
|
||||||
|
throw new NullInstanceException();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Callbacks
|
||||||
|
void IEcsPoolImplementation.OnInit(EcsWorld world, EcsWorld.PoolsMediator mediator, int componentTypeID) { }
|
||||||
|
void IEcsPoolImplementation.OnWorldDestroy() { }
|
||||||
|
void IEcsPoolImplementation.OnWorldResize(int newSize) { }
|
||||||
|
void IEcsPoolImplementation.OnReleaseDelEntityBuffer(ReadOnlySpan<int> buffer) { }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Listeners
|
||||||
|
void IEcsReadonlyPool.AddListener(IEcsPoolEventListener listener) { }
|
||||||
|
void IEcsReadonlyPool.RemoveListener(IEcsPoolEventListener listener) { }
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
|
#region Interfaces
|
||||||
public interface IEcsReadonlyPool
|
public interface IEcsReadonlyPool
|
||||||
{
|
{
|
||||||
#region Properties
|
#region Properties
|
||||||
@ -39,57 +173,31 @@ namespace DCFApixels.DragonECS
|
|||||||
/// <summary>A pool for struct components.</summary>
|
/// <summary>A pool for struct components.</summary>
|
||||||
public interface IEcsStructPool<T> : IEcsPool where T : struct
|
public interface IEcsStructPool<T> : IEcsPool where T : struct
|
||||||
{
|
{
|
||||||
|
#region Methods
|
||||||
ref T Add(int entityID);
|
ref T Add(int entityID);
|
||||||
ref readonly T Read(int entityID);
|
ref readonly T Read(int entityID);
|
||||||
ref T Get(int entityID);
|
ref T Get(int entityID);
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
/// <summary>A pool for reference components of type T that instantiates components itself.</summary>
|
/// <summary>A pool for reference components of type T that instantiates components itself.</summary>
|
||||||
public interface IEcsClassPool<T> : IEcsPool where T : class
|
public interface IEcsClassPool<T> : IEcsPool where T : class
|
||||||
{
|
{
|
||||||
|
#region Methods
|
||||||
T Add(int entityID);
|
T Add(int entityID);
|
||||||
T Get(int entityID);
|
T Get(int entityID);
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
/// <summary>A pool for reference components of type T, which does not instantiate components itself but receives components from external sources..</summary>
|
/// <summary>A pool for reference components of type T, which does not instantiate components itself but receives components from external sources..</summary>
|
||||||
public interface IEcsHybridPool<T> : IEcsPool where T : class
|
public interface IEcsHybridPool<T> : IEcsPool where T : class
|
||||||
{
|
{
|
||||||
|
#region Methods
|
||||||
void Add(int entityID, T component);
|
void Add(int entityID, T component);
|
||||||
T Get(int entityID);
|
T Get(int entityID);
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
/// <summary>Only used to implement a custom pool. In other contexts use IEcsPool or IEcsPool<T>.</summary>
|
#endregion
|
||||||
public interface IEcsPoolImplementation : IEcsPool
|
|
||||||
{
|
|
||||||
void OnInit(EcsWorld world, EcsWorld.PoolsMediator mediator, int componentTypeID);
|
|
||||||
void OnWorldResize(int newSize);
|
|
||||||
void OnReleaseDelEntityBuffer(ReadOnlySpan<int> buffer);
|
|
||||||
void OnWorldDestroy();
|
|
||||||
}
|
|
||||||
/// <summary>Only used to implement a custom pool. In other contexts use IEcsPool or IEcsPool<T>.</summary>
|
|
||||||
/// <typeparam name="T">Component type</typeparam>
|
|
||||||
public interface IEcsPoolImplementation<T> : IEcsPoolImplementation { }
|
|
||||||
|
|
||||||
public static class EcsPoolThrowHalper
|
#region Extensions
|
||||||
{
|
|
||||||
public static void ThrowAlreadyHasComponent<T>(int entityID)
|
|
||||||
{
|
|
||||||
throw new EcsFrameworkException($"Entity({entityID}) already has component {EcsDebugUtility.GetGenericTypeName<T>()}.");
|
|
||||||
}
|
|
||||||
public static void ThrowNotHaveComponent<T>(int entityID)
|
|
||||||
{
|
|
||||||
throw new EcsFrameworkException($"Entity({entityID}) has no component {EcsDebugUtility.GetGenericTypeName<T>()}.");
|
|
||||||
}
|
|
||||||
public static void ThrowAlreadyHasComponent(Type type, int entityID)
|
|
||||||
{
|
|
||||||
throw new EcsFrameworkException($"Entity({entityID}) already has component {EcsDebugUtility.GetGenericTypeName(type)}.");
|
|
||||||
}
|
|
||||||
public static void ThrowNotHaveComponent(Type type, int entityID)
|
|
||||||
{
|
|
||||||
throw new EcsFrameworkException($"Entity({entityID}) has no component {EcsDebugUtility.GetGenericTypeName(type)}.");
|
|
||||||
}
|
|
||||||
public static void ThrowNullListener()
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("listener is null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static class IEcsPoolImplementationExtensions
|
public static class IEcsPoolImplementationExtensions
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@ -98,97 +206,6 @@ namespace DCFApixels.DragonECS
|
|||||||
return self == null || self == EcsNullPool.instance;
|
return self == null || self == EcsNullPool.instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Dummy EcsNullPool
|
|
||||||
namespace Internal
|
|
||||||
{
|
|
||||||
public struct NullComponent { }
|
|
||||||
public sealed class EcsNullPool : IEcsPoolImplementation<NullComponent>
|
|
||||||
{
|
|
||||||
public static readonly EcsNullPool instance = new EcsNullPool();
|
|
||||||
|
|
||||||
#region Properties
|
|
||||||
int IEcsReadonlyPool.ComponentTypeID { get { return 0; } }//TODO Првоерить что NullComponent всегда имеет id 0
|
|
||||||
Type IEcsReadonlyPool.ComponentType { get { return typeof(NullComponent); } }
|
|
||||||
EcsWorld IEcsReadonlyPool.World
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
#if (DEBUG && !DISABLE_DEBUG)
|
|
||||||
throw new NullInstanceException();
|
|
||||||
#else
|
|
||||||
return EcsWorld.GetWorld(0);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public int Count { get { return 0; } }
|
|
||||||
public bool IsReadOnly { get { return true; } }
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Methods
|
|
||||||
bool IEcsReadonlyPool.Has(int index)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
void IEcsPool.Del(int entityID)
|
|
||||||
{
|
|
||||||
#if (DEBUG && !DISABLE_DEBUG)
|
|
||||||
throw new NullInstanceException();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
void IEcsPool.AddRaw(int entityID, object dataRaw)
|
|
||||||
{
|
|
||||||
#if (DEBUG && !DISABLE_DEBUG)
|
|
||||||
throw new NullInstanceException();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
object IEcsReadonlyPool.GetRaw(int entityID)
|
|
||||||
{
|
|
||||||
#if (DEBUG && !DISABLE_DEBUG)
|
|
||||||
throw new NullInstanceException();
|
|
||||||
#else
|
|
||||||
return null;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
void IEcsPool.SetRaw(int entity, object dataRaw)
|
|
||||||
{
|
|
||||||
#if (DEBUG && !DISABLE_DEBUG)
|
|
||||||
throw new NullInstanceException();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
void IEcsReadonlyPool.Copy(int fromEntityID, int toEntityID)
|
|
||||||
{
|
|
||||||
#if (DEBUG && !DISABLE_DEBUG)
|
|
||||||
throw new NullInstanceException();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
void IEcsReadonlyPool.Copy(int fromEntityID, EcsWorld toWorld, int toEntityID)
|
|
||||||
{
|
|
||||||
#if (DEBUG && !DISABLE_DEBUG)
|
|
||||||
throw new NullInstanceException();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
void IEcsPool.ClearAll()
|
|
||||||
{
|
|
||||||
#if (DEBUG && !DISABLE_DEBUG)
|
|
||||||
throw new NullInstanceException();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Callbacks
|
|
||||||
void IEcsPoolImplementation.OnInit(EcsWorld world, EcsWorld.PoolsMediator mediator, int componentTypeID) { }
|
|
||||||
void IEcsPoolImplementation.OnWorldDestroy() { }
|
|
||||||
void IEcsPoolImplementation.OnWorldResize(int newSize) { }
|
|
||||||
void IEcsPoolImplementation.OnReleaseDelEntityBuffer(ReadOnlySpan<int> buffer) { }
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Listeners
|
|
||||||
void IEcsReadonlyPool.AddListener(IEcsPoolEventListener listener) { }
|
|
||||||
void IEcsReadonlyPool.RemoveListener(IEcsPoolEventListener listener) { }
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Callbacks Interface
|
#region Callbacks Interface
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
using DCFApixels.DragonECS.PoolsCore;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -6,6 +7,8 @@ using System.Runtime.CompilerServices;
|
|||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
|
/// <summary>Component without data</summary>
|
||||||
|
public interface IEcsTagComponent : IEcsComponentType { }
|
||||||
#if ENABLE_IL2CPP
|
#if ENABLE_IL2CPP
|
||||||
using Unity.IL2CPP.CompilerServices;
|
using Unity.IL2CPP.CompilerServices;
|
||||||
[Il2CppSetOption (Option.NullChecks, false)]
|
[Il2CppSetOption (Option.NullChecks, false)]
|
||||||
@ -255,9 +258,6 @@ namespace DCFApixels.DragonECS
|
|||||||
public static implicit operator EcsTagPool<T>(OptionalMarker a) { return a.GetInstance<EcsTagPool<T>>(); }
|
public static implicit operator EcsTagPool<T>(OptionalMarker a) { return a.GetInstance<EcsTagPool<T>>(); }
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Component without data</summary>
|
|
||||||
public interface IEcsTagComponent { }
|
|
||||||
public static class EcsTagPoolExt
|
public static class EcsTagPoolExt
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
Loading…
Reference in New Issue
Block a user