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
|
namespace GlitchyEngine.World
|
||||||
{
|
{
|
||||||
public class ComponentPool
|
public interface IComponentPool
|
||||||
{
|
{
|
||||||
int _objectSize;
|
public void* Get(int index);
|
||||||
int _capacity;
|
}
|
||||||
|
|
||||||
int PoolSize => _objectSize * _capacity;
|
public class ComponentPool<T> : IComponentPool
|
||||||
|
{
|
||||||
|
int PoolSize => sizeof(T) * _data.Count;
|
||||||
|
T[] _data ~ delete _;
|
||||||
|
|
||||||
uint8* _rawData ~ delete _;
|
public this(int capacity)
|
||||||
|
|
||||||
public this(int objectSize, int capacity)
|
|
||||||
{
|
{
|
||||||
_objectSize = objectSize;
|
_data = new T[capacity];
|
||||||
_capacity = capacity;
|
|
||||||
|
|
||||||
_rawData = new uint8[_capacity * _objectSize]*;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Inline]
|
[Inline]
|
||||||
public void* Get(int index)
|
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);
|
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 .();
|
internal Dictionary<Type, ComponentPoolEntry> _componentPools = new .();
|
||||||
|
|
||||||
/// A list containing all pools whose components need to be disposed before removal.
|
/// 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
|
public void Register<T>() where T: struct
|
||||||
{
|
{
|
||||||
uint32 id = (uint32)_componentPools.Count;
|
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));
|
_componentPools.Add(typeof(T), (id, componentPool, null));
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,8 @@ namespace GlitchyEngine.World
|
|||||||
public void Register<T>() where T: struct, IDisposableComponent
|
public void Register<T>() where T: struct, IDisposableComponent
|
||||||
{
|
{
|
||||||
uint32 id = (uint32)_componentPools.Count;
|
uint32 id = (uint32)_componentPools.Count;
|
||||||
ComponentPool componentPool = new ComponentPool(sizeof(T), MaxEntities);
|
ComponentPool<T> componentPool = new ComponentPool<T>(MaxEntities);
|
||||||
|
|
||||||
DisposeFunction disposeFunction = => T.DisposeComponent;
|
DisposeFunction disposeFunction = => T.DisposeComponent;
|
||||||
|
|
||||||
_componentPools.Add(typeof(T), (id, componentPool, disposeFunction));
|
_componentPools.Add(typeof(T), (id, componentPool, disposeFunction));
|
||||||
|
|||||||
Reference in New Issue
Block a user