| 171 | | enum State |
| 172 | | { |
| 173 | | Play, |
| 174 | | Stop |
| 175 | | }; |
| 176 | | |
| 177 | | |
| 178 | | ActionLayers _actions; |
| 179 | | double _lastUpdate; |
| 180 | | double _speed; |
| 181 | | unsigned int _currentFrame; |
| 182 | | unsigned int _fps; |
| 183 | | unsigned int _numberFrame; |
| 184 | | unsigned int _previousFrameEvaluated; |
| 185 | | bool _loop; |
| 186 | | bool _initFirstFrame; |
| 187 | | |
| 188 | | State _state; |
| 189 | | |
| 190 | | // to manage pending operation |
| 191 | | bool _evaluating; |
| 192 | | |
| 193 | | struct Command |
| 194 | | { |
| 195 | | Command():_priority(0) {} |
| 196 | | Command(int priority, const FrameAction& action) : _priority(priority), _action(action) {} |
| 197 | | int _priority; |
| 198 | | FrameAction _action; |
| 199 | | }; |
| 200 | | |
| 201 | | typedef std::vector<Command> CommandList; |
| 202 | | CommandList _addActionOperations; |
| 203 | | ActionList _removeActionOperations; |
| 204 | | |
| 205 | | void setEvaluating(bool state) { _evaluating = state;} |
| 206 | | void processPendingOperation() |
| 207 | | { |
| 208 | | // process all pending add action operation |
| 209 | | while( !_addActionOperations.empty()) |
| 210 | | { |
| 211 | | internalAddAction(_addActionOperations.back()._priority, _addActionOperations.back()._action); |
| 212 | | _addActionOperations.pop_back(); |
| 213 | | } |
| 214 | | |
| 215 | | // process all pending remove action operation |
| 216 | | while( !_removeActionOperations.empty()) |
| 217 | | { |
| 218 | | internalRemoveAction(_removeActionOperations.back().second.get()); |
| 219 | | _removeActionOperations.pop_back(); |
| 220 | | } |
| 221 | | } |
| 222 | | |
| 223 | | void internalRemoveAction(Action* action) |
| 224 | | { |
| 225 | | for (ActionLayers::iterator it = _actions.begin(); it != _actions.end(); it++) |
| 226 | | { |
| 227 | | ActionList& fa = it->second; |
| 228 | | for (unsigned int i = 0; i < fa.size(); i++) |
| 229 | | if (fa[i].second.get() == action) |
| 230 | | { |
| 231 | | fa.erase(fa.begin() + i); |
| 232 | | return; |
| 233 | | } |
| 234 | | } |
| 235 | | } |
| 236 | | void internalAddAction(int priority, const FrameAction& ftl) |
| 237 | | { |
| 238 | | _actions[priority].push_back(ftl); |
| 239 | | } |
| 240 | | |
| 241 | | public: |
| 242 | | |
| 243 | | META_Object(osgAnimation, Timeline); |
| 244 | | |
| 245 | | Timeline(); |
| 246 | | Timeline(const Timeline& nc,const osg::CopyOp& op = osg::CopyOp::SHALLOW_COPY); |
| 247 | | State getStatus() const { return _state; } |
| | 185 | |
| | 315 | |
| | 316 | protected: |
| | 317 | |
| | 318 | |
| | 319 | ActionLayers _actions; |
| | 320 | double _lastUpdate; |
| | 321 | double _speed; |
| | 322 | unsigned int _currentFrame; |
| | 323 | unsigned int _fps; |
| | 324 | unsigned int _numberFrame; |
| | 325 | unsigned int _previousFrameEvaluated; |
| | 326 | bool _loop; |
| | 327 | bool _initFirstFrame; |
| | 328 | |
| | 329 | Status _state; |
| | 330 | |
| | 331 | // to manage pending operation |
| | 332 | bool _evaluating; |
| | 333 | |
| | 334 | struct Command |
| | 335 | { |
| | 336 | Command():_priority(0) {} |
| | 337 | Command(int priority, const FrameAction& action) : _priority(priority), _action(action) {} |
| | 338 | int _priority; |
| | 339 | FrameAction _action; |
| | 340 | }; |
| | 341 | |
| | 342 | typedef std::vector<Command> CommandList; |
| | 343 | CommandList _addActionOperations; |
| | 344 | ActionList _removeActionOperations; |
| | 345 | |
| | 346 | void setEvaluating(bool state) { _evaluating = state;} |
| | 347 | void processPendingOperation() |
| | 348 | { |
| | 349 | // process all pending add action operation |
| | 350 | while( !_addActionOperations.empty()) |
| | 351 | { |
| | 352 | internalAddAction(_addActionOperations.back()._priority, _addActionOperations.back()._action); |
| | 353 | _addActionOperations.pop_back(); |
| | 354 | } |
| | 355 | |
| | 356 | // process all pending remove action operation |
| | 357 | while( !_removeActionOperations.empty()) |
| | 358 | { |
| | 359 | internalRemoveAction(_removeActionOperations.back().second.get()); |
| | 360 | _removeActionOperations.pop_back(); |
| | 361 | } |
| | 362 | } |
| | 363 | |
| | 364 | void internalRemoveAction(Action* action) |
| | 365 | { |
| | 366 | for (ActionLayers::iterator it = _actions.begin(); it != _actions.end(); it++) |
| | 367 | { |
| | 368 | ActionList& fa = it->second; |
| | 369 | for (unsigned int i = 0; i < fa.size(); i++) |
| | 370 | if (fa[i].second.get() == action) |
| | 371 | { |
| | 372 | fa.erase(fa.begin() + i); |
| | 373 | return; |
| | 374 | } |
| | 375 | } |
| | 376 | } |
| | 377 | void internalAddAction(int priority, const FrameAction& ftl) |
| | 378 | { |
| | 379 | _actions[priority].push_back(ftl); |
| | 380 | } |
| | 381 | |