public VFDataReader(string dataFilePrefix, ChunkDataLoadedProcessor chunkDataProc = null, bool bPreopenFiles = true) { _dataFilePrefix = dataFilePrefix; _chunkDataProc = chunkDataProc; if (bPreopenFiles) { VFFileUtil.PreOpenAllFiles(_dataFilePrefix, out _fileStreams, out _fileLens); } }
public void SetChunkData(VFVoxelChunkData chunkData, ChunkDataLoadedProcessor chunkDataProc) { byte[] chunkDataVT; //bool bFromPool; byte vol, typ; if (IsHollow()) { vol = zippedDataBuffer[0]; typ = zippedDataBuffer[1]; if (vol == 0) { chunkDataVT = VFVoxelChunkData.S_ChunkDataAir; } else if (vol == 128) { chunkDataVT = VFVoxelChunkData.S_ChunkDataWaterPlane; } else if (vol == 255) { chunkDataVT = VFVoxelChunkData.S_ChunkDataSolid[typ]; } else { chunkDataVT = new byte[VFVoxel.c_VTSize] { vol, typ } }; if (chunkDataProc == null) { chunkData.OnDataLoaded(chunkDataVT, false); } else { chunkDataProc(chunkData, chunkDataVT, false); } return; } byte[] chunkDataSet = unzippedDataBuffer; int lenChunkDataSet = unzippedDataLen; int ofsDataAddr = 0; int idxChunk = VFFileUtil.ChunkPos2IndexInPiece(chunkData.ChunkPosLod); int idChunkMax = VoxelTerrainConstants._ChunksPerPiece - 1; ofsDataAddr += 4 * idxChunk; try{ int vxDataAddr = (chunkDataSet[ofsDataAddr]) + (chunkDataSet[ofsDataAddr + 1] << 8) + (chunkDataSet[ofsDataAddr + 2] << 16) + (chunkDataSet[ofsDataAddr + 3] << 24); int vxDataNextAddr = (idxChunk < idChunkMax) ? (chunkDataSet[ofsDataAddr + 4]) + (chunkDataSet[ofsDataAddr + 5] << 8) + (chunkDataSet[ofsDataAddr + 6] << 16) + (chunkDataSet[ofsDataAddr + 7] << 24) : lenChunkDataSet; int dataLen = vxDataNextAddr - vxDataAddr; if (dataLen == VoxelTerrainConstants.VOXEL_ARRAY_LENGTH_VT) { chunkDataVT = VFVoxelChunkData.s_ChunkDataPool.Get(); Array.Copy(chunkDataSet, vxDataAddr, chunkDataVT, 0, VoxelTerrainConstants.VOXEL_ARRAY_LENGTH_VT); if (chunkDataProc == null) { chunkData.OnDataLoaded(chunkDataVT, true); } else { chunkDataProc(chunkData, chunkDataVT, true); } } else if (dataLen == VFVoxel.c_VTSize) { vol = chunkDataSet[vxDataAddr]; typ = chunkDataSet[vxDataAddr + 1]; if (vol == 0) { chunkDataVT = VFVoxelChunkData.S_ChunkDataAir; } else if (vol == 128) { chunkDataVT = VFVoxelChunkData.S_ChunkDataWaterPlane; } else if (vol == 255) { chunkDataVT = VFVoxelChunkData.S_ChunkDataSolid[typ]; } else { chunkDataVT = new byte[VFVoxel.c_VTSize] { vol, typ } }; if (chunkDataProc == null) { chunkData.OnDataLoaded(chunkDataVT, false); } else { chunkDataProc(chunkData, chunkDataVT, false); } } else { Debug.LogWarning("[VFDATAReader]Unsupported data length(" + dataLen + ")@" + chunkData.ChunkPosLod); } } catch { Debug.LogWarning("[VFDATAReader]Failed to read Chunk" + chunkData.ChunkPosLod); } } }