Proper Entity and Component bucketing/tracking

This commit is contained in:
Matt Thorson
2020-05-21 21:24:04 -07:00
parent df00a1ec82
commit 0b1a938fe2
6 changed files with 180 additions and 14 deletions

View File

@ -53,5 +53,13 @@ namespace Strawberry
v.ToString(string);
Debug.WriteLine(string);
}
[Inline]
static public void Log(delegate void(String) del)
{
String string = scope String();
del(string);
Debug.WriteLine(string);
}
}
}

61
src/Static/TypeTree.bf Normal file
View File

@ -0,0 +1,61 @@
using System.Collections;
using System;
namespace Strawberry
{
static public class TypeTree
{
static private Dictionary<Type, List<Type>> EntityAssignableLists;
static private Dictionary<Type, List<Type>> ComponentAssignableLists;
static private void Build()
{
/*
For each Type that extends Entity, we build a list of all the other Entity Types that it is assignable to.
We cache these lists, and use them later to bucket Entities as they are added to the Scene.
This allows us to retrieve Entities by type very easily.
*/
EntityAssignableLists = new Dictionary<Type, List<Type>>();
for (let type in Type.Enumerator())
{
if (type != typeof(Entity) && type.IsSubtypeOf(typeof(Entity)))
{
let list = new List<Type>();
for (let check in Type.Enumerator())
if (check != typeof(Entity) && check.IsSubtypeOf(typeof(Entity)) && type.IsSubtypeOf(check))
list.Add(check);
EntityAssignableLists.Add(type, list);
}
}
/*
And then we also do this for components
*/
ComponentAssignableLists = new Dictionary<Type, List<Type>>();
for (let type in Type.Enumerator())
{
if (type != typeof(Component) && type.IsSubtypeOf(typeof(Component)))
{
let list = new List<Type>();
for (let check in Type.Enumerator())
if (check != typeof(Component) && check.IsSubtypeOf(typeof(Component)) && type.IsSubtypeOf(check))
list.Add(check);
ComponentAssignableLists.Add(type, list);
}
}
}
static private void Dispose()
{
for (let list in EntityAssignableLists.Values)
delete list;
delete EntityAssignableLists;
for (let list in ComponentAssignableLists.Values)
delete list;
delete ComponentAssignableLists;
}
}
}