fix erroneous engine cycle detection

pull/5/head
Evan Hemsley 2019-12-05 23:16:47 -08:00
parent ba286f337c
commit f0ef0fbb21
1 changed files with 10 additions and 6 deletions

View File

@ -91,7 +91,6 @@ namespace Encompass
internal void RegisterComponent(Type componentType) internal void RegisterComponent(Type componentType)
{ {
registeredComponentTypes.Add(componentType); registeredComponentTypes.Add(componentType);
AddEngine((Engine)Activator.CreateInstance(typeof(ComponentEmitter<>).MakeGenericType(componentType)));
} }
/// <summary> /// <summary>
@ -133,14 +132,11 @@ namespace Encompass
} }
foreach (var componentType in engine.readTypes.Union(engine.writeTypes)) foreach (var componentType in engine.readTypes.Union(engine.writeTypes))
{
if (!registeredComponentTypes.Contains(componentType))
{ {
RegisterComponent(componentType); RegisterComponent(componentType);
} }
}
foreach (var receiveType in engine.receiveTypes.Union(engine.readPendingTypes).Union(engine.readTypes)) foreach (var receiveType in engine.receiveTypes.Union(engine.readPendingTypes))
{ {
if (!typeToReaders.ContainsKey(receiveType)) if (!typeToReaders.ContainsKey(receiveType))
{ {
@ -327,6 +323,14 @@ namespace Encompass
} }
var engineOrder = new List<Engine>(); var engineOrder = new List<Engine>();
foreach (var registeredComponentType in registeredComponentTypes)
{
var emitterEngine = (Engine)Activator.CreateInstance(typeof(ComponentEmitter<>).MakeGenericType(registeredComponentType));
AddEngine(emitterEngine);
engineOrder.Add(emitterEngine);
}
foreach (var engine in engineGraph.TopologicalSort()) foreach (var engine in engineGraph.TopologicalSort())
{ {
engineOrder.Add(engine); engineOrder.Add(engine);