зеркало из https://github.com/microsoft/cocos2d-x.git
issue #4058: Get rid of Object ,rename it to Ref.
This commit is contained in:
Родитель
43e51a9cb1
Коммит
5e6130c92c
|
@ -1 +1 @@
|
|||
8f6bd203bc07c8cff824450938e8931abc027341
|
||||
6f2f4d4cad4517fbd5b711d5895f5912b6d0c8bd
|
|
@ -28,12 +28,12 @@ THE SOFTWARE.
|
|||
#ifndef __ACTIONS_CCACTION_H__
|
||||
#define __ACTIONS_CCACTION_H__
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCGeometry.h"
|
||||
#include "CCPlatformMacros.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class Node;
|
||||
/**
|
||||
* @addtogroup actions
|
||||
* @{
|
||||
|
@ -42,7 +42,7 @@ NS_CC_BEGIN
|
|||
/**
|
||||
@brief Base class for Action objects.
|
||||
*/
|
||||
class CC_DLL Action : public Object, public Clonable
|
||||
class CC_DLL Action : public Ref, public Clonable
|
||||
{
|
||||
public:
|
||||
/// Default tag used for all the actions
|
||||
|
|
|
@ -52,7 +52,7 @@ NS_CC_BEGIN;
|
|||
Used by CardinalSplineTo and (By) and CatmullRomTo (and By) actions.
|
||||
@ingroup Actions
|
||||
*/
|
||||
class CC_DLL PointArray : public Object, public Clonable
|
||||
class CC_DLL PointArray : public Ref, public Clonable
|
||||
{
|
||||
public:
|
||||
|
||||
|
|
|
@ -31,8 +31,6 @@ THE SOFTWARE.
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class Object;
|
||||
|
||||
/**
|
||||
* @addtogroup actions
|
||||
* @{
|
||||
|
|
|
@ -98,8 +98,6 @@ private:
|
|||
class CC_DLL FlipY3D : public FlipX3D
|
||||
{
|
||||
public:
|
||||
FlipY3D() {}
|
||||
virtual ~FlipY3D() {}
|
||||
/** creates the action with duration */
|
||||
static FlipY3D* create(float duration);
|
||||
|
||||
|
@ -107,6 +105,9 @@ public:
|
|||
virtual void update(float time) override;
|
||||
virtual FlipY3D* clone() const override;
|
||||
|
||||
protected:
|
||||
FlipY3D() {}
|
||||
virtual ~FlipY3D() {}
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(FlipY3D);
|
||||
};
|
||||
|
|
|
@ -333,7 +333,7 @@ CallFunc * CallFunc::create(const std::function<void()> &func)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
CallFunc * CallFunc::create(Object* selectorTarget, SEL_CallFunc selector)
|
||||
CallFunc * CallFunc::create(Ref* selectorTarget, SEL_CallFunc selector)
|
||||
{
|
||||
CallFunc *ret = new CallFunc();
|
||||
|
||||
|
@ -353,7 +353,7 @@ bool CallFunc::initWithFunction(const std::function<void()> &func)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool CallFunc::initWithTarget(Object* target) {
|
||||
bool CallFunc::initWithTarget(Ref* target) {
|
||||
if (target)
|
||||
{
|
||||
target->retain();
|
||||
|
@ -426,7 +426,7 @@ CallFuncN * CallFuncN::create(const std::function<void(Node*)> &func)
|
|||
}
|
||||
|
||||
// XXX deprecated
|
||||
CallFuncN * CallFuncN::create(Object* selectorTarget, SEL_CallFuncN selector)
|
||||
CallFuncN * CallFuncN::create(Ref* selectorTarget, SEL_CallFuncN selector)
|
||||
{
|
||||
CallFuncN *ret = new CallFuncN();
|
||||
|
||||
|
@ -455,7 +455,7 @@ bool CallFuncN::initWithFunction(const std::function<void (Node *)> &func)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool CallFuncN::initWithTarget(Object* selectorTarget, SEL_CallFuncN selector)
|
||||
bool CallFuncN::initWithTarget(Ref* selectorTarget, SEL_CallFuncN selector)
|
||||
{
|
||||
if (CallFunc::initWithTarget(selectorTarget)) {
|
||||
_callFuncN = selector;
|
||||
|
@ -485,7 +485,7 @@ CallFuncN * CallFuncN::clone() const
|
|||
// CallFuncND
|
||||
//
|
||||
|
||||
__CCCallFuncND * __CCCallFuncND::create(Object* selectorTarget, SEL_CallFuncND selector, void* d)
|
||||
__CCCallFuncND * __CCCallFuncND::create(Ref* selectorTarget, SEL_CallFuncND selector, void* d)
|
||||
{
|
||||
__CCCallFuncND* ret = new __CCCallFuncND();
|
||||
|
||||
|
@ -498,7 +498,7 @@ __CCCallFuncND * __CCCallFuncND::create(Object* selectorTarget, SEL_CallFuncND s
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
bool __CCCallFuncND::initWithTarget(Object* selectorTarget, SEL_CallFuncND selector, void* d)
|
||||
bool __CCCallFuncND::initWithTarget(Ref* selectorTarget, SEL_CallFuncND selector, void* d)
|
||||
{
|
||||
if (CallFunc::initWithTarget(selectorTarget))
|
||||
{
|
||||
|
@ -552,7 +552,7 @@ void __CCCallFuncO::execute()
|
|||
}
|
||||
}
|
||||
|
||||
__CCCallFuncO * __CCCallFuncO::create(Object* selectorTarget, SEL_CallFuncO selector, Object* object)
|
||||
__CCCallFuncO * __CCCallFuncO::create(Ref* selectorTarget, SEL_CallFuncO selector, Ref* object)
|
||||
{
|
||||
__CCCallFuncO *ret = new __CCCallFuncO();
|
||||
|
||||
|
@ -565,7 +565,7 @@ __CCCallFuncO * __CCCallFuncO::create(Object* selectorTarget, SEL_CallFuncO sele
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
bool __CCCallFuncO::initWithTarget(Object* selectorTarget, SEL_CallFuncO selector, Object* object)
|
||||
bool __CCCallFuncO::initWithTarget(Ref* selectorTarget, SEL_CallFuncO selector, Ref* object)
|
||||
{
|
||||
if (CallFunc::initWithTarget(selectorTarget))
|
||||
{
|
||||
|
@ -593,12 +593,12 @@ __CCCallFuncO * __CCCallFuncO::clone() const
|
|||
return a;
|
||||
}
|
||||
|
||||
Object* __CCCallFuncO::getObject() const
|
||||
Ref* __CCCallFuncO::getObject() const
|
||||
{
|
||||
return _object;
|
||||
}
|
||||
|
||||
void __CCCallFuncO::setObject(Object* obj)
|
||||
void __CCCallFuncO::setObject(Ref* obj)
|
||||
{
|
||||
if (obj != _object)
|
||||
{
|
||||
|
|
|
@ -259,23 +259,23 @@ public:
|
|||
|
||||
/** creates the action with the callback
|
||||
|
||||
typedef void (Object::*SEL_CallFunc)();
|
||||
typedef void (Ref::*SEL_CallFunc)();
|
||||
@deprecated Use the std::function API instead.
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static CallFunc * create(Object* target, SEL_CallFunc selector);
|
||||
CC_DEPRECATED_ATTRIBUTE static CallFunc * create(Ref* target, SEL_CallFunc selector);
|
||||
|
||||
public:
|
||||
/** executes the callback */
|
||||
virtual void execute();
|
||||
|
||||
inline Object* getTargetCallback()
|
||||
inline Ref* getTargetCallback()
|
||||
{
|
||||
return _selectorTarget;
|
||||
}
|
||||
|
||||
inline void setTargetCallback(Object* sel)
|
||||
inline void setTargetCallback(Ref* sel)
|
||||
{
|
||||
if (sel != _selectorTarget)
|
||||
{
|
||||
|
@ -301,10 +301,10 @@ protected:
|
|||
virtual ~CallFunc();
|
||||
|
||||
/** initializes the action with the callback
|
||||
typedef void (Object::*SEL_CallFunc)();
|
||||
typedef void (Ref::*SEL_CallFunc)();
|
||||
@deprecated Use the std::function API instead.
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithTarget(Object* target);
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithTarget(Ref* target);
|
||||
|
||||
/** initializes the action with the std::function<void()>
|
||||
* @js NA
|
||||
|
@ -313,7 +313,7 @@ protected:
|
|||
bool initWithFunction(const std::function<void()>& func);
|
||||
|
||||
/** Target that will be called */
|
||||
Object* _selectorTarget;
|
||||
Ref* _selectorTarget;
|
||||
|
||||
union
|
||||
{
|
||||
|
@ -342,10 +342,10 @@ public:
|
|||
|
||||
/** creates the action with the callback
|
||||
|
||||
typedef void (Object::*SEL_CallFuncN)(Node*);
|
||||
typedef void (Ref::*SEL_CallFuncN)(Node*);
|
||||
@deprecated Use the std::function API instead.
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static CallFuncN * create(Object* target, SEL_CallFuncN selector);
|
||||
CC_DEPRECATED_ATTRIBUTE static CallFuncN * create(Ref* target, SEL_CallFuncN selector);
|
||||
|
||||
//
|
||||
// Overrides
|
||||
|
@ -361,10 +361,10 @@ protected:
|
|||
|
||||
/** initializes the action with the callback
|
||||
|
||||
typedef void (Object::*SEL_CallFuncN)(Node*);
|
||||
typedef void (Ref::*SEL_CallFuncN)(Node*);
|
||||
@deprecated Use the std::function API instead.
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithTarget(Object* target, SEL_CallFuncN selector);
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithTarget(Ref* target, SEL_CallFuncN selector);
|
||||
|
||||
|
||||
/** function that will be called with the "sender" as the 1st argument */
|
||||
|
@ -384,7 +384,7 @@ class CC_DLL __CCCallFuncND : public CallFunc
|
|||
{
|
||||
public:
|
||||
/** creates the action with the callback and the data to pass as an argument */
|
||||
CC_DEPRECATED_ATTRIBUTE static __CCCallFuncND * create(Object* target, SEL_CallFuncND selector, void* d);
|
||||
CC_DEPRECATED_ATTRIBUTE static __CCCallFuncND * create(Ref* target, SEL_CallFuncND selector, void* d);
|
||||
|
||||
//
|
||||
// Overrides
|
||||
|
@ -397,7 +397,7 @@ protected:
|
|||
virtual ~__CCCallFuncND() {}
|
||||
|
||||
/** initializes the action with the callback and the data to pass as an argument */
|
||||
bool initWithTarget(Object* target, SEL_CallFuncND selector, void* d);
|
||||
bool initWithTarget(Ref* target, SEL_CallFuncND selector, void* d);
|
||||
|
||||
SEL_CallFuncND _callFuncND;
|
||||
void* _data;
|
||||
|
@ -419,30 +419,30 @@ class CC_DLL __CCCallFuncO : public CallFunc
|
|||
public:
|
||||
/** creates the action with the callback
|
||||
|
||||
typedef void (Object::*SEL_CallFuncO)(Object*);
|
||||
typedef void (Ref::*SEL_CallFuncO)(Ref*);
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static __CCCallFuncO * create(Object* target, SEL_CallFuncO selector, Object* object);
|
||||
CC_DEPRECATED_ATTRIBUTE static __CCCallFuncO * create(Ref* target, SEL_CallFuncO selector, Ref* object);
|
||||
//
|
||||
// Overrides
|
||||
//
|
||||
virtual __CCCallFuncO* clone() const override;
|
||||
virtual void execute() override;
|
||||
|
||||
Object* getObject() const;
|
||||
void setObject(Object* obj);
|
||||
Ref* getObject() const;
|
||||
void setObject(Ref* obj);
|
||||
|
||||
protected:
|
||||
__CCCallFuncO();
|
||||
virtual ~__CCCallFuncO();
|
||||
/** initializes the action with the callback
|
||||
|
||||
typedef void (Object::*SEL_CallFuncO)(Object*);
|
||||
typedef void (Ref::*SEL_CallFuncO)(Ref*);
|
||||
*/
|
||||
bool initWithTarget(Object* target, SEL_CallFuncO selector, Object* object);
|
||||
bool initWithTarget(Ref* target, SEL_CallFuncO selector, Ref* object);
|
||||
|
||||
|
||||
/** object to be passed as argument */
|
||||
Object* _object;
|
||||
Ref* _object;
|
||||
SEL_CallFuncO _callFuncO;
|
||||
|
||||
private:
|
||||
|
|
|
@ -172,8 +172,8 @@ void ActionManager::addAction(Action *action, Node *target, bool paused)
|
|||
CCASSERT(target != nullptr, "");
|
||||
|
||||
tHashElement *element = nullptr;
|
||||
// we should convert it to Object*, because we save it as Object*
|
||||
Object *tmp = target;
|
||||
// we should convert it to Ref*, because we save it as Ref*
|
||||
Ref *tmp = target;
|
||||
HASH_FIND_PTR(_targets, &tmp, element);
|
||||
if (! element)
|
||||
{
|
||||
|
@ -247,7 +247,7 @@ void ActionManager::removeAction(Action *action)
|
|||
}
|
||||
|
||||
tHashElement *element = nullptr;
|
||||
Object *target = action->getOriginalTarget();
|
||||
Ref *target = action->getOriginalTarget();
|
||||
HASH_FIND_PTR(_targets, &target, element);
|
||||
if (element)
|
||||
{
|
||||
|
|
|
@ -31,7 +31,7 @@ THE SOFTWARE.
|
|||
|
||||
#include "CCAction.h"
|
||||
#include "CCVector.h"
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -53,7 +53,7 @@ struct _hashElement;
|
|||
|
||||
@since v0.8
|
||||
*/
|
||||
class CC_DLL ActionManager : public Object
|
||||
class CC_DLL ActionManager : public Ref
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -122,13 +122,14 @@ public:
|
|||
*/
|
||||
void resumeTargets(const Vector<Node*>& targetsToResume);
|
||||
|
||||
void update(float dt);
|
||||
|
||||
protected:
|
||||
// declared in ActionManager.m
|
||||
|
||||
void removeActionAtIndex(ssize_t index, struct _hashElement *element);
|
||||
void deleteHashElement(struct _hashElement *element);
|
||||
void actionAllocWithHashElement(struct _hashElement *element);
|
||||
void update(float dt);
|
||||
|
||||
protected:
|
||||
struct _hashElement *_targets;
|
||||
|
|
|
@ -28,7 +28,7 @@ THE SOFTWARE.
|
|||
#define __CC_ANIMATION_H__
|
||||
|
||||
#include "CCPlatformConfig.h"
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCArray.h"
|
||||
#include "CCValue.h"
|
||||
#include "CCGeometry.h"
|
||||
|
@ -55,7 +55,7 @@ class SpriteFrame;
|
|||
|
||||
@since v2.0
|
||||
*/
|
||||
class CC_DLL AnimationFrame : public Object, public Clonable
|
||||
class CC_DLL AnimationFrame : public Ref, public Clonable
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -135,7 +135,7 @@ You can animate a Animation object by using the Animate action. Example:
|
|||
@endcode
|
||||
|
||||
*/
|
||||
class CC_DLL Animation : public Object, public Clonable
|
||||
class CC_DLL Animation : public Ref, public Clonable
|
||||
{
|
||||
public:
|
||||
/** Creates an animation
|
||||
|
|
|
@ -27,9 +27,10 @@ THE SOFTWARE.
|
|||
#ifndef __CC_ANIMATION_CACHE_H__
|
||||
#define __CC_ANIMATION_CACHE_H__
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCMap.h"
|
||||
#include "CCValue.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -48,7 +49,7 @@ Before v0.99.5, the recommend way was to save them on the Sprite. Since v0.99.5,
|
|||
|
||||
@since v0.99.5
|
||||
*/
|
||||
class CC_DLL AnimationCache : public Object
|
||||
class CC_DLL AnimationCache : public Ref
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -25,12 +25,14 @@ THE SOFTWARE.
|
|||
#ifndef __CC_FRAMEWORK_COMPONENT_H__
|
||||
#define __CC_FRAMEWORK_COMPONENT_H__
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CC_DLL Component : public Object
|
||||
class Node;
|
||||
|
||||
class CC_DLL Component : public Ref
|
||||
{
|
||||
protected:
|
||||
/**
|
||||
|
|
|
@ -27,7 +27,7 @@ THE SOFTWARE.
|
|||
#ifndef __CCCONFIGURATION_H__
|
||||
#define __CCCONFIGURATION_H__
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCGL.h"
|
||||
#include "CCString.h"
|
||||
#include "CCValue.h"
|
||||
|
@ -43,7 +43,7 @@ NS_CC_BEGIN
|
|||
@brief Configuration contains some openGL variables
|
||||
@since v0.99.0
|
||||
*/
|
||||
class CC_DLL Configuration : public Object
|
||||
class CC_DLL Configuration : public Ref
|
||||
{
|
||||
public:
|
||||
|
||||
|
|
|
@ -533,7 +533,7 @@ CC_DEPRECATED_ATTRIBUTE static inline AffineTransform CCAffineTransformIdentity(
|
|||
}
|
||||
|
||||
// CC prefix compatibility
|
||||
CC_DEPRECATED_ATTRIBUTE typedef Object CCObject;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef Ref CCObject;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef Event CCEvent;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef DataVisitor CCDataVisitor;
|
||||
CC_DEPRECATED_ATTRIBUTE typedef PrettyPrinter CCPrettyPrinter;
|
||||
|
|
|
@ -142,7 +142,9 @@ bool Director::init(void)
|
|||
_scheduler = new Scheduler();
|
||||
// action manager
|
||||
_actionManager = new ActionManager();
|
||||
_scheduler->scheduleUpdateForTarget(_actionManager, Scheduler::PRIORITY_SYSTEM, false);
|
||||
_scheduler->scheduleUpdate([this](float dt){
|
||||
this->_actionManager->update(dt);
|
||||
}, _actionManager, Scheduler::PRIORITY_SYSTEM, false);
|
||||
|
||||
_eventDispatcher = new EventDispatcher();
|
||||
_eventAfterDraw = new EventCustom(EVENT_AFTER_DRAW);
|
||||
|
|
|
@ -30,13 +30,12 @@ THE SOFTWARE.
|
|||
|
||||
#include "CCPlatformMacros.h"
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "ccTypes.h"
|
||||
#include "CCGeometry.h"
|
||||
#include "CCVector.h"
|
||||
#include "CCGL.h"
|
||||
#include "CCLabelAtlas.h"
|
||||
|
||||
#include "kazmath/mat4.h"
|
||||
|
||||
|
||||
|
@ -83,7 +82,7 @@ and when to execute the Scenes.
|
|||
- GL_COLOR_ARRAY is enabled
|
||||
- GL_TEXTURE_COORD_ARRAY is enabled
|
||||
*/
|
||||
class CC_DLL Director : public Object
|
||||
class CC_DLL Director : public Ref
|
||||
{
|
||||
public:
|
||||
static const char *EVENT_PROJECTION_CHANGED;
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include <string>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCPlatformMacros.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -39,7 +39,7 @@ class Node;
|
|||
/**
|
||||
* Base class of all kinds of events.
|
||||
*/
|
||||
class Event : public Object
|
||||
class Event : public Ref
|
||||
{
|
||||
public:
|
||||
enum class Type
|
||||
|
|
|
@ -52,7 +52,7 @@ event listeners can be added and removed even
|
|||
from within an EventListener, while events are being
|
||||
dispatched.
|
||||
*/
|
||||
class EventDispatcher : public Object
|
||||
class EventDispatcher : public Ref
|
||||
{
|
||||
public:
|
||||
/** Adds a event listener for a specified event with the priority of scene graph.
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#define cocos2d_libs_EventListener_h
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
@ -43,7 +43,7 @@ class Node;
|
|||
* If you need custom listener which with different callback, you need to inherit this class.
|
||||
* For instance, you could refer to EventListenerAcceleration, EventListenerKeyboard, EventListenerTouchOneByOne, EventListenerCustom.
|
||||
*/
|
||||
class EventListener : public Object
|
||||
class EventListener : public Ref
|
||||
{
|
||||
public:
|
||||
enum class Type
|
||||
|
|
|
@ -36,7 +36,7 @@ NS_CC_BEGIN
|
|||
class FontAtlas;
|
||||
|
||||
|
||||
class CC_DLL Font : public Object
|
||||
class CC_DLL Font : public Ref
|
||||
{
|
||||
public:
|
||||
virtual FontAtlas *createFontAtlas() = 0;
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
#include <unordered_map>
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -49,7 +49,7 @@ struct FontLetterDefinition
|
|||
int xAdvance;
|
||||
};
|
||||
|
||||
class CC_DLL FontAtlas : public Object
|
||||
class CC_DLL FontAtlas : public Ref
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -31,8 +31,7 @@ THE SOFTWARE.
|
|||
#define __CCGLPROGRAM_H__
|
||||
|
||||
#include "ccMacros.h"
|
||||
#include "CCObject.h"
|
||||
|
||||
#include "CCRef.h"
|
||||
#include "CCGL.h"
|
||||
#include "kazmath/kazmath.h"
|
||||
|
||||
|
@ -54,7 +53,7 @@ typedef void (*GLLogFunction) (GLuint program, GLsizei bufsize, GLsizei* length,
|
|||
|
||||
@since v2.0.0
|
||||
*/
|
||||
class CC_DLL GLProgram : public Object
|
||||
class CC_DLL GLProgram : public Ref
|
||||
{
|
||||
public:
|
||||
enum
|
||||
|
|
|
@ -27,7 +27,7 @@ THE SOFTWARE.
|
|||
#define __EFFECTS_CCGRABBER_H__
|
||||
|
||||
#include "CCConfiguration.h"
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCGL.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -40,7 +40,7 @@ class Texture2D;
|
|||
*/
|
||||
|
||||
/** FBO class that grabs the the contents of the screen */
|
||||
class Grabber : public Object
|
||||
class Grabber : public Ref
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -26,7 +26,7 @@ THE SOFTWARE.
|
|||
#ifndef __EFFECTS_CCGRID_H__
|
||||
#define __EFFECTS_CCGRID_H__
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCNode.h"
|
||||
#include "ccTypes.h"
|
||||
#include "CCTexture2D.h"
|
||||
|
@ -49,7 +49,7 @@ class GLProgram;
|
|||
|
||||
/** Base class for other
|
||||
*/
|
||||
class CC_DLL GridBase : public Object
|
||||
class CC_DLL GridBase : public Ref
|
||||
{
|
||||
public:
|
||||
/** create one Grid */
|
||||
|
|
|
@ -38,6 +38,7 @@ THE SOFTWARE.
|
|||
#include "platform/CCFileUtils.h"
|
||||
// external
|
||||
#include "kazmath/GL/matrix.h"
|
||||
#include "CCString.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ typedef struct _KerningHashElement
|
|||
/** @brief CCBMFontConfiguration has parsed configuration of the the .fnt file
|
||||
@since v0.8
|
||||
*/
|
||||
class CC_DLL CCBMFontConfiguration : public Object
|
||||
class CC_DLL CCBMFontConfiguration : public Ref
|
||||
{
|
||||
// XXX: Creating a public interface so that the bitmapFontArray[] is accessible
|
||||
public://@public
|
||||
|
|
|
@ -46,6 +46,7 @@ THE SOFTWARE.
|
|||
#include "CCScene.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "CCString.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ MenuItem* MenuItem::create()
|
|||
}
|
||||
|
||||
// XXX deprecated
|
||||
MenuItem* MenuItem::create(Object *target, SEL_MenuHandler selector)
|
||||
MenuItem* MenuItem::create(Ref *target, SEL_MenuHandler selector)
|
||||
{
|
||||
MenuItem *ret = new MenuItem();
|
||||
ret->initWithTarget(target, selector);
|
||||
|
@ -80,7 +80,7 @@ MenuItem* MenuItem::create( const ccMenuCallback& callback)
|
|||
}
|
||||
|
||||
// XXX deprecated
|
||||
bool MenuItem::initWithTarget(cocos2d::Object *target, SEL_MenuHandler selector )
|
||||
bool MenuItem::initWithTarget(cocos2d::Ref *target, SEL_MenuHandler selector )
|
||||
{
|
||||
_target = target;
|
||||
CC_SAFE_RETAIN(_target);
|
||||
|
@ -152,7 +152,7 @@ bool MenuItem::isSelected() const
|
|||
}
|
||||
|
||||
// XXX deprecated
|
||||
void MenuItem::setTarget(Object *target, SEL_MenuHandler selector)
|
||||
void MenuItem::setTarget(Ref *target, SEL_MenuHandler selector)
|
||||
{
|
||||
_target = target;
|
||||
CC_SAFE_RETAIN(_target);
|
||||
|
@ -191,7 +191,7 @@ void MenuItemLabel::setLabel(Node* var)
|
|||
}
|
||||
|
||||
// XXX: deprecated
|
||||
MenuItemLabel * MenuItemLabel::create(Node*label, Object* target, SEL_MenuHandler selector)
|
||||
MenuItemLabel * MenuItemLabel::create(Node*label, Ref* target, SEL_MenuHandler selector)
|
||||
{
|
||||
MenuItemLabel *ret = new MenuItemLabel();
|
||||
ret->initWithLabel(label, target, selector);
|
||||
|
@ -216,7 +216,7 @@ MenuItemLabel* MenuItemLabel::create(Node *label)
|
|||
}
|
||||
|
||||
// XXX: deprecated
|
||||
bool MenuItemLabel::initWithLabel(Node* label, Object* target, SEL_MenuHandler selector)
|
||||
bool MenuItemLabel::initWithLabel(Node* label, Ref* target, SEL_MenuHandler selector)
|
||||
{
|
||||
_target = target;
|
||||
CC_SAFE_RETAIN(_target);
|
||||
|
@ -321,7 +321,7 @@ MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const st
|
|||
}
|
||||
|
||||
// XXX: deprecated
|
||||
MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector)
|
||||
MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, Ref* target, SEL_MenuHandler selector)
|
||||
{
|
||||
MenuItemAtlasFont *ret = new MenuItemAtlasFont();
|
||||
ret->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, target, selector);
|
||||
|
@ -338,7 +338,7 @@ MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const st
|
|||
}
|
||||
|
||||
// XXX: deprecated
|
||||
bool MenuItemAtlasFont::initWithString(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector)
|
||||
bool MenuItemAtlasFont::initWithString(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, Ref* target, SEL_MenuHandler selector)
|
||||
{
|
||||
_target = target;
|
||||
CC_SAFE_RETAIN(_target);
|
||||
|
@ -387,7 +387,7 @@ const std::string& MenuItemFont::getFontName()
|
|||
}
|
||||
|
||||
// XXX: deprecated
|
||||
MenuItemFont * MenuItemFont::create(const std::string& value, Object* target, SEL_MenuHandler selector)
|
||||
MenuItemFont * MenuItemFont::create(const std::string& value, Ref* target, SEL_MenuHandler selector)
|
||||
{
|
||||
MenuItemFont *ret = new MenuItemFont();
|
||||
ret->initWithString(value, target, selector);
|
||||
|
@ -422,7 +422,7 @@ MenuItemFont::~MenuItemFont()
|
|||
}
|
||||
|
||||
// XXX: deprecated
|
||||
bool MenuItemFont::initWithString(const std::string& value, Object* target, SEL_MenuHandler selector)
|
||||
bool MenuItemFont::initWithString(const std::string& value, Ref* target, SEL_MenuHandler selector)
|
||||
{
|
||||
CCASSERT( !value.empty(), "Value length must be greater than 0");
|
||||
|
||||
|
@ -550,7 +550,7 @@ MenuItemSprite * MenuItemSprite::create(Node* normalSprite, Node* selectedSprite
|
|||
}
|
||||
|
||||
// XXX deprecated
|
||||
MenuItemSprite * MenuItemSprite::create(Node* normalSprite, Node* selectedSprite, Object* target, SEL_MenuHandler selector)
|
||||
MenuItemSprite * MenuItemSprite::create(Node* normalSprite, Node* selectedSprite, Ref* target, SEL_MenuHandler selector)
|
||||
{
|
||||
return MenuItemSprite::create(normalSprite, selectedSprite, nullptr, target, selector);
|
||||
}
|
||||
|
@ -561,7 +561,7 @@ MenuItemSprite * MenuItemSprite::create(Node* normalSprite, Node* selectedSprite
|
|||
}
|
||||
|
||||
// XXX deprecated
|
||||
MenuItemSprite * MenuItemSprite::create(Node *normalSprite, Node *selectedSprite, Node *disabledSprite, Object *target, SEL_MenuHandler selector)
|
||||
MenuItemSprite * MenuItemSprite::create(Node *normalSprite, Node *selectedSprite, Node *disabledSprite, Ref *target, SEL_MenuHandler selector)
|
||||
{
|
||||
MenuItemSprite *ret = new MenuItemSprite();
|
||||
ret->initWithNormalSprite(normalSprite, selectedSprite, disabledSprite, target, selector);
|
||||
|
@ -578,7 +578,7 @@ MenuItemSprite * MenuItemSprite::create(Node *normalSprite, Node *selectedSprite
|
|||
}
|
||||
|
||||
// XXX deprecated
|
||||
bool MenuItemSprite::initWithNormalSprite(Node* normalSprite, Node* selectedSprite, Node* disabledSprite, Object* target, SEL_MenuHandler selector)
|
||||
bool MenuItemSprite::initWithNormalSprite(Node* normalSprite, Node* selectedSprite, Node* disabledSprite, Ref* target, SEL_MenuHandler selector)
|
||||
{
|
||||
_target = target;
|
||||
CC_SAFE_RETAIN(_target);
|
||||
|
@ -710,7 +710,7 @@ MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std:
|
|||
}
|
||||
|
||||
// XXX deprecated
|
||||
MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std::string& selectedImage, Object* target, SEL_MenuHandler selector)
|
||||
MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std::string& selectedImage, Ref* target, SEL_MenuHandler selector)
|
||||
{
|
||||
return MenuItemImage::create(normalImage, selectedImage, "", target, selector);
|
||||
}
|
||||
|
@ -721,7 +721,7 @@ MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std:
|
|||
}
|
||||
|
||||
// XXX deprecated
|
||||
MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, Object* target, SEL_MenuHandler selector)
|
||||
MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, Ref* target, SEL_MenuHandler selector)
|
||||
{
|
||||
MenuItemImage *ret = new MenuItemImage();
|
||||
if (ret && ret->initWithNormalImage(normalImage, selectedImage, disabledImage, target, selector))
|
||||
|
@ -758,7 +758,7 @@ MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std:
|
|||
}
|
||||
|
||||
// XXX: deprecated
|
||||
bool MenuItemImage::initWithNormalImage(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, Object* target, SEL_MenuHandler selector)
|
||||
bool MenuItemImage::initWithNormalImage(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, Ref* target, SEL_MenuHandler selector)
|
||||
{
|
||||
_target = target;
|
||||
CC_SAFE_RETAIN(_target);
|
||||
|
@ -810,7 +810,7 @@ void MenuItemImage::setDisabledSpriteFrame(SpriteFrame * frame)
|
|||
//
|
||||
|
||||
// XXX: deprecated
|
||||
MenuItemToggle * MenuItemToggle::createWithTarget(Object* target, SEL_MenuHandler selector, const Vector<MenuItem*>& menuItems)
|
||||
MenuItemToggle * MenuItemToggle::createWithTarget(Ref* target, SEL_MenuHandler selector, const Vector<MenuItem*>& menuItems)
|
||||
{
|
||||
MenuItemToggle *ret = new MenuItemToggle();
|
||||
ret->MenuItem::initWithTarget(target, selector);
|
||||
|
@ -831,7 +831,7 @@ MenuItemToggle * MenuItemToggle::createWithCallback(const ccMenuCallback &callba
|
|||
}
|
||||
|
||||
// XXX: deprecated
|
||||
MenuItemToggle * MenuItemToggle::createWithTarget(Object* target, SEL_MenuHandler selector, MenuItem* item, ...)
|
||||
MenuItemToggle * MenuItemToggle::createWithTarget(Ref* target, SEL_MenuHandler selector, MenuItem* item, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, item);
|
||||
|
@ -862,7 +862,7 @@ MenuItemToggle * MenuItemToggle::create()
|
|||
}
|
||||
|
||||
// XXX: deprecated
|
||||
bool MenuItemToggle::initWithTarget(Object* target, SEL_MenuHandler selector, MenuItem* item, va_list args)
|
||||
bool MenuItemToggle::initWithTarget(Ref* target, SEL_MenuHandler selector, MenuItem* item, va_list args)
|
||||
{
|
||||
_target = target;
|
||||
CC_SAFE_RETAIN(_target);
|
||||
|
|
|
@ -38,7 +38,7 @@ THE SOFTWARE.
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
typedef std::function<void(Object*)> ccMenuCallback;
|
||||
typedef std::function<void(Ref*)> ccMenuCallback;
|
||||
|
||||
class LabelTTF;
|
||||
class LabelAtlas;
|
||||
|
@ -63,7 +63,7 @@ public:
|
|||
/** Creates a MenuItem with no target/selector */
|
||||
static MenuItem* create();
|
||||
/** Creates a MenuItem with a target/selector */
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItem* create(Object *rec, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItem* create(Ref *rec, SEL_MenuHandler selector);
|
||||
/** Creates a MenuItem with a target/selector */
|
||||
static MenuItem* create(const ccMenuCallback& callback);
|
||||
|
||||
|
@ -93,7 +93,7 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE void setTarget(Object *rec, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE void setTarget(Ref *rec, SEL_MenuHandler selector);
|
||||
|
||||
|
||||
virtual std::string getDescription() const override;
|
||||
|
@ -123,14 +123,14 @@ protected:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithTarget( Object *rec, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithTarget(Ref *rec, SEL_MenuHandler selector);
|
||||
|
||||
bool _selected;
|
||||
bool _enabled;
|
||||
// callback
|
||||
ccMenuCallback _callback;
|
||||
// If using the old API, the _target needs to be retained / released
|
||||
Object *_target;
|
||||
Ref *_target;
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(MenuItem);
|
||||
|
@ -147,7 +147,7 @@ class CC_DLL MenuItemLabel : public MenuItem
|
|||
{
|
||||
public:
|
||||
/** creates a MenuItemLabel with a Label, target and selector */
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemLabel * create(Node*label, Object* target, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemLabel * create(Node*label, Ref* target, SEL_MenuHandler selector);
|
||||
|
||||
/** creates a MenuItemLabel with a Label and a callback */
|
||||
static MenuItemLabel * create(Node*label, const ccMenuCallback& callback);
|
||||
|
@ -194,7 +194,7 @@ protected:
|
|||
bool initWithLabel(Node* label, const ccMenuCallback& callback);
|
||||
|
||||
/** initializes a MenuItemLabel with a Label, target and selector */
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithLabel(Node* label, Object* target, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithLabel(Node* label, Ref* target, SEL_MenuHandler selector);
|
||||
|
||||
Color3B _colorBackup;
|
||||
float _originalScale;
|
||||
|
@ -218,7 +218,7 @@ public:
|
|||
/** creates a menu item from a string and atlas with a target/selector */
|
||||
static MenuItemAtlasFont* create(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap);
|
||||
/** creates a menu item from a string and atlas. Use it with MenuItemToggle */
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemAtlasFont* create(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemAtlasFont* create(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, Ref* target, SEL_MenuHandler selector);
|
||||
/** creates a menu item from a string and atlas. Use it with MenuItemToggle */
|
||||
static MenuItemAtlasFont* create(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback);
|
||||
|
||||
|
@ -234,7 +234,7 @@ protected:
|
|||
virtual ~MenuItemAtlasFont(){}
|
||||
|
||||
/** initializes a menu item from a string and atlas with a target/selector */
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithString(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithString(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, Ref* target, SEL_MenuHandler selector);
|
||||
/** initializes a menu item from a string and atlas with a target/selector */
|
||||
bool initWithString(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback);
|
||||
|
||||
|
@ -252,7 +252,7 @@ public:
|
|||
/** creates a menu item from a string without target/selector. To be used with MenuItemToggle */
|
||||
static MenuItemFont * create(const std::string& value = "");
|
||||
/** creates a menu item from a string with a target/selector */
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemFont * create(const std::string& value, Object* target, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemFont * create(const std::string& value, Ref* target, SEL_MenuHandler selector);
|
||||
/** creates a menu item from a string with a target/selector */
|
||||
static MenuItemFont * create(const std::string& value, const ccMenuCallback& callback);
|
||||
|
||||
|
@ -307,7 +307,7 @@ protected:
|
|||
virtual ~MenuItemFont();
|
||||
|
||||
/** initializes a menu item from a string with a target/selector */
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithString(const std::string& value, Object* target, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithString(const std::string& value, Ref* target, SEL_MenuHandler selector);
|
||||
/** initializes a menu item from a string with a target/selector */
|
||||
bool initWithString(const std::string& value, const ccMenuCallback& callback);
|
||||
|
||||
|
@ -335,9 +335,9 @@ public:
|
|||
/** creates a menu item with a normal, selected and disabled image*/
|
||||
static MenuItemSprite * create(Node* normalSprite, Node* selectedSprite, Node* disabledSprite = nullptr);
|
||||
/** creates a menu item with a normal and selected image with target/selector */
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemSprite * create(Node* normalSprite, Node* selectedSprite, Object* target, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemSprite * create(Node* normalSprite, Node* selectedSprite, Ref* target, SEL_MenuHandler selector);
|
||||
/** creates a menu item with a normal,selected and disabled image with target/selector */
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemSprite * create(Node* normalSprite, Node* selectedSprite, Node* disabledSprite, Object* target, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemSprite * create(Node* normalSprite, Node* selectedSprite, Node* disabledSprite, Ref* target, SEL_MenuHandler selector);
|
||||
/** creates a menu item with a normal and selected image with a callable object */
|
||||
static MenuItemSprite * create(Node* normalSprite, Node* selectedSprite, const ccMenuCallback& callback);
|
||||
/** creates a menu item with a normal,selected and disabled image with target/selector */
|
||||
|
@ -376,7 +376,7 @@ protected:
|
|||
{}
|
||||
|
||||
/** initializes a menu item with a normal, selected and disabled image with target/selector */
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithNormalSprite(Node* normalSprite, Node* selectedSprite, Node* disabledSprite, Object* target, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithNormalSprite(Node* normalSprite, Node* selectedSprite, Node* disabledSprite, Ref* target, SEL_MenuHandler selector);
|
||||
/** initializes a menu item with a normal, selected and disabled image with a callable object */
|
||||
bool initWithNormalSprite(Node* normalSprite, Node* selectedSprite, Node* disabledSprite, const ccMenuCallback& callback);
|
||||
|
||||
|
@ -412,12 +412,12 @@ public:
|
|||
/** creates a menu item with a normal,selected and disabled image*/
|
||||
static MenuItemImage* create(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage);
|
||||
/** creates a menu item with a normal and selected image with target/selector */
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemImage* create(const std::string& normalImage, const std::string& selectedImage, Object* target, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemImage* create(const std::string& normalImage, const std::string& selectedImage, Ref* target, SEL_MenuHandler selector);
|
||||
/** creates a menu item with a normal and selected image with a callable object */
|
||||
static MenuItemImage* create(const std::string&normalImage, const std::string&selectedImage, const ccMenuCallback& callback);
|
||||
|
||||
/** creates a menu item with a normal,selected and disabled image with target/selector */
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemImage* create(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, Object* target, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemImage* create(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, Ref* target, SEL_MenuHandler selector);
|
||||
/** creates a menu item with a normal,selected and disabled image with a callable object */
|
||||
static MenuItemImage* create(const std::string&normalImage, const std::string&selectedImage, const std::string&disabledImage, const ccMenuCallback& callback);
|
||||
|
||||
|
@ -441,7 +441,7 @@ protected:
|
|||
|
||||
bool init();
|
||||
/** initializes a menu item with a normal, selected and disabled image with target/selector */
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithNormalImage(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, Object* target, SEL_MenuHandler selector);
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithNormalImage(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, Ref* target, SEL_MenuHandler selector);
|
||||
/** initializes a menu item with a normal, selected and disabled image with a callable object */
|
||||
bool initWithNormalImage(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, const ccMenuCallback& callback);
|
||||
|
||||
|
@ -461,12 +461,12 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemToggle * createWithTarget(Object* target, SEL_MenuHandler selector, const Vector<MenuItem*>& menuItems);
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemToggle * createWithTarget(Ref* target, SEL_MenuHandler selector, const Vector<MenuItem*>& menuItems);
|
||||
/** creates a menu item from a list of items with a target/selector
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemToggle* createWithTarget(Object* target, SEL_MenuHandler selector, MenuItem* item, ...)CC_REQUIRES_NULL_TERMINATION;
|
||||
CC_DEPRECATED_ATTRIBUTE static MenuItemToggle* createWithTarget(Ref* target, SEL_MenuHandler selector, MenuItem* item, ...)CC_REQUIRES_NULL_TERMINATION;
|
||||
|
||||
/** creates a menu item from a Array with a callable object */
|
||||
static MenuItemToggle * createWithCallback(const ccMenuCallback& callback, const Vector<MenuItem*>& menuItems);
|
||||
|
@ -527,7 +527,7 @@ protected:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithTarget(Object* target, SEL_MenuHandler selector, MenuItem* item, va_list args);
|
||||
CC_DEPRECATED_ATTRIBUTE bool initWithTarget(Ref* target, SEL_MenuHandler selector, MenuItem* item, va_list args);
|
||||
/** initializes a menu item from a list of items with a callable object */
|
||||
bool initWithCallback(const ccMenuCallback& callback, MenuItem* item, va_list args);
|
||||
|
||||
|
|
|
@ -492,7 +492,7 @@ void Node::setOrderOfArrival(int orderOfArrival)
|
|||
_orderOfArrival = orderOfArrival;
|
||||
}
|
||||
|
||||
void Node::setUserObject(Object *pUserObject)
|
||||
void Node::setUserObject(Ref *pUserObject)
|
||||
{
|
||||
CC_SAFE_RETAIN(pUserObject);
|
||||
CC_SAFE_RELEASE(_userObject);
|
||||
|
@ -985,7 +985,7 @@ void Node::setScheduler(Scheduler* scheduler)
|
|||
|
||||
bool Node::isScheduled(SEL_SCHEDULE selector)
|
||||
{
|
||||
return _scheduler->isScheduledForTarget(selector, this);
|
||||
return _scheduler->isScheduled(this, schedule_selector_to_key(selector));
|
||||
}
|
||||
|
||||
void Node::scheduleUpdate()
|
||||
|
@ -995,19 +995,23 @@ void Node::scheduleUpdate()
|
|||
|
||||
void Node::scheduleUpdateWithPriority(int priority)
|
||||
{
|
||||
_scheduler->scheduleUpdateForTarget(this, priority, !_running);
|
||||
_scheduler->scheduleUpdate([this](float dt){
|
||||
this->update(dt);
|
||||
}, this, priority, !_running);
|
||||
}
|
||||
|
||||
void Node::scheduleUpdateWithPriorityLua(int nHandler, int priority)
|
||||
{
|
||||
unscheduleUpdate();
|
||||
_updateScriptHandler = nHandler;
|
||||
_scheduler->scheduleUpdateForTarget(this, priority, !_running);
|
||||
_scheduler->scheduleUpdate([this](float dt){
|
||||
this->update(dt);
|
||||
}, this, priority, !_running);
|
||||
}
|
||||
|
||||
void Node::unscheduleUpdate()
|
||||
{
|
||||
_scheduler->unscheduleUpdateForTarget(this);
|
||||
_scheduler->unscheduleUpdate(this);
|
||||
if (_updateScriptHandler)
|
||||
{
|
||||
ScriptEngineManager::getInstance()->getScriptEngine()->removeScriptHandler(_updateScriptHandler);
|
||||
|
@ -1030,7 +1034,9 @@ void Node::schedule(SEL_SCHEDULE selector, float interval, unsigned int repeat,
|
|||
CCASSERT( selector, "Argument must be non-nil");
|
||||
CCASSERT( interval >=0, "Argument must be positive");
|
||||
|
||||
_scheduler->scheduleSelector(selector, this, interval , repeat, delay, !_running);
|
||||
_scheduler->schedule([=](float dt){
|
||||
(this->*selector)(dt);
|
||||
}, this, schedule_selector_to_key(selector), interval , repeat, delay, !_running);
|
||||
}
|
||||
|
||||
void Node::scheduleOnce(SEL_SCHEDULE selector, float delay)
|
||||
|
@ -1040,11 +1046,11 @@ void Node::scheduleOnce(SEL_SCHEDULE selector, float delay)
|
|||
|
||||
void Node::unschedule(SEL_SCHEDULE selector)
|
||||
{
|
||||
// explicit nil handling
|
||||
if (selector == 0)
|
||||
// explicit null handling
|
||||
if (selector == nullptr)
|
||||
return;
|
||||
|
||||
_scheduler->unscheduleSelector(selector, this);
|
||||
|
||||
_scheduler->unschedule(this, schedule_selector_to_key(selector));
|
||||
}
|
||||
|
||||
void Node::unscheduleAllSelectors()
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __PLATFORM_CCNODE_H__
|
||||
#define __PLATFORM_CCNODE_H__
|
||||
#ifndef __CCNODE_H__
|
||||
#define __CCNODE_H__
|
||||
|
||||
#include "ccMacros.h"
|
||||
#include "CCAffineTransform.h"
|
||||
|
@ -126,7 +126,7 @@ class EventListener;
|
|||
|
||||
*/
|
||||
|
||||
class CC_DLL Node : public Object
|
||||
class CC_DLL Node : public Ref
|
||||
{
|
||||
public:
|
||||
/// Default tag used for all the nodes
|
||||
|
@ -808,12 +808,12 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual Object* getUserObject() { return _userObject; }
|
||||
virtual Ref* getUserObject() { return _userObject; }
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual const Object* getUserObject() const { return _userObject; }
|
||||
virtual const Ref* getUserObject() const { return _userObject; }
|
||||
|
||||
/**
|
||||
* Returns a user assigned Object
|
||||
|
@ -825,7 +825,7 @@ public:
|
|||
*
|
||||
* @param userObject A user assigned Object
|
||||
*/
|
||||
virtual void setUserObject(Object *userObject);
|
||||
virtual void setUserObject(Ref *userObject);
|
||||
|
||||
/// @} end of Tag & User Data
|
||||
|
||||
|
@ -1469,7 +1469,7 @@ protected:
|
|||
int _tag; ///< a tag. Can be any number you assigned just to identify this node
|
||||
|
||||
void *_userData; ///< A user assingned void pointer, Can be point to any cpp object
|
||||
Object *_userObject; ///< A user assigned Object
|
||||
Ref *_userObject; ///< A user assigned Object
|
||||
|
||||
GLProgram *_shaderProgram; ///< OpenGL shader
|
||||
|
||||
|
@ -1558,4 +1558,4 @@ private:
|
|||
|
||||
NS_CC_END
|
||||
|
||||
#endif // __PLATFORM_CCNODE_H__
|
||||
#endif // __CCNODE_H__
|
||||
|
|
|
@ -76,9 +76,9 @@ void __NotificationCenter::purgeNotificationCenter(void)
|
|||
//
|
||||
// internal functions
|
||||
//
|
||||
bool __NotificationCenter::observerExisted(Object *target, const std::string& name, Object *sender)
|
||||
bool __NotificationCenter::observerExisted(Ref *target, const std::string& name, Ref *sender)
|
||||
{
|
||||
Object* obj = nullptr;
|
||||
Ref* obj = nullptr;
|
||||
CCARRAY_FOREACH(_observers, obj)
|
||||
{
|
||||
NotificationObserver* observer = (NotificationObserver*) obj;
|
||||
|
@ -94,10 +94,10 @@ bool __NotificationCenter::observerExisted(Object *target, const std::string& na
|
|||
//
|
||||
// observer functions
|
||||
//
|
||||
void __NotificationCenter::addObserver(Object *target,
|
||||
void __NotificationCenter::addObserver(Ref *target,
|
||||
SEL_CallFuncO selector,
|
||||
const std::string& name,
|
||||
Object *sender)
|
||||
Ref *sender)
|
||||
{
|
||||
if (this->observerExisted(target, name, sender))
|
||||
return;
|
||||
|
@ -110,9 +110,9 @@ void __NotificationCenter::addObserver(Object *target,
|
|||
_observers->addObject(observer);
|
||||
}
|
||||
|
||||
void __NotificationCenter::removeObserver(Object *target, const std::string& name)
|
||||
void __NotificationCenter::removeObserver(Ref *target, const std::string& name)
|
||||
{
|
||||
Object* obj = nullptr;
|
||||
Ref* obj = nullptr;
|
||||
CCARRAY_FOREACH(_observers, obj)
|
||||
{
|
||||
NotificationObserver* observer = static_cast<NotificationObserver*>(obj);
|
||||
|
@ -127,9 +127,9 @@ void __NotificationCenter::removeObserver(Object *target, const std::string& nam
|
|||
}
|
||||
}
|
||||
|
||||
int __NotificationCenter::removeAllObservers(Object *target)
|
||||
int __NotificationCenter::removeAllObservers(Ref *target)
|
||||
{
|
||||
Object *obj = nullptr;
|
||||
Ref *obj = nullptr;
|
||||
__Array *toRemove = __Array::create();
|
||||
|
||||
CCARRAY_FOREACH(_observers, obj)
|
||||
|
@ -148,7 +148,7 @@ int __NotificationCenter::removeAllObservers(Object *target)
|
|||
return static_cast<int>(toRemove->count());
|
||||
}
|
||||
|
||||
void __NotificationCenter::registerScriptObserver( Object *target, int handler,const std::string& name)
|
||||
void __NotificationCenter::registerScriptObserver(Ref *target, int handler,const std::string& name)
|
||||
{
|
||||
|
||||
if (this->observerExisted(target, name, nullptr))
|
||||
|
@ -163,9 +163,9 @@ void __NotificationCenter::registerScriptObserver( Object *target, int handler,c
|
|||
_observers->addObject(observer);
|
||||
}
|
||||
|
||||
void __NotificationCenter::unregisterScriptObserver(Object *target,const std::string& name)
|
||||
void __NotificationCenter::unregisterScriptObserver(Ref *target,const std::string& name)
|
||||
{
|
||||
Object* obj = nullptr;
|
||||
Ref* obj = nullptr;
|
||||
CCARRAY_FOREACH(_observers, obj)
|
||||
{
|
||||
NotificationObserver* observer = static_cast<NotificationObserver*>(obj);
|
||||
|
@ -179,11 +179,11 @@ void __NotificationCenter::unregisterScriptObserver(Object *target,const std::st
|
|||
}
|
||||
}
|
||||
|
||||
void __NotificationCenter::postNotification(const std::string& name, Object *sender)
|
||||
void __NotificationCenter::postNotification(const std::string& name, Ref *sender)
|
||||
{
|
||||
__Array* ObserversCopy = __Array::createWithCapacity(_observers->count());
|
||||
ObserversCopy->addObjectsFromArray(_observers);
|
||||
Object* obj = nullptr;
|
||||
Ref* obj = nullptr;
|
||||
CCARRAY_FOREACH(ObserversCopy, obj)
|
||||
{
|
||||
NotificationObserver* observer = static_cast<NotificationObserver*>(obj);
|
||||
|
@ -212,7 +212,7 @@ int __NotificationCenter::getObserverHandlerByName(const std::string& name)
|
|||
return 0;
|
||||
}
|
||||
|
||||
Object* obj = nullptr;
|
||||
Ref* obj = nullptr;
|
||||
CCARRAY_FOREACH(_observers, obj)
|
||||
{
|
||||
NotificationObserver* observer = static_cast<NotificationObserver*>(obj);
|
||||
|
@ -234,10 +234,10 @@ int __NotificationCenter::getObserverHandlerByName(const std::string& name)
|
|||
/// NotificationObserver
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
NotificationObserver::NotificationObserver(Object *target,
|
||||
NotificationObserver::NotificationObserver(Ref *target,
|
||||
SEL_CallFuncO selector,
|
||||
const std::string& name,
|
||||
Object *sender)
|
||||
Ref *sender)
|
||||
{
|
||||
_target = target;
|
||||
_selector = selector;
|
||||
|
@ -252,7 +252,7 @@ NotificationObserver::~NotificationObserver()
|
|||
|
||||
}
|
||||
|
||||
void NotificationObserver::performSelector(Object *sender)
|
||||
void NotificationObserver::performSelector(Ref *sender)
|
||||
{
|
||||
if (_target)
|
||||
{
|
||||
|
@ -264,7 +264,7 @@ void NotificationObserver::performSelector(Object *sender)
|
|||
}
|
||||
}
|
||||
|
||||
Object *NotificationObserver::getTarget() const
|
||||
Ref *NotificationObserver::getTarget() const
|
||||
{
|
||||
return _target;
|
||||
}
|
||||
|
@ -279,7 +279,7 @@ const std::string& NotificationObserver::getName() const
|
|||
return _name;
|
||||
}
|
||||
|
||||
Object* NotificationObserver::getSender() const
|
||||
Ref* NotificationObserver::getSender() const
|
||||
{
|
||||
return _sender;
|
||||
}
|
||||
|
|
|
@ -27,13 +27,14 @@ THE SOFTWARE.
|
|||
#ifndef __CCNOTIFICATIONCENTER_H__
|
||||
#define __CCNOTIFICATIONCENTER_H__
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCArray.h"
|
||||
#include "ccTypes.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class ScriptHandlerMgr;
|
||||
class CC_DLL __NotificationCenter : public Object
|
||||
class CC_DLL __NotificationCenter : public Ref
|
||||
{
|
||||
friend class ScriptHandlerMgr;
|
||||
public:
|
||||
|
@ -67,31 +68,31 @@ public:
|
|||
* @param name The name of this notification.
|
||||
* @param sender The object whose notifications the target wants to receive. Only notifications sent by this sender are delivered to the target. nullptr means that the sender is not used to decide whether to deliver the notification to target.
|
||||
*/
|
||||
void addObserver(Object *target,
|
||||
void addObserver(Ref *target,
|
||||
SEL_CallFuncO selector,
|
||||
const std::string& name,
|
||||
Object *sender);
|
||||
Ref *sender);
|
||||
|
||||
/** @brief Removes the observer by the specified target and name.
|
||||
* @param target The target of this notification.
|
||||
* @param name The name of this notification.
|
||||
*/
|
||||
void removeObserver(Object *target,const std::string& name);
|
||||
void removeObserver(Ref *target,const std::string& name);
|
||||
|
||||
/** @brief Removes all notifications registered by this target
|
||||
* @param target The target of this notification.
|
||||
* @returns the number of observers removed
|
||||
*/
|
||||
int removeAllObservers(Object *target);
|
||||
int removeAllObservers(Ref *target);
|
||||
|
||||
/** @brief Registers one hander for script binding.
|
||||
* @note Only supports Lua Binding now.
|
||||
* @param handler The lua handler.
|
||||
*/
|
||||
void registerScriptObserver(Object *target,int handler,const std::string& name);
|
||||
void registerScriptObserver(Ref *target,int handler,const std::string& name);
|
||||
|
||||
/** Unregisters script observer */
|
||||
void unregisterScriptObserver(Object *target,const std::string& name);
|
||||
void unregisterScriptObserver(Ref *target,const std::string& name);
|
||||
|
||||
/** @brief Posts one notification event by name.
|
||||
* @param name The name of this notification.
|
||||
|
@ -102,7 +103,7 @@ public:
|
|||
* @param name The name of this notification.
|
||||
* @param sender The object posting the notification. Can be nullptr
|
||||
*/
|
||||
void postNotification(const std::string& name, Object *sender);
|
||||
void postNotification(const std::string& name, Ref *sender);
|
||||
|
||||
/** @brief Gets script handler.
|
||||
* @note Only supports Lua Binding now.
|
||||
|
@ -119,7 +120,7 @@ private:
|
|||
// internal functions
|
||||
|
||||
// Check whether the observer exists by the specified target and name.
|
||||
bool observerExisted(Object *target,const std::string& name, Object *sender);
|
||||
bool observerExisted(Ref *target,const std::string& name, Ref *sender);
|
||||
|
||||
// variables
|
||||
//
|
||||
|
@ -127,7 +128,7 @@ private:
|
|||
int _scriptHandler;
|
||||
};
|
||||
|
||||
class CC_DLL NotificationObserver : public Object
|
||||
class CC_DLL NotificationObserver : public Ref
|
||||
{
|
||||
public:
|
||||
/** @brief NotificationObserver constructor
|
||||
|
@ -138,10 +139,10 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
NotificationObserver(Object *target,
|
||||
NotificationObserver(Ref *target,
|
||||
SEL_CallFuncO selector,
|
||||
const std::string& name,
|
||||
Object *sender);
|
||||
Ref *sender);
|
||||
|
||||
/** NotificationObserver destructor function
|
||||
* @js NA
|
||||
|
@ -153,14 +154,14 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
void performSelector(Object *sender);
|
||||
void performSelector(Ref *sender);
|
||||
|
||||
// Getters / Setters
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
Object* getTarget() const;
|
||||
Ref* getTarget() const;
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
@ -175,7 +176,7 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
Object* getSender() const;
|
||||
Ref* getSender() const;
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
@ -188,10 +189,10 @@ public:
|
|||
void setHandler(int handler);
|
||||
|
||||
private:
|
||||
Object* _target;
|
||||
Ref* _target;
|
||||
SEL_CallFuncO _selector;
|
||||
std::string _name;
|
||||
Object* _sender;
|
||||
Ref* _sender;
|
||||
int _handler;
|
||||
};
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ THE SOFTWARE.
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PointObject : Object
|
||||
class PointObject : public Ref
|
||||
{
|
||||
public:
|
||||
static PointObject * create(Point ratio, Point offset)
|
||||
|
@ -98,7 +98,7 @@ void ParallaxNode::addChild(Node *child, int z, const Point& ratio, const Point&
|
|||
CCASSERT( child != nullptr, "Argument must be non-nil");
|
||||
PointObject *obj = PointObject::create(ratio, offset);
|
||||
obj->setChild(child);
|
||||
ccArrayAppendObjectWithResize(_parallaxArray, (Object*)obj);
|
||||
ccArrayAppendObjectWithResize(_parallaxArray, (Ref*)obj);
|
||||
|
||||
Point pos = this->absolutePosition();
|
||||
pos.x = -pos.x + pos.x * ratio.x + offset.x;
|
||||
|
@ -107,12 +107,13 @@ void ParallaxNode::addChild(Node *child, int z, const Point& ratio, const Point&
|
|||
|
||||
Node::addChild(child, z, child->getTag());
|
||||
}
|
||||
|
||||
void ParallaxNode::removeChild(Node* child, bool cleanup)
|
||||
{
|
||||
for( int i=0;i < _parallaxArray->num;i++)
|
||||
{
|
||||
PointObject *point = (PointObject*)_parallaxArray->arr[i];
|
||||
if( point->getChild()->isEqual(child))
|
||||
if (point->getChild() == child)
|
||||
{
|
||||
ccArrayRemoveObjectAtIndex(_parallaxArray, i, true);
|
||||
break;
|
||||
|
@ -120,11 +121,13 @@ void ParallaxNode::removeChild(Node* child, bool cleanup)
|
|||
}
|
||||
Node::removeChild(child, cleanup);
|
||||
}
|
||||
|
||||
void ParallaxNode::removeAllChildrenWithCleanup(bool cleanup)
|
||||
{
|
||||
ccArrayRemoveAllObjects(_parallaxArray);
|
||||
Node::removeAllChildrenWithCleanup(cleanup);
|
||||
}
|
||||
|
||||
Point ParallaxNode::absolutePosition()
|
||||
{
|
||||
Point ret = _position;
|
||||
|
|
|
@ -29,7 +29,7 @@ THE SOFTWARE.
|
|||
#include <string>
|
||||
#include <chrono>
|
||||
#include "ccConfig.h"
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCMap.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -47,7 +47,7 @@ class ProfilingTimer;
|
|||
To use it, enable set the CC_ENABLE_PROFILERS=1 in the ccConfig.h file
|
||||
*/
|
||||
|
||||
class CC_DLL Profiler : public Object
|
||||
class CC_DLL Profiler : public Ref
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -98,7 +98,7 @@ public:
|
|||
Map<std::string, ProfilingTimer*> _activeTimers;
|
||||
};
|
||||
|
||||
class ProfilingTimer : public Object
|
||||
class ProfilingTimer : public Ref
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -37,13 +37,24 @@ using namespace std;
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
long schedule_selector_to_key(SEL_SCHEDULE selector)
|
||||
{
|
||||
static union{
|
||||
SEL_SCHEDULE func;
|
||||
long key;
|
||||
};
|
||||
func = selector;
|
||||
return key;
|
||||
}
|
||||
|
||||
// data structures
|
||||
|
||||
// A list double-linked list used for "updates with priority"
|
||||
typedef struct _listEntry
|
||||
{
|
||||
struct _listEntry *prev, *next;
|
||||
Object *target; // not retained (retained by hashUpdateEntry)
|
||||
Ref *target; // not retained (retained by hashUpdateEntry)
|
||||
ccSchedulerFunc callback;
|
||||
int priority;
|
||||
bool paused;
|
||||
bool markedForDeletion; // selector will no longer be called and entry will be removed at end of the next tick
|
||||
|
@ -53,7 +64,8 @@ typedef struct _hashUpdateEntry
|
|||
{
|
||||
tListEntry **list; // Which list does it belong to ?
|
||||
tListEntry *entry; // entry in the list
|
||||
Object *target; // hash key (retained)
|
||||
Ref *target; // hash key (retained)
|
||||
ccSchedulerFunc callback;
|
||||
UT_hash_handle hh;
|
||||
} tHashUpdateEntry;
|
||||
|
||||
|
@ -61,9 +73,9 @@ typedef struct _hashUpdateEntry
|
|||
typedef struct _hashSelectorEntry
|
||||
{
|
||||
ccArray *timers;
|
||||
Object *target; // hash key (retained)
|
||||
int timerIndex;
|
||||
Timer *currentTimer;
|
||||
Ref *target; // hash key (retained)
|
||||
int timerIndex;
|
||||
Timer *currentTimer;
|
||||
bool currentTimerSalvaged;
|
||||
bool paused;
|
||||
UT_hash_handle hh;
|
||||
|
@ -80,26 +92,17 @@ Timer::Timer()
|
|||
, _repeat(0)
|
||||
, _delay(0.0f)
|
||||
, _interval(0.0f)
|
||||
, _selector(nullptr)
|
||||
, _callback(nullptr)
|
||||
, _key(0)
|
||||
, _scriptHandler(0)
|
||||
{
|
||||
}
|
||||
|
||||
Timer* Timer::create(Object *target, SEL_SCHEDULE selector)
|
||||
Timer* Timer::create(const ccSchedulerFunc& callback, Ref *target, long key, float seconds/* = 0 */)
|
||||
{
|
||||
Timer *timer = new Timer();
|
||||
|
||||
timer->initWithTarget(target, selector, 0.0f, kRepeatForever, 0.0f);
|
||||
timer->autorelease();
|
||||
|
||||
return timer;
|
||||
}
|
||||
|
||||
Timer* Timer::create(Object *target, SEL_SCHEDULE selector, float seconds)
|
||||
{
|
||||
Timer *timer = new Timer();
|
||||
|
||||
timer->initWithTarget(target, selector, seconds, kRepeatForever, 0.0f);
|
||||
timer->initWithTarget(callback, target, key, seconds, kRepeatForever, 0.0f);
|
||||
timer->autorelease();
|
||||
|
||||
return timer;
|
||||
|
@ -124,15 +127,11 @@ bool Timer::initWithScriptHandler(int handler, float seconds)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Timer::initWithTarget(Object *target, SEL_SCHEDULE selector)
|
||||
{
|
||||
return initWithTarget(target, selector, 0, kRepeatForever, 0.0f);
|
||||
}
|
||||
|
||||
bool Timer::initWithTarget(Object *target, SEL_SCHEDULE selector, float seconds, unsigned int repeat, float delay)
|
||||
bool Timer::initWithTarget(const ccSchedulerFunc& callback, Ref *target, long key, float seconds, unsigned int repeat, float delay)
|
||||
{
|
||||
_target = target;
|
||||
_selector = selector;
|
||||
_callback = callback;
|
||||
_key = key;
|
||||
_elapsed = -1;
|
||||
_interval = seconds;
|
||||
_delay = delay;
|
||||
|
@ -156,9 +155,9 @@ void Timer::update(float dt)
|
|||
_elapsed += dt;
|
||||
if (_elapsed >= _interval)
|
||||
{
|
||||
if (_target && _selector)
|
||||
if (_target && _key != 0 && _callback)
|
||||
{
|
||||
(_target->*_selector)(_elapsed);
|
||||
_callback(_elapsed);
|
||||
}
|
||||
|
||||
if (0 != _scriptHandler)
|
||||
|
@ -177,9 +176,9 @@ void Timer::update(float dt)
|
|||
{
|
||||
if( _elapsed >= _delay )
|
||||
{
|
||||
if (_target && _selector)
|
||||
if (_target && _key != 0 && _callback)
|
||||
{
|
||||
(_target->*_selector)(_elapsed);
|
||||
_callback(_elapsed);
|
||||
}
|
||||
|
||||
if (0 != _scriptHandler)
|
||||
|
@ -198,9 +197,9 @@ void Timer::update(float dt)
|
|||
{
|
||||
if (_elapsed >= _interval)
|
||||
{
|
||||
if (_target && _selector)
|
||||
if (_target && _key != 0 && _callback)
|
||||
{
|
||||
(_target->*_selector)(_elapsed);
|
||||
_callback(_elapsed);
|
||||
}
|
||||
|
||||
if (0 != _scriptHandler)
|
||||
|
@ -218,27 +217,12 @@ void Timer::update(float dt)
|
|||
|
||||
if (!_runForever && _timesExecuted > _repeat)
|
||||
{ //unschedule timer
|
||||
Director::getInstance()->getScheduler()->unscheduleSelector(_selector, _target);
|
||||
Director::getInstance()->getScheduler()->unschedule(_target, _key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float Timer::getInterval() const
|
||||
{
|
||||
return _interval;
|
||||
}
|
||||
|
||||
void Timer::setInterval(float interval)
|
||||
{
|
||||
_interval = interval;
|
||||
}
|
||||
|
||||
SEL_SCHEDULE Timer::getSelector() const
|
||||
{
|
||||
return _selector;
|
||||
}
|
||||
|
||||
// implementation of Scheduler
|
||||
|
||||
// Priority level reserved for system services.
|
||||
|
@ -271,7 +255,7 @@ Scheduler::~Scheduler(void)
|
|||
void Scheduler::removeHashElement(_hashSelectorEntry *element)
|
||||
{
|
||||
|
||||
cocos2d::Object *target = element->target;
|
||||
Ref *target = element->target;
|
||||
|
||||
ccArrayFree(element->timers);
|
||||
HASH_DEL(_hashForTimers, element);
|
||||
|
@ -284,15 +268,15 @@ void Scheduler::removeHashElement(_hashSelectorEntry *element)
|
|||
|
||||
}
|
||||
|
||||
void Scheduler::scheduleSelector(SEL_SCHEDULE selector, Object *target, float interval, bool paused)
|
||||
void Scheduler::schedule(const ccSchedulerFunc& callback, Ref *target, long key, float interval, bool paused)
|
||||
{
|
||||
this->scheduleSelector(selector, target, interval, kRepeatForever, 0.0f, paused);
|
||||
this->schedule(callback, target, key, interval, kRepeatForever, 0.0f, paused);
|
||||
}
|
||||
|
||||
void Scheduler::scheduleSelector(SEL_SCHEDULE selector, Object *target, float interval, unsigned int repeat, float delay, bool paused)
|
||||
void Scheduler::schedule(const ccSchedulerFunc& callback, Ref *target, long key, float interval, unsigned int repeat, float delay, bool paused)
|
||||
{
|
||||
CCASSERT(selector, "Argument selector must be non-nullptr");
|
||||
CCASSERT(target, "Argument target must be non-nullptr");
|
||||
CCASSERT(key != 0, "key should not be empty!");
|
||||
|
||||
tHashTimerEntry *element = nullptr;
|
||||
HASH_FIND_PTR(_hashForTimers, &target, element);
|
||||
|
@ -325,7 +309,7 @@ void Scheduler::scheduleSelector(SEL_SCHEDULE selector, Object *target, float in
|
|||
{
|
||||
Timer *timer = (Timer*)element->timers->arr[i];
|
||||
|
||||
if (selector == timer->getSelector())
|
||||
if (key == timer->getKey())
|
||||
{
|
||||
CCLOG("CCScheduler#scheduleSelector. Selector already scheduled. Updating interval from: %.4f to %.4f", timer->getInterval(), interval);
|
||||
timer->setInterval(interval);
|
||||
|
@ -335,16 +319,16 @@ void Scheduler::scheduleSelector(SEL_SCHEDULE selector, Object *target, float in
|
|||
ccArrayEnsureExtraCapacity(element->timers, 1);
|
||||
}
|
||||
|
||||
Timer *pTimer = new Timer();
|
||||
pTimer->initWithTarget(target, selector, interval, repeat, delay);
|
||||
ccArrayAppendObject(element->timers, pTimer);
|
||||
pTimer->release();
|
||||
Timer *timer = new Timer();
|
||||
timer->initWithTarget(callback, target, key, interval, repeat, delay);
|
||||
ccArrayAppendObject(element->timers, timer);
|
||||
timer->release();
|
||||
}
|
||||
|
||||
void Scheduler::unscheduleSelector(SEL_SCHEDULE selector, Object *target)
|
||||
void Scheduler::unschedule(Ref *target, long key)
|
||||
{
|
||||
// explicity handle nil arguments when removing an object
|
||||
if (target == 0 || selector == 0)
|
||||
if (target == nullptr || key == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -361,7 +345,7 @@ void Scheduler::unscheduleSelector(SEL_SCHEDULE selector, Object *target)
|
|||
{
|
||||
Timer *timer = static_cast<Timer*>(element->timers->arr[i]);
|
||||
|
||||
if (selector == timer->getSelector())
|
||||
if (key == timer->getKey())
|
||||
{
|
||||
if (timer == element->currentTimer && (! element->currentTimerSalvaged))
|
||||
{
|
||||
|
@ -395,10 +379,11 @@ void Scheduler::unscheduleSelector(SEL_SCHEDULE selector, Object *target)
|
|||
}
|
||||
}
|
||||
|
||||
void Scheduler::priorityIn(tListEntry **list, Object *target, int priority, bool paused)
|
||||
void Scheduler::priorityIn(tListEntry **list, const ccSchedulerFunc& callback, Ref *target, int priority, bool paused)
|
||||
{
|
||||
tListEntry *listElement = (tListEntry *)malloc(sizeof(*listElement));
|
||||
tListEntry *listElement = new tListEntry();
|
||||
|
||||
listElement->callback = callback;
|
||||
listElement->target = target;
|
||||
listElement->priority = priority;
|
||||
listElement->paused = paused;
|
||||
|
@ -452,10 +437,11 @@ void Scheduler::priorityIn(tListEntry **list, Object *target, int priority, bool
|
|||
HASH_ADD_PTR(_hashForUpdates, target, hashElement);
|
||||
}
|
||||
|
||||
void Scheduler::appendIn(_listEntry **list, Object *target, bool paused)
|
||||
void Scheduler::appendIn(_listEntry **list, const ccSchedulerFunc& callback, Ref *target, bool paused)
|
||||
{
|
||||
tListEntry *listElement = (tListEntry *)malloc(sizeof(*listElement));
|
||||
tListEntry *listElement = new tListEntry();
|
||||
|
||||
listElement->callback = callback;
|
||||
listElement->target = target;
|
||||
listElement->paused = paused;
|
||||
listElement->markedForDeletion = false;
|
||||
|
@ -471,9 +457,8 @@ void Scheduler::appendIn(_listEntry **list, Object *target, bool paused)
|
|||
HASH_ADD_PTR(_hashForUpdates, target, hashElement);
|
||||
}
|
||||
|
||||
void Scheduler::scheduleUpdateForTarget(Object *target, int priority, bool paused)
|
||||
void Scheduler::scheduleUpdate(const ccSchedulerFunc& callback, Ref *target, int priority, bool paused)
|
||||
{
|
||||
|
||||
tHashUpdateEntry *hashElement = nullptr;
|
||||
HASH_FIND_PTR(_hashForUpdates, &target, hashElement);
|
||||
if (hashElement)
|
||||
|
@ -491,22 +476,22 @@ void Scheduler::scheduleUpdateForTarget(Object *target, int priority, bool pause
|
|||
// is an special list for updates with priority 0
|
||||
if (priority == 0)
|
||||
{
|
||||
appendIn(&_updates0List, target, paused);
|
||||
appendIn(&_updates0List, callback, target, paused);
|
||||
}
|
||||
else if (priority < 0)
|
||||
{
|
||||
priorityIn(&_updatesNegList, target, priority, paused);
|
||||
priorityIn(&_updatesNegList, callback, target, priority, paused);
|
||||
}
|
||||
else
|
||||
{
|
||||
// priority > 0
|
||||
priorityIn(&_updatesPosList, target, priority, paused);
|
||||
priorityIn(&_updatesPosList, callback, target, priority, paused);
|
||||
}
|
||||
}
|
||||
|
||||
bool Scheduler::isScheduledForTarget(SEL_SCHEDULE selector, Object *target)
|
||||
bool Scheduler::isScheduled(Ref *target, long key)
|
||||
{
|
||||
CCASSERT(selector, "Argument selector must be non-nullptr");
|
||||
CCASSERT(key != 0, "Argument key must be empty");
|
||||
CCASSERT(target, "Argument target must be non-nullptr");
|
||||
|
||||
tHashTimerEntry *element = nullptr;
|
||||
|
@ -526,7 +511,7 @@ bool Scheduler::isScheduledForTarget(SEL_SCHEDULE selector, Object *target)
|
|||
{
|
||||
Timer *timer = (Timer*)element->timers->arr[i];
|
||||
|
||||
if (selector == timer->getSelector())
|
||||
if (key == timer->getKey())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -547,10 +532,10 @@ void Scheduler::removeUpdateFromHash(struct _listEntry *entry)
|
|||
{
|
||||
// list entry
|
||||
DL_DELETE(*element->list, element->entry);
|
||||
free(element->entry);
|
||||
CC_SAFE_DELETE(element->entry);
|
||||
|
||||
// hash entry
|
||||
Object* target = element->target;
|
||||
Ref* target = element->target;
|
||||
HASH_DEL(_hashForUpdates, element);
|
||||
free(element);
|
||||
|
||||
|
@ -560,7 +545,7 @@ void Scheduler::removeUpdateFromHash(struct _listEntry *entry)
|
|||
}
|
||||
}
|
||||
|
||||
void Scheduler::unscheduleUpdateForTarget(const Object *target)
|
||||
void Scheduler::unscheduleUpdate(Ref* target)
|
||||
{
|
||||
if (target == nullptr)
|
||||
{
|
||||
|
@ -609,7 +594,7 @@ void Scheduler::unscheduleAllWithMinPriority(int minPriority)
|
|||
{
|
||||
if(entry->priority >= minPriority)
|
||||
{
|
||||
unscheduleUpdateForTarget(entry->target);
|
||||
unscheduleUpdate(entry->target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -618,7 +603,7 @@ void Scheduler::unscheduleAllWithMinPriority(int minPriority)
|
|||
{
|
||||
DL_FOREACH_SAFE(_updates0List, entry, tmp)
|
||||
{
|
||||
unscheduleUpdateForTarget(entry->target);
|
||||
unscheduleUpdate(entry->target);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -626,14 +611,14 @@ void Scheduler::unscheduleAllWithMinPriority(int minPriority)
|
|||
{
|
||||
if(entry->priority >= minPriority)
|
||||
{
|
||||
unscheduleUpdateForTarget(entry->target);
|
||||
unscheduleUpdate(entry->target);
|
||||
}
|
||||
}
|
||||
|
||||
_scriptHandlerEntries.clear();
|
||||
}
|
||||
|
||||
void Scheduler::unscheduleAllForTarget(Object *target)
|
||||
void Scheduler::unscheduleAllForTarget(Ref *target)
|
||||
{
|
||||
// explicit nullptr handling
|
||||
if (target == nullptr)
|
||||
|
@ -666,7 +651,7 @@ void Scheduler::unscheduleAllForTarget(Object *target)
|
|||
}
|
||||
|
||||
// update selector
|
||||
unscheduleUpdateForTarget(target);
|
||||
unscheduleUpdate(target);
|
||||
}
|
||||
|
||||
unsigned int Scheduler::scheduleScriptFunc(unsigned int handler, float interval, bool paused)
|
||||
|
@ -689,7 +674,7 @@ void Scheduler::unscheduleScriptEntry(unsigned int scheduleScriptEntryID)
|
|||
}
|
||||
}
|
||||
|
||||
void Scheduler::resumeTarget(Object *target)
|
||||
void Scheduler::resumeTarget(Ref *target)
|
||||
{
|
||||
CCASSERT(target != nullptr, "");
|
||||
|
||||
|
@ -711,7 +696,7 @@ void Scheduler::resumeTarget(Object *target)
|
|||
}
|
||||
}
|
||||
|
||||
void Scheduler::pauseTarget(Object *target)
|
||||
void Scheduler::pauseTarget(Ref *target)
|
||||
{
|
||||
CCASSERT(target != nullptr, "");
|
||||
|
||||
|
@ -733,7 +718,7 @@ void Scheduler::pauseTarget(Object *target)
|
|||
}
|
||||
}
|
||||
|
||||
bool Scheduler::isTargetPaused(Object *target)
|
||||
bool Scheduler::isTargetPaused(Ref *target)
|
||||
{
|
||||
CCASSERT( target != nullptr, "target must be non nil" );
|
||||
|
||||
|
@ -756,14 +741,14 @@ bool Scheduler::isTargetPaused(Object *target)
|
|||
return false; // should never get here
|
||||
}
|
||||
|
||||
Vector<Object*> Scheduler::pauseAllTargets()
|
||||
Vector<Ref*> Scheduler::pauseAllTargets()
|
||||
{
|
||||
return pauseAllTargetsWithMinPriority(PRIORITY_SYSTEM);
|
||||
}
|
||||
|
||||
Vector<Object*> Scheduler::pauseAllTargetsWithMinPriority(int minPriority)
|
||||
Vector<Ref*> Scheduler::pauseAllTargetsWithMinPriority(int minPriority)
|
||||
{
|
||||
Vector<Object*> idsWithSelectors(50);
|
||||
Vector<Ref*> idsWithSelectors(50);
|
||||
|
||||
// Custom Selectors
|
||||
for(tHashTimerEntry *element = _hashForTimers; element != nullptr;
|
||||
|
@ -808,7 +793,7 @@ Vector<Object*> Scheduler::pauseAllTargetsWithMinPriority(int minPriority)
|
|||
return idsWithSelectors;
|
||||
}
|
||||
|
||||
void Scheduler::resumeTargets(const Vector<Object*>& targetsToResume)
|
||||
void Scheduler::resumeTargets(const Vector<Ref*>& targetsToResume)
|
||||
{
|
||||
for(const auto &obj : targetsToResume) {
|
||||
this->resumeTarget(obj);
|
||||
|
@ -846,7 +831,7 @@ void Scheduler::update(float dt)
|
|||
{
|
||||
if ((! entry->paused) && (! entry->markedForDeletion))
|
||||
{
|
||||
entry->target->update(dt);
|
||||
entry->callback(dt);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -855,7 +840,7 @@ void Scheduler::update(float dt)
|
|||
{
|
||||
if ((! entry->paused) && (! entry->markedForDeletion))
|
||||
{
|
||||
entry->target->update(dt);
|
||||
entry->callback(dt);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -864,7 +849,7 @@ void Scheduler::update(float dt)
|
|||
{
|
||||
if ((! entry->paused) && (! entry->markedForDeletion))
|
||||
{
|
||||
entry->target->update(dt);
|
||||
entry->callback(dt);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -975,5 +960,34 @@ void Scheduler::update(float dt)
|
|||
}
|
||||
}
|
||||
|
||||
//OLD METHODS:
|
||||
void Scheduler::scheduleSelector(SEL_SCHEDULE selector, Ref *target, float interval, unsigned int repeat, float delay, bool paused)
|
||||
{
|
||||
this->schedule([=](float dt){
|
||||
(target->*selector)(dt);
|
||||
}, target, schedule_selector_to_key(selector), interval , repeat, delay, paused);
|
||||
}
|
||||
|
||||
void Scheduler::scheduleSelector(SEL_SCHEDULE selector, Ref *target, float interval, bool paused)
|
||||
{
|
||||
this->schedule([=](float dt){
|
||||
(target->*selector)(dt);
|
||||
}, target, schedule_selector_to_key(selector), interval, paused);
|
||||
}
|
||||
|
||||
void Scheduler::scheduleUpdateForTarget(Ref *target, int priority, bool paused)
|
||||
{
|
||||
CCASSERT(false, "Please use scheduleUpdate instead.");
|
||||
}
|
||||
|
||||
bool Scheduler::isScheduledForTarget(SEL_SCHEDULE selector, Ref *target)
|
||||
{
|
||||
return this->isScheduled(target, schedule_selector_to_key(selector));
|
||||
}
|
||||
|
||||
void Scheduler::unscheduleSelector(SEL_SCHEDULE selector, Ref *target)
|
||||
{
|
||||
this->unschedule(target, schedule_selector_to_key(selector));
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -28,13 +28,13 @@ THE SOFTWARE.
|
|||
#ifndef __CCSCHEDULER_H__
|
||||
#define __CCSCHEDULER_H__
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCVector.h"
|
||||
#include "uthash.h"
|
||||
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
|
||||
#include "CCRef.h"
|
||||
#include "CCVector.h"
|
||||
#include "uthash.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
/**
|
||||
|
@ -42,54 +42,50 @@ NS_CC_BEGIN
|
|||
* @{
|
||||
*/
|
||||
|
||||
long schedule_selector_to_key(SEL_SCHEDULE selector);
|
||||
|
||||
typedef std::function<void(float)> ccSchedulerFunc;
|
||||
//
|
||||
// Timer
|
||||
//
|
||||
/** @brief Light-weight timer */
|
||||
//
|
||||
class CC_DLL Timer : public Object
|
||||
class CC_DLL Timer : public Ref
|
||||
{
|
||||
public:
|
||||
/** Allocates a timer with a target and a selector. */
|
||||
static Timer* create(Object *target, SEL_SCHEDULE selector);
|
||||
/** Allocates a timer with a target, a selector and an interval in seconds. */
|
||||
static Timer* create(Object *target, SEL_SCHEDULE selector, float seconds);
|
||||
static Timer* create(const ccSchedulerFunc& callback, Ref *target, long key, float seconds = 0.0f);
|
||||
/** Allocates a timer with a script callback function and an interval in seconds.
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
static Timer* createWithScriptHandler(int handler, float seconds);
|
||||
|
||||
CC_DEPRECATED_ATTRIBUTE static Timer* timerWithTarget(Object *target, SEL_SCHEDULE selector) { return Timer::create(target, selector); }
|
||||
CC_DEPRECATED_ATTRIBUTE static Timer* timerWithTarget(Object *target, SEL_SCHEDULE selector, float seconds) { return Timer::create(target, selector, seconds); }
|
||||
CC_DEPRECATED_ATTRIBUTE static Timer* timerWithScriptHandler(int handler, float seconds) { return Timer::createWithScriptHandler(handler, seconds); }
|
||||
|
||||
Timer(void);
|
||||
|
||||
/** Initializes a timer with a target and a selector. */
|
||||
bool initWithTarget(Object *target, SEL_SCHEDULE selector);
|
||||
/** Initializes a timer with a target, a selector and an interval in seconds, repeat in number of times to repeat, delay in seconds. */
|
||||
bool initWithTarget(Object *target, SEL_SCHEDULE selector, float seconds, unsigned int repeat, float delay);
|
||||
bool initWithTarget(const ccSchedulerFunc& callback, Ref *target, long key, float seconds, unsigned int repeat, float delay);
|
||||
/** Initializes a timer with a script callback function and an interval in seconds. */
|
||||
bool initWithScriptHandler(int handler, float seconds);
|
||||
|
||||
/** get interval in seconds */
|
||||
float getInterval() const;
|
||||
inline float getInterval() const { return _interval; };
|
||||
/** set interval in seconds */
|
||||
void setInterval(float interval);
|
||||
inline void setInterval(float interval) { _interval = interval; };
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
SEL_SCHEDULE getSelector() const;
|
||||
|
||||
inline const ccSchedulerFunc& getCallback() const { return _callback; };
|
||||
inline long getKey() const { return _key; };
|
||||
|
||||
/** triggers the timer */
|
||||
void update(float dt);
|
||||
|
||||
inline int getScriptHandler() const { return _scriptHandler; };
|
||||
|
||||
protected:
|
||||
Object *_target;
|
||||
Ref *_target;
|
||||
float _elapsed;
|
||||
bool _runForever;
|
||||
bool _useDelay;
|
||||
|
@ -97,8 +93,8 @@ protected:
|
|||
unsigned int _repeat; //0 = once, 1 is 2 x executed
|
||||
float _delay;
|
||||
float _interval;
|
||||
SEL_SCHEDULE _selector;
|
||||
|
||||
ccSchedulerFunc _callback;
|
||||
long _key;
|
||||
int _scriptHandler;
|
||||
};
|
||||
|
||||
|
@ -121,7 +117,7 @@ There are 2 different types of callbacks (selectors):
|
|||
The 'custom selectors' should be avoided when possible. It is faster, and consumes less memory to use the 'update selector'.
|
||||
|
||||
*/
|
||||
class CC_DLL Scheduler : public Object
|
||||
class CC_DLL Scheduler : public Ref
|
||||
{
|
||||
public:
|
||||
// Priority level reserved for system services.
|
||||
|
@ -163,41 +159,77 @@ public:
|
|||
repeat let the action be repeated repeat + 1 times, use kRepeatForever to let the action run continuously
|
||||
delay is the amount of time the action will wait before it'll start
|
||||
|
||||
@since v0.99.3, repeat and delay added in v1.1
|
||||
@since v3.0
|
||||
*/
|
||||
void scheduleSelector(SEL_SCHEDULE selector, Object *target, float interval, unsigned int repeat, float delay, bool paused);
|
||||
void schedule(const ccSchedulerFunc& callback, Ref *target, long key, float interval, unsigned int repeat, float delay, bool paused);
|
||||
|
||||
/** calls scheduleSelector with kRepeatForever and a 0 delay */
|
||||
void scheduleSelector(SEL_SCHEDULE selector, Object *target, float interval, bool paused);
|
||||
void schedule(const ccSchedulerFunc& callback, Ref *target, long key, float interval, bool paused);
|
||||
|
||||
/** Schedules the 'update' selector for a given target with a given priority.
|
||||
The 'update' selector will be called every frame.
|
||||
The lower the priority, the earlier it is called.
|
||||
@since v0.99.3
|
||||
@since v3.0
|
||||
*/
|
||||
void scheduleUpdateForTarget(Object *target, int priority, bool paused);
|
||||
void scheduleUpdate(const ccSchedulerFunc& callback, Ref *target, int priority, bool paused);
|
||||
|
||||
/** Checks whether a selector for a given taget is scheduled.
|
||||
@since v3.0.0
|
||||
*/
|
||||
bool isScheduledForTarget(SEL_SCHEDULE selector, Object *target);
|
||||
bool isScheduled(Ref *target, long key);
|
||||
|
||||
/** Unschedule a selector for a given target.
|
||||
If you want to unschedule the "update", use unscheudleUpdateForTarget.
|
||||
@since v3.0
|
||||
*/
|
||||
void unschedule(Ref *target, long key);
|
||||
|
||||
/** Unschedules the update selector for a given target
|
||||
@since v3.0
|
||||
*/
|
||||
void unscheduleUpdate(Ref *target);
|
||||
|
||||
/** Unschedules all selectors for a given target.
|
||||
This also includes the "update" selector.
|
||||
@since v3.0
|
||||
*/
|
||||
void unscheduleAllForTarget(Ref *target);
|
||||
|
||||
// OLD METHODS
|
||||
/** The scheduled method will be called every 'interval' seconds.
|
||||
If paused is true, then it won't be called until it is resumed.
|
||||
If 'interval' is 0, it will be called every frame, but if so, it's recommended to use 'scheduleUpdateForTarget:' instead.
|
||||
If the selector is already scheduled, then only the interval parameter will be updated without re-scheduling it again.
|
||||
repeat let the action be repeated repeat + 1 times, use kRepeatForever to let the action run continuously
|
||||
delay is the amount of time the action will wait before it'll start
|
||||
|
||||
@since v0.99.3, repeat and delay added in v1.1
|
||||
*/
|
||||
void scheduleSelector(SEL_SCHEDULE selector, Ref *target, float interval, unsigned int repeat, float delay, bool paused);
|
||||
|
||||
/** calls scheduleSelector with kRepeatForever and a 0 delay */
|
||||
void scheduleSelector(SEL_SCHEDULE selector, Ref *target, float interval, bool paused);
|
||||
|
||||
CC_DEPRECATED_ATTRIBUTE void scheduleUpdateForTarget(Ref *target, int priority, bool paused);
|
||||
|
||||
/** Checks whether a selector for a given taget is scheduled.
|
||||
@since v3.0.0
|
||||
*/
|
||||
bool isScheduledForTarget(SEL_SCHEDULE selector, Ref *target);
|
||||
|
||||
/** Unschedule a selector for a given target.
|
||||
If you want to unschedule the "update", use unscheudleUpdateForTarget.
|
||||
@since v0.99.3
|
||||
*/
|
||||
void unscheduleSelector(SEL_SCHEDULE selector, Object *target);
|
||||
|
||||
void unscheduleSelector(SEL_SCHEDULE selector, Ref *target);
|
||||
|
||||
/** Unschedules the update selector for a given target
|
||||
@since v0.99.3
|
||||
*/
|
||||
void unscheduleUpdateForTarget(const Object *target);
|
||||
|
||||
/** Unschedules all selectors for a given target.
|
||||
This also includes the "update" selector.
|
||||
@since v0.99.3
|
||||
*/
|
||||
void unscheduleAllForTarget(Object *target);
|
||||
|
||||
void unscheduleUpdateForTarget(Ref *target) { unscheduleUpdate(target); };
|
||||
|
||||
///
|
||||
|
||||
/** Unschedules all selectors from all targets.
|
||||
You should NEVER call this method, unless you know what you are doing.
|
||||
|
||||
|
@ -226,39 +258,39 @@ public:
|
|||
If the target is not present, nothing happens.
|
||||
@since v0.99.3
|
||||
*/
|
||||
void pauseTarget(Object *target);
|
||||
void pauseTarget(Ref *target);
|
||||
|
||||
/** Resumes the target.
|
||||
The 'target' will be unpaused, so all schedule selectors/update will be 'ticked' again.
|
||||
If the target is not present, nothing happens.
|
||||
@since v0.99.3
|
||||
*/
|
||||
void resumeTarget(Object *target);
|
||||
void resumeTarget(Ref *target);
|
||||
|
||||
/** Returns whether or not the target is paused
|
||||
@since v1.0.0
|
||||
* In js: var isTargetPaused(var jsObject)
|
||||
* @lua NA
|
||||
*/
|
||||
bool isTargetPaused(Object *target);
|
||||
bool isTargetPaused(Ref *target);
|
||||
|
||||
/** Pause all selectors from all targets.
|
||||
You should NEVER call this method, unless you know what you are doing.
|
||||
@since v2.0.0
|
||||
*/
|
||||
Vector<Object*> pauseAllTargets();
|
||||
Vector<Ref*> pauseAllTargets();
|
||||
|
||||
/** Pause all selectors from all targets with a minimum priority.
|
||||
You should only call this with kPriorityNonSystemMin or higher.
|
||||
@since v2.0.0
|
||||
*/
|
||||
Vector<Object*> pauseAllTargetsWithMinPriority(int minPriority);
|
||||
Vector<Ref*> pauseAllTargetsWithMinPriority(int minPriority);
|
||||
|
||||
/** Resume selectors on a set of targets.
|
||||
This can be useful for undoing a call to pauseAllSelectors.
|
||||
@since v2.0.0
|
||||
*/
|
||||
void resumeTargets(const Vector<Object*>& targetsToResume);
|
||||
void resumeTargets(const Vector<Ref*>& targetsToResume);
|
||||
|
||||
/** calls a function on the cocos2d thread. Useful when you need to call a cocos2d function from another thread.
|
||||
This function is thread safe.
|
||||
|
@ -272,8 +304,8 @@ protected:
|
|||
|
||||
// update specific
|
||||
|
||||
void priorityIn(struct _listEntry **list, Object *target, int priority, bool paused);
|
||||
void appendIn(struct _listEntry **list, Object *target, bool paused);
|
||||
void priorityIn(struct _listEntry **list, const ccSchedulerFunc& callback, Ref *target, int priority, bool paused);
|
||||
void appendIn(struct _listEntry **list, const ccSchedulerFunc& callback, Ref *target, bool paused);
|
||||
|
||||
|
||||
float _timeScale;
|
||||
|
|
|
@ -51,7 +51,7 @@ enum ccScriptType {
|
|||
kScriptTypeJavascript
|
||||
};
|
||||
|
||||
class ScriptHandlerEntry : public Object
|
||||
class ScriptHandlerEntry : public Ref
|
||||
{
|
||||
public:
|
||||
static ScriptHandlerEntry* create(int handler);
|
||||
|
@ -309,7 +309,7 @@ struct CommonScriptData
|
|||
// Now this struct is only used in LuaBinding.
|
||||
int handler;
|
||||
char eventName[64];
|
||||
Object* eventSource;
|
||||
Ref* eventSource;
|
||||
char eventSourceClassName[64];
|
||||
|
||||
// Constructor
|
||||
|
@ -317,7 +317,7 @@ struct CommonScriptData
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
CommonScriptData(int inHandler,const char* inName,Object* inSource = nullptr,const char* inClassName = nullptr)
|
||||
CommonScriptData(int inHandler,const char* inName, Ref* inSource = nullptr,const char* inClassName = nullptr)
|
||||
: handler(inHandler),
|
||||
eventSource(inSource)
|
||||
{
|
||||
|
@ -373,7 +373,7 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual void removeScriptObjectByObject(Object* obj) = 0;
|
||||
virtual void removeScriptObjectByObject(Ref* obj) = 0;
|
||||
|
||||
/** Remove script function handler, only LuaEngine class need to implement this function.
|
||||
* @js NA
|
||||
|
|
|
@ -28,11 +28,11 @@ THE SOFTWARE.
|
|||
#ifndef __CCSHADERCACHE_H__
|
||||
#define __CCSHADERCACHE_H__
|
||||
|
||||
#include "CCRef.h"
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "CCDictionary.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class GLProgram;
|
||||
|
@ -46,7 +46,7 @@ class GLProgram;
|
|||
Singleton that stores manages GL shaders
|
||||
@since v2.0
|
||||
*/
|
||||
class CC_DLL ShaderCache : public Object
|
||||
class CC_DLL ShaderCache : public Ref
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -398,7 +398,7 @@ ssize_t SpriteBatchNode::rebuildIndexInOrder(Sprite *parent, ssize_t index)
|
|||
}
|
||||
|
||||
// ignore self (batch node)
|
||||
if (! parent->isEqual(this))
|
||||
if (parent != static_cast<Ref*>(this))
|
||||
{
|
||||
parent->setAtlasIndex(index);
|
||||
index++;
|
||||
|
|
|
@ -30,7 +30,7 @@ THE SOFTWARE.
|
|||
|
||||
#include "CCNode.h"
|
||||
#include "CCProtocols.h"
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCGeometry.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -52,7 +52,7 @@ class Texture2D;
|
|||
SpriteFrame *frame = SpriteFrame::frameWithTexture(texture, rect, offset);
|
||||
sprite->setDisplayFrame(frame);
|
||||
*/
|
||||
class CC_DLL SpriteFrame : public Object, public Clonable
|
||||
class CC_DLL SpriteFrame : public Ref, public Clonable
|
||||
{
|
||||
public:
|
||||
|
||||
|
|
|
@ -37,9 +37,10 @@ THE SOFTWARE.
|
|||
|
||||
#include "CCSpriteFrame.h"
|
||||
#include "CCTexture2D.h"
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCValue.h"
|
||||
#include "CCMap.h"
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
|
@ -56,7 +57,7 @@ class Sprite;
|
|||
It saves in a cache the sprite frames.
|
||||
@since v0.9
|
||||
*/
|
||||
class CC_DLL SpriteFrameCache : public Object
|
||||
class CC_DLL SpriteFrameCache : public Ref
|
||||
{
|
||||
public:
|
||||
/** Returns the shared instance of the Sprite Frame cache */
|
||||
|
|
|
@ -29,9 +29,8 @@ THE SOFTWARE.
|
|||
#define __CCTMX_OBJECT_GROUP_H__
|
||||
|
||||
#include "CCGeometry.h"
|
||||
#include "CCString.h"
|
||||
#include "CCArray.h"
|
||||
#include "CCValue.h"
|
||||
#include "CCRef.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -43,7 +42,7 @@ NS_CC_BEGIN
|
|||
/** @brief TMXObjectGroup represents the TMX object group.
|
||||
@since v0.99.0
|
||||
*/
|
||||
class CC_DLL TMXObjectGroup : public Object
|
||||
class CC_DLL TMXObjectGroup : public Ref
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -29,11 +29,11 @@ THE SOFTWARE.
|
|||
#ifndef __CC_TM_XML_PARSER__
|
||||
#define __CC_TM_XML_PARSER__
|
||||
|
||||
#include "CCArray.h"
|
||||
#include "CCGeometry.h"
|
||||
#include "platform/CCSAXParser.h"
|
||||
#include "CCVector.h"
|
||||
#include "CCValue.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -89,7 +89,7 @@ typedef enum TMXTileFlags_ {
|
|||
|
||||
This information is obtained from the TMX file.
|
||||
*/
|
||||
class CC_DLL TMXLayerInfo : public Object
|
||||
class CC_DLL TMXLayerInfo : public Ref
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -125,7 +125,7 @@ public:
|
|||
|
||||
This information is obtained from the TMX file.
|
||||
*/
|
||||
class CC_DLL TMXTilesetInfo : public Object
|
||||
class CC_DLL TMXTilesetInfo : public Ref
|
||||
{
|
||||
public:
|
||||
std::string _name;
|
||||
|
@ -163,7 +163,7 @@ And it also contains:
|
|||
This information is obtained from the TMX file.
|
||||
|
||||
*/
|
||||
class CC_DLL TMXMapInfo : public Object, public SAXDelegator
|
||||
class CC_DLL TMXMapInfo : public Ref, public SAXDelegator
|
||||
{
|
||||
public:
|
||||
/** creates a TMX Format with a tmx file */
|
||||
|
|
|
@ -31,7 +31,7 @@ THE SOFTWARE.
|
|||
#include <map>
|
||||
#include <map>
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCGeometry.h"
|
||||
#include "ccTypes.h"
|
||||
#ifdef EMSCRIPTEN
|
||||
|
@ -60,7 +60,7 @@ class GLProgram;
|
|||
* Depending on how you create the Texture2D object, the actual image area of the texture might be smaller than the texture dimensions i.e. "contentSize" != (pixelsWide, pixelsHigh) and (maxS, maxT) != (1.0, 1.0).
|
||||
* Be aware that the content of the generated textures will be upside-down!
|
||||
*/
|
||||
class CC_DLL Texture2D : public Object
|
||||
class CC_DLL Texture2D : public Ref
|
||||
#ifdef EMSCRIPTEN
|
||||
, public GLBufferedNode
|
||||
#endif // EMSCRIPTEN
|
||||
|
|
|
@ -29,7 +29,7 @@ THE SOFTWARE.
|
|||
#define __CCTEXTURE_ATLAS_H__
|
||||
|
||||
#include "ccTypes.h"
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "ccConfig.h"
|
||||
#include <string>
|
||||
|
||||
|
@ -56,7 +56,7 @@ Supported features:
|
|||
The quads are rendered using an OpenGL ES VBO.
|
||||
To render the quads using an interleaved vertex array list, you should modify the ccConfig.h file
|
||||
*/
|
||||
class CC_DLL TextureAtlas : public Object
|
||||
class CC_DLL TextureAtlas : public Ref
|
||||
{
|
||||
public:
|
||||
/** creates a TextureAtlas with an filename and with an initial capacity for Quads.
|
||||
|
|
|
@ -123,7 +123,7 @@ void TextureCache::addImageAsync(const std::string &path, std::function<void(Tex
|
|||
|
||||
if (0 == _asyncRefCount)
|
||||
{
|
||||
Director::getInstance()->getScheduler()->scheduleSelector(schedule_selector(TextureCache::addImageAsyncCallBack), this, 0, false);
|
||||
Director::getInstance()->getScheduler()->schedule(CC_CALLBACK_1(TextureCache::addImageAsyncCallBack, this), this, schedule_selector_to_key(schedule_selector(TextureCache::addImageAsyncCallBack)), 0, false);
|
||||
}
|
||||
|
||||
++_asyncRefCount;
|
||||
|
@ -277,7 +277,7 @@ void TextureCache::addImageAsyncCallBack(float dt)
|
|||
--_asyncRefCount;
|
||||
if (0 == _asyncRefCount)
|
||||
{
|
||||
Director::getInstance()->getScheduler()->unscheduleSelector(schedule_selector(TextureCache::addImageAsyncCallBack), this);
|
||||
Director::getInstance()->getScheduler()->unschedule(this, schedule_selector_to_key(schedule_selector(TextureCache::addImageAsyncCallBack)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ THE SOFTWARE.
|
|||
#include <unordered_map>
|
||||
#include <functional>
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCTexture2D.h"
|
||||
#include "platform/CCImage.h"
|
||||
|
||||
|
@ -61,7 +61,7 @@ NS_CC_BEGIN
|
|||
* Once the texture is loaded, the next time it will return
|
||||
* a reference of the previously loaded texture reducing GPU & CPU memory
|
||||
*/
|
||||
class CC_DLL TextureCache : public Object
|
||||
class CC_DLL TextureCache : public Ref
|
||||
{
|
||||
public:
|
||||
/** Returns the shared instance of the cache */
|
||||
|
|
|
@ -26,7 +26,7 @@ THE SOFTWARE.
|
|||
#ifndef __CC_TOUCH_H__
|
||||
#define __CC_TOUCH_H__
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCGeometry.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -36,7 +36,7 @@ NS_CC_BEGIN
|
|||
* @{
|
||||
*/
|
||||
|
||||
class CC_DLL Touch : public Object
|
||||
class CC_DLL Touch : public Ref
|
||||
{
|
||||
public:
|
||||
/** how the touches are dispathced */
|
||||
|
|
|
@ -49,7 +49,7 @@ class NodeGrid;
|
|||
/** @brief TransitionEaseScene can ease the actions of the scene protocol.
|
||||
@since v0.8.2
|
||||
*/
|
||||
class CC_DLL TransitionEaseScene// : public Object
|
||||
class CC_DLL TransitionEaseScene// : public Ref
|
||||
{
|
||||
public:
|
||||
virtual ~TransitionEaseScene() {}
|
||||
|
|
|
@ -25,7 +25,7 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
|
||||
#include "ccCArray.h"
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -39,7 +39,7 @@ ccArray* ccArrayNew(ssize_t capacity)
|
|||
|
||||
ccArray *arr = (ccArray*)malloc( sizeof(ccArray) );
|
||||
arr->num = 0;
|
||||
arr->arr = (Object**)calloc(capacity, sizeof(Object*));
|
||||
arr->arr = (Ref**)calloc(capacity, sizeof(Ref*));
|
||||
arr->max = capacity;
|
||||
|
||||
return arr;
|
||||
|
@ -63,7 +63,7 @@ void ccArrayFree(ccArray*& arr)
|
|||
void ccArrayDoubleCapacity(ccArray *arr)
|
||||
{
|
||||
arr->max *= 2;
|
||||
Object** newArr = (Object**)realloc( arr->arr, arr->max * sizeof(Object*) );
|
||||
Ref** newArr = (Ref**)realloc( arr->arr, arr->max * sizeof(Ref*) );
|
||||
// will fail when there's not enough memory
|
||||
CCASSERT(newArr != 0, "ccArrayDoubleCapacity failed. Not enough memory");
|
||||
arr->arr = newArr;
|
||||
|
@ -99,16 +99,16 @@ void ccArrayShrink(ccArray *arr)
|
|||
arr->max=1;
|
||||
}
|
||||
|
||||
arr->arr = (Object**)realloc(arr->arr,newSize * sizeof(Object*) );
|
||||
arr->arr = (Ref**)realloc(arr->arr,newSize * sizeof(Ref*) );
|
||||
CCASSERT(arr->arr!=nullptr,"could not reallocate the memory");
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns index of first occurrence of object, CC_INVALID_INDEX if object not found. */
|
||||
ssize_t ccArrayGetIndexOfObject(ccArray *arr, Object* object)
|
||||
ssize_t ccArrayGetIndexOfObject(ccArray *arr, Ref* object)
|
||||
{
|
||||
const auto arrNum = arr->num;
|
||||
Object** ptr = arr->arr;
|
||||
Ref** ptr = arr->arr;
|
||||
for (ssize_t i = 0; i < arrNum; ++i, ++ptr)
|
||||
{
|
||||
if (*ptr == object)
|
||||
|
@ -119,13 +119,13 @@ ssize_t ccArrayGetIndexOfObject(ccArray *arr, Object* object)
|
|||
}
|
||||
|
||||
/** Returns a Boolean value that indicates whether object is present in array. */
|
||||
bool ccArrayContainsObject(ccArray *arr, Object* object)
|
||||
bool ccArrayContainsObject(ccArray *arr, Ref* object)
|
||||
{
|
||||
return ccArrayGetIndexOfObject(arr, object) != CC_INVALID_INDEX;
|
||||
}
|
||||
|
||||
/** Appends an object. Behavior undefined if array doesn't have enough capacity. */
|
||||
void ccArrayAppendObject(ccArray *arr, Object* object)
|
||||
void ccArrayAppendObject(ccArray *arr, Ref* object)
|
||||
{
|
||||
CCASSERT(object != nullptr, "Invalid parameter!");
|
||||
object->retain();
|
||||
|
@ -134,7 +134,7 @@ void ccArrayAppendObject(ccArray *arr, Object* object)
|
|||
}
|
||||
|
||||
/** Appends an object. Capacity of arr is increased if needed. */
|
||||
void ccArrayAppendObjectWithResize(ccArray *arr, Object* object)
|
||||
void ccArrayAppendObjectWithResize(ccArray *arr, Ref* object)
|
||||
{
|
||||
ccArrayEnsureExtraCapacity(arr, 1);
|
||||
ccArrayAppendObject(arr, object);
|
||||
|
@ -158,7 +158,7 @@ void ccArrayAppendArrayWithResize(ccArray *arr, ccArray *plusArr)
|
|||
}
|
||||
|
||||
/** Inserts an object at index */
|
||||
void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, ssize_t index)
|
||||
void ccArrayInsertObjectAtIndex(ccArray *arr, Ref* object, ssize_t index)
|
||||
{
|
||||
CCASSERT(index<=arr->num, "Invalid index. Out of bounds");
|
||||
CCASSERT(object != nullptr, "Invalid parameter!");
|
||||
|
@ -168,7 +168,7 @@ void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, ssize_t index)
|
|||
ssize_t remaining = arr->num - index;
|
||||
if (remaining > 0)
|
||||
{
|
||||
memmove((void *)&arr->arr[index+1], (void *)&arr->arr[index], sizeof(Object*) * remaining );
|
||||
memmove((void *)&arr->arr[index+1], (void *)&arr->arr[index], sizeof(Ref*) * remaining );
|
||||
}
|
||||
|
||||
object->retain();
|
||||
|
@ -182,7 +182,7 @@ void ccArraySwapObjectsAtIndexes(ccArray *arr, ssize_t index1, ssize_t index2)
|
|||
CCASSERT(index1>=0 && index1 < arr->num, "(1) Invalid index. Out of bounds");
|
||||
CCASSERT(index2>=0 && index2 < arr->num, "(2) Invalid index. Out of bounds");
|
||||
|
||||
Object* object1 = arr->arr[index1];
|
||||
Ref* object1 = arr->arr[index1];
|
||||
|
||||
arr->arr[index1] = arr->arr[index2];
|
||||
arr->arr[index2] = object1;
|
||||
|
@ -212,7 +212,7 @@ void ccArrayRemoveObjectAtIndex(ccArray *arr, ssize_t index, bool releaseObj/* =
|
|||
ssize_t remaining = arr->num - index;
|
||||
if(remaining>0)
|
||||
{
|
||||
memmove((void *)&arr->arr[index], (void *)&arr->arr[index+1], remaining * sizeof(Object*));
|
||||
memmove((void *)&arr->arr[index], (void *)&arr->arr[index+1], remaining * sizeof(Ref*));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ void ccArrayFastRemoveObjectAtIndex(ccArray *arr, ssize_t index)
|
|||
arr->arr[index] = arr->arr[last];
|
||||
}
|
||||
|
||||
void ccArrayFastRemoveObject(ccArray *arr, Object* object)
|
||||
void ccArrayFastRemoveObject(ccArray *arr, Ref* object)
|
||||
{
|
||||
auto index = ccArrayGetIndexOfObject(arr, object);
|
||||
if (index != CC_INVALID_INDEX)
|
||||
|
@ -237,7 +237,7 @@ void ccArrayFastRemoveObject(ccArray *arr, Object* object)
|
|||
|
||||
/** Searches for the first occurrence of object and removes it. If object is not
|
||||
found the function has no effect. */
|
||||
void ccArrayRemoveObject(ccArray *arr, Object* object, bool releaseObj/* = true*/)
|
||||
void ccArrayRemoveObject(ccArray *arr, Ref* object, bool releaseObj/* = true*/)
|
||||
{
|
||||
auto index = ccArrayGetIndexOfObject(arr, object);
|
||||
if (index != CC_INVALID_INDEX)
|
||||
|
|
|
@ -44,7 +44,7 @@ THE SOFTWARE.
|
|||
#define CC_ARRAY_H
|
||||
|
||||
#include "ccMacros.h"
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -61,7 +61,7 @@ __object__=__array__->arr[0]; for(ssize_t i=0, num=__array__->num; i<num; i++, _
|
|||
|
||||
typedef struct _ccArray {
|
||||
ssize_t num, max;
|
||||
Object** arr;
|
||||
Ref** arr;
|
||||
} ccArray;
|
||||
|
||||
/** Allocates and initializes a new array with specified capacity */
|
||||
|
@ -80,16 +80,16 @@ void ccArrayEnsureExtraCapacity(ccArray *arr, ssize_t extra);
|
|||
void ccArrayShrink(ccArray *arr);
|
||||
|
||||
/** Returns index of first occurrence of object, NSNotFound if object not found. */
|
||||
ssize_t ccArrayGetIndexOfObject(ccArray *arr, Object* object);
|
||||
ssize_t ccArrayGetIndexOfObject(ccArray *arr, Ref* object);
|
||||
|
||||
/** Returns a Boolean value that indicates whether object is present in array. */
|
||||
bool ccArrayContainsObject(ccArray *arr, Object* object);
|
||||
bool ccArrayContainsObject(ccArray *arr, Ref* object);
|
||||
|
||||
/** Appends an object. Behavior undefined if array doesn't have enough capacity. */
|
||||
void ccArrayAppendObject(ccArray *arr, Object* object);
|
||||
void ccArrayAppendObject(ccArray *arr, Ref* object);
|
||||
|
||||
/** Appends an object. Capacity of arr is increased if needed. */
|
||||
void ccArrayAppendObjectWithResize(ccArray *arr, Object* object);
|
||||
void ccArrayAppendObjectWithResize(ccArray *arr, Ref* object);
|
||||
|
||||
/** Appends objects from plusArr to arr.
|
||||
Behavior undefined if arr doesn't have enough capacity. */
|
||||
|
@ -99,7 +99,7 @@ void ccArrayAppendArray(ccArray *arr, ccArray *plusArr);
|
|||
void ccArrayAppendArrayWithResize(ccArray *arr, ccArray *plusArr);
|
||||
|
||||
/** Inserts an object at index */
|
||||
void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, ssize_t index);
|
||||
void ccArrayInsertObjectAtIndex(ccArray *arr, Ref* object, ssize_t index);
|
||||
|
||||
/** Swaps two objects */
|
||||
void ccArraySwapObjectsAtIndexes(ccArray *arr, ssize_t index1, ssize_t index2);
|
||||
|
@ -116,11 +116,11 @@ void ccArrayRemoveObjectAtIndex(ccArray *arr, ssize_t index, bool releaseObj = t
|
|||
Behavior undefined if index outside [0, num-1]. */
|
||||
void ccArrayFastRemoveObjectAtIndex(ccArray *arr, ssize_t index);
|
||||
|
||||
void ccArrayFastRemoveObject(ccArray *arr, Object* object);
|
||||
void ccArrayFastRemoveObject(ccArray *arr, Ref* object);
|
||||
|
||||
/** Searches for the first occurrence of object and removes it. If object is not
|
||||
found the function has no effect. */
|
||||
void ccArrayRemoveObject(ccArray *arr, Object* object, bool releaseObj = true);
|
||||
void ccArrayRemoveObject(ccArray *arr, Ref* object, bool releaseObj = true);
|
||||
|
||||
/** Removes from arr all objects in minusArr. For each object in minusArr, the
|
||||
first matching instance in arr will be removed. */
|
||||
|
|
|
@ -263,4 +263,10 @@ It should work same as apples CFSwapInt32LittleToHost(..)
|
|||
*/
|
||||
#define AnimationFrameDisplayedNotification "CCAnimationFrameDisplayedNotification"
|
||||
|
||||
// new callbacks based on C++11
|
||||
#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__)
|
||||
#define CC_CALLBACK_3(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3 ##__VA_ARGS__)
|
||||
|
||||
#endif // __CCMACROS_H__
|
||||
|
|
|
@ -60,7 +60,7 @@ THE SOFTWARE.
|
|||
// cocoa
|
||||
#include "CCAffineTransform.h"
|
||||
#include "CCDictionary.h"
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCArray.h"
|
||||
#include "CCVector.h"
|
||||
#include "CCMap.h"
|
||||
|
|
|
@ -26,6 +26,8 @@ THE SOFTWARE.
|
|||
#ifndef __CC_APPLICATION_PROTOCOL_H__
|
||||
#define __CC_APPLICATION_PROTOCOL_H__
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
/**
|
||||
|
@ -33,8 +35,6 @@ NS_CC_BEGIN
|
|||
* @{
|
||||
*/
|
||||
|
||||
class EAGLView;
|
||||
|
||||
class CC_DLL ApplicationProtocol
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -25,14 +25,15 @@ THE SOFTWARE.
|
|||
#ifndef __CC_FILEUTILS_H__
|
||||
#define __CC_FILEUTILS_H__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "ccTypes.h"
|
||||
#include "CCValue.h"
|
||||
#include "CCData.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,7 +26,7 @@ THE SOFTWARE.
|
|||
#ifndef __CC_IMAGE_H__
|
||||
#define __CC_IMAGE_H__
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCTexture2D.h"
|
||||
|
||||
// premultiply alpha, or the effect will wrong when want to use other pixel format in Texture2D,
|
||||
|
@ -53,7 +53,7 @@ typedef struct _MipmapInfo
|
|||
int len;
|
||||
}MipmapInfo;
|
||||
|
||||
class CC_DLL Image : public Object
|
||||
class CC_DLL Image : public Ref
|
||||
{
|
||||
public:
|
||||
friend class TextureCache;
|
||||
|
|
|
@ -29,13 +29,13 @@ THE SOFTWARE.
|
|||
#include "CCPlatformConfig.h"
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCGeometry.h"
|
||||
#include "platform/CCGLViewProtocol.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CC_DLL GLView : public Object, public GLViewProtocol
|
||||
class CC_DLL GLView : public Ref, public GLViewProtocol
|
||||
{
|
||||
public:
|
||||
|
||||
|
|
|
@ -26,14 +26,14 @@ THE SOFTWARE.
|
|||
#ifndef __CC_EGLVIEW_DESKTOP_H__
|
||||
#define __CC_EGLVIEW_DESKTOP_H__
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "platform/CCCommon.h"
|
||||
#include "platform/CCGLViewProtocol.h"
|
||||
#include "glfw3.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CC_DLL GLView : public Object, public GLViewProtocol
|
||||
class CC_DLL GLView : public Ref, public GLViewProtocol
|
||||
{
|
||||
public:
|
||||
static GLView* create(const std::string& viewName);
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include "CCPlatformConfig.h"
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "platform/CCCommon.h"
|
||||
#include "platform/CCGLViewProtocol.h"
|
||||
|
||||
|
@ -38,7 +38,7 @@ NS_CC_BEGIN
|
|||
|
||||
/** Class that represent the OpenGL View
|
||||
*/
|
||||
class CC_DLL GLView : public Object, public GLViewProtocol
|
||||
class CC_DLL GLView : public Ref, public GLViewProtocol
|
||||
{
|
||||
public:
|
||||
/** creates a GLView with a objective-c CCEAGLView instance */
|
||||
|
|
|
@ -26,14 +26,15 @@
|
|||
#ifndef _CC_GROUPCOMMAND_H_
|
||||
#define _CC_GROUPCOMMAND_H_
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCRenderCommand.h"
|
||||
#include "CCRenderCommandPool.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class GroupCommandManager : public Object
|
||||
class GroupCommandManager : public Ref
|
||||
{
|
||||
public:
|
||||
static GroupCommandManager* getInstance();
|
||||
|
|
|
@ -27,13 +27,13 @@
|
|||
#define _CC_MATERIALMANAGER_H_
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "ccTypes.h"
|
||||
#include <map>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class MaterialManager : public Object
|
||||
class MaterialManager : public Ref
|
||||
{
|
||||
public:
|
||||
static MaterialManager* getInstance();
|
||||
|
|
|
@ -58,7 +58,7 @@ __Array* __Array::create()
|
|||
return array;
|
||||
}
|
||||
|
||||
__Array* __Array::createWithObject(Object* object)
|
||||
__Array* __Array::createWithObject(Ref* object)
|
||||
{
|
||||
__Array* array = new __Array();
|
||||
|
||||
|
@ -74,7 +74,7 @@ __Array* __Array::createWithObject(Object* object)
|
|||
return array;
|
||||
}
|
||||
|
||||
__Array* __Array::create(Object* object, ...)
|
||||
__Array* __Array::create(Ref* object, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args,object);
|
||||
|
@ -83,11 +83,11 @@ __Array* __Array::create(Object* object, ...)
|
|||
if (array && object)
|
||||
{
|
||||
array->addObject(object);
|
||||
Object *i = va_arg(args, Object*);
|
||||
Ref* i = va_arg(args, Ref*);
|
||||
while (i)
|
||||
{
|
||||
array->addObject(i);
|
||||
i = va_arg(args, Object*);
|
||||
i = va_arg(args, Ref*);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -143,7 +143,7 @@ bool __Array::init()
|
|||
return initWithCapacity(7);
|
||||
}
|
||||
|
||||
bool __Array::initWithObject(Object* object)
|
||||
bool __Array::initWithObject(Ref* object)
|
||||
{
|
||||
bool ret = initWithCapacity(7);
|
||||
if (ret)
|
||||
|
@ -154,7 +154,7 @@ bool __Array::initWithObject(Object* object)
|
|||
}
|
||||
|
||||
/** Initializes an array with some objects */
|
||||
bool __Array::initWithObjects(Object* object, ...)
|
||||
bool __Array::initWithObjects(Ref* object, ...)
|
||||
{
|
||||
bool ret = false;
|
||||
do
|
||||
|
@ -167,11 +167,11 @@ bool __Array::initWithObjects(Object* object, ...)
|
|||
if (object)
|
||||
{
|
||||
this->addObject(object);
|
||||
Object* i = va_arg(args, Object*);
|
||||
Ref* i = va_arg(args, Ref*);
|
||||
while (i)
|
||||
{
|
||||
this->addObject(i);
|
||||
i = va_arg(args, Object*);
|
||||
i = va_arg(args, Ref*);
|
||||
}
|
||||
ret = true;
|
||||
}
|
||||
|
@ -196,7 +196,7 @@ bool __Array::initWithArray(__Array* otherArray)
|
|||
return true;
|
||||
}
|
||||
|
||||
ssize_t __Array::getIndexOfObject(Object* object) const
|
||||
ssize_t __Array::getIndexOfObject(Ref* object) const
|
||||
{
|
||||
auto it = data.begin();
|
||||
|
||||
|
@ -211,7 +211,7 @@ ssize_t __Array::getIndexOfObject(Object* object) const
|
|||
return -1;
|
||||
}
|
||||
|
||||
Object* __Array::getRandomObject()
|
||||
Ref* __Array::getRandomObject()
|
||||
{
|
||||
if (data.size()==0)
|
||||
{
|
||||
|
@ -230,7 +230,7 @@ Object* __Array::getRandomObject()
|
|||
return data[r].get();
|
||||
}
|
||||
|
||||
bool __Array::containsObject(Object* object) const
|
||||
bool __Array::containsObject(Ref* object) const
|
||||
{
|
||||
ssize_t i = this->getIndexOfObject(object);
|
||||
return (i >= 0);
|
||||
|
@ -248,7 +248,7 @@ bool __Array::isEqualToArray(__Array* otherArray)
|
|||
return true;
|
||||
}
|
||||
|
||||
void __Array::addObject(Object* object)
|
||||
void __Array::addObject(Ref* object)
|
||||
{
|
||||
data.push_back(RCPtr<Object>(object));
|
||||
}
|
||||
|
@ -258,12 +258,12 @@ void __Array::addObjectsFromArray(__Array* otherArray)
|
|||
data.insert(data.end(), otherArray->data.begin(), otherArray->data.end());
|
||||
}
|
||||
|
||||
void __Array::insertObject(Object* object, int index)
|
||||
void __Array::insertObject(Ref* object, int index)
|
||||
{
|
||||
data.insert(std::begin(data) + index, RCPtr<Object>(object));
|
||||
}
|
||||
|
||||
void __Array::setObject(Object* object, int index)
|
||||
void __Array::setObject(Ref* object, int index)
|
||||
{
|
||||
data[index] = RCPtr<Object>(object);
|
||||
}
|
||||
|
@ -274,7 +274,7 @@ void __Array::removeLastObject(bool releaseObj)
|
|||
data.pop_back();
|
||||
}
|
||||
|
||||
void __Array::removeObject(Object* object, bool releaseObj /* ignored */)
|
||||
void __Array::removeObject(Ref* object, bool releaseObj /* ignored */)
|
||||
{
|
||||
data.erase(std::remove(data.begin(), data.end(), object));
|
||||
}
|
||||
|
@ -300,12 +300,12 @@ void __Array::fastRemoveObjectAtIndex(int index)
|
|||
removeObjectAtIndex(index);
|
||||
}
|
||||
|
||||
void __Array::fastRemoveObject(Object* object)
|
||||
void __Array::fastRemoveObject(Ref* object)
|
||||
{
|
||||
removeObject(object);
|
||||
}
|
||||
|
||||
void __Array::exchangeObject(Object* object1, Object* object2)
|
||||
void __Array::exchangeObject(Ref* object1, Ref* object2)
|
||||
{
|
||||
ssize_t idx1 = getIndexOfObject(object1);
|
||||
ssize_t idx2 = getIndexOfObject(object2);
|
||||
|
@ -320,7 +320,7 @@ void __Array::exchangeObjectAtIndex(ssize_t index1, ssize_t index2)
|
|||
std::swap(data[index1], data[index2]);
|
||||
}
|
||||
|
||||
void __Array::replaceObjectAtIndex(int index, Object* object, bool releaseObject /* ignored */)
|
||||
void __Array::replaceObjectAtIndex(int index, Ref* object, bool releaseObject /* ignored */)
|
||||
{
|
||||
data[index] = object;
|
||||
}
|
||||
|
@ -346,15 +346,15 @@ __Array* __Array::clone() const
|
|||
ret->autorelease();
|
||||
ret->initWithCapacity(this->data.size() > 0 ? this->data.size() : 1);
|
||||
|
||||
Object* obj = nullptr;
|
||||
Object* tmpObj = nullptr;
|
||||
Ref* obj = nullptr;
|
||||
Ref* tmpObj = nullptr;
|
||||
Clonable* clonable = nullptr;
|
||||
CCARRAY_FOREACH(this, obj)
|
||||
{
|
||||
clonable = dynamic_cast<Clonable*>(obj);
|
||||
if (clonable)
|
||||
{
|
||||
tmpObj = dynamic_cast<Object*>(clonable->clone());
|
||||
tmpObj = dynamic_cast<Ref*>(clonable->clone());
|
||||
if (tmpObj)
|
||||
{
|
||||
ret->addObject(tmpObj);
|
||||
|
@ -401,7 +401,7 @@ __Array* __Array::create()
|
|||
return array;
|
||||
}
|
||||
|
||||
__Array* __Array::createWithObject(Object* object)
|
||||
__Array* __Array::createWithObject(Ref* object)
|
||||
{
|
||||
__Array* array = new __Array();
|
||||
|
||||
|
@ -417,7 +417,7 @@ __Array* __Array::createWithObject(Object* object)
|
|||
return array;
|
||||
}
|
||||
|
||||
__Array* __Array::create(Object* object, ...)
|
||||
__Array* __Array::create(Ref* object, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args,object);
|
||||
|
@ -426,11 +426,11 @@ __Array* __Array::create(Object* object, ...)
|
|||
if (array && object)
|
||||
{
|
||||
array->addObject(object);
|
||||
Object *i = va_arg(args, Object*);
|
||||
Ref *i = va_arg(args, Ref*);
|
||||
while (i)
|
||||
{
|
||||
array->addObject(i);
|
||||
i = va_arg(args, Object*);
|
||||
i = va_arg(args, Ref*);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -496,7 +496,7 @@ bool __Array::init()
|
|||
return initWithCapacity(7);
|
||||
}
|
||||
|
||||
bool __Array::initWithObject(Object* object)
|
||||
bool __Array::initWithObject(Ref* object)
|
||||
{
|
||||
CCASSERT(!data, "Array cannot be re-initialized");
|
||||
|
||||
|
@ -509,7 +509,7 @@ bool __Array::initWithObject(Object* object)
|
|||
}
|
||||
|
||||
/** Initializes an array with some objects */
|
||||
bool __Array::initWithObjects(Object* object, ...)
|
||||
bool __Array::initWithObjects(Ref* object, ...)
|
||||
{
|
||||
CCASSERT(!data, "Array cannot be re-initialized");
|
||||
|
||||
|
@ -524,11 +524,11 @@ bool __Array::initWithObjects(Object* object, ...)
|
|||
if (object)
|
||||
{
|
||||
this->addObject(object);
|
||||
Object* i = va_arg(args, Object*);
|
||||
Ref* i = va_arg(args, Ref*);
|
||||
while (i)
|
||||
{
|
||||
this->addObject(i);
|
||||
i = va_arg(args, Object*);
|
||||
i = va_arg(args, Ref*);
|
||||
}
|
||||
ret = true;
|
||||
}
|
||||
|
@ -563,12 +563,12 @@ bool __Array::initWithArray(__Array* otherArray)
|
|||
return ret;
|
||||
}
|
||||
|
||||
ssize_t __Array::getIndexOfObject(Object* object) const
|
||||
ssize_t __Array::getIndexOfObject(Ref* object) const
|
||||
{
|
||||
return ccArrayGetIndexOfObject(data, object);
|
||||
}
|
||||
|
||||
Object* __Array::getRandomObject()
|
||||
Ref* __Array::getRandomObject()
|
||||
{
|
||||
if (data->num == 0)
|
||||
{
|
||||
|
@ -585,7 +585,7 @@ Object* __Array::getRandomObject()
|
|||
return data->arr[static_cast<int>(data->num * r)];
|
||||
}
|
||||
|
||||
bool __Array::containsObject(Object* object) const
|
||||
bool __Array::containsObject(Ref* object) const
|
||||
{
|
||||
return ccArrayContainsObject(data, object);
|
||||
}
|
||||
|
@ -594,7 +594,8 @@ bool __Array::isEqualToArray(__Array* otherArray)
|
|||
{
|
||||
for (int i = 0; i < this->count(); ++i)
|
||||
{
|
||||
if (!this->getObjectAtIndex(i)->isEqual(otherArray->getObjectAtIndex(i)))
|
||||
//FIXME:james
|
||||
if (this->getObjectAtIndex(i) != otherArray->getObjectAtIndex(i))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -602,7 +603,7 @@ bool __Array::isEqualToArray(__Array* otherArray)
|
|||
return true;
|
||||
}
|
||||
|
||||
void __Array::addObject(Object* object)
|
||||
void __Array::addObject(Ref* object)
|
||||
{
|
||||
CCASSERT(data, "Array not initialized");
|
||||
ccArrayAppendObjectWithResize(data, object);
|
||||
|
@ -614,13 +615,13 @@ void __Array::addObjectsFromArray(__Array* otherArray)
|
|||
ccArrayAppendArrayWithResize(data, otherArray->data);
|
||||
}
|
||||
|
||||
void __Array::insertObject(Object* object, ssize_t index)
|
||||
void __Array::insertObject(Ref* object, ssize_t index)
|
||||
{
|
||||
CCASSERT(data, "Array not initialized");
|
||||
ccArrayInsertObjectAtIndex(data, object, index);
|
||||
}
|
||||
|
||||
void __Array::setObject(Object* object, ssize_t index)
|
||||
void __Array::setObject(Ref* object, ssize_t index)
|
||||
{
|
||||
CCASSERT(index >= 0 && index < count(), "Invalid index");
|
||||
|
||||
|
@ -638,7 +639,7 @@ void __Array::removeLastObject(bool releaseObj)
|
|||
ccArrayRemoveObjectAtIndex(data, data->num - 1, releaseObj);
|
||||
}
|
||||
|
||||
void __Array::removeObject(Object* object, bool releaseObj/* = true*/)
|
||||
void __Array::removeObject(Ref* object, bool releaseObj/* = true*/)
|
||||
{
|
||||
ccArrayRemoveObject(data, object, releaseObj);
|
||||
}
|
||||
|
@ -663,12 +664,12 @@ void __Array::fastRemoveObjectAtIndex(ssize_t index)
|
|||
ccArrayFastRemoveObjectAtIndex(data, index);
|
||||
}
|
||||
|
||||
void __Array::fastRemoveObject(Object* object)
|
||||
void __Array::fastRemoveObject(Ref* object)
|
||||
{
|
||||
ccArrayFastRemoveObject(data, object);
|
||||
}
|
||||
|
||||
void __Array::exchangeObject(Object* object1, Object* object2)
|
||||
void __Array::exchangeObject(Ref* object1, Ref* object2)
|
||||
{
|
||||
auto index1 = ccArrayGetIndexOfObject(data, object1);
|
||||
if (index1 == CC_INVALID_INDEX)
|
||||
|
@ -690,7 +691,7 @@ void __Array::exchangeObjectAtIndex(ssize_t index1, ssize_t index2)
|
|||
ccArraySwapObjectsAtIndexes(data, index1, index2);
|
||||
}
|
||||
|
||||
void __Array::replaceObjectAtIndex(ssize_t index, Object* object, bool releaseObject/* = true*/)
|
||||
void __Array::replaceObjectAtIndex(ssize_t index, Ref* object, bool releaseObject/* = true*/)
|
||||
{
|
||||
ccArrayInsertObjectAtIndex(data, object, index);
|
||||
ccArrayRemoveObjectAtIndex(data, index + 1);
|
||||
|
@ -730,15 +731,15 @@ __Array* __Array::clone() const
|
|||
ret->autorelease();
|
||||
ret->initWithCapacity(this->data->num > 0 ? this->data->num : 1);
|
||||
|
||||
Object* obj = nullptr;
|
||||
Object* tmpObj = nullptr;
|
||||
Ref* obj = nullptr;
|
||||
Ref* tmpObj = nullptr;
|
||||
Clonable* clonable = nullptr;
|
||||
CCARRAY_FOREACH(this, obj)
|
||||
{
|
||||
clonable = dynamic_cast<Clonable*>(obj);
|
||||
if (clonable)
|
||||
{
|
||||
tmpObj = dynamic_cast<Object*>(clonable->clone());
|
||||
tmpObj = dynamic_cast<Ref*>(clonable->clone());
|
||||
if (tmpObj)
|
||||
{
|
||||
ret->addObject(tmpObj);
|
||||
|
|
|
@ -31,12 +31,13 @@ THE SOFTWARE.
|
|||
#if CC_USE_ARRAY_VECTOR
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "ccMacros.h"
|
||||
#else
|
||||
#include "ccCArray.h"
|
||||
#endif
|
||||
|
||||
#include "CCDataVisitor.h"
|
||||
|
||||
#if CC_USE_ARRAY_VECTOR
|
||||
/**
|
||||
|
@ -167,13 +168,13 @@ I found that it's not work in C++. So it keep what it's look like in version 1.0
|
|||
|
||||
#define CCARRAY_FOREACH(__array__, __object__) \
|
||||
if ((__array__) && (__array__)->data->num > 0) \
|
||||
for(Object** __arr__ = (__array__)->data->arr, **__end__ = (__array__)->data->arr + (__array__)->data->num-1; \
|
||||
for(Ref** __arr__ = (__array__)->data->arr, **__end__ = (__array__)->data->arr + (__array__)->data->num-1; \
|
||||
__arr__ <= __end__ && (((__object__) = *__arr__) != NULL/* || true*/); \
|
||||
__arr__++)
|
||||
|
||||
#define CCARRAY_FOREACH_REVERSE(__array__, __object__) \
|
||||
if ((__array__) && (__array__)->data->num > 0) \
|
||||
for(Object** __arr__ = (__array__)->data->arr + (__array__)->data->num-1, **__end__ = (__array__)->data->arr; \
|
||||
for(Ref** __arr__ = (__array__)->data->arr + (__array__)->data->num-1, **__end__ = (__array__)->data->arr; \
|
||||
__arr__ >= __end__ && (((__object__) = *__arr__) != NULL/* || true*/); \
|
||||
__arr__--)
|
||||
|
||||
|
@ -181,7 +182,7 @@ I found that it's not work in C++. So it keep what it's look like in version 1.0
|
|||
#define CCARRAY_VERIFY_TYPE(__array__, __type__) \
|
||||
do { \
|
||||
if ((__array__) && (__array__)->data->num > 0) \
|
||||
for(Object** __arr__ = (__array__)->data->arr, \
|
||||
for(Ref** __arr__ = (__array__)->data->arr, \
|
||||
**__end__ = (__array__)->data->arr + (__array__)->data->num-1; __arr__ <= __end__; __arr__++) \
|
||||
CCASSERT(dynamic_cast<__type__>(*__arr__), "element type is wrong!"); \
|
||||
} while(false)
|
||||
|
@ -198,7 +199,7 @@ I found that it's not work in C++. So it keep what it's look like in version 1.0
|
|||
do { \
|
||||
if(pArray && pArray->count() > 0) \
|
||||
{ \
|
||||
Object* child; \
|
||||
Ref* child; \
|
||||
CCARRAY_FOREACH(pArray, child) \
|
||||
{ \
|
||||
elementType pNode = static_cast<elementType>(child); \
|
||||
|
@ -215,7 +216,7 @@ while(false)
|
|||
do { \
|
||||
if(pArray && pArray->count() > 0) \
|
||||
{ \
|
||||
Object* child; \
|
||||
Ref* child; \
|
||||
CCARRAY_FOREACH(pArray, child) \
|
||||
{ \
|
||||
elementType pNode = static_cast<elementType>(child); \
|
||||
|
@ -231,7 +232,7 @@ while(false)
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CC_DLL __Array : public Object, public Clonable
|
||||
class CC_DLL __Array : public Ref, public Clonable
|
||||
{
|
||||
public:
|
||||
|
||||
|
@ -243,11 +244,11 @@ public:
|
|||
/** Create an array with objects
|
||||
* @js NA
|
||||
*/
|
||||
static __Array* create(Object* object, ...) CC_REQUIRES_NULL_TERMINATION;
|
||||
static __Array* create(Ref* object, ...) CC_REQUIRES_NULL_TERMINATION;
|
||||
/** Create an array with one object
|
||||
* @js NA
|
||||
*/
|
||||
static __Array* createWithObject(Object* object);
|
||||
static __Array* createWithObject(Ref* object);
|
||||
/** Create an array with a default capacity
|
||||
* @js NA
|
||||
*/
|
||||
|
@ -286,12 +287,12 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
bool initWithObject(Object* object);
|
||||
bool initWithObject(Ref* object);
|
||||
/** Initializes an array with some objects
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
bool initWithObjects(Object* object, ...) CC_REQUIRES_NULL_TERMINATION;
|
||||
bool initWithObjects(Ref* object, ...) CC_REQUIRES_NULL_TERMINATION;
|
||||
/** Initializes an array with capacity
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
@ -331,17 +332,17 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
ssize_t getIndexOfObject(Object* object) const;
|
||||
ssize_t getIndexOfObject(Ref* object) const;
|
||||
/**
|
||||
* @js NA
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE ssize_t indexOfObject(Object* object) const { return getIndexOfObject(object); }
|
||||
CC_DEPRECATED_ATTRIBUTE ssize_t indexOfObject(Ref* object) const { return getIndexOfObject(object); }
|
||||
|
||||
/** Returns an element with a certain index
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
Object* getObjectAtIndex(ssize_t index)
|
||||
Ref* getObjectAtIndex(ssize_t index)
|
||||
{
|
||||
CCASSERT(index>=0 && index < count(), "index out of range in getObjectAtIndex()");
|
||||
#if CC_USE_ARRAY_VECTOR
|
||||
|
@ -350,11 +351,11 @@ public:
|
|||
return data->arr[index];
|
||||
#endif
|
||||
}
|
||||
CC_DEPRECATED_ATTRIBUTE Object* objectAtIndex(ssize_t index) { return getObjectAtIndex(index); }
|
||||
CC_DEPRECATED_ATTRIBUTE Ref* objectAtIndex(ssize_t index) { return getObjectAtIndex(index); }
|
||||
/** Returns the last element of the array
|
||||
* @js NA
|
||||
*/
|
||||
Object* getLastObject()
|
||||
Ref* getLastObject()
|
||||
{
|
||||
#if CC_USE_ARRAY_VECTOR
|
||||
return data.back().get();
|
||||
|
@ -368,20 +369,20 @@ public:
|
|||
/**
|
||||
* @js NA
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE Object* lastObject() { return getLastObject(); }
|
||||
CC_DEPRECATED_ATTRIBUTE Ref* lastObject() { return getLastObject(); }
|
||||
/** Returns a random element
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
Object* getRandomObject();
|
||||
Ref* getRandomObject();
|
||||
/**
|
||||
* @js NA
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE Object* randomObject() { return getRandomObject(); }
|
||||
CC_DEPRECATED_ATTRIBUTE Ref* randomObject() { return getRandomObject(); }
|
||||
/** Returns a Boolean value that indicates whether object is present in array.
|
||||
* @js NA
|
||||
*/
|
||||
bool containsObject(Object* object) const;
|
||||
bool containsObject(Ref* object) const;
|
||||
/** @since 1.1
|
||||
* @js NA
|
||||
*/
|
||||
|
@ -391,7 +392,7 @@ public:
|
|||
/** Add a certain object
|
||||
* @js NA
|
||||
*/
|
||||
void addObject(Object* object);
|
||||
void addObject(Ref* object);
|
||||
/**
|
||||
* @js NA
|
||||
*/
|
||||
|
@ -402,17 +403,17 @@ public:
|
|||
/** Insert a certain object at a certain index
|
||||
* @js NA
|
||||
*/
|
||||
void insertObject(Object* object, ssize_t index);
|
||||
void insertObject(Ref* object, ssize_t index);
|
||||
/** sets a certain object at a certain index
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
void setObject(Object* object, ssize_t index);
|
||||
void setObject(Ref* object, ssize_t index);
|
||||
/** sets a certain object at a certain index without retaining. Use it with caution
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
void fastSetObject(Object* object, ssize_t index)
|
||||
void fastSetObject(Ref* object, ssize_t index)
|
||||
{
|
||||
#if CC_USE_ARRAY_VECTOR
|
||||
setObject(object, index);
|
||||
|
@ -444,7 +445,7 @@ public:
|
|||
/** Remove a certain object
|
||||
* @js NA
|
||||
*/
|
||||
void removeObject(Object* object, bool releaseObj = true);
|
||||
void removeObject(Ref* object, bool releaseObj = true);
|
||||
/** Remove an element with a certain index
|
||||
* @js NA
|
||||
*/
|
||||
|
@ -460,7 +461,7 @@ public:
|
|||
/** Fast way to remove a certain object
|
||||
* @js NA
|
||||
*/
|
||||
void fastRemoveObject(Object* object);
|
||||
void fastRemoveObject(Ref* object);
|
||||
/** Fast way to remove an element with a certain index
|
||||
* @js NA
|
||||
*/
|
||||
|
@ -471,7 +472,7 @@ public:
|
|||
/** Swap two elements
|
||||
* @js NA
|
||||
*/
|
||||
void exchangeObject(Object* object1, Object* object2);
|
||||
void exchangeObject(Ref* object1, Ref* object2);
|
||||
/** Swap two elements with certain indexes
|
||||
* @js NA
|
||||
*/
|
||||
|
@ -480,7 +481,7 @@ public:
|
|||
/** Replace object at index with another object.
|
||||
* @js NA
|
||||
*/
|
||||
void replaceObjectAtIndex(ssize_t index, Object* object, bool releaseObject = true);
|
||||
void replaceObjectAtIndex(ssize_t index, Ref* object, bool releaseObject = true);
|
||||
|
||||
/** Revers the array
|
||||
* @js NA
|
||||
|
@ -531,12 +532,12 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
Object** begin() { return &data->arr[0]; }
|
||||
Ref** begin() { return &data->arr[0]; }
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
Object** end() { return &data->arr[data->num]; }
|
||||
Ref** end() { return &data->arr[data->num]; }
|
||||
|
||||
ccArray* data;
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ AutoreleasePool::~AutoreleasePool()
|
|||
PoolManager::getInstance()->pop();
|
||||
}
|
||||
|
||||
void AutoreleasePool::addObject(Object* object)
|
||||
void AutoreleasePool::addObject(Ref* object)
|
||||
{
|
||||
_managedObjectArray.push_back(object);
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ void AutoreleasePool::clear()
|
|||
#endif
|
||||
}
|
||||
|
||||
bool AutoreleasePool::contains(Object* object) const
|
||||
bool AutoreleasePool::contains(Ref* object) const
|
||||
{
|
||||
for (const auto& obj : _managedObjectArray)
|
||||
{
|
||||
|
@ -91,7 +91,7 @@ void AutoreleasePool::dump()
|
|||
CCLOG("%20s%20s%20s", "Object pointer", "Object id", "reference count");
|
||||
for (const auto &obj : _managedObjectArray)
|
||||
{
|
||||
CCLOG("%20p%20u%20u\n", obj, obj->_ID, obj->getReferenceCount());
|
||||
CCLOG("%20p%20u\n", obj, obj->getReferenceCount());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ AutoreleasePool* PoolManager::getCurrentPool() const
|
|||
return _curReleasePool;
|
||||
}
|
||||
|
||||
bool PoolManager::isObjectInPools(Object* obj) const
|
||||
bool PoolManager::isObjectInPools(Ref* obj) const
|
||||
{
|
||||
for (const auto& pool : _releasePoolStack)
|
||||
{
|
||||
|
|
|
@ -28,7 +28,7 @@ THE SOFTWARE.
|
|||
#include <stack>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -62,19 +62,19 @@ public:
|
|||
* Add a given object to this pool.
|
||||
*
|
||||
* The same object may be added several times to the same pool; When the
|
||||
* pool is destructed, the object's Object::release() method will be called
|
||||
* pool is destructed, the object's Ref::release() method will be called
|
||||
* for each time it was added.
|
||||
*
|
||||
* @param object The object to add to the pool.
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
void addObject(Object *object);
|
||||
void addObject(Ref *object);
|
||||
|
||||
/**
|
||||
* Clear the autorelease pool.
|
||||
*
|
||||
* Object::release() will be called for each time the managed object is
|
||||
* Ref::release() will be called for each time the managed object is
|
||||
* added to the pool.
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
@ -91,7 +91,7 @@ public:
|
|||
/**
|
||||
* Checks whether the pool contains the specified object.
|
||||
*/
|
||||
bool contains(Object* object) const;
|
||||
bool contains(Ref* object) const;
|
||||
|
||||
/**
|
||||
* Dump the objects that are put into autorelease pool. It is used for debugging.
|
||||
|
@ -107,12 +107,12 @@ private:
|
|||
* The underlying array of object managed by the pool.
|
||||
*
|
||||
* Although Array retains the object once when an object is added, proper
|
||||
* Object::release() is called outside the array to make sure that the pool
|
||||
* Ref::release() is called outside the array to make sure that the pool
|
||||
* does not affect the managed object's reference count. So an object can
|
||||
* be destructed properly by calling Object::release() even if the object
|
||||
* be destructed properly by calling Ref::release() even if the object
|
||||
* is in the pool.
|
||||
*/
|
||||
std::vector<Object*> _managedObjectArray;
|
||||
std::vector<Ref*> _managedObjectArray;
|
||||
std::string _name;
|
||||
|
||||
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
|
||||
|
@ -146,7 +146,7 @@ public:
|
|||
*/
|
||||
AutoreleasePool *getCurrentPool() const;
|
||||
|
||||
bool isObjectInPools(Object* obj) const;
|
||||
bool isObjectInPools(Ref* obj) const;
|
||||
|
||||
/**
|
||||
* @js NA
|
||||
|
|
|
@ -26,7 +26,8 @@ Copyright (c) 2013-2014 Chukong Technologies Inc.
|
|||
#ifndef __CCBOOL_H__
|
||||
#define __CCBOOL_H__
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCDataVisitor.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -35,7 +36,7 @@ NS_CC_BEGIN
|
|||
* @{
|
||||
*/
|
||||
|
||||
class CC_DLL __Bool : public Object, public Clonable
|
||||
class CC_DLL __Bool : public Ref, public Clonable
|
||||
{
|
||||
public:
|
||||
__Bool(bool v)
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCBool.h"
|
||||
#include "CCInteger.h"
|
||||
#include "CCFloat.h"
|
||||
|
@ -90,7 +90,7 @@ std::string PrettyPrinter::getResult()
|
|||
return _result;
|
||||
}
|
||||
|
||||
void PrettyPrinter::visitObject(const Object *p)
|
||||
void PrettyPrinter::visitObject(const Ref *p)
|
||||
{
|
||||
char buf[50] = {0};
|
||||
sprintf(buf, "%p", p);
|
||||
|
@ -137,7 +137,7 @@ void PrettyPrinter::visit(const __Array *p)
|
|||
_result += "<array>\n";
|
||||
|
||||
setIndentLevel(_indentLevel+1);
|
||||
Object* obj;
|
||||
Ref* obj;
|
||||
int i = 0;
|
||||
char buf[50] = {0};
|
||||
CCARRAY_FOREACH(p, obj)
|
||||
|
@ -148,7 +148,7 @@ void PrettyPrinter::visit(const __Array *p)
|
|||
sprintf(buf, "%s%02d: ", _indentStr.c_str(), i);
|
||||
_result += buf;
|
||||
PrettyPrinter v(_indentLevel);
|
||||
obj->acceptVisitor(v);
|
||||
//FIXME:james obj->acceptVisitor(v);
|
||||
_result += v.getResult();
|
||||
i++;
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ void PrettyPrinter::visit(const __Dictionary *p)
|
|||
sprintf(buf, "%s%s: ", _indentStr.c_str(),element->getStrKey());
|
||||
_result += buf;
|
||||
PrettyPrinter v(_indentLevel);
|
||||
element->getObject()->acceptVisitor(v);
|
||||
//FIXME:james element->getObject()->acceptVisitor(v);
|
||||
_result += v.getResult();
|
||||
bFirstElement = false;
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ void PrettyPrinter::visit(const __Set *p)
|
|||
}
|
||||
_result += _indentStr.c_str();
|
||||
PrettyPrinter v(_indentLevel);
|
||||
(*it)->acceptVisitor(v);
|
||||
//FIXME:james (*it)->acceptVisitor(v);
|
||||
_result += v.getResult();
|
||||
}
|
||||
setIndentLevel(_indentLevel-1);
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class Object;
|
||||
class Ref;
|
||||
class __Bool;
|
||||
class __Integer;
|
||||
class __Float;
|
||||
|
@ -50,7 +50,7 @@ class __Set;
|
|||
*
|
||||
* Use cases:
|
||||
* - data serialization,
|
||||
* - pretty printing of Object *
|
||||
* - pretty printing of Ref*
|
||||
* - safe value reading from Array, __Dictionary, Set
|
||||
*
|
||||
* Usage:
|
||||
|
@ -69,7 +69,7 @@ public:
|
|||
virtual ~DataVisitor() {}
|
||||
|
||||
/** default method, called from non-overloaded methods and for unrecognized objects */
|
||||
virtual void visitObject(const Object *p) = 0;
|
||||
virtual void visitObject(const Ref *p) = 0;
|
||||
|
||||
virtual void visit(const __Bool *p);
|
||||
virtual void visit(const __Integer *p);
|
||||
|
@ -90,7 +90,7 @@ public:
|
|||
virtual void clear();
|
||||
virtual std::string getResult();
|
||||
|
||||
virtual void visitObject(const Object *p);
|
||||
virtual void visitObject(const Ref *p);
|
||||
virtual void visit(const __Bool * p);
|
||||
virtual void visit(const __Integer *p);
|
||||
virtual void visit(const __Float *p);
|
||||
|
|
|
@ -41,7 +41,7 @@ NS_CC_BEGIN
|
|||
// -----------------------------------------------------------------------
|
||||
// DictElement
|
||||
|
||||
DictElement::DictElement(const char* pszKey, Object* pObject)
|
||||
DictElement::DictElement(const char* pszKey, Ref* pObject)
|
||||
{
|
||||
CCASSERT(pszKey && strlen(pszKey) > 0, "Invalid key value.");
|
||||
_intKey = 0;
|
||||
|
@ -60,7 +60,7 @@ DictElement::DictElement(const char* pszKey, Object* pObject)
|
|||
memset(&hh, 0, sizeof(hh));
|
||||
}
|
||||
|
||||
DictElement::DictElement(intptr_t iKey, Object* pObject)
|
||||
DictElement::DictElement(intptr_t iKey, Ref* pObject)
|
||||
{
|
||||
_strKey[0] = '\0';
|
||||
_intKey = iKey;
|
||||
|
@ -124,7 +124,7 @@ __Array* __Dictionary::allKeys()
|
|||
return array;
|
||||
}
|
||||
|
||||
__Array* __Dictionary::allKeysForObject(Object* object)
|
||||
__Array* __Dictionary::allKeysForObject(Ref* object)
|
||||
{
|
||||
int iKeyCount = this->count();
|
||||
if (iKeyCount <= 0) return NULL;
|
||||
|
@ -159,7 +159,7 @@ __Array* __Dictionary::allKeysForObject(Object* object)
|
|||
return array;
|
||||
}
|
||||
|
||||
Object* __Dictionary::objectForKey(const std::string& key)
|
||||
Ref* __Dictionary::objectForKey(const std::string& key)
|
||||
{
|
||||
// if dictionary wasn't initialized, return NULL directly.
|
||||
if (_dictType == kDictUnknown) return NULL;
|
||||
|
@ -167,7 +167,7 @@ Object* __Dictionary::objectForKey(const std::string& key)
|
|||
// This method uses string as key, therefore we should make sure that the key type of this __Dictionary is string.
|
||||
CCASSERT(_dictType == kDictStr, "this dictionary does not use string as key.");
|
||||
|
||||
Object* pRetObject = NULL;
|
||||
Ref* pRetObject = NULL;
|
||||
DictElement *pElement = NULL;
|
||||
HASH_FIND_STR(_elements, key.c_str(), pElement);
|
||||
if (pElement != NULL)
|
||||
|
@ -177,7 +177,7 @@ Object* __Dictionary::objectForKey(const std::string& key)
|
|||
return pRetObject;
|
||||
}
|
||||
|
||||
Object* __Dictionary::objectForKey(intptr_t key)
|
||||
Ref* __Dictionary::objectForKey(intptr_t key)
|
||||
{
|
||||
// if dictionary wasn't initialized, return NULL directly.
|
||||
if (_dictType == kDictUnknown) return NULL;
|
||||
|
@ -185,7 +185,7 @@ Object* __Dictionary::objectForKey(intptr_t key)
|
|||
// This method uses integer as key, therefore we should make sure that the key type of this __Dictionary is integer.
|
||||
CCASSERT(_dictType == kDictInt, "this dictionary does not use integer as key.");
|
||||
|
||||
Object* pRetObject = NULL;
|
||||
Ref* pRetObject = NULL;
|
||||
DictElement *pElement = NULL;
|
||||
HASH_FIND_PTR(_elements, &key, pElement);
|
||||
if (pElement != NULL)
|
||||
|
@ -215,7 +215,7 @@ const __String* __Dictionary::valueForKey(intptr_t key)
|
|||
return pStr;
|
||||
}
|
||||
|
||||
void __Dictionary::setObject(Object* pObject, const std::string& key)
|
||||
void __Dictionary::setObject(Ref* pObject, const std::string& key)
|
||||
{
|
||||
CCASSERT(key.length() > 0 && pObject != NULL, "Invalid Argument!");
|
||||
if (_dictType == kDictUnknown)
|
||||
|
@ -233,7 +233,7 @@ void __Dictionary::setObject(Object* pObject, const std::string& key)
|
|||
}
|
||||
else if (pElement->_object != pObject)
|
||||
{
|
||||
Object* pTmpObj = pElement->_object;
|
||||
Ref* pTmpObj = pElement->_object;
|
||||
pTmpObj->retain();
|
||||
removeObjectForElememt(pElement);
|
||||
setObjectUnSafe(pObject, key);
|
||||
|
@ -241,7 +241,7 @@ void __Dictionary::setObject(Object* pObject, const std::string& key)
|
|||
}
|
||||
}
|
||||
|
||||
void __Dictionary::setObject(Object* pObject, intptr_t key)
|
||||
void __Dictionary::setObject(Ref* pObject, intptr_t key)
|
||||
{
|
||||
CCASSERT(pObject != NULL, "Invalid Argument!");
|
||||
if (_dictType == kDictUnknown)
|
||||
|
@ -259,7 +259,7 @@ void __Dictionary::setObject(Object* pObject, intptr_t key)
|
|||
}
|
||||
else if (pElement->_object != pObject)
|
||||
{
|
||||
Object* pTmpObj = pElement->_object;
|
||||
Ref* pTmpObj = pElement->_object;
|
||||
pTmpObj->retain();
|
||||
removeObjectForElememt(pElement);
|
||||
setObjectUnSafe(pObject, key);
|
||||
|
@ -295,14 +295,14 @@ void __Dictionary::removeObjectForKey(intptr_t key)
|
|||
removeObjectForElememt(pElement);
|
||||
}
|
||||
|
||||
void __Dictionary::setObjectUnSafe(Object* pObject, const std::string& key)
|
||||
void __Dictionary::setObjectUnSafe(Ref* pObject, const std::string& key)
|
||||
{
|
||||
pObject->retain();
|
||||
DictElement* pElement = new DictElement(key.c_str(), pObject);
|
||||
HASH_ADD_STR(_elements, _strKey, pElement);
|
||||
}
|
||||
|
||||
void __Dictionary::setObjectUnSafe(Object* pObject, const intptr_t key)
|
||||
void __Dictionary::setObjectUnSafe(Ref* pObject, const intptr_t key)
|
||||
{
|
||||
pObject->retain();
|
||||
DictElement* pElement = new DictElement(key, pObject);
|
||||
|
@ -311,7 +311,7 @@ void __Dictionary::setObjectUnSafe(Object* pObject, const intptr_t key)
|
|||
|
||||
void __Dictionary::removeObjectsForKeys(__Array* pKey__Array)
|
||||
{
|
||||
Object* pObj = NULL;
|
||||
Ref* pObj = NULL;
|
||||
CCARRAY_FOREACH(pKey__Array, pObj)
|
||||
{
|
||||
__String* pStr = static_cast<__String*>(pObj);
|
||||
|
@ -341,14 +341,14 @@ void __Dictionary::removeAllObjects()
|
|||
}
|
||||
}
|
||||
|
||||
Object* __Dictionary::randomObject()
|
||||
Ref* __Dictionary::randomObject()
|
||||
{
|
||||
if (_dictType == kDictUnknown)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Object* key = allKeys()->getRandomObject();
|
||||
Ref* key = allKeys()->getRandomObject();
|
||||
|
||||
if (_dictType == kDictInt)
|
||||
{
|
||||
|
@ -474,7 +474,7 @@ static ValueVector ccarray_to_valuevector(__Array* arr)
|
|||
{
|
||||
ValueVector ret;
|
||||
|
||||
Object* obj;
|
||||
Ref* obj;
|
||||
CCARRAY_FOREACH(arr, obj)
|
||||
{
|
||||
Value arrElement;
|
||||
|
@ -516,7 +516,7 @@ static ValueMap ccdictionary_to_valuemap(__Dictionary* dict)
|
|||
DictElement* pElement = nullptr;
|
||||
CCDICT_FOREACH(dict, pElement)
|
||||
{
|
||||
Object* obj = pElement->getObject();
|
||||
Ref* obj = pElement->getObject();
|
||||
|
||||
__String* strVal = nullptr;
|
||||
__Dictionary* dictVal = nullptr;
|
||||
|
@ -567,7 +567,7 @@ __Dictionary* __Dictionary::clone() const
|
|||
__Dictionary* newDict = __Dictionary::create();
|
||||
|
||||
DictElement* element = NULL;
|
||||
Object* tmpObj = NULL;
|
||||
Ref* tmpObj = NULL;
|
||||
Clonable* obj = NULL;
|
||||
if (_dictType == kDictInt)
|
||||
{
|
||||
|
@ -576,7 +576,7 @@ __Dictionary* __Dictionary::clone() const
|
|||
obj = dynamic_cast<Clonable*>(element->getObject());
|
||||
if (obj)
|
||||
{
|
||||
tmpObj = dynamic_cast<Object*>(obj->clone());
|
||||
tmpObj = dynamic_cast<Ref*>(obj->clone());
|
||||
if (tmpObj)
|
||||
{
|
||||
newDict->setObject(tmpObj, element->getIntKey());
|
||||
|
@ -595,7 +595,7 @@ __Dictionary* __Dictionary::clone() const
|
|||
obj = dynamic_cast<Clonable*>(element->getObject());
|
||||
if (obj)
|
||||
{
|
||||
tmpObj = dynamic_cast<Object*>(obj->clone());
|
||||
tmpObj = dynamic_cast<Ref*>(obj->clone());
|
||||
if (tmpObj)
|
||||
{
|
||||
newDict->setObject(tmpObj, element->getStrKey());
|
||||
|
|
|
@ -27,7 +27,7 @@ THE SOFTWARE.
|
|||
#define __CCDICTIONARY_H__
|
||||
|
||||
#include "uthash.h"
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCArray.h"
|
||||
#include "CCString.h"
|
||||
|
||||
|
@ -69,7 +69,7 @@ private:
|
|||
* @param pszKey The string key of this element.
|
||||
* @param pObject The object of this element.
|
||||
*/
|
||||
DictElement(const char* pszKey, Object* pObject);
|
||||
DictElement(const char* pszKey, Ref* pObject);
|
||||
|
||||
/**
|
||||
* Constructor of DictElement. It's only for internal usage. Dictionary is its friend class.
|
||||
|
@ -77,7 +77,7 @@ private:
|
|||
* @param iKey The integer key of this element.
|
||||
* @param pObject The object of this element.
|
||||
*/
|
||||
DictElement(intptr_t iKey, Object* pObject);
|
||||
DictElement(intptr_t iKey, Ref* pObject);
|
||||
|
||||
public:
|
||||
/**
|
||||
|
@ -120,7 +120,7 @@ public:
|
|||
*
|
||||
* @return The object of this element.
|
||||
*/
|
||||
inline Object* getObject() const { return _object; }
|
||||
inline Ref* getObject() const { return _object; }
|
||||
|
||||
private:
|
||||
// The max length of string key.
|
||||
|
@ -129,7 +129,7 @@ private:
|
|||
// So it's a pain that all elements will allocate 256 bytes for this array.
|
||||
char _strKey[MAX_KEY_LEN]; // hash key of string type
|
||||
intptr_t _intKey; // hash key of integer type
|
||||
Object* _object; // hash value
|
||||
Ref* _object; // hash value
|
||||
public:
|
||||
UT_hash_handle hh; // makes this class hashable
|
||||
friend class __Dictionary; // declare Dictionary as friend class
|
||||
|
@ -172,7 +172,7 @@ public:
|
|||
*
|
||||
*/
|
||||
|
||||
class CC_DLL __Dictionary : public Object, public Clonable
|
||||
class CC_DLL __Dictionary : public Ref, public Clonable
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -216,7 +216,7 @@ public:
|
|||
* @return The array contains all keys for the specified object. It's an autorelease object yet.
|
||||
* @js NA
|
||||
*/
|
||||
__Array* allKeysForObject(Object* object);
|
||||
__Array* allKeysForObject(Ref* object);
|
||||
|
||||
/**
|
||||
* Get the object according to the specified string key.
|
||||
|
@ -237,7 +237,7 @@ public:
|
|||
* @see objectForKey(intptr_t)
|
||||
* @js NA
|
||||
*/
|
||||
Object* objectForKey(const std::string& key);
|
||||
Ref* objectForKey(const std::string& key);
|
||||
|
||||
/**
|
||||
* Get the object according to the specified integer key.
|
||||
|
@ -248,7 +248,7 @@ public:
|
|||
* @see objectForKey(const std::string&)
|
||||
* @js NA
|
||||
*/
|
||||
Object* objectForKey(intptr_t key);
|
||||
Ref* objectForKey(intptr_t key);
|
||||
|
||||
/** Get the value according to the specified string key.
|
||||
*
|
||||
|
@ -281,10 +281,10 @@ public:
|
|||
*
|
||||
* @param pObject The Object to be inserted.
|
||||
* @param key The string key for searching.
|
||||
* @see setObject(Object*, intptr_t)
|
||||
* @see setObject(Ref*, intptr_t)
|
||||
* @js NA
|
||||
*/
|
||||
void setObject(Object* pObject, const std::string& key);
|
||||
void setObject(Ref* pObject, const std::string& key);
|
||||
|
||||
/** Insert an object to dictionary, and match it with the specified string key.
|
||||
*
|
||||
|
@ -294,10 +294,10 @@ public:
|
|||
* Then the new object will be inserted after that.
|
||||
* @param pObject The Object to be inserted.
|
||||
* @param key The string key for searching.
|
||||
* @see setObject(Object*, const std::string&)
|
||||
* @see setObject(Ref*, const std::string&)
|
||||
* @js NA
|
||||
*/
|
||||
void setObject(Object* pObject, intptr_t key);
|
||||
void setObject(Ref* pObject, intptr_t key);
|
||||
|
||||
/**
|
||||
* Remove an object by the specified string key.
|
||||
|
@ -357,7 +357,7 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
Object* randomObject();
|
||||
Ref* randomObject();
|
||||
|
||||
/**
|
||||
* Create a dictionary.
|
||||
|
@ -425,8 +425,8 @@ private:
|
|||
/**
|
||||
* For internal usage, invoked by setObject.
|
||||
*/
|
||||
void setObjectUnSafe(Object* pObject, const std::string& key);
|
||||
void setObjectUnSafe(Object* pObject, const intptr_t key);
|
||||
void setObjectUnSafe(Ref* pObject, const std::string& key);
|
||||
void setObjectUnSafe(Ref* pObject, const intptr_t key);
|
||||
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -25,7 +25,8 @@
|
|||
#ifndef __CCDOUBLE_H__
|
||||
#define __CCDOUBLE_H__
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCDataVisitor.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -34,7 +35,7 @@ NS_CC_BEGIN
|
|||
* @{
|
||||
*/
|
||||
|
||||
class CC_DLL __Double : public Object, public Clonable
|
||||
class CC_DLL __Double : public Ref, public Clonable
|
||||
{
|
||||
public:
|
||||
__Double(double v)
|
||||
|
|
|
@ -25,7 +25,8 @@
|
|||
#ifndef __CCFLOAT_H__
|
||||
#define __CCFLOAT_H__
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCDataVisitor.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -34,7 +35,7 @@ NS_CC_BEGIN
|
|||
* @{
|
||||
*/
|
||||
|
||||
class CC_DLL __Float : public Object, public Clonable
|
||||
class CC_DLL __Float : public Ref, public Clonable
|
||||
{
|
||||
public:
|
||||
__Float(float v)
|
||||
|
|
|
@ -30,7 +30,6 @@ THE SOFTWARE.
|
|||
#include <functional>
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "CCObject.h"
|
||||
#include "ccMacros.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
|
|
@ -25,7 +25,8 @@
|
|||
#ifndef __CCINTEGER_H__
|
||||
#define __CCINTEGER_H__
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCDataVisitor.h"
|
||||
#include "platform/CCCommon.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -35,7 +36,7 @@ NS_CC_BEGIN
|
|||
* @{
|
||||
*/
|
||||
|
||||
class CC_DLL __Integer : public Object, public Clonable
|
||||
class CC_DLL __Integer : public Ref, public Clonable
|
||||
{
|
||||
public:
|
||||
static __Integer* create(int v)
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#define USE_STD_UNORDERED_MAP 1
|
||||
|
||||
#include "ccMacros.h"
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include <vector>
|
||||
|
||||
#if USE_STD_UNORDERED_MAP
|
||||
|
@ -73,7 +73,7 @@ public:
|
|||
Map<K, V>()
|
||||
: _data()
|
||||
{
|
||||
static_assert(std::is_convertible<V, Object*>::value, "Invalid Type for cocos2d::Map<K, V>!");
|
||||
static_assert(std::is_convertible<V, Ref*>::value, "Invalid Type for cocos2d::Map<K, V>!");
|
||||
CCLOGINFO("In the default constructor of Map!");
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ public:
|
|||
explicit Map<K, V>(ssize_t capacity)
|
||||
: _data()
|
||||
{
|
||||
static_assert(std::is_convertible<V, Object*>::value, "Invalid Type for cocos2d::Map<K, V>!");
|
||||
static_assert(std::is_convertible<V, Ref*>::value, "Invalid Type for cocos2d::Map<K, V>!");
|
||||
CCLOGINFO("In the constructor with capacity of Map!");
|
||||
_data.reserve(capacity);
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ public:
|
|||
/** Copy constructor */
|
||||
Map<K, V>(const Map<K, V>& other)
|
||||
{
|
||||
static_assert(std::is_convertible<V, Object*>::value, "Invalid Type for cocos2d::Map<K, V>!");
|
||||
static_assert(std::is_convertible<V, Ref*>::value, "Invalid Type for cocos2d::Map<K, V>!");
|
||||
CCLOGINFO("In the copy constructor of Map!");
|
||||
_data = other._data;
|
||||
addRefForAllObjects();
|
||||
|
@ -98,7 +98,7 @@ public:
|
|||
/** Move constructor */
|
||||
Map<K, V>(Map<K, V>&& other)
|
||||
{
|
||||
static_assert(std::is_convertible<V, Object*>::value, "Invalid Type for cocos2d::Map<K, V>!");
|
||||
static_assert(std::is_convertible<V, Ref*>::value, "Invalid Type for cocos2d::Map<K, V>!");
|
||||
CCLOGINFO("In the move constructor of Map!");
|
||||
_data = std::move(other._data);
|
||||
}
|
||||
|
|
|
@ -23,24 +23,23 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCAutoreleasePool.h"
|
||||
#include "ccMacros.h"
|
||||
#include "CCScriptSupport.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
Object::Object()
|
||||
: _luaID(0)
|
||||
, _referenceCount(1) // when the object is created, the reference count of it is 1
|
||||
Ref::Ref()
|
||||
: _referenceCount(1) // when the Ref is created, the reference count of it is 1
|
||||
, _luaID(0)
|
||||
{
|
||||
static unsigned int uObjectCount = 0;
|
||||
|
||||
|
||||
_ID = ++uObjectCount;
|
||||
}
|
||||
|
||||
Object::~Object()
|
||||
Ref::~Ref()
|
||||
{
|
||||
// if the object is referenced by Lua engine, remove it
|
||||
if (_luaID)
|
||||
|
@ -57,15 +56,13 @@ Object::~Object()
|
|||
}
|
||||
}
|
||||
|
||||
Object* Object::autorelease()
|
||||
void Ref::retain()
|
||||
{
|
||||
PoolManager::getInstance()->getCurrentPool()->addObject(this);
|
||||
return this;
|
||||
CCASSERT(_referenceCount > 0, "reference count should greater than 0");
|
||||
++_referenceCount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Object::release()
|
||||
void Ref::release()
|
||||
{
|
||||
CCASSERT(_referenceCount > 0, "reference count should greater than 0");
|
||||
--_referenceCount;
|
||||
|
@ -76,18 +73,18 @@ void Object::release()
|
|||
auto poolManager = PoolManager::getInstance();
|
||||
if (!poolManager->getCurrentPool()->isClearing() && poolManager->isObjectInPools(this))
|
||||
{
|
||||
// Trigger an assert if the reference count is 0 but the object is still in autorelease pool.
|
||||
// Trigger an assert if the reference count is 0 but the Ref is still in autorelease pool.
|
||||
// This happens when 'autorelease/release' were not used in pairs with 'new/retain'.
|
||||
//
|
||||
// Wrong usage (1):
|
||||
//
|
||||
// auto obj = Node::create(); // Ref = 1, but it's an autorelease object which means it was in the autorelease pool.
|
||||
// auto obj = Node::create(); // Ref = 1, but it's an autorelease Ref which means it was in the autorelease pool.
|
||||
// obj->autorelease(); // Wrong: If you wish to invoke autorelease several times, you should retain `obj` first.
|
||||
//
|
||||
// Wrong usage (2):
|
||||
//
|
||||
// auto obj = Node::create();
|
||||
// obj->release(); // Wrong: obj is an autorelease object, it will be released when clearing current pool.
|
||||
// obj->release(); // Wrong: obj is an autorelease Ref, it will be released when clearing current pool.
|
||||
//
|
||||
// Correct usage (1):
|
||||
//
|
||||
|
@ -110,24 +107,15 @@ void Object::release()
|
|||
}
|
||||
}
|
||||
|
||||
bool Object::isSingleReference() const
|
||||
Ref* Ref::autorelease()
|
||||
{
|
||||
return _referenceCount == 1;
|
||||
PoolManager::getInstance()->getCurrentPool()->addObject(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
unsigned int Object::getReferenceCount() const
|
||||
unsigned int Ref::getReferenceCount() const
|
||||
{
|
||||
return _referenceCount;
|
||||
}
|
||||
|
||||
bool Object::isEqual(const Object *object)
|
||||
{
|
||||
return this == object;
|
||||
}
|
||||
|
||||
void Object::acceptVisitor(DataVisitor &visitor)
|
||||
{
|
||||
visitor.visitObject(this);
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -23,16 +23,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CCOBJECT_H__
|
||||
#define __CCOBJECT_H__
|
||||
#ifndef __CCREF_H__
|
||||
#define __CCREF_H__
|
||||
|
||||
#include "CCDataVisitor.h"
|
||||
#include "ccMacros.h"
|
||||
#include "CCConsole.h"
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
#include <GLES2/gl2.h>
|
||||
#endif // EMSCRIPTEN
|
||||
#include "CCPlatformMacros.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -41,14 +35,13 @@ NS_CC_BEGIN
|
|||
* @{
|
||||
*/
|
||||
|
||||
class Object;
|
||||
class Node;
|
||||
class Ref;
|
||||
|
||||
/** Interface that defines how to clone an object */
|
||||
/** Interface that defines how to clone an Ref */
|
||||
class CC_DLL Clonable
|
||||
{
|
||||
public:
|
||||
/** returns a copy of the object */
|
||||
/** returns a copy of the Ref */
|
||||
virtual Clonable* clone() const = 0;
|
||||
/**
|
||||
* @js NA
|
||||
|
@ -56,10 +49,10 @@ public:
|
|||
*/
|
||||
virtual ~Clonable() {};
|
||||
|
||||
/** returns a copy of the object.
|
||||
/** returns a copy of the Ref.
|
||||
@deprecated Use clone() instead
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE Object* copy() const
|
||||
CC_DEPRECATED_ATTRIBUTE Ref* copy() const
|
||||
{
|
||||
// use "clone" instead
|
||||
CC_ASSERT(false);
|
||||
|
@ -67,37 +60,39 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class CC_DLL Object
|
||||
class CC_DLL Ref
|
||||
{
|
||||
public:
|
||||
/// object id, ScriptSupport need public _ID
|
||||
unsigned int _ID;
|
||||
/// Lua reference id
|
||||
int _luaID;
|
||||
protected:
|
||||
/// count of references
|
||||
unsigned int _referenceCount;
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* The object's reference count is 1 after construction.
|
||||
* The Ref's reference count is 1 after construction.
|
||||
* @js NA
|
||||
*/
|
||||
Object();
|
||||
Ref();
|
||||
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual ~Object();
|
||||
virtual ~Ref();
|
||||
|
||||
/**
|
||||
* Retains the ownership.
|
||||
*
|
||||
* This increases the Ref's reference count.
|
||||
*
|
||||
* @see release, autorelease
|
||||
* @js NA
|
||||
*/
|
||||
void retain();
|
||||
|
||||
/**
|
||||
* Release the ownership immediately.
|
||||
*
|
||||
* This decrements the object's reference count.
|
||||
* This decrements the Ref's reference count.
|
||||
*
|
||||
* If the reference count reaches 0 after the descrement, this object is
|
||||
* If the reference count reaches 0 after the descrement, this Ref is
|
||||
* destructed.
|
||||
*
|
||||
* @see retain, autorelease
|
||||
|
@ -105,107 +100,63 @@ public:
|
|||
*/
|
||||
void release();
|
||||
|
||||
/**
|
||||
* Retains the ownership.
|
||||
*
|
||||
* This increases the object's reference count.
|
||||
*
|
||||
* @see release, autorelease
|
||||
* @js NA
|
||||
*/
|
||||
inline void retain()
|
||||
{
|
||||
CCASSERT(_referenceCount > 0, "reference count should greater than 0");
|
||||
++_referenceCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Release the ownership sometime soon automatically.
|
||||
*
|
||||
* This descrements the object's reference count at the end of current
|
||||
* This descrements the Ref's reference count at the end of current
|
||||
* autorelease pool block.
|
||||
*
|
||||
* If the reference count reaches 0 after the descrement, this object is
|
||||
* If the reference count reaches 0 after the descrement, this Ref is
|
||||
* destructed.
|
||||
*
|
||||
* @returns The object itself.
|
||||
* @returns The Ref itself.
|
||||
*
|
||||
* @see AutoreleasePool, retain, release
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
Object* autorelease();
|
||||
Ref* autorelease();
|
||||
|
||||
/**
|
||||
* Returns a boolean value that indicates whether there is only one
|
||||
* reference to the object. That is, whether the reference count is 1.
|
||||
* Returns the Ref's current reference count.
|
||||
*
|
||||
* @returns Whether the object's reference count is 1.
|
||||
* @returns The Ref's reference count.
|
||||
* @js NA
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE bool isSingleReference() const;
|
||||
|
||||
/**
|
||||
* Returns the object's current reference count.
|
||||
*
|
||||
* @returns The object's reference count.
|
||||
* @js NA
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE unsigned int retainCount() const { return getReferenceCount(); };
|
||||
unsigned int getReferenceCount() const;
|
||||
|
||||
/**
|
||||
* Returns a boolean value that indicates whether this object and a given
|
||||
* object are equal.
|
||||
*
|
||||
* @param object The object to be compared to this object.
|
||||
*
|
||||
* @returns True if this object and @p object are equal, otherwise false.
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual bool isEqual(const Object* object);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual void acceptVisitor(DataVisitor &visitor);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual void update(float dt) {CC_UNUSED_PARAM(dt);};
|
||||
protected:
|
||||
/// count of references
|
||||
unsigned int _referenceCount;
|
||||
|
||||
friend class AutoreleasePool;
|
||||
|
||||
public:
|
||||
/// object id, ScriptSupport need public _ID
|
||||
unsigned int _ID;
|
||||
/// Lua reference id
|
||||
int _luaID;
|
||||
};
|
||||
|
||||
class Node;
|
||||
|
||||
typedef void (Object::*SEL_SCHEDULE)(float);
|
||||
typedef void (Object::*SEL_CallFunc)();
|
||||
typedef void (Object::*SEL_CallFuncN)(Node*);
|
||||
typedef void (Object::*SEL_CallFuncND)(Node*, void*);
|
||||
typedef void (Object::*SEL_CallFuncO)(Object*);
|
||||
typedef void (Object::*SEL_MenuHandler)(Object*);
|
||||
typedef int (Object::*SEL_Compare)(Object*);
|
||||
typedef void (Ref::*SEL_CallFunc)();
|
||||
typedef void (Ref::*SEL_CallFuncN)(Node*);
|
||||
typedef void (Ref::*SEL_CallFuncND)(Node*, void*);
|
||||
typedef void (Ref::*SEL_CallFuncO)(Ref*);
|
||||
typedef void (Ref::*SEL_MenuHandler)(Ref*);
|
||||
typedef void (Ref::*SEL_SCHEDULE)(float);
|
||||
|
||||
#define schedule_selector(_SELECTOR) static_cast<cocos2d::SEL_SCHEDULE>(&_SELECTOR)
|
||||
#define callfunc_selector(_SELECTOR) static_cast<cocos2d::SEL_CallFunc>(&_SELECTOR)
|
||||
#define callfuncN_selector(_SELECTOR) static_cast<cocos2d::SEL_CallFuncN>(&_SELECTOR)
|
||||
#define callfuncND_selector(_SELECTOR) static_cast<cocos2d::SEL_CallFuncND>(&_SELECTOR)
|
||||
#define callfuncO_selector(_SELECTOR) static_cast<cocos2d::SEL_CallFuncO>(&_SELECTOR)
|
||||
#define menu_selector(_SELECTOR) static_cast<cocos2d::SEL_MenuHandler>(&_SELECTOR)
|
||||
#define event_selector(_SELECTOR) static_cast<cocos2d::SEL_EventHandler>(&_SELECTOR)
|
||||
#define compare_selector(_SELECTOR) static_cast<cocos2d::SEL_Compare>(&_SELECTOR)
|
||||
|
||||
// new callbacks based on C++11
|
||||
#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__)
|
||||
#define CC_CALLBACK_3(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3 ##__VA_ARGS__)
|
||||
#define schedule_selector(_SELECTOR) static_cast<cocos2d::SEL_SCHEDULE>(&_SELECTOR)
|
||||
|
||||
// end of base_nodes group
|
||||
/// @}
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // __CCOBJECT_H__
|
||||
#endif // __CCREF_H__
|
|
@ -31,12 +31,12 @@ NS_CC_BEGIN
|
|||
|
||||
__Set::__Set(void)
|
||||
{
|
||||
_set = new set<Object *>;
|
||||
_set = new set<Ref *>;
|
||||
}
|
||||
|
||||
__Set::__Set(const __Set &r__SetObject)
|
||||
__Set::__Set(const __Set &other)
|
||||
{
|
||||
_set = new set<Object *>(*r__SetObject._set);
|
||||
_set = new set<Ref *>(*other._set);
|
||||
|
||||
// call retain of members
|
||||
__SetIterator iter;
|
||||
|
@ -91,7 +91,7 @@ int __Set::count(void)
|
|||
return (int)_set->size();
|
||||
}
|
||||
|
||||
void __Set::addObject(Object *pObject)
|
||||
void __Set::addObject(Ref *pObject)
|
||||
{
|
||||
if (_set->count(pObject) == 0)
|
||||
{
|
||||
|
@ -100,7 +100,7 @@ void __Set::addObject(Object *pObject)
|
|||
}
|
||||
}
|
||||
|
||||
void __Set::removeObject(Object *pObject)
|
||||
void __Set::removeObject(Ref *pObject)
|
||||
{
|
||||
if (_set->erase(pObject) > 0)
|
||||
{
|
||||
|
@ -122,14 +122,14 @@ void __Set::removeAllObjects()
|
|||
|
||||
tmp = it;
|
||||
++tmp;
|
||||
Object * obj = *it;
|
||||
Ref * obj = *it;
|
||||
_set->erase(it);
|
||||
CC_SAFE_RELEASE(obj);
|
||||
it = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
bool __Set::containsObject(Object *pObject)
|
||||
bool __Set::containsObject(Ref *pObject)
|
||||
{
|
||||
return _set->find(pObject) != _set->end();
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ __SetIterator __Set::end(void)
|
|||
return _set->end();
|
||||
}
|
||||
|
||||
Object* __Set::anyObject()
|
||||
Ref* __Set::anyObject()
|
||||
{
|
||||
if (!_set || _set->empty())
|
||||
{
|
||||
|
|
|
@ -27,7 +27,8 @@ THE SOFTWARE.
|
|||
#define __CC_SET_H__
|
||||
|
||||
#include <set>
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCDataVisitor.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -36,9 +37,9 @@ NS_CC_BEGIN
|
|||
* @{
|
||||
*/
|
||||
|
||||
typedef std::set<Object *>::iterator __SetIterator;
|
||||
typedef std::set<Ref *>::iterator __SetIterator;
|
||||
|
||||
class CC_DLL __Set : public Object
|
||||
class CC_DLL __Set : public Ref
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -72,11 +73,11 @@ public:
|
|||
/**
|
||||
*@brief Add a element into Set, it will retain the element.
|
||||
*/
|
||||
void addObject(Object *pObject);
|
||||
void addObject(Ref *pObject);
|
||||
/**
|
||||
*@brief Remove the given element, nothing todo if no element equals pObject.
|
||||
*/
|
||||
void removeObject(Object *pObject);
|
||||
void removeObject(Ref *pObject);
|
||||
/**
|
||||
*@brief Remove all elements of the set
|
||||
*/
|
||||
|
@ -84,7 +85,7 @@ public:
|
|||
/**
|
||||
*@brief Check if Set contains a element equals pObject.
|
||||
*/
|
||||
bool containsObject(Object *pObject);
|
||||
bool containsObject(Ref *pObject);
|
||||
/**
|
||||
*@brief Return the iterator that points to the first element.
|
||||
* @js NA
|
||||
|
@ -100,7 +101,7 @@ public:
|
|||
/**
|
||||
*@brief Return the first element if it contains elements, or null if it doesn't contain any element.
|
||||
*/
|
||||
Object* anyObject();
|
||||
Ref* anyObject();
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
@ -108,7 +109,7 @@ public:
|
|||
virtual void acceptVisitor(DataVisitor &visitor);
|
||||
|
||||
private:
|
||||
std::set<Object *> *_set;
|
||||
std::set<Ref *> *_set;
|
||||
};
|
||||
|
||||
// end of data_structure group
|
||||
|
|
|
@ -203,7 +203,7 @@ __Array* __String::componentsSeparatedByString(const char *delimiter)
|
|||
return result;
|
||||
}
|
||||
|
||||
bool __String::isEqual(const Object* pObject)
|
||||
bool __String::isEqual(const Ref* pObject)
|
||||
{
|
||||
bool bRet = false;
|
||||
const __String* pStr = dynamic_cast<const __String*>(pObject);
|
||||
|
|
|
@ -33,8 +33,8 @@ THE SOFTWARE.
|
|||
#include <string>
|
||||
#include <functional>
|
||||
#include <sstream>
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCArray.h"
|
||||
#include "CCRef.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -43,7 +43,7 @@ NS_CC_BEGIN
|
|||
* @{
|
||||
*/
|
||||
|
||||
class CC_DLL __String : public Object, public Clonable
|
||||
class CC_DLL __String : public Ref, public Clonable
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -145,7 +145,7 @@ public:
|
|||
/* override functions
|
||||
* @js NA
|
||||
*/
|
||||
virtual bool isEqual(const Object* pObject);
|
||||
virtual bool isEqual(const Ref* pObject);
|
||||
|
||||
/** create a string with std string, you can also pass a c string pointer because the default constructor of std::string can access a c string pointer.
|
||||
* @return A String pointer which is an autorelease object pointer,
|
||||
|
|
|
@ -27,7 +27,7 @@ THE SOFTWARE.
|
|||
#define __CCVECTOR_H__
|
||||
|
||||
#include "ccMacros.h"
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <algorithm> // for std::find
|
||||
|
@ -69,14 +69,14 @@ public:
|
|||
Vector<T>()
|
||||
: _data()
|
||||
{
|
||||
static_assert(std::is_convertible<T, Object*>::value, "Invalid Type for cocos2d::Vector<T>!");
|
||||
static_assert(std::is_convertible<T, Ref*>::value, "Invalid Type for cocos2d::Vector<T>!");
|
||||
}
|
||||
|
||||
/** Constructor with a capacity */
|
||||
explicit Vector<T>(ssize_t capacity)
|
||||
: _data()
|
||||
{
|
||||
static_assert(std::is_convertible<T, Object*>::value, "Invalid Type for cocos2d::Vector<T>!");
|
||||
static_assert(std::is_convertible<T, Ref*>::value, "Invalid Type for cocos2d::Vector<T>!");
|
||||
CCLOGINFO("In the default constructor with capacity of Vector.");
|
||||
reserve(capacity);
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ public:
|
|||
/** Copy constructor */
|
||||
Vector<T>(const Vector<T>& other)
|
||||
{
|
||||
static_assert(std::is_convertible<T, Object*>::value, "Invalid Type for cocos2d::Vector<T>!");
|
||||
static_assert(std::is_convertible<T, Ref*>::value, "Invalid Type for cocos2d::Vector<T>!");
|
||||
CCLOGINFO("In the copy constructor!");
|
||||
_data = other._data;
|
||||
addRefForAllObjects();
|
||||
|
@ -100,7 +100,7 @@ public:
|
|||
/** Move constructor */
|
||||
Vector<T>(Vector<T>&& other)
|
||||
{
|
||||
static_assert(std::is_convertible<T, Object*>::value, "Invalid Type for cocos2d::Vector<T>!");
|
||||
static_assert(std::is_convertible<T, Ref*>::value, "Invalid Type for cocos2d::Vector<T>!");
|
||||
CCLOGINFO("In the move constructor of Vector!");
|
||||
_data = std::move(other._data);
|
||||
}
|
||||
|
@ -251,7 +251,7 @@ public:
|
|||
|
||||
for (ssize_t i = 0; i < s; i++)
|
||||
{
|
||||
if (!this->at(i)->isEqual(other.at(i)))
|
||||
if (this->at(i) != other.at(i))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -188,9 +188,9 @@ CCBAnimationManagerDelegate* CCBAnimationManager::getDelegate()
|
|||
|
||||
void CCBAnimationManager::setDelegate(CCBAnimationManagerDelegate *pDelegate)
|
||||
{
|
||||
CC_SAFE_RELEASE(dynamic_cast<Object*>(_delegate));
|
||||
CC_SAFE_RELEASE(dynamic_cast<Ref*>(_delegate));
|
||||
_delegate = pDelegate;
|
||||
CC_SAFE_RETAIN(dynamic_cast<Object*>(_delegate));
|
||||
CC_SAFE_RETAIN(dynamic_cast<Ref*>(_delegate));
|
||||
}
|
||||
|
||||
const char* CCBAnimationManager::getRunningSequenceName()
|
||||
|
@ -234,7 +234,7 @@ const Value& CCBAnimationManager::getBaseValue(Node *pNode, const std::string& p
|
|||
return props[propName];
|
||||
}
|
||||
|
||||
void CCBAnimationManager::setObject(Object* obj, Node *pNode, const std::string& propName)
|
||||
void CCBAnimationManager::setObject(Ref* obj, Node *pNode, const std::string& propName)
|
||||
{
|
||||
auto& props = _objects[pNode];
|
||||
auto iter = props.find(propName);
|
||||
|
@ -245,7 +245,7 @@ void CCBAnimationManager::setObject(Object* obj, Node *pNode, const std::string&
|
|||
obj->retain();
|
||||
}
|
||||
|
||||
Object* CCBAnimationManager::getObject(Node *pNode, const std::string& propName)
|
||||
Ref* CCBAnimationManager::getObject(Node *pNode, const std::string& propName)
|
||||
{
|
||||
auto& props = _objects[pNode];
|
||||
auto iter = props.find(propName);
|
||||
|
@ -420,7 +420,7 @@ ActionInterval* CCBAnimationManager::getAction(CCBKeyframe *pKeyframe0, CCBKeyfr
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void CCBAnimationManager::setAnimatedProperty(const std::string& propName, Node *pNode, const Value& value, Object* obj, float fTweenDuration)
|
||||
void CCBAnimationManager::setAnimatedProperty(const std::string& propName, Node *pNode, const Value& value, Ref* obj, float fTweenDuration)
|
||||
{
|
||||
if (fTweenDuration > 0)
|
||||
{
|
||||
|
@ -615,7 +615,7 @@ ActionInterval* CCBAnimationManager::getEaseAction(ActionInterval *pAction, CCBK
|
|||
}
|
||||
}
|
||||
|
||||
Object* CCBAnimationManager::actionForCallbackChannel(CCBSequenceProperty* channel) {
|
||||
Sequence* CCBAnimationManager::actionForCallbackChannel(CCBSequenceProperty* channel) {
|
||||
|
||||
float lastKeyframeTime = 0;
|
||||
|
||||
|
@ -655,7 +655,7 @@ Object* CCBAnimationManager::actionForCallbackChannel(CCBSequenceProperty* chann
|
|||
}
|
||||
else
|
||||
{
|
||||
Object* target = nullptr;
|
||||
Ref* target = nullptr;
|
||||
|
||||
if(selectorTarget == CCBReader::TargetType::DOCUMENT_ROOT)
|
||||
target = _rootNode;
|
||||
|
@ -681,7 +681,7 @@ Object* CCBAnimationManager::actionForCallbackChannel(CCBSequenceProperty* chann
|
|||
}
|
||||
else
|
||||
{
|
||||
auto savedTarget = std::make_shared<Vector<Object*>>();
|
||||
auto savedTarget = std::make_shared<Vector<Ref*>>();
|
||||
savedTarget->pushBack(target);
|
||||
|
||||
auto callback = CallFuncN::create([savedTarget, selCallFunc](Node* sender){
|
||||
|
@ -701,10 +701,10 @@ Object* CCBAnimationManager::actionForCallbackChannel(CCBSequenceProperty* chann
|
|||
}
|
||||
if(actions.size() < 1) return nullptr;
|
||||
|
||||
return (Object *) Sequence::create(actions);
|
||||
return Sequence::create(actions);
|
||||
}
|
||||
|
||||
Object* CCBAnimationManager::actionForSoundChannel(CCBSequenceProperty* channel) {
|
||||
Sequence* CCBAnimationManager::actionForSoundChannel(CCBSequenceProperty* channel) {
|
||||
|
||||
float lastKeyframeTime = 0;
|
||||
|
||||
|
@ -901,7 +901,7 @@ void CCBAnimationManager::debug()
|
|||
|
||||
}
|
||||
|
||||
void CCBAnimationManager::setAnimationCompletedCallback(Object *target, SEL_CallFunc callbackFunc) {
|
||||
void CCBAnimationManager::setAnimationCompletedCallback(Ref *target, SEL_CallFunc callbackFunc) {
|
||||
if (target)
|
||||
{
|
||||
target->retain();
|
||||
|
|
|
@ -20,7 +20,7 @@ public:
|
|||
virtual void completedAnimationSequenceNamed(const char *name) = 0;
|
||||
};
|
||||
|
||||
class CCBAnimationManager : public cocos2d::Object
|
||||
class CCBAnimationManager : public cocos2d::Ref
|
||||
{
|
||||
public:
|
||||
bool _jsControlled;
|
||||
|
@ -35,7 +35,7 @@ public:
|
|||
~CCBAnimationManager();
|
||||
|
||||
|
||||
cocos2d::Object *_owner;
|
||||
cocos2d::Ref *_owner;
|
||||
|
||||
virtual bool init();
|
||||
|
||||
|
@ -82,7 +82,7 @@ public:
|
|||
|
||||
void addNode(cocos2d::Node *pNode, const std::unordered_map<int, cocos2d::Map<std::string, CCBSequenceProperty*>>& seq);
|
||||
void setBaseValue(const cocos2d::Value& value, cocos2d::Node *pNode, const std::string& propName);
|
||||
void setObject(cocos2d::Object* obj, cocos2d::Node *pNode, const std::string& propName);
|
||||
void setObject(cocos2d::Ref* obj, cocos2d::Node *pNode, const std::string& propName);
|
||||
|
||||
void moveAnimationsFromNode(cocos2d::Node* fromNode, cocos2d::Node* toNode);
|
||||
|
||||
|
@ -100,7 +100,7 @@ public:
|
|||
* when this function bound to js ,the second param are callfunc_selector
|
||||
* @lua NA
|
||||
*/
|
||||
void setAnimationCompletedCallback(cocos2d::Object *target, cocos2d::SEL_CallFunc callbackFunc);
|
||||
void setAnimationCompletedCallback(cocos2d::Ref *target, cocos2d::SEL_CallFunc callbackFunc);
|
||||
|
||||
void debug();
|
||||
/**
|
||||
|
@ -108,8 +108,8 @@ public:
|
|||
*/
|
||||
void setCallFunc(cocos2d::CallFunc *callFunc, const std::string &callbackNamed);
|
||||
|
||||
cocos2d::Object* actionForCallbackChannel(CCBSequenceProperty* channel);
|
||||
cocos2d::Object* actionForSoundChannel(CCBSequenceProperty* channel);
|
||||
cocos2d::Sequence* actionForCallbackChannel(CCBSequenceProperty* channel);
|
||||
cocos2d::Sequence* actionForSoundChannel(CCBSequenceProperty* channel);
|
||||
|
||||
// return -1 if timeline not exsit
|
||||
int getSequenceId(const char* pSequenceName);
|
||||
|
@ -119,11 +119,11 @@ public:
|
|||
|
||||
private:
|
||||
const cocos2d::Value& getBaseValue(cocos2d::Node *pNode, const std::string& propName);
|
||||
Object* getObject(cocos2d::Node *pNode, const std::string& propName);
|
||||
Ref* getObject(cocos2d::Node *pNode, const std::string& propName);
|
||||
|
||||
CCBSequence* getSequence(int nSequenceId);
|
||||
cocos2d::ActionInterval* getAction(CCBKeyframe *pKeyframe0, CCBKeyframe *pKeyframe1, const std::string& propName, cocos2d::Node *pNode);
|
||||
void setAnimatedProperty(const std::string& propName,cocos2d::Node *pNode, const cocos2d::Value& value, Object* obj, float fTweenDuraion);
|
||||
void setAnimatedProperty(const std::string& propName,cocos2d::Node *pNode, const cocos2d::Value& value, Ref* obj, float fTweenDuraion);
|
||||
void setFirstFrame(cocos2d::Node *pNode, CCBSequenceProperty *pSeqProp, float fTweenDuration);
|
||||
cocos2d::ActionInterval* getEaseAction(cocos2d::ActionInterval *pAction, CCBKeyframe::EasingType easingType, float fEasingOpt);
|
||||
void runAction(cocos2d::Node *pNode, CCBSequenceProperty *pSeqProp, float fTweenDuration);
|
||||
|
@ -133,7 +133,7 @@ private:
|
|||
cocos2d::Vector<CCBSequence*> _sequences;
|
||||
std::unordered_map<cocos2d::Node*, std::unordered_map<int, cocos2d::Map<std::string, CCBSequenceProperty*>>> _nodeSequences;
|
||||
std::unordered_map<cocos2d::Node*, std::unordered_map<std::string, cocos2d::Value>> _baseValues;
|
||||
std::unordered_map<cocos2d::Node*, std::unordered_map<std::string, cocos2d::Object*>> _objects;
|
||||
std::unordered_map<cocos2d::Node*, std::unordered_map<std::string, cocos2d::Ref*>> _objects;
|
||||
|
||||
int _autoPlaySequenceId;
|
||||
|
||||
|
@ -156,7 +156,8 @@ private:
|
|||
std::string _lastCompletedSequenceName;
|
||||
|
||||
cocos2d::SEL_CallFunc _animationCompleteCallbackFunc;
|
||||
cocos2d::Object *_target;
|
||||
cocos2d::Ref *_target;
|
||||
|
||||
};
|
||||
|
||||
class CCBSetSpriteFrame : public cocos2d::ActionInstant
|
||||
|
|
|
@ -26,12 +26,12 @@ void CCBKeyframe::setValue(const Value& value)
|
|||
_value = value;
|
||||
}
|
||||
|
||||
Object* CCBKeyframe::getObject() const
|
||||
Ref* CCBKeyframe::getObject() const
|
||||
{
|
||||
return _object;
|
||||
}
|
||||
|
||||
void CCBKeyframe::setObject(Object* obj)
|
||||
void CCBKeyframe::setObject(Ref* obj)
|
||||
{
|
||||
CC_SAFE_RETAIN(obj);
|
||||
CC_SAFE_RELEASE(_object);
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#ifndef __CCB_KEYFRAME_H__
|
||||
#define __CCB_KEYFRAME_H__
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCValue.h"
|
||||
|
||||
|
||||
namespace cocosbuilder {
|
||||
|
||||
class CCBKeyframe : public cocos2d::Object
|
||||
class CCBKeyframe : public cocos2d::Ref
|
||||
{
|
||||
public:
|
||||
enum class EasingType
|
||||
|
@ -45,8 +45,8 @@ public:
|
|||
const cocos2d::Value& getValue() const;
|
||||
void setValue(const cocos2d::Value& value);
|
||||
|
||||
cocos2d::Object* getObject() const;
|
||||
void setObject(cocos2d::Object* obj);
|
||||
cocos2d::Ref* getObject() const;
|
||||
void setObject(cocos2d::Ref* obj);
|
||||
|
||||
float getTime();
|
||||
void setTime(float fTime);
|
||||
|
@ -59,7 +59,7 @@ public:
|
|||
|
||||
private:
|
||||
cocos2d::Value _value;
|
||||
cocos2d::Object* _object;
|
||||
cocos2d::Ref* _object;
|
||||
float _time;
|
||||
EasingType _easingType;
|
||||
float _easingOpt;
|
||||
|
|
|
@ -39,7 +39,7 @@ class CCBMemberVariableAssigner {
|
|||
* @param node The member variable.
|
||||
* @return Whether the assignment was successful.
|
||||
*/
|
||||
virtual bool onAssignCCBMemberVariable(cocos2d::Object* target, const char* memberVariableName, cocos2d::Node* node) = 0;
|
||||
virtual bool onAssignCCBMemberVariable(cocos2d::Ref* target, const char* memberVariableName, cocos2d::Node* node) = 0;
|
||||
|
||||
/**
|
||||
* The callback function of assigning custom properties.
|
||||
|
@ -49,7 +49,7 @@ class CCBMemberVariableAssigner {
|
|||
* @param value The value of the property.
|
||||
* @return Whether the assignment was successful.
|
||||
*/
|
||||
virtual bool onAssignCCBCustomProperty(cocos2d::Object* target, const char* memberVariableName, const cocos2d::Value& value) { return false; };
|
||||
virtual bool onAssignCCBCustomProperty(cocos2d::Ref* target, const char* memberVariableName, const cocos2d::Value& value) { return false; };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -192,7 +192,7 @@ set<string>& CCBReader::getLoadedSpriteSheet()
|
|||
return _loadedSpriteSheets;
|
||||
}
|
||||
|
||||
Object* CCBReader::getOwner()
|
||||
Ref* CCBReader::getOwner()
|
||||
{
|
||||
return _owner;
|
||||
}
|
||||
|
@ -202,12 +202,12 @@ Node* CCBReader::readNodeGraphFromFile(const char *pCCBFileName)
|
|||
return this->readNodeGraphFromFile(pCCBFileName, nullptr);
|
||||
}
|
||||
|
||||
Node* CCBReader::readNodeGraphFromFile(const char* pCCBFileName, Object* pOwner)
|
||||
Node* CCBReader::readNodeGraphFromFile(const char* pCCBFileName, Ref* pOwner)
|
||||
{
|
||||
return this->readNodeGraphFromFile(pCCBFileName, pOwner, Director::getInstance()->getWinSize());
|
||||
}
|
||||
|
||||
Node* CCBReader::readNodeGraphFromFile(const char *pCCBFileName, Object *pOwner, const Size &parentSize)
|
||||
Node* CCBReader::readNodeGraphFromFile(const char *pCCBFileName, Ref *pOwner, const Size &parentSize)
|
||||
{
|
||||
if (nullptr == pCCBFileName || strlen(pCCBFileName) == 0)
|
||||
{
|
||||
|
@ -231,7 +231,7 @@ Node* CCBReader::readNodeGraphFromFile(const char *pCCBFileName, Object *pOwner,
|
|||
return ret;
|
||||
}
|
||||
|
||||
Node* CCBReader::readNodeGraphFromData(std::shared_ptr<cocos2d::Data> data, Object *pOwner, const Size &parentSize)
|
||||
Node* CCBReader::readNodeGraphFromData(std::shared_ptr<cocos2d::Data> data, Ref *pOwner, const Size &parentSize)
|
||||
{
|
||||
_data = data;
|
||||
_bytes =_data->getBytes();
|
||||
|
@ -274,12 +274,12 @@ Scene* CCBReader::createSceneWithNodeGraphFromFile(const char *pCCBFileName)
|
|||
return createSceneWithNodeGraphFromFile(pCCBFileName, nullptr);
|
||||
}
|
||||
|
||||
Scene* CCBReader::createSceneWithNodeGraphFromFile(const char *pCCBFileName, Object *pOwner)
|
||||
Scene* CCBReader::createSceneWithNodeGraphFromFile(const char *pCCBFileName, Ref *pOwner)
|
||||
{
|
||||
return createSceneWithNodeGraphFromFile(pCCBFileName, pOwner, Director::getInstance()->getWinSize());
|
||||
}
|
||||
|
||||
Scene* CCBReader::createSceneWithNodeGraphFromFile(const char *pCCBFileName, Object *pOwner, const Size &parentSize)
|
||||
Scene* CCBReader::createSceneWithNodeGraphFromFile(const char *pCCBFileName, Ref *pOwner, const Size &parentSize)
|
||||
{
|
||||
Node *pNode = readNodeGraphFromFile(pCCBFileName, pOwner, parentSize);
|
||||
Scene *pScene = Scene::create();
|
||||
|
@ -626,7 +626,7 @@ Node * CCBReader::readNodeGraph(Node * pParent)
|
|||
{
|
||||
if(!_jsControlled)
|
||||
{
|
||||
Object * target = nullptr;
|
||||
Ref* target = nullptr;
|
||||
if(memberVarAssignmentType == TargetType::DOCUMENT_ROOT)
|
||||
{
|
||||
target = _animationManager->getRootNode();
|
||||
|
@ -677,7 +677,7 @@ Node * CCBReader::readNodeGraph(Node * pParent)
|
|||
|
||||
if(!_jsControlled)
|
||||
{
|
||||
Object * target = node;
|
||||
Ref* target = node;
|
||||
if(target != nullptr)
|
||||
{
|
||||
CCBMemberVariableAssigner * targetAsCCBMemberVariableAssigner = dynamic_cast<CCBMemberVariableAssigner *>(target);
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include "CCNode.h"
|
||||
#include "CCData.h"
|
||||
#include "CCMap.h"
|
||||
|
||||
#include "CCBSequence.h"
|
||||
#include "extensions/GUI/CCControlExtension/CCControl.h"
|
||||
|
||||
|
@ -65,7 +64,7 @@ class CCBKeyframe;
|
|||
/**
|
||||
* @brief Parse CCBI file which is generated by CocosBuilder
|
||||
*/
|
||||
class CCBReader : public cocos2d::Object
|
||||
class CCBReader : public cocos2d::Ref
|
||||
{
|
||||
public:
|
||||
enum class PropertyType {
|
||||
|
@ -170,13 +169,13 @@ public:
|
|||
const std::string& getCCBRootPath() const;
|
||||
|
||||
cocos2d::Node* readNodeGraphFromFile(const char *pCCBFileName);
|
||||
cocos2d::Node* readNodeGraphFromFile(const char *pCCBFileName, cocos2d::Object *pOwner);
|
||||
cocos2d::Node* readNodeGraphFromFile(const char *pCCBFileName, cocos2d::Object *pOwner, const cocos2d::Size &parentSize);
|
||||
cocos2d::Node* readNodeGraphFromFile(const char *pCCBFileName, cocos2d::Ref *pOwner);
|
||||
cocos2d::Node* readNodeGraphFromFile(const char *pCCBFileName, cocos2d::Ref *pOwner, const cocos2d::Size &parentSize);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
cocos2d::Node* readNodeGraphFromData(std::shared_ptr<cocos2d::Data> data, cocos2d::Object *pOwner, const cocos2d::Size &parentSize);
|
||||
cocos2d::Node* readNodeGraphFromData(std::shared_ptr<cocos2d::Data> data, cocos2d::Ref *pOwner, const cocos2d::Size &parentSize);
|
||||
|
||||
/**
|
||||
@lua NA
|
||||
|
@ -185,11 +184,11 @@ public:
|
|||
/**
|
||||
@lua NA
|
||||
*/
|
||||
cocos2d::Scene* createSceneWithNodeGraphFromFile(const char *pCCBFileName, cocos2d::Object *pOwner);
|
||||
cocos2d::Scene* createSceneWithNodeGraphFromFile(const char *pCCBFileName, cocos2d::Ref *pOwner);
|
||||
/**
|
||||
@lua NA
|
||||
*/
|
||||
cocos2d::Scene* createSceneWithNodeGraphFromFile(const char *pCCBFileName, cocos2d::Object *pOwner, const cocos2d::Size &parentSize);
|
||||
cocos2d::Scene* createSceneWithNodeGraphFromFile(const char *pCCBFileName, cocos2d::Ref *pOwner, const cocos2d::Size &parentSize);
|
||||
|
||||
/**
|
||||
* @js NA
|
||||
|
@ -227,7 +226,7 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
cocos2d::Object* getOwner();
|
||||
cocos2d::Ref* getOwner();
|
||||
|
||||
/* Utility methods.
|
||||
* @js NA
|
||||
|
@ -371,7 +370,7 @@ private:
|
|||
std::vector<std::string> _stringCache;
|
||||
std::set<std::string> _loadedSpriteSheets;
|
||||
|
||||
cocos2d::Object *_owner;
|
||||
cocos2d::Ref *_owner;
|
||||
|
||||
CCBAnimationManager* _animationManager; //retain
|
||||
CCBAnimationManagerMapPtr _animationManagers;
|
||||
|
|
|
@ -25,9 +25,9 @@ class CCBSelectorResolver {
|
|||
* @lua NA
|
||||
*/
|
||||
virtual ~CCBSelectorResolver() {};
|
||||
virtual cocos2d::SEL_MenuHandler onResolveCCBCCMenuItemSelector(cocos2d::Object * pTarget, const char* pSelectorName) = 0;
|
||||
virtual cocos2d::SEL_CallFuncN onResolveCCBCCCallFuncSelector(cocos2d::Object * pTarget, const char* pSelectorName) { return NULL; };
|
||||
virtual cocos2d::extension::Control::Handler onResolveCCBCCControlSelector(cocos2d::Object * pTarget, const char* pSelectorName) = 0;
|
||||
virtual cocos2d::SEL_MenuHandler onResolveCCBCCMenuItemSelector(cocos2d::Ref * pTarget, const char* pSelectorName) = 0;
|
||||
virtual cocos2d::SEL_CallFuncN onResolveCCBCCCallFuncSelector(cocos2d::Ref * pTarget, const char* pSelectorName) { return NULL; };
|
||||
virtual cocos2d::extension::Control::Handler onResolveCCBCCControlSelector(cocos2d::Ref * pTarget, const char* pSelectorName) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCBSequenceProperty.h"
|
||||
|
||||
namespace cocosbuilder {
|
||||
|
||||
class CCBSequence : public cocos2d::Object
|
||||
class CCBSequence : public cocos2d::Ref
|
||||
{
|
||||
public:
|
||||
CCBSequence();
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#ifndef __CCB_SEQUENCE_PROPERTY_H__
|
||||
#define __CCB_SEQUENCE_PROPERTY_H__
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCVector.h"
|
||||
#include "CCBKeyframe.h"
|
||||
|
||||
namespace cocosbuilder {
|
||||
|
||||
class CCBSequenceProperty : public cocos2d::Object
|
||||
class CCBSequenceProperty : public cocos2d::Ref
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _CCB_CCLABELBMFONTLOADER_H_
|
||||
#define _CCB_CCLABELBMFONTLOADER_H_
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCLabelBMFont.h"
|
||||
|
||||
#include "CCNodeLoader.h"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _CCB_CCLABELTTFLOADER_H_
|
||||
#define _CCB_CCLABELTTFLOADER_H_
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCLabelTTF.h"
|
||||
|
||||
#include "CCNodeLoader.h"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _CCB_CCMENUITEMLOADER_H_
|
||||
#define _CCB_CCMENUITEMLOADER_H_
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCMenuItem.h"
|
||||
|
||||
#include "CCLayerLoader.h"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define _CCB_CCMENULOADER_H_
|
||||
|
||||
#include "CCLayerLoader.h"
|
||||
#include "CCObject.h"
|
||||
#include "CCRef.h"
|
||||
#include "CCMenu.h"
|
||||
|
||||
namespace cocosbuilder {
|
||||
|
|
|
@ -80,7 +80,7 @@ void NodeLoader::parseProperties(Node * pNode, Node * pParent, CCBReader * ccbRe
|
|||
|
||||
// Skip properties that doesn't have a value to override
|
||||
Array *extraPropsNames = (Array*)pNode->getUserObject();
|
||||
Object* pObj = NULL;
|
||||
Ref* pObj = NULL;
|
||||
bool bFound = false;
|
||||
CCARRAY_FOREACH(extraPropsNames, pObj)
|
||||
{
|
||||
|
@ -761,7 +761,7 @@ BlockData * NodeLoader::parsePropTypeBlock(Node * pNode, Node * pParent, CCBRead
|
|||
|
||||
if(selectorTarget != CCBReader::TargetType::NONE)
|
||||
{
|
||||
Object * target = NULL;
|
||||
Ref* target = NULL;
|
||||
if(!ccbReader->isJSControlled())
|
||||
{
|
||||
if(selectorTarget == CCBReader::TargetType::DOCUMENT_ROOT)
|
||||
|
@ -844,7 +844,7 @@ BlockControlData * NodeLoader::parsePropTypeBlockControl(Node * pNode, Node * pP
|
|||
{
|
||||
if(!ccbReader->isJSControlled())
|
||||
{
|
||||
Object * target = NULL;
|
||||
Ref* target = NULL;
|
||||
if(selectorTarget == CCBReader::TargetType::DOCUMENT_ROOT)
|
||||
{
|
||||
target = ccbReader->getAnimationManager()->getRootNode();
|
||||
|
|
|
@ -30,19 +30,19 @@ namespace cocosbuilder {
|
|||
|
||||
struct BlockData {
|
||||
cocos2d::SEL_MenuHandler mSELMenuHandler;
|
||||
cocos2d::Object * _target;
|
||||
cocos2d::Ref * _target;
|
||||
};
|
||||
|
||||
struct BlockControlData {
|
||||
cocos2d::extension::Control::Handler mSELControlHandler;
|
||||
cocos2d::Object * _target;
|
||||
cocos2d::Ref * _target;
|
||||
cocos2d::extension::Control::EventType mControlEvents;
|
||||
};
|
||||
|
||||
/* Forward declaration. */
|
||||
class CCBReader;
|
||||
|
||||
class NodeLoader : public cocos2d::Object {
|
||||
class NodeLoader : public cocos2d::Ref {
|
||||
public:
|
||||
/**
|
||||
* @js NA
|
||||
|
|
|
@ -10,7 +10,7 @@ class NodeLoader;
|
|||
typedef std::map<std::string, NodeLoader *> NodeLoaderMap;
|
||||
typedef std::pair<std::string, NodeLoader *> NodeLoaderMapEntry;
|
||||
|
||||
class NodeLoaderLibrary : public cocos2d::Object
|
||||
class NodeLoaderLibrary : public cocos2d::Ref
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче