2013-10-12 15:25:45 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:47:11 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2017-02-14 14:36:57 +08:00
|
|
|
Copyright (c) 2013-2017 Chukong Technologies
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
2015-03-24 20:23:51 +08:00
|
|
|
|
2013-10-12 15:25:45 +08:00
|
|
|
#ifndef __CC_PLATFORM_MACROS_H__
|
|
|
|
#define __CC_PLATFORM_MACROS_H__
|
|
|
|
|
|
|
|
/**
|
2015-03-25 10:59:04 +08:00
|
|
|
* Define some platform specific macros.
|
2013-10-12 15:25:45 +08:00
|
|
|
*/
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "base/ccConfig.h"
|
2014-09-10 08:17:07 +08:00
|
|
|
#include "platform/CCPlatformConfig.h"
|
2014-09-10 07:50:02 +08:00
|
|
|
#include "platform/CCPlatformDefine.h"
|
2013-10-12 15:25:45 +08:00
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
/** @def CREATE_FUNC(__TYPE__)
|
|
|
|
* Define a create function for a specific type, such as Layer.
|
|
|
|
*
|
|
|
|
* @param __TYPE__ class type to add create(), such as Layer.
|
2013-10-12 15:25:45 +08:00
|
|
|
*/
|
|
|
|
#define CREATE_FUNC(__TYPE__) \
|
|
|
|
static __TYPE__* create() \
|
|
|
|
{ \
|
2014-09-27 19:53:44 +08:00
|
|
|
__TYPE__ *pRet = new(std::nothrow) __TYPE__(); \
|
2013-10-12 15:25:45 +08:00
|
|
|
if (pRet && pRet->init()) \
|
|
|
|
{ \
|
|
|
|
pRet->autorelease(); \
|
|
|
|
return pRet; \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
{ \
|
|
|
|
delete pRet; \
|
2015-10-31 19:18:39 +08:00
|
|
|
pRet = nullptr; \
|
|
|
|
return nullptr; \
|
2013-10-12 15:25:45 +08:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
/** @def NODE_FUNC(__TYPE__)
|
|
|
|
* Define a node function for a specific type, such as Layer.
|
|
|
|
*
|
|
|
|
* @param __TYPE__ class type to add node(), such as Layer.
|
2013-10-12 15:25:45 +08:00
|
|
|
* @deprecated This interface will be deprecated sooner or later.
|
|
|
|
*/
|
|
|
|
#define NODE_FUNC(__TYPE__) \
|
|
|
|
CC_DEPRECATED_ATTRIBUTE static __TYPE__* node() \
|
|
|
|
{ \
|
2014-09-27 19:53:44 +08:00
|
|
|
__TYPE__ *pRet = new(std::nothrow) __TYPE__(); \
|
2013-10-12 15:25:45 +08:00
|
|
|
if (pRet && pRet->init()) \
|
|
|
|
{ \
|
|
|
|
pRet->autorelease(); \
|
|
|
|
return pRet; \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
{ \
|
|
|
|
delete pRet; \
|
|
|
|
pRet = NULL; \
|
|
|
|
return NULL; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @def CC_ENABLE_CACHE_TEXTURE_DATA
|
2015-03-25 10:59:04 +08:00
|
|
|
* Enable it if you want to cache the texture data.
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @since v0.99.5
|
|
|
|
*/
|
2015-05-09 00:19:13 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
2013-10-12 15:25:45 +08:00
|
|
|
#define CC_ENABLE_CACHE_TEXTURE_DATA 1
|
|
|
|
#else
|
|
|
|
#define CC_ENABLE_CACHE_TEXTURE_DATA 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_EMSCRIPTEN)
|
2015-03-25 10:59:04 +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.
|
2013-10-12 15:25:45 +08:00
|
|
|
*/
|
|
|
|
#define CC_REBIND_INDICES_BUFFER 1
|
|
|
|
#else
|
|
|
|
#define CC_REBIND_INDICES_BUFFER 0
|
|
|
|
#endif
|
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
// Generic macros
|
2013-10-12 15:25:45 +08:00
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
/// @name namespace cocos2d
|
|
|
|
/// @{
|
2013-10-12 15:25:45 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
#define NS_CC_BEGIN namespace cocos2d {
|
|
|
|
#define NS_CC_END }
|
|
|
|
#define USING_NS_CC using namespace cocos2d
|
2015-08-14 21:17:51 +08:00
|
|
|
#define NS_CC ::cocos2d
|
2013-10-12 15:25:45 +08:00
|
|
|
#else
|
|
|
|
#define NS_CC_BEGIN
|
|
|
|
#define NS_CC_END
|
|
|
|
#define USING_NS_CC
|
2014-08-20 00:24:56 +08:00
|
|
|
#define NS_CC
|
2013-10-12 15:25:45 +08:00
|
|
|
#endif
|
2015-03-25 10:59:04 +08:00
|
|
|
// end of namespace group
|
|
|
|
/// @}
|
|
|
|
|
|
|
|
/** @def CC_PROPERTY_READONLY
|
|
|
|
* It is used to declare a protected variable. We can use getter to read the variable.
|
|
|
|
*
|
|
|
|
* @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.
|
2013-10-12 15:25:45 +08:00
|
|
|
*/
|
|
|
|
#define CC_PROPERTY_READONLY(varType, varName, funName)\
|
2017-05-03 10:12:31 +08:00
|
|
|
protected: varType varName; public: virtual varType get##funName(void) const;
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
#define CC_PROPERTY_READONLY_PASS_BY_REF(varType, varName, funName)\
|
2017-05-03 10:12:31 +08:00
|
|
|
protected: varType varName; public: virtual const varType& get##funName(void) const;
|
2013-10-12 15:25:45 +08:00
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
/** @def CC_PROPERTY
|
|
|
|
* It is used to declare a protected variable.
|
|
|
|
* We can use getter to read the variable, and use the setter to change the variable.
|
|
|
|
*
|
|
|
|
* @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.
|
2013-10-12 15:25:45 +08:00
|
|
|
*/
|
|
|
|
#define CC_PROPERTY(varType, varName, funName)\
|
2017-05-03 10:12:31 +08:00
|
|
|
protected: varType varName; public: virtual varType get##funName(void) const; virtual void set##funName(varType var);
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
#define CC_PROPERTY_PASS_BY_REF(varType, varName, funName)\
|
2017-05-03 10:12:31 +08:00
|
|
|
protected: varType varName; public: virtual const varType& get##funName(void) const; virtual void set##funName(const varType& var);
|
2013-10-12 15:25:45 +08:00
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
/** @def CC_SYNTHESIZE_READONLY
|
|
|
|
* It is used to declare a protected variable. We can use getter to read the variable.
|
|
|
|
*
|
|
|
|
* @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.
|
2013-10-12 15:25:45 +08:00
|
|
|
*/
|
|
|
|
#define CC_SYNTHESIZE_READONLY(varType, varName, funName)\
|
2017-05-03 10:12:31 +08:00
|
|
|
protected: varType varName; public: virtual inline varType get##funName(void) const { return varName; }
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
#define CC_SYNTHESIZE_READONLY_PASS_BY_REF(varType, varName, funName)\
|
2017-05-03 10:12:31 +08:00
|
|
|
protected: varType varName; public: virtual inline const varType& get##funName(void) const { return varName; }
|
2013-10-12 15:25:45 +08:00
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
/** @def CC_SYNTHESIZE
|
|
|
|
* It is used to declare a protected variable.
|
|
|
|
* We can use getter to read the variable, and use the setter to change the variable.
|
|
|
|
*
|
|
|
|
* @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.
|
2013-10-12 15:25:45 +08:00
|
|
|
*/
|
|
|
|
#define CC_SYNTHESIZE(varType, varName, funName)\
|
2017-05-03 10:12:31 +08:00
|
|
|
protected: varType varName; public: virtual inline varType get##funName(void) const { return varName; } virtual inline void set##funName(varType var){ varName = var; }
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
#define CC_SYNTHESIZE_PASS_BY_REF(varType, varName, funName)\
|
2017-05-03 10:12:31 +08:00
|
|
|
protected: varType varName; public: virtual inline const varType& get##funName(void) const { return varName; } virtual inline void set##funName(const varType& var){ varName = var; }
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
#define CC_SYNTHESIZE_RETAIN(varType, varName, funName) \
|
2017-05-03 10:12:31 +08:00
|
|
|
private: varType varName; public: virtual inline varType get##funName(void) const { return varName; } virtual inline void set##funName(varType var) \
|
2013-10-12 15:25:45 +08:00
|
|
|
{ \
|
|
|
|
if (varName != var) \
|
|
|
|
{ \
|
|
|
|
CC_SAFE_RETAIN(var); \
|
|
|
|
CC_SAFE_RELEASE(varName); \
|
|
|
|
varName = var; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
#define __CCLOGWITHFUNCTION(s, ...) \
|
2016-01-07 23:15:11 +08:00
|
|
|
cocos2d::log("%s : %s",__FUNCTION__, cocos2d::StringUtils::format(s, ##__VA_ARGS__).c_str())
|
2013-10-12 15:25:45 +08:00
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
/// @name Cocos2d debug
|
|
|
|
/// @{
|
2013-10-12 15:25:45 +08:00
|
|
|
#if !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0
|
|
|
|
#define CCLOG(...) do {} while (0)
|
|
|
|
#define CCLOGINFO(...) do {} while (0)
|
|
|
|
#define CCLOGERROR(...) do {} while (0)
|
|
|
|
#define CCLOGWARN(...) do {} while (0)
|
|
|
|
|
|
|
|
#elif COCOS2D_DEBUG == 1
|
|
|
|
#define CCLOG(format, ...) cocos2d::log(format, ##__VA_ARGS__)
|
|
|
|
#define CCLOGERROR(format,...) cocos2d::log(format, ##__VA_ARGS__)
|
|
|
|
#define CCLOGINFO(format,...) do {} while (0)
|
|
|
|
#define CCLOGWARN(...) __CCLOGWITHFUNCTION(__VA_ARGS__)
|
|
|
|
|
|
|
|
#elif COCOS2D_DEBUG > 1
|
|
|
|
#define CCLOG(format, ...) cocos2d::log(format, ##__VA_ARGS__)
|
|
|
|
#define CCLOGERROR(format,...) cocos2d::log(format, ##__VA_ARGS__)
|
|
|
|
#define CCLOGINFO(format,...) cocos2d::log(format, ##__VA_ARGS__)
|
|
|
|
#define CCLOGWARN(...) __CCLOGWITHFUNCTION(__VA_ARGS__)
|
|
|
|
#endif // COCOS2D_DEBUG
|
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
/** Lua engine debug */
|
2013-10-12 15:25:45 +08:00
|
|
|
#if !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0 || CC_LUA_ENGINE_DEBUG == 0
|
|
|
|
#define LUALOG(...)
|
|
|
|
#else
|
|
|
|
#define LUALOG(format, ...) cocos2d::log(format, ##__VA_ARGS__)
|
|
|
|
#endif // Lua engine debug
|
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
// end of debug group
|
|
|
|
/// @}
|
|
|
|
|
|
|
|
/** @def CC_DISALLOW_COPY_AND_ASSIGN(TypeName)
|
|
|
|
* A macro to disallow the copy constructor and operator= functions.
|
|
|
|
* This should be used in the private: declarations for a class
|
|
|
|
*/
|
2013-10-12 15:25:45 +08:00
|
|
|
#if defined(__GNUC__) && ((__GNUC__ >= 5) || ((__GNUG__ == 4) && (__GNUC_MINOR__ >= 4))) \
|
2015-08-14 21:17:51 +08:00
|
|
|
|| (defined(__clang__) && (__clang_major__ >= 3)) || (_MSC_VER >= 1800)
|
2013-11-23 08:09:05 +08:00
|
|
|
#define CC_DISALLOW_COPY_AND_ASSIGN(TypeName) \
|
|
|
|
TypeName(const TypeName &) = delete; \
|
|
|
|
TypeName &operator =(const TypeName &) = delete;
|
2013-10-12 15:25:45 +08:00
|
|
|
#else
|
2013-11-23 08:09:05 +08:00
|
|
|
#define CC_DISALLOW_COPY_AND_ASSIGN(TypeName) \
|
2013-11-30 02:34:15 +08:00
|
|
|
TypeName(const TypeName &); \
|
|
|
|
TypeName &operator =(const TypeName &);
|
2013-10-12 15:25:45 +08:00
|
|
|
#endif
|
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
/** @def CC_DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName)
|
|
|
|
* A macro to disallow all the implicit constructors, namely the
|
|
|
|
* default constructor, copy constructor and operator= functions.
|
|
|
|
*
|
|
|
|
* This should be used in the private: declarations for a class
|
|
|
|
* that wants to prevent anyone from instantiating it. This is
|
|
|
|
* especially useful for classes containing only static methods.
|
|
|
|
*/
|
2013-11-23 08:09:05 +08:00
|
|
|
#define CC_DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
|
|
|
|
TypeName(); \
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(TypeName)
|
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
/** @def CC_DEPRECATED_ATTRIBUTE
|
|
|
|
* Only certain compilers support __attribute__((deprecated)).
|
2013-10-12 15:25:45 +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
|
|
|
|
#define CC_DEPRECATED_ATTRIBUTE
|
|
|
|
#endif
|
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
/** @def CC_DEPRECATED(...)
|
|
|
|
* Macro to mark things deprecated as of a particular version
|
2015-09-22 16:08:23 +08:00
|
|
|
* can be used with arbitrary parameters which are thrown away.
|
2015-02-18 04:19:36 +08:00
|
|
|
* e.g. CC_DEPRECATED(4.0) or CC_DEPRECATED(4.0, "not going to need this anymore") etc.
|
|
|
|
*/
|
|
|
|
#define CC_DEPRECATED(...) CC_DEPRECATED_ATTRIBUTE
|
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
/** @def CC_FORMAT_PRINTF(formatPos, argPos)
|
|
|
|
* Only certain compiler support __attribute__((format))
|
|
|
|
*
|
|
|
|
* @param formatPos 1-based position of format string argument.
|
|
|
|
* @param argPos 1-based position of first format-dependent argument.
|
2013-10-12 15:25:45 +08:00
|
|
|
*/
|
|
|
|
#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
|
|
|
|
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#define CC_FORMAT_PRINTF_SIZE_T "%08lX"
|
|
|
|
#else
|
|
|
|
#define CC_FORMAT_PRINTF_SIZE_T "%08zX"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#define CC_UNUSED __attribute__ ((unused))
|
|
|
|
#else
|
|
|
|
#define CC_UNUSED
|
|
|
|
#endif
|
|
|
|
|
2015-03-25 10:59:04 +08:00
|
|
|
/** @def CC_REQUIRES_NULL_TERMINATION
|
|
|
|
*
|
|
|
|
*/
|
2013-10-12 15:25:45 +08:00
|
|
|
#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
|
|
|
|
|
|
|
|
#endif // __CC_PLATFORM_MACROS_H__
|