public static void Run() { List <AsyncLoader> list = new List <AsyncLoader>(); Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { Type[] types = assembly.GetTypes(); foreach (Type type in types) { if (!type.IsAbstract && typeof(AsyncLoaderType).IsAssignableFrom(type)) { AsyncLoader asyncLoader = (AsyncLoader)Activator.CreateInstance(type); list.Add(asyncLoader); loaders[type] = asyncLoader; asyncLoader.CollectLoaders(list); } } } if (loaders.Count > 0) { WorkItemCollection <RunLoader, object> workItemCollection = new WorkItemCollection <RunLoader, object>(); workItemCollection.Reset(null); foreach (AsyncLoader item in list) { workItemCollection.Add(new RunLoader { loader = item }); } GlobalJobManager.Run(workItemCollection); } }
private void AsyncPathProbe() { int probeSize = this.probeSize; pathProbeJob.Reset(null); for (int i = 0; i != brains.Count; i++) { ClampBrainIndex(ref nextPathProbeBrain); Navigator component = brains[nextPathProbeBrain].GetComponent <Navigator>(); IncrementBrainIndex(ref nextPathProbeBrain); if ((UnityEngine.Object)component != (UnityEngine.Object)null) { component.executePathProbeTaskAsync = true; component.PathProber.potentialCellsPerUpdate = this.probeSize; component.pathProbeTask.Update(); pathProbeJob.Add(component.pathProbeTask); if (pathProbeJob.Count == probeCount) { break; } } } CPUBudget.Start(this); GlobalJobManager.Run(pathProbeJob); CPUBudget.End(this); }
public void Sim200ms(float time_delta) { find_top_priority_job.Reset(null); FindTopPriorityTask.abort = false; int num = 512; for (int i = 0; i < Components.Prioritizables.Items.Count; i += num) { int num2 = i + num; if (Components.Prioritizables.Items.Count < num2) { num2 = Components.Prioritizables.Items.Count; } find_top_priority_job.Add(new FindTopPriorityTask(i, num2)); } GlobalJobManager.Run(find_top_priority_job); bool on = false; for (int j = 0; j != find_top_priority_job.Count; j++) { FindTopPriorityTask workItem = find_top_priority_job.GetWorkItem(j); if (workItem.found) { on = true; break; } } VignetteManager.Instance.Get().HasTopPriorityChore(on); }
public void UpdateData(Texture2D texture, byte[] textureBytes, HashedString viewMode, byte alpha) { if (!dataUpdateFuncs.TryGetValue(viewMode, out Action <SimDebugView, Texture> value)) { value = SetDefaultPoint; } value(this, texture); Grid.GetVisibleExtents(out int min_x, out int min_y, out int max_x, out int max_y); selectedPathProber = null; KSelectable selected = SelectTool.Instance.selected; if ((UnityEngine.Object)selected != (UnityEngine.Object)null) { selectedPathProber = selected.GetComponent <PathProber>(); } updateSimViewWorkItems.Reset(new UpdateSimViewSharedData(this, texBytes, viewMode, this)); int num = 16; for (int i = min_y; i <= max_y; i += num) { int y = Math.Min(i + num - 1, max_y); updateSimViewWorkItems.Add(new UpdateSimViewWorkItem(min_x, i, max_x, y)); } currentFrame = Time.frameCount; selectedCell = Grid.PosToCell(Camera.main.ScreenToWorldPoint(KInputManager.GetMousePos())); GlobalJobManager.Run(updateSimViewWorkItems); texture.LoadRawTextureData(textureBytes); texture.Apply(); }
public void UpdatePickups(PathProber path_prober, Worker worker) { Navigator component = worker.GetComponent <Navigator>(); updatePickupsWorkItems.Reset(null); foreach (KeyValuePair <Tag, FetchablesByPrefabId> prefabIdToFetchable in prefabIdToFetchables) { FetchablesByPrefabId value = prefabIdToFetchable.Value; value.UpdateOffsetTables(); updatePickupsWorkItems.Add(new UpdatePickupWorkItem { fetchablesByPrefabId = value, pathProber = path_prober, navigator = component, worker = worker.gameObject }); } OffsetTracker.isExecutingWithinJob = true; GlobalJobManager.Run(updatePickupsWorkItems); OffsetTracker.isExecutingWithinJob = false; pickups.Clear(); foreach (KeyValuePair <Tag, FetchablesByPrefabId> prefabIdToFetchable2 in prefabIdToFetchables) { pickups.AddRange(prefabIdToFetchable2.Value.finalPickups); } pickups.Sort(ComparerNoPriority); }
private void RenderMesh(float z, int render_layer, float lerp_percent, bool trigger_audio) { GridArea visibleArea = GridVisibleArea.GetVisibleArea(); Vector2I min = visibleArea.Min; int a = Mathf.Max(0, min.x - 1); Vector2I min2 = visibleArea.Min; Vector2I min3 = new Vector2I(a, Mathf.Max(0, min2.y - 1)); int a2 = Grid.WidthInCells - 1; Vector2I max = visibleArea.Max; int a3 = Mathf.Min(a2, max.x + 1); int a4 = Grid.HeightInCells - 1; Vector2I max2 = visibleArea.Max; Vector2I max3 = new Vector2I(a3, Mathf.Min(a4, max2.y + 1)); RenderMeshContext shared_data = new RenderMeshContext(this, lerp_percent, min3, max3); if (shared_data.visible_conduits.Count == 0) { shared_data.Finish(); } else { render_mesh_job.Reset(shared_data); int num = Mathf.Max(1, (int)((float)(shared_data.visible_conduits.Count / CPUBudget.coreCount) / 1.5f)); int num2 = Mathf.Max(1, shared_data.visible_conduits.Count / num); for (int i = 0; i != num2; i++) { int num3 = i * num; int end = (i != num2 - 1) ? (num3 + num) : shared_data.visible_conduits.Count; render_mesh_job.Add(new RenderMeshTask(num3, end)); } GlobalJobManager.Run(render_mesh_job); float z2 = 0f; if (showContents) { z2 = 1f; } int num4 = (int)(animTime / (1.0 / (double)tuning.framesPerSecond)) % (int)tuning.spriteCount; float w = (float)num4 * (1f / tuning.spriteCount); movingBallMesh.Begin(); movingBallMesh.SetTexture("_BackgroundTex", tuning.backgroundTexture); movingBallMesh.SetTexture("_ForegroundTex", tuning.foregroundTexture); movingBallMesh.SetVector("_SpriteSettings", new Vector4(1f / tuning.spriteCount, 1f, z2, w)); movingBallMesh.SetVector("_Highlight", new Vector4((float)(int)highlightColour.r / 255f, (float)(int)highlightColour.g / 255f, (float)(int)highlightColour.b / 255f, 0f)); staticBallMesh.Begin(); staticBallMesh.SetTexture("_BackgroundTex", tuning.backgroundTexture); staticBallMesh.SetTexture("_ForegroundTex", tuning.foregroundTexture); staticBallMesh.SetVector("_SpriteSettings", new Vector4(1f / tuning.spriteCount, 1f, z2, 0f)); staticBallMesh.SetVector("_Highlight", new Vector4((float)(int)highlightColour.r / 255f, (float)(int)highlightColour.g / 255f, (float)(int)highlightColour.b / 255f, 0f)); Vector3 position = CameraController.Instance.transform.GetPosition(); ConduitFlowVisualizer visualizer = (!trigger_audio) ? null : this; for (int j = 0; j != render_mesh_job.Count; j++) { render_mesh_job.GetWorkItem(j).Finish(movingBallMesh, staticBallMesh, position, visualizer); } movingBallMesh.End(z, layer); staticBallMesh.End(z, layer); shared_data.Finish(); } }
public static void FindEggToGuard(List <UpdateBucketWithUpdater <Instance> .Entry> instances, float time_delta) { ListPool <KPrefabID, EggProtectionMonitor> .PooledList pooledList = ListPool <KPrefabID, EggProtectionMonitor> .Allocate(); pooledList.Capacity = Mathf.Max(pooledList.Capacity, Components.Pickupables.Count); IEnumerator enumerator = Components.Pickupables.GetEnumerator(); try { while (enumerator.MoveNext()) { Pickupable pickupable = (Pickupable)enumerator.Current; pooledList.Add(pickupable.gameObject.GetComponent <KPrefabID>()); } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } ListPool <Egg, EggProtectionMonitor> .PooledList pooledList2 = ListPool <Egg, EggProtectionMonitor> .Allocate(); find_eggs_job.Reset(pooledList); for (int i = 0; i < pooledList.Count; i += 256) { find_eggs_job.Add(new FindEggsTask(i, Mathf.Min(i + 256, pooledList.Count))); } GlobalJobManager.Run(find_eggs_job); for (int j = 0; j != find_eggs_job.Count; j++) { find_eggs_job.GetWorkItem(j).Finish(pooledList, pooledList2); } pooledList.Recycle(); foreach (UpdateBucketWithUpdater <Instance> .Entry instance in instances) { UpdateBucketWithUpdater <Instance> .Entry current = instance; GameObject eggToGuard = null; int num = 100; foreach (Egg item in pooledList2) { Egg current2 = item; int navigationCost = current.data.navigator.GetNavigationCost(current2.cell); if (navigationCost != -1 && navigationCost < num) { eggToGuard = current2.game_object; num = navigationCost; } } current.data.SetEggToGuard(eggToGuard); } pooledList2.Recycle(); }
private static void MarkValidCells(NavTable nav_table, NavType[] valid_nav_types, NavTableValidator[] validators, CellOffset[] bounding_offsets) { WorkItemCollection <MarkValidCellWorkItem, object> workItemCollection = new WorkItemCollection <MarkValidCellWorkItem, object>(); workItemCollection.Reset(null); for (int i = 0; i < Grid.HeightInCells; i++) { workItemCollection.Add(new MarkValidCellWorkItem(Grid.OffsetCell(0, new CellOffset(0, i)), nav_table, bounding_offsets, validators)); } GlobalJobManager.Run(workItemCollection); }
private static void CreateLinks(NavTable nav_table, int max_links_per_cell, NavGrid.Link[] links, NavGrid.Transition[][] transitions_by_nav_type) { WorkItemCollection <CreateLinkWorkItem, object> workItemCollection = new WorkItemCollection <CreateLinkWorkItem, object>(); workItemCollection.Reset(null); for (int i = 0; i < Grid.HeightInCells; i++) { workItemCollection.Add(new CreateLinkWorkItem(Grid.OffsetCell(0, new CellOffset(0, i)), nav_table, max_links_per_cell, links, transitions_by_nav_type)); } GlobalJobManager.Run(workItemCollection); }
private void UpdateTextureThreaded(TextureRegion texture_region, int x0, int y0, int x1, int y1, WorkItem.Callback update_texture_cb) { workItems.Reset(null); int num = 16; for (int i = y0; i <= y1; i += num) { int y2 = Math.Min(i + num - 1, y1); workItems.Add(new WorkItem(texture_region, x0, i, x1, y2, update_texture_cb)); } GlobalJobManager.Run(workItems); }
public static void BatchUpdate(List <UpdateBucketWithUpdater <ISim200ms> .Entry> amount_instances, float time_delta) { if (time_delta != 0f) { BatchUpdateContext shared_data = new BatchUpdateContext(amount_instances, time_delta); batch_update_job.Reset(shared_data); int num = 512; for (int i = 0; i < amount_instances.Count; i += num) { int num2 = i + num; if (amount_instances.Count < num2) { num2 = amount_instances.Count; } batch_update_job.Add(new BatchUpdateTask(i, num2)); } GlobalJobManager.Run(batch_update_job); shared_data.Finish(); } }
/// <summary> /// Reduce the time that async loaders take to index, by only indexing the game /// assemblies and not stuff like UnityEngine. /// </summary> private static void QuickAsyncLoad() { var collectedLoaders = new List <AsyncLoader>(); var loaderFor = AsyncLoadManager <IGlobalAsyncLoader> .loaders; // Only index the game assemblies var assemblies = new Assembly[] { typeof(Game).Assembly, typeof(KAnim).Assembly }; int n = assemblies.Length; loaderFor.Clear(); for (int i = 0; i < n; i++) { foreach (var type in assemblies[i].GetTypes()) { if (!type.IsAbstract && typeof(IGlobalAsyncLoader).IsAssignableFrom(type)) { var loadInstance = Activator.CreateInstance(type) as AsyncLoader; collectedLoaders.Add(loadInstance); loaderFor[type] = loadInstance; loadInstance.CollectLoaders(collectedLoaders); } } } #if DEBUG PUtil.LogDebug("Async loading {0:D} types".F(collectedLoaders.Count)); #endif // Run them all in parallel (base game does it too!) if (loaderFor.Count > 0) { var jobs = new WorkItemCollection <RunLoader, object>(); jobs.Reset(null); foreach (var loader in collectedLoaders) { jobs.Add(new RunLoader { loader = loader }); } GlobalJobManager.Run(jobs); } collectedLoaders.Clear(); }
public static void ModifyBrightness(List <UpdateBucketWithUpdater <Instance> .Entry> instances, ModifyLuxDelegate modify_lux, float time_delta) { modify_brightness_job.Reset(null); for (int i = 0; i != instances.Count; i++) { UpdateBucketWithUpdater <Instance> .Entry value = instances[i]; value.lastUpdateTime = 0f; instances[i] = value; Instance data = value.data; modify_lux(data, time_delta); data.light.Range = data.originalRange * (float)data.light.Lux / (float)data.originalLux; data.light.RefreshShapeAndPosition(); if (data.light.RefreshShapeAndPosition() != 0) { modify_brightness_job.Add(new ModifyBrightnessTask(data.light.emitter)); } } GlobalJobManager.Run(modify_brightness_job); for (int j = 0; j != modify_brightness_job.Count; j++) { modify_brightness_job.GetWorkItem(j).Finish(); } }