register and preload component types via reflection in worldbuilder
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
4a962bac3c
commit
1c3c6c6b69
|
@ -36,7 +36,7 @@ namespace Encompass
|
||||||
|
|
||||||
private readonly HashSet<Engine> senders = new HashSet<Engine>();
|
private readonly HashSet<Engine> senders = new HashSet<Engine>();
|
||||||
|
|
||||||
private readonly HashSet<Type> componentTypesToRegister = new HashSet<Type>();
|
private readonly HashSet<Type> componentTypesToPreload = new HashSet<Type>();
|
||||||
|
|
||||||
private readonly HashSet<Type> messageTypes = new HashSet<Type>();
|
private readonly HashSet<Type> messageTypes = new HashSet<Type>();
|
||||||
|
|
||||||
|
@ -87,8 +87,6 @@ namespace Encompass
|
||||||
public void SetComponent<TComponent>(Entity entity, TComponent component) where TComponent : struct, IComponent
|
public void SetComponent<TComponent>(Entity entity, TComponent component) where TComponent : struct, IComponent
|
||||||
{
|
{
|
||||||
RegisterComponentType<TComponent>();
|
RegisterComponentType<TComponent>();
|
||||||
componentTypesToRegister.Add(typeof(TComponent));
|
|
||||||
|
|
||||||
startingExistingComponentStore.Set(entity.ID, component);
|
startingExistingComponentStore.Set(entity.ID, component);
|
||||||
startingUpToDateComponentStore.Set(entity.ID, component);
|
startingUpToDateComponentStore.Set(entity.ID, component);
|
||||||
|
|
||||||
|
@ -104,6 +102,7 @@ namespace Encompass
|
||||||
if (!typeToIndex.ContainsKey(typeof(TComponent)))
|
if (!typeToIndex.ContainsKey(typeof(TComponent)))
|
||||||
{
|
{
|
||||||
typeToIndex.Add(typeof(TComponent), typeToIndex.Count);
|
typeToIndex.Add(typeof(TComponent), typeToIndex.Count);
|
||||||
|
componentTypesToPreload.Add(typeof(TComponent));
|
||||||
componentManager.RegisterComponentType<TComponent>();
|
componentManager.RegisterComponentType<TComponent>();
|
||||||
startingExistingComponentStore.RegisterComponentType<TComponent>();
|
startingExistingComponentStore.RegisterComponentType<TComponent>();
|
||||||
startingUpToDateComponentStore.RegisterComponentType<TComponent>();
|
startingUpToDateComponentStore.RegisterComponentType<TComponent>();
|
||||||
|
@ -115,11 +114,6 @@ namespace Encompass
|
||||||
messageTypes.UnionWith(types);
|
messageTypes.UnionWith(types);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void AddComponentTypeToRegister(Type componentType)
|
|
||||||
{
|
|
||||||
componentTypesToRegister.Add(componentType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds the specified Engine to the World.
|
/// Adds the specified Engine to the World.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -164,11 +158,6 @@ namespace Encompass
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var componentType in engine.readTypes.Union(engine.writeTypes).Union(engine.readImmediateTypes))
|
|
||||||
{
|
|
||||||
AddComponentTypeToRegister(componentType);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var receiveType in engine.receiveTypes.Union(engine.readImmediateTypes))
|
foreach (var receiveType in engine.receiveTypes.Union(engine.readImmediateTypes))
|
||||||
{
|
{
|
||||||
if (!typeToReaders.ContainsKey(receiveType))
|
if (!typeToReaders.ContainsKey(receiveType))
|
||||||
|
@ -197,7 +186,6 @@ namespace Encompass
|
||||||
public OrderedRenderer<TComponent> AddOrderedRenderer<TComponent>(OrderedRenderer<TComponent> renderer) where TComponent : struct, IComponent, IDrawableComponent
|
public OrderedRenderer<TComponent> AddOrderedRenderer<TComponent>(OrderedRenderer<TComponent> renderer) where TComponent : struct, IComponent, IDrawableComponent
|
||||||
{
|
{
|
||||||
RegisterComponentType<TComponent>();
|
RegisterComponentType<TComponent>();
|
||||||
componentTypesToRegister.Add(typeof(TComponent));
|
|
||||||
renderer.AssignEntityManager(entityManager);
|
renderer.AssignEntityManager(entityManager);
|
||||||
renderer.AssignComponentManager(componentManager);
|
renderer.AssignComponentManager(componentManager);
|
||||||
renderManager.RegisterOrderedRenderer<TComponent>(renderer.InternalRender);
|
renderManager.RegisterOrderedRenderer<TComponent>(renderer.InternalRender);
|
||||||
|
@ -366,16 +354,23 @@ namespace Encompass
|
||||||
throw new EngineWriteConflictException(errorString);
|
throw new EngineWriteConflictException(errorString);
|
||||||
}
|
}
|
||||||
|
|
||||||
var engineOrder = new List<Engine>();
|
// doing reflection to grab all component types, because not all writes need to be declared
|
||||||
|
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||||
foreach (var registeredComponentType in componentTypesToRegister)
|
{
|
||||||
|
foreach (var componentType in assembly.GetTypes())
|
||||||
|
{
|
||||||
|
if (typeof(IComponent).IsAssignableFrom(componentType) && componentType.IsValueType && !componentType.IsEnum && !componentType.IsPrimitive)
|
||||||
{
|
{
|
||||||
var method = typeof(WorldBuilder).GetMethod("RegisterComponentType", BindingFlags.NonPublic | BindingFlags.Instance);
|
var method = typeof(WorldBuilder).GetMethod("RegisterComponentType", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
var generic = method.MakeGenericMethod(registeredComponentType);
|
var generic = method.MakeGenericMethod(componentType);
|
||||||
generic.Invoke(this, null);
|
generic.Invoke(this, null);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PreloadJIT(componentTypesToRegister, messageTypes);
|
PreloadJIT(componentTypesToPreload, messageTypes);
|
||||||
|
|
||||||
|
var engineOrder = new List<Engine>();
|
||||||
|
|
||||||
foreach (var engine in engineGraph.TopologicalSort())
|
foreach (var engine in engineGraph.TopologicalSort())
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue