예제 #1
0
bool StateMachine::triggerEvent(const std::string &event)
{
    bool ret = false;
    std::string current = getCurrentStateName();
    std::vector<Rule::ptr>::iterator iter;
    for (iter = rules_.begin(); iter < rules_.end(); ++iter)
    {
        Rule *rule = (*iter).get();
        if (rule->getEventName() == event)
        {
            if (rule->getStateFrom() == getCurrentStateName())
            {
                std::string stateTo = rule->getStateTo();
                if (hasStateName(stateTo))
                {
                    setCurrentStateName(stateTo);
                    on_state_changed_signal_(stateTo);
                    ret = true;
                    break;
                }
            }
        }
    }
    return ret;
}
예제 #2
0
파일: FSM.cpp 프로젝트: FaithZL/utils
void FSM::translateToStateNextUpdateNoRepeat(int stateName)
{
	if (getCurrentStateName() != stateName)
	{
		this->translateToStateNextUpdate(stateName);
	}
}
void ofxStateMachine<T>::setError(string msg, float retryAgainInSeconds, int maxRetries_){

	error = true;
	errorMsg = msg;
	numRetries++;
	waitTime = retryAgainInSeconds;
	maxRetries = maxRetries_;
	ofLogError("ofxStateMachine") << "Error '" << msg << "' while in state '" << getCurrentStateName() << "' "
	<< "(" << numRetries<< "/" << maxRetries << ")";
	ErrorStateEventArgs errArgs = {state, msg, numRetries};
	ofNotifyEvent(eventStateError, errArgs, this);

};
예제 #4
0
bool StateMachine::setCurrentStateName(const std::string &name)
{
    if (! hasStateName(name))
    {
        std::cout << "StateMachine::" << __FUNCTION__ << ": No such state " << name << std::endl;
        return false;
    }
    if (current_state_ != "")
    {
        getState(getCurrentStateName())->on_leaved_signal_();
    }
    current_state_ = name;
    getState(name)->on_entered_signal_();
    return true;
}
예제 #5
0
파일: FSM.cpp 프로젝트: FaithZL/utils
void FSM::translateToStateNoRepeat(int stateName)
{
	if (!_currentState || getCurrentStateName() != stateName) {
		translateToState(stateName);
	}
}