Example #1
0
    // Update function set
    //=====================
    void UpdateIdle()
    {
        int n = _lstIdle.Count;

        //Profiler.BeginSample ("UpdateIdle:"+n);
        for (int i = n - 1; i >= 0; i--)
        {
            ISceneObjAgent obj = _lstIdle[i];
            if (IntoInactive(obj))
            {
                _lstIdle.RemoveAt(i);
                _toConstruct.Add(obj);
                _lstInactive.Add(obj);
                _dirtyLstInactive = true;
            }
        }
        n = _toConstruct.Count;
        if (n > 0)
        {
            for (int i = n - 1; i >= 0; i--)
            {
                _toConstruct[i].OnConstruct();
            }
            _toConstruct.Clear();
        }
        _dirtyLstIdle = false;
        //Profiler.EndSample ();
    }
Example #2
0
    void UpdateInactive()
    {
        int n = _lstInactive.Count;

        //Profiler.BeginSample ("UpdateInactive:"+n);
        for (int i = n - 1; i >= 0; i--)
        {
            ISceneObjAgent obj = _lstInactive[i];
            if (ExitInactive(obj))
            {
                _lstInactive.RemoveAt(i);
                _toDestruct.Add(obj);
                _lstIdle.Add(obj);
                _dirtyLstIdle = true;
            }
            else if (obj.NeedToActivate && IntoActive(obj))
            {
                _lstInactive.RemoveAt(i);
                _lstToActive.Add(obj);
                //_dirtyLstToActive = true;
            }
        }
        n = _toDestruct.Count;
        if (n > 0)
        {
            for (int i = n - 1; i >= 0; i--)
            {
                _toDestruct[i].OnDestruct();
            }
            _toDestruct.Clear();
        }
        _dirtyLstInactive = false;
        //Profiler.EndSample ();
    }
Example #3
0
    // Return : 0:not in sceneman; 1: in idle; 2: in inactive; 3: in toactive; 4: in active
    public static int RemoveSceneObj(ISceneObjAgent obj)
    {
        if (null == self)
        {
            return(0);
        }

        if (self._lstIsActive.Remove(obj))
        {
            return(4);
        }
        if (self._lstToActive.Remove(obj))
        {
            return(3);
        }
        if (self._lstInactive.Remove(obj))
        {
            return(2);
        }
        if (self._lstIdle.Remove(obj))
        {
            return(1);
        }
        return(0);
    }
Example #4
0
    public static void AddSceneObj(ISceneObjAgent obj)
    {
        if (null == self)
        {
            return;
        }
#if SceneWithOnlyPlayer
        if (!(obj is Pathea.LodCmpt))
        {
            return;
        }
        if (((Pathea.LodCmpt)obj).Entity.commonCmpt == null)
        {
            return;
        }
        if (!((Pathea.LodCmpt)obj).Entity.commonCmpt.IsPlayer)
        {
            return;
        }
#endif

        if (obj.Id == InvalidID)
        {
            obj.Id = self._idGen.Fetch();
        }
        self._lstIdle.Add(obj);
        self._dirtyLstIdle = true;
    }
Example #5
0
    public static RaycastHit[] DependenceHitTst(ISceneObjAgent agent)
    {
        float   rayLen = agent.TstYOnActivate ? (agent.Pos.y + 1) : SceneMan.MaxHitTstHeight;
        Vector3 pos    = new Vector3(agent.Pos.x, rayLen, agent.Pos.z);

        RaycastHit[] ret = Physics.RaycastAll(pos, Vector3.down, rayLen, SceneMan.DependenceLayer);
        return((ret == null || ret.Length == 0) ? null : ret);
    }
Example #6
0
    void UpdateToActive()
    {
        int n = _lstToActive.Count;

        //Profiler.BeginSample ("UpdateToActive:"+n);
        for (int i = n - 1; i >= 0; i--)
        {
            ISceneObjAgent obj = _lstToActive[i];
            if (!IntoActive(obj))
            {
                _lstToActive.RemoveAt(i);
                _lstInactive.Add(obj);
                _dirtyLstInactive = true;
            }
            else                // Test collider and Activate it
            {
                bool             allDp = true;
                EDependChunkType type  = 0;
                int nDp = _lstActDependences.Count;
                for (int iDp = 0; iDp < nDp; iDp++)
                {
                    ISceneObjActivationDependence dp = _lstActDependences[iDp];
                    if (!dp.IsDependableForAgent(obj, ref type))
                    {
                        allDp = false;
                        break;
                    }
                }
                if (allDp)
                {
                    //if((type&EDependChunkType.ChunkColMask) == 0 || null != DependenceHitTst(obj))
                    {
                        _lstToActive.RemoveAt(i);
                        _toActivate.Add(obj);
                        _lstIsActive.Add(obj);
                    }
                }
            }
        }
        n = _toActivate.Count;
        if (n > 0)
        {
            for (int i = n - 1; i >= 0; i--)
            {
                _toActivate[i].OnActivate();
            }
            _toActivate.Clear();
        }
        //_dirtyLstToActive = false;
        //Profiler.EndSample ();
    }
