Allow AIStateMachine::kill to be called while not running.

This can be used for example when a parent statemachine has
a child statemachine and wants to kill() it upon finish.
This commit is contained in:
Aleric Inglewood
2012-02-16 01:10:48 +01:00
parent 42518dbfaa
commit 9b4b234c12

View File

@@ -254,19 +254,25 @@ void AIStateMachine::finish(void)
// Fix the final state. // Fix the final state.
if (mState == bs_callback) if (mState == bs_callback)
mState = default_delete ? bs_killed : bs_initialize; mState = default_delete ? bs_killed : bs_initialize;
} if (mState == bs_killed && mActive == as_idle)
void AIStateMachine::kill(void)
{
// Should only be called from finish().
llassert(mIdle && (mState == bs_callback || mState == bs_finish));
if (mState == bs_callback && mActive == as_idle)
{ {
// Bump the statemachine onto the active statemachine list, or else it won't be deleted. // Bump the statemachine onto the active statemachine list, or else it won't be deleted.
cont(); cont();
idle(); idle();
} }
}
void AIStateMachine::kill(void)
{
// Should only be called from finish() (or when not running (bs_initialize)).
llassert(mIdle && (mState == bs_callback || mState == bs_finish || mState == bs_initialize));
base_state_type prev_state = mState;
mState = bs_killed; mState = bs_killed;
if (prev_state == bs_initialize)
{
// We're not running (ie being deleted by a parent statemachine), delete it immediately.
delete this;
}
} }
// Return stringified 'state'. // Return stringified 'state'.