Changeset 27702
- Timestamp:
- Jun 14, 2023, 4:58:37 PM (14 months ago)
- Location:
- ps/trunk/source/network
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/source/network/FSM.cpp
r27385 r27702 44 44 { 45 45 m_Actions.clear(); 46 m_Conditions.clear();47 46 } 48 47 … … 58 57 } 59 58 60 void CFsmTransition::RegisterCondition(void* pCondition, void* pContext)61 {62 CallbackFunction callback;63 64 // Add condition at the end of conditions list65 callback.pFunction = pCondition;66 callback.pContext = pContext;67 68 m_Conditions.push_back(callback);69 }70 71 59 void CFsmTransition::SetEvent(CFsmEvent* pEvent) 72 60 { … … 77 65 { 78 66 m_NextState = nextState; 79 }80 81 bool CFsmTransition::ApplyConditions() const82 {83 bool eval = true;84 85 CallbackList::const_iterator it = m_Conditions.begin();86 for (; it != m_Conditions.end(); ++it)87 {88 if (it->pFunction)89 {90 // Evaluate condition91 Condition* condition = reinterpret_cast<Condition*>(it->pFunction);92 eval &= condition(it->pContext);93 }94 }95 96 return eval;97 67 } 98 68 … … 286 256 } 287 257 288 // Valid transition?289 if (!pTransition->ApplyConditions())290 return false;291 292 258 // Save the default state transition (actions might call SetNextState 293 259 // to override this) -
ps/trunk/source/network/FSM.h
r27385 r27702 31 31 class CFsm; 32 32 33 using Condition = bool(void* pContext);34 33 using Action = bool(void* pContext, const CFsmEvent* pEvent); 35 34 … … 77 76 78 77 /** 79 * An association of event, condition,action and next state.78 * An association of event, action and next state. 80 79 */ 81 80 class CFsmTransition … … 95 94 96 95 /** 97 * Registers a condition which will be evaluated when the transition occurs.98 * @param pCondition the predicate which will be executed.99 * @param pContext data passed to the predicate.100 */101 void RegisterCondition(void* pCondition, void* pContext);102 103 /**104 96 * Set event for which transition will occur. 105 97 */ … … 128 120 return m_Actions; 129 121 } 130 131 const CallbackList& GetConditions() const132 {133 return m_Conditions;134 }135 136 /**137 * Evaluates conditions for the transition.138 * @return whether all the conditions are true.139 */140 bool ApplyConditions() const;141 122 142 123 /** … … 152 133 CFsmEvent* m_Event; 153 134 CallbackList m_Actions; 154 CallbackList m_Conditions;155 135 }; 156 136 … … 181 161 182 162 /** 183 * Clear event, action and conditionlists and reset state machine.163 * Clear event, action lists and reset state machine. 184 164 */ 185 165 void Shutdown();
Note:
See TracChangeset
for help on using the changeset viewer.