示例#1
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();
        }
示例#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);
        }
示例#3
0
    // Calculate a road-cell position in this tile from world position
    public static INTVECTOR3 WorldPosToRoadCellPos_s(int hash, Vector3 wpos)
    {
        INTVECTOR2 tile_pos = new INTVECTOR2();

        tile_pos.hash = hash;
        wpos.x       -= (tile_pos.x * TILE_SIZEF);
        wpos.z       -= (tile_pos.y * TILE_SIZEF);
        return(new INTVECTOR3(wpos.x / CELL_SIZEF, wpos.y / CELL_YSIZEF, wpos.z / CELL_SIZEF));
    }
示例#4
0
    public RSTile GetTile(INTVECTOR2 pos)
    {
        int hash = pos.hash;

        if (m_Tiles.ContainsKey(hash))
        {
            return(m_Tiles[hash]);
        }
        return(null);
    }
示例#5
0
 public override bool Equals(object obj)
 {
     if (null == obj)
     {
         return(false);
     }
     if (obj is INTVECTOR2)
     {
         INTVECTOR2 vec = (INTVECTOR2)obj;
         return(x == vec.x && y == vec.y);
     }
     return(false);
 }
示例#6
0
        public void RefreshImmediately()
        {
            Transform trans = tracedObj == null ? PETools.PEUtil.MainCamTransform : tracedObj;

            Vector3 pos         = trans.position;
            int     cur_chunk_x = Mathf.FloorToInt(pos.x) >> evniAsset.SHIFT;
            int     cur_chunk_z = Mathf.FloorToInt(pos.z) >> evniAsset.SHIFT;

            data.RefreshImmediately(cur_chunk_x, cur_chunk_z);

            mCenter = new INTVECTOR2(cur_chunk_x, cur_chunk_z);

            UpdateMeshImmediately();
        }
示例#7
0
    private void AddRenderer(INTVECTOR2 pos)
    {
        int hash = pos.hash;

        if (!m_Renderers.ContainsKey(hash))
        {
            RSTileRenderer tr = RSTileRenderer.Instantiate(m_RendererResource) as RSTileRenderer;
            tr.gameObject.name      = "Road Tile " + pos.ToString();
            tr.transform.parent     = m_RendererGroup;
            tr.transform.position   = new Vector3(pos.x * RSTile.TILE_SIZE, 0, pos.y * RSTile.TILE_SIZE);
            tr.transform.rotation   = Quaternion.identity;
            tr.transform.localScale = Vector3.one;
            tr.m_DataSource         = m_DataSource;
            tr.m_Pos = pos;
            m_Renderers.Add(hash, tr);
        }
    }
示例#8
0
        /// <summary>
        /// Init Renderer part of Vars and Functions
        /// </summary>
        void Init_Render()
        {
            mRenderCenter = new INTVECTOR2(-10000, -10000);
            mTree         = new RGLODQuadTree(evniAsset);
            mRootNodes    = new Dictionary <int, RGLODQuadTreeNode>();
            mTargetNodes  = new Dictionary <int, RGLODQuadTreeNode>();

            mTailNodes = new Dictionary <int, Dictionary <int, RGLODQuadTreeNode> >();

            int maxlod = evniAsset.MaxLOD;

            mXLodIndex = new int[maxlod + 1];
            mZLodIndex = new int[maxlod + 1];
            mInitIndex = true;

            if (meshCreator != null)
            {
                meshCreator.Init(evniAsset, data);
            }
        }
示例#9
0
 public INTVECTOR2(INTVECTOR2 vec)
 {
     x = vec.x;
     y = vec.y;
 }
示例#10
0
 public float Distance(INTVECTOR2 vec)
 {
     return(Mathf.Sqrt((vec.x - x) * (vec.x - x) +
                       (vec.y - y) * (vec.y - y)));
 }
