Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 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;
     }
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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>());
        }
Ejemplo n.º 6
0
        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());
        }
Ejemplo n.º 7
0
    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);
    }
Ejemplo n.º 8
0
        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;
                    }
                }
            }
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
    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());
        }
    }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
    // 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);
        }
    }
Ejemplo n.º 13
0
    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());
        }
    }
Ejemplo n.º 14
0
        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();
        }
Ejemplo n.º 15
0
 public static void RecycleChunk(RGChunk chunk)
 {
     chunk.Free();
     _self.mChunkPool.Recycle(chunk);
 }