cocos2d-x节点(ccMacros.h)API

来源:互联网 发布:android编程入门自学 编辑:程序博客网 时间:2024/05/22 05:01

本文来自http://blog.csdn.net/runaying ,引用必须注明出处!

cocos2d-x节点(ccMacros.h)API

温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记

一些预处理宏

///cocos2d-x-3.0alpha0/cocos2dx/include//一些预处理宏#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 > 0extern 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::log("Assert failed: %s", msg);             \        CC_ASSERT(cond);                                      \      } \    } while (0)#else#define CCASSERT(cond, msg)#endif// XXX: Backward compatible //向后兼容#define CCAssert CCASSERT#endif  // CCASSERT         //声明#include "ccConfig.h"/** @def CC_SWAP简单的 macro(宏),互换 2 个变量*/#define CC_SWAP(x, y, type)    \{    type temp = (x);        \    x = y; y = temp;        \}/** @def CCRANDOM_MINUS1_1 returns 1和1之间的随机float */#define CCRANDOM_MINUS1_1() ((2.0f*((float)rand()/RAND_MAX))-1.0f)/** @def CCRANDOM_0_1 returns 0和1之间的随机float */#define CCRANDOM_0_1() ((float)rand()/RAND_MAX)/** @def CC_DEGREES_TO_RADIANS 把 度 转换为 弧度 */#define CC_DEGREES_TO_RADIANS(__ANGLE__) ((__ANGLE__) * 0.01745329252f) // PI / 180/** @def CC_RADIANS_TO_DEGREES 把 弧度转化为度 */#define CC_RADIANS_TO_DEGREES(__ANGLE__) ((__ANGLE__) * 57.29577951f) // PI * 180#define kRepeatForever (UINT_MAX -1)/** @def CC_BLEND_SRC默认 gl 混合 src 功能. 和 premultiplied(预乘) alpha 图片兼容.*/#define CC_BLEND_SRC GL_ONE#define CC_BLEND_DST GL_ONE_MINUS_SRC_ALPHA/** @def CC_NODE_DRAW_SETUP 帮助宏,设置 GL 服务状态,GL程序正确的设置 Model View Projection(投影) matrix(矩阵) @since v2.0 */#define CC_NODE_DRAW_SETUP() \do { \    CCASSERT(getShaderProgram(), "No shader program set for this node"); \    { \        getShaderProgram()->use(); \        getShaderProgram()->setUniformsForBuiltins(); \    } \} while(0) /** @def CC_DIRECTOR_END  停止并从内存中删除 director . 从 parent上面移除 GLView  @since v0.99.4  */#define CC_DIRECTOR_END()                                       \do {                                                            \    Director *__director = Director::getInstance();             \    __director->end();                                          \} while(0)/** @def CC_CONTENT_SCALE_FACTOROn Mac it returns 1;On iPhone it returns 2 if RetinaDisplay(Retina显示屏) is On. Otherwise it returns 1*/#define CC_CONTENT_SCALE_FACTOR() Director::getInstance()->getContentScaleFactor()/****************************//** RETINA DISPLAY ENABLED **/  //启用视网膜显示/****************************//** @def CC_RECT_PIXELS_TO_POINTS把以像素为单位的矩形转换为以点为单位的矩形 */#define CC_RECT_PIXELS_TO_POINTS(__rect_in_pixels__)                                                                        \    Rect( (__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 把以点为单位的矩形转换为以像素为单位的矩形 */#define CC_RECT_POINTS_TO_PIXELS(__rect_in_points_points__)                                                                        \    Rect( (__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把以像素为单位的矩形转换为以点为单位的矩形 */#define CC_POINT_PIXELS_TO_POINTS(__pixels__)                                                                        \Point( (__pixels__).x / CC_CONTENT_SCALE_FACTOR(), (__pixels__).y / CC_CONTENT_SCALE_FACTOR())/** @def CC_POINT_POINTS_TO_PIXELS 把以点为单位的矩形转换为以像素为单位的矩形 */#define CC_POINT_POINTS_TO_PIXELS(__points__)                                                                        \Point( (__points__).x * CC_CONTENT_SCALE_FACTOR(), (__points__).y * CC_CONTENT_SCALE_FACTOR())/** @def CC_POINT_PIXELS_TO_POINTS把以像素为单位的矩形转换为以点为单位的矩形 */#define CC_SIZE_PIXELS_TO_POINTS(__size_in_pixels__)                                                                        \Size( (__size_in_pixels__).width / CC_CONTENT_SCALE_FACTOR(), (__size_in_pixels__).height / CC_CONTENT_SCALE_FACTOR())/** @def CC_POINT_POINTS_TO_PIXELS 把以点为单位的矩形转换为以像素为单位的矩形 */#define CC_SIZE_POINTS_TO_PIXELS(__size_in_points__)                                                                        \Size( (__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&)/**辅助宏,把 4-byte little/big 整形尾数转化为机器码表示(二进制数据) 它应该和 apple的 CFSwapInt32LittleToHost(..) 工作的一样*//// 当定义 returns true 它意味着我们的构架使用 big endian(尾数)#define CC_HOST_IS_BIG_ENDIAN (bool)(*(unsigned short *)"\0\xff" < 0x100) #define CC_SWAP32(i)  ((i & 0x000000ff) << 24 | (i & 0x0000ff00) << 8 | (i & 0x00ff0000) >> 8 | (i & 0xff000000) >> 24)#define CC_SWAP16(i)  ((i & 0x00ff) << 8 | (i &0xff00) >> 8)   #define CC_SWAP_INT32_LITTLE_TO_HOST(i) ((CC_HOST_IS_BIG_ENDIAN == true)? CC_SWAP32(i) : (i) )#define CC_SWAP_INT16_LITTLE_TO_HOST(i) ((CC_HOST_IS_BIG_ENDIAN == true)? CC_SWAP16(i) : (i) )#define CC_SWAP_INT32_BIG_TO_HOST(i)    ((CC_HOST_IS_BIG_ENDIAN == true)? (i) : CC_SWAP32(i) )#define CC_SWAP_INT16_BIG_TO_HOST(i)    ((CC_HOST_IS_BIG_ENDIAN == true)? (i):  CC_SWAP16(i) )/**********************//** Profiling Macros **/        //  剖析宏/**********************/#if CC_ENABLE_PROFILERS#define CC_PROFILER_DISPLAY_TIMERS() Profiler::getInstance()->displayTimers()#define CC_PROFILER_PURGE_ALL() Profiler::getInstance()->releaseAllTimers()#define CC_PROFILER_START(__name__) ProfilingBeginTimingBlock(__name__)#define CC_PROFILER_STOP(__name__) ProfilingEndTimingBlock(__name__)#define CC_PROFILER_RESET(__name__) ProfilingResetTimingBlock(__name__)#define CC_PROFILER_START_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingBeginTimingBlock(__name__); } while(0)#define CC_PROFILER_STOP_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingEndTimingBlock(__name__); } while(0)#define CC_PROFILER_RESET_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingResetTimingBlock(__name__); } while(0)#define CC_PROFILER_START_INSTANCE(__id__, __name__) do{ ProfilingBeginTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0)#define CC_PROFILER_STOP_INSTANCE(__id__, __name__) do{ ProfilingEndTimingBlock(    String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0)#define CC_PROFILER_RESET_INSTANCE(__id__, __name__) do{ ProfilingResetTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0)#else#define CC_PROFILER_DISPLAY_TIMERS() do {} while (0)#define CC_PROFILER_PURGE_ALL() do {} while (0)#define CC_PROFILER_START(__name__)  do {} while (0)#define CC_PROFILER_STOP(__name__) do {} while (0)#define CC_PROFILER_RESET(__name__) do {} while (0)#define CC_PROFILER_START_CATEGORY(__cat__, __name__) do {} while(0)#define CC_PROFILER_STOP_CATEGORY(__cat__, __name__) do {} while(0)#define CC_PROFILER_RESET_CATEGORY(__cat__, __name__) do {} while(0)#define CC_PROFILER_START_INSTANCE(__id__, __name__) do {} while(0)#define CC_PROFILER_STOP_INSTANCE(__id__, __name__) do {} while(0)#define CC_PROFILER_RESET_INSTANCE(__id__, __name__) do {} while(0)#endif#if !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0#define CHECK_GL_ERROR_DEBUG()#else#define CHECK_GL_ERROR_DEBUG() \    do { \        GLenum __error = glGetError(); \        if(__error) { \            cocos2d::log("OpenGL error 0x%04X in %s %s %d\n", __error, __FILE__, __FUNCTION__, __LINE__); \        } \    } while (false)#endif/** @def CC_INCREMENT_GL_DRAWS_BY_ONE Increments(增加) the GL Draws counts by one. 当 Director‘s 的 stats 启用时,每帧调用的次数就会在屏幕上显示 */extern unsigned int CC_DLL g_uNumberOfDraws;#define CC_INCREMENT_GL_DRAWS(__n__) g_uNumberOfDraws += __n__/*******************//** Notifications **/       //通知/*******************//** @def AnimationFrameDisplayedNotificationSpriteFrame 正在显示的的通知名 */#define AnimationFrameDisplayedNotification "CCAnimationFrameDisplayedNotification"#endif // __CCMACROS_H__


原创粉丝点击