Merge pull request #637 from rh101/fix-screen-blank

Fix Android screen blank issue after unlocking device
This commit is contained in:
涓€绾跨伒 2022-06-07 20:05:29 +08:00 committed by GitHub
parent a30815f2bf
commit 4c18771e34
4 changed files with 169 additions and 1752 deletions

File diff suppressed because it is too large Load Diff

View File

@ -32,8 +32,6 @@ THE SOFTWARE.
#include "base/CCProtocols.h"
#include "2d/CCNode.h"
#include "base/CCValue.h"
#include "2d/CCSpriteFrame.h"
#include "2d/CCSpriteFrameCache.h"
NS_CC_BEGIN
@ -54,64 +52,6 @@ struct particle_point
float y;
};
/**
* Particle emission shapes.
* Current supported shapes are Point, Rectangle, RectangularTorus, Circle, Torus
* @since adxe-1.0.0b7
*/
enum class EmissionShapeType
{
POINT,
RECT,
RECTTORUS,
CIRCLE,
TORUS,
CONE,
CONETORUS,
};
/**
* Particle emission shapes.
* Current supported shapes are Point, Rectangle, RectangularTorus, Circle, Torus
* @since adxe-1.0.0b7
*/
struct EmissionShape
{
EmissionShapeType type;
float x;
float y;
float innerWidth;
float innerHeight;
float outerWidth;
float outerHeight;
float innerRadius;
float outerRadius;
float edgeElasticity;
};
/** @struct ParticleAnimationDescriptor
Structure that contains animation description
*/
struct ParticleAnimationDescriptor
{
float animationSpeed;
float animationSpeedVariance;
std::vector<unsigned short> animationIndices;
bool reverseIndices;
};
/** @struct ParticleFrameDescriptor
Structure that contains frame description
*/
struct ParticleFrameDescriptor
{
cocos2d::Rect rect;
bool isRotated;
};
class CC_DLL ParticleData
{
public:
@ -130,27 +70,11 @@ public:
float* deltaColorB;
float* deltaColorA;
float* hue;
float* sat;
float* val;
float* opacityFadeInDelta;
float* opacityFadeInLength;
float* scaleInDelta;
float* scaleInLength;
float* size;
float* deltaSize;
float* rotation;
float* staticRotation;
float* deltaRotation;
float* totalTimeToLive;
float* timeToLive;
float* animTimeDelta;
float* animTimeLength;
unsigned short* animIndex;
unsigned short* animCellIndex;
unsigned int* atlasIndex;
//! Mode A: gravity, direction, radial accel, tangential accel
@ -194,41 +118,13 @@ public:
deltaColorB[p1] = deltaColorB[p2];
deltaColorA[p1] = deltaColorA[p2];
if (hue && sat && val)
{
hue[p1] = hue[p2];
sat[p1] = sat[p2];
val[p1] = val[p2];
}
size[p1] = size[p2];
deltaSize[p1] = deltaSize[p2];
if (opacityFadeInDelta && opacityFadeInLength)
{
opacityFadeInDelta[p1] = opacityFadeInDelta[p2];
opacityFadeInLength[p1] = opacityFadeInLength[p2];
}
rotation[p1] = rotation[p2];
deltaRotation[p1] = deltaRotation[p2];
if (scaleInDelta && scaleInLength)
{
scaleInDelta[p1] = scaleInDelta[p2];
scaleInLength[p1] = scaleInLength[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];
if (animTimeDelta && animTimeLength && animIndex && animCellIndex)
{
animTimeDelta[p1] = animTimeDelta[p2];
animTimeLength[p1] = animTimeLength[p2];
animIndex[p1] = animIndex[p2];
animCellIndex[p1] = animCellIndex[p2];
}
timeToLive[p1] = timeToLive[p2];
atlasIndex[p1] = atlasIndex[p2];
@ -306,7 +202,7 @@ public:
};
/** PositionType
Types of particle positioning.
Possible types of particle positions.
* @js cc.ParticleSystem.TYPE_FREE
*/
enum class PositionType
@ -320,17 +216,6 @@ public:
};
/** TexAnimDir
Texture animation direction for the particles.
*/
enum class TexAnimDir
{
VERTICAL, /** texture coordinates are read top to bottom within the texture */
HORIZONTAL, /** texture coordinates are read left to right within the texture */
};
//* @enum
enum
{
@ -342,12 +227,6 @@ public:
/** The starting radius of the particle is equal to the ending radius. */
START_RADIUS_EQUAL_TO_END_RADIUS = -1,
/** The simulation's seconds are set to the particles' lifetime specified inclusive of variant. */
SIMULATION_USE_PARTICLE_LIFETIME = -1,
/** The simulation's framerate is set to the animation interval specified in director. */
SIMULATION_USE_GAME_ANIMATION_INTERVAL = -1,
};
/** Creates an initializes a ParticleSystem from a plist file.
@ -372,25 +251,8 @@ public:
*/
static Vector<ParticleSystem*>& getAllParticleSystems();
protected:
bool allocAnimationMem();
void deallocAnimationMem();
bool _isAnimAllocated;
bool allocHSVMem();
void deallocHSVMem();
bool _isHSVAllocated;
bool allocOpacityFadeInMem();
void deallocOpacityFadeInMem();
bool _isOpacityFadeInAllocated;
bool allocScaleInMem();
void deallocScaleInMem();
bool _isScaleInAllocated;
public:
void addParticles(int count, int animationIndex = -1, int animationCellIndex = -1);
void addParticles(int count);
void stopSystem();
/** Kill all living particles.
@ -796,58 +658,6 @@ public:
*/
void setEndColorVar(const Color4F& color) { _endColorVar = color; }
/** Sets wether to use HSV color system.
* WARNING: becareful when using HSV with too many particles because it's expensive.
*
* @param hsv Use HSV color system.
*/
void useHSV(bool hsv);
bool isHSV() { return _isHSVAllocated; };
/** Gets the hue of each particle.
*
* @return The hue of each particle.
*/
float getHue() const { return _hsv.h; }
/** Sets the hue of each particle.
*
* @param hsv The hue color of each particle.
*/
void setHue(float hue) { _hsv.h = hue; }
/** Gets the hue variance of each particle.
*
* @return The hue variance of each particle.
*/
float getHueVar() const { return _hsvVar.h; }
/** Sets the hue variance of each particle.
*
* @param hsv The hue variance color of each particle.
*/
void setHueVar(float hue) { _hsvVar.h = hue; }
/** Gets the HSV color of each particle.
*
* @return The HSV color of each particle.
*/
const HSV& getHSV() const { return _hsv; }
/** Sets the HSV color of each particle.
*
* @param hsv The HSV color of each particle.
*/
void setHSV(const HSV& hsv) { _hsv = hsv; }
/** Gets the HSV color variance of each particle.
*
* @return The HSV color variance of each particle.
*/
const HSV& getHSVVar() const { return _hsvVar; }
/** Sets the HSV color variance of each particle.
*
* @param hsv The HSV color variance of each particle.
*/
void setHSVVar(const HSV& hsv) { _hsvVar = hsv; }
/** Gets the start spin of each particle.
*
* @return The start spin of each particle.
@ -892,88 +702,6 @@ public:
*/
void setEndSpinVar(float endSpinVar) { _endSpinVar = endSpinVar; }
/** Gets the spawn angle of each particle
*
* @return The angle in degrees of each particle.
*/
float getSpawnAngle() { return _spawnAngle; }
/** Sets the spawn angle of each particle
*
* @param angle The angle in degrees of each particle.
*/
void setSpawnAngle(float angle) { _spawnAngle = angle; }
/** Sets the spawn angle variance of each particle.
*
* @return The angle variance in degrees of each particle.
*/
float getSpawnAngleVar() { return _spawnAngleVar; }
/** Sets the spawn angle variance of each particle.
*
* @param angle The angle variance in degrees of each particle.
*/
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.
* @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.
*
* @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.
*
* @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.
*
* @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.
*
* @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.
*
* @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.
*
* @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.
*
* @param time The spawn opacity fade in time variance in seconds.
*/
void setSpawnScaleInVar(float time);
/** Gets the emission rate of the particles.
*
* @return The emission rate of the particles.
@ -1000,182 +728,6 @@ public:
void setOpacityModifyRGB(bool opacityModifyRGB) override { _opacityModifyRGB = opacityModifyRGB; }
bool isOpacityModifyRGB() const override { return _opacityModifyRGB; }
/** Enables or disables tex coord animations that are set based on particle life. */
void setLifeAnimation(bool enabled);
/** 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
*/
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.
*/
int getTotalAnimationIndices() { return _animIndexCount; }
/** Sets wether to start from first cell and go forwards (normal) or last cell and go backwards (reversed) */
void setAnimationReverse(bool reverse) { _isAnimationReversed = reverse; }
bool isAnimationReversed() { return _isAnimationReversed; }
/** Resets the count of indices to 0 and empties the animation index array */
void resetAnimationIndices();
/** Empties the container of animation descriptors */
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<unsigned short>& 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.
*/
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 :) */
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
*/
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
*/
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
*/
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
*/
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
*/
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
*/
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
*/
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)
*/
void setAnimationDescriptor(unsigned short indexOfDescriptor,
float time,
float timeVariance,
const std::vector<unsigned short>& indices,
bool reverse = false);
/** Add a particle animation descriptor with the index 0.
*
* @param indices An array of the indicies
* @param reverse Should the animation indicies be played backwards? (default: false)
*/
void setAnimationDescriptor(const std::vector<unsigned short>& indices, bool reverse = false)
{
setAnimationDescriptor(0, 0, 0, indices, reverse);
};
/** Sets wether the animation descriptors should follow the time scale of the system or not.
*
* @param independent Should the animation descriptor speeds be played independently? (default: false)
*/
void setAnimationSpeedTimescaleIndependent(bool independent) { _animationTimescaleInd = independent; };
bool isAnimationSpeedTimescaleIndependent() { return _animationTimescaleInd; };
/** Sets wether to use emission shapes for this particle system or not */
void setEmissionShapes(bool enabled) { _isEmissionShapes = enabled; }
bool isEmissionShapes() { return _isEmissionShapes; }
/** Resets the count of emission shapes to 0 and empties the emission shapes array */
void resetEmissionShapes();
/** Adds an emission shape of type point to the system. */
void addEmissionShapePoint(Vec2 pos);
/** Adds an emission shape of type Rectangle to the system. */
void addEmissionShapeRect(Vec2 pos, Size size);
/** Adds an emission shape of type Rectangular Torus to the system. */
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.
*/
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.
*/
void addEmissionShapeTorus(Vec2 pos, float innerRadius, float outerRadius, float edgeElasticity = 1.0F);
/** Gets the particles movement type: Free or Grouped.
@since v0.8
*
@ -1189,27 +741,6 @@ public:
*/
void setPositionType(PositionType type) { _positionType = type; }
/** 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)
*/
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)
*/
void resimulate(float seconds = SIMULATION_USE_PARTICLE_LIFETIME,
float frameRate = SIMULATION_USE_GAME_ANIMATION_INTERVAL);
// Overrides
virtual void onEnter() override;
virtual void onExit() override;
@ -1281,46 +812,12 @@ public:
*/
virtual bool isPaused() const;
/* Pause the emissions */
/* Pause the emissions*/
virtual void pauseEmissions();
/* Unpause the emissions */
/* UnPause the emissions*/
virtual void resumeEmissions();
/** Is system update paused
@return True if the emissions are paused, else false
*/
virtual bool isUpdatePaused() const;
/* Pause the particles from being updated */
virtual void pauseUpdate();
/* Unpause the particles from being updated */
virtual void resumeUpdate();
/** Gets the fixed frame rate count of the particle system.
@return Fixed frame rate count of the particle system.
*/
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);
/** Gets the time scale of the particle system.
@return Time scale of the particle system.
*/
virtual float getTimeScale();
/** Sets the time scale of the particle system.
@param Time scale of the particle system. (default: 1.0)
*/
virtual void setTimeScale(float scale = 1.0F);
protected:
virtual void updateBlendFunc();
@ -1460,10 +957,6 @@ protected:
Color4F _endColor;
/** end color variance of each particle */
Color4F _endColorVar;
/** hsv color of each particle */
HSV _hsv;
/** hsv color variance of each particle */
HSV _hsvVar;
//* initial angle of each particle
float _startSpin;
//* initial angle of each particle
@ -1472,18 +965,6 @@ protected:
float _endSpin;
//* initial angle of each particle
float _endSpinVar;
//* initial rotation of each particle
float _spawnAngle;
//* initial rotation of each particle
float _spawnAngleVar;
//* initial fade in time of each particle
float _spawnFadeIn;
//* initial fade in time variance of each particle
float _spawnFadeInVar;
//* initial scale in time of each particle
float _spawnScaleIn;
//* initial scale in time variance of each particle
float _spawnScaleInVar;
/** emission rate of the particles */
float _emissionRate;
/** maximum particles of the system */
@ -1494,35 +975,9 @@ protected:
BlendFunc _blendFunc;
/** does the alpha value modify color */
bool _opacityModifyRGB;
/** is the particle system animated */
bool _isLifeAnimated;
/** is the emitter particle system animated */
bool _isEmitterAnimated;
/** is the emitter particle system animated */
bool _isLoopAnimated;
/** variable keeping count of sprite frames or atlas indices added */
int _animIndexCount;
/** wether to start from first or last when using life animation */
bool _isAnimationReversed;
/** A map that stores particle animation index coords */
std::unordered_map<unsigned short, ParticleFrameDescriptor> _animationIndices;
/** A map that stores particle animation descriptors */
std::unordered_map<unsigned short, ParticleAnimationDescriptor> _animations;
/** A vector that stores ids of animation descriptors that are choosen at random */
std::vector<unsigned short> _randomAnimations;
/** Wether the animation goes with the time scale of the system or is independent. */
bool _animationTimescaleInd;
/** A rect that is used instead when an index is not found */
cocos2d::Rect _undefinedIndexRect;
/** does FlippedY variance of each particle */
int _yCoordFlipped;
/** Wether to use emission shapes for this particle system or not */
bool _isEmissionShapes;
/** A vector that contains emission shapes. */
std::vector<EmissionShape> _emissionShapes;
/** particles movement type: Free or Grouped
@since v0.8
*/
@ -1531,18 +986,6 @@ protected:
/** is the emitter paused */
bool _paused;
/** is particle system update paused */
bool _updatePaused;
/** time scale of the particle system */
float _timeScale;
/** Fixed frame rate of the particle system */
float _fixedFPS;
/** Fixed frame rate delta (internal) */
float _fixedFPSDelta;
/** is sourcePosition compatible */
bool _sourcePositionCompatible;