示例#11
0
        public void UpdateMeshImmediately()
        {
            lock (meshCreator.procLockObj)
            {
                meshCreator.StopProcess();

                mRenderCenter = mCenter;

                List <GameObject> gos = new List <GameObject>();
                Dictionary <int, RGLODQuadTreeNode> roots = mTree.GetRootNodes();

                foreach (RGLODQuadTreeNode node in roots.Values)
                {
                    if (node != null)
                    {
                        mTree.TraversalNode(node, item0 =>
                        {
                            item0.UpdateTimeStamp();
                            if (item0.gameObject != null)
                            {
                                gos.Add(item0.gameObject);
                                item0.gameObject = null;
                            }
                        });
                    }
                }

                meshCreator.ClearMeshes(gos);


                // Update Tree
                int maxLod = evniAsset.MaxLOD;

                UpdateLodIndex();

                for (int i = maxLod; i >= 0; i--)
                {
                    int _x = 0;
                    int _z = 0;

                    if (mRenderCenter.x >= 0)
                    {
                        _x = mRenderCenter.x / (1 << i) * (1 << i);
                    }
                    else
                    {
                        _x = mRenderCenter.x / (1 << i) * (1 << i) - (1 << i);
                    }

                    if (mRenderCenter.y >= 0)
                    {
                        _z = mRenderCenter.y / (1 << i) * (1 << i);
                    }
                    else
                    {
                        _z = mRenderCenter.y / (1 << i) * (1 << i) - (1 << i);
                    }

                    mXLodIndex[i] = _x;
                    mZLodIndex[i] = _z;
                    mTree.UpdateTree(i, mXLodIndex[i], mZLodIndex[i]);
                }

                mTargetNodes = mTree.GetRootNodes();
                mRootNodes   = mTargetNodes;

                foreach (KeyValuePair <int, RGLODQuadTreeNode> kvp in mTargetNodes)
                {
                    List <RGLODQuadTreeNode> new_list = new List <RGLODQuadTreeNode>();
                    List <GameObject>        old_list = new List <GameObject>();

                    TraverseNode(kvp.Value, old_list, new_list);

                    RGRegion region = new RGRegion();
                    region.nodes  = new_list;
                    region.oldGos = old_list;
                    meshCreator.AddReqs(region);
                }

                meshCreator.ProcessReqsImmediatly();
            }
        }
示例#12
0
        /// <summary>
        /// Updates the rendering of LOD Meshes, and Add the requests to
        /// the creator.
        /// </summary>
        public void UpdateMesh()
        {
            if (meshCreator.isActive())
            {
                return;
            }

            if (!mUpdateMesh)
            {
                return;
            }


            mUpdateMesh = false;

            mRenderCenter = mCenter;

            // Update Tree
            int maxLod = evniAsset.MaxLOD;

            if (!mInitIndex)
            {
                for (int i = maxLod; i >= 0; i--)
                {
                    int _x = 0;
                    int _z = 0;

                    if (mRenderCenter.x >= 0)
                    {
                        _x = mRenderCenter.x / (1 << i) * (1 << i);
                    }
                    else
                    {
                        _x = mRenderCenter.x / (1 << i) * (1 << i) - (1 << i);
                    }

                    if (mRenderCenter.y >= 0)
                    {
                        _z = mRenderCenter.y / (1 << i) * (1 << i);
                    }
                    else
                    {
                        _z = mRenderCenter.y / (1 << i) * (1 << i) - (1 << i);
                    }

                    if (_x != mXLodIndex[i] || _z != mZLodIndex[i])
                    {
                        mXLodIndex[i] = _x;
                        mZLodIndex[i] = _z;
                        mTree.UpdateTree(i, mXLodIndex[i], mZLodIndex[i]);
                    }
                }
            }
            else
            {
                for (int i = maxLod; i >= 0; i--)
                {
                    int _x = 0;
                    int _z = 0;

                    if (mRenderCenter.x >= 0)
                    {
                        _x = mRenderCenter.x / (1 << i) * (1 << i);
                    }
                    else
                    {
                        _x = mRenderCenter.x / (1 << i) * (1 << i) - (1 << i);
                    }

                    if (mRenderCenter.y >= 0)
                    {
                        _z = mRenderCenter.y / (1 << i) * (1 << i);
                    }
                    else
                    {
                        _z = mRenderCenter.y / (1 << i) * (1 << i) - (1 << i);
                    }

                    mXLodIndex[i] = _x;
                    mZLodIndex[i] = _z;
                    mTree.UpdateTree(i, mXLodIndex[i], mZLodIndex[i]);
                }

                mInitIndex = false;
            }


            //
            mTargetNodes = mTree.GetRootNodes();

            DestroyExtraGo();

            mRootNodes = mTargetNodes;

            int count = 0;

            foreach (KeyValuePair <int, RGLODQuadTreeNode> kvp in mTargetNodes)
            {
                List <RGLODQuadTreeNode> new_list = new List <RGLODQuadTreeNode>();
                List <GameObject>        old_list = new List <GameObject>();

                TraverseNode(kvp.Value, old_list, new_list);

                if (new_list.Count != 0)
                {
                    count++;
                }


                RGRegion region = new RGRegion();
                region.nodes  = new_list;
                region.oldGos = old_list;
                meshCreator.AddReqs(region);
            }

            meshCreator.Active(null);
        }