Example #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);
        }
Example #2
0
 //---------------------------------------------------------------------
 public void _defState(string state_name, int state_group)
 {
     mStrStateName       = state_name;
     miStateGroup        = state_group;
     mStrParentStateName = "";
     mpParentState       = null;
     mbInitState         = true;
 }
Example #3
0
 //---------------------------------------------------------------------
 public void _defState(string state_name, int state_group)
 {
     mStrStateName = state_name;
     miStateGroup = state_group;
     mStrParentStateName = "";
     mpParentState = null;
     mbInitState = true;
 }
Example #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;
 }
Example #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;
 }
Example #6
0
 //---------------------------------------------------------------------
 void _releaseFsm()
 {
     while (mQueCurrentState.Count > 0)
     {
         EbState s = mQueCurrentState[mQueCurrentState.Count - 1];
         s.exit();
         mQueCurrentState.RemoveAt(mQueCurrentState.Count - 1);
     }
 }
Example #7
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;
        }
Example #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;
            }
        }
Example #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);
            }
        }
Example #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);
        }
Example #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);
        }
Example #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;
                    }
                }
            }
        }
Example #13
0
 //---------------------------------------------------------------------
 public void _setParentState(EbState parent)
 {
     mpParentState = parent;
 }
Example #14
0
 //---------------------------------------------------------------------
 public void _setParentState(EbState parent)
 {
     mpParentState = parent;
 }
Example #15
0
        //---------------------------------------------------------------------
        void _rattleOn()
        {
            if (mbRattleOn)
            {
                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);

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

                    if (null == next_state)
                    {
                        break;
                    }

                    while (mQueCurrentState.Count > 0)
                    {
                        EbState s = mQueCurrentState[mQueCurrentState.Count - 1];

                        if (next_state == s)
                        {
                            break;
                        }
                        else if (_isDirectLine(s, next_state))
                        {
                            mQueTmpState.Clear();

                            EbState p = next_state;
                            do
                            {
                                mQueTmpState.Add(p);
                                p = p._getParentState();
                            } while (p != s);

                            while (mQueTmpState.Count > 0)
                            {
                                EbState q = mQueTmpState[0];
                                q.enter();
                                mQueCurrentState.Add(q);
                                mQueTmpState.RemoveAt(0);
                            }
                        }
                        else
                        {
                            s.exit();
                            mQueCurrentState.RemoveAt(mQueCurrentState.Count - 1);
                        }
                    }

                    break;
                }
            }
            mbRattleOn = false;
        }
Example #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;
     }
 }
Example #17
0
 //---------------------------------------------------------------------
 public void addState(EbState state)
 {
     mMapState[state._getStateName()] = state;
 }