Example #7
0
    void UpdateIsActive()
    {
        int n = _lstIsActive.Count;

        //Profiler.BeginSample ("UpdateIsActive:"+n);
        for (int i = n - 1; i >= 0; i--)
        {
            ISceneObjAgent obj = _lstIsActive[i];
            if (ExitActive(obj))
            {
                _lstIsActive.RemoveAt(i);
                _toDeactivate.Add(obj);
                _lstInactive.Add(obj);
                _dirtyLstInactive = true;
            }
            else if (_dirtyLstIsActive)
            {
                bool             allDp = true;
                EDependChunkType type  = 0;
                int nDp = _lstActDependences.Count;
                for (int iDp = 0; iDp < nDp; iDp++)
                {
                    ISceneObjActivationDependence dp = _lstActDependences[iDp];
                    if (!dp.IsDependableForAgent(obj, ref type))
                    {
                        allDp = false;
                        break;
                    }
                }
                if (!allDp)
                {
                    _lstIsActive.RemoveAt(i);
                    _toDeactivate.Add(obj);
                    _lstInactive.Add(obj);
                    _dirtyLstInactive = true;
                }
            }
        }
        n = _toDeactivate.Count;
        if (n > 0)
        {
            for (int i = n - 1; i >= 0; i--)
            {
                _toDeactivate[i].OnDeactivate();
            }
            _toDeactivate.Clear();
        }
        _dirtyLstIsActive = false;
        //Profiler.EndSample ();
    }
Example #8
0
    bool ExitActive(ISceneObjAgent obj)
    {
#if BoundCheckEnable
        if (obj.Bound != null)
        {
            return(!obj.Bound.Intersection(ref _curBoundsActive, obj.TstYOnActivate));
        }
#endif
        if (obj.TstYOnActivate)
        {
            return(!_curBoundsActive.Contains(obj.Pos));
        }
        return(!_curRectActive.Contains(new Vector2(obj.Pos.x, obj.Pos.z)));
    }
Example #9
0
    public static ISceneObjAgent GetSceneObjByGo(GameObject go)
    {
        if (null == self || go == null)
        {
            return(null);
        }

        ISceneObjAgent obj = null;

        return((
                   (obj = self._lstIsActive.Find(it => it.Go == go)) != null ||
                   (obj = self._lstToActive.Find(it => it.Go == go)) != null ||
                   (obj = self._lstInactive.Find(it => it.Go == go)) != null ||
                   (obj = self._lstIdle.Find(it => it.Go == go)) != null) ? obj : null);
    }
Example #10
0
    //public static bool RemoveSceneObjById(int id)
    //{
    //    if (null == self || InvalidID == id) return false;

    //    return
    //        self._lstIsActive.RemoveAll(it => it.Id == id) > 0 ||
    //        self._lstToActive.RemoveAll(it => it.Id == id) > 0 ||
    //        self._lstInactive.RemoveAll(it => it.Id == id) > 0 ||
    //        self._lstIdle.RemoveAll(it => it.Id == id) > 0;
    //}

    public static ISceneObjAgent GetSceneObjById(int id)
    {
        if (null == self || InvalidID == id)
        {
            return(null);
        }

        ISceneObjAgent obj = null;

        return((
                   (obj = self._lstIsActive.Find(it => it.Id == id)) != null ||
                   (obj = self._lstToActive.Find(it => it.Id == id)) != null ||
                   (obj = self._lstInactive.Find(it => it.Id == id)) != null ||
                   (obj = self._lstIdle.Find(it => it.Id == id)) != null) ? obj : null);
    }
Example #11
0
    public bool IsDependableForAgent(ISceneObjAgent agent, ref EDependChunkType type)
    {
        int n = _sceneObjs.Count;

        if (Time.frameCount != _nLastFrame)
        {
            _nLastFrame = Time.frameCount;

            _posToCheck.Clear();
            _boundsToCheck.Clear();
            for (int i = 0; i < n; i++)
            {
                ISceneObjAgent dp = _sceneObjs [i];
                if (dp != null && !dp.NeedToActivate && dp.Go == null)
                {
                    if (dp.Bound != null)
                    {
                        _boundsToCheck.Add(dp.Bound);
                    }
                    else
                    {
                        _posToCheck.Add(dp.Pos);
                    }
                }
            }
        }

        n = _posToCheck.Count;
        for (int i = 0; i < n; i++)
        {
            if (Vector3.SqrMagnitude(_posToCheck[i] - agent.Pos) < 64)                  //8m
            {
                return(false);
            }
        }

        n = _boundsToCheck.Count;
        for (int i = 0; i < n; i++)
        {
            if (_boundsToCheck[i].Contains(agent.Pos, agent.TstYOnActivate))
            {
                return(false);
            }
        }
        return(true);
    }
    protected virtual void OnPEDestroy()
    {
        StopAllCoroutines();

        if (null != Runner)
        {
            Runner.InitNetworkLayer(null);
        }

        Pathea.EntityMgr.Instance.Destroy(Id);
        ISceneObjAgent obj = SceneMan.GetSceneObjById(Id);

        if (null != obj)
        {
            SceneMan.RemoveSceneObj(obj);
        }
    }
Example #13
0
    public static void AddSceneObjs <T>(List <T> objs) where T : ISceneObjAgent
    {
        if (null == self)
        {
            return;
        }
#if SceneWithOnlyPlayer
        return;
#endif

        int n = objs.Count;
        for (int i = 0; i < n; i++)
        {
            ISceneObjAgent obj = objs[i];
            if (obj.Id == InvalidID)
            {
                obj.Id = self._idGen.Fetch();
            }
            self._lstIdle.Add(obj);
        }
        self._dirtyLstIdle = true;
    }
Example #14
0
    public static int SetDirty(ISceneObjAgent obj)
    {
        if (null == self)
        {
            return(0);
        }

#if false //these 2 are always true
        if (!self._dirtyLstToActive && self._lstToActive.Contains(obj) && !self._curBoundsActive.Contains(obj.Pos))
        {
            self._dirtyLstToActive = true;
            return(3);
        }
        if (!self._dirtyLstIsActive && self._lstIsActive.Contains(obj))
        {
            self._dirtyLstIsActive = true;
            return(4);
        }
#endif
        //Profiler.BeginSample ("SetDirty");
        // should not in Inactive
        if (!self._dirtyLstInactive && (!self._curBoundsInactive.Contains(obj.Pos) || self._curBoundsActive.Contains(obj.Pos)) && self._lstInactive.Contains(obj))
        {
            self._dirtyLstInactive = true;
            //Profiler.EndSample();
            return(2);
        }
        // should not in Idle
        if (!self._dirtyLstIdle && self._curBoundsInactive.Contains(obj.Pos) && self._lstIdle.Contains(obj))
        {
            self._dirtyLstIdle = true;
            //Profiler.EndSample();
            return(1);
        }
        //Profiler.EndSample();
        return(5);
    }
Example #15
0
    // Return : count of removed objs
    public static int RemoveSceneObjs <T>(List <T> objs) where T : ISceneObjAgent
    {
        if (null == self)
        {
            return(0);
        }

        int ret = 0;
        int n   = objs.Count;

        for (int i = 0; i < n; i++)
        {
            ISceneObjAgent obj = objs[i];
            if (
                self._lstIsActive.Remove(obj) ||
                self._lstToActive.Remove(obj) ||
                self._lstInactive.Remove(obj) ||
                self._lstIdle.Remove(obj))
            {
                ret++;
            }
        }
        return(ret);
    }
Example #16
0
    public bool IsDependableForAgent(ISceneObjAgent agent, ref EDependChunkType type)
    {
        lock (_lstValidChunks)
        {
            Vector3          pos = agent.Pos;
            int              x   = ((int)pos.x) >> LODOctreeMan.Lod0NodeShift;
            int              z   = ((int)pos.z) >> LODOctreeMan.Lod0NodeShift;
            EDependChunkType v   = 0;
            _tmpPos.x = x;
            _tmpPos.z = z;
            _tmpPos.w = 0;
            if (agent.TstYOnActivate)
            {
                int y = ((int)pos.y) >> LODOctreeMan.Lod0NodeShift;
                _tmpPos.y = y;
                GetDependChunkType(_tmpPos, out v);
                if ((v & EDependChunkType.ChunkBlkMask) != 0 &&
                    //(v&EDependChunkType.ChunkWatMask) != 0 &&
                    (v & EDependChunkType.ChunkTerMask) != 0)
                {
                    type |= v;
                    return(true);
                }
                return(false);
            }
            else
            {
                // Note: here may be buggy on ChunkTerCol
                int y = ((int)SceneMan.LastRefreshPos.y) >> LODOctreeMan.Lod0NodeShift;
                _tmpPos.y = y;
                GetDependChunkType(_tmpPos, out v);
                if ((v & EDependChunkType.ChunkBlkMask) != 0 &&
                    //(v&EDependChunkType.ChunkWatCol) != 0 &&
                    (v & EDependChunkType.ChunkTerCol) != 0)
                {
                    type |= v;
                    return(true);
                }

                int ofs = 1;
                while (ofs <= 8)
                {
                    _tmpPos.y = y - ofs;
                    GetDependChunkType(_tmpPos, out v);
                    if ((v & EDependChunkType.ChunkBlkMask) != 0 &&
                        //(v&EDependChunkType.ChunkWatCol) != 0 &&
                        (v & EDependChunkType.ChunkTerCol) != 0)
                    {
                        type |= v;
                        return(true);
                    }
                    _tmpPos.y = y + ofs;
                    GetDependChunkType(_tmpPos, out v);
                    if ((v & EDependChunkType.ChunkBlkMask) != 0 &&
                        //(v&EDependChunkType.ChunkWatCol) != 0 &&
                        (v & EDependChunkType.ChunkTerCol) != 0)
                    {
                        type |= v;
                        return(true);
                    }
                    ofs++;
                }
                return(false);
            }
        }
    }