}
StateMachine* _p;
+ bool _initialised;
State_ptr _currentState;
StatePtrVec _states;
std::vector<Transition_ptr> _transitions;
d(new StateMachinePrivate(this))
{
d->_root = new SGPropertyNode();
+ d->_listenerLockout = false;
+ d->_initialised = false;
}
StateMachine::~StateMachine()
void StateMachine::init()
{
+ if (d->_initialised) {
+ return;
+ }
+ if (d->_states.empty()) {
+ throw sg_range_exception("StateMachine::init: no states defined");
+ }
d->_currentStateIndex = d->_root->getChild("current-index", 0, true);
d->_currentStateIndex->setIntValue(0);
d->_timeInStateProp->setIntValue(0);
// TODO go to default state if found
- d->computeEligibleTransitions();
-
+ innerChangeState(d->_states[0], NULL);
+ d->_initialised = true;
}
void StateMachine::shutdown()
void StateMachine::innerChangeState(State_ptr aState, Transition_ptr aTrans)
{
- d->_currentState->fireExitBindings();
+ if (d->_currentState) {
+ d->_currentState->fireExitBindings();
+ }
// fire bindings before we change the state, hmmmm
if (aTrans) {