public tileReader(tileReader copy) { id = nextId; nextId++; filePos = copy.filePos; tileLookup = new TileImportance(copy.tileLookup); tile = new Tile(copy.tile); tileOrder = new List<Byte>(); tilesRead = copy.tilesRead; foreach (Byte b in copy.tileOrder) tileOrder.Add(b); }
private TileImportance[] ScanWorldTiles() { Byte tryByte; Byte tileType; Tile curTile; Int32 i, j, k; tileReader curReader; tileReader splitReader; TileImportance curList; TileImportance[] returnList; List<tileReader> readerList = new List<tileReader>(); buffReader.Seek(stream.Position); // We set up the lookup we can change here and we'll simply change it. // We might not even need this lookup at all. Work the logic later. curReader = new tileReader(stream.Position); curReader.startAt = new Point(0, 0); curReader.splitAt = 255; curList = curReader.tileLookup; curTile = curReader.tile; readerList.Add(curReader); for (i = 0; i < MaxX; i++) { progress = (Int32)(((i * MaxY) / (double)(MaxX * MaxY)) * 100); for (j = 0; j < MaxY; j++) { // If somehow we manage to knock out every reader as bad then we need to quit. if (readerList.Count == 0) return null; for (k = 0; k < readerList.Count; k++) { // No reason to keep resetting these if we only have one path going. if (readerList.Count > 1) { curReader = readerList[k]; curList = curReader.tileLookup; curTile = curReader.tile; buffReader.Seek(curReader.filePos); } tryByte = buffReader.ReadByte(); if (tryByte > 1) goto badPath; if (tryByte == 1) { curTile.Active = true; tileType = buffReader.ReadByte(); curTile.TileType = tileType; if (curList.isKnown(tileType) == false) { // Here we need to split the lists. curReader.tileOrder.Add(tileType); curList.setKnown(tileType, true); splitReader = new tileReader(curReader); splitReader.startAt = new Point(i, j); splitReader.splitAt = tileType; curList.setImportant(tileType, false); splitReader.tileLookup.setImportant(tileType, true); readerList.Add(splitReader); bw.ReportProgress(progress, String.Format("Split #{0} {1}", splitReader.id, readerList.Count)); curTile.Important = false; } else { curTile.Important = curList.isImportant(tileType); } } else { curTile.Active = false; curTile.Important = false; } if (curTile.Important == true) { curTile.Frame = new PointInt16(buffReader.ReadInt16(), buffReader.ReadInt16()); } // isLighted tryByte = buffReader.ReadByte(); if (tryByte > 1) goto badPath; // isWall tryByte = buffReader.ReadByte(); if (tryByte > 1) goto badPath; if (tryByte == 1) { curTile.Wall = true; // wallType tryByte = buffReader.ReadByte(); // It turns out there will never be a wall type 0. if (tryByte == 0) goto badPath; curTile.WallType = tryByte; } else { curTile.Wall = false; } // isWater tryByte = buffReader.ReadByte(); if (tryByte > 1) goto badPath; if (tryByte == 1) { // waterLevel tryByte = buffReader.ReadByte(); curTile.LiquidLevel = tryByte; // We can have any water value besides zero, if the isWater bit is set. if (tryByte == 0) goto badPath; // isLava tryByte = buffReader.ReadByte(); if (tryByte > 1) goto badPath; if (tryByte == 1) curTile.Lava = true; else curTile.Lava = false; } curReader.filePos = buffReader.Position; // This path passed over the end of the tile range. Bad path. // We might not always have a valid chest position though, if they // have changed something in a new version. if (posChests != 0 && curReader.filePos > posChests) goto badPath; curReader.tilesRead++; continue; badPath: bw.ReportProgress(progress, String.Format("Path #{0} Terminated {1}", readerList[k].id, readerList.Count - 1)); // Erase the bad path from the list to process. readerList.RemoveAt(k); // Now that we removed one we need to move the loop back one to // compensate for how it shifts them over. Otherwise we could // have a 0,1,2 then remove 1 which leaves 0,1 and our next // loop is for 2 so the old 2 (new 1) gets skipped. k--; // If we took it back to one we'll need to set up for the next loop // as we put the skip in to speed it up. if (readerList.Count == 1) { curReader = readerList[0]; curList = curReader.tileLookup; curTile = curReader.tile; buffReader.Seek(curReader.filePos); } } } } // Time to prep for the return. returnList = new TileImportance[readerList.Count]; // Find the first one that matched up with the end of the tile position. for (k = 0; k < readerList.Count; k++) { if (readerList[k].filePos == posChests) break; } // Now generate the list but put the one that matched first, if one existed. if (readerList.Count == k) { for (i = 0; i < readerList.Count; i++) returnList[i] = readerList[i].tileLookup; } else { returnList[0] = readerList[k].tileLookup; j = 1; for (i = 0; i < readerList.Count; i++) { if (i != k) { returnList[j] = readerList[k].tileLookup; j++; } } } //bw.ReportProgress(progress, String.Format("Path #{0} Terminated {1}", readerList[k].id, readerList.Count - 1)); return returnList; }
public Client(ClientOps ops = default, uint didLookup = default, sync.Once initOnce = default, error initErr = default, @string name = default, note.Verifiers verifiers = default, tileReader tileReader = default, long tileHeight = default, @string nosumdb = default, parCache record = default, parCache tileCache = default, sync.Mutex latestMu = default, tlog.Tree latest = default, slice <byte> latestMsg = default, sync.Mutex tileSavedMu = default, map <tlog.Tile, bool> tileSaved = default) { this.ops = ops; this.didLookup = didLookup; this.initOnce = initOnce; this.initErr = initErr; this.name = name; this.verifiers = verifiers; this.tileReader = tileReader; this.tileHeight = tileHeight; this.nosumdb = nosumdb; this.record = record; this.tileCache = tileCache; this.latestMu = latestMu; this.latest = latest; this.latestMsg = latestMsg; this.tileSavedMu = tileSavedMu; this.tileSaved = tileSaved; }