2011-01-07 09:35:27 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 cocos2d-x.org
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef __CC_PLATFORM_MACROS_H__
|
|
|
|
#define __CC_PLATFORM_MACROS_H__
|
|
|
|
|
|
|
|
/**
|
|
|
|
* define some platform specific macros
|
|
|
|
*/
|
2011-01-15 18:05:35 +08:00
|
|
|
#include "ccConfig.h"
|
2011-03-07 17:11:57 +08:00
|
|
|
#include "CCPlatformConfig.h"
|
2012-04-25 16:18:04 +08:00
|
|
|
#include "CCPlatformDefine.h"
|
2011-01-07 09:35:27 +08:00
|
|
|
|
2012-08-27 16:11:07 +08:00
|
|
|
/**
|
2013-06-20 14:13:12 +08:00
|
|
|
* define a create function for a specific type, such as Layer
|
2013-07-30 02:04:17 +08:00
|
|
|
* @param \__TYPE__ class type to add create(), such as Layer
|
2012-08-27 16:11:07 +08:00
|
|
|
*/
|
|
|
|
#define CREATE_FUNC(__TYPE__) \
|
|
|
|
static __TYPE__* create() \
|
|
|
|
{ \
|
|
|
|
__TYPE__ *pRet = new __TYPE__(); \
|
|
|
|
if (pRet && pRet->init()) \
|
|
|
|
{ \
|
|
|
|
pRet->autorelease(); \
|
|
|
|
return pRet; \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
{ \
|
|
|
|
delete pRet; \
|
|
|
|
pRet = NULL; \
|
|
|
|
return NULL; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-06-20 14:13:12 +08:00
|
|
|
* define a node function for a specific type, such as Layer
|
2013-07-30 02:04:17 +08:00
|
|
|
* @param \__TYPE__ class type to add node(), such as Layer
|
|
|
|
* @deprecated This interface will be deprecated sooner or later.
|
2012-08-27 16:11:07 +08:00
|
|
|
*/
|
|
|
|
#define NODE_FUNC(__TYPE__) \
|
|
|
|
CC_DEPRECATED_ATTRIBUTE static __TYPE__* node() \
|
|
|
|
{ \
|
|
|
|
__TYPE__ *pRet = new __TYPE__(); \
|
|
|
|
if (pRet && pRet->init()) \
|
|
|
|
{ \
|
|
|
|
pRet->autorelease(); \
|
|
|
|
return pRet; \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
{ \
|
|
|
|
delete pRet; \
|
|
|
|
pRet = NULL; \
|
|
|
|
return NULL; \
|
|
|
|
} \
|
|
|
|
}
|
2012-06-19 13:50:11 +08:00
|
|
|
|
2012-06-06 10:06:51 +08:00
|
|
|
/** @def CC_ENABLE_CACHE_TEXTURE_DATA
|
2011-03-09 11:38:36 +08:00
|
|
|
Enable it if you want to cache the texture data.
|
2013-06-13 05:46:32 +08:00
|
|
|
Not enabling for Emscripten any more -- doesn't seem necessary and don't want
|
|
|
|
to be different from other platforms unless there's a good reason.
|
2011-03-09 11:38:36 +08:00
|
|
|
|
|
|
|
It's new in cocos2d-x since v0.99.5
|
|
|
|
*/
|
2013-07-10 04:21:43 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
2013-04-09 10:10:12 +08:00
|
|
|
#define CC_ENABLE_CACHE_TEXTURE_DATA 1
|
2011-03-09 11:38:36 +08:00
|
|
|
#else
|
2012-06-06 10:06:51 +08:00
|
|
|
#define CC_ENABLE_CACHE_TEXTURE_DATA 0
|
2011-01-10 17:54:44 +08:00
|
|
|
#endif
|
|
|
|
|
2013-04-30 11:53:38 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_EMSCRIPTEN)
|
2012-04-19 14:35:52 +08:00
|
|
|
/* Application will crash in glDrawElements function on some win32 computers and some android devices.
|
|
|
|
Indices should be bound again while drawing to avoid this bug.
|
2012-04-13 17:24:50 +08:00
|
|
|
*/
|
|
|
|
#define CC_REBIND_INDICES_BUFFER 1
|
|
|
|
#else
|
|
|
|
#define CC_REBIND_INDICES_BUFFER 0
|
|
|
|
#endif
|
2011-03-09 11:38:36 +08:00
|
|
|
|
|
|
|
// generic macros
|
|
|
|
|
|
|
|
// namespace cocos2d {}
|
2012-04-20 15:12:20 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
#define NS_CC_BEGIN namespace cocos2d {
|
|
|
|
#define NS_CC_END }
|
|
|
|
#define USING_NS_CC using namespace cocos2d
|
|
|
|
#else
|
2012-07-20 14:05:52 +08:00
|
|
|
#define NS_CC_BEGIN
|
|
|
|
#define NS_CC_END
|
|
|
|
#define USING_NS_CC
|
2012-04-20 15:12:20 +08:00
|
|
|
#endif
|
2011-03-09 11:38:36 +08:00
|
|
|
|
|
|
|
/** CC_PROPERTY_READONLY is used to declare a protected variable.
|
|
|
|
We can use getter to read the variable.
|
2013-07-30 02:04:17 +08:00
|
|
|
@param varType the type of variable.
|
|
|
|
@param varName variable name.
|
|
|
|
@param funName "get + funName" will be the name of the getter.
|
|
|
|
@warning The getter is a public virtual function, you should rewrite it first.
|
|
|
|
The variables and methods declared after CC_PROPERTY_READONLY are all public.
|
|
|
|
If you need protected or private, please declare.
|
2011-03-09 11:38:36 +08:00
|
|
|
*/
|
|
|
|
#define CC_PROPERTY_READONLY(varType, varName, funName)\
|
|
|
|
protected: varType varName;\
|
2013-06-14 08:25:14 +08:00
|
|
|
public: virtual varType get##funName(void) const;
|
2011-03-09 11:38:36 +08:00
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
#define CC_PROPERTY_READONLY_PASS_BY_REF(varType, varName, funName)\
|
|
|
|
protected: varType varName;\
|
2013-06-14 08:25:14 +08:00
|
|
|
public: virtual const varType& get##funName(void) const;
|
2011-08-17 21:19:57 +08:00
|
|
|
|
2011-03-09 11:38:36 +08:00
|
|
|
/** CC_PROPERTY is used to declare a protected variable.
|
|
|
|
We can use getter to read the variable, and use the setter to change the variable.
|
2013-07-30 02:04:17 +08:00
|
|
|
@param varType the type of variable.
|
|
|
|
@param varName variable name.
|
|
|
|
@param funName "get + funName" will be the name of the getter.
|
|
|
|
"set + funName" will be the name of the setter.
|
|
|
|
@warning The getter and setter are public virtual functions, you should rewrite them first.
|
|
|
|
The variables and methods declared after CC_PROPERTY are all public.
|
|
|
|
If you need protected or private, please declare.
|
2011-03-09 11:38:36 +08:00
|
|
|
*/
|
|
|
|
#define CC_PROPERTY(varType, varName, funName)\
|
|
|
|
protected: varType varName;\
|
2012-01-09 11:07:45 +08:00
|
|
|
public: virtual varType get##funName(void);\
|
|
|
|
public: virtual void set##funName(varType var);
|
2011-03-09 11:38:36 +08:00
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
#define CC_PROPERTY_PASS_BY_REF(varType, varName, funName)\
|
|
|
|
protected: varType varName;\
|
2013-07-04 08:22:15 +08:00
|
|
|
public: virtual const varType& get##funName(void) const;\
|
2012-01-09 11:07:45 +08:00
|
|
|
public: virtual void set##funName(const varType& var);
|
2011-08-17 21:19:57 +08:00
|
|
|
|
2011-03-09 11:38:36 +08:00
|
|
|
/** CC_SYNTHESIZE_READONLY is used to declare a protected variable.
|
|
|
|
We can use getter to read the variable.
|
2013-07-30 02:04:17 +08:00
|
|
|
@param varType the type of variable.
|
|
|
|
@param varName variable name.
|
|
|
|
@param funName "get + funName" will be the name of the getter.
|
|
|
|
@warning The getter is a public inline function.
|
|
|
|
The variables and methods declared after CC_SYNTHESIZE_READONLY are all public.
|
|
|
|
If you need protected or private, please declare.
|
2011-03-09 11:38:36 +08:00
|
|
|
*/
|
|
|
|
#define CC_SYNTHESIZE_READONLY(varType, varName, funName)\
|
|
|
|
protected: varType varName;\
|
2012-01-09 11:07:45 +08:00
|
|
|
public: virtual varType get##funName(void) const { return varName; }
|
2011-03-09 11:38:36 +08:00
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
#define CC_SYNTHESIZE_READONLY_PASS_BY_REF(varType, varName, funName)\
|
|
|
|
protected: varType varName;\
|
2012-01-09 11:07:45 +08:00
|
|
|
public: virtual const varType& get##funName(void) const { return varName; }
|
2011-08-17 21:19:57 +08:00
|
|
|
|
2011-03-09 11:38:36 +08:00
|
|
|
/** CC_SYNTHESIZE is used to declare a protected variable.
|
|
|
|
We can use getter to read the variable, and use the setter to change the variable.
|
2013-07-30 02:04:17 +08:00
|
|
|
@param varType the type of variable.
|
|
|
|
@param varName variable name.
|
|
|
|
@param funName "get + funName" will be the name of the getter.
|
|
|
|
"set + funName" will be the name of the setter.
|
|
|
|
@warning The getter and setter are public inline functions.
|
|
|
|
The variables and methods declared after CC_SYNTHESIZE are all public.
|
|
|
|
If you need protected or private, please declare.
|
2011-03-09 11:38:36 +08:00
|
|
|
*/
|
|
|
|
#define CC_SYNTHESIZE(varType, varName, funName)\
|
|
|
|
protected: varType varName;\
|
2012-01-09 11:07:45 +08:00
|
|
|
public: virtual varType get##funName(void) const { return varName; }\
|
|
|
|
public: virtual void set##funName(varType var){ varName = var; }
|
2011-03-09 11:38:36 +08:00
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
#define CC_SYNTHESIZE_PASS_BY_REF(varType, varName, funName)\
|
|
|
|
protected: varType varName;\
|
2013-01-14 15:51:53 +08:00
|
|
|
public: virtual const varType& get##funName(void) const { return varName; }\
|
2012-01-09 11:07:45 +08:00
|
|
|
public: virtual void set##funName(const varType& var){ varName = var; }
|
|
|
|
|
|
|
|
#define CC_SYNTHESIZE_RETAIN(varType, varName, funName) \
|
2012-03-16 13:42:53 +08:00
|
|
|
private: varType varName; \
|
2012-01-09 11:07:45 +08:00
|
|
|
public: virtual varType get##funName(void) const { return varName; } \
|
|
|
|
public: virtual void set##funName(varType var) \
|
|
|
|
{ \
|
2012-04-19 14:35:52 +08:00
|
|
|
if (varName != var) \
|
|
|
|
{ \
|
|
|
|
CC_SAFE_RETAIN(var); \
|
|
|
|
CC_SAFE_RELEASE(varName); \
|
|
|
|
varName = var; \
|
|
|
|
} \
|
2012-01-09 11:07:45 +08:00
|
|
|
}
|
|
|
|
|
2013-07-26 15:33:40 +08:00
|
|
|
#define CC_SAFE_DELETE(p) do { delete (p); (p) = nullptr; } while(0)
|
|
|
|
#define CC_SAFE_DELETE_ARRAY(p) do { if(p) { delete[] (p); (p) = nullptr; } } while(0)
|
|
|
|
#define CC_SAFE_FREE(p) do { if(p) { free(p); (p) = nullptr; } } while(0)
|
|
|
|
#define CC_SAFE_RELEASE(p) do { if(p) { (p)->release(); } } while(0)
|
|
|
|
#define CC_SAFE_RELEASE_NULL(p) do { if(p) { (p)->release(); (p) = nullptr; } } while(0)
|
|
|
|
#define CC_SAFE_RETAIN(p) do { if(p) { (p)->retain(); } } while(0)
|
|
|
|
#define CC_BREAK_IF(cond) if(cond) break
|
2011-03-09 11:38:36 +08:00
|
|
|
|
2012-06-08 16:22:57 +08:00
|
|
|
#define __CCLOGWITHFUNCTION(s, ...) \
|
2013-07-24 06:20:22 +08:00
|
|
|
log("%s : %s",__FUNCTION__, String::createWithFormat(s, ##__VA_ARGS__)->getCString())
|
2011-03-09 11:38:36 +08:00
|
|
|
|
|
|
|
// cocos2d debug
|
|
|
|
#if !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0
|
2012-06-08 16:22:57 +08:00
|
|
|
#define CCLOG(...) do {} while (0)
|
|
|
|
#define CCLOGINFO(...) do {} while (0)
|
|
|
|
#define CCLOGERROR(...) do {} while (0)
|
|
|
|
#define CCLOGWARN(...) do {} while (0)
|
2011-03-09 11:38:36 +08:00
|
|
|
|
|
|
|
#elif COCOS2D_DEBUG == 1
|
2013-07-24 06:20:22 +08:00
|
|
|
#define CCLOG(format, ...) cocos2d::log(format, ##__VA_ARGS__)
|
|
|
|
#define CCLOGERROR(format,...) cocos2d::log(format, ##__VA_ARGS__)
|
2011-03-09 11:38:36 +08:00
|
|
|
#define CCLOGINFO(format,...) do {} while (0)
|
2012-06-08 16:22:57 +08:00
|
|
|
#define CCLOGWARN(...) __CCLOGWITHFUNCTION(__VA_ARGS__)
|
2011-03-09 11:38:36 +08:00
|
|
|
|
|
|
|
#elif COCOS2D_DEBUG > 1
|
2013-07-24 06:20:22 +08:00
|
|
|
#define CCLOG(format, ...) cocos2d::log(format, ##__VA_ARGS__)
|
|
|
|
#define CCLOGERROR(format,...) cocos2d::log(format, ##__VA_ARGS__)
|
|
|
|
#define CCLOGINFO(format,...) cocos2d::log(format, ##__VA_ARGS__)
|
2012-06-08 16:22:57 +08:00
|
|
|
#define CCLOGWARN(...) __CCLOGWITHFUNCTION(__VA_ARGS__)
|
2011-03-09 11:38:36 +08:00
|
|
|
#endif // COCOS2D_DEBUG
|
|
|
|
|
2012-02-02 10:37:21 +08:00
|
|
|
// Lua engine debug
|
|
|
|
#if !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0 || CC_LUA_ENGINE_DEBUG == 0
|
|
|
|
#define LUALOG(...)
|
|
|
|
#else
|
2013-07-24 06:20:22 +08:00
|
|
|
#define LUALOG(format, ...) cocos2d::log(format, ##__VA_ARGS__)
|
2012-02-02 10:37:21 +08:00
|
|
|
#endif // Lua engine debug
|
|
|
|
|
2013-04-20 19:13:19 +08:00
|
|
|
#if defined(__GNUC__) && ((__GNUC__ >= 5) || ((__GNUG__ == 4) && (__GNUC_MINOR__ >= 4))) \
|
|
|
|
|| (defined(__clang__) && (__clang_major__ >= 3))
|
|
|
|
#define CC_DISABLE_COPY(Class) \
|
|
|
|
private: \
|
|
|
|
Class(const Class &) = delete; \
|
|
|
|
Class &operator =(const Class &) = delete;
|
|
|
|
#else
|
|
|
|
#define CC_DISABLE_COPY(Class) \
|
|
|
|
private: \
|
|
|
|
Class(const Class &); \
|
|
|
|
Class &operator =(const Class &);
|
|
|
|
#endif
|
|
|
|
|
2012-07-19 17:22:36 +08:00
|
|
|
/*
|
|
|
|
* only certain compilers support __attribute__((deprecated))
|
|
|
|
*/
|
2012-08-01 13:24:23 +08:00
|
|
|
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
|
|
|
#define CC_DEPRECATED_ATTRIBUTE __attribute__((deprecated))
|
|
|
|
#elif _MSC_VER >= 1400 //vs 2005 or higher
|
|
|
|
#define CC_DEPRECATED_ATTRIBUTE __declspec(deprecated)
|
|
|
|
#else
|
2012-07-19 17:22:36 +08:00
|
|
|
#define CC_DEPRECATED_ATTRIBUTE
|
2012-08-01 13:24:23 +08:00
|
|
|
#endif
|
2011-03-09 11:38:36 +08:00
|
|
|
|
2013-04-19 15:47:14 +08:00
|
|
|
/*
|
|
|
|
* only certain compiler support __attribute__((format))
|
|
|
|
* formatPos - 1-based position of format string argument
|
|
|
|
* argPos - 1-based position of first format-dependent argument
|
|
|
|
*/
|
|
|
|
#if defined(__GNUC__) && (__GNUC__ >= 4)
|
|
|
|
#define CC_FORMAT_PRINTF(formatPos, argPos) __attribute__((__format__(printf, formatPos, argPos)))
|
|
|
|
#elif defined(__has_attribute)
|
|
|
|
#if __has_attribute(format)
|
|
|
|
#define CC_FORMAT_PRINTF(formatPos, argPos) __attribute__((__format__(printf, formatPos, argPos)))
|
|
|
|
#endif // __has_attribute(format)
|
|
|
|
#else
|
|
|
|
#define CC_FORMAT_PRINTF(formatPos, argPos)
|
|
|
|
#endif
|
|
|
|
|
2013-04-19 17:56:27 +08:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#define CC_FORMAT_PRINTF_SIZE_T "%08lX"
|
|
|
|
#else
|
|
|
|
#define CC_FORMAT_PRINTF_SIZE_T "%08zX"
|
|
|
|
#endif
|
|
|
|
|
2013-03-03 10:32:09 +08:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#define CC_UNUSED __attribute__ ((unused))
|
|
|
|
#else
|
|
|
|
#define CC_UNUSED
|
|
|
|
#endif
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
//
|
|
|
|
// CC_REQUIRES_NULL_TERMINATION
|
|
|
|
//
|
|
|
|
#if !defined(CC_REQUIRES_NULL_TERMINATION)
|
|
|
|
#if defined(__APPLE_CC__) && (__APPLE_CC__ >= 5549)
|
|
|
|
#define CC_REQUIRES_NULL_TERMINATION __attribute__((sentinel(0,1)))
|
|
|
|
#elif defined(__GNUC__)
|
|
|
|
#define CC_REQUIRES_NULL_TERMINATION __attribute__((sentinel))
|
|
|
|
#else
|
|
|
|
#define CC_REQUIRES_NULL_TERMINATION
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2011-01-07 09:35:27 +08:00
|
|
|
#endif // __CC_PLATFORM_MACROS_H__
|