32 lines
847 B
C#
32 lines
847 B
C#
using System.Collections.Generic;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace MoonTools.ECS
|
|
{
|
|
// for saving and loading component storage
|
|
public class ComponentStorageState
|
|
{
|
|
public int Count;
|
|
public Dictionary<int, int> EntityIdToStorageIndex;
|
|
public byte[] EntityIDs;
|
|
public byte[] Components;
|
|
|
|
public static ComponentStorageState Create<TComponent>(int count)
|
|
{
|
|
return new ComponentStorageState(
|
|
count,
|
|
count * Marshal.SizeOf<int>(),
|
|
count * Marshal.SizeOf<TComponent>()
|
|
);
|
|
}
|
|
|
|
private ComponentStorageState(int count, int entityIDSize, int componentSize)
|
|
{
|
|
Count = count;
|
|
EntityIdToStorageIndex = new Dictionary<int, int>(count);
|
|
EntityIDs = new byte[entityIDSize];
|
|
Components = new byte[componentSize];
|
|
}
|
|
}
|
|
}
|