Reorder will be done in this function, no "lazy" reorder to particles
| 261 | |
| 262 | // Reorder will be done in this function, no "lazy" reorder to particles |
| 263 | void ParticleBatchNode::reorderChild(Node* aChild, int zOrder) |
| 264 | { |
| 265 | AXASSERT(aChild != nullptr, "Child must be non-nullptr"); |
| 266 | AXASSERT(dynamic_cast<ParticleSystem*>(aChild) != nullptr, |
| 267 | "CCParticleBatchNode only supports QuadParticleSystems as children"); |
| 268 | AXASSERT(_children.contains(aChild), "Child doesn't belong to batch"); |
| 269 | |
| 270 | ParticleSystem* child = static_cast<ParticleSystem*>(aChild); |
| 271 | |
| 272 | if (zOrder == child->getLocalZOrder()) |
| 273 | { |
| 274 | return; |
| 275 | } |
| 276 | |
| 277 | // no reordering if only 1 child |
| 278 | if (!_children.empty()) |
| 279 | { |
| 280 | int newIndex = 0, oldIndex = 0; |
| 281 | |
| 282 | getCurrentIndex(&oldIndex, &newIndex, child, zOrder); |
| 283 | |
| 284 | if (oldIndex != newIndex) |
| 285 | { |
| 286 | |
| 287 | // reorder _children->array |
| 288 | child->retain(); |
| 289 | _children.erase(oldIndex); |
| 290 | _children.insert(newIndex, child); |
| 291 | child->release(); |
| 292 | |
| 293 | // save old altasIndex |
| 294 | int oldAtlasIndex = child->getAtlasIndex(); |
| 295 | |
| 296 | // update atlas index |
| 297 | updateAllAtlasIndexes(); |
| 298 | |
| 299 | // Find new AtlasIndex |
| 300 | int newAtlasIndex = 0; |
| 301 | for (const auto& iter : _children) |
| 302 | { |
| 303 | auto node = static_cast<ParticleSystem*>(iter); |
| 304 | if (node == child) |
| 305 | { |
| 306 | newAtlasIndex = child->getAtlasIndex(); |
| 307 | break; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | // reorder textureAtlas quads |
| 312 | _textureAtlas->moveQuadsFromIndex(oldAtlasIndex, child->getTotalParticles(), newAtlasIndex); |
| 313 | |
| 314 | child->updateWithNoTime(); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | child->setLocalZOrder(zOrder); |
| 319 | } |
| 320 |
nothing calls this directly
no test coverage detected