CCObject
/****************************************************************************
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的更多相关文章
- 继承自CCObject的对象成员变量出错或者为空的问题
写了个类想让其作为某种数据集合,还可以自动销毁,所以就直接继承了最底层的CCObject,所以并不属于视图,也就不会被addChild到显示列表里,于是就造成了接下来遇到的一个情况:其所有的成员变量被 ...
- cocos2d-x 的CCObject与autorelease 之深入分析
转自: http://blog.csdn.net/honghaier/article/details/8160519 CCObject.h: #ifndef __CCOBJECT_H__ #defin ...
- cocos2dx进阶学习之CCObject
继承关系 CCObject -> CCCopying 类定义 class CC_DLL CCObject : public CCCopying { public: // object id, C ...
- [置顶] 【玩转cocos2d-x之二十】从CCObject看cocos2d-x的内存管理机制
原创作品,转载请标明:http://blog.csdn.net/jackystudio/article/details/13765639 再看CCObject,剔除上节的拷贝相关,以及Lua脚本相关的 ...
- 程序挂在dynamic_cast<CCObject*>(pDelegate)->retain();
CCTargetedTouchDelegate 的继承 和 dynamic_cast 想写个可以响应touch的sprite 类定义成了这个样子: class GemBoard : public CC ...
- cocos2d-x 源代码分析 : Ref (CCObject) 源代码分析 cocos2d-x内存管理策略
从源代码版本号3.x.转载请注明 cocos2d-x 总的文件夹的源代码分析: http://blog.csdn.net/u011225840/article/details/31743129 1.R ...
- Cocos2d-x不要随便在onEnter里面addChild
使用任何版本的Cocos2d-x(1.x,2.x,3.0),在onEnter中调用addChild,都要小心谨慎,因为它有可能导致两种莫名其妙的BUG,莫名其妙的BUG当然难以定位了!更何况这个BUG ...
- cocos2dx 实现flappybird
前两天在博客园看到网友实现的一个网页版的flappy bird,挂在360游戏平台,玩了一会儿得分超低,就很想自己做一个.刚好这两天炫舞的活都清了,就弄一下玩玩. 效果图 布局类GameScene.h ...
- Pointer's NULL And 0
问题起源 在使用Qt框架的时候, 经常发现一些构造函数 *parent = 0 这样的代码. 时间长了, 就觉的疑惑了. 一个指针不是等于NULL吗? 这样写, 行得通吗? 自己测试一下就可以了. 测 ...
随机推荐
- codevs 2010 求后序遍历
时间限制: 1 s空间限制: 64000 KB题目描述 Description输入一棵二叉树的先序和中序遍历序列,输出其后序遍历序列.输入描述 Input Description共两行,第一行一个字符 ...
- Spring Cloud开发实践 - 01 - 简介和根模块
简介 使用Spring Boot的提升主要在于jar的打包形式给运维带来了很大的便利, 而Spring Cloud本身的优点不是那么明显, 相对于Dubbo而言, 可能体现在跨语言的交互性上(例如可以 ...
- Centos下和Win7下查看端口占用情况
Centos #会列出所有正在使用的端口及关联的进程/应用 netstat -nap #portnumber要用具体的端口号代替,可以直接列出该端口听使用进程/应用 lsof -i :portnumb ...
- 利用组策略API 编辑GPO(Group Policy Object)
用windows自带的GPO Editor编辑修改,然后利用注册表监控器regFromApp监视注册表的改动,就知道某个策略修改了注册表的哪个字段了. 下面是禁止U盘访问的例子: #include ...
- java实现https ssl请求url
import java.io.*;import java.net.*;import java.security.*;import java.security.cert.*;import java.ut ...
- 如何找到Firefox的收藏夹,就像IE一样,出现在网页的侧面
firefox有这个插件,安装后就可以 http://addons.mozine.cn/firefox/19/ All-In-OneSidebar ? 概述 All-In-OneSidebar ...
- std::string std::wstring 删除最后元素 得到最后元素
std::string str = "abcdefg,"; std::cout << "last character:"<<str.ba ...
- 使用Java调用JS
import junit.framework.TestCase; import javax.script.ScriptEngine; import javax.script.ScriptEngineM ...
- 转:Spring Cache抽象详解
缓存简介 缓存,我的理解是:让数据更接近于使用者:工作机制是:先从缓存中读取数据,如果没有再从慢速设备上读取实际数据(数据也会存入缓存):缓存什么:那些经常读取且不经常修改的数据/那些昂贵(CPU/I ...
- IT公司管理发展经验
2012-11-14 内容存档在evernote,笔记名"IT公司管理发展经验"