coding style fix

This commit is contained in:
minggo 2014-05-28 17:41:34 +08:00
parent d4d2bbfdfd
commit 2e7865a4f6
21 changed files with 230 additions and 249 deletions

View File

@ -263,7 +263,7 @@ AccelAmplitude* AccelAmplitude::clone() const
return a; return a;
} }
AccelAmplitude::~AccelAmplitude(void) AccelAmplitude::~AccelAmplitude()
{ {
CC_SAFE_DELETE(_other); CC_SAFE_DELETE(_other);
} }

View File

@ -169,7 +169,7 @@ public:
/** get amplitude rate */ /** get amplitude rate */
inline float getRate(void) const { return _rate; } inline float getRate(void) const { return _rate; }
/** set amplitude rate */ /** set amplitude rate */
inline void setRate(float fRate) { _rate = fRate; } inline void setRate(float rate) { _rate = rate; }
// Overrides // Overrides
virtual void startWithTarget(Node *target) override; virtual void startWithTarget(Node *target) override;
@ -182,7 +182,7 @@ CC_CONSTRUCTOR_ACCESS:
virtual ~AccelDeccelAmplitude(); virtual ~AccelDeccelAmplitude();
/** initializes the action with an inner action that has the amplitude property, and a duration time */ /** initializes the action with an inner action that has the amplitude property, and a duration time */
bool initWithAction(Action *pAction, float duration); bool initWithAction(Action *action, float duration);
protected: protected:
float _rate; float _rate;
@ -232,7 +232,7 @@ public:
static DeccelAmplitude* create(Action *action, float duration); static DeccelAmplitude* create(Action *action, float duration);
/** get amplitude rate */ /** get amplitude rate */
inline float getRate(void) const { return _rate; } inline float getRate() const { return _rate; }
/** set amplitude rate */ /** set amplitude rate */
inline void setRate(float rate) { _rate = rate; } inline void setRate(float rate) { _rate = rate; }

View File

@ -57,7 +57,7 @@ ExtraAction* ExtraAction::create()
} }
return ret; return ret;
} }
ExtraAction* ExtraAction::clone(void) const ExtraAction* ExtraAction::clone() const
{ {
// no copy constructor // no copy constructor
auto a = new ExtraAction(); auto a = new ExtraAction();
@ -65,7 +65,7 @@ ExtraAction* ExtraAction::clone(void) const
return a; return a;
} }
ExtraAction* ExtraAction::reverse(void) const ExtraAction* ExtraAction::reverse() const
{ {
return ExtraAction::create(); return ExtraAction::create();
} }
@ -102,7 +102,7 @@ bool ActionInterval::initWithDuration(float d)
return true; return true;
} }
bool ActionInterval::isDone(void) const bool ActionInterval::isDone() const
{ {
return _elapsed >= _duration; return _elapsed >= _duration;
} }
@ -134,7 +134,7 @@ void ActionInterval::setAmplitudeRate(float amp)
CCASSERT(0, ""); CCASSERT(0, "");
} }
float ActionInterval::getAmplitudeRate(void) float ActionInterval::getAmplitudeRate()
{ {
// Abstract class needs implementation // Abstract class needs implementation
CCASSERT(0, ""); CCASSERT(0, "");
@ -260,7 +260,7 @@ bool Sequence::initWithTwoActions(FiniteTimeAction *actionOne, FiniteTimeAction
return true; return true;
} }
Sequence* Sequence::clone(void) const Sequence* Sequence::clone() const
{ {
// no copy constructor // no copy constructor
auto a = new Sequence(); auto a = new Sequence();
@ -507,7 +507,7 @@ bool RepeatForever::initWithAction(ActionInterval *action)
return true; return true;
} }
RepeatForever *RepeatForever::clone(void) const RepeatForever *RepeatForever::clone() const
{ {
// no copy constructor // no copy constructor
auto a = new RepeatForever(); auto a = new RepeatForever();
@ -909,7 +909,7 @@ bool RotateBy::initWithDuration(float duration, const Vec3& deltaAngle3D)
} }
RotateBy* RotateBy::clone(void) const RotateBy* RotateBy::clone() const
{ {
// no copy constructor // no copy constructor
auto a = new RotateBy(); auto a = new RotateBy();
@ -993,7 +993,7 @@ bool MoveBy::initWithDuration(float duration, const Vec2& deltaPosition)
return false; return false;
} }
MoveBy* MoveBy::clone(void) const MoveBy* MoveBy::clone() const
{ {
// no copy constructor // no copy constructor
auto a = new MoveBy(); auto a = new MoveBy();
@ -1055,7 +1055,7 @@ bool MoveTo::initWithDuration(float duration, const Vec2& position)
return false; return false;
} }
MoveTo* MoveTo::clone(void) const MoveTo* MoveTo::clone() const
{ {
// no copy constructor // no copy constructor
auto a = new MoveTo(); auto a = new MoveTo();
@ -1107,7 +1107,7 @@ bool SkewTo::initWithDuration(float t, float sx, float sy)
return bRet; return bRet;
} }
SkewTo* SkewTo::clone(void) const SkewTo* SkewTo::clone() const
{ {
// no copy constructor // no copy constructor
auto a = new SkewTo(); auto a = new SkewTo();
@ -1277,7 +1277,7 @@ bool JumpBy::initWithDuration(float duration, const Vec2& position, float height
return false; return false;
} }
JumpBy* JumpBy::clone(void) const JumpBy* JumpBy::clone() const
{ {
// no copy constructor // no copy constructor
auto a = new JumpBy(); auto a = new JumpBy();
@ -1337,7 +1337,7 @@ JumpTo* JumpTo::create(float duration, const Vec2& position, float height, int j
return jumpTo; return jumpTo;
} }
JumpTo* JumpTo::clone(void) const JumpTo* JumpTo::clone() const
{ {
// no copy constructor // no copy constructor
auto a = new JumpTo(); auto a = new JumpTo();
@ -1400,7 +1400,7 @@ void BezierBy::startWithTarget(Node *target)
_previousPosition = _startPosition = target->getPosition(); _previousPosition = _startPosition = target->getPosition();
} }
BezierBy* BezierBy::clone(void) const BezierBy* BezierBy::clone() const
{ {
// no copy constructor // no copy constructor
auto a = new BezierBy(); auto a = new BezierBy();
@ -1441,7 +1441,7 @@ void BezierBy::update(float time)
} }
} }
BezierBy* BezierBy::reverse(void) const BezierBy* BezierBy::reverse() const
{ {
ccBezierConfig r; ccBezierConfig r;
@ -1477,7 +1477,7 @@ bool BezierTo::initWithDuration(float t, const ccBezierConfig &c)
return false; return false;
} }
BezierTo* BezierTo::clone(void) const BezierTo* BezierTo::clone() const
{ {
// no copy constructor // no copy constructor
auto a = new BezierTo(); auto a = new BezierTo();
@ -1573,7 +1573,7 @@ bool ScaleTo::initWithDuration(float duration, float sx, float sy, float sz)
return false; return false;
} }
ScaleTo* ScaleTo::clone(void) const ScaleTo* ScaleTo::clone() const
{ {
// no copy constructor // no copy constructor
auto a = new ScaleTo(); auto a = new ScaleTo();
@ -1641,7 +1641,7 @@ ScaleBy* ScaleBy::create(float duration, float sx, float sy, float sz)
return scaleBy; return scaleBy;
} }
ScaleBy* ScaleBy::clone(void) const ScaleBy* ScaleBy::clone() const
{ {
// no copy constructor // no copy constructor
auto a = new ScaleBy(); auto a = new ScaleBy();
@ -2091,7 +2091,7 @@ ReverseTime::ReverseTime() : _other(nullptr)
} }
ReverseTime::~ReverseTime(void) ReverseTime::~ReverseTime()
{ {
CC_SAFE_RELEASE(_other); CC_SAFE_RELEASE(_other);
} }
@ -2219,7 +2219,7 @@ void Animate::startWithTarget(Node *target)
_executedLoops = 0; _executedLoops = 0;
} }
void Animate::stop(void) void Animate::stop()
{ {
if (_animation->getRestoreOriginalFrame() && _target) if (_animation->getRestoreOriginalFrame() && _target)
{ {
@ -2349,7 +2349,7 @@ TargetedAction* TargetedAction::clone() const
return a; return a;
} }
TargetedAction* TargetedAction::reverse(void) const TargetedAction* TargetedAction::reverse() const
{ {
// just reverse the internal action // just reverse the internal action
auto a = new TargetedAction(); auto a = new TargetedAction();
@ -2364,7 +2364,7 @@ void TargetedAction::startWithTarget(Node *target)
_action->startWithTarget(_forcedTarget); _action->startWithTarget(_forcedTarget);
} }
void TargetedAction::stop(void) void TargetedAction::stop()
{ {
_action->stop(); _action->stop();
} }

View File

@ -766,7 +766,7 @@ public:
// Overrides // Overrides
// //
virtual Blink* clone() const override; virtual Blink* clone() const override;
virtual Blink* reverse(void) const override; virtual Blink* reverse() const override;
virtual void update(float time) override; virtual void update(float time) override;
virtual void startWithTarget(Node *target) override; virtual void startWithTarget(Node *target) override;
virtual void stop() override; virtual void stop() override;

View File

@ -39,16 +39,16 @@ NS_CC_BEGIN
// //
typedef struct _hashElement typedef struct _hashElement
{ {
struct _ccArray *actions; struct _ccArray *actions;
Node *target; Node *target;
int actionIndex; int actionIndex;
Action *currentAction; Action *currentAction;
bool currentActionSalvaged; bool currentActionSalvaged;
bool paused; bool paused;
UT_hash_handle hh; UT_hash_handle hh;
} tHashElement; } tHashElement;
ActionManager::ActionManager(void) ActionManager::ActionManager()
: _targets(nullptr), : _targets(nullptr),
_currentTarget(nullptr), _currentTarget(nullptr),
_currentTargetSalvaged(false) _currentTargetSalvaged(false)
@ -56,7 +56,7 @@ ActionManager::ActionManager(void)
} }
ActionManager::~ActionManager(void) ActionManager::~ActionManager()
{ {
CCLOGINFO("deallocing ActionManager: %p", this); CCLOGINFO("deallocing ActionManager: %p", this);

View File

@ -113,7 +113,7 @@ ProgressFromTo* ProgressFromTo::clone() const
} }
ProgressFromTo* ProgressFromTo::reverse(void) const ProgressFromTo* ProgressFromTo::reverse() const
{ {
return ProgressFromTo::create(_duration, _to, _from); return ProgressFromTo::create(_duration, _to, _from);
} }

View File

@ -49,7 +49,7 @@ public:
// Overrides // Overrides
// //
virtual ProgressTo* clone() const override; virtual ProgressTo* clone() const override;
virtual ProgressTo* reverse(void) const override; virtual ProgressTo* reverse() const override;
virtual void startWithTarget(Node *target) override; virtual void startWithTarget(Node *target) override;
virtual void update(float time) override; virtual void update(float time) override;
@ -82,7 +82,7 @@ public:
// Overrides // Overrides
// //
virtual ProgressFromTo* clone() const override; virtual ProgressFromTo* clone() const override;
virtual ProgressFromTo* reverse(void) const override; virtual ProgressFromTo* reverse() const override;
virtual void startWithTarget(Node *target) override; virtual void startWithTarget(Node *target) override;
virtual void update(float time) override; virtual void update(float time) override;

View File

@ -247,7 +247,7 @@ ShuffleTiles* ShuffleTiles::clone() const
return a; return a;
} }
ShuffleTiles::~ShuffleTiles(void) ShuffleTiles::~ShuffleTiles()
{ {
CC_SAFE_DELETE_ARRAY(_tilesOrder); CC_SAFE_DELETE_ARRAY(_tilesOrder);
CC_SAFE_DELETE_ARRAY(_tiles); CC_SAFE_DELETE_ARRAY(_tiles);
@ -255,8 +255,7 @@ ShuffleTiles::~ShuffleTiles(void)
void ShuffleTiles::shuffle(unsigned int *array, unsigned int len) void ShuffleTiles::shuffle(unsigned int *array, unsigned int len)
{ {
int i; for (int i = len - 1; i >= 0; i-- )
for( i = len - 1; i >= 0; i-- )
{ {
unsigned int j = rand() % (i+1); unsigned int j = rand() % (i+1);
unsigned int v = array[i]; unsigned int v = array[i];
@ -308,14 +307,12 @@ void ShuffleTiles::startWithTarget(Node *target)
_tilesCount = _gridSize.width * _gridSize.height; _tilesCount = _gridSize.width * _gridSize.height;
_tilesOrder = new unsigned int[_tilesCount]; _tilesOrder = new unsigned int[_tilesCount];
int i, j;
unsigned int k;
/** /**
* Use k to loop. Because _tilesCount is unsigned int, * Use k to loop. Because _tilesCount is unsigned int,
* and i is used later for int. * and i is used later for int.
*/ */
for (k = 0; k < _tilesCount; ++k) for (unsigned int k = 0; k < _tilesCount; ++k)
{ {
_tilesOrder[k] = k; _tilesOrder[k] = k;
} }
@ -325,9 +322,9 @@ void ShuffleTiles::startWithTarget(Node *target)
_tiles = (struct Tile *)new Tile[_tilesCount]; _tiles = (struct Tile *)new Tile[_tilesCount];
Tile *tileArray = (Tile*) _tiles; Tile *tileArray = (Tile*) _tiles;
for (i = 0; i < _gridSize.width; ++i) for (int i = 0; i < _gridSize.width; ++i)
{ {
for (j = 0; j < _gridSize.height; ++j) for ( int j = 0; j < _gridSize.height; ++j)
{ {
tileArray->position = Vec2((float)i, (float)j); tileArray->position = Vec2((float)i, (float)j);
tileArray->startPosition = Vec2((float)i, (float)j); tileArray->startPosition = Vec2((float)i, (float)j);
@ -339,13 +336,11 @@ void ShuffleTiles::startWithTarget(Node *target)
void ShuffleTiles::update(float time) void ShuffleTiles::update(float time)
{ {
int i, j;
Tile *tileArray = (Tile*)_tiles; Tile *tileArray = (Tile*)_tiles;
for (i = 0; i < _gridSize.width; ++i) for (int i = 0; i < _gridSize.width; ++i)
{ {
for (j = 0; j < _gridSize.height; ++j) for (int j = 0; j < _gridSize.height; ++j)
{ {
tileArray->position = Vec2((float)tileArray->delta.width, (float)tileArray->delta.height) * time; tileArray->position = Vec2((float)tileArray->delta.width, (float)tileArray->delta.height) * time;
placeTile(Vec2(i, j), tileArray); placeTile(Vec2(i, j), tileArray);
@ -429,11 +424,9 @@ void FadeOutTRTiles::transformTile(const Vec2& pos, float distance)
void FadeOutTRTiles::update(float time) void FadeOutTRTiles::update(float time)
{ {
int i, j; for (int i = 0; i < _gridSize.width; ++i)
for (i = 0; i < _gridSize.width; ++i)
{ {
for (j = 0; j < _gridSize.height; ++j) for (int j = 0; j < _gridSize.height; ++j)
{ {
float distance = testFunc(Size(i, j), time); float distance = testFunc(Size(i, j), time);
if ( distance == 0 ) if ( distance == 0 )
@ -652,8 +645,7 @@ TurnOffTiles::~TurnOffTiles(void)
void TurnOffTiles::shuffle(unsigned int *array, unsigned int len) void TurnOffTiles::shuffle(unsigned int *array, unsigned int len)
{ {
int i; for (int i = len - 1; i >= 0; i--)
for (i = len - 1; i >= 0; i--)
{ {
unsigned int j = rand() % (i+1); unsigned int j = rand() % (i+1);
unsigned int v = array[i]; unsigned int v = array[i];
@ -677,8 +669,6 @@ void TurnOffTiles::turnOffTile(const Vec2& pos)
void TurnOffTiles::startWithTarget(Node *target) void TurnOffTiles::startWithTarget(Node *target)
{ {
unsigned int i;
TiledGrid3DAction::startWithTarget(target); TiledGrid3DAction::startWithTarget(target);
if (_seed != (unsigned int)-1) if (_seed != (unsigned int)-1)
@ -689,7 +679,7 @@ void TurnOffTiles::startWithTarget(Node *target)
_tilesCount = _gridSize.width * _gridSize.height; _tilesCount = _gridSize.width * _gridSize.height;
_tilesOrder = new unsigned int[_tilesCount]; _tilesOrder = new unsigned int[_tilesCount];
for (i = 0; i < _tilesCount; ++i) for (unsigned int i = 0; i < _tilesCount; ++i)
{ {
_tilesOrder[i] = i; _tilesOrder[i] = i;
} }
@ -699,11 +689,10 @@ void TurnOffTiles::startWithTarget(Node *target)
void TurnOffTiles::update(float time) void TurnOffTiles::update(float time)
{ {
unsigned int i, l, t; unsigned int l = (unsigned int)(time * (float)_tilesCount);
l = (unsigned int)(time * (float)_tilesCount); unsigned int t = 0;
for (unsigned int i = 0; i < _tilesCount; i++ )
for( i = 0; i < _tilesCount; i++ )
{ {
t = _tilesOrder[i]; t = _tilesOrder[i];
Vec2 tilePos = Vec2( (unsigned int)(t / _gridSize.height), t % (unsigned int)_gridSize.height ); Vec2 tilePos = Vec2( (unsigned int)(t / _gridSize.height), t % (unsigned int)_gridSize.height );
@ -765,11 +754,9 @@ WavesTiles3D* WavesTiles3D::clone() const
void WavesTiles3D::update(float time) void WavesTiles3D::update(float time)
{ {
int i, j; for (int i = 0; i < _gridSize.width; i++ )
for( i = 0; i < _gridSize.width; i++ )
{ {
for( j = 0; j < _gridSize.height; j++ ) for (int j = 0; j < _gridSize.height; j++ )
{ {
Quad3 coords = getOriginalTile(Vec2(i, j)); Quad3 coords = getOriginalTile(Vec2(i, j));
@ -830,14 +817,12 @@ JumpTiles3D* JumpTiles3D::clone() const
void JumpTiles3D::update(float time) void JumpTiles3D::update(float time)
{ {
int i, j;
float sinz = (sinf((float)M_PI * time * _jumps * 2) * _amplitude * _amplitudeRate ); float sinz = (sinf((float)M_PI * time * _jumps * 2) * _amplitude * _amplitudeRate );
float sinz2 = (sinf((float)M_PI * (time * _jumps * 2 + 1)) * _amplitude * _amplitudeRate ); float sinz2 = (sinf((float)M_PI * (time * _jumps * 2 + 1)) * _amplitude * _amplitudeRate );
for( i = 0; i < _gridSize.width; i++ ) for (int i = 0; i < _gridSize.width; i++ )
{ {
for( j = 0; j < _gridSize.height; j++ ) for (int j = 0; j < _gridSize.height; j++ )
{ {
Quad3 coords = getOriginalTile(Vec2(i, j)); Quad3 coords = getOriginalTile(Vec2(i, j));
@ -906,9 +891,7 @@ void SplitRows::startWithTarget(Node *target)
void SplitRows::update(float time) void SplitRows::update(float time)
{ {
unsigned int j; for (unsigned int j = 0; j < _gridSize.height; ++j)
for (j = 0; j < _gridSize.height; ++j)
{ {
Quad3 coords = getOriginalTile(Vec2(0, j)); Quad3 coords = getOriginalTile(Vec2(0, j));
float direction = 1; float direction = 1;
@ -971,9 +954,7 @@ void SplitCols::startWithTarget(Node *target)
void SplitCols::update(float time) void SplitCols::update(float time)
{ {
unsigned int i; for (unsigned int i = 0; i < _gridSize.width; ++i)
for (i = 0; i < _gridSize.width; ++i)
{ {
Quad3 coords = getOriginalTile(Vec2(i, 0)); Quad3 coords = getOriginalTile(Vec2(i, 0));
float direction = 1; float direction = 1;

View File

@ -259,11 +259,11 @@ public:
static WavesTiles3D* create(float duration, const Size& gridSize, unsigned int waves, float amplitude); static WavesTiles3D* create(float duration, const Size& gridSize, unsigned int waves, float amplitude);
/** waves amplitude */ /** waves amplitude */
inline float getAmplitude(void) const { return _amplitude; } inline float getAmplitude() const { return _amplitude; }
inline void setAmplitude(float amplitude) { _amplitude = amplitude; } inline void setAmplitude(float amplitude) { _amplitude = amplitude; }
/** waves amplitude rate */ /** waves amplitude rate */
inline float getAmplitudeRate(void) const { return _amplitudeRate; } inline float getAmplitudeRate() const { return _amplitudeRate; }
inline void setAmplitudeRate(float amplitudeRate) { _amplitudeRate = amplitudeRate; } inline void setAmplitudeRate(float amplitudeRate) { _amplitudeRate = amplitudeRate; }
// Override // Override
@ -296,11 +296,11 @@ public:
static JumpTiles3D* create(float duration, const Size& gridSize, unsigned int numberOfJumps, float amplitude); static JumpTiles3D* create(float duration, const Size& gridSize, unsigned int numberOfJumps, float amplitude);
/** amplitude of the sin*/ /** amplitude of the sin*/
inline float getAmplitude(void) const { return _amplitude; } inline float getAmplitude() const { return _amplitude; }
inline void setAmplitude(float amplitude) { _amplitude = amplitude; } inline void setAmplitude(float amplitude) { _amplitude = amplitude; }
/** amplitude rate */ /** amplitude rate */
inline float getAmplitudeRate(void) const { return _amplitudeRate; } inline float getAmplitudeRate() const { return _amplitudeRate; }
inline void setAmplitudeRate(float amplitudeRate) { _amplitudeRate = amplitudeRate; } inline void setAmplitudeRate(float amplitudeRate) { _amplitudeRate = amplitudeRate; }
// Override // Override

View File

@ -28,10 +28,10 @@ THE SOFTWARE.
NS_CC_BEGIN NS_CC_BEGIN
ActionTween* ActionTween::create(float aDuration, const std::string& key, float from, float to) ActionTween* ActionTween::create(float duration, const std::string& key, float from, float to)
{ {
ActionTween* ret = new ActionTween(); ActionTween* ret = new ActionTween();
if (ret && ret->initWithDuration(aDuration, key, from, to)) if (ret && ret->initWithDuration(duration, key, from, to))
{ {
ret->autorelease(); ret->autorelease();
} }

View File

@ -83,7 +83,7 @@ CC_CONSTRUCTOR_ACCESS:
bool initWithDuration(float duration, const std::string& key, float from, float to); bool initWithDuration(float duration, const std::string& key, float from, float to);
protected: protected:
std::string _key; std::string _key;
float _from, _to; float _from, _to;
float _delta; float _delta;
}; };

View File

@ -92,7 +92,7 @@ static void setGLBufferData(void *buf, GLuint bufSize)
#endif // EMSCRIPTEN #endif // EMSCRIPTEN
static void lazy_init( void ) static void lazy_init()
{ {
if( ! s_initialized ) { if( ! s_initialized ) {
@ -123,7 +123,7 @@ void free()
s_initialized = false; s_initialized = false;
} }
void drawPoint( const Vec2& point ) void drawPoint(const Vec2& point)
{ {
lazy_init(); lazy_init();
@ -198,7 +198,7 @@ void drawPoints( const Vec2 *points, unsigned int numberOfPoints )
} }
void drawLine( const Vec2& origin, const Vec2& destination ) void drawLine(const Vec2& origin, const Vec2& destination)
{ {
lazy_init(); lazy_init();
@ -231,7 +231,7 @@ void drawRect( Vec2 origin, Vec2 destination )
drawLine(Vec2(origin.x, destination.y), Vec2(origin.x, origin.y)); drawLine(Vec2(origin.x, destination.y), Vec2(origin.x, origin.y));
} }
void drawSolidRect( Vec2 origin, Vec2 destination, Color4F color ) void drawSolidRect(Vec2 origin, Vec2 destination, Color4F color)
{ {
Vec2 vertices[] = { Vec2 vertices[] = {
origin, origin,
@ -243,7 +243,7 @@ void drawSolidRect( Vec2 origin, Vec2 destination, Color4F color )
drawSolidPoly(vertices, 4, color ); drawSolidPoly(vertices, 4, color );
} }
void drawPoly( const Vec2 *poli, unsigned int numberOfPoints, bool closePolygon ) void drawPoly(const Vec2 *poli, unsigned int numberOfPoints, bool closePolygon)
{ {
lazy_init(); lazy_init();
@ -295,7 +295,7 @@ void drawPoly( const Vec2 *poli, unsigned int numberOfPoints, bool closePolygon
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, numberOfPoints); CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, numberOfPoints);
} }
void drawSolidPoly( const Vec2 *poli, unsigned int numberOfPoints, Color4F color ) void drawSolidPoly(const Vec2 *poli, unsigned int numberOfPoints, Color4F color)
{ {
lazy_init(); lazy_init();
@ -309,7 +309,7 @@ void drawSolidPoly( const Vec2 *poli, unsigned int numberOfPoints, Color4F color
Vec2* newPoli = new Vec2[numberOfPoints]; Vec2* newPoli = new Vec2[numberOfPoints];
// iPhone and 32-bit machines optimization // iPhone and 32-bit machines optimization
if( sizeof(Vec2) == sizeof(Vec2) ) if (sizeof(Vec2) == sizeof(Vec2))
{ {
#ifdef EMSCRIPTEN #ifdef EMSCRIPTEN
setGLBufferData((void*) poli, numberOfPoints * sizeof(Vec2)); setGLBufferData((void*) poli, numberOfPoints * sizeof(Vec2));
@ -321,7 +321,7 @@ void drawSolidPoly( const Vec2 *poli, unsigned int numberOfPoints, Color4F color
else else
{ {
// Mac on 64-bit // Mac on 64-bit
for( unsigned int i=0; i<numberOfPoints;i++) for(unsigned int i = 0; i < numberOfPoints; i++)
{ {
newPoli[i] = Vec2( poli[i].x, poli[i].y ); newPoli[i] = Vec2( poli[i].x, poli[i].y );
} }
@ -532,7 +532,7 @@ void drawCubicBezier(const Vec2& origin, const Vec2& control1, const Vec2& contr
Vec2* vertices = new Vec2[segments + 1]; Vec2* vertices = new Vec2[segments + 1];
float t = 0; float t = 0;
for(unsigned int i = 0; i < segments; i++) for (unsigned int i = 0; i < segments; i++)
{ {
vertices[i].x = powf(1 - t, 3) * origin.x + 3.0f * powf(1 - t, 2) * t * control1.x + 3.0f * (1 - t) * t * t * control2.x + t * t * t * destination.x; vertices[i].x = powf(1 - t, 3) * origin.x + 3.0f * powf(1 - t, 2) * t * control1.x + 3.0f * (1 - t) * t * t * control2.x + t * t * t * destination.x;
vertices[i].y = powf(1 - t, 3) * origin.y + 3.0f * powf(1 - t, 2) * t * control1.y + 3.0f * (1 - t) * t * t * control2.y + t * t * t * destination.y; vertices[i].y = powf(1 - t, 3) * origin.y + 3.0f * powf(1 - t, 2) * t * control1.y + 3.0f * (1 - t) * t * t * control2.y + t * t * t * destination.y;

View File

@ -85,40 +85,40 @@ namespace DrawPrimitives
void free(); void free();
/** draws a point given x and y coordinate measured in points */ /** draws a point given x and y coordinate measured in points */
void drawPoint( const Vec2& point ); void drawPoint(const Vec2& point);
/** draws an array of points. /** draws an array of points.
@since v0.7.2 @since v0.7.2
*/ */
void drawPoints( const Vec2 *points, unsigned int numberOfPoints ); void drawPoints(const Vec2 *points, unsigned int numberOfPoints);
/** draws a line given the origin and destination point measured in points */ /** draws a line given the origin and destination point measured in points */
void drawLine( const Vec2& origin, const Vec2& destination ); void drawLine(const Vec2& origin, const Vec2& destination);
/** draws a rectangle given the origin and destination point measured in points. */ /** draws a rectangle given the origin and destination point measured in points. */
void drawRect( Vec2 origin, Vec2 destination ); void drawRect(Vec2 origin, Vec2 destination);
/** draws a solid rectangle given the origin and destination point measured in points. /** draws a solid rectangle given the origin and destination point measured in points.
@since 1.1 @since 1.1
*/ */
void drawSolidRect( Vec2 origin, Vec2 destination, Color4F color ); void drawSolidRect(Vec2 origin, Vec2 destination, Color4F color);
/** draws a polygon given a pointer to point coordinates and the number of vertices measured in points. /** draws a polygon given a pointer to point coordinates and the number of vertices measured in points.
The polygon can be closed or open The polygon can be closed or open
*/ */
void drawPoly( const Vec2 *vertices, unsigned int numOfVertices, bool closePolygon ); void drawPoly(const Vec2 *vertices, unsigned int numOfVertices, bool closePolygon);
/** draws a solid polygon given a pointer to CGPoint coordinates, the number of vertices measured in points, and a color. /** draws a solid polygon given a pointer to CGPoint coordinates, the number of vertices measured in points, and a color.
*/ */
void drawSolidPoly( const Vec2 *poli, unsigned int numberOfPoints, Color4F color ); void drawSolidPoly(const Vec2 *poli, unsigned int numberOfPoints, Color4F color);
/** draws a circle given the center, radius and number of segments. */ /** draws a circle given the center, radius and number of segments. */
void drawCircle( const Vec2& center, float radius, float angle, unsigned int segments, bool drawLineToCenter, float scaleX, float scaleY); void drawCircle(const Vec2& center, float radius, float angle, unsigned int segments, bool drawLineToCenter, float scaleX, float scaleY);
void drawCircle( const Vec2& center, float radius, float angle, unsigned int segments, bool drawLineToCenter); void drawCircle(const Vec2& center, float radius, float angle, unsigned int segments, bool drawLineToCenter);
/** draws a solid circle given the center, radius and number of segments. */ /** draws a solid circle given the center, radius and number of segments. */
void drawSolidCircle( const Vec2& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY); void drawSolidCircle(const Vec2& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY);
void drawSolidCircle( const Vec2& center, float radius, float angle, unsigned int segments); void drawSolidCircle(const Vec2& center, float radius, float angle, unsigned int segments);
/** draws a quad bezier path /** draws a quad bezier path
@warning This function could be pretty slow. Use it only for debugging purposes. @warning This function could be pretty slow. Use it only for debugging purposes.
@ -136,28 +136,28 @@ namespace DrawPrimitives
@warning This function could be pretty slow. Use it only for debugging purposes. @warning This function could be pretty slow. Use it only for debugging purposes.
@since v2.0 @since v2.0
*/ */
void drawCatmullRom( PointArray *arrayOfControlPoints, unsigned int segments ); void drawCatmullRom(PointArray *arrayOfControlPoints, unsigned int segments);
/** draws a Cardinal Spline path. /** draws a Cardinal Spline path.
@warning This function could be pretty slow. Use it only for debugging purposes. @warning This function could be pretty slow. Use it only for debugging purposes.
@since v2.0 @since v2.0
*/ */
void drawCardinalSpline( PointArray *config, float tension, unsigned int segments ); void drawCardinalSpline(PointArray *config, float tension, unsigned int segments);
/** set the drawing color with 4 unsigned bytes /** set the drawing color with 4 unsigned bytes
@since v2.0 @since v2.0
*/ */
void setDrawColor4B( GLubyte r, GLubyte g, GLubyte b, GLubyte a ); void setDrawColor4B(GLubyte r, GLubyte g, GLubyte b, GLubyte a);
/** set the drawing color with 4 floats /** set the drawing color with 4 floats
@since v2.0 @since v2.0
*/ */
void setDrawColor4F( GLfloat r, GLfloat g, GLfloat b, GLfloat a ); void setDrawColor4F(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
/** set the point size in points. Default 1. /** set the point size in points. Default 1.
@since v2.0 @since v2.0
*/ */
void setPointSize( GLfloat pointSize ); void setPointSize(GLfloat pointSize);
}; };

View File

@ -510,11 +510,11 @@ bool Node::isVisible() const
} }
/// isVisible setter /// isVisible setter
void Node::setVisible(bool var) void Node::setVisible(bool visible)
{ {
if(var != _visible) if(visible != _visible)
{ {
_visible = var; _visible = visible;
if(_visible) _transformUpdated = _transformDirty = _inverseDirty = true; if(_visible) _transformUpdated = _transformDirty = _inverseDirty = true;
} }
} }
@ -572,9 +572,9 @@ bool Node::isRunning() const
} }
/// parent setter /// parent setter
void Node::setParent(Node * var) void Node::setParent(Node * parent)
{ {
_parent = var; _parent = parent;
} }
/// isRelativeAnchorPoint getter /// isRelativeAnchorPoint getter
@ -599,15 +599,15 @@ int Node::getTag() const
} }
/// tag setter /// tag setter
void Node::setTag(int var) void Node::setTag(int tag)
{ {
_tag = var; _tag = tag ;
} }
/// userData setter /// userData setter
void Node::setUserData(void *var) void Node::setUserData(void *userData)
{ {
_userData = var; _userData = userData;
} }
int Node::getOrderOfArrival() const int Node::getOrderOfArrival() const
@ -621,14 +621,14 @@ void Node::setOrderOfArrival(int orderOfArrival)
_orderOfArrival = orderOfArrival; _orderOfArrival = orderOfArrival;
} }
void Node::setUserObject(Ref *pUserObject) void Node::setUserObject(Ref *userObject)
{ {
CC_SAFE_RETAIN(pUserObject); CC_SAFE_RETAIN(userObject);
CC_SAFE_RELEASE(_userObject); CC_SAFE_RELEASE(_userObject);
_userObject = pUserObject; _userObject = userObject;
} }
GLProgramState* Node::getGLProgramState() GLProgramState* Node::getGLProgramState() const
{ {
return _glProgramState; return _glProgramState;
} }
@ -652,7 +652,7 @@ void Node::setGLProgram(GLProgram *glProgram)
} }
} }
GLProgram * Node::getGLProgram() GLProgram * Node::getGLProgram() const
{ {
return _glProgramState ? _glProgramState->getGLProgram() : nullptr; return _glProgramState ? _glProgramState->getGLProgram() : nullptr;
} }
@ -671,7 +671,7 @@ Rect Node::getBoundingBox() const
return RectApplyAffineTransform(rect, getNodeToParentAffineTransform()); return RectApplyAffineTransform(rect, getNodeToParentAffineTransform());
} }
Node * Node::create(void) Node * Node::create()
{ {
Node * ret = new Node(); Node * ret = new Node();
if (ret && ret->init()) if (ret && ret->init())
@ -713,7 +713,7 @@ std::string Node::getDescription() const
} }
// lazy allocs // lazy allocs
void Node::childrenAlloc(void) void Node::childrenAlloc()
{ {
_children.reserve(4); _children.reserve(4);
} }
@ -1572,25 +1572,25 @@ void Node::updateTransform()
child->updateTransform(); child->updateTransform();
} }
Component* Node::getComponent(const std::string& pName) Component* Node::getComponent(const std::string& name)
{ {
if( _componentContainer ) if( _componentContainer )
return _componentContainer->get(pName); return _componentContainer->get(name);
return nullptr; return nullptr;
} }
bool Node::addComponent(Component *pComponent) bool Node::addComponent(Component *component)
{ {
// lazy alloc // lazy alloc
if( !_componentContainer ) if( !_componentContainer )
_componentContainer = new ComponentContainer(this); _componentContainer = new ComponentContainer(this);
return _componentContainer->add(pComponent); return _componentContainer->add(component);
} }
bool Node::removeComponent(const std::string& pName) bool Node::removeComponent(const std::string& name)
{ {
if( _componentContainer ) if( _componentContainer )
return _componentContainer->remove(pName); return _componentContainer->remove(name);
return false; return false;
} }
@ -1699,7 +1699,7 @@ GLubyte Node::getOpacity(void) const
return _realOpacity; return _realOpacity;
} }
GLubyte Node::getDisplayedOpacity(void) const GLubyte Node::getDisplayedOpacity() const
{ {
return _displayedOpacity; return _displayedOpacity;
} }

View File

@ -114,7 +114,7 @@ public:
* Allocates and initializes a node. * Allocates and initializes a node.
* @return A initialized node which is marked as "autorelease". * @return A initialized node which is marked as "autorelease".
*/ */
static Node * create(void); static Node * create();
/** /**
* Gets the description string. It makes debugging easier. * Gets the description string. It makes debugging easier.
@ -826,10 +826,10 @@ public:
* *
* @return The GLProgram (shader) currently used for this node * @return The GLProgram (shader) currently used for this node
*/ */
GLProgram* getGLProgram(); GLProgram* getGLProgram() const;
CC_DEPRECATED_ATTRIBUTE GLProgram* getShaderProgram() { return getGLProgram(); } CC_DEPRECATED_ATTRIBUTE GLProgram* getShaderProgram() const { return getGLProgram(); }
GLProgramState *getGLProgramState(); GLProgramState *getGLProgramState() const;
void setGLProgramState(GLProgramState *glProgramState); void setGLProgramState(GLProgramState *glProgramState);
/** /**
@ -1164,12 +1164,12 @@ public:
* Resumes all scheduled selectors, actions and event listeners. * Resumes all scheduled selectors, actions and event listeners.
* This method is called internally by onEnter * This method is called internally by onEnter
*/ */
CC_DEPRECATED_ATTRIBUTE void resumeSchedulerAndActions(void); CC_DEPRECATED_ATTRIBUTE void resumeSchedulerAndActions();
/** /**
* Pauses all scheduled selectors, actions and event listeners.. * Pauses all scheduled selectors, actions and event listeners..
* This method is called internally by onExit * This method is called internally by onExit
*/ */
CC_DEPRECATED_ATTRIBUTE void pauseSchedulerAndActions(void); CC_DEPRECATED_ATTRIBUTE void pauseSchedulerAndActions();
/* /*
* Update method will be called automatically every frame if "scheduleUpdate" is called, and the node is "live" * Update method will be called automatically every frame if "scheduleUpdate" is called, and the node is "live"
@ -1290,17 +1290,17 @@ public:
/** /**
* gets a component by its name * gets a component by its name
*/ */
Component* getComponent(const std::string& pName); Component* getComponent(const std::string& name);
/** /**
* adds a component * adds a component
*/ */
virtual bool addComponent(Component *pComponent); virtual bool addComponent(Component *component);
/** /**
* removes a component by its name * removes a component by its name
*/ */
virtual bool removeComponent(const std::string& pName); virtual bool removeComponent(const std::string& name);
/** /**
* removes all components * removes all components
@ -1331,14 +1331,14 @@ public:
virtual bool isCascadeOpacityEnabled() const; virtual bool isCascadeOpacityEnabled() const;
virtual void setCascadeOpacityEnabled(bool cascadeOpacityEnabled); virtual void setCascadeOpacityEnabled(bool cascadeOpacityEnabled);
virtual const Color3B& getColor(void) const; virtual const Color3B& getColor() const;
virtual const Color3B& getDisplayedColor() const; virtual const Color3B& getDisplayedColor() const;
virtual void setColor(const Color3B& color); virtual void setColor(const Color3B& color);
virtual void updateDisplayedColor(const Color3B& parentColor); virtual void updateDisplayedColor(const Color3B& parentColor);
virtual bool isCascadeColorEnabled() const; virtual bool isCascadeColorEnabled() const;
virtual void setCascadeColorEnabled(bool cascadeColorEnabled); virtual void setCascadeColorEnabled(bool cascadeColorEnabled);
virtual void setOpacityModifyRGB(bool bValue) {CC_UNUSED_PARAM(bValue);} virtual void setOpacityModifyRGB(bool value) {CC_UNUSED_PARAM(value);}
virtual bool isOpacityModifyRGB() const { return false; }; virtual bool isOpacityModifyRGB() const { return false; };
CC_CONSTRUCTOR_ACCESS: CC_CONSTRUCTOR_ACCESS:

View File

@ -26,7 +26,7 @@ THE SOFTWARE.
#define __ANDROID_IME_JNI_H__ #define __ANDROID_IME_JNI_H__
extern "C" { extern "C" {
extern void setKeyboardStateJNI(int bOpen); extern void setKeyboardStateJNI(int open);
extern void openKeyboardJNI(); extern void openKeyboardJNI();
extern void closeKeyboardJNI(); extern void closeKeyboardJNI();
} }

View File

@ -45,17 +45,17 @@ int getFontSizeAccordingHeightJni(int height) {
return ret; return ret;
} }
std::string getStringWithEllipsisJni(const char* pszText, float width, float fontSize) { std::string getStringWithEllipsisJni(const char* text, float width, float fontSize) {
std::string ret; std::string ret;
JniMethodInfo t; JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, "org/cocos2dx/lib/Cocos2dxBitmap", "getStringWithEllipsis", "(Ljava/lang/String;FF)Ljava/lang/String;")) { if (JniHelper::getStaticMethodInfo(t, "org/cocos2dx/lib/Cocos2dxBitmap", "getStringWithEllipsis", "(Ljava/lang/String;FF)Ljava/lang/String;")) {
jstring stringArg1; jstring stringArg1;
if (!pszText) { if (!text) {
stringArg1 = t.env->NewStringUTF(""); stringArg1 = t.env->NewStringUTF("");
} else { } else {
stringArg1 = t.env->NewStringUTF(pszText); stringArg1 = t.env->NewStringUTF(text);
} }
jstring retFromJava = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID, stringArg1, width, fontSize); jstring retFromJava = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID, stringArg1, width, fontSize);

View File

@ -28,6 +28,6 @@ THE SOFTWARE.
#include <string> #include <string>
int getFontSizeAccordingHeightJni(int height); int getFontSizeAccordingHeightJni(int height);
std::string getStringWithEllipsisJni(const char* pszText, float width, float fontSize); std::string getStringWithEllipsisJni(const char* text, float width, float fontSize);
#endif // __EDITBOX_JNI_H__ #endif // __EDITBOX_JNI_H__

View File

@ -37,8 +37,8 @@ THE SOFTWARE.
#define CLASS_NAME "org/cocos2dx/lib/Cocos2dxHelper" #define CLASS_NAME "org/cocos2dx/lib/Cocos2dxHelper"
EditTextCallback s_pfEditTextCallback = NULL; static EditTextCallback s_editTextCallback = nullptr;
void* s_ctx = NULL; static void* s_ctx = nullptr;
using namespace cocos2d; using namespace cocos2d;
using namespace std; using namespace std;
@ -61,17 +61,17 @@ extern "C" {
if (size > 0) { if (size > 0) {
jbyte * data = (jbyte*)env->GetByteArrayElements(text, 0); jbyte * data = (jbyte*)env->GetByteArrayElements(text, 0);
char* pBuf = (char*)malloc(size+1); char* buffer = (char*)malloc(size+1);
if (pBuf != NULL) { if (buffer != nullptr) {
memcpy(pBuf, data, size); memcpy(buffer, data, size);
pBuf[size] = '\0'; buffer[size] = '\0';
// pass data to edittext's delegate // pass data to edittext's delegate
if (s_pfEditTextCallback) s_pfEditTextCallback(pBuf, s_ctx); if (s_editTextCallback) s_editTextCallback(buffer, s_ctx);
free(pBuf); free(buffer);
} }
env->ReleaseByteArrayElements(text, data, 0); env->ReleaseByteArrayElements(text, data, 0);
} else { } else {
if (s_pfEditTextCallback) s_pfEditTextCallback("", s_ctx); if (s_editTextCallback) s_editTextCallback("", s_ctx);
} }
} }
} }
@ -80,8 +80,8 @@ const char * getApkPath() {
return g_apkPath.c_str(); return g_apkPath.c_str();
} }
void showDialogJNI(const char * pszMsg, const char * pszTitle) { void showDialogJNI(const char * message, const char * title) {
if (!pszMsg) { if (!message) {
return; return;
} }
@ -89,13 +89,13 @@ void showDialogJNI(const char * pszMsg, const char * pszTitle) {
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "showDialog", "(Ljava/lang/String;Ljava/lang/String;)V")) { if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "showDialog", "(Ljava/lang/String;Ljava/lang/String;)V")) {
jstring stringArg1; jstring stringArg1;
if (!pszTitle) { if (!title) {
stringArg1 = t.env->NewStringUTF(""); stringArg1 = t.env->NewStringUTF("");
} else { } else {
stringArg1 = t.env->NewStringUTF(pszTitle); stringArg1 = t.env->NewStringUTF(title);
} }
jstring stringArg2 = t.env->NewStringUTF(pszMsg); jstring stringArg2 = t.env->NewStringUTF(message);
t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg1, stringArg2); t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg1, stringArg2);
t.env->DeleteLocalRef(stringArg1); t.env->DeleteLocalRef(stringArg1);
@ -104,27 +104,27 @@ void showDialogJNI(const char * pszMsg, const char * pszTitle) {
} }
} }
void showEditTextDialogJNI(const char* pszTitle, const char* pszMessage, int nInputMode, int nInputFlag, int nReturnType, int nMaxLength, EditTextCallback pfEditTextCallback, void* ctx) { void showEditTextDialogJNI(const char* title, const char* message, int inputMode, int inputFlag, int returnType, int maxLength, EditTextCallback callback, void* ctx) {
if (pszMessage == NULL) { if (message == nullptr) {
return; return;
} }
s_pfEditTextCallback = pfEditTextCallback; s_editTextCallback = callback;
s_ctx = ctx; s_ctx = ctx;
JniMethodInfo t; JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "showEditTextDialog", "(Ljava/lang/String;Ljava/lang/String;IIII)V")) { if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "showEditTextDialog", "(Ljava/lang/String;Ljava/lang/String;IIII)V")) {
jstring stringArg1; jstring stringArg1;
if (!pszTitle) { if (!title) {
stringArg1 = t.env->NewStringUTF(""); stringArg1 = t.env->NewStringUTF("");
} else { } else {
stringArg1 = t.env->NewStringUTF(pszTitle); stringArg1 = t.env->NewStringUTF(title);
} }
jstring stringArg2 = t.env->NewStringUTF(pszMessage); jstring stringArg2 = t.env->NewStringUTF(message);
t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg1, stringArg2, nInputMode, nInputFlag, nReturnType, nMaxLength); t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg1, stringArg2,inputMode, inputFlag, returnType, maxLength);
t.env->DeleteLocalRef(stringArg1); t.env->DeleteLocalRef(stringArg1);
t.env->DeleteLocalRef(stringArg2); t.env->DeleteLocalRef(stringArg2);
@ -210,12 +210,12 @@ void disableAccelerometerJni() {
} }
// functions for UserDefault // functions for UserDefault
bool getBoolForKeyJNI(const char* pKey, bool defaultValue) bool getBoolForKeyJNI(const char* key, bool defaultValue)
{ {
JniMethodInfo t; JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "getBoolForKey", "(Ljava/lang/String;Z)Z")) { if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "getBoolForKey", "(Ljava/lang/String;Z)Z")) {
jstring stringArg = t.env->NewStringUTF(pKey); jstring stringArg = t.env->NewStringUTF(key);
jboolean ret = t.env->CallStaticBooleanMethod(t.classID, t.methodID, stringArg, defaultValue); jboolean ret = t.env->CallStaticBooleanMethod(t.classID, t.methodID, stringArg, defaultValue);
t.env->DeleteLocalRef(t.classID); t.env->DeleteLocalRef(t.classID);
@ -227,12 +227,12 @@ bool getBoolForKeyJNI(const char* pKey, bool defaultValue)
return defaultValue; return defaultValue;
} }
int getIntegerForKeyJNI(const char* pKey, int defaultValue) int getIntegerForKeyJNI(const char* key, int defaultValue)
{ {
JniMethodInfo t; JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "getIntegerForKey", "(Ljava/lang/String;I)I")) { if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "getIntegerForKey", "(Ljava/lang/String;I)I")) {
jstring stringArg = t.env->NewStringUTF(pKey); jstring stringArg = t.env->NewStringUTF(key);
jint ret = t.env->CallStaticIntMethod(t.classID, t.methodID, stringArg, defaultValue); jint ret = t.env->CallStaticIntMethod(t.classID, t.methodID, stringArg, defaultValue);
t.env->DeleteLocalRef(t.classID); t.env->DeleteLocalRef(t.classID);
@ -244,12 +244,12 @@ int getIntegerForKeyJNI(const char* pKey, int defaultValue)
return defaultValue; return defaultValue;
} }
float getFloatForKeyJNI(const char* pKey, float defaultValue) float getFloatForKeyJNI(const char* key, float defaultValue)
{ {
JniMethodInfo t; JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "getFloatForKey", "(Ljava/lang/String;F)F")) { if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "getFloatForKey", "(Ljava/lang/String;F)F")) {
jstring stringArg = t.env->NewStringUTF(pKey); jstring stringArg = t.env->NewStringUTF(key);
jfloat ret = t.env->CallStaticFloatMethod(t.classID, t.methodID, stringArg, defaultValue); jfloat ret = t.env->CallStaticFloatMethod(t.classID, t.methodID, stringArg, defaultValue);
t.env->DeleteLocalRef(t.classID); t.env->DeleteLocalRef(t.classID);
@ -261,12 +261,12 @@ float getFloatForKeyJNI(const char* pKey, float defaultValue)
return defaultValue; return defaultValue;
} }
double getDoubleForKeyJNI(const char* pKey, double defaultValue) double getDoubleForKeyJNI(const char* key, double defaultValue)
{ {
JniMethodInfo t; JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "getDoubleForKey", "(Ljava/lang/String;D)D")) { if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "getDoubleForKey", "(Ljava/lang/String;D)D")) {
jstring stringArg = t.env->NewStringUTF(pKey); jstring stringArg = t.env->NewStringUTF(key);
jdouble ret = t.env->CallStaticDoubleMethod(t.classID, t.methodID, stringArg, defaultValue); jdouble ret = t.env->CallStaticDoubleMethod(t.classID, t.methodID, stringArg, defaultValue);
t.env->DeleteLocalRef(t.classID); t.env->DeleteLocalRef(t.classID);
@ -278,13 +278,13 @@ double getDoubleForKeyJNI(const char* pKey, double defaultValue)
return defaultValue; return defaultValue;
} }
std::string getStringForKeyJNI(const char* pKey, const char* defaultValue) std::string getStringForKeyJNI(const char* key, const char* defaultValue)
{ {
JniMethodInfo t; JniMethodInfo t;
std::string ret(""); std::string ret("");
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "getStringForKey", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;")) { if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "getStringForKey", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;")) {
jstring stringArg1 = t.env->NewStringUTF(pKey); jstring stringArg1 = t.env->NewStringUTF(key);
jstring stringArg2 = t.env->NewStringUTF(defaultValue); jstring stringArg2 = t.env->NewStringUTF(defaultValue);
jstring str = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID, stringArg1, stringArg2); jstring str = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID, stringArg1, stringArg2);
ret = JniHelper::jstring2string(str); ret = JniHelper::jstring2string(str);
@ -300,12 +300,12 @@ std::string getStringForKeyJNI(const char* pKey, const char* defaultValue)
return defaultValue; return defaultValue;
} }
void setBoolForKeyJNI(const char* pKey, bool value) void setBoolForKeyJNI(const char* key, bool value)
{ {
JniMethodInfo t; JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setBoolForKey", "(Ljava/lang/String;Z)V")) { if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setBoolForKey", "(Ljava/lang/String;Z)V")) {
jstring stringArg = t.env->NewStringUTF(pKey); jstring stringArg = t.env->NewStringUTF(key);
t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg, value); t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg, value);
t.env->DeleteLocalRef(t.classID); t.env->DeleteLocalRef(t.classID);
@ -313,12 +313,12 @@ void setBoolForKeyJNI(const char* pKey, bool value)
} }
} }
void setIntegerForKeyJNI(const char* pKey, int value) void setIntegerForKeyJNI(const char* key, int value)
{ {
JniMethodInfo t; JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setIntegerForKey", "(Ljava/lang/String;I)V")) { if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setIntegerForKey", "(Ljava/lang/String;I)V")) {
jstring stringArg = t.env->NewStringUTF(pKey); jstring stringArg = t.env->NewStringUTF(key);
t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg, value); t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg, value);
t.env->DeleteLocalRef(t.classID); t.env->DeleteLocalRef(t.classID);
@ -326,12 +326,12 @@ void setIntegerForKeyJNI(const char* pKey, int value)
} }
} }
void setFloatForKeyJNI(const char* pKey, float value) void setFloatForKeyJNI(const char* key, float value)
{ {
JniMethodInfo t; JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setFloatForKey", "(Ljava/lang/String;F)V")) { if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setFloatForKey", "(Ljava/lang/String;F)V")) {
jstring stringArg = t.env->NewStringUTF(pKey); jstring stringArg = t.env->NewStringUTF(key);
t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg, value); t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg, value);
t.env->DeleteLocalRef(t.classID); t.env->DeleteLocalRef(t.classID);
@ -339,12 +339,12 @@ void setFloatForKeyJNI(const char* pKey, float value)
} }
} }
void setDoubleForKeyJNI(const char* pKey, double value) void setDoubleForKeyJNI(const char* key, double value)
{ {
JniMethodInfo t; JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setDoubleForKey", "(Ljava/lang/String;D)V")) { if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setDoubleForKey", "(Ljava/lang/String;D)V")) {
jstring stringArg = t.env->NewStringUTF(pKey); jstring stringArg = t.env->NewStringUTF(key);
t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg, value); t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg, value);
t.env->DeleteLocalRef(t.classID); t.env->DeleteLocalRef(t.classID);
@ -352,12 +352,12 @@ void setDoubleForKeyJNI(const char* pKey, double value)
} }
} }
void setStringForKeyJNI(const char* pKey, const char* value) void setStringForKeyJNI(const char* key, const char* value)
{ {
JniMethodInfo t; JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setStringForKey", "(Ljava/lang/String;Ljava/lang/String;)V")) { if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setStringForKey", "(Ljava/lang/String;Ljava/lang/String;)V")) {
jstring stringArg1 = t.env->NewStringUTF(pKey); jstring stringArg1 = t.env->NewStringUTF(key);
jstring stringArg2 = t.env->NewStringUTF(value); jstring stringArg2 = t.env->NewStringUTF(value);
t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg1, stringArg2); t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg1, stringArg2);

View File

@ -27,11 +27,11 @@ THE SOFTWARE.
#include <string> #include <string>
typedef void (*EditTextCallback)(const char* pText, void* ctx); typedef void (*EditTextCallback)(const char* text, void* ctx);
extern const char * getApkPath(); extern const char * getApkPath();
extern void showDialogJNI(const char * pszMsg, const char * pszTitle); extern void showDialogJNI(const char * message, const char * title);
extern void showEditTextDialogJNI(const char* pszTitle, const char* pszContent, int nInputMode, int nInputFlag, int nReturnType, int nMaxLength, EditTextCallback pfEditTextCallback, void* ctx); extern void showEditTextDialogJNI(const char* title, const char* content, int inputMode, int inputFlag, int returnType, int maxLength, EditTextCallback callback, void* ctx);
extern void terminateProcessJNI(); extern void terminateProcessJNI();
extern std::string getCurrentLanguageJNI(); extern std::string getCurrentLanguageJNI();
extern std::string getPackageNameJNI(); extern std::string getPackageNameJNI();
@ -40,15 +40,15 @@ extern void enableAccelerometerJni();
extern void disableAccelerometerJni(); extern void disableAccelerometerJni();
extern void setAccelerometerIntervalJni(float interval); extern void setAccelerometerIntervalJni(float interval);
// functions for UserDefault // functions for UserDefault
extern bool getBoolForKeyJNI(const char* pKey, bool defaultValue); extern bool getBoolForKeyJNI(const char* key, bool defaultValue);
extern int getIntegerForKeyJNI(const char* pKey, int defaultValue); extern int getIntegerForKeyJNI(const char* key, int defaultValue);
extern float getFloatForKeyJNI(const char* pKey, float defaultValue); extern float getFloatForKeyJNI(const char* key, float defaultValue);
extern double getDoubleForKeyJNI(const char* pKey, double defaultValue); extern double getDoubleForKeyJNI(const char* key, double defaultValue);
extern std::string getStringForKeyJNI(const char* pKey, const char* defaultValue); extern std::string getStringForKeyJNI(const char* key, const char* defaultValue);
extern void setBoolForKeyJNI(const char* pKey, bool value); extern void setBoolForKeyJNI(const char* key, bool value);
extern void setIntegerForKeyJNI(const char* pKey, int value); extern void setIntegerForKeyJNI(const char* key, int value);
extern void setFloatForKeyJNI(const char* pKey, float value); extern void setFloatForKeyJNI(const char* key, float value);
extern void setDoubleForKeyJNI(const char* pKey, double value); extern void setDoubleForKeyJNI(const char* key, double value);
extern void setStringForKeyJNI(const char* pKey, const char* value); extern void setStringForKeyJNI(const char* key, const char* value);
#endif /* __Java_org_cocos2dx_lib_Cocos2dxHelper_H__ */ #endif /* __Java_org_cocos2dx_lib_Cocos2dxHelper_H__ */

View File

@ -34,8 +34,8 @@ THE SOFTWARE.
static pthread_key_t g_key; static pthread_key_t g_key;
jclass _getClassID(const char *className) { jclass _getClassID(const char *className) {
if (NULL == className) { if (nullptr == className) {
return NULL; return nullptr;
} }
JNIEnv* env = cocos2d::JniHelper::getEnv(); JNIEnv* env = cocos2d::JniHelper::getEnv();
@ -46,7 +46,7 @@ jclass _getClassID(const char *className) {
cocos2d::JniHelper::loadclassMethod_methodID, cocos2d::JniHelper::loadclassMethod_methodID,
_jstrClassName); _jstrClassName);
if (NULL == _clazz) { if (nullptr == _clazz) {
LOGE("Classloader failed to find class of %s", className); LOGE("Classloader failed to find class of %s", className);
env->ExceptionClear(); env->ExceptionClear();
} }
@ -58,9 +58,9 @@ jclass _getClassID(const char *className) {
namespace cocos2d { namespace cocos2d {
JavaVM* JniHelper::_psJavaVM = NULL; JavaVM* JniHelper::_psJavaVM = nullptr;
jmethodID JniHelper::loadclassMethod_methodID = NULL; jmethodID JniHelper::loadclassMethod_methodID = nullptr;
jobject JniHelper::classloader = NULL; jobject JniHelper::classloader = nullptr;
JavaVM* JniHelper::getJavaVM() { JavaVM* JniHelper::getJavaVM() {
pthread_t thisthread = pthread_self(); pthread_t thisthread = pthread_self();
@ -73,11 +73,11 @@ namespace cocos2d {
LOGD("JniHelper::setJavaVM(%p), pthread_self() = %ld", javaVM, thisthread); LOGD("JniHelper::setJavaVM(%p), pthread_self() = %ld", javaVM, thisthread);
_psJavaVM = javaVM; _psJavaVM = javaVM;
pthread_key_create(&g_key, NULL); pthread_key_create(&g_key, nullptr);
} }
JNIEnv* JniHelper::cacheEnv(JavaVM* jvm) { JNIEnv* JniHelper::cacheEnv(JavaVM* jvm) {
JNIEnv* _env = NULL; JNIEnv* _env = nullptr;
// get jni environment // get jni environment
jint ret = jvm->GetEnv((void**)&_env, JNI_VERSION_1_4); jint ret = jvm->GetEnv((void**)&_env, JNI_VERSION_1_4);
@ -94,11 +94,11 @@ namespace cocos2d {
// must call DetachCurrentThread() in future. // must call DetachCurrentThread() in future.
// see: http://developer.android.com/guide/practices/design/jni.html // see: http://developer.android.com/guide/practices/design/jni.html
if (jvm->AttachCurrentThread(&_env, NULL) < 0) if (jvm->AttachCurrentThread(&_env, nullptr) < 0)
{ {
LOGE("Failed to get the environment using AttachCurrentThread()"); LOGE("Failed to get the environment using AttachCurrentThread()");
return NULL; return nullptr;
} else { } else {
// Success : Attached and obtained JNIEnv! // Success : Attached and obtained JNIEnv!
pthread_setspecific(g_key, _env); pthread_setspecific(g_key, _env);
@ -110,13 +110,13 @@ namespace cocos2d {
LOGE("JNI interface version 1.4 not supported"); LOGE("JNI interface version 1.4 not supported");
default : default :
LOGE("Failed to get the environment using GetEnv()"); LOGE("Failed to get the environment using GetEnv()");
return NULL; return nullptr;
} }
} }
JNIEnv* JniHelper::getEnv() { JNIEnv* JniHelper::getEnv() {
JNIEnv *_env = (JNIEnv *)pthread_getspecific(g_key); JNIEnv *_env = (JNIEnv *)pthread_getspecific(g_key);
if (_env == NULL) if (_env == nullptr)
_env = JniHelper::cacheEnv(_psJavaVM); _env = JniHelper::cacheEnv(_psJavaVM);
return _env; return _env;
} }
@ -133,7 +133,7 @@ namespace cocos2d {
jobject _c = cocos2d::JniHelper::getEnv()->CallObjectMethod(activityinstance, jobject _c = cocos2d::JniHelper::getEnv()->CallObjectMethod(activityinstance,
_getclassloaderMethod.methodID); _getclassloaderMethod.methodID);
if (NULL == _c) { if (nullptr == _c) {
return false; return false;
} }
@ -155,14 +155,14 @@ namespace cocos2d {
const char *className, const char *className,
const char *methodName, const char *methodName,
const char *paramCode) { const char *paramCode) {
if ((NULL == className) || if ((nullptr == className) ||
(NULL == methodName) || (nullptr == methodName) ||
(NULL == paramCode)) { (nullptr == paramCode)) {
return false; return false;
} }
JNIEnv *pEnv = JniHelper::getEnv(); JNIEnv *env = JniHelper::getEnv();
if (!pEnv) { if (!env) {
LOGE("Failed to get JNIEnv"); LOGE("Failed to get JNIEnv");
return false; return false;
} }
@ -170,19 +170,19 @@ namespace cocos2d {
jclass classID = _getClassID(className); jclass classID = _getClassID(className);
if (! classID) { if (! classID) {
LOGE("Failed to find class %s", className); LOGE("Failed to find class %s", className);
pEnv->ExceptionClear(); env->ExceptionClear();
return false; return false;
} }
jmethodID methodID = pEnv->GetStaticMethodID(classID, methodName, paramCode); jmethodID methodID = env->GetStaticMethodID(classID, methodName, paramCode);
if (! methodID) { if (! methodID) {
LOGE("Failed to find static method id of %s", methodName); LOGE("Failed to find static method id of %s", methodName);
pEnv->ExceptionClear(); env->ExceptionClear();
return false; return false;
} }
methodinfo.classID = classID; methodinfo.classID = classID;
methodinfo.env = pEnv; methodinfo.env = env;
methodinfo.methodID = methodID; methodinfo.methodID = methodID;
return true; return true;
} }
@ -191,33 +191,33 @@ namespace cocos2d {
const char *className, const char *className,
const char *methodName, const char *methodName,
const char *paramCode) { const char *paramCode) {
if ((NULL == className) || if ((nullptr == className) ||
(NULL == methodName) || (nullptr == methodName) ||
(NULL == paramCode)) { (nullptr == paramCode)) {
return false; return false;
} }
JNIEnv *pEnv = JniHelper::getEnv(); JNIEnv *env = JniHelper::getEnv();
if (!pEnv) { if (!env) {
return false; return false;
} }
jclass classID = pEnv->FindClass(className); jclass classID = env->FindClass(className);
if (! classID) { if (! classID) {
LOGE("Failed to find class %s", className); LOGE("Failed to find class %s", className);
pEnv->ExceptionClear(); env->ExceptionClear();
return false; return false;
} }
jmethodID methodID = pEnv->GetMethodID(classID, methodName, paramCode); jmethodID methodID = env->GetMethodID(classID, methodName, paramCode);
if (! methodID) { if (! methodID) {
LOGE("Failed to find method id of %s", methodName); LOGE("Failed to find method id of %s", methodName);
pEnv->ExceptionClear(); env->ExceptionClear();
return false; return false;
} }
methodinfo.classID = classID; methodinfo.classID = classID;
methodinfo.env = pEnv; methodinfo.env = env;
methodinfo.methodID = methodID; methodinfo.methodID = methodID;
return true; return true;
@ -227,51 +227,51 @@ namespace cocos2d {
const char *className, const char *className,
const char *methodName, const char *methodName,
const char *paramCode) { const char *paramCode) {
if ((NULL == className) || if ((nullptr == className) ||
(NULL == methodName) || (nullptr == methodName) ||
(NULL == paramCode)) { (nullptr == paramCode)) {
return false; return false;
} }
JNIEnv *pEnv = JniHelper::getEnv(); JNIEnv *env = JniHelper::getEnv();
if (!pEnv) { if (!env) {
return false; return false;
} }
jclass classID = _getClassID(className); jclass classID = _getClassID(className);
if (! classID) { if (! classID) {
LOGE("Failed to find class %s", className); LOGE("Failed to find class %s", className);
pEnv->ExceptionClear(); env->ExceptionClear();
return false; return false;
} }
jmethodID methodID = pEnv->GetMethodID(classID, methodName, paramCode); jmethodID methodID = env->GetMethodID(classID, methodName, paramCode);
if (! methodID) { if (! methodID) {
LOGE("Failed to find method id of %s", methodName); LOGE("Failed to find method id of %s", methodName);
pEnv->ExceptionClear(); env->ExceptionClear();
return false; return false;
} }
methodinfo.classID = classID; methodinfo.classID = classID;
methodinfo.env = pEnv; methodinfo.env = env;
methodinfo.methodID = methodID; methodinfo.methodID = methodID;
return true; return true;
} }
std::string JniHelper::jstring2string(jstring jstr) { std::string JniHelper::jstring2string(jstring jstr) {
if (jstr == NULL) { if (jstr == nullptr) {
return ""; return "";
} }
JNIEnv *pEnv = JniHelper::getEnv(); JNIEnv *env = JniHelper::getEnv();
if (!pEnv) { if (!env) {
return NULL; return nullptr;
} }
const char* chars = pEnv->GetStringUTFChars(jstr, NULL); const char* chars = env->GetStringUTFChars(jstr, nullptr);
std::string ret(chars); std::string ret(chars);
pEnv->ReleaseStringUTFChars(jstr, chars); env->ReleaseStringUTFChars(jstr, chars);
return ret; return ret;
} }