2011-11-18 21:23:54 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-04-25 16:18:04 +08:00
|
|
|
#ifndef __CCOBJECT_H__
|
|
|
|
#define __CCOBJECT_H__
|
2011-11-18 21:23:54 +08:00
|
|
|
|
2013-05-10 15:07:05 +08:00
|
|
|
#include "CCDataVisitor.h"
|
2011-11-18 21:23:54 +08:00
|
|
|
|
2013-04-09 08:51:30 +08:00
|
|
|
#ifdef EMSCRIPTEN
|
|
|
|
#include <GLES2/gl2.h>
|
|
|
|
#endif // EMSCRIPTEN
|
|
|
|
|
2012-04-07 12:02:40 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup base_nodes
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2011-11-18 21:23:54 +08:00
|
|
|
class CCZone;
|
|
|
|
class CCObject;
|
2012-01-08 21:03:16 +08:00
|
|
|
class CCNode;
|
|
|
|
class CCEvent;
|
2011-11-18 21:23:54 +08:00
|
|
|
|
|
|
|
class CC_DLL CCCopying
|
|
|
|
{
|
|
|
|
public:
|
2012-01-08 21:03:16 +08:00
|
|
|
virtual CCObject* copyWithZone(CCZone* pZone);
|
2013-06-14 08:25:14 +08:00
|
|
|
|
2011-11-18 21:23:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class CC_DLL CCObject : public CCCopying
|
|
|
|
{
|
|
|
|
public:
|
2012-02-09 17:48:15 +08:00
|
|
|
// object id, CCScriptSupport need public m_uID
|
2012-04-19 14:35:52 +08:00
|
|
|
unsigned int m_uID;
|
2012-01-08 21:03:16 +08:00
|
|
|
// Lua reference id
|
2012-02-04 11:34:17 +08:00
|
|
|
int m_nLuaID;
|
2012-01-08 21:03:16 +08:00
|
|
|
protected:
|
2012-09-17 15:02:24 +08:00
|
|
|
// count of references
|
2012-04-19 14:35:52 +08:00
|
|
|
unsigned int m_uReference;
|
2012-10-08 13:41:48 +08:00
|
|
|
// count of autorelease
|
|
|
|
unsigned int m_uAutoReleaseCount;
|
2011-11-18 21:23:54 +08:00
|
|
|
public:
|
2012-01-08 21:03:16 +08:00
|
|
|
CCObject(void);
|
|
|
|
virtual ~CCObject(void);
|
2012-01-20 19:08:21 +08:00
|
|
|
|
|
|
|
void release(void);
|
2012-01-08 21:03:16 +08:00
|
|
|
void retain(void);
|
|
|
|
CCObject* autorelease(void);
|
|
|
|
CCObject* copy(void);
|
2013-05-04 20:05:06 +08:00
|
|
|
bool isSingleReference(void) const;
|
|
|
|
unsigned int retainCount(void) const;
|
2012-01-08 21:03:16 +08:00
|
|
|
virtual bool isEqual(const CCObject* pObject);
|
2012-06-11 21:58:04 +08:00
|
|
|
|
2013-05-10 15:07:05 +08:00
|
|
|
virtual void acceptVisitor(CCDataVisitor &visitor);
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
virtual void update(float dt) {CC_UNUSED_PARAM(dt);};
|
2012-01-08 21:03:16 +08:00
|
|
|
|
|
|
|
friend class CCAutoreleasePool;
|
|
|
|
};
|
2011-11-18 21:23:54 +08:00
|
|
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
typedef void (CCObject::*SEL_SCHEDULE)(float);
|
2012-01-08 21:03:16 +08:00
|
|
|
typedef void (CCObject::*SEL_CallFunc)();
|
|
|
|
typedef void (CCObject::*SEL_CallFuncN)(CCNode*);
|
|
|
|
typedef void (CCObject::*SEL_CallFuncND)(CCNode*, void*);
|
|
|
|
typedef void (CCObject::*SEL_CallFuncO)(CCObject*);
|
|
|
|
typedef void (CCObject::*SEL_MenuHandler)(CCObject*);
|
|
|
|
typedef void (CCObject::*SEL_EventHandler)(CCEvent*);
|
2012-06-08 14:11:48 +08:00
|
|
|
typedef int (CCObject::*SEL_Compare)(CCObject*);
|
|
|
|
|
2012-01-08 21:03:16 +08:00
|
|
|
#define schedule_selector(_SELECTOR) (SEL_SCHEDULE)(&_SELECTOR)
|
|
|
|
#define callfunc_selector(_SELECTOR) (SEL_CallFunc)(&_SELECTOR)
|
|
|
|
#define callfuncN_selector(_SELECTOR) (SEL_CallFuncN)(&_SELECTOR)
|
|
|
|
#define callfuncND_selector(_SELECTOR) (SEL_CallFuncND)(&_SELECTOR)
|
|
|
|
#define callfuncO_selector(_SELECTOR) (SEL_CallFuncO)(&_SELECTOR)
|
|
|
|
#define menu_selector(_SELECTOR) (SEL_MenuHandler)(&_SELECTOR)
|
|
|
|
#define event_selector(_SELECTOR) (SEL_EventHandler)(&_SELECTOR)
|
2012-06-08 14:11:48 +08:00
|
|
|
#define compare_selector(_SELECTOR) (SEL_Compare)(&_SELECTOR)
|
2012-04-07 12:02:40 +08:00
|
|
|
|
2013-06-12 07:30:05 +08:00
|
|
|
// new callbacks based on C++11
|
2013-06-14 11:36:43 +08:00
|
|
|
#define CC_CALLBACK_0(__selector__,__target__, ...) std::bind(&__selector__,__target__, ##__VA_ARGS__)
|
|
|
|
#define CC_CALLBACK_1(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, ##__VA_ARGS__)
|
|
|
|
#define CC_CALLBACK_2(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, std::placeholders::_2, ##__VA_ARGS__)
|
2013-06-12 07:30:05 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of base_nodes group
|
|
|
|
/// @}
|
|
|
|
|
2012-04-07 12:02:40 +08:00
|
|
|
NS_CC_END
|
2011-11-18 21:23:54 +08:00
|
|
|
|
2012-04-25 16:18:04 +08:00
|
|
|
#endif // __CCOBJECT_H__
|