public RoomieThread(RoomieEngine engine, string name, HierarchicalVariableScope parentScope) { Engine = engine; Id = Guid.NewGuid().ToString(); Name = name; _interpreter = new RoomieCommandInterpreter(this, parentScope ?? Engine.GlobalScope); _workQueue = new ParallelWorkQueue(); }
public ZWaveNetwork(HomeAutomationNetworkContext context) : base(context) { ZWaveController = new global::ControlThink.ZWave.ZWaveController(); this.Devices = new ZWaveDeviceCollection(this); base.Devices = this.Devices; WorkQueue = new ParallelWorkQueue(); Connect(); }
// Token: 0x06002630 RID: 9776 RVA: 0x001A8106 File Offset: 0x001A6306 protected IEnumerable <Progress> ScanAllTiles() { RecastGraph.< > c__DisplayClass50_0 CS$ < > 8__locals1 = new RecastGraph.< > c__DisplayClass50_0(); CS$ < > 8__locals1.< > 4__this = this; this.transform = this.CalculateTransform(); this.InitializeTileInfo(); if (this.scanEmptyGraph) { base.FillWithEmptyTiles(); yield break; } this.walkableClimb = Mathf.Min(this.walkableClimb, this.walkableHeight); yield return(new Progress(0f, "Finding Meshes")); Bounds bounds = this.transform.Transform(new Bounds(this.forcedBoundsSize * 0.5f, this.forcedBoundsSize)); List <RasterizationMesh> meshes = this.CollectMeshes(bounds); CS$ < > 8__locals1.buckets = this.PutMeshesIntoTileBuckets(meshes); Queue <Int2> tileQueue = new Queue <Int2>(); for (int i = 0; i < this.tileZCount; i++) { for (int j = 0; j < this.tileXCount; j++) { tileQueue.Enqueue(new Int2(j, i)); } } ParallelWorkQueue <Int2> parallelWorkQueue = new ParallelWorkQueue <Int2>(tileQueue); CS$ < > 8__locals1.voxelizers = new Voxelize[parallelWorkQueue.threadCount]; for (int k = 0; k < CS$ < > 8__locals1.voxelizers.Length; k++) { CS$ < > 8__locals1.voxelizers[k] = new Voxelize(this.CellHeight, this.cellSize, this.walkableClimb, this.walkableHeight, this.maxSlope, this.maxEdgeLength); } parallelWorkQueue.action = delegate(Int2 tile, int threadIndex) { CS$ < > 8__locals1.voxelizers[threadIndex].inputMeshes = CS$ < > 8__locals1.buckets[tile.x + tile.y * CS$ < > 8__locals1.< > 4__this.tileXCount]; CS$ < > 8__locals1.< > 4__this.tiles[tile.x + tile.y * CS$ < > 8__locals1.< > 4__this.tileXCount] = CS$ < > 8__locals1.< > 4__this.BuildTileMesh(CS$ < > 8__locals1.voxelizers[threadIndex], tile.x, tile.y, threadIndex);
protected IEnumerable <Progress> ScanAllTiles() { transform = CalculateTransform(); InitializeTileInfo(); // If this is true, just fill the graph with empty tiles if (scanEmptyGraph) { FillWithEmptyTiles(); yield break; } // A walkableClimb higher than walkableHeight can cause issues when generating the navmesh since then it can in some cases // Both be valid for a character to walk under an obstacle and climb up on top of it (and that cannot be handled with navmesh without links) // The editor scripts also enforce this but we enforce it here too just to be sure walkableClimb = Mathf.Min(walkableClimb, walkableHeight); yield return(new Progress(0, "Finding Meshes")); var bounds = transform.Transform(new Bounds(forcedBoundsSize * 0.5f, forcedBoundsSize)); var meshes = CollectMeshes(bounds); var buckets = PutMeshesIntoTileBuckets(meshes); Queue <Int2> tileQueue = new Queue <Int2>(); // Put all tiles in the queue for (int z = 0; z < tileZCount; z++) { for (int x = 0; x < tileXCount; x++) { tileQueue.Enqueue(new Int2(x, z)); } } var workQueue = new ParallelWorkQueue <Int2>(tileQueue); // Create the voxelizers and set all settings (one for each thread) var voxelizers = new Voxelize[workQueue.threadCount]; for (int i = 0; i < voxelizers.Length; i++) { voxelizers[i] = new Voxelize(CellHeight, cellSize, walkableClimb, walkableHeight, maxSlope, maxEdgeLength); } workQueue.action = (tile, threadIndex) => { voxelizers[threadIndex].inputMeshes = buckets[tile.x + tile.y * tileXCount]; tiles[tile.x + tile.y * tileXCount] = BuildTileMesh(voxelizers[threadIndex], tile.x, tile.y, threadIndex); }; // Prioritize responsiveness while playing // but when not playing prioritize throughput // (the Unity progress bar is also pretty slow to update) int timeoutMillis = Application.isPlaying ? 1 : 200; // Scan all tiles in parallel foreach (var done in workQueue.Run(timeoutMillis)) { yield return(new Progress(Mathf.Lerp(0.1f, 0.9f, done / (float)tiles.Length), "Calculated Tiles: " + done + "/" + tiles.Length)); } yield return(new Progress(0.9f, "Assigning Graph Indices")); // Assign graph index to nodes uint graphIndex = (uint)AstarPath.active.data.GetGraphIndex(this); GetNodes(node => node.GraphIndex = graphIndex); // First connect all tiles with an EVEN coordinate sum // This would be the white squares on a chess board. // Then connect all tiles with an ODD coordinate sum (which would be all black squares on a chess board). // This will prevent the different threads that do all // this in parallel from conflicting with each other. // The directions are also done separately // first they are connected along the X direction and then along the Z direction. // Looping over 0 and then 1 for (int coordinateSum = 0; coordinateSum <= 1; coordinateSum++) { for (int direction = 0; direction <= 1; direction++) { for (int i = 0; i < tiles.Length; i++) { if ((tiles[i].x + tiles[i].z) % 2 == coordinateSum) { tileQueue.Enqueue(new Int2(tiles[i].x, tiles[i].z)); } } workQueue = new ParallelWorkQueue <Int2>(tileQueue); workQueue.action = (tile, threadIndex) => { // Connect with tile at (x+1,z) and (x,z+1) if (direction == 0 && tile.x < tileXCount - 1) { ConnectTiles(tiles[tile.x + tile.y * tileXCount], tiles[tile.x + 1 + tile.y * tileXCount]); } if (direction == 1 && tile.y < tileZCount - 1) { ConnectTiles(tiles[tile.x + tile.y * tileXCount], tiles[tile.x + (tile.y + 1) * tileXCount]); } }; var numTilesInQueue = tileQueue.Count; // Connect all tiles in parallel foreach (var done in workQueue.Run(timeoutMillis)) { yield return(new Progress(0.95f, "Connected Tiles " + (numTilesInQueue - done) + "/" + numTilesInQueue + " (Phase " + (direction + 1 + 2 * coordinateSum) + " of 4)")); } } } for (int i = 0; i < meshes.Count; i++) { meshes[i].Pool(); } ListPool <RasterizationMesh> .Release(ref meshes); // This may be used by the TileHandlerHelper script to update the tiles // while taking NavmeshCuts into account after the graph has been completely recalculated. if (OnRecalculatedTiles != null) { OnRecalculatedTiles(tiles.Clone() as NavmeshTile[]); } }
protected IEnumerable <Progress> ScanAllTiles() { this.transform = this.CalculateTransform(); this.InitializeTileInfo(); if (this.scanEmptyGraph) { base.FillWithEmptyTiles(); yield break; } this.walkableClimb = Mathf.Min(this.walkableClimb, this.walkableHeight); yield return(new Progress(0f, "Finding Meshes")); Bounds bounds = this.transform.Transform(new Bounds(this.forcedBoundsSize * 0.5f, this.forcedBoundsSize)); List <RasterizationMesh> meshes = this.CollectMeshes(bounds); List <RasterizationMesh>[] buckets = this.PutMeshesIntoTileBuckets(meshes); Queue <Int2> tileQueue = new Queue <Int2>(); for (int i = 0; i < this.tileZCount; i++) { for (int j = 0; j < this.tileXCount; j++) { tileQueue.Enqueue(new Int2(j, i)); } } ParallelWorkQueue <Int2> workQueue = new ParallelWorkQueue <Int2>(tileQueue); Voxelize[] voxelizers = new Voxelize[workQueue.threadCount]; for (int k = 0; k < voxelizers.Length; k++) { voxelizers[k] = new Voxelize(this.CellHeight, this.cellSize, this.walkableClimb, this.walkableHeight, this.maxSlope, this.maxEdgeLength); } workQueue.action = delegate(Int2 tile, int threadIndex) { voxelizers[threadIndex].inputMeshes = buckets[tile.x + tile.y * this.$this.tileXCount]; this.$this.tiles[tile.x + tile.y * this.$this.tileXCount] = this.$this.BuildTileMesh(voxelizers[threadIndex], tile.x, tile.y, threadIndex); }; int timeoutMillis = (!Application.isPlaying) ? 200 : 1; foreach (int done in workQueue.Run(timeoutMillis)) { yield return(new Progress(Mathf.Lerp(0.1f, 0.9f, (float)done / (float)this.tiles.Length), string.Concat(new object[] { "Calculated Tiles: ", done, "/", this.tiles.Length }))); } yield return(new Progress(0.9f, "Assigning Graph Indices")); uint graphIndex = (uint)AstarPath.active.data.GetGraphIndex(this); this.GetNodes(delegate(GraphNode node) { node.GraphIndex = graphIndex; }); for (int coordinateSum = 0; coordinateSum <= 1; coordinateSum++) { int direction; for (direction = 0; direction <= 1; direction++) { for (int l = 0; l < this.tiles.Length; l++) { if ((this.tiles[l].x + this.tiles[l].z) % 2 == coordinateSum) { tileQueue.Enqueue(new Int2(this.tiles[l].x, this.tiles[l].z)); } } workQueue = new ParallelWorkQueue <Int2>(tileQueue); workQueue.action = delegate(Int2 tile, int threadIndex) { if (direction == 0 && tile.x < this.$this.tileXCount - 1) { this.$this.ConnectTiles(this.$this.tiles[tile.x + tile.y * this.$this.tileXCount], this.$this.tiles[tile.x + 1 + tile.y * this.$this.tileXCount]); } if (direction == 1 && tile.y < this.$this.tileZCount - 1) { this.$this.ConnectTiles(this.$this.tiles[tile.x + tile.y * this.$this.tileXCount], this.$this.tiles[tile.x + (tile.y + 1) * this.$this.tileXCount]); } }; int numTilesInQueue = tileQueue.Count; foreach (int done2 in workQueue.Run(timeoutMillis)) { yield return(new Progress(0.95f, string.Concat(new object[] { "Connected Tiles ", numTilesInQueue - done2, "/", numTilesInQueue, " (Phase ", direction + 1 + 2 * coordinateSum, " of 4)" }))); } } } for (int m = 0; m < meshes.Count; m++) { meshes[m].Pool(); } ListPool <RasterizationMesh> .Release(meshes); if (this.OnRecalculatedTiles != null) { this.OnRecalculatedTiles(this.tiles.Clone() as NavmeshTile[]); } yield break; }