mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
@@ -2,29 +2,27 @@ using System;
|
||||
|
||||
namespace GlitchyEngine.World
|
||||
{
|
||||
public class ComponentPool
|
||||
public interface IComponentPool
|
||||
{
|
||||
int _objectSize;
|
||||
int _capacity;
|
||||
public void* Get(int index);
|
||||
}
|
||||
|
||||
int PoolSize => _objectSize * _capacity;
|
||||
|
||||
uint8* _rawData ~ delete _;
|
||||
|
||||
public this(int objectSize, int capacity)
|
||||
public class ComponentPool<T> : IComponentPool
|
||||
{
|
||||
_objectSize = objectSize;
|
||||
_capacity = capacity;
|
||||
int PoolSize => sizeof(T) * _data.Count;
|
||||
T[] _data ~ delete _;
|
||||
|
||||
_rawData = new uint8[_capacity * _objectSize]*;
|
||||
public this(int capacity)
|
||||
{
|
||||
_data = new T[capacity];
|
||||
}
|
||||
|
||||
[Inline]
|
||||
public void* Get(int index)
|
||||
{
|
||||
Log.EngineLogger.AssertDebug(index >= 0 && index < _capacity);
|
||||
Log.EngineLogger.AssertDebug(index >= 0 && index < _data.Count);
|
||||
|
||||
return _rawData + index * _objectSize;
|
||||
return &_data[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace GlitchyEngine.World
|
||||
|
||||
typealias DisposeFunction = function void(void* component);
|
||||
|
||||
internal typealias ComponentPoolEntry = (uint32 Id, ComponentPool Pool, DisposeFunction DisposeFunction);
|
||||
internal typealias ComponentPoolEntry = (uint32 Id, IComponentPool Pool, DisposeFunction DisposeFunction);
|
||||
internal Dictionary<Type, ComponentPoolEntry> _componentPools = new .();
|
||||
|
||||
/// A list containing all pools whose components need to be disposed before removal.
|
||||
@@ -47,7 +47,7 @@ namespace GlitchyEngine.World
|
||||
public void Register<T>() where T: struct
|
||||
{
|
||||
uint32 id = (uint32)_componentPools.Count;
|
||||
ComponentPool componentPool = new ComponentPool(sizeof(T), MaxEntities);
|
||||
ComponentPool<T> componentPool = new ComponentPool<T>(MaxEntities);
|
||||
|
||||
_componentPools.Add(typeof(T), (id, componentPool, null));
|
||||
}
|
||||
@@ -58,7 +58,8 @@ namespace GlitchyEngine.World
|
||||
public void Register<T>() where T: struct, IDisposableComponent
|
||||
{
|
||||
uint32 id = (uint32)_componentPools.Count;
|
||||
ComponentPool componentPool = new ComponentPool(sizeof(T), MaxEntities);
|
||||
ComponentPool<T> componentPool = new ComponentPool<T>(MaxEntities);
|
||||
|
||||
DisposeFunction disposeFunction = => T.DisposeComponent;
|
||||
|
||||
_componentPools.Add(typeof(T), (id, componentPool, disposeFunction));
|
||||
|
||||
Reference in New Issue
Block a user