| 106 | } |
| 107 | |
| 108 | void ActionManager::update( const Time& time, Action** actions, size_t count ) { |
| 109 | std::vector<Action*> removeList; |
| 110 | std::vector<Action*> deferredRemoveList; |
| 111 | |
| 112 | // Copy the deferred remove list under lock to avoid data races during the loop. |
| 113 | { |
| 114 | Lock l( mMutex ); |
| 115 | if ( !mActionsRemoveList.empty() ) |
| 116 | deferredRemoveList = mActionsRemoveList; |
| 117 | } |
| 118 | |
| 119 | for ( size_t i = 0; i < count; i++ ) { |
| 120 | Action* action = actions[i]; |
| 121 | |
| 122 | if ( std::find( deferredRemoveList.begin(), deferredRemoveList.end(), action ) != |
| 123 | deferredRemoveList.end() ) |
| 124 | continue; |
| 125 | |
| 126 | action->update( time ); |
| 127 | |
| 128 | if ( action->isDone() ) { |
| 129 | action->sendEvent( Action::ActionType::OnDone ); |
| 130 | |
| 131 | removeList.emplace_back( action ); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | mUpdating = false; |
| 136 | |
| 137 | // Atomically get the list of deferred removals and clear the shared list. |
| 138 | { |
| 139 | Lock l( mMutex ); |
| 140 | deferredRemoveList.clear(); // Reuse the vector |
| 141 | deferredRemoveList.swap( mActionsRemoveList ); |
| 142 | } |
| 143 | |
| 144 | // Process actions that were queued for removal. |
| 145 | for ( auto it = deferredRemoveList.begin(); it != deferredRemoveList.end(); ++it ) |
| 146 | removeAction( *it ); |
| 147 | |
| 148 | // Process actions that finished during this update. |
| 149 | for ( auto it = removeList.begin(); it != removeList.end(); ++it ) |
| 150 | removeAction( *it ); |
| 151 | } |
| 152 | |
| 153 | void ActionManager::update( const Time& time ) { |
| 154 | if ( isEmpty() ) |
nothing calls this directly
no test coverage detected