/// <summary> /// Initialize the ComponentSystems. See <see cref="Initialize"/> for use. /// </summary> public static void InitializeSystems(World world) { var allSystemTypes = TypeManager.GetSystems(); var allSystemNames = TypeManager.SystemNames; if (allSystemTypes.Length == 0) { throw new InvalidOperationException("DefaultTinyWorldInitialization: No Systems found."); } // Create top level presentation system and simulation systems. InitializationSystemGroup initializationSystemGroup = new InitializationSystemGroup(); world.AddSystem(initializationSystemGroup); SimulationSystemGroup simulationSystemGroup = new SimulationSystemGroup(); world.AddSystem(simulationSystemGroup); PresentationSystemGroup presentationSystemGroup = new PresentationSystemGroup(); world.AddSystem(presentationSystemGroup); // Create the working set of systems. #if WRITE_LOG Console.WriteLine("--- Adding systems:"); #endif for (int i = 0; i < allSystemTypes.Length; i++) { if (TypeManager.GetSystemAttributes(allSystemTypes[i], typeof(DisableAutoCreationAttribute)).Length > 0) { continue; } if (allSystemTypes[i] == initializationSystemGroup.GetType() || allSystemTypes[i] == simulationSystemGroup.GetType() || allSystemTypes[i] == presentationSystemGroup.GetType()) { continue; } // Subtle issue. If the System was created by GetOrCreateSystem at the "right" time // before its own initialization, then it will exist. GetExistingSystem will return a valid // object. BUT, that object will not have been put into a SystemGroup. var sys = world.GetExistingSystem(allSystemTypes[i]); if (sys != null) { AddSystemToGroup(world, sys); continue; } #if WRITE_LOG Console.WriteLine(allSystemNames[i]); #endif AddSystem(world, TypeManager.ConstructSystem(allSystemTypes[i])); } }
public static void InitializeSystems(World world) { var allSystemTypes = TypeManager.GetSystems(); var allSystemNames = TypeManager.SystemNames; if (allSystemTypes.Length == 0) { throw new InvalidOperationException("DefaultTinyWorldInitialization: No Systems found."); } // Create top level presentation system and simulation systems. InitializationSystemGroup initializationSystemGroup = new InitializationSystemGroup(); world.AddSystem(initializationSystemGroup); SimulationSystemGroup simulationSystemGroup = new SimulationSystemGroup(); world.AddSystem(simulationSystemGroup); PresentationSystemGroup presentationSystemGroup = new PresentationSystemGroup(); world.AddSystem(presentationSystemGroup); // Create the working set of systems. #if WRITE_LOG Console.WriteLine("--- Adding systems:"); #endif for (int i = 0; i < allSystemTypes.Length; i++) { if (TypeManager.GetSystemAttributes(allSystemTypes[i], typeof(DisableAutoCreationAttribute)).Length > 0) { continue; } if (allSystemTypes[i] == initializationSystemGroup.GetType() || allSystemTypes[i] == simulationSystemGroup.GetType() || allSystemTypes[i] == presentationSystemGroup.GetType()) { continue; } if (world.GetExistingSystem(allSystemTypes[i]) != null) { continue; } #if WRITE_LOG Console.WriteLine(allSystemNames[i]); #endif AddSystem(world, TypeManager.ConstructSystem(allSystemTypes[i])); } }
static void IterateAllAutoSystems(World world, Action <World, Type> Action) { InitializationSystemGroup initializationSystemGroup = world.GetExistingSystem <InitializationSystemGroup>(); SimulationSystemGroup simulationSystemGroup = world.GetExistingSystem <SimulationSystemGroup>(); PresentationSystemGroup presentationSystemGroup = world.GetExistingSystem <PresentationSystemGroup>(); foreach (var systemType in TypeManager.GetSystems()) { if (TypeManager.GetSystemAttributes(systemType, typeof(DisableAutoCreationAttribute)).Length > 0) { continue; } if (systemType == initializationSystemGroup.GetType() || systemType == simulationSystemGroup.GetType() || systemType == presentationSystemGroup.GetType()) { continue; } Action(world, systemType); } }
public static void InitializeSystems(World world) { var allSystemTypes = TypeManager.GetSystems(); var allSystemNames = TypeManager.SystemNames; if (allSystemTypes.Length == 0) { throw new InvalidOperationException("DefaultTinyWorldInitialization: No Systems found."); } // Create top level presentation system and simulation systems. InitializationSystemGroup initializationSystemGroup = new InitializationSystemGroup(); world.AddManager(initializationSystemGroup); SimulationSystemGroup simulationSystemGroup = new SimulationSystemGroup(); world.AddManager(simulationSystemGroup); PresentationSystemGroup presentationSystemGroup = new PresentationSystemGroup(); world.AddManager(presentationSystemGroup); // Create the working set of systems. int nSystems = 0; Type[] systemTypes = new Type[allSystemTypes.Length]; ComponentSystem[] systems = new ComponentSystem[allSystemTypes.Length]; #if WRITE_LOG Console.WriteLine("--- Adding systems:"); #endif for (int i = 0; i < allSystemTypes.Length; i++) { if (TypeManager.GetSystemAttributes(allSystemTypes[i], typeof(DisableAutoCreationAttribute)).Length > 0) { continue; } if (allSystemTypes[i] == initializationSystemGroup.GetType() || allSystemTypes[i] == simulationSystemGroup.GetType() || allSystemTypes[i] == presentationSystemGroup.GetType()) { continue; } if (world.GetExistingManager(allSystemTypes[i]) != null) { continue; } #if WRITE_LOG Console.WriteLine(allSystemNames[i]); #endif systemTypes[nSystems] = allSystemTypes[i]; systems[nSystems] = TypeManager.ConstructSystem(allSystemTypes[i]); world.AddManager(systems[nSystems]); nSystems++; } #if WRITE_LOG Console.WriteLine("--- Adding systems Done."); #endif for (int i = 0; i < nSystems; ++i) { var sysType = systemTypes[i]; var system = systems[i]; var groups = TypeManager.GetSystemAttributes(sysType, typeof(UpdateInGroupAttribute)); if (groups.Length == 0) { simulationSystemGroup.AddSystemToUpdateList(system); } for (int g = 0; g < groups.Length; ++g) { var groupType = groups[g] as UpdateInGroupAttribute; var groupSystem = world.GetExistingManager(groupType.GroupType) as ComponentSystemGroup; if (groupSystem == null) { throw new Exception("DefaultTinyWorldInitialization failed to find existing SystemGroup."); } groupSystem.AddSystemToUpdateList(system); } } }