/****************************************************************************
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 __CCOBJECT_H__
#define __CCOBJECT_H__ #include "CCDataVisitor.h" #ifdef EMSCRIPTEN
#include <GLES2/gl2.h>
#endif // EMSCRIPTEN NS_CC_BEGIN /**
* @addtogroup base_nodes
* @{
*/ class CCZone;
class CCObject;
class CCNode;
class CCEvent; class CC_DLL CCCopying
{
public:
virtual CCObject* copyWithZone(CCZone* pZone);
}; class CC_DLL CCObject : public CCCopying
{
public:
// object id, CCScriptSupport need public m_uID
unsigned int m_uID;
// Lua reference id
int m_nLuaID;
protected:
// count of references
unsigned int m_uReference;
// count of autorelease
unsigned int m_uAutoReleaseCount;
public:
CCObject(void);
virtual ~CCObject(void); void release(void);
void retain(void);
CCObject* autorelease(void);
CCObject* copy(void);
bool isSingleReference(void) const;
unsigned int retainCount(void) const;
virtual bool isEqual(const CCObject* pObject); virtual void acceptVisitor(CCDataVisitor &visitor); virtual void update(float dt) {CC_UNUSED_PARAM(dt);}; friend class CCAutoreleasePool;
}; typedef void (CCObject::*SEL_SCHEDULE)(float);
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*);
typedef int (CCObject::*SEL_Compare)(CCObject*); #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)
#define compare_selector(_SELECTOR) (SEL_Compare)(&_SELECTOR) // end of base_nodes group
/// @} NS_CC_END #endif // __CCOBJECT_H__
/****************************************************************************
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.
****************************************************************************/ #include "CCObject.h"
#include "CCAutoreleasePool.h"
#include "ccMacros.h"
#include "script_support/CCScriptSupport.h" NS_CC_BEGIN CCObject* CCCopying::copyWithZone(CCZone *pZone)
{
CC_UNUSED_PARAM(pZone);
CCAssert(, "not implement");
return ;
} CCObject::CCObject(void)
: m_nLuaID()
, m_uReference() // when the object is created, the reference count of it is 1
, m_uAutoReleaseCount()
{
static unsigned int uObjectCount = ; m_uID = ++uObjectCount;
} CCObject::~CCObject(void)
{
// if the object is managed, we should remove it
// from pool manager
if (m_uAutoReleaseCount > )
{
CCPoolManager::sharedPoolManager()->removeObject(this);
} // if the object is referenced by Lua engine, remove it
if (m_nLuaID)
{
CCScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptObjectByCCObject(this);
}
else
{
CCScriptEngineProtocol* pEngine = CCScriptEngineManager::sharedManager()->getScriptEngine();
if (pEngine != NULL && pEngine->getScriptType() == kScriptTypeJavascript)
{
pEngine->removeScriptObjectByCCObject(this);
}
}
} CCObject* CCObject::copy()
{
return copyWithZone();
} void CCObject::release(void)
{
CCAssert(m_uReference > , "reference count should greater than 0");
--m_uReference; if (m_uReference == )
{
delete this;
}
} void CCObject::retain(void)
{
CCAssert(m_uReference > , "reference count should greater than 0"); ++m_uReference;
} CCObject* CCObject::autorelease(void)
{
CCPoolManager::sharedPoolManager()->addObject(this);
return this;
} bool CCObject::isSingleReference(void) const
{
return m_uReference == ;
} unsigned int CCObject::retainCount(void) const
{
return m_uReference;
} bool CCObject::isEqual(const CCObject *pObject)
{
return this == pObject;
} void CCObject::acceptVisitor(CCDataVisitor &visitor)
{
visitor.visitObject(this);
} NS_CC_END

CCObject的更多相关文章

  1. 继承自CCObject的对象成员变量出错或者为空的问题

    写了个类想让其作为某种数据集合,还可以自动销毁,所以就直接继承了最底层的CCObject,所以并不属于视图,也就不会被addChild到显示列表里,于是就造成了接下来遇到的一个情况:其所有的成员变量被 ...

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

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

  3. cocos2dx进阶学习之CCObject

    继承关系 CCObject -> CCCopying 类定义 class CC_DLL CCObject : public CCCopying { public: // object id, C ...

  4. [置顶] 【玩转cocos2d-x之二十】从CCObject看cocos2d-x的内存管理机制

    原创作品,转载请标明:http://blog.csdn.net/jackystudio/article/details/13765639 再看CCObject,剔除上节的拷贝相关,以及Lua脚本相关的 ...

  5. 程序挂在dynamic_cast<CCObject*>(pDelegate)->retain();

    CCTargetedTouchDelegate 的继承 和 dynamic_cast 想写个可以响应touch的sprite 类定义成了这个样子: class GemBoard : public CC ...

  6. cocos2d-x 源代码分析 : Ref (CCObject) 源代码分析 cocos2d-x内存管理策略

    从源代码版本号3.x.转载请注明 cocos2d-x 总的文件夹的源代码分析: http://blog.csdn.net/u011225840/article/details/31743129 1.R ...

  7. Cocos2d-x不要随便在onEnter里面addChild

    使用任何版本的Cocos2d-x(1.x,2.x,3.0),在onEnter中调用addChild,都要小心谨慎,因为它有可能导致两种莫名其妙的BUG,莫名其妙的BUG当然难以定位了!更何况这个BUG ...

  8. cocos2dx 实现flappybird

    前两天在博客园看到网友实现的一个网页版的flappy bird,挂在360游戏平台,玩了一会儿得分超低,就很想自己做一个.刚好这两天炫舞的活都清了,就弄一下玩玩. 效果图 布局类GameScene.h ...

  9. Pointer's NULL And 0

    问题起源 在使用Qt框架的时候, 经常发现一些构造函数 *parent = 0 这样的代码. 时间长了, 就觉的疑惑了. 一个指针不是等于NULL吗? 这样写, 行得通吗? 自己测试一下就可以了. 测 ...

随机推荐

  1. tomcat,很多时候,可以在服务server.xml中可以实现一些效果

    一.--日志 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="log ...

  2. 微信小程序云端解决方案探索之路

    小程序刚推出的时候,很多人都觉得它就是 H5,因为开发小程序的三大语言和 HTML.CSS.JS 是一脉相承的,即使改变了扩展名也改不了其实质. 那么小程序的实质到底是不是 H5 呢?经过我们的论证分 ...

  3. jsp空指针异常

    1.Tomcat启动后访问首页报错 显示JSP 空指针异常 这哥们是因为lib下jar包和Tomcat下的jar包冲突,去掉lib下 servlet-api-2.5.jar 以及jsp-api.jar ...

  4. webDriver.Close() 和 webDriver.Quit() 、webDriver.Dispose() 的区别

    1. webDriver.Close() - Close the browser window that the driver has focus of //关闭当前焦点所在的窗口2. webDriv ...

  5. 【LeetCode】215. Kth Largest Element in an Array (2 solutions)

    Kth Largest Element in an Array Find the kth largest element in an unsorted array. Note that it is t ...

  6. Maven学习--- 搭建多模块企业级项目

    我们先在eclipse中新建一个maven项目,pom.xml的文件如下: 搭建多模块项目,必须要有一个packaging为pom的根目录.创建好这个maven项目后,我们对着项目右键-->ne ...

  7. Could not connect to Redis at xxx.xxx.xxx.xxx:6379: Connection refused

    开发发来消息说测试环境的redis无法登录: # redis-cli -p 6379 -h xxx.xxx.xxx.xxx Could not connect to Redis at xxx.xxx. ...

  8. Android 自定义可拖拽View,界面渲染刷新后不会自动回到起始位置

    以自定义ImageView为例: /** * 可拖拽ImageView * Created by admin on 2017/2/21. */ public class FloatingImageVi ...

  9. linux文件系统 - 初始化(二)

    加载initrd(上) 一.目的 本文主要讲述linux3.10文件系统初始化过程的第二阶段:加载initrd. initrd是一个临时文件系统,由bootload负责加载到内存中,里面包含了基本的可 ...

  10. (LeetCode)用两个栈实现一个队列

    LeetCode上面的一道题目.原文例如以下: Implement the following operations of a queue using stacks. push(x) -- Push ...