View File

@ -42,7 +42,6 @@ THE SOFTWARE.
#include "base/ccUTF8.h"
#include "renderer/ccShaders.h"
#include "renderer/backend/ProgramState.h"
#include "2d/CCTweenFunction.h"
NS_CC_BEGIN
@ -106,10 +105,6 @@ 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)");
ParticleSystemQuad* ret = new ParticleSystemQuad();
if (ret->initWithTotalParticles(numberOfParticles))
{
@ -278,24 +273,19 @@ void ParticleSystemQuad::initIndices()
}
}
inline void updatePosWithParticle(V3F_C4B_T2F_Quad* quad,
const Vec2& newPosition,
float size,
float scaleInSize,
float rotation,
float staticRotation)
inline void updatePosWithParticle(V3F_C4B_T2F_Quad* quad, const Vec2& newPosition, float size, float rotation)
{
// vertices
float size_2 = size / 2;
float x1 = -size_2 * scaleInSize;
float y1 = -size_2 * scaleInSize;
float x1 = -size_2;
float y1 = -size_2;
float x2 = size_2 * scaleInSize;
float y2 = size_2 * scaleInSize;
float x2 = size_2;
float y2 = size_2;
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);
float cr = cosf(r);
float sr = sinf(r);
float ax = x1 * cr - y1 * sr + x;
@ -367,36 +357,16 @@ void ParticleSystemQuad::updateParticleQuads()
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)
{
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);
newPos.set(*x, *y);
p2 = p1 - p2;
newPos.x -= p2.x - pos.x;
newPos.y -= p2.y - pos.y;
updatePosWithParticle(quadStart, newPos, *s, tweenfunc::expoEaseOut(*sid / *sil), *r, *sr);
}
}
else
{
for (int i = 0; i < _particleCount; ++i, ++startX, ++startY, ++x, ++y, ++quadStart, ++s, ++r, ++sr)
{
p2.set(*startX, *startY, 0);
worldToNodeTM.transformPoint(&p2);
newPos.set(*x, *y);
p2 = p1 - p2;
newPos.x -= p2.x - pos.x;
newPos.y -= p2.y - pos.y;
updatePosWithParticle(quadStart, newPos, *s, 1.0F, *r, *sr);
}
p2.set(*startX, *startY, 0);
worldToNodeTM.transformPoint(&p2);
newPos.set(*x, *y);
p2 = p1 - p2;
newPos.x -= p2.x - pos.x;
newPos.y -= p2.y - pos.y;
updatePosWithParticle(quadStart, newPos, *s, *r);
}
}
else if (_positionType == PositionType::RELATIVE)
@ -408,32 +378,14 @@ void ParticleSystemQuad::updateParticleQuads()
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)
{
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);
newPos.y = *y - (currentPosition.y - *startY);
newPos += pos;
updatePosWithParticle(quadStart, newPos, *s, tweenfunc::expoEaseOut(*sid / *sil), *r, *sr);
}
}
else
{
for (int i = 0; i < _particleCount; ++i, ++startX, ++startY, ++x, ++y, ++quadStart, ++s, ++r, ++sr)
{
newPos.set(*x, *y);
newPos.x = *x - (currentPosition.x - *startX);
newPos.y = *y - (currentPosition.y - *startY);
newPos += pos;
updatePosWithParticle(quadStart, newPos, *s, 1.0F, *r, *sr);
}
newPos.set(*x, *y);
newPos.x = *x - (currentPosition.x - *startX);
newPos.y = *y - (currentPosition.y - *startY);
newPos += pos;
updatePosWithParticle(quadStart, newPos, *s, *r);
}
}
else
@ -445,259 +397,53 @@ void ParticleSystemQuad::updateParticleQuads()
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)
{
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);
}
}
else
{
for (int i = 0; i < _particleCount; ++i, ++startX, ++startY, ++x, ++y, ++quadStart, ++s, ++r, ++sr)
{
newPos.set(*x + pos.x, *y + pos.y);
updatePosWithParticle(quadStart, newPos, *s, 1.0F, *r, *sr);
}
newPos.set(*x + pos.x, *y + pos.y);
updatePosWithParticle(quadStart, newPos, *s, *r);
}
}
V3F_C4B_T2F_Quad* quad = startQuad;
float* r = _particleData.colorR;
float* g = _particleData.colorG;
float* b = _particleData.colorB;
float* a = _particleData.colorA;
if (_isOpacityFadeInAllocated)
// set color
if (_opacityModifyRGB)
{
float* fadeDt = _particleData.opacityFadeInDelta;
float* fadeLn = _particleData.opacityFadeInLength;
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 (_isHSVAllocated)
for (int i = 0; i < _particleCount; ++i, ++quad, ++r, ++g, ++b, ++a)
{
float* hue = _particleData.hue;
float* sat = _particleData.sat;
float* val = _particleData.val;
if (_opacityModifyRGB)
{
auto hsv = HSV();
for (int i = 0; i < _particleCount;
++i, ++quad, ++r, ++g, ++b, ++a, ++hue, ++sat, ++val, ++fadeDt, ++fadeLn)
{
float colorR = *r;
float colorG = *g;
float colorB = *b;
float colorA = *a * (*fadeDt / *fadeLn);
hsv.set(colorR, colorG, colorB, colorA);
hsv.h += *hue;
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);
quad->br.colors.set(colF.r * colF.a * 255.0F, colF.g * colF.a * 255.0F, colF.b * colF.a * 255.0F,
colF.a * 255.0F);
quad->tl.colors.set(colF.r * colF.a * 255.0F, colF.g * colF.a * 255.0F, colF.b * colF.a * 255.0F,
colF.a * 255.0F);
quad->tr.colors.set(colF.r * colF.a * 255.0F, colF.g * colF.a * 255.0F, colF.b * colF.a * 255.0F,
colF.a * 255.0F);
}
}
else
{
auto hsv = HSV();
for (int i = 0; i < _particleCount;
++i, ++quad, ++r, ++g, ++b, ++a, ++hue, ++sat, ++val, ++fadeDt, ++fadeLn)
{
float colorR = *r;
float colorG = *g;
float colorB = *b;
float colorA = *a * (*fadeDt / *fadeLn);
hsv.set(colorR, colorG, colorB, colorA);
hsv.h += *hue;
hsv.s = abs(*sat);
hsv.v = abs(*val);
auto col = hsv.toColor4B();
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
{
// set color
if (_opacityModifyRGB)
{
for (int i = 0; i < _particleCount; ++i, ++quad, ++r, ++g, ++b, ++a, ++fadeDt, ++fadeLn)
{
uint8_t colorR = *r * *a * 255;
uint8_t colorG = *g * *a * 255;
uint8_t colorB = *b * *a * 255;
uint8_t colorA = *a * (*fadeDt / *fadeLn) * 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
{
for (int i = 0; i < _particleCount; ++i, ++quad, ++r, ++g, ++b, ++a, ++fadeDt, ++fadeLn)
{
uint8_t colorR = *r * 255;
uint8_t colorG = *g * 255;
uint8_t colorB = *b * 255;
uint8_t colorA = *a * (*fadeDt / *fadeLn) * 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);
}
}
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
{
// HSV calculation is expensive, so we should skip it if it's not enabled.
if (_isHSVAllocated)
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)
{
float* hue = _particleData.hue;
float* sat = _particleData.sat;
float* val = _particleData.val;
if (_opacityModifyRGB)
{
auto hsv = HSV();
for (int i = 0; i < _particleCount; ++i, ++quad, ++r, ++g, ++b, ++a, ++hue, ++sat, ++val)
{
float colorR = *r;
float colorG = *g;
float colorB = *b;
float colorA = *a;
hsv.set(colorR, colorG, colorB, colorA);
hsv.h += *hue;
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);
quad->br.colors.set(colF.r * colF.a * 255.0F, colF.g * colF.a * 255.0F, colF.b * colF.a * 255.0F,
colF.a * 255.0F);
quad->tl.colors.set(colF.r * colF.a * 255.0F, colF.g * colF.a * 255.0F, colF.b * colF.a * 255.0F,
colF.a * 255.0F);
quad->tr.colors.set(colF.r * colF.a * 255.0F, colF.g * colF.a * 255.0F, colF.b * colF.a * 255.0F,
colF.a * 255.0F);
}
}
else
{
auto hsv = HSV();
for (int i = 0; i < _particleCount; ++i, ++quad, ++r, ++g, ++b, ++a, ++hue, ++sat, ++val)
{
float colorR = *r;
float colorG = *g;
float colorB = *b;
float colorA = *a;
hsv.set(colorR, colorG, colorB, colorA);
hsv.h += *hue;
hsv.s = abs(*sat);
hsv.v = abs(*val);
auto col = hsv.toColor4B();
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
{
// set color
if (_opacityModifyRGB)
{
for (int i = 0; i < _particleCount; ++i, ++quad, ++r, ++g, ++b, ++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
{
for (int i = 0; i < _particleCount; ++i, ++quad, ++r, ++g, ++b, ++a)
{
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);
}
}
}
}
// The reason for using for-loops separately for every property is because
// When the processor needs to read from or write to a location in memory,
// it first checks whether a copy of that data is in the cpu's cache.
// And wether if every property's memory of the particle system is continuous,
// for the purpose of improving cache hit rate, we should process only one property in one for-loop.
// It was proved to be effective especially for low-end devices.
if (_isLifeAnimated || _isEmitterAnimated || _isLoopAnimated || _isAnimAllocated)
{
V3F_C4B_T2F_Quad* quad = startQuad;
unsigned short* cellIndex = _particleData.animCellIndex;
ParticleFrameDescriptor index;
for (int i = 0; i < _particleCount; ++i, ++quad, ++cellIndex)
{
float left = 0.0F, bottom = 0.0F, top = 1.0F, right = 1.0F;
// TODO: index.isRotated should be treated accordingly
auto iter = _animationIndices.find(*cellIndex);
if (iter == _animationIndices.end())
index.rect = {0, 0, float(_texture->getPixelsWide()), float(_texture->getPixelsHigh())};
else
index = iter->second;
auto texWidth = _texture->getPixelsWide();
auto texHeight = _texture->getPixelsHigh();
left = index.rect.origin.x / texWidth;
right = (index.rect.origin.x + index.rect.size.x) / texWidth;
top = index.rect.origin.y / texHeight;
bottom = (index.rect.origin.y + index.rect.size.y) / texHeight;
quad->bl.texCoords.u = left;
quad->bl.texCoords.v = bottom;
quad->br.texCoords.u = right;
quad->br.texCoords.v = bottom;
quad->tl.texCoords.u = left;
quad->tl.texCoords.v = top;
quad->tr.texCoords.u = right;
quad->tr.texCoords.v = top;
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);
}
}
}

View File

@ -171,8 +171,9 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
Log.d(TAG, "onResume()");
paused = false;
super.onResume();
this.hideVirtualButton();
resumeIfHasFocus();
if (this.hasFocus) {
resume();
}
}
@Override
@ -181,7 +182,15 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
super.onWindowFocusChanged(hasFocus);
this.hasFocus = hasFocus;
resumeIfHasFocus();
if (this.hasFocus && !paused) {
resume();
}
}
private void resume() {
this.hideVirtualButton();
Cocos2dxHelper.onResume();
mGLSurfaceView.onResume();
}
private void resumeIfHasFocus() {
@ -190,9 +199,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
boolean readyToPlay = !isDeviceLocked() && !isDeviceAsleep();
if(hasFocus && readyToPlay) {
this.hideVirtualButton();
Cocos2dxHelper.onResume();
mGLSurfaceView.onResume();
resume();
}
}