/// <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])); } }
/// <summary> /// Call this to add a System that was manually constructed; normally these /// Systems are marked with [DisableAutoCreation] /// </summary> public static void AddSystem(World world, ComponentSystemBase[] systems) { foreach (ComponentSystemBase system in systems) { if (world.GetExistingSystem(system.GetType()) != null) { throw new ArgumentException("AddAndSortSystem: Error to add a duplicate system."); } world.AddSystem(system); var groups = TypeManager.GetSystemAttributes(system.GetType(), typeof(UpdateInGroupAttribute)); if (groups.Length == 0) { var simulationSystemGroup = world.GetExistingSystem <SimulationSystemGroup>(); simulationSystemGroup.AddSystemToUpdateList(system); } for (int g = 0; g < groups.Length; ++g) { var groupType = groups[g] as UpdateInGroupAttribute; var groupSystem = world.GetExistingSystem(groupType.GroupType) as ComponentSystemGroup; if (groupSystem == null) { throw new Exception("AddAndSortSystem failed to find existing SystemGroup."); } groupSystem.AddSystemToUpdateList(system); } } }
/// <summary> /// Call this to add a System that was manually constructed; normally these /// Systems are marked with [DisableAutoCreation]. /// </summary> public static void AddSystem(World world, ComponentSystemBase system) { if (world.GetExistingSystem(system.GetType()) != null) { throw new ArgumentException("AddSystem: Error to add a duplicate system."); } world.AddSystem(system); AddSystemToGroup(world, system); }
/// <summary> /// Initialize the ComponentSystems. See <see cref="Initialize"/> for use. /// </summary> public static void InitializeSystems(World world) { var allSystemTypes = TypeManager.GetSystems(); 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. // The full set of Systems must be created (and initialized with the World) before // they can be placed into SystemGroup. Else you get the problem that a System may // be put into a SystemGroup that hasn't been created. IterateAllAutoSystems(world, (World w, Type systemType) => { // Need the if check because game/test code may have auto-constructed a System already. if (world.GetExistingSystem(systemType) == null) { AddSystem(world, TypeManager.ConstructSystem(systemType), false); } }); IterateAllAutoSystems(world, (World w, Type systemType) => { AddSystemToGroup(world, world.GetExistingSystem(systemType)); }); }
internal static World CreateConversionWorld(GameObjectConversionSettings settings) { using (s_CreateConversionWorld.Auto()) { var gameObjectWorld = new World($"GameObject -> Entity Conversion '{settings.DebugConversionName}'", WorldFlags.Live | WorldFlags.Conversion | WorldFlags.Staging); gameObjectWorld.AddSystem(new GameObjectConversionMappingSystem(settings)); var systemTypes = settings.Systems ?? DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.GameObjectConversion); var includeExport = settings.GetType() != typeof(GameObjectConversionSettings); AddConversionSystems(gameObjectWorld, systemTypes.Concat(settings.ExtraSystems), includeExport); settings.ConversionWorldCreated?.Invoke(gameObjectWorld); return(gameObjectWorld); } }
internal static World CreateConversionWorld(GameObjectConversionSettings settings, Scene scene = default) { using (s_CreateConversionWorld.Auto()) { var gameObjectWorld = new World($"GameObject -> Entity Conversion '{settings.DebugConversionName}'", WorldFlags.Live | WorldFlags.Conversion | WorldFlags.Staging); var mappingSystem = new GameObjectConversionMappingSystem(settings); gameObjectWorld.AddSystem(mappingSystem); if (mappingSystem.IsLiveLink) { mappingSystem.PrepareForLiveLink(scene); } var systemTypes = settings.Systems ?? DefaultWorldInitialization.GetAllSystems(settings.FilterFlags); var includeExport = settings.SupportsExporting; AddConversionSystems(gameObjectWorld, systemTypes.Concat(settings.ExtraSystems), includeExport, mappingSystem.IsLiveLink); settings.ConversionWorldCreated?.Invoke(gameObjectWorld); return(gameObjectWorld); } }
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. 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.GetExistingSystem(allSystemTypes[i]) != null) { continue; } #if WRITE_LOG Console.WriteLine(allSystemNames[i]); #endif systemTypes[nSystems] = allSystemTypes[i]; systems[nSystems] = TypeManager.ConstructSystem(allSystemTypes[i]); world.AddSystem(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.GetExistingSystem(groupType.GroupType) as ComponentSystemGroup; if (groupSystem == null) { throw new Exception("DefaultTinyWorldInitialization failed to find existing SystemGroup."); } groupSystem.AddSystemToUpdateList(system); } } }