| 728 | } |
| 729 | |
| 730 | void ParticleSystem::addParticles(int count, int animationIndex, int animationCellIndex) |
| 731 | { |
| 732 | if (_paused) |
| 733 | return; |
| 734 | |
| 735 | // Try to add as many particles as possible without overflowing. |
| 736 | count = MIN(int(_totalParticles * __totalParticleCountFactor) - _particleCount, count); |
| 737 | |
| 738 | animationCellIndex = MIN(animationCellIndex, _animIndexCount - 1); |
| 739 | animationIndex = MIN(animationIndex, _animIndexCount - 1); |
| 740 | |
| 741 | int start = _particleCount; |
| 742 | _particleCount += count; |
| 743 | |
| 744 | // life |
| 745 | for (int i = start; i < _particleCount; ++i) |
| 746 | { |
| 747 | float particleLife = _life + _lifeVar * _rng.rangef(); |
| 748 | _particleData.totalTimeToLive[i] = MAX(0, particleLife); |
| 749 | _particleData.timeToLive[i] = MAX(0, particleLife); |
| 750 | } |
| 751 | |
| 752 | if (_isEmissionShapes) |
| 753 | { |
| 754 | for (int i = start; i < _particleCount; ++i) |
| 755 | { |
| 756 | if (_emissionShapes.empty()) |
| 757 | { |
| 758 | _particleData.posx[i] = _sourcePosition.x + _posVar.x * _rng.rangef(); |
| 759 | _particleData.posy[i] = _sourcePosition.y + _posVar.y * _rng.rangef(); |
| 760 | continue; |
| 761 | } |
| 762 | |
| 763 | auto randElem = _rng.float01(); |
| 764 | auto& shape = _emissionShapes[MIN(randElem * _emissionShapes.size(), _emissionShapes.size() - 1)]; |
| 765 | |
| 766 | switch (shape.type) |
| 767 | { |
| 768 | case EmissionShapeType::POINT: |
| 769 | { |
| 770 | _particleData.posx[i] = _sourcePosition.x + shape.x; |
| 771 | _particleData.posy[i] = _sourcePosition.y + shape.y; |
| 772 | |
| 773 | break; |
| 774 | } |
| 775 | case EmissionShapeType::RECT: |
| 776 | { |
| 777 | _particleData.posx[i] = _sourcePosition.x + shape.x + shape.innerWidth / 2 * _rng.rangef(); |
| 778 | _particleData.posy[i] = _sourcePosition.y + shape.y + shape.innerHeight / 2 * _rng.rangef(); |
| 779 | |
| 780 | break; |
| 781 | } |
| 782 | case EmissionShapeType::RECTTORUS: |
| 783 | { |
| 784 | float width = (shape.outerWidth - shape.innerWidth) * _rng.float01() + shape.innerWidth; |
| 785 | float height = (shape.outerHeight - shape.innerHeight) * _rng.float01() + shape.innerHeight; |
| 786 | width = _rng.rangef() < 0.0F ? width * -1 : width; |
| 787 | height = _rng.rangef() < 0.0F ? height * -1 : height; |
nothing calls this directly
no test coverage detected