#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 *)"\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() CCProfiler::sharedProfiler()->displayTimers()

#define CC_PROFILER_PURGE_ALL() CCProfiler::sharedProfiler()->releaseAllTimers()

#define CC_PROFILER_START(__name__) CCProfilingBeginTimingBlock(__name__)

#define CC_PROFILER_STOP(__name__) CCProfilingEndTimingBlock(__name__)

#define CC_PROFILER_RESET(__name__) CCProfilingResetTimingBlock(__name__)

#define CC_PROFILER_START_CATEGORY(__cat__, __name__) do{ if(__cat__) CCProfilingBeginTimingBlock(__name__); } while(0)

#define CC_PROFILER_STOP_CATEGORY(__cat__, __name__) do{ if(__cat__) CCProfilingEndTimingBlock(__name__); } while(0)

#define CC_PROFILER_RESET_CATEGORY(__cat__, __name__) do{ if(__cat__) CCProfilingResetTimingBlock(__name__); } while(0)

#define CC_PROFILER_START_INSTANCE(__id__, __name__) do{ CCProfilingBeginTimingBlock( CCString::createWithFormat("%08X - %s", __id__, __name__)->getCString()
); } while(0)

#define CC_PROFILER_STOP_INSTANCE(__id__, __name__) do{ CCProfilingEndTimingBlock(    CCString::createWithFormat("%08X - %s", __id__, __name__)->getCString()
); } while(0)

#define CC_PROFILER_RESET_INSTANCE(__id__, __name__) do{ CCProfilingResetTimingBlock( CCString::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) { \

CCLog("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.

The number of calls per frame are displayed on the screen when the CCDirector's stats are enabled.

*/

extern unsigned int CC_DLL g_uNumberOfDraws;

#define CC_INCREMENT_GL_DRAWS(__n__) g_uNumberOfDraws += __n__

/*******************/

/** Notifications **/

/*******************/

/** @def CCAnimationFrameDisplayedNotification

Notification name when a CCSpriteFrame is displayed

*/

#define CCAnimationFrameDisplayedNotification "CCAnimationFrameDisplayedNotification"

#endif // __CCMACROS_H__


ccMacros的更多相关文章

  1. Cocos2d-X3.0 刨根问底(五)----- Node类及显示对象列表源码分析

    上一章 我们分析了Cocos2d-x的内存管理,主要解剖了 Ref.PoolManager.AutoreleasePool这三个类,了解了对象是如何自动释放的机制.之前有一个类 Node经常出现在各种 ...

  2. cocos2d-x 2.0 序列帧动画 深入分析

    转自:http://blog.csdn.net/honghaier/article/details/8222401 序列帧动画主要有几个类: CCSpriteFrame:精灵帧信息,序列帧动画是依靠多 ...

  3. cocos2d-x 纹理源码分析

    转自:http://blog.csdn.net/honghaier/article/details/8068895 当一张图片被加载到内存后,它是以纹理的形式存在的.纹理是什么东西呢?纹理就是一块内存 ...

  4. cocos2d-x 的CCObject与autorelease 之深入分析

    转自: http://blog.csdn.net/honghaier/article/details/8160519 CCObject.h: #ifndef __CCOBJECT_H__ #defin ...

  5. cocos2d-x 2.0 拖尾效果分析

    转自:http://game.dapps.net/gamedev/game-engine/7281.html 在Cocos2d-x中,拖尾效果有一个专门的类CCMotionStreak来实现.下面我们 ...

  6. cocos2d-x学习笔记

    转自:http://blog.csdn.net/we000636/article/details/8263503 接受触屏事件的优先级是值越小,响应触屏事件的优先级越高 Z值越大,越外面 JNI:允许 ...

  7. [置顶] COcos2d-X 中文API

    本文来自http://blog.csdn.net/runaying ,引用必须注明出处! COcos2d-X 中文API 温馨提醒:使用二维码扫描软件,就可以在手机上访问我的博客啦!另外大家可以访问另 ...

  8. cocos2d-x-3.1 经常使用宏 (coco2d-x 学习笔记五)

    在代码中使用这些宏,能够降低敲键盘的次数,从而提高编写效率. 与节点属性(property)相关的 CC_PROPERTY_READONLY CC_PROPERTY_READONLY_PASS_BY_ ...

  9. cocos 自动内存管理分析

    #include "CCAutoreleasePool.h" #include "ccMacros.h" NS_CC_BEGIN static CCPoolMa ...

随机推荐

  1. The type javax.servlet.http.HttpServletRequest cannot be resolved.

    The type javax.servlet.http.HttpServletRequest cannot be resolved. It is indirectly referenced from ...

  2. Struts学习之自定义拦截器

    * 所有的拦截器都需要实现Interceptor接口或者继承Interceptor接口的扩展实现类    * 要重写init().intercept().destroy()方法        * in ...

  3. delphi R3下 跨进程获取DLL信息 NtQueryInformationProcess

    unit APIUnit; { GetProcessModuleHandle API Unit Ring3调用NtQueryInformationProcess实现跨进程获取DLL句柄 } inter ...

  4. 关于微信浏览不能URL传参,URL中的问号被删除

    关于微信浏览不能URL传参,URL中的问号被删除. 尼玛难道没有人遇到过这个问题?看了微信支付SDK3.0的代码,看到urlencode 看到了几次.实际上 在微信浏览器下 header('locat ...

  5. poj 1966 Cable TV Network 顶点连通度

    题目链接 给一个图, n个点m条边, 求至少去掉多少个点可以使得图不再联通.随便指定一个点为源点, 枚举其他点为汇点的情况, 跑网络流, 求其中最小的情况. 如果最后ans为inf, 说明是一个完全图 ...

  6. Windows Phone

    错误: DEP6100 : 引导阶段“正在连接到设备”出现以下意外错误: SmartDeviceException - Windows Phone IP over USB Transport (IpO ...

  7. curl: (6) Couldn’t resolve host ‘www.ttlsa.com’

      上周, 部分站点出现Couldn't resolve host.....问题,  导致公司所有走api的程序都无法正常使用(系统redhat 6.3的都出现问题, redhat 5一切OK). 最 ...

  8. QT小记之在VS2005中使用(设置QMAKESPEC环境变量,以及编译QT Lib)

    QT的结构很清晰明了,看过第一个HELLO WORLD便爱上了它,感觉CEGUI有借鉴过QT的设计.如何在Windows平台下使用QT开发?一,下载SDK包请去官网(QT被NOKIA收购,貌似使用协议 ...

  9. 再探Delphi2010 Class的构造和析构顺序

    发了上一篇博客.盒子上有朋友认为Class的构造和析构延迟加载.是在Unit的初始化后调用的Class的构造.在Unit的反初始化前调用的Class的析构函数. 为了证明一下我又做了个试验 unit ...

  10. python 入门快速学习整理

    Python 入门学习 1  : 对象类型 1 1.1 列表 1 1.2 字典 2 1.3 元组 2 1.4 元组 2 1.4 文件 3 2  : 条件和循环语句 3 2.1  if else语句 3 ...