diff --git a/core/2d/CCParticleSystem.cpp b/core/2d/CCParticleSystem.cpp index f190e6f89c..a6202c60ac 100644 --- a/core/2d/CCParticleSystem.cpp +++ b/core/2d/CCParticleSystem.cpp @@ -138,9 +138,6 @@ bool ParticleData::init(int count) deltaColorG = (float*)malloc(count * sizeof(float)); deltaColorB = (float*)malloc(count * sizeof(float)); deltaColorA = (float*)malloc(count * sizeof(float)); - hueValue = (float*)malloc(count * sizeof(float)); - saturationValue = (float*)malloc(count * sizeof(float)); - luminanceValue = (float*)malloc(count * sizeof(float)); size = (float*)malloc(count * sizeof(float)); deltaSize = (float*)malloc(count * sizeof(float)); rotation = (float*)malloc(count * sizeof(float)); @@ -165,11 +162,10 @@ bool ParticleData::init(int count) modeB.radius = (float*)malloc(count * sizeof(float)); return posx && posy && startPosX && startPosY && colorR && colorG && colorB && colorA && deltaColorR && - deltaColorG && deltaColorB && deltaColorA && size && hueValue && saturationValue && luminanceValue && - deltaSize && rotation && staticRotation && deltaRotation && totalTimeToLive && timeToLive && - animTimeLength && animTimeDelta && animIndex && animCellIndex && atlasIndex && modeA.dirX && modeA.dirY && - modeA.radialAccel && modeA.tangentialAccel && modeB.angle && modeB.degreesPerSecond && modeB.deltaRadius && - modeB.radius; + deltaColorG && deltaColorB && deltaColorA && size && deltaSize && rotation && staticRotation && + deltaRotation && totalTimeToLive && timeToLive && animTimeLength && animTimeDelta && animIndex && + animCellIndex && atlasIndex && modeA.dirX && modeA.dirY && modeA.radialAccel && modeA.tangentialAccel && + modeB.angle && modeB.degreesPerSecond && modeB.deltaRadius && modeB.radius; } void ParticleData::release() @@ -186,9 +182,6 @@ void ParticleData::release() CC_SAFE_FREE(deltaColorG); CC_SAFE_FREE(deltaColorB); CC_SAFE_FREE(deltaColorA); - CC_SAFE_FREE(hueValue); - CC_SAFE_FREE(saturationValue); - CC_SAFE_FREE(luminanceValue); CC_SAFE_FREE(size); CC_SAFE_FREE(deltaSize); CC_SAFE_FREE(rotation); @@ -235,13 +228,6 @@ ParticleSystem::ParticleSystem() , _angle(0) , _angleVar(0) , _emitterMode(Mode::GRAVITY) - , _isHsv(false) - , _hueValue(0) - , _hueValueVar(0) - , _saturationValue(1) - , _saturationValueVar(0) - , _luminanceValue(1) - , _luminanceValueVar(0) , _startSize(0) , _startSizeVar(0) , _endSize(0) @@ -263,7 +249,6 @@ ParticleSystem::ParticleSystem() , _animIndexCount(0) , _isAnimationReversed(false) , _undefinedIndexRect({0,0,0,0}) - , _animationTimescaleInd(false) , _yCoordFlipped(1) , _positionType(PositionType::FREE) , _paused(false) @@ -757,24 +742,6 @@ void ParticleSystem::addParticles(int count, int animationCellIndex, int animati SET_DELTA_COLOR(_particleData.colorB, _particleData.deltaColorB); SET_DELTA_COLOR(_particleData.colorA, _particleData.deltaColorA); - // hue saturation luminance color values - { - for (int i = start; i < _particleCount; ++i) - { - _particleData.hueValue[i] = _hueValue + _hueValueVar * RANDOM_KISS(); - } - - for (int i = start; i < _particleCount; ++i) - { - _particleData.saturationValue[i] = _saturationValue + _saturationValueVar * RANDOM_KISS(); - } - - for (int i = start; i < _particleCount; ++i) - { - _particleData.luminanceValue[i] = _luminanceValue + _luminanceValueVar * RANDOM_KISS(); - } - } - // size for (int i = start; i < _particleCount; ++i) { @@ -1134,9 +1101,9 @@ void ParticleSystem::update(float dt) _componentContainer->visit(dt); } - if (dt > 0.3F) + if (dt > 0.5F) { - this->simulate(dt, 10); + this->simulate(dt, 15); return; } diff --git a/core/2d/CCParticleSystem.h b/core/2d/CCParticleSystem.h index 4bfdf93264..a89062aa90 100644 --- a/core/2d/CCParticleSystem.h +++ b/core/2d/CCParticleSystem.h @@ -92,10 +92,6 @@ public: float* deltaColorB; float* deltaColorA; - float* hueValue; - float* saturationValue; - float* luminanceValue; - float* size; float* deltaSize; float* rotation; @@ -135,10 +131,10 @@ public: void copyParticle(int p1, int p2) { - posx[p1] = posx[p2]; - posy[p1] = posy[p2]; - startPosX[p1] = startPosX[p2]; - startPosY[p1] = startPosY[p2]; + posx[p1] = posx[p2]; + posy[p1] = posy[p2]; + startPosX[p1] = startPosX[p2]; + startPosY[p1] = startPosY[p2]; colorR[p1] = colorR[p2]; colorG[p1] = colorG[p2]; @@ -150,24 +146,17 @@ public: deltaColorB[p1] = deltaColorB[p2]; deltaColorA[p1] = deltaColorA[p2]; - hueValue[p1] = hueValue[p2]; - saturationValue[p1] = saturationValue[p2]; - luminanceValue[p1] = luminanceValue[p2]; + size[p1] = size[p2]; + deltaSize[p1] = deltaSize[p2]; + + rotation[p1] = rotation[p2]; + deltaRotation[p1] = deltaRotation[p2]; - size[p1] = size[p2]; - deltaSize[p1] = deltaSize[p2]; - rotation[p1] = rotation[p2]; - staticRotation[p1] = staticRotation[p2]; - deltaRotation[p1] = deltaRotation[p2]; - totalTimeToLive[p1] = totalTimeToLive[p2]; - timeToLive[p1] = timeToLive[p2]; - animTimeDelta[p1] = animTimeDelta[p2]; - animTimeLength[p1] = animTimeLength[p2]; + timeToLive[p1] = timeToLive[p2]; - animIndex[p1] = animIndex[p2]; animCellIndex[p1] = animCellIndex[p2]; - atlasIndex[p1] = atlasIndex[p2]; + atlasIndex[p1] = atlasIndex[p2]; modeA.dirX[p1] = modeA.dirX[p2]; modeA.dirY[p1] = modeA.dirY[p2]; @@ -716,92 +705,6 @@ public: */ void setEndColorVar(const Color4F& color) { _endColorVar = color; } - /** Sets wether to use HSV color system. - * WARNING: careful when using HSV with too many particles because it's expensive. - * - * @param hsv Use hsv color system. - */ - void useHSV(bool hsv) { _isHsv = hsv; }; - bool isHSV() { return _isHsv; }; - - /** Gets the hue value of each particle. - * NOTE: hsv has to be enabled using useHSV(true) for this function to work. - * - * @return The hue value of each particle in degress (i.e. 360). - */ - float getHue() const { return _hueValue; } - /** Sets the hue value of each particle. - * NOTE: hsv has to be enabled using useHSV(true) for this function to work. - * - * @param degrees The hue value of each particle in degress (i.e. 360). - */ - void setHue(float degrees) { _hueValue = degrees; } - - /** Gets the hue variance value of each particle. - * NOTE: hsv has to be enabled using useHSV(true) for this function to work. - * - * @return The hue variance value of each particle in degress (i.e. 360). - */ - float getHueVar() const { return _hueValueVar; } - /** Sets the hue variance value of each particle. - * NOTE: hsv has to be enabled using useHSV(true) for this function to work. - * - * @param degrees The hue variance value of each particle in degress (i.e. 360). - */ - void setHueVar(float degrees) { _hueValueVar = degrees; } - - /** Gets the saturation value of each particle. - * NOTE: hsv has to be enabled using useHSV(true) for this function to work. - * - * @return The saturation value of each particle. - */ - float getSaturation() const { return _saturationValue; } - /** Sets the saturation value of each particle. - * NOTE: hsv has to be enabled using useHSV(true) for this function to work. - * - * @param value The saturation value of each particle. - */ - void setSaturation(float value) { _saturationValue = value; } - - /** Gets the saturation variance value of each particle. - * NOTE: hsv has to be enabled using useHSV(true) for this function to work. - * - * @return The saturation variance value of each particle. - */ - float getSaturationVar() const { return _saturationValueVar; } - /** Sets the saturation variance value of each particle. - * NOTE: hsv has to be enabled using useHSV(true) for this function to work. - * - * @param value The saturation variance value of each particle. - */ - void setSaturationVar(float value) { _saturationValueVar = value; } - - /** Gets the luminance value of each particle. - * NOTE: hsv has to be enabled using useHSV(true) for this function to work. - * - * @return The luminance value of each particle. - */ - float getLuminance() const { return _luminanceValue; } - /** Sets the luminance value of each particle. - * NOTE: hsv has to be enabled using useHSV(true) for this function to work. - * - * @param value The luminance value of each particle. - */ - void setLuminance(float value) { _luminanceValue = value; } - - /** Gets the luminance variance value of each particle. - * NOTE: hsv has to be enabled using useHSV(true) for this function to work. - * - * @return The luminance variance value of each particle. - */ - float getLuminanceVar() const { return _luminanceValueVar; } - /** Sets the luminance variance value of each particle. - * NOTE: hsv has to be enabled using useHSV(true) for this function to work. - * - * @param value The luminance variance value of each particle. - */ - void setLuminanceVar(float value) { _luminanceValueVar = value; } - /** Gets the start spin of each particle. * * @return The start spin of each particle. @@ -1325,20 +1228,6 @@ protected: Color4F _endColor; /** end color variance of each particle */ Color4F _endColorVar; - //* Is the hsv system used or not. - bool _isHsv; - //* Hue value of each particle - float _hueValue; - //* Hue value variance of each particle - float _hueValueVar; - //* Saturation value of each particle - float _saturationValue; - //* Saturation value variance of each particle - float _saturationValueVar; - //* Luminance value of each particle - float _luminanceValue; - //* Luminance value variance of each particle - float _luminanceValueVar; //* initial angle of each particle float _startSpin; //* initial angle of each particle diff --git a/core/2d/CCParticleSystemQuad.cpp b/core/2d/CCParticleSystemQuad.cpp index c8b12732a6..f0bb09df59 100644 --- a/core/2d/CCParticleSystemQuad.cpp +++ b/core/2d/CCParticleSystemQuad.cpp @@ -415,91 +415,44 @@ void ParticleSystemQuad::updateParticleQuads() } // set color - V3F_C4B_T2F_Quad* quad = startQuad; - float* r = _particleData.colorR; - float* g = _particleData.colorG; - float* b = _particleData.colorB; - float* a = _particleData.colorA; - - // HSV calculation is expensive, so we should skip it if it's not enabled. - if (_isHsv) + if (_opacityModifyRGB) { - float* hue = _particleData.hueValue; - float* sat = _particleData.saturationValue; - float* lum = _particleData.luminanceValue; + V3F_C4B_T2F_Quad* quad = startQuad; + float* r = _particleData.colorR; + float* g = _particleData.colorG; + float* b = _particleData.colorB; + float* a = _particleData.colorA; - if (_opacityModifyRGB) + for (int i = 0; i < _particleCount; ++i, ++quad, ++r, ++g, ++b, ++a) { - auto hsv = HSV(); - for (int i = 0; i < _particleCount; ++i, ++quad, ++r, ++g, ++b, ++a, ++hue, ++sat, ++lum) - { - float colorR = *r * *a; - float colorG = *g * *a; - float colorB = *b * *a; - float colorA = *a; - hsv.rgb(colorR, colorG, colorB, colorA); - hsv.h += *hue; - hsv.h = abs(fmod(hsv.h, 360.0F)); - hsv.s = abs(*sat); - hsv.v = abs(*lum); - auto col = Color4B(hsv); - quad->bl.colors.set(col.r, col.g, col.b, col.a); - quad->br.colors.set(col.r, col.g, col.b, col.a); - quad->tl.colors.set(col.r, col.g, col.b, col.a); - quad->tr.colors.set(col.r, col.g, col.b, col.a); - } - } - else - { - auto hsv = HSV(); - for (int i = 0; i < _particleCount; ++i, ++quad, ++r, ++g, ++b, ++a, ++hue, ++sat, ++lum) - { - float colorR = *r; - float colorG = *g; - float colorB = *b; - float colorA = *a; - hsv.rgb(colorR, colorG, colorB, colorA); - hsv.h += *hue; - hsv.h = abs(fmod(hsv.h, 360.0F)); - hsv.s = abs(*sat); - hsv.v = abs(*lum); - auto col = Color4B(hsv); - quad->bl.colors.set(col.r, col.g, col.b, col.a); - quad->br.colors.set(col.r, col.g, col.b, col.a); - quad->tl.colors.set(col.r, col.g, col.b, col.a); - quad->tr.colors.set(col.r, col.g, col.b, col.a); - } + uint8_t colorR = *r * *a * 255; + uint8_t colorG = *g * *a * 255; + uint8_t colorB = *b * *a * 255; + uint8_t colorA = *a * 255; + quad->bl.colors.set(colorR, colorG, colorB, colorA); + quad->br.colors.set(colorR, colorG, colorB, colorA); + quad->tl.colors.set(colorR, colorG, colorB, colorA); + quad->tr.colors.set(colorR, colorG, colorB, colorA); } } else { - if (_opacityModifyRGB) + V3F_C4B_T2F_Quad* quad = startQuad; + float* r = _particleData.colorR; + float* g = _particleData.colorG; + float* b = _particleData.colorB; + float* a = _particleData.colorA; + + for (int i = 0; i < _particleCount; ++i, ++quad, ++r, ++g, ++b, ++a) { - for (int i = 0; i < _particleCount; ++i, ++quad, ++r, ++g, ++b, ++a) - { - uint8_t colorR = *r * *a * 255.0F; - uint8_t colorG = *g * *a * 255.0F; - uint8_t colorB = *b * *a * 255.0F; - uint8_t colorA = *a * 255.0F; - quad->bl.colors.set(colorR, colorG, colorB, colorA); - quad->br.colors.set(colorR, colorG, colorB, colorA); - quad->tl.colors.set(colorR, colorG, colorB, colorA); - quad->tr.colors.set(colorR, colorG, colorB, colorA); - } - } - else - { - for (int i = 0; i < _particleCount; ++i, ++quad, ++r, ++g, ++b, ++a) - { - uint8_t colorR = *r * 255.0F; - uint8_t colorG = *g * 255.0F; - uint8_t colorB = *b * 255.0F; - uint8_t colorA = *a * 255.0F; - quad->bl.colors.set(colorR, colorG, colorB, colorA); - quad->br.colors.set(colorR, colorG, colorB, colorA); - quad->tl.colors.set(colorR, colorG, colorB, colorA); - quad->tr.colors.set(colorR, colorG, colorB, colorA); - } + uint8_t colorR = *r * 255; + uint8_t colorG = *g * 255; + uint8_t colorB = *b * 255; + uint8_t colorA = *a * 255; + quad->bl.colors.set(colorR, colorG, colorB, colorA); + quad->br.colors.set(colorR, colorG, colorB, colorA); + quad->tl.colors.set(colorR, colorG, colorB, colorA); + quad->tr.colors.set(colorR, colorG, colorB, colorA); } }