From b670066756b658e55a74d3ff3c8cec4660a0b3e9 Mon Sep 17 00:00:00 2001 From: DelinWorks Date: Sun, 12 Jun 2022 02:44:27 +0300 Subject: [PATCH] Avoid unnecessary copying of memory. --- core/2d/CCParticleSystem.cpp | 14 ++++++++------ core/2d/CCParticleSystem.h | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/core/2d/CCParticleSystem.cpp b/core/2d/CCParticleSystem.cpp index 494ce5437f..14ba8b1907 100644 --- a/core/2d/CCParticleSystem.cpp +++ b/core/2d/CCParticleSystem.cpp @@ -848,21 +848,23 @@ void ParticleSystem::addParticles(int count, int animationIndex, int animationCe } case EmissionShapeType::ALPHA_MASK: { + auto& mask = ParticleEmissionMaskCache::getInstance()->getEmissionMask(shape.maskName); + Vec2 pos = {shape.x, shape.y}; - Vec2 size = shape.mask.size; + Vec2 size = mask.size; Vec2 overrideSize = {shape.innerWidth, shape.innerHeight}; Vec2 scale = {shape.outerWidth, shape.outerHeight}; float angle = shape.coneOffset; if (overrideSize.isZero()) - overrideSize = shape.mask.size; + overrideSize = mask.size; Vec2 point = {0, 0}; { - int rand0 = RANDOM_KISS_ABS() * shape.mask.points.size(); - int index = MIN(rand0, shape.mask.points.size() - 1); - point = shape.mask.points[index]; + int rand0 = RANDOM_KISS_ABS() * mask.points.size(); + int index = MIN(rand0, mask.points.size() - 1); + point = mask.points[index]; } point -= size / 2; @@ -1192,7 +1194,7 @@ EmissionShape ParticleSystem::createMaskShape(std::string_view maskName, shape.type = EmissionShapeType::ALPHA_MASK; - shape.mask = ParticleEmissionMaskCache::getInstance()->getEmissionMask(maskName); + shape.maskName = maskName; shape.x = pos.x; shape.y = pos.y; diff --git a/core/2d/CCParticleSystem.h b/core/2d/CCParticleSystem.h index 1d0fd0ce5f..efeec1ee1e 100644 --- a/core/2d/CCParticleSystem.h +++ b/core/2d/CCParticleSystem.h @@ -98,7 +98,7 @@ struct EmissionShape float coneAngle; float edgeElasticity; - ParticleEmissionMaskDescriptor mask; + std::string_view maskName; }; /** @struct ParticleAnimationDescriptor