/// <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])); } }
public void Update() { InitializationSystemGroup initializationSystemGroup = GetExistingSystem(typeof(InitializationSystemGroup)) as InitializationSystemGroup; SimulationSystemGroup simulationSystemGroup = GetExistingSystem(typeof(SimulationSystemGroup)) as SimulationSystemGroup; PresentationSystemGroup presentationSystemGroup = GetExistingSystem(typeof(PresentationSystemGroup)) as PresentationSystemGroup; initializationSystemGroup?.Update(); simulationSystemGroup?.Update(); presentationSystemGroup?.Update(); }
public void Update() { InitializationSystemGroup initializationSystemGroup = GetExistingSystem(typeof(InitializationSystemGroup)) as InitializationSystemGroup; SimulationSystemGroup simulationSystemGroup = GetExistingSystem(typeof(SimulationSystemGroup)) as SimulationSystemGroup; PresentationSystemGroup presentationSystemGroup = GetExistingSystem(typeof(PresentationSystemGroup)) as PresentationSystemGroup; initializationSystemGroup?.Update(); simulationSystemGroup?.Update(); presentationSystemGroup?.Update(); Assert.IsTrue(EntityManager.GetBuffer <WorldTimeQueue>(TimeSingleton).Length == 0, "PushTimeData without matching PopTimedata"); }
/// <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)); }); }
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 Initialize(string worldName, bool editorWorld) { // Register hybrid injection hooks #pragma warning disable 0618 InjectionHookSupport.RegisterHook(new GameObjectArrayInjectionHook()); InjectionHookSupport.RegisterHook(new TransformAccessArrayInjectionHook()); InjectionHookSupport.RegisterHook(new ComponentArrayInjectionHook()); #pragma warning restore 0618 PlayerLoopManager.RegisterDomainUnload(DomainUnloadShutdown, 10000); var world = new World(worldName); World.Active = world; var systems = GetAllSystems(WorldSystemFilterFlags.Default); if (systems == null) { world.Dispose(); if (World.Active == world) { World.Active = null; } return; } // create presentation system and simulation system InitializationSystemGroup initializationSystemGroup = world.GetOrCreateManager <InitializationSystemGroup>(); SimulationSystemGroup simulationSystemGroup = world.GetOrCreateManager <SimulationSystemGroup>(); PresentationSystemGroup presentationSystemGroup = world.GetOrCreateManager <PresentationSystemGroup>(); // Add systems to their groups, based on the [UpdateInGroup] attribute. foreach (var type in systems) { // Skip the built-in root-level systems if (type == typeof(InitializationSystemGroup) || type == typeof(SimulationSystemGroup) || type == typeof(PresentationSystemGroup)) { continue; } if (editorWorld) { if (Attribute.IsDefined(type, typeof(ExecuteInEditMode))) { Debug.LogError( $"{type} is decorated with {typeof(ExecuteInEditMode)}. Support for this attribute will be deprecated. Please use {typeof(ExecuteAlways)} instead."); } if (!Attribute.IsDefined(type, typeof(ExecuteAlways))) { continue; } } var groups = type.GetCustomAttributes(typeof(UpdateInGroupAttribute), true); if (groups.Length == 0) { simulationSystemGroup.AddSystemToUpdateList(GetOrCreateManagerAndLogException(world, type) as ComponentSystemBase); } foreach (var g in groups) { var group = g as UpdateInGroupAttribute; if (group == null) { continue; } if (!(typeof(ComponentSystemGroup)).IsAssignableFrom(group.GroupType)) { Debug.LogError($"Invalid [UpdateInGroup] attribute for {type}: {group.GroupType} must be derived from ComponentSystemGroup."); continue; } var groupMgr = GetOrCreateManagerAndLogException(world, group.GroupType); if (groupMgr == null) { Debug.LogWarning( $"Skipping creation of {type} due to errors creating the group {group.GroupType}. Fix these errors before continuing."); continue; } var groupSys = groupMgr as ComponentSystemGroup; if (groupSys != null) { groupSys.AddSystemToUpdateList(GetOrCreateManagerAndLogException(world, type) as ComponentSystemBase); } } } // Update player loop initializationSystemGroup.SortSystemUpdateList(); simulationSystemGroup.SortSystemUpdateList(); presentationSystemGroup.SortSystemUpdateList(); ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world); }
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); } } }
private static Unity.Entities.World GetOrCreateWorld() { if (Unity.Entities.World.DefaultGameObjectInjectionWorld != null && Unity.Entities.World.DefaultGameObjectInjectionWorld.Name == "KodeboldsWorld") { return(Unity.Entities.World.DefaultGameObjectInjectionWorld); } Unity.Entities.World world = new Unity.Entities.World("KodeboldsWorld"); Unity.Entities.World.DefaultGameObjectInjectionWorld = world; //INITIALISATION Unity.Entities.InitializationSystemGroup initSystemGroup = world.GetOrCreateSystem <Unity.Entities.InitializationSystemGroup>(); initSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Entities.BeginInitializationEntityCommandBufferSystem>()); initSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Entities.ConvertToEntitySystem>()); initSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <CameraSyncSystem>()); initSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <InputManagementSystem>()); initSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <InstantiationSystem>()); initSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <SpawningSystem>()); initSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Entities.RetainBlobAssetSystem>()); initSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Entities.UpdateWorldTimeSystem>()); { Unity.Scenes.SceneSystemGroup sceneSystemGroup = world.GetOrCreateSystem <Unity.Scenes.SceneSystemGroup>(); initSystemGroup.AddSystemToUpdateList(sceneSystemGroup); sceneSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Scenes.SceneSystem>()); sceneSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Scenes.ResolveSceneReferenceSystem>()); sceneSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Scenes.SceneSectionStreamingSystem>()); } initSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Transforms.CopyInitialTransformFromGameObjectSystem>()); //Must run after CopyInitialTransformFromGameObjectSystem. initSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <FreezeRotationSystem>()); initSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Entities.EndInitializationEntityCommandBufferSystem>()); //SIMULATION Unity.Entities.SimulationSystemGroup simSystemGroup = world.GetOrCreateSystem <Unity.Entities.SimulationSystemGroup>(); simSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Entities.BeginSimulationEntityCommandBufferSystem>()); //simSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem<DebugStream>()); //Unity system, they just didn't put it in a namespace hurr durr. simSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Physics.Systems.BuildPhysicsWorld>()); simSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Physics.Authoring.DisplayJointsSystem>()); simSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Physics.Systems.StepPhysicsWorld>()); simSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Physics.Systems.ExportPhysicsWorld>()); simSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Physics.Authoring.DisplayContactsSystem>()); simSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Physics.Authoring.DisplayBroadphaseAabbsSystem>()); simSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Physics.Authoring.DisplayColliderAabbsSystem>()); simSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Physics.Authoring.DisplayBodyColliders>()); simSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Physics.Authoring.DisplayCollisionEventsSystem>()); simSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Physics.Authoring.DisplayContactsSystem>()); simSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Physics.Authoring.DisplayMassPropertiesSystem>()); simSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Physics.Authoring.DisplayTriggerEventsSystem>()); simSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Physics.Systems.EndFramePhysicsSystem>()); { PostPhysicsSystemsGroup postPhysicsSystemsGroup = world.GetOrCreateSystem <PostPhysicsSystemsGroup>(); simSystemGroup.AddSystemToUpdateList(postPhysicsSystemsGroup); postPhysicsSystemsGroup.AddSystemToUpdateList(world.GetOrCreateSystem <RaycastSystem>()); postPhysicsSystemsGroup.AddSystemToUpdateList(world.GetOrCreateSystem <SpawningQueueSystem>()); postPhysicsSystemsGroup.AddSystemToUpdateList(world.GetOrCreateSystem <SelectionSystem>()); postPhysicsSystemsGroup.AddSystemToUpdateList(world.GetOrCreateSystem <CameraControlSystem>()); postPhysicsSystemsGroup.AddSystemToUpdateList(world.GetOrCreateSystem <HarvestingSystem>()); postPhysicsSystemsGroup.AddSystemToUpdateList(world.GetOrCreateSystem <DepositSystem>()); postPhysicsSystemsGroup.AddSystemToUpdateList(world.GetOrCreateSystem <UnitMoveSystem>()); } { //These systems must be updated after all the game logic systems as state transitions add/remove components via an entity command buffer, meaning the command status data //will be out of sync with the state components until the next sync point (command buffer system). //We do this step at the end to avoid an additional sync point that would halt the main thread. CommandStateProcessingSystemsGroup commandStateProcessingSystemsGroup = world.GetOrCreateSystem <CommandStateProcessingSystemsGroup>(); simSystemGroup.AddSystemToUpdateList(commandStateProcessingSystemsGroup); commandStateProcessingSystemsGroup.AddSystemToUpdateList(world.GetOrCreateSystem <FindAITargetSystem>()); commandStateProcessingSystemsGroup.AddSystemToUpdateList(world.GetOrCreateSystem <CommandProcessSystem>()); commandStateProcessingSystemsGroup.AddSystemToUpdateList(world.GetOrCreateSystem <StateTransitionSystem>()); } { Unity.Transforms.TransformSystemGroup transformSystemGroup = world.GetOrCreateSystem <Unity.Transforms.TransformSystemGroup>(); simSystemGroup.AddSystemToUpdateList(transformSystemGroup); transformSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Transforms.CopyTransformFromGameObjectSystem>()); transformSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Transforms.EndFrameCompositeScaleSystem>()); transformSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Transforms.EndFrameParentSystem>()); transformSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Transforms.EndFramePostRotationEulerSystem>()); transformSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Transforms.EndFrameRotationEulerSystem>()); transformSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Transforms.EndFrameCompositeRotationSystem>()); transformSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Transforms.EndFrameParentScaleInverseSystem>()); transformSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Transforms.EndFrameTRSToLocalToParentSystem>()); transformSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Transforms.EndFrameTRSToLocalToWorldSystem>()); transformSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Transforms.EndFrameLocalToParentSystem>()); transformSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Transforms.CopyTransformToGameObjectSystem>()); transformSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Transforms.EndFrameWorldToLocalSystem>()); } { BehaviourUpdaterSystemsGroup behaviourUpdaterSystemsGroup = world.GetOrCreateSystem <BehaviourUpdaterSystemsGroup>(); simSystemGroup.AddSystemToUpdateList(behaviourUpdaterSystemsGroup); m_behaviourUpdaterSystem = world.GetOrCreateSystem <BehaviourUpdaterSystem>(); behaviourUpdaterSystemsGroup.AddSystemToUpdateList(m_behaviourUpdaterSystem); } simSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Entities.EndSimulationEntityCommandBufferSystem>()); //PRESENTATION Unity.Entities.PresentationSystemGroup presentationSystemGroup = world.GetOrCreateSystem <Unity.Entities.PresentationSystemGroup>(); presentationSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Entities.BeginPresentationEntityCommandBufferSystem>()); { Unity.Rendering.StructuralChangePresentationSystemGroup structuralChangePresentationSystemGroup = world.GetOrCreateSystem <Unity.Rendering.StructuralChangePresentationSystemGroup>(); presentationSystemGroup.AddSystemToUpdateList(structuralChangePresentationSystemGroup); structuralChangePresentationSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Rendering.AddWorldAndChunkRenderBounds>()); structuralChangePresentationSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Rendering.AddLodRequirementComponents>()); } { Unity.Rendering.UpdatePresentationSystemGroup updatePresentationSystemGroup = world.GetOrCreateSystem <Unity.Rendering.UpdatePresentationSystemGroup>(); presentationSystemGroup.AddSystemToUpdateList(updatePresentationSystemGroup); updatePresentationSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Rendering.RenderBoundsUpdateSystem>()); updatePresentationSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Rendering.LodRequirementsUpdateSystem>()); } presentationSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <Unity.Rendering.RenderMeshSystemV2>()); presentationSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem <EndFrameJobCompleteSystem>()); Unity.Entities.ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world); return(world); }