From c54b142e5845a7d6b9a5931dd5c6e7461c48df02 Mon Sep 17 00:00:00 2001 From: DelinWorks Date: Mon, 6 Jun 2022 19:23:11 +0300 Subject: [PATCH] Fix indentations. --- core/2d/CCParticleSystem.cpp | 111 ++++++++-------- core/2d/CCParticleSystem.h | 220 +++++++++++++++++-------------- core/2d/CCParticleSystemQuad.cpp | 43 +++--- 3 files changed, 203 insertions(+), 171 deletions(-) diff --git a/core/2d/CCParticleSystem.cpp b/core/2d/CCParticleSystem.cpp index f5876dedfc..c444c24c36 100644 --- a/core/2d/CCParticleSystem.cpp +++ b/core/2d/CCParticleSystem.cpp @@ -126,27 +126,27 @@ bool ParticleData::init(int count) { maxCount = count; - posx = (float*)malloc(count * sizeof(float)); - posy = (float*)malloc(count * sizeof(float)); - startPosX = (float*)malloc(count * sizeof(float)); - startPosY = (float*)malloc(count * sizeof(float)); - colorR = (float*)malloc(count * sizeof(float)); - colorG = (float*)malloc(count * sizeof(float)); - colorB = (float*)malloc(count * sizeof(float)); - colorA = (float*)malloc(count * sizeof(float)); - deltaColorR = (float*)malloc(count * sizeof(float)); - deltaColorG = (float*)malloc(count * sizeof(float)); - deltaColorB = (float*)malloc(count * sizeof(float)); - deltaColorA = (float*)malloc(count * sizeof(float)); + posx = (float*)malloc(count * sizeof(float)); + posy = (float*)malloc(count * sizeof(float)); + startPosX = (float*)malloc(count * sizeof(float)); + startPosY = (float*)malloc(count * sizeof(float)); + colorR = (float*)malloc(count * sizeof(float)); + colorG = (float*)malloc(count * sizeof(float)); + colorB = (float*)malloc(count * sizeof(float)); + colorA = (float*)malloc(count * sizeof(float)); + deltaColorR = (float*)malloc(count * sizeof(float)); + deltaColorG = (float*)malloc(count * sizeof(float)); + deltaColorB = (float*)malloc(count * sizeof(float)); + deltaColorA = (float*)malloc(count * sizeof(float)); - size = (float*)malloc(count * sizeof(float)); - deltaSize = (float*)malloc(count * sizeof(float)); - rotation = (float*)malloc(count * sizeof(float)); - staticRotation = (float*)malloc(count * sizeof(float)); - deltaRotation = (float*)malloc(count * sizeof(float)); - totalTimeToLive = (float*)malloc(count * sizeof(float)); - timeToLive = (float*)malloc(count * sizeof(float)); - atlasIndex = (unsigned int*)malloc(count * sizeof(unsigned int)); + size = (float*)malloc(count * sizeof(float)); + deltaSize = (float*)malloc(count * sizeof(float)); + rotation = (float*)malloc(count * sizeof(float)); + staticRotation = (float*)malloc(count * sizeof(float)); + deltaRotation = (float*)malloc(count * sizeof(float)); + totalTimeToLive = (float*)malloc(count * sizeof(float)); + timeToLive = (float*)malloc(count * sizeof(float)); + atlasIndex = (unsigned int*)malloc(count * sizeof(unsigned int)); modeA.dirX = (float*)malloc(count * sizeof(float)); modeA.dirY = (float*)malloc(count * sizeof(float)); @@ -262,7 +262,7 @@ ParticleSystem::ParticleSystem() , _isLoopAnimated(false) , _animIndexCount(0) , _isAnimationReversed(false) - , _undefinedIndexRect({0,0,0,0}) + , _undefinedIndexRect({0, 0, 0, 0}) , _animationTimescaleInd(false) , _yCoordFlipped(1) , _positionType(PositionType::FREE) @@ -325,11 +325,11 @@ bool ParticleSystem::allocAnimationMem() if (!_isAnimAllocated) { _particleData.animTimeLength = (float*)malloc(_totalParticles * sizeof(float)); - _particleData.animTimeDelta = (float*)malloc(_totalParticles * sizeof(float)); - _particleData.animIndex = (unsigned short*)malloc(_totalParticles * sizeof(unsigned short)); - _particleData.animCellIndex = (unsigned short*)malloc(_totalParticles * sizeof(unsigned short)); - if (_particleData.animTimeLength && _particleData.animTimeDelta && - _particleData.animIndex && _particleData.animCellIndex) + _particleData.animTimeDelta = (float*)malloc(_totalParticles * sizeof(float)); + _particleData.animIndex = (unsigned short*)malloc(_totalParticles * sizeof(unsigned short)); + _particleData.animCellIndex = (unsigned short*)malloc(_totalParticles * sizeof(unsigned short)); + if (_particleData.animTimeLength && _particleData.animTimeDelta && _particleData.animIndex && + _particleData.animCellIndex) return _isAnimAllocated = true; else // If any of the above allocations fail, then we safely deallocate the ones that succeeded. @@ -782,7 +782,7 @@ void ParticleSystem::addParticles(int count, int animationIndex, int animationCe } auto randElem = abs(RANDOM_KISS()); - auto& shape = _emissionShapes[MIN(randElem * _emissionShapes.size(), _emissionShapes.size() - 1)]; + auto& shape = _emissionShapes[MIN(randElem * _emissionShapes.size(), _emissionShapes.size() - 1)]; switch (shape.type) { @@ -802,11 +802,11 @@ void ParticleSystem::addParticles(int count, int animationIndex, int animationCe } case EmissionShapeType::RECTTORUS: { - float width = (shape.outerWidth - shape.innerWidth) * abs(RANDOM_KISS()) + shape.innerWidth; - float height = (shape.outerHeight - shape.innerHeight) * abs(RANDOM_KISS()) + shape.innerHeight; - width = RANDOM_KISS() < 0.0F ? width * -1 : width; - height = RANDOM_KISS() < 0.0F ? height * -1 : height; - float prob = RANDOM_KISS(); + float width = (shape.outerWidth - shape.innerWidth) * abs(RANDOM_KISS()) + shape.innerWidth; + float height = (shape.outerHeight - shape.innerHeight) * abs(RANDOM_KISS()) + shape.innerHeight; + width = RANDOM_KISS() < 0.0F ? width * -1 : width; + height = RANDOM_KISS() < 0.0F ? height * -1 : height; + float prob = RANDOM_KISS(); _particleData.posx[i] = _sourcePosition.x + shape.x + width / 2 * (prob >= 0.0F ? 1.0F : RANDOM_KISS()); _particleData.posy[i] = _sourcePosition.y + shape.y + height / 2 * (prob < 0.0F ? 1.0F : RANDOM_KISS()); @@ -827,9 +827,10 @@ void ParticleSystem::addParticles(int count, int animationIndex, int animationCe { auto val = abs(RANDOM_KISS()) * shape.outerRadius / shape.outerRadius; val = powf(val, 1 / shape.edgeElasticity); - auto point = Vec2(((val * (shape.outerRadius - shape.innerRadius) + shape.outerRadius) - + auto point = Vec2(((val * (shape.outerRadius - shape.innerRadius) + shape.outerRadius) - (shape.outerRadius - shape.innerRadius)) * - (RANDOM_KISS() < 0.0F ? 1.0F : -1.0F), 0.0F); + (RANDOM_KISS() < 0.0F ? 1.0F : -1.0F), + 0.0F); point = point.rotateByAngle(Vec2::ZERO, CC_DEGREES_TO_RADIANS(RANDOM_KISS() * 360)); _particleData.posx[i] = _sourcePosition.x + shape.x + point.x / 2; _particleData.posy[i] = _sourcePosition.y + shape.y + point.y / 2; @@ -907,9 +908,9 @@ void ParticleSystem::addParticles(int count, int animationIndex, int animationCe } // color -#define SET_COLOR(c, b, v) \ - for (int i = start; i < _particleCount; ++i) \ - { \ +#define SET_COLOR(c, b, v) \ + for (int i = start; i < _particleCount; ++i) \ + { \ c[i] = clampf(b + v * RANDOM_KISS(), 0, 1); \ } @@ -1035,8 +1036,7 @@ void ParticleSystem::addParticles(int count, int animationIndex, int animationCe // tangential accel for (int i = start; i < _particleCount; ++i) { - _particleData.modeA.tangentialAccel[i] = - modeA.tangentialAccel + modeA.tangentialAccelVar * RANDOM_KISS(); + _particleData.modeA.tangentialAccel[i] = modeA.tangentialAccel + modeA.tangentialAccelVar * RANDOM_KISS(); } // rotation is dir @@ -1105,7 +1105,7 @@ void ParticleSystem::addParticles(int count, int animationIndex, int animationCe void ParticleSystem::setAnimationDescriptor(unsigned short indexOfDescriptor, float time, float timeVariance, - const std::vector &indices, + const std::vector& indices, bool reverse) { auto iter = _animations.find(indexOfDescriptor); @@ -1266,16 +1266,14 @@ void ParticleSystem::setAnimationIndicesAtlas() // VERTICAL if (_texture->getPixelsHigh() > _texture->getPixelsWide()) { - setAnimationIndicesAtlas(_texture->getPixelsWide(), - ParticleSystem::TexAnimDir::VERTICAL); + setAnimationIndicesAtlas(_texture->getPixelsWide(), ParticleSystem::TexAnimDir::VERTICAL); return; } // HORIZONTAL if (_texture->getPixelsWide() > _texture->getPixelsHigh()) { - setAnimationIndicesAtlas(_texture->getPixelsHigh(), - ParticleSystem::TexAnimDir::HORIZONTAL); + setAnimationIndicesAtlas(_texture->getPixelsHigh(), ParticleSystem::TexAnimDir::HORIZONTAL); return; } @@ -1287,7 +1285,7 @@ void ParticleSystem::setAnimationIndicesAtlas(unsigned int unifiedCellSize, TexA CCASSERT(unifiedCellSize > 0, "A cell cannot have a size of zero."); resetAnimationIndices(); - + auto texWidth = _texture->getPixelsWide(); auto texHeight = _texture->getPixelsHigh(); @@ -1319,8 +1317,8 @@ void ParticleSystem::setAnimationIndicesAtlas(unsigned int unifiedCellSize, TexA frame.origin.x = unifiedCellSize * i; frame.origin.y = 0; - frame.size.x = unifiedCellSize; - frame.size.y = texHeight; + frame.size.x = unifiedCellSize; + frame.size.y = texHeight; addAnimationIndex(_animIndexCount, frame); } @@ -1342,7 +1340,7 @@ bool ParticleSystem::addAnimationIndex(unsigned short index, std::string_view fr if (frame) return addAnimationIndex(index, frame); return false; - } +} bool ParticleSystem::addAnimationIndex(cocos2d::SpriteFrame* frame) { @@ -1374,12 +1372,12 @@ bool ParticleSystem::addAnimationIndex(unsigned short index, cocos2d::Rect rect, void ParticleSystem::simulate(float seconds, float frameRate) { auto l_updatePaused = _updatePaused; - _updatePaused = false; - seconds = seconds == SIMULATION_USE_PARTICLE_LIFETIME ? - getLife() + getLifeVar() : seconds; - frameRate = frameRate == SIMULATION_USE_GAME_ANIMATION_INTERVAL ? - 1.0F / Director::getInstance()->getAnimationInterval() : frameRate; - auto delta = 1.0F / frameRate; + _updatePaused = false; + seconds = seconds == SIMULATION_USE_PARTICLE_LIFETIME ? getLife() + getLifeVar() : seconds; + frameRate = frameRate == SIMULATION_USE_GAME_ANIMATION_INTERVAL + ? 1.0F / Director::getInstance()->getAnimationInterval() + : frameRate; + auto delta = 1.0F / frameRate; if (seconds > delta) { while (seconds > 0.0F) @@ -1459,8 +1457,11 @@ void ParticleSystem::update(float dt) { _fixedFPSDelta += dt; if (_fixedFPSDelta < 1.0F / _fixedFPS) + { + CC_PROFILER_STOP_CATEGORY(kProfilerCategoryParticles, "CCParticleSystem - update"); return; - dt = _fixedFPSDelta; + } + dt = _fixedFPSDelta; _fixedFPSDelta = 0.0F; } diff --git a/core/2d/CCParticleSystem.h b/core/2d/CCParticleSystem.h index f95e3c0dac..f05a057ad6 100644 --- a/core/2d/CCParticleSystem.h +++ b/core/2d/CCParticleSystem.h @@ -66,6 +66,8 @@ enum class EmissionShapeType RECTTORUS, CIRCLE, TORUS, + CONE, + CONETORUS, }; /** @@ -95,10 +97,10 @@ Structure that contains animation description */ struct ParticleAnimationDescriptor { - float animationSpeed; - float animationSpeedVariance; + float animationSpeed; + float animationSpeedVariance; std::vector animationIndices; - bool reverseIndices; + bool reverseIndices; }; /** @struct ParticleFrameDescriptor @@ -107,7 +109,7 @@ Structure that contains frame description struct ParticleFrameDescriptor { cocos2d::Rect rect; - bool isRotated; + bool isRotated; }; class CC_DLL ParticleData @@ -228,7 +230,7 @@ public: animCellIndex[p1] = animCellIndex[p2]; } - atlasIndex[p1] = atlasIndex[p2]; + atlasIndex[p1] = atlasIndex[p2]; modeA.dirX[p1] = modeA.dirX[p2]; modeA.dirY[p1] = modeA.dirY[p2]; @@ -318,9 +320,9 @@ public: }; - /** TexAnimDir - Texture animation direction for the particles. - */ + /** TexAnimDir + Texture animation direction for the particles. + */ enum class TexAnimDir { VERTICAL, /** texture coordinates are read top to bottom within the texture */ @@ -913,53 +915,61 @@ public: void setSpawnAngleVar(float angle) { _spawnAngleVar = angle; } /** Gets the spawn opacity fade in time of each particle. - * Particles have the ability to spawn while having 0 opacity and gradually start going to 255 opacity with a specified time. + * Particles have the ability to spawn while having 0 opacity and gradually start going to 255 opacity with a + specified time. * @return The spawn opacity fade in time in seconds. */ float getSpawnFadeIn() { return _spawnFadeIn; } /** Sets the spawn opacity fade in time of each particle when it's created. - * Particles have the ability to spawn while having 0 opacity and gradually start going to 255 opacity with a specified time. - * + * Particles have the ability to spawn while having 0 opacity and gradually start going to 255 opacity with a + * specified time. + * * @param time The spawn opacity fade in time in seconds. */ void setSpawnFadeIn(float time); /** Gets the spawn opacity fade in time variance of each particle. - * Particles have the ability to spawn while having 0 opacity and gradually start going to 255 opacity with a specified time. - * + * Particles have the ability to spawn while having 0 opacity and gradually start going to 255 opacity with a + * specified time. + * * @return The spawn opacity fade in time variance in seconds. */ float getSpawnFadeInVar() { return _spawnFadeInVar; } /** Sets the spawn opacity fade in time variance of each particle when it's created. - * Particles have the ability to spawn while having 0 opacity and gradually start going to 255 opacity with a specified time. - * + * Particles have the ability to spawn while having 0 opacity and gradually start going to 255 opacity with a + * specified time. + * * @param time The spawn opacity fade in time variance in seconds. */ void setSpawnFadeInVar(float time); /** Gets the spawn opacity fade in time of each particle. - * Particles have the ability to spawn while having 0.0 size and gradually start going to 1.0 size with a specified time. - * + * Particles have the ability to spawn while having 0.0 size and gradually start going to 1.0 size with a specified + * time. + * * @return The spawn opacity fade in time in seconds. */ float getSpawnScaleIn() { return _spawnScaleIn; } /** Sets the spawn opacity fade in time of each particle when it's created. - * Particles have the ability to spawn while having 0.0 size and gradually start going to 1.0 size with a specified time. - * + * Particles have the ability to spawn while having 0.0 size and gradually start going to 1.0 size with a specified + * time. + * * @param time The spawn opacity fade in time in seconds. */ void setSpawnScaleIn(float time); /** Gets the spawn opacity fade in time variance of each particle. - * Particles have the ability to spawn while having 0.0 size and gradually start going to 1.0 size with a specified time. - * + * Particles have the ability to spawn while having 0.0 size and gradually start going to 1.0 size with a specified + * time. + * * @return The spawn opacity fade in time variance in seconds. */ float getSpawnScaleInVar() { return _spawnScaleInVar; } /** Sets the spawn opacity fade in time variance of each particle when it's created. - * Particles have the ability to spawn while having 0.0 size and gradually start going to 1.0 size with a specified time. - * + * Particles have the ability to spawn while having 0.0 size and gradually start going to 1.0 size with a specified + * time. + * * @param time The spawn opacity fade in time variance in seconds. */ void setSpawnScaleInVar(float time); @@ -996,17 +1006,18 @@ public: /** Enables or disables tex coord animations that are set by the emitter randomly when a particle is emitted. */ void setEmitterAnimation(bool enabled); - /** Enables or disables tex coord animations that are used to make particles play a sequence forever until they die */ + /** Enables or disables tex coord animations that are used to make particles play a sequence forever until they die + */ void setLoopAnimation(bool enabled); bool isLifeAnimated() { return _isLifeAnimated; } bool isEmitterAnimated() { return _isEmitterAnimated; } bool isLoopAnimated() { return _isLoopAnimated; } - /** Gets the total number of indices. - * - * @return The size of the list holding animation indices. - */ + /** Gets the total number of indices. + * + * @return The size of the list holding animation indices. + */ int getTotalAnimationIndices() { return _animIndexCount; } /** Sets wether to start from first cell and go forwards (normal) or last cell and go backwards (reversed) */ @@ -1020,96 +1031,100 @@ public: void resetAnimationDescriptors(); /** Choose what animation descriptors are to be selected at random for particles. - * This function should be called after you've inserted/overwritten any animation descriptors. - * - * @param animations Array of specific indices of animations to play at random - */ - void setMultiAnimationRandomSpecific(const std::vector &animations) { _randomAnimations = animations; }; + * This function should be called after you've inserted/overwritten any animation descriptors. + * + * @param animations Array of specific indices of animations to play at random + */ + void setMultiAnimationRandomSpecific(const std::vector& animations) + { + _randomAnimations = animations; + }; /** Choose ALL animation descriptors to be selected at random for particles. - * This function should be called after you've inserted/overwritten any animation descriptors. - */ + * This function should be called after you've inserted/overwritten any animation descriptors. + */ void setMultiAnimationRandom(); /** Add all particle animation indices based on cells size and direction spicified using a texture atlas. - * will erase the array and add new indices from the atlas. - * This function will automatically figure out your atlas cell size and direction for you! thank her later :) */ + * will erase the array and add new indices from the atlas. + * This function will automatically figure out your atlas cell size and direction for you! thank her later :) */ void setAnimationIndicesAtlas(); - /** Add all particle animation indices based on cell size and direction spicified if the method of rendering preferred is texture atlas. - * will erase the array and add new indices from the atlas. - * - * @param unifiedCellSize The size of cell unified. - * @param direction What direction is the atlas - */ + /** Add all particle animation indices based on cell size and direction spicified if the method of rendering + * preferred is texture atlas. will erase the array and add new indices from the atlas. + * + * @param unifiedCellSize The size of cell unified. + * @param direction What direction is the atlas + */ void setAnimationIndicesAtlas(unsigned int unifiedCellSize, TexAnimDir direction = TexAnimDir::HORIZONTAL); /** Add a particle animation index based on tex coords spicified using a sprite frame. - * The index is automatically incremented on each addition. - * - * @param frameName SpriteFrame name to search for - * - * @return Returns true of the index was successfully found and added. Otherwise, false - */ + * The index is automatically incremented on each addition. + * + * @param frameName SpriteFrame name to search for + * + * @return Returns true of the index was successfully found and added. Otherwise, false + */ bool addAnimationIndex(std::string_view frameName); /** Add a particle animation index based on tex coords spicified using a sprite frame. - * - * @param index Index id to add the frame to or override it with the new frame - * @param frameName SpriteFrame name to search for - * - * @return Returns true of the index was successfully found and added. Otherwise, false - */ + * + * @param index Index id to add the frame to or override it with the new frame + * @param frameName SpriteFrame name to search for + * + * @return Returns true of the index was successfully found and added. Otherwise, false + */ bool addAnimationIndex(unsigned short index, std::string_view frameName); /** Add a particle animation index based on tex coords spicified using a sprite frame. - * The index is automatically incremented on each addition. - * - * @param frame SpriteFrame containting data about tex coords - * - * @return Returns true of the index was successfully found and added. Otherwise, false - */ + * The index is automatically incremented on each addition. + * + * @param frame SpriteFrame containting data about tex coords + * + * @return Returns true of the index was successfully found and added. Otherwise, false + */ bool addAnimationIndex(cocos2d::SpriteFrame* frame); /** Add a particle animation index based on tex coords spicified using a sprite frame. - * you can specify which index you want to override in this function - * - * @param index Index id to add the frame to or override it with the new frame - * @param frame SpriteFrame containting data about tex coords - * - * @return Returns true of the index was successfully found and added. Otherwise, false - */ + * you can specify which index you want to override in this function + * + * @param index Index id to add the frame to or override it with the new frame + * @param frame SpriteFrame containting data about tex coords + * + * @return Returns true of the index was successfully found and added. Otherwise, false + */ bool addAnimationIndex(unsigned short index, cocos2d::SpriteFrame* frame); /** Add a particle animation index based on tex coords spicified. - * you can specify which index you want to override in this function - * - * @param index Index id to add the frame to or override it with the new rect - * @param rect Rect containting data about tex coords in pixels - * @param rotated Not implemented. - * - * @return Returns true of the index was successfully found and added. Otherwise, false - */ + * you can specify which index you want to override in this function + * + * @param index Index id to add the frame to or override it with the new rect + * @param rect Rect containting data about tex coords in pixels + * @param rotated Not implemented. + * + * @return Returns true of the index was successfully found and added. Otherwise, false + */ bool addAnimationIndex(unsigned short index, cocos2d::Rect rect, bool rotated = false); /** You can specify what rect is used if an index in an animation descriptor wasn't found. - * - * @param rect Rect containting data about tex coords in pixels - */ + * + * @param rect Rect containting data about tex coords in pixels + */ void setRectForUndefinedIndices(cocos2d::Rect rect) { _undefinedIndexRect = rect; }; /** Add a particle animation descriptor with an index. - * - * @param indexOfDescriptor Index of the animation to be added, adding to the same index will just override the pervious animation descriptor - * @param time length of the animation in seconds - * @param timeVariance Time randomly selected for each different particle added on the animation length - * @param indices An array of the indicies - * @param reverse Should the animation indicies be played backwards? (default: false) - */ + * + * @param indexOfDescriptor Index of the animation to be added, adding to the same index will just override the + * pervious animation descriptor + * @param time length of the animation in seconds + * @param timeVariance Time randomly selected for each different particle added on the animation length + * @param indices An array of the indicies + * @param reverse Should the animation indicies be played backwards? (default: false) + */ void setAnimationDescriptor(unsigned short indexOfDescriptor, float time, float timeVariance, - const std::vector &indices, + const std::vector& indices, bool reverse = false); /** Add a particle animation descriptor with the index 0. @@ -1117,7 +1132,7 @@ public: * @param indices An array of the indicies * @param reverse Should the animation indicies be played backwards? (default: false) */ - void setAnimationDescriptor(const std::vector &indices, bool reverse = false) + void setAnimationDescriptor(const std::vector& indices, bool reverse = false) { setAnimationDescriptor(0, 0, 0, indices, reverse); }; @@ -1146,13 +1161,19 @@ public: void addEmissionShapeRectTorus(Vec2 pos, Size innerSize, Size outerSize); /** Adds an emission shape of type Circle to the system. - * @param edgeElasticity If the value is greater than 1.0 then particles will bias towards the edge of the circle more often the greater the value is; If the value is lower than 1.0 then particles will bias towards the center of the circle more often the closer the value is to 0.0; If the value is exactly 1.0 then there will be no bias behaviour. - */ + * @param edgeElasticity If the value is greater than 1.0 then particles will bias towards the edge of the circle + * more often the greater the value is; If the value is lower than 1.0 then particles will bias towards the center + * of the circle more often the closer the value is to 0.0; If the value is exactly 1.0 then there will be no bias + * behaviour. + */ void addEmissionShapeCircle(Vec2 pos, float radius, float edgeElasticity = 1.0F); /** Adds an emission shape of type Torus to the system. - * @param edgeElasticity If the value is greater than 1.0 then particles will bias towards the edge of the torus more often the greater the value is; If the value is lower than 1.0 then particles will bias towards the inner radius of the torus more often the closer the value is to 0.0; If the value is exactly 1.0 then there will be no bias behaviour. - */ + * @param edgeElasticity If the value is greater than 1.0 then particles will bias towards the edge of the torus + * more often the greater the value is; If the value is lower than 1.0 then particles will bias towards the inner + * radius of the torus more often the closer the value is to 0.0; If the value is exactly 1.0 then there will be no + * bias behaviour. + */ void addEmissionShapeTorus(Vec2 pos, float innerRadius, float outerRadius, float edgeElasticity = 1.0F); /** Gets the particles movement type: Free or Grouped. @@ -1171,16 +1192,20 @@ public: /** Advance the particle system and make it seem like it ran for this many seconds. * * @param seconds Seconds to advance. value of -1 means (SIMULATION_USE_PARTICLE_LIFETIME) - * @param frameRate Frame rate to run the simulation with (preferred: 30.0) The higher this value is the more accurate the simulation will be at the cost of performance. value of -1 means (SIMULATION_USE_GAME_ANIMATION_INTERVAL) + * @param frameRate Frame rate to run the simulation with (preferred: 30.0) The higher this value is the more + * accurate the simulation will be at the cost of performance. value of -1 means + * (SIMULATION_USE_GAME_ANIMATION_INTERVAL) */ - void simulate(float seconds = SIMULATION_USE_PARTICLE_LIFETIME, - float frameRate = SIMULATION_USE_GAME_ANIMATION_INTERVAL); + void simulate(float seconds = SIMULATION_USE_PARTICLE_LIFETIME, + float frameRate = SIMULATION_USE_GAME_ANIMATION_INTERVAL); /** Resets the particle system and then advances the particle system and make it seem like it ran for this many * seconds. The frame rate used for simulation accuracy is the screens refresh rate. * * @param seconds Seconds to advance. value of -1 means (SIMULATION_USE_PARTICLE_LIFETIME) - * @param frameRate Frame rate to run the simulation with (preferred: 30.0) The higher this value is the more accurate the simulation will be at the cost of performance. value of -1 means (SIMULATION_USE_GAME_ANIMATION_INTERVAL) + * @param frameRate Frame rate to run the simulation with (preferred: 30.0) The higher this value is the more + * accurate the simulation will be at the cost of performance. value of -1 means + * (SIMULATION_USE_GAME_ANIMATION_INTERVAL) */ void resimulate(float seconds = SIMULATION_USE_PARTICLE_LIFETIME, float frameRate = SIMULATION_USE_GAME_ANIMATION_INTERVAL); @@ -1279,6 +1304,9 @@ public: virtual float getFixedFPS(); /** Sets the fixed frame rate count of the particle system. + * i.e. if the framerate is set to 30.0 while the refresh rate is greater than 30.0 then the particle system will + wait until it hits the 30.0 FPS mark. + * This is usefull for increasing performance or for creating old-school effects with it. @param Fixed frame rate count of the particle system. (default: 0.0) */ virtual void setFixedFPS(float frameRate = 0.0F); diff --git a/core/2d/CCParticleSystemQuad.cpp b/core/2d/CCParticleSystemQuad.cpp index 8f7a71d005..9326319b8d 100644 --- a/core/2d/CCParticleSystemQuad.cpp +++ b/core/2d/CCParticleSystemQuad.cpp @@ -106,7 +106,9 @@ ParticleSystemQuad* ParticleSystemQuad::create(std::string_view filename) ParticleSystemQuad* ParticleSystemQuad::createWithTotalParticles(int numberOfParticles) { - CCASSERT(numberOfParticles <= 10000, "Adding more than 10000 particles will crash the renderer, the mesh generated has an index format of U_SHORT (uint16_t)"); + CCASSERT(numberOfParticles <= 10000, + "Adding more than 10000 particles will crash the renderer, the mesh generated has an index format of " + "U_SHORT (uint16_t)"); ParticleSystemQuad* ret = new ParticleSystemQuad(); if (ret->initWithTotalParticles(numberOfParticles)) @@ -293,7 +295,7 @@ inline void updatePosWithParticle(V3F_C4B_T2F_Quad* quad, float x = newPosition.x; float y = newPosition.y; - float r = (float)-CC_DEGREES_TO_RADIANS(rotation + staticRotation); + float r = (float)-CC_DEGREES_TO_RADIANS(rotation + staticRotation); float cr = cosf(r); float sr = sinf(r); float ax = x1 * cr - y1 * sr + x; @@ -359,19 +361,20 @@ void ParticleSystemQuad::updateParticleQuads() worldToNodeTM.transformPoint(&p1); Vec3 p2; Vec2 newPos; - float* startX = _particleData.startPosX; - float* startY = _particleData.startPosY; - float* x = _particleData.posx; - float* y = _particleData.posy; - float* s = _particleData.size; - float* r = _particleData.rotation; - float* sr = _particleData.staticRotation; - float* sid = _particleData.scaleInDelta; - float* sil = _particleData.scaleInLength; + float* startX = _particleData.startPosX; + float* startY = _particleData.startPosY; + float* x = _particleData.posx; + float* y = _particleData.posy; + float* s = _particleData.size; + float* r = _particleData.rotation; + float* sr = _particleData.staticRotation; + float* sid = _particleData.scaleInDelta; + float* sil = _particleData.scaleInLength; V3F_C4B_T2F_Quad* quadStart = startQuad; if (_isScaleInAllocated) { - for (int i = 0; i < _particleCount; ++i, ++startX, ++startY, ++x, ++y, ++quadStart, ++s, ++r, ++sr, ++sid, ++sil) + for (int i = 0; i < _particleCount; + ++i, ++startX, ++startY, ++x, ++y, ++quadStart, ++s, ++r, ++sr, ++sid, ++sil) { p2.set(*startX, *startY, 0); worldToNodeTM.transformPoint(&p2); @@ -411,7 +414,8 @@ void ParticleSystemQuad::updateParticleQuads() V3F_C4B_T2F_Quad* quadStart = startQuad; if (_isScaleInAllocated) { - for (int i = 0; i < _particleCount; ++i, ++startX, ++startY, ++x, ++y, ++quadStart, ++s, ++r, ++sr, ++sid, ++sil) + for (int i = 0; i < _particleCount; + ++i, ++startX, ++startY, ++x, ++y, ++quadStart, ++s, ++r, ++sr, ++sid, ++sil) { newPos.set(*x, *y); newPos.x = *x - (currentPosition.x - *startX); @@ -447,7 +451,8 @@ void ParticleSystemQuad::updateParticleQuads() V3F_C4B_T2F_Quad* quadStart = startQuad; if (_isScaleInAllocated) { - for (int i = 0; i < _particleCount; ++i, ++startX, ++startY, ++x, ++y, ++quadStart, ++s, ++r, ++sr, ++sid, ++sil) + for (int i = 0; i < _particleCount; + ++i, ++startX, ++startY, ++x, ++y, ++quadStart, ++s, ++r, ++sr, ++sid, ++sil) { newPos.set(*x + pos.x, *y + pos.y); updatePosWithParticle(quadStart, newPos, *s, tweenfunc::expoEaseOut(*sid / *sil), *r, *sr); @@ -573,8 +578,7 @@ void ParticleSystemQuad::updateParticleQuads() if (_opacityModifyRGB) { auto hsv = HSV(); - for (int i = 0; i < _particleCount; - ++i, ++quad, ++r, ++g, ++b, ++a, ++hue, ++sat, ++val) + for (int i = 0; i < _particleCount; ++i, ++quad, ++r, ++g, ++b, ++a, ++hue, ++sat, ++val) { float colorR = *r; float colorG = *g; @@ -582,8 +586,8 @@ void ParticleSystemQuad::updateParticleQuads() float colorA = *a; hsv.set(colorR, colorG, colorB, colorA); hsv.h += *hue; - hsv.s = abs(*sat); - hsv.v = abs(*val); + hsv.s = abs(*sat); + hsv.v = abs(*val); auto colF = hsv.toColor4F(); quad->bl.colors.set(colF.r * colF.a * 255.0F, colF.g * colF.a * 255.0F, colF.b * colF.a * 255.0F, colF.a * 255.0F); @@ -598,8 +602,7 @@ void ParticleSystemQuad::updateParticleQuads() else { auto hsv = HSV(); - for (int i = 0; i < _particleCount; - ++i, ++quad, ++r, ++g, ++b, ++a, ++hue, ++sat, ++val) + for (int i = 0; i < _particleCount; ++i, ++quad, ++r, ++g, ++b, ++a, ++hue, ++sat, ++val) { float colorR = *r; float colorG = *g;