Exemple #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);
        }
Exemple #2
0
 //---------------------------------------------------------------------
 public void _defState(string state_name, int state_group)
 {
     mStrStateName       = state_name;
     miStateGroup        = state_group;
     mStrParentStateName = "";
     mpParentState       = null;
     mbInitState         = true;
 }
Exemple #3
0
 //---------------------------------------------------------------------
 void _releaseFsm()
 {
     while (mQueCurrentState.Count > 0)
     {
         EbState s = mQueCurrentState[mQueCurrentState.Count - 1];
         s.exit();
         mQueCurrentState.RemoveAt(mQueCurrentState.Count - 1);
     }
 }
Exemple #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;
 }
Exemple #5
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;
            }
        }
Exemple #6
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);
        }
Exemple #7
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);
        }
Exemple #8
0
 //---------------------------------------------------------------------
 public void addState(EbState state)
 {
     mMapState[state._getStateName()] = state;
 }
Exemple #9
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;
        }
Exemple #10
0
 //---------------------------------------------------------------------
 public void _setParentState(EbState parent)
 {
     mpParentState = parent;
 }