public void Initialize(bool createClientWorld, bool createServerWorld) { var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default); GenerateSystemLists(systems); var world = new World("DefaultWorld"); World.DefaultGameObjectInjectionWorld = world; DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, ExplicitDefaultWorldSystems); var currentPlayerLoop = PlayerLoop.GetCurrentPlayerLoop(); ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(world, ref currentPlayerLoop); PlayerLoop.SetPlayerLoop(currentPlayerLoop); if (createClientWorld) { CreateClientWorld(world, "ClientWorld"); } if (createServerWorld) { CreateServerWorld(world, "ServerWorld"); } EntityWorldManager.Instance.Initialize(); }
private void OnEnable() { var worldNameA = "BuildConfiguration Test World A"; var worldNameB = "BuildConfiguration Test World B"; World.DisposeAllWorlds(); DefaultWorldInitialization.Initialize(worldNameA, !Application.isPlaying); DefaultWorldInitialization.Initialize(worldNameB, !Application.isPlaying); foreach (var world in World.All) { if (worldA == null && world.Name == worldNameA) { worldA = world; } else if (worldB == null && world.Name == worldNameB) { worldB = world; } } OnValidate(); var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); // TODO(DOTS-2283): shouldn't stomp the default player loop here ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(worldA, ref playerLoop); ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(worldB, ref playerLoop); PlayerLoop.SetPlayerLoop(playerLoop); }
public void IsInPlayerLoop_WorldInPlayerLoop_ReturnsTrue() { using (var world = new World("Test World")) { world.CreateSystem <InitializationSystemGroup>(); var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(world, ref playerLoop); Assert.IsTrue(ScriptBehaviourUpdateOrder.IsWorldInPlayerLoop(world, playerLoop)); } }
public void AddToPlayerLoop_AddTwoWorlds_BothAreAdded() { using (var worldA = new World("Test World A")) using (var worldB = new World("Test World B")) { worldA.CreateSystem <InitializationSystemGroup>(); worldB.CreateSystem <InitializationSystemGroup>(); var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(worldA, ref playerLoop); Assert.IsTrue(ScriptBehaviourUpdateOrder.IsWorldInPlayerLoop(worldA, playerLoop)); ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(worldB, ref playerLoop); Assert.IsTrue(ScriptBehaviourUpdateOrder.IsWorldInPlayerLoop(worldA, playerLoop)); Assert.IsTrue(ScriptBehaviourUpdateOrder.IsWorldInPlayerLoop(worldB, playerLoop)); } }
protected override void OnUpdate() { if (Input.GetKeyDown(KeyCode.W)) { var newWorld = new World("TurboWorld"); var playerLoop = PlayerLoop.GetCurrentPlayerLoop(); ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(newWorld, ref playerLoop); var turboManager = newWorld.EntityManager; var newEnt = turboManager.CreateEntity(); turboManager.AddComponent <BravoTag>(newEnt); //var newSys = newWorld.GetOrCreateSystem<TestSystem2>(); newWorld.AddSystem(new TestSystem2()); //newWorld.AddSystem(newSys); } }
public void RemoveFromPlayerLoop_OtherWorldsInPlayerLoop_NotAffected() { using (var worldA = new World("Test World A")) using (var worldB = new World("Test World B")) { worldA.CreateSystem <InitializationSystemGroup>(); worldB.CreateSystem <InitializationSystemGroup>(); var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(worldA, ref playerLoop); ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(worldB, ref playerLoop); Assert.IsTrue(ScriptBehaviourUpdateOrder.IsWorldInPlayerLoop(worldA, playerLoop)); Assert.IsTrue(ScriptBehaviourUpdateOrder.IsWorldInPlayerLoop(worldB, playerLoop)); ScriptBehaviourUpdateOrder.RemoveWorldFromPlayerLoop(worldA, ref playerLoop); Assert.IsFalse(ScriptBehaviourUpdateOrder.IsWorldInPlayerLoop(worldA, playerLoop)); Assert.IsTrue(ScriptBehaviourUpdateOrder.IsWorldInPlayerLoop(worldB, playerLoop)); } }
public void Initialize(ProblemDefinition problemDefinition, string planningSimulationWorldName) { var world = new World(planningSimulationWorldName); var stateManager = world.GetOrCreateSystem <StateManager>(); world.GetOrCreateSystem <SimulationSystemGroup>().AddSystemToUpdateList(stateManager); var playerLoop = UnityEngine.LowLevel.PlayerLoop.GetCurrentPlayerLoop(); ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(world, ref playerLoop); m_StateConverter = new PlannerStateConverter <TraitBasedObject, StateEntityKey, StateData, StateDataContext, StateManager>(problemDefinition, stateManager); m_Scheduler = new PlannerScheduler <StateEntityKey, ActionKey, StateManager, StateData, StateDataContext, ActionScheduler, DefaultCumulativeRewardEstimator, TerminationEvaluator, DestroyStatesJobScheduler>(); m_Scheduler.Initialize(stateManager, new DefaultCumulativeRewardEstimator(), new TerminationEvaluator(), problemDefinition.DiscountFactor); m_Executor = new Match3PlanExecutor(stateManager, m_StateConverter); // Ensure planning jobs are not running when destroying the state manager stateManager.Destroying += () => m_Scheduler.CurrentJobHandle.Complete(); }
public bool Initialize(string defaultWorldName) { Debug.Log("Tiny Hybrid Bootstrap executing"); var world = new World("Default World"); World.DefaultGameObjectInjectionWorld = world; var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default); // filter out the tiny systems systems = systems.Where(s => { var asmName = s.Assembly.FullName; // White list `Unity.Tiny.Rendering`, but not `Unity.Tiny.Rendering.Native` // We need the camera and the world bounds for in editor play mode if (asmName.Contains("Unity.Tiny.Rendering") && !asmName.Contains("Native")) { return(true); } if (asmName.Contains("Unity.Tiny.Animation")) { return(true); } if (asmName.Contains("Unity.Tiny") && !asmName.Contains("Hybrid")) { return(false); } return(true); }).ToList(); DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, systems); var playerLoop = UnityEngine.LowLevel.PlayerLoop.GetDefaultPlayerLoop(); // TODO(DOTS-2283): shouldn't stomp the default player loop here ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(world, ref playerLoop); UnityEngine.LowLevel.PlayerLoop.SetPlayerLoop(playerLoop); return(true); }
public void AddRemoveScriptUpdate() { DefaultWorldInitialization.Initialize("Test World", true); var newWorld = new World("WorldA"); newWorld.CreateSystem <InitializationSystemGroup>(); newWorld.CreateSystem <SimulationSystemGroup>(); newWorld.CreateSystem <PresentationSystemGroup>(); Assert.IsFalse(ScriptBehaviourUpdateOrder.IsWorldInCurrentPlayerLoop(newWorld)); ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(newWorld); Assert.IsTrue(ScriptBehaviourUpdateOrder.IsWorldInCurrentPlayerLoop(newWorld)); PlayerLoop.SetPlayerLoop(PlayerLoop.GetDefaultPlayerLoop()); Assert.IsFalse(ScriptBehaviourUpdateOrder.IsWorldInCurrentPlayerLoop(newWorld)); var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(World.DefaultGameObjectInjectionWorld, ref playerLoop); PlayerLoop.SetPlayerLoop(playerLoop); Assert.IsTrue(ScriptBehaviourUpdateOrder.IsWorldInCurrentPlayerLoop(World.DefaultGameObjectInjectionWorld)); }
public IEnumerator SystemScheduleWindow_CustomWorld() { var world = new World(k_SystemScheduleTestWorld); m_TestSystem1 = world.GetOrCreateSystem <SystemScheduleTestSystem1>(); m_TestSystem2 = world.GetOrCreateSystem <SystemScheduleTestSystem2>(); world.GetOrCreateSystem <SimulationSystemGroup>().AddSystemToUpdateList(m_TestSystem1); world.GetOrCreateSystem <SimulationSystemGroup>().AddSystemToUpdateList(m_TestSystem2); var m_PreviousPlayerLoop = PlayerLoop.GetCurrentPlayerLoop(); var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(world, ref playerLoop); PlayerLoop.SetPlayerLoop(playerLoop); m_SystemScheduleWindow.SelectedWorld = world; m_SystemScheduleWindow.BaseState.SelectedWorldName = k_SystemScheduleTestWorld; Assert.That(m_SystemScheduleWindow.SelectedWorld.Name, Is.EqualTo(k_SystemScheduleTestWorld)); yield return(new SystemScheduleTestUtilities.UpdateSystemGraph(typeof(SystemScheduleTestSystem1))); Assert.That(m_SystemScheduleWindow.rootVisualElement.Q <SystemTreeView>().CheckIfTreeViewContainsGivenSystemType(typeof(SystemScheduleTestSystem1)), Is.True); world.Dispose(); m_SystemScheduleWindow.Update(); Assert.That(m_SystemScheduleWindow.SelectedWorld.Name, Is.EqualTo(k_SystemScheduleEditorWorld)); if (world != null && world.IsCreated) { world.Dispose(); } PlayerLoop.SetPlayerLoop(m_PreviousPlayerLoop); }