From: James Turner Date: Fri, 25 Jan 2013 11:05:16 +0000 (+0100) Subject: State-machine correctness tweaks. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=98b6102e56d1a90fdd65a35b30cfed40cf1f74df;p=simgear.git State-machine correctness tweaks. --- diff --git a/simgear/structure/StateMachine.cxx b/simgear/structure/StateMachine.cxx index e1921739..b9e540c8 100644 --- a/simgear/structure/StateMachine.cxx +++ b/simgear/structure/StateMachine.cxx @@ -93,6 +93,7 @@ public: } StateMachine* _p; + bool _initialised; State_ptr _currentState; StatePtrVec _states; std::vector _transitions; @@ -245,6 +246,8 @@ StateMachine::StateMachine() : d(new StateMachinePrivate(this)) { d->_root = new SGPropertyNode(); + d->_listenerLockout = false; + d->_initialised = false; } StateMachine::~StateMachine() @@ -254,7 +257,13 @@ 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); @@ -269,8 +278,8 @@ void StateMachine::init() d->_timeInStateProp->setIntValue(0); // TODO go to default state if found - d->computeEligibleTransitions(); - + innerChangeState(d->_states[0], NULL); + d->_initialised = true; } void StateMachine::shutdown() @@ -282,7 +291,9 @@ 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) {