/****************************************************************************
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. GitLab概念——Group、Project、Member

    概念说明: Group是一个父子结构的目录 Group每一级都可以设置关联的Member,同时每一级下都可以创建项目 Group关联的Member和Member对应的权限,会继承到Group下的所有P ...

  2. Dubbo框架探讨(转)

    1. Dubbo是什么? Dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案.简单的说,dubbo就是个服务框架,如果没有分布式的需求,其实是不需 ...

  3. Ubuntu16.04 安装Processing

    下载 在 https://processing.org/ 上下载最新的linux 64bit版本gzip文件, 当前是 http://download.processing.org/processin ...

  4. 一些有用的git命令清单

    以下是一些我常用的git命令清单 如果以下的命令不清晰细节,请看git的文档. 设置个人信息 git config --global user.name "John Doe" gi ...

  5. HttpClient库设置超时

    HttpClient库API跟Lucene一样,每个版本的API都变化很大,这有点让人头疼.就好比创建一个HttpClient对象吧,每一个版本的都不一样. 3.X是正常的Java语法 HttpCli ...

  6. NFS安装及优化过程--centos6.6

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...

  7. Linux中tomcat启动很慢,SessionIdGeneratorBase.createSecureRandom耗时5分钟

    通常情况下,tomcat启动只要2~3秒钟,突然有一天,tomcat启动非常慢,要花5~6分钟,查了很久,终于在这篇文章找到了解决方案,博主牛人啊. 原文参见:http://blog.csdn.NET ...

  8. Sqlserver大数据量分区表创建

    /* 逆向删除对象 DROP PARTITION SCHEME [PS_BasicPolicy2014]; DROP PARTITION FUNCTION [PF_BasicPolicy2014]; ...

  9. bootstrap fileinput 文件上传

    最近因为项目需要研究了下bootstrap fileinput的使用,来记录下这几天的使用心得吧. 前台html页面的代码 <form role="form" id=&quo ...

  10. 安装Nginx+Tomcat

    Centos下安装nginx rpm包 1 在nginx官方网站下载一个rpm包,下载地址是:http://nginx.org/packages/centos/  http://nginx.org/e ...