| 420 | } |
| 421 | |
| 422 | void ParticleNode::visit() { |
| 423 | if (_flags.isOff(ParticleNode::Emitting)) { |
| 424 | Node::visit(); |
| 425 | return; |
| 426 | } |
| 427 | float deltaTime = s_cast<float>(getScheduler()->getDeltaTime()); |
| 428 | if (_flags.isOn(ParticleNode::Active) && _particleDef->emissionRate) { |
| 429 | float rate = 1.0f / _particleDef->emissionRate; |
| 430 | if (s_cast<uint32_t>(_particles.size()) < _particleDef->maxParticles) { |
| 431 | _emitCounter += deltaTime; |
| 432 | } |
| 433 | while (s_cast<uint32_t>(_particles.size()) < _particleDef->maxParticles && _emitCounter > rate) { |
| 434 | addParticle(); |
| 435 | _emitCounter -= rate; |
| 436 | } |
| 437 | _elapsed += deltaTime; |
| 438 | if (_particleDef->duration >= 0 && _particleDef->duration < _elapsed) { |
| 439 | stop(); |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | float scaleX = getScaleX(), scaleY = getScaleY(), angleX = getAngleX(), angleY = getAngleY(); |
| 444 | for (Node* parent = Node::getParent(); parent; parent = parent->getParent()) { |
| 445 | scaleX *= parent->getScaleX(); |
| 446 | scaleY *= parent->getScaleY(); |
| 447 | angleX += parent->getAngleX(); |
| 448 | angleY += parent->getAngleY(); |
| 449 | } |
| 450 | scaleX = std::abs(scaleX); |
| 451 | scaleY = std::abs(scaleY); |
| 452 | float scale = Vec2{scaleX, scaleY}.length() / std::sqrt(2.0f); |
| 453 | |
| 454 | _quads.clear(); |
| 455 | int index = 0; |
| 456 | while (index < s_cast<int>(_particles.size())) { |
| 457 | Particle& p = _particles[index]; |
| 458 | p.timeToLive -= deltaTime; |
| 459 | if (p.timeToLive > 0) { |
| 460 | switch (_particleDef->emitterMode) { |
| 461 | case EmitterMode::Gravity: { |
| 462 | Vec2 tmp, radial, tangential; |
| 463 | radial = Vec2::zero; |
| 464 | |
| 465 | if (p.pos.x || p.pos.y) { |
| 466 | radial = p.pos; |
| 467 | radial.normalize(); |
| 468 | } |
| 469 | tangential = radial; |
| 470 | radial *= p.mode.gravity.radialAccel; |
| 471 | |
| 472 | float newy = tangential.x; |
| 473 | tangential.x = -tangential.y; |
| 474 | tangential.y = newy; |
| 475 | tangential *= p.mode.gravity.tangentialAccel; |
| 476 | |
| 477 | tmp = radial + tangential + _particleDef->mode.gravity.gravity; |
| 478 | tmp *= deltaTime; |
| 479 | p.mode.gravity.dir += tmp; |
nothing calls this directly
no test coverage detected