Ejemplo n.º 1
0
        //---------------------------------------------------------------------
        bool _initFsm(EbState state)
        {
            bool is_initstate = state._isInitState();

            if (!is_initstate)
            {
                return(false);
            }

            state.enter();

            mQueCurrentState.Add(state);

            var map_childstate = state._getMapChildState();

            if (map_childstate.ContainsKey(0))
            {
                var v = map_childstate[0];
                foreach (var itc in v)
                {
                    if (_initFsm(itc))
                    {
                        return(true);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
 //---------------------------------------------------------------------
 public void _defState(string state_name, int state_group)
 {
     mStrStateName       = state_name;
     miStateGroup        = state_group;
     mStrParentStateName = "";
     mpParentState       = null;
     mbInitState         = true;
 }
Ejemplo n.º 3
0
 //---------------------------------------------------------------------
 public void _defState(string state_name, int state_group)
 {
     mStrStateName = state_name;
     miStateGroup = state_group;
     mStrParentStateName = "";
     mpParentState = null;
     mbInitState = true;
 }
Ejemplo n.º 4
0
 //---------------------------------------------------------------------
 public void _defState(string state_name, string parent_state_name,
                       int state_group, bool init_state)
 {
     mStrStateName       = state_name;
     miStateGroup        = state_group;
     mStrParentStateName = parent_state_name;
     mpParentState       = null;
     mbInitState         = init_state;
 }
Ejemplo n.º 5
0
 //---------------------------------------------------------------------
 public void _defState(string state_name, string parent_state_name,
     int state_group, bool init_state)
 {
     mStrStateName = state_name;
     miStateGroup = state_group;
     mStrParentStateName = parent_state_name;
     mpParentState = null;
     mbInitState = init_state;
 }
Ejemplo n.º 6
0
        //---------------------------------------------------------------------
        void _rattleOn()
        {
            if (mbRattleOn || mbDestroy)
            {
                return;
            }
            mbRattleOn = true;

            while (mQueEvent.Count > 0)
            {
                IEbEvent ev = mQueEvent.Dequeue();

                for (int i = mQueCurrentState.Count - 1; i >= 0; i--)
                {
                    var it = mQueCurrentState[i];

                    EbState state = it;

                    if (!state._isBindEvent(ev.name))
                    {
                        continue;
                    }

                    string next_state_name = state._onEvent(ev);

                    if (string.IsNullOrEmpty(next_state_name))
                    {
                        continue;
                    }
                    if (mbDestroy)
                    {
                        break;
                    }

                    EbState next_state = null;
                    if (mMapState.ContainsKey(next_state_name))
                    {
                        next_state = mMapState[next_state_name];
                    }

                    if (next_state == null)
                    {
                        break;
                    }

                    EbState p = next_state._getParentState();

                    _exitChildState(p);

                    _enterState(next_state);

                    break;
                }
            }
            mbRattleOn = false;
        }
Ejemplo n.º 7
0
        //---------------------------------------------------------------------
        void _releaseFsm()
        {
            mbDestroy = true;

            while (mQueCurrentState.Count > 0)
            {
                EbState s = mQueCurrentState[mQueCurrentState.Count - 1];
                s.exit();
                mQueCurrentState.RemoveAt(mQueCurrentState.Count - 1);
            }
        }
Ejemplo n.º 8
0
        //---------------------------------------------------------------------
        public void _addChildState(EbState child)
        {
            int group = child._getStateGroup();

            if (mMapChildState.ContainsKey(group))
            {
                mMapChildState[group].Add(child);
            }
            else
            {
                List <EbState> v = new List <EbState>();
                v.Add(child);
                mMapChildState[group] = v;
            }
        }
Ejemplo n.º 9
0
        //---------------------------------------------------------------------
        void _exitChildState(EbState cur_state)
        {
            if (mQueCurrentState.Count == 0)
            {
                return;
            }

            EbState s = mQueCurrentState[mQueCurrentState.Count - 1];

            if (s != cur_state)
            {
                s.exit();

                mQueCurrentState.Remove(s);

                _exitChildState(cur_state);
            }
        }
Ejemplo n.º 10
0
        //---------------------------------------------------------------------
        public void setupFsm()
        {
            // 建立所有状态父子关系
            foreach (var it in mMapState)
            {
                EbState state             = it.Value;
                var     parent_state_name = state._getParentStateName();
                if (mMapState.ContainsKey(parent_state_name))
                {
                    var parent_state = mMapState[parent_state_name];
                    state._setParentState(parent_state);
                    parent_state._addChildState(state);
                }
            }

            // 初始化当前状态列表
            _initFsm(this);
        }
Ejemplo n.º 11
0
        //---------------------------------------------------------------------
        bool _isDirectLine(EbState parent, EbState child)
        {
            if (parent == child)
            {
                return(true);
            }

            Dictionary <int, List <EbState> > map_childstate = parent._getMapChildState();

            if (map_childstate.ContainsKey(0))
            {
                var v = map_childstate[0];
                foreach (var itc in v)
                {
                    if (_isDirectLine(itc, child))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 12
0
        //---------------------------------------------------------------------
        void _enterState(EbState next_state)
        {
            next_state.enter();
            mQueCurrentState.Add(next_state);

            var map_childstate = next_state._getMapChildState();

            foreach (var i in map_childstate)
            {
                if (i.Value == null)
                {
                    continue;
                }

                foreach (var s in i.Value)
                {
                    if (s._isInitState())
                    {
                        _enterState(s);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 13
0
 //---------------------------------------------------------------------
 public void addState(EbState state)
 {
     mMapState[state._getStateName()] = state;
 }
Ejemplo n.º 14
0
 //---------------------------------------------------------------------
 public void _setParentState(EbState parent)
 {
     mpParentState = parent;
 }
Ejemplo n.º 15
0
 //---------------------------------------------------------------------
 public void _setParentState(EbState parent)
 {
     mpParentState = parent;
 }
Ejemplo n.º 16
0
 //---------------------------------------------------------------------
 public void _addChildState(EbState child)
 {
     int group = child._getStateGroup();
     if (mMapChildState.ContainsKey(group))
     {
         mMapChildState[group].Add(child);
     }
     else
     {
         List<EbState> v = new List<EbState>();
         v.Add(child);
         mMapChildState[group] = v;
     }
 }