diff --git a/indra/aistatemachine/aistatemachine.cpp b/indra/aistatemachine/aistatemachine.cpp index 642be5d2f..cec58baec 100644 --- a/indra/aistatemachine/aistatemachine.cpp +++ b/indra/aistatemachine/aistatemachine.cpp @@ -1173,6 +1173,16 @@ void AIStateMachine::yield(AIEngine* engine) mYieldEngine = engine; } +bool AIStateMachine::yield_if_not(AIEngine* engine) +{ + if (engine && multiplex_state_type_rat(mState)->current_engine != engine) + { + yield(engine); + return true; + } + return false; +} + void AIStateMachine::yield_frame(unsigned int frames) { DoutEntering(dc::statemachine(mSMDebug), "AIStateMachine::yield_frame(" << frames << ") [" << (void*)this << "]"); diff --git a/indra/aistatemachine/aistatemachine.h b/indra/aistatemachine/aistatemachine.h index 0086c03a7..2e5a47acc 100644 --- a/indra/aistatemachine/aistatemachine.h +++ b/indra/aistatemachine/aistatemachine.h @@ -237,6 +237,7 @@ class AIStateMachine : public LLThreadSafeRefCount void yield(AIEngine* engine); // Yield to give CPU to other state machines, but do not go idle. Continue running from engine 'engine'. void yield_frame(unsigned int frames); // Run from the main-thread engine after at least 'frames' frames have passed. void yield_ms(unsigned int ms); // Run from the main-thread engine after roughly 'ms' miliseconds have passed. + bool yield_if_not(AIEngine* engine); // Do not really yield, unless the current engine is not 'engine'. Returns true if it switched engine. public: // This function can be called from multiplex_imp(), but also by a child state machine and