#ifndef __CCMACROS_H__
#define __CCMACROS_H__
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
#include "platform/CCCommon.h"
#include "CCStdC.h"
#ifndef CCAssert
#if COCOS2D_DEBUG > 0
extern bool CC_DLL cc_assert_script_compatible(const char *msg);
#define CCAssert(cond, msg) do {
if (!(cond)) {
if (!cc_assert_script_compatible(msg) && strlen(msg))
cocos2d::CCLog("Assert failed: %s", msg);
CC_ASSERT(cond);
}
} while (0)
#else
#define CCAssert(cond, msg)
#endif
#endif // CCAssert
#include "ccConfig.h"
/** @def CC_SWAP
simple macro that swaps 2 variables
*/
#define CC_SWAP(x, y, type)
{ type temp = (x);
x = y; y = temp;
}
/** @def CCRANDOM_MINUS1_1
returns a random float between -1 and 1
*/
#define CCRANDOM_MINUS1_1() ((2.0f*((float)rand()/RAND_MAX))-1.0f)
/** @def CCRANDOM_0_1
returns a random float between 0 and 1
*/
#define CCRANDOM_0_1() ((float)rand()/RAND_MAX)
/** @def CC_DEGREES_TO_RADIANS
converts degrees to radians
*/
#define CC_DEGREES_TO_RADIANS(__ANGLE__) ((__ANGLE__) * 0.01745329252f) // PI / 180
/** @def CC_RADIANS_TO_DEGREES
converts radians to degrees
*/
#define CC_RADIANS_TO_DEGREES(__ANGLE__) ((__ANGLE__) * 57.29577951f) // PI * 180
#define kCCRepeatForever (UINT_MAX -1)
/** @def CC_BLEND_SRC
default gl blend src function. Compatible with premultiplied alpha images.
*/
#define CC_BLEND_SRC GL_ONE
#define CC_BLEND_DST GL_ONE_MINUS_SRC_ALPHA
/** @def CC_NODE_DRAW_SETUP
Helpful macro that setups the GL server state, the correct GL program and sets the Model View Projection matrix
@since v2.0
*/
#define CC_NODE_DRAW_SETUP()
do {
ccGLEnable(m_eGLServerState);
CCAssert(getShaderProgram(), "No shader program set for this node");
{
getShaderProgram()->use();
getShaderProgram()->setUniformsForBuiltins();
}
} while(0)
/** @def CC_DIRECTOR_END
Stops and removes the director from memory.
Removes the CCGLView from its parent
@since v0.99.4
*/
#define CC_DIRECTOR_END()
do {
CCDirector *__director = CCDirector::sharedDirector();
__director->end();
} while(0)
/** @def CC_CONTENT_SCALE_FACTOR
On Mac it returns 1;
On iPhone it returns 2 if RetinaDisplay is On. Otherwise it returns 1
*/
#define CC_CONTENT_SCALE_FACTOR() CCDirector::sharedDirector()->getContentScaleFactor()
/****************************/
/** RETINA DISPLAY ENABLED **/
/****************************/
/** @def CC_RECT_PIXELS_TO_POINTS
Converts a rect in pixels to points
*/
#define CC_RECT_PIXELS_TO_POINTS(__rect_in_pixels__)
CCRectMake( (__rect_in_pixels__).origin.x / CC_CONTENT_SCALE_FACTOR(), (__rect_in_pixels__).origin.y / CC_CONTENT_SCALE_FACTOR(),
(__rect_in_pixels__).size.width / CC_CONTENT_SCALE_FACTOR(), (__rect_in_pixels__).size.height / CC_CONTENT_SCALE_FACTOR() )
/** @def CC_RECT_POINTS_TO_PIXELS
Converts a rect in points to pixels
*/
#define CC_RECT_POINTS_TO_PIXELS(__rect_in_points_points__)
CCRectMake( (__rect_in_points_points__).origin.x * CC_CONTENT_SCALE_FACTOR(), (__rect_in_points_points__).origin.y * CC_CONTENT_SCALE_FACTOR(),
(__rect_in_points_points__).size.width * CC_CONTENT_SCALE_FACTOR(), (__rect_in_points_points__).size.height * CC_CONTENT_SCALE_FACTOR() )
/** @def CC_POINT_PIXELS_TO_POINTS
Converts a rect in pixels to points
*/
#define CC_POINT_PIXELS_TO_POINTS(__pixels__)
CCPointMake( (__pixels__).x / CC_CONTENT_SCALE_FACTOR(), (__pixels__).y / CC_CONTENT_SCALE_FACTOR())
/** @def CC_POINT_POINTS_TO_PIXELS
Converts a rect in points to pixels
*/
#define CC_POINT_POINTS_TO_PIXELS(__points__)
CCPointMake( (__points__).x * CC_CONTENT_SCALE_FACTOR(), (__points__).y * CC_CONTENT_SCALE_FACTOR())
/** @def CC_POINT_PIXELS_TO_POINTS
Converts a rect in pixels to points
*/
#define CC_SIZE_PIXELS_TO_POINTS(__size_in_pixels__)
CCSizeMake( (__size_in_pixels__).width / CC_CONTENT_SCALE_FACTOR(), (__size_in_pixels__).height / CC_CONTENT_SCALE_FACTOR())
/** @def CC_POINT_POINTS_TO_PIXELS
Converts a rect in points to pixels
*/
#define CC_SIZE_POINTS_TO_PIXELS(__size_in_points__)
CCSizeMake( (__size_in_points__).width * CC_CONTENT_SCALE_FACTOR(), (__size_in_points__).height * CC_CONTENT_SCALE_FACTOR())
#ifndef FLT_EPSILON
#define FLT_EPSILON 1.192092896e-07F
#endif // FLT_EPSILON
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName(const TypeName&);
void operator=(const TypeName&)
/**
Helper macros which converts 4-byte little/big endian
integral number to the machine native number representation
It should work same as apples CFSwapInt32LittleToHost(..)
*/
/// when define returns true it means that our architecture uses big endian
#define CC_HOST_IS_BIG_ENDIAN (bool)(*(unsigned short *)"