public bool Write(RedGrassInstance rgi) { Vector3 pos = rgi.Position; int cx = (int)pos.x >> SHIFT; int cz = (int)pos.z >> SHIFT; RGChunk chunk = mChunks [cx, cz]; if (chunk != null) { if (rgi.Density < 0.001f) { chunk.Remove((int)pos.x, (int)pos.y, (int)pos.z); } else { chunk.Write(rgi); } } else { if (rgi.Density > 0.001f) { chunk = RGPoolSig.GetChunk(); chunk.Init(cx, cz, mEvni); mChunks[cx, cz] = chunk; chunk.Write(rgi); } } return(true); }
public override void ProcessReqsImmediatly() { try { while (mReqs.Count != 0) { RedGrass.RGChunk chunk = null; lock (mReqs) { chunk = mReqs.Dequeue(); } BinaryReader _in = new BinaryReader(mOrgnGrassFile); INTVECTOR3 chunk32Pos = ChunkPosToPos32(chunk.xIndex, chunk.zIndex); int expands = mEvni.CHUNKSIZE / mEvni.Tile; lock (chunk) { for (int _x = chunk32Pos.x; _x < chunk32Pos.x + expands; ++_x) { for (int _z = chunk32Pos.z; _z < chunk32Pos.z + expands; ++_z) { int index32 = Pos32ToIndex32(_x, _z); _in.BaseStream.Seek(mOrgnOfsData[index32], SeekOrigin.Begin); int count = mOrgnLenData[index32]; for (int i = 0; i < count; ++i) { RedGrass.RedGrassInstance rgi = new RedGrassInstance(); rgi.ReadFromStream(_in); chunk.Write(rgi); } } } } } } catch (System.Exception ex) { Debug.LogError(ex.ToString()); } }
// Thread function void Run() { try { while (mRunning) { if (!mActive) { Thread.Sleep(10); continue; } while (true) { RedGrass.RGChunk chunk = null; lock (mReqs) { if (mReqs.Count == 0) { break; } chunk = mReqs.Dequeue(); } if (mOrgnGrassFile == null) { continue; } BinaryReader _in = new BinaryReader(mOrgnGrassFile); INTVECTOR3 chunk32Pos = ChunkPosToPos32(chunk.xIndex, chunk.zIndex); int expands = mEvni.CHUNKSIZE / mEvni.Tile; lock (chunk) { for (int _x = chunk32Pos.x; _x < chunk32Pos.x + expands; ++_x) { for (int _z = chunk32Pos.z; _z < chunk32Pos.z + expands; ++_z) { int index32 = Pos32ToIndex32(_x, _z); _in.BaseStream.Seek(mOrgnOfsData[index32], SeekOrigin.Begin); int count = mOrgnLenData[index32]; for (int i = 0; i < count; ++i) { RedGrass.RedGrassInstance rgi = new RedGrassInstance(); rgi.ReadFromStream(_in); chunk.Write(rgi); } } } } } mStart = false; Thread.Sleep(10); } } catch (System.Exception ex) { Debug.LogError("<<<< Data IO Thread error >>>> \r\n" + ex); } }
public override void ProcessReqsImmediatly() { try { while (mReqs.Count != 0) { RedGrass.RGChunk chunk = null; lock (mReqs) { chunk = mReqs.Dequeue(); } INTVECTOR3 chunk32Pos = ChunkPosToPos32(chunk.xIndex, chunk.zIndex); // Find the file index int file_index = FindOrginFileIndex(chunk32Pos); if (file_index != -1 && mOrgnGrassFile[file_index] != null) { BinaryReader _in = new BinaryReader(mOrgnGrassFile[file_index]); int expands = mEvni.CHUNKSIZE / mEvni.Tile; lock (chunk) { for (int x = chunk32Pos.x; x < chunk32Pos.x + expands; ++x) { for (int z = chunk32Pos.z; z < chunk32Pos.z + expands; ++z) { int _x = x % mEvni.XTileCount; int _z = z % mEvni.ZTileCount; int index32 = Pos32ToIndex32(_x, _z); if (mOrgnOfsData[file_index, index32] > 0) { _in.BaseStream.Seek(mOrgnOfsData[file_index, index32], SeekOrigin.Begin); int count = _in.ReadInt32(); for (int i = 0; i < count; ++i) { RedGrassInstance rgi = new RedGrassInstance(); rgi.ReadFromStream(_in); Vector3 pos = rgi.Position; if (!GrassDataSL.m_mapDelPos.ContainsKey(new INTVECTOR3((int)pos.x, (int)pos.y, (int)pos.z))) { chunk.Write(rgi); } } } } } } } } } catch (System.Exception ex) { Debug.LogWarning(ex.ToString()); } }