Beispiel #1
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);
        }
Beispiel #2
0
        public void SumbmitReqs(INTVECTOR2 center)
        {
            Profiler.BeginSample("sr0");
            for (int i = 0; i < mReqsOutput.discardChunk.Count; ++i)
            {
                mReqsOutput.discardChunk[i].Free();
                if (!mChunks.Remove(mReqsOutput.discardChunk[i].xIndex, mReqsOutput.discardChunk[i].zIndex))
                {
//					Debug.LogError ("This key is not exist.");
                }
                else
                {
                    RGPoolSig.RecycleChunk(mReqsOutput.discardChunk[i]);
                }
            }
            Profiler.EndSample();

            Profiler.BeginSample("sr1");
            for (int i = 0; i < mReqsOutput.reqsChunk.Count; i++)
            {
                if (mReqsOutput.reqsChunk[i].isEmpty)
                {
                    RGPoolSig.RecycleChunk(mReqsOutput.reqsChunk[i]);
                    continue;
                }
//				mChunks.Add(key, mReqsOutput.reqsChunk[i]);
                mChunks[mReqsOutput.reqsChunk[i].xIndex, mReqsOutput.reqsChunk[i].zIndex] = mReqsOutput.reqsChunk[i];
            }
            Profiler.EndSample();

            mCenter = center;
            mReqsOutput.Clear();
        }
Beispiel #3
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);
        }
Beispiel #4
0
 public static void Init()
 {
     if (_self == null)
     {
         _self = new RGPoolSig();
     }
 }
Beispiel #5
0
 public void Clear()
 {
     foreach (KeyValuePair <int, RGChunk> p in _dicData)
     {
         p.Value.Free();
         RGPoolSig.RecycleChunk(p.Value);
     }
     _dicData.Clear();
 }
Beispiel #6
0
        public void Free()
        {
            if (data != null)
            {
                data.Free();
                data = null;
            }

            RGPoolSig.Destroy();
        }
Beispiel #7
0
        public void Init()
        {
            RedGrassInstance.Init();

            data = new RGDataSource();
            data.Init(evniAsset, dataIO);

            RGPoolSig.Init();

            // Render Part Init
            mTree = new RGLODQuadTree(evniAsset);
        }
Beispiel #8
0
        public bool Remove(int x, int y, int z)
        {
            int key = PosToKey(Mathf.FloorToInt(x) & MASK, Mathf.FloorToInt(z) & MASK);

            if (mGrasses.ContainsKey(key))
            {
                RedGrassInstance rgi = mGrasses[key];
                if ((int)rgi.Position.y == y)
                {
                    if (mHGrass.ContainsKey(key))
                    {
                        List <RedGrassInstance> rgis = mHGrass[key];
                        mGrasses[key] = rgis[0];
                        rgis.RemoveAt(0);
                        if (rgis.Count == 0)
                        {
                            RGPoolSig.RecycleRGList(rgis);
                            mHGrass.Remove(key);
                        }

                        Dirty = true;
                        return(true);
                    }
                    else
                    {
                        Dirty = true;
                        mGrasses.Remove(key);
                        return(true);
                    }
                }
                else if (mHGrass.ContainsKey(key))
                {
                    int index = mHGrass[key].FindIndex(item0 => (int)item0.Position.y == y);
                    if (index != -1)
                    {
                        mHGrass[key].RemoveAt(index);
                        if (mHGrass[key].Count == 0)
                        {
                            mHGrass.Remove(key);
                        }

                        Dirty = true;
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #9
0
        public void Free()
        {
            lock (this)
            {
                mGrasses.Clear();

                if (mHGrass.Count > 0)
                {
                    foreach (KeyValuePair <int, List <RedGrassInstance> > pair in mHGrass)
                    {
                        pair.Value.Clear();
                        RGPoolSig.RecycleRGList(pair.Value);
                    }
                    mHGrass.Clear();
                }

                Dirty = true;
            }
        }
Beispiel #10
0
        public void Write(RedGrassInstance grass)
        {
            Vector3 pos = grass.Position;
            int     y   = (int)pos.y;
            int     key = PosToKey(Mathf.FloorToInt(pos.x) & MASK, Mathf.FloorToInt(pos.z) & MASK);

            if (mGrasses.ContainsKey(key))
            {
                RedGrassInstance rgi = mGrasses[key];
                if ((int)rgi.Position.y == y)
                {
                    mGrasses[key] = grass;
                }
                else if (mHGrass.ContainsKey(key))
                {
                    List <RedGrassInstance> rgis = mHGrass[key];
                    int index = rgis.FindIndex(item0 => (int)item0.Position.y == y);
                    if (index != -1)
                    {
                        rgis[index] = grass;
                    }
                    else
                    {
                        rgis.Add(grass);
                    }
                }
                else
                {
                    List <RedGrassInstance> rgis = RGPoolSig.GetRGList();
                    rgis.Add(grass);
                    mHGrass[key] = rgis;
                }
            }
            else
            {
                mGrasses.Add(key, grass);
            }

            Dirty = true;
        }
Beispiel #11
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();
        }