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 void RefreshImmediately(int cx, int cz) { mIO.StopProcess(); Clear(); mReqsOutput.Clear(); int expand = mEvni.DataExpandNum; for (int i = cx - expand; i <= cx + expand; i++) { for (int j = cz - expand; j <= cz + expand; j++) { RGChunk chunk = RGPoolSig.GetChunk(); chunk.Init(i, j, mEvni); mReqsOutput.reqsChunk.Add(chunk); } } mIO.AddReqs(mReqsOutput.reqsChunk); mIO.ProcessReqsImmediatly(); foreach (RGChunk chunk in mReqsOutput.reqsChunk) { if (chunk.isEmpty) { continue; } mChunks[chunk.xIndex, chunk.zIndex] = chunk; } mCenter = new INTVECTOR2(cx, cz); }
public RGChunk this[int x, int z] { get{ RGChunk ret = null; int key = Utils.PosToIndex(x, z); _dicData.TryGetValue(key, out ret); return(ret); } set{ int key = Utils.PosToIndex(x, z); _dicData[key] = value; } }
public bool Remove(int x, int y, int z) { int cx = x >> SHIFT; int cz = z >> SHIFT; RGChunk chunk = mChunks [cx, cz]; if (chunk != null) { return(chunk.Remove(x, y, z)); } return(false); }
public List <RedGrassInstance> Read(int x, int z, int ymin, int ymax) { int cx = x >> SHIFT; int cz = z >> SHIFT; RGChunk chunk = mChunks [cx, cz]; if (chunk != null) { return(chunk.Read(x, z, ymin, ymax)); } return(new List <RedGrassInstance>()); }
public RedGrassInstance Read(int x, int y, int z) { int cx = x >> SHIFT; int cz = z >> SHIFT; RGChunk chunk = mChunks [cx, cz]; if (chunk != null) { return(chunk.Read(x, y, z)); } return(new RedGrassInstance()); }
public override bool AddReqs(RedGrass.RGChunk chunk) { if (mActive) { Debug.LogError("The data IO is already acitve"); return(false); } lock (mReqs) { mReqs.Enqueue(chunk); } return(true); }
public void Dirty(RGDataSource data, bool dirty) { int expand = 1 << LOD; for (int x = xIndex; x < xIndex + expand; x++) { for (int z = zIndex; z < zIndex + expand; z++) { RGChunk gc = data.Node(x, z); if (gc != null) { gc.Dirty = dirty; } } } }
public bool IsDirty(RGDataSource data) { int expand = 1 << LOD; for (int x = xIndex; x < xIndex + expand; x++) { for (int z = zIndex; z < zIndex + expand; z++) { RGChunk gc = data.Node(x, z); if (gc != null && gc.Dirty) { return(true); } } } return(false); }
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()); } }
public List <RGChunk> GetChunks(RGDataSource data) { List <RGChunk> gc_list = new List <RGChunk>(); int expand = 1 << LOD; for (int x = xIndex; x < xIndex + expand; x++) { for (int z = zIndex; z < zIndex + expand; z++) { RGChunk gc = data.Node(x, z); if (gc == null) { continue; } gc_list.Add(gc); } } return(gc_list); }
// 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()); } }
public void ReqsUpdate(int cx, int cz) { Profiler.BeginSample("Req"); mReqsOutput.Clear(); IsProcessReqs = true; // Find the loading chunk int expand = mEvni.DataExpandNum; for (int i = cx - expand; i <= cx + expand; i++) { for (int j = cz - expand; j <= cz + expand; j++) { if (!mChunks.Contains(i, j)) { RGChunk chunk = RGPoolSig.GetChunk(); chunk.Init(i, j, mEvni); mReqsOutput.reqsChunk.Add(chunk); } } } if (mReqsOutput.reqsChunk.Count != 0) { mIO.AddReqs(mReqsOutput.reqsChunk); } // Descarding part int max_new_x = cx + expand; int min_new_x = cx - expand; int max_new_z = cz + expand; int min_new_z = cz - expand; for (int i = mCenter.x - expand; i <= mCenter.x + expand; i++) { for (int j = mCenter.y - expand; j <= mCenter.y + expand; j++) { if (i < min_new_x || i > max_new_x || j < min_new_z || j > max_new_z) { RGChunk chunk = mChunks[i, j]; if (chunk != null) { mReqsOutput.discardChunk.Add(chunk); } } } } if (mReqsOutput.reqsChunk.Count != 0 || mReqsOutput.discardChunk.Count != 0) { // Activate the DataIO mIO.Active(delegate() { IsProcessReqs = false; }); } Profiler.EndSample(); }
public static void RecycleChunk(RGChunk chunk) { chunk.Free(); _self.mChunkPool.Recycle(chunk); }