public bool Initialize(string defaultWorldName) { var world = new LatiosWorld(defaultWorldName); World.DefaultGameObjectInjectionWorld = world; var initializationSystemGroup = world.GetExistingSystem <InitializationSystemGroup>(); var simulationSystemGroup = world.GetExistingSystem <SimulationSystemGroup>(); var presentationSystemGroup = world.GetExistingSystem <PresentationSystemGroup>(); var systems = new List <Type>(DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default)); systems.RemoveSwapBack(typeof(InitializationSystemGroup)); systems.RemoveSwapBack(typeof(SimulationSystemGroup)); systems.RemoveSwapBack(typeof(PresentationSystemGroup)); BootstrapTools.InjectUnitySystems(systems, world, simulationSystemGroup); BootstrapTools.InjectRootSuperSystems(systems, world, simulationSystemGroup); initializationSystemGroup.SortSystems(); simulationSystemGroup.SortSystems(); presentationSystemGroup.SortSystems(); BootstrapTools.UpdatePlayerLoopWithDelayedSimulation(world); return(true); }
public bool Initialize(string defaultWorldName) { var world = new LatiosWorld(defaultWorldName); World.DefaultGameObjectInjectionWorld = world; var initializationSystemGroup = world.GetExistingSystem <InitializationSystemGroup>(); var simulationSystemGroup = world.GetExistingSystem <SimulationSystemGroup>(); var presentationSystemGroup = world.GetExistingSystem <PresentationSystemGroup>(); var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default); systems.RemoveSwapBack(typeof(InitializationSystemGroup)); systems.RemoveSwapBack(typeof(SimulationSystemGroup)); systems.RemoveSwapBack(typeof(PresentationSystemGroup)); BootstrapTools.InjectSystemsFromNamespace(systems, "Unity", world, simulationSystemGroup); BootstrapTools.InjectRootSuperSystems(systems, world, simulationSystemGroup); initializationSystemGroup.SortSystemUpdateList(); simulationSystemGroup.SortSystemUpdateList(); presentationSystemGroup.SortSystemUpdateList(); ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world); return(true); }
public bool Initialize(string defaultWorldName) { var world = new LatiosWorld(defaultWorldName); World.DefaultGameObjectInjectionWorld = world; world.useExplicitSystemOrdering = true; var initializationSystemGroup = world.initializationSystemGroup; var simulationSystemGroup = world.simulationSystemGroup; var presentationSystemGroup = world.presentationSystemGroup; var systems = new List <Type>(DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default)); systems.RemoveSwapBack(typeof(LatiosInitializationSystemGroup)); systems.RemoveSwapBack(typeof(LatiosSimulationSystemGroup)); systems.RemoveSwapBack(typeof(LatiosPresentationSystemGroup)); systems.RemoveSwapBack(typeof(InitializationSystemGroup)); systems.RemoveSwapBack(typeof(SimulationSystemGroup)); systems.RemoveSwapBack(typeof(PresentationSystemGroup)); BootstrapTools.InjectUnitySystems(systems, world, simulationSystemGroup); BootstrapTools.InjectRootSuperSystems(systems, world, simulationSystemGroup); initializationSystemGroup.SortSystems(); simulationSystemGroup.SortSystems(); presentationSystemGroup.SortSystems(); //Reset playerloop so we don't infinitely add systems. PlayerLoop.SetPlayerLoop(PlayerLoop.GetDefaultPlayerLoop()); var beforeGpuProfiling = world.CreateSystem <Lsss.Tools.BeginGpuWaitProfilingSystem>(); var afterGpuProfiling = world.CreateSystem <Lsss.Tools.EndGpuWaitProfilingSystem>(); BootstrapTools.AddWorldToCurrentPlayerLoopWithDelayedSimulation(world); var loop = PlayerLoop.GetCurrentPlayerLoop(); #if UNITY_EDITOR ScriptBehaviourUpdateOrder.AppendSystemToPlayerLoopList(beforeGpuProfiling, ref loop, typeof(PostLateUpdate)); #else ScriptBehaviourUpdateOrder.AppendSystemToPlayerLoopList(beforeGpuProfiling, ref loop, typeof(UnityEngine.PlayerLoop.PostLateUpdate.PlayerEmitCanvasGeometry)); #endif PlayerLoop.SetPlayerLoop(loop); return(true); }
protected override void CreateSystems() { var managedCreateType = typeof(ManagedComponentCreateSystem <>); var managedDestroyType = typeof(ManagedComponentDestroySystem <>); var collectionCreateType = typeof(CollectionComponentCreateSystem <>); var collectionDestroyType = typeof(CollectionComponentDestroySystem <>); var managedSysStateTagType = typeof(ManagedComponentSystemStateTag <>); var collectionSysStateTagType = typeof(CollectionComponentSystemStateTag <>); var typePairs = new NativeHashSet <AssociatedTypeSysStateTagTypePair>(128, Allocator.TempJob); var assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (var assembly in assemblies) { if (!BootstrapTools.IsAssemblyReferencingLatios(assembly)) { continue; } foreach (var type in assembly.GetTypes()) { if (type.GetCustomAttribute(typeof(DisableAutoTypeRegistration)) != null) { continue; } if (type == typeof(IManagedComponent) || type == typeof(ICollectionComponent)) { continue; } if (typeof(IManagedComponent).IsAssignableFrom(type)) { GetOrCreateAndAddSystem(managedCreateType.MakeGenericType(type)); GetOrCreateAndAddSystem(managedDestroyType.MakeGenericType(type)); typePairs.Add(new AssociatedTypeSysStateTagTypePair { sysStateTagType = ComponentType.ReadOnly(managedSysStateTagType.MakeGenericType(type)), associatedType = ComponentType.ReadOnly((Activator.CreateInstance(type) as IManagedComponent).AssociatedComponentType) }); } else if (typeof(ICollectionComponent).IsAssignableFrom(type)) { GetOrCreateAndAddSystem(collectionCreateType.MakeGenericType(type)); GetOrCreateAndAddSystem(collectionDestroyType.MakeGenericType(type)); typePairs.Add(new AssociatedTypeSysStateTagTypePair { sysStateTagType = ComponentType.ReadOnly(collectionSysStateTagType.MakeGenericType(type)), associatedType = ComponentType.ReadOnly((Activator.CreateInstance(type) as ICollectionComponent).AssociatedComponentType) }); } } } //Todo: Bug in Unity prevents iterating over NativeHashSet (value is defaulted). var typePairsArr = typePairs.ToNativeArray(Allocator.TempJob); EntityQueryDesc[] descs = new EntityQueryDesc[typePairsArr.Length * 2]; int i = 0; foreach (var pair in typePairsArr) { descs[i] = new EntityQueryDesc { All = new ComponentType[] { pair.associatedType }, None = new ComponentType[] { pair.sysStateTagType } }; i++; descs[i] = new EntityQueryDesc { All = new ComponentType[] { pair.sysStateTagType }, None = new ComponentType[] { pair.associatedType } }; i++; } //Bug in Unity prevents constructing this EntityQuery because the scratch buffer is hardcoded to a size of 1024 which is not enough. //m_allSystemsQuery = GetEntityQuery(descs); typePairsArr.Dispose(); typePairs.Dispose(); }
protected override void CreateSystems() { var managedCreateType = typeof(ManagedComponentCreateSystem <>); var managedDestroyType = typeof(ManagedComponentDestroySystem <>); var collectionCreateType = typeof(CollectionComponentCreateSystem <>); var collectionDestroyType = typeof(CollectionComponentDestroySystem <>); //var managedTagType = typeof(ManagedComponentTag<>); var managedSysStateType = typeof(ManagedComponentSystemStateTag <>); //var collectionTagType = typeof(CollectionComponentTag<>); var collectionSysStateType = typeof(CollectionComponentSystemStateTag <>); var tagTypes = new NativeList <ComponentType>(Allocator.TempJob); var sysTypes = new NativeHashMap <ComponentType, byte>(128, Allocator.TempJob); var assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (var assembly in assemblies) { if (!BootstrapTools.IsAssemblyReferencingLatios(assembly)) { continue; } foreach (var type in assembly.GetTypes()) { if (type.GetCustomAttribute(typeof(DisableAutoTypeRegistration)) != null) { continue; } if (type == typeof(IManagedComponent) || type == typeof(ICollectionComponent)) { continue; } if (typeof(IManagedComponent).IsAssignableFrom(type)) { GetOrCreateAndAddSystem(managedCreateType.MakeGenericType(type)); GetOrCreateAndAddSystem(managedDestroyType.MakeGenericType(type)); sysTypes.TryAdd(ComponentType.ReadOnly(managedSysStateType.MakeGenericType(type)), 0); //tagTypes.Add(ComponentType.ReadOnly(managedTagType.MakeGenericType(type))); tagTypes.Add(ComponentType.ReadOnly((Activator.CreateInstance(type) as IManagedComponent).AssociatedComponentType)); } else if (typeof(ICollectionComponent).IsAssignableFrom(type)) { GetOrCreateAndAddSystem(collectionCreateType.MakeGenericType(type)); GetOrCreateAndAddSystem(collectionDestroyType.MakeGenericType(type)); sysTypes.TryAdd(ComponentType.ReadOnly(collectionSysStateType.MakeGenericType(type)), 0); //tagTypes.Add(ComponentType.ReadOnly(collectionTagType.MakeGenericType(type))); tagTypes.Add(ComponentType.ReadOnly((Activator.CreateInstance(type) as ICollectionComponent).AssociatedComponentType)); } } } var tags = tagTypes.ToArray(); var nss = sysTypes.GetKeyArray(Allocator.Temp); var ss = nss.ToArray(); nss.Dispose(); //Todo: Is this necessary? I keep getting conflicting info from Unity on Allocator.Temp EntityQueryDesc descCreate = new EntityQueryDesc { Any = tags, None = ss }; m_anythingNeedsCreationQuery = GetEntityQuery(descCreate); EntityQueryDesc descDestroy = new EntityQueryDesc { Any = ss, None = tags }; m_anythingNeedsDestructionQuery = GetEntityQuery(descDestroy); tagTypes.Dispose(); sysTypes.Dispose(); }