closed #2865: Deprecates CCNotificationCenter, uses EventDispatcher instead.

This commit is contained in:
James Chen 2013-12-31 10:54:37 +08:00
parent 1d8ee016e5
commit cf006df9ff
23 changed files with 126 additions and 156 deletions

View File

@ -545,7 +545,8 @@ CC_DEPRECATED_ATTRIBUTE typedef IMEDelegate CCIMEDelegate;
CC_DEPRECATED_ATTRIBUTE typedef IMEKeyboardNotificationInfo CCIMEKeyboardNotificationInfo;
CC_DEPRECATED_ATTRIBUTE typedef TextFieldDelegate CCTextFieldDelegate;
CC_DEPRECATED_ATTRIBUTE typedef TextFieldTTF CCTextFieldTTF;
CC_DEPRECATED_ATTRIBUTE typedef NotificationCenter CCNotificationCenter;
CC_DEPRECATED_ATTRIBUTE typedef __NotificationCenter CCNotificationCenter;
CC_DEPRECATED_ATTRIBUTE typedef __NotificationCenter NotificationCenter;
//CC_DEPRECATED_ATTRIBUTE typedef TargetedTouchDelegate CCTargetedTouchDelegate;
//CC_DEPRECATED_ATTRIBUTE typedef StandardTouchDelegate CCStandardTouchDelegate;
//CC_DEPRECATED_ATTRIBUTE typedef TouchDelegate CCTouchDelegate;

View File

@ -37,7 +37,6 @@ THE SOFTWARE.
#include "CCArray.h"
#include "CCScheduler.h"
#include "ccMacros.h"
#include "CCNotificationCenter.h"
#include "CCTransition.h"
#include "CCTextureCache.h"
#include "CCSpriteFrameCache.h"
@ -768,7 +767,6 @@ void Director::purgeDirector()
// cocos2d-x specific data structures
UserDefault::destroyInstance();
NotificationCenter::destroyInstance();
GL::invalidateStateCache();

View File

@ -23,12 +23,13 @@
#include "CCDrawNode.h"
#include "CCShaderCache.h"
#include "CCGL.h"
#include "CCNotificationCenter.h"
#include "CCEventType.h"
#include "CCConfiguration.h"
#include "CCCustomCommand.h"
#include "CCDirector.h"
#include "CCRenderer.h"
#include "CCEventListenerCustom.h"
#include "CCEventDispatcher.h"
NS_CC_BEGIN
@ -124,10 +125,6 @@ DrawNode::~DrawNode()
GL::bindVAO(0);
_vao = 0;
}
#if CC_ENABLE_CACHE_TEXTURE_DATA
NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND);
#endif
}
DrawNode* DrawNode::create()
@ -196,10 +193,12 @@ bool DrawNode::init()
#if CC_ENABLE_CACHE_TEXTURE_DATA
// Need to listen the event only when not use batchnode, because it will use VBO
NotificationCenter::getInstance()->addObserver(this,
callfuncO_selector(DrawNode::listenBackToForeground),
EVNET_COME_TO_FOREGROUND,
nullptr);
auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom* event){
/** listen the event that coming to foreground on Android */
this->init();
});
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
#endif
return true;
@ -472,11 +471,4 @@ void DrawNode::setBlendFunc(const BlendFunc &blendFunc)
_blendFunc = blendFunc;
}
/** listen the event that coming to foreground on Android
*/
void DrawNode::listenBackToForeground(Object *obj)
{
init();
}
NS_CC_END

View File

@ -78,12 +78,6 @@ public:
* @lua NA
*/
void setBlendFunc(const BlendFunc &blendFunc);
/** listen the event that coming to foreground on Android
* @js NA
* @lua NA
*/
void listenBackToForeground(Object *obj);
void onDraw();

View File

@ -9,7 +9,7 @@
// The application will come to foreground.
// This message is used for reloading resources before come to foreground on Android.
// This message is posted in main.cpp.
#define EVNET_COME_TO_FOREGROUND "event_come_to_foreground"
#define EVENT_COME_TO_FOREGROUND "event_come_to_foreground"
// The application will come to background.
// This message is used for doing something before coming to background, such as save RenderTexture.

View File

@ -31,50 +31,50 @@ using namespace std;
NS_CC_BEGIN
static NotificationCenter *s_sharedNotifCenter = nullptr;
static __NotificationCenter *s_sharedNotifCenter = nullptr;
NotificationCenter::NotificationCenter()
__NotificationCenter::__NotificationCenter()
: _scriptHandler(0)
{
_observers = __Array::createWithCapacity(3);
_observers->retain();
}
NotificationCenter::~NotificationCenter()
__NotificationCenter::~__NotificationCenter()
{
_observers->release();
}
NotificationCenter *NotificationCenter::getInstance()
__NotificationCenter *__NotificationCenter::getInstance()
{
if (!s_sharedNotifCenter)
{
s_sharedNotifCenter = new NotificationCenter;
s_sharedNotifCenter = new __NotificationCenter;
}
return s_sharedNotifCenter;
}
void NotificationCenter::destroyInstance()
void __NotificationCenter::destroyInstance()
{
CC_SAFE_RELEASE_NULL(s_sharedNotifCenter);
}
// XXX: deprecated
NotificationCenter *NotificationCenter::sharedNotificationCenter(void)
__NotificationCenter *__NotificationCenter::sharedNotificationCenter(void)
{
return NotificationCenter::getInstance();
return __NotificationCenter::getInstance();
}
// XXX: deprecated
void NotificationCenter::purgeNotificationCenter(void)
void __NotificationCenter::purgeNotificationCenter(void)
{
NotificationCenter::destroyInstance();
__NotificationCenter::destroyInstance();
}
//
// internal functions
//
bool NotificationCenter::observerExisted(Object *target, const std::string& name, Object *sender)
bool __NotificationCenter::observerExisted(Object *target, const std::string& name, Object *sender)
{
Object* obj = nullptr;
CCARRAY_FOREACH(_observers, obj)
@ -92,7 +92,7 @@ bool NotificationCenter::observerExisted(Object *target, const std::string& name
//
// observer functions
//
void NotificationCenter::addObserver(Object *target,
void __NotificationCenter::addObserver(Object *target,
SEL_CallFuncO selector,
const std::string& name,
Object *sender)
@ -108,7 +108,7 @@ void NotificationCenter::addObserver(Object *target,
_observers->addObject(observer);
}
void NotificationCenter::removeObserver(Object *target, const std::string& name)
void __NotificationCenter::removeObserver(Object *target, const std::string& name)
{
Object* obj = nullptr;
CCARRAY_FOREACH(_observers, obj)
@ -125,7 +125,7 @@ void NotificationCenter::removeObserver(Object *target, const std::string& name)
}
}
int NotificationCenter::removeAllObservers(Object *target)
int __NotificationCenter::removeAllObservers(Object *target)
{
Object *obj = nullptr;
__Array *toRemove = __Array::create();
@ -146,7 +146,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( Object *target, int handler,const std::string& name)
{
if (this->observerExisted(target, name, nullptr))
@ -161,7 +161,7 @@ void NotificationCenter::registerScriptObserver( Object *target, int handler,con
_observers->addObject(observer);
}
void NotificationCenter::unregisterScriptObserver(Object *target,const std::string& name)
void __NotificationCenter::unregisterScriptObserver(Object *target,const std::string& name)
{
Object* obj = nullptr;
CCARRAY_FOREACH(_observers, obj)
@ -177,7 +177,7 @@ void NotificationCenter::unregisterScriptObserver(Object *target,const std::stri
}
}
void NotificationCenter::postNotification(const std::string& name, Object *sender)
void __NotificationCenter::postNotification(const std::string& name, Object *sender)
{
__Array* ObserversCopy = __Array::createWithCapacity(_observers->count());
ObserversCopy->addObjectsFromArray(_observers);
@ -198,12 +198,12 @@ void NotificationCenter::postNotification(const std::string& name, Object *sende
}
}
void NotificationCenter::postNotification(const std::string& name)
void __NotificationCenter::postNotification(const std::string& name)
{
this->postNotification(name,nullptr);
}
int NotificationCenter::getObserverHandlerByName(const std::string& name)
int __NotificationCenter::getObserverHandlerByName(const std::string& name)
{
if (name.empty())
{

View File

@ -31,29 +31,29 @@ THE SOFTWARE.
NS_CC_BEGIN
class ScriptHandlerMgr;
class CC_DLL NotificationCenter : public Object
class CC_DLL __NotificationCenter : public Object
{
friend class ScriptHandlerMgr;
public:
/** NotificationCenter constructor
/** __NotificationCenter constructor
* @js ctor
*/
NotificationCenter();
__NotificationCenter();
/** NotificationCenter destructor
/** __NotificationCenter destructor
* @js NA
* @lua NA
*/
~NotificationCenter();
~__NotificationCenter();
/** Gets the single instance of NotificationCenter. */
static NotificationCenter *getInstance();
/** Gets the single instance of __NotificationCenter. */
static __NotificationCenter *getInstance();
/** Destroys the single instance of NotificationCenter. */
/** Destroys the single instance of __NotificationCenter. */
static void destroyInstance();
/** @deprecated use getInstance() instead */
CC_DEPRECATED_ATTRIBUTE static NotificationCenter *sharedNotificationCenter(void);
CC_DEPRECATED_ATTRIBUTE static __NotificationCenter *sharedNotificationCenter(void);
/** @deprecated use destroyInstance() instead */
CC_DEPRECATED_ATTRIBUTE static void purgeNotificationCenter(void);

View File

@ -35,7 +35,6 @@ THE SOFTWARE.
#include "ccGLStateCache.h"
#include "CCGLProgram.h"
#include "TransformUtils.h"
#include "CCNotificationCenter.h"
#include "CCEventType.h"
#include "CCConfiguration.h"
#include "CCRenderer.h"
@ -44,6 +43,8 @@ THE SOFTWARE.
// extern
#include "kazmath/GL/matrix.h"
#include "CCEventListenerCustom.h"
#include "CCEventDispatcher.h"
NS_CC_BEGIN
@ -74,10 +75,8 @@ bool ParticleSystemQuad::initWithTotalParticles(int numberOfParticles)
#if CC_ENABLE_CACHE_TEXTURE_DATA
// Need to listen the event only when not use batchnode, because it will use VBO
NotificationCenter::getInstance()->addObserver(this,
callfuncO_selector(ParticleSystemQuad::listenBackToForeground),
EVNET_COME_TO_FOREGROUND,
nullptr);
auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, CC_CALLBACK_1(ParticleSystemQuad::listenBackToForeground, this));
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
#endif
return true;
@ -106,10 +105,6 @@ ParticleSystemQuad::~ParticleSystemQuad()
GL::bindVAO(0);
}
}
#if CC_ENABLE_CACHE_TEXTURE_DATA
NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND);
#endif
}
// implementation ParticleSystemQuad
@ -576,7 +571,7 @@ void ParticleSystemQuad::setupVBO()
CHECK_GL_ERROR_DEBUG();
}
void ParticleSystemQuad::listenBackToForeground(Object *obj)
void ParticleSystemQuad::listenBackToForeground(EventCustom* event)
{
if (Configuration::getInstance()->supportsShareableVAO())
{

View File

@ -33,6 +33,7 @@ THE SOFTWARE.
NS_CC_BEGIN
class SpriteFrame;
class EventCustom;
/**
* @addtogroup particle_nodes
@ -81,7 +82,7 @@ public:
* @js NA
* @lua NA
*/
void listenBackToForeground(Object *obj);
void listenBackToForeground(EventCustom* event);
// Overrides
/**

View File

@ -34,7 +34,6 @@ THE SOFTWARE.
#include "CCTextureCache.h"
#include "platform/CCFileUtils.h"
#include "CCGL.h"
#include "CCNotificationCenter.h"
#include "CCEventType.h"
#include "CCGrid.h"
@ -44,6 +43,8 @@ THE SOFTWARE.
// extern
#include "kazmath/GL/matrix.h"
#include "CCEventListenerCustom.h"
#include "CCEventDispatcher.h"
NS_CC_BEGIN
@ -66,15 +67,11 @@ RenderTexture::RenderTexture()
#if CC_ENABLE_CACHE_TEXTURE_DATA
// Listen this event to save render texture before come to background.
// Then it can be restored after coming to foreground on Android.
NotificationCenter::getInstance()->addObserver(this,
callfuncO_selector(RenderTexture::listenToBackground),
EVENT_COME_TO_BACKGROUND,
nullptr);
NotificationCenter::getInstance()->addObserver(this,
callfuncO_selector(RenderTexture::listenToForeground),
EVNET_COME_TO_FOREGROUND, // this is misspelt
nullptr);
auto toBackgroundListener = EventListenerCustom::create(EVENT_COME_TO_BACKGROUND, CC_CALLBACK_1(RenderTexture::listenToBackground, this));
_eventDispatcher->addEventListenerWithSceneGraphPriority(toBackgroundListener, this);
auto toForegroundListener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, CC_CALLBACK_1(RenderTexture::listenToForeground, this));
_eventDispatcher->addEventListenerWithSceneGraphPriority(toForegroundListener, this);
#endif
}
@ -89,14 +86,9 @@ RenderTexture::~RenderTexture()
glDeleteRenderbuffers(1, &_depthRenderBufffer);
}
CC_SAFE_DELETE(_UITextureImage);
#if CC_ENABLE_CACHE_TEXTURE_DATA
NotificationCenter::getInstance()->removeObserver(this, EVENT_COME_TO_BACKGROUND);
NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND);
#endif
}
void RenderTexture::listenToBackground(cocos2d::Object *obj)
void RenderTexture::listenToBackground(EventCustom *event)
{
#if CC_ENABLE_CACHE_TEXTURE_DATA
CC_SAFE_DELETE(_UITextureImage);
@ -124,7 +116,7 @@ void RenderTexture::listenToBackground(cocos2d::Object *obj)
#endif
}
void RenderTexture::listenToForeground(cocos2d::Object *obj)
void RenderTexture::listenToForeground(EventCustom *event)
{
#if CC_ENABLE_CACHE_TEXTURE_DATA
// -- regenerate frame buffer object and attach the texture

View File

@ -34,6 +34,8 @@ THE SOFTWARE.
NS_CC_BEGIN
class EventCustom;
/**
* @addtogroup textures
* @{
@ -111,12 +113,12 @@ public:
/** Listen "come to background" message, and save render texture.
It only has effect on Android.
*/
void listenToBackground(Object *obj);
void listenToBackground(EventCustom *event);
/** Listen "come to foreground" message and restore the frame buffer object
It only has effect on Android.
*/
void listenToForeground(Object *obj);
void listenToForeground(EventCustom *event);
/** Valid flags: GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT. They can be OR'ed. Valid when "autoDraw" is true. */
inline unsigned int getClearFlags() const { return _clearFlags; };

View File

@ -41,7 +41,6 @@ NS_CC_BEGIN
class Timer;
class Layer;
class MenuItem;
class NotificationCenter;
class CallFunc;
class Acceleration;

View File

@ -30,7 +30,6 @@ THE SOFTWARE.
#include "ccMacros.h"
#include "CCGLProgram.h"
#include "ccGLStateCache.h"
#include "CCNotificationCenter.h"
#include "CCEventType.h"
#include "CCDirector.h"
#include "CCGL.h"
@ -39,6 +38,8 @@ THE SOFTWARE.
#include "CCTexture2D.h"
#include "CCString.h"
#include <stdlib.h>
#include "CCEventDispatcher.h"
#include "CCEventListenerCustom.h"
//According to some tests GL_TRIANGLE_STRIP is slower, MUCH slower. Probably I'm doing something very wrong
@ -70,7 +71,7 @@ TextureAtlas::~TextureAtlas()
CC_SAFE_RELEASE(_texture);
#if CC_ENABLE_CACHE_TEXTURE_DATA
NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND);
Director::getInstance()->getEventDispatcher()->removeEventListener(_backToForegroundlistener);
#endif
}
@ -185,10 +186,8 @@ bool TextureAtlas::initWithTexture(Texture2D *texture, ssize_t capacity)
#if CC_ENABLE_CACHE_TEXTURE_DATA
// listen the event when app go to background
NotificationCenter::getInstance()->addObserver(this,
callfuncO_selector(TextureAtlas::listenBackToForeground),
EVNET_COME_TO_FOREGROUND,
nullptr);
_backToForegroundlistener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, CC_CALLBACK_1(TextureAtlas::listenBackToForeground, this));
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_backToForegroundlistener, -1);
#endif
this->setupIndices();
@ -207,7 +206,7 @@ bool TextureAtlas::initWithTexture(Texture2D *texture, ssize_t capacity)
return true;
}
void TextureAtlas::listenBackToForeground(Object *obj)
void TextureAtlas::listenBackToForeground(EventCustom* event)
{
if (Configuration::getInstance()->supportsShareableVAO())
{

View File

@ -35,6 +35,8 @@ THE SOFTWARE.
NS_CC_BEGIN
class Texture2D;
class EventCustom;
class EventListenerCustom;
/**
* @addtogroup textures
@ -184,7 +186,7 @@ public:
void drawQuads();
/** listen the event that coming to foreground on Android
*/
void listenBackToForeground(Object *obj);
void listenBackToForeground(EventCustom* event);
/** whether or not the array buffer of the VBO needs to be updated*/
inline bool isDirty(void) { return _dirty; }
@ -235,6 +237,8 @@ protected:
Texture2D* _texture;
/** Quads that are going to be rendered */
V3F_C4B_T2F_Quad* _quads;
EventListenerCustom* _backToForegroundlistener;
};
// end of textures group

View File

@ -3,8 +3,6 @@
#include "CCDirector.h"
#include "../CCApplication.h"
#include "platform/CCFileUtils.h"
#include "CCEventType.h"
#include "CCNotificationCenter.h"
#include <jni.h>
using namespace cocos2d;

View File

@ -17,7 +17,6 @@
#include "CCDirector.h"
#include "CCApplication.h"
#include "CCEventType.h"
#include "CCNotificationCenter.h"
#include "CCFileUtilsAndroid.h"
#include "jni/JniHelper.h"
@ -28,6 +27,7 @@
#include "CCEventDispatcher.h"
#include "CCEventAcceleration.h"
#include "CCEventKeyboard.h"
#include "CCEventCustom.h"
#include "jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h"
@ -140,7 +140,8 @@ static void cocos_init(cocos_dimensions d, struct android_app* app) {
cocos2d::ShaderCache::getInstance()->reloadDefaultShaders();
cocos2d::DrawPrimitives::init();
cocos2d::VolatileTextureMgr::reloadAllTextures();
cocos2d::NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
cocos2d::EventCustom foregroundEvent(EVENT_COME_TO_FOREGROUND);
cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&foregroundEvent);
cocos2d::Director::getInstance()->setGLDefaultValues();
}
}
@ -557,12 +558,14 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
break;
case APP_CMD_LOST_FOCUS:
cocos2d::Application::getInstance()->applicationDidEnterBackground();
cocos2d::NotificationCenter::getInstance()->postNotification(EVENT_COME_TO_BACKGROUND, NULL);
// Also stop animating.
engine->animating = 0;
engine_draw_frame(engine);
{
cocos2d::Application::getInstance()->applicationDidEnterBackground();
cocos2d::EventCustom backgroundEvent(EVENT_COME_TO_BACKGROUND);
cocos2d::EventDispatcher::getInstance()->dispatchEvent(&backgroundEvent);
// Also stop animating.
engine->animating = 0;
engine_draw_frame(engine);
}
break;
}
}

View File

@ -29,7 +29,9 @@
#include "renderer/CCQuadCommand.h"
#include "CCGroupCommand.h"
#include "CCConfiguration.h"
#include "CCNotificationCenter.h"
#include "CCDirector.h"
#include "CCEventDispatcher.h"
#include "CCEventListenerCustom.h"
#include "CCEventType.h"
#include <algorithm> // for std::stable_sort
@ -45,6 +47,7 @@ Renderer::Renderer()
,_lastCommand(0)
,_numQuads(0)
,_glViewAssigned(false)
,_cacheTextureListener(nullptr)
{
_commandGroupStack.push(DEFAULT_RENDER_QUEUE);
@ -66,18 +69,19 @@ Renderer::~Renderer()
GL::bindVAO(0);
}
#if CC_ENABLE_CACHE_TEXTURE_DATA
NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND);
Director::getInstance()->getEventDispatcher()->removeEventListener(_cacheTextureListener);
#endif
}
void Renderer::initGLView()
{
#if CC_ENABLE_CACHE_TEXTURE_DATA
// listen the event when app go to background
NotificationCenter::getInstance()->addObserver(this,
callfuncO_selector(Renderer::onBackToForeground),
EVNET_COME_TO_FOREGROUND,
nullptr);
_cacheTextureListener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom* event){
/** listen the event that coming to foreground on Android */
this->setupBuffer();
});
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_cacheTextureListener, -1);
#endif
setupIndices();
@ -87,12 +91,6 @@ void Renderer::initGLView()
_glViewAssigned = true;
}
void Renderer::onBackToForeground(Object* obj)
{
CC_UNUSED_PARAM(obj);
setupBuffer();
}
void Renderer::setupIndices()
{
for( int i=0; i < VBO_SIZE; i++)

View File

@ -35,6 +35,8 @@
NS_CC_BEGIN
class EventListenerCustom;
typedef std::vector<RenderCommand*> RenderQueue;
struct RenderStackElement
@ -43,7 +45,7 @@ struct RenderStackElement
size_t currentIndex;
};
class Renderer : public Object
class Renderer
{
public:
static const int VBO_SIZE = 65536 / 6;
@ -76,8 +78,6 @@ protected:
//Draw the previews queued quads and flush previous context
void flush();
void onBackToForeground(Object* obj);
std::stack<int> _commandGroupStack;
std::stack<RenderStackElement> _renderStack;
@ -96,6 +96,10 @@ protected:
int _numQuads;
bool _glViewAssigned;
#if CC_ENABLE_CACHE_TEXTURE_DATA
EventListenerCustom* _cacheTextureListener;
#endif
};
NS_CC_END

View File

@ -122,7 +122,6 @@ ShaderNode::ShaderNode()
ShaderNode::~ShaderNode()
{
NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND);
}
ShaderNode* ShaderNode::shaderNodeWithVertex(const char *vert, const char *frag)
@ -136,10 +135,14 @@ ShaderNode* ShaderNode::shaderNodeWithVertex(const char *vert, const char *frag)
bool ShaderNode::initWithVertex(const char *vert, const char *frag)
{
NotificationCenter::getInstance()->addObserver(this,
callfuncO_selector(ShaderNode::listenBackToForeground),
EVNET_COME_TO_FOREGROUND,
NULL);
#if CC_ENABLE_CACHE_TEXTURE_DATA
auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom* event){
this->setShaderProgram(NULL);
loadShaderVertex(_vertFileName.c_str(), _fragFileName.c_str());
});
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
#endif
loadShaderVertex(vert, frag);
@ -157,12 +160,6 @@ bool ShaderNode::initWithVertex(const char *vert, const char *frag)
return true;
}
void ShaderNode::listenBackToForeground(Object *obj)
{
this->setShaderProgram(NULL);
loadShaderVertex(_vertFileName.c_str(), _fragFileName.c_str());
}
void ShaderNode::loadShaderVertex(const char *vert, const char *frag)
{
auto shader = new GLProgram();
@ -437,7 +434,6 @@ public:
bool initWithTexture(Texture2D* texture, const Rect& rect);
void draw();
void initProgram();
void listenBackToForeground(Object *obj);
static SpriteBlur* create(const char *pszFileName);
@ -454,7 +450,6 @@ private:
SpriteBlur::~SpriteBlur()
{
NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND);
}
SpriteBlur* SpriteBlur::create(const char *pszFileName)
@ -472,20 +467,18 @@ SpriteBlur* SpriteBlur::create(const char *pszFileName)
return pRet;
}
void SpriteBlur::listenBackToForeground(Object *obj)
{
setShaderProgram(NULL);
initProgram();
}
bool SpriteBlur::initWithTexture(Texture2D* texture, const Rect& rect)
{
if( Sprite::initWithTexture(texture, rect) )
{
NotificationCenter::getInstance()->addObserver(this,
callfuncO_selector(SpriteBlur::listenBackToForeground),
EVNET_COME_TO_FOREGROUND,
NULL);
#if CC_ENABLE_CACHE_TEXTURE_DATA
auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom* event){
setShaderProgram(NULL);
initProgram();
});
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
#endif
auto s = getTexture()->getContentSizeInPixels();

View File

@ -118,7 +118,6 @@ public:
bool initWithVertex(const char *vert, const char *frag);
void loadShaderVertex(const char *vert, const char *frag);
void listenBackToForeground(Object *obj);
virtual void update(float dt);
virtual void setPosition(const Point &newPosition);

View File

@ -133,21 +133,17 @@ ShaderSprite::ShaderSprite()
ShaderSprite::~ShaderSprite()
{
NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND);
}
void ShaderSprite::listenBackToForeground(Object *obj)
{
setShaderProgram(NULL);
initShader();
}
void ShaderSprite::setBackgroundNotification()
{
NotificationCenter::getInstance()->addObserver(this,
callfuncO_selector(ShaderSprite::listenBackToForeground),
EVNET_COME_TO_FOREGROUND,
NULL);
#if CC_ENABLE_CACHE_TEXTURE_DATA
auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom* event){
this->setShaderProgram(nullptr);
this->initShader();
});
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
#endif
}
void ShaderSprite::initShader()

View File

@ -108,7 +108,8 @@ skip = Node::[^setPosition$ setGrid setGLServerState description getUserObject .
Application::[^application.* ^run$],
Camera::[getEyeXYZ getCenterXYZ getUpXYZ],
ccFontDefinition::[*],
NewTextureAtlas::[*]
NewTextureAtlas::[*],
RenderTexture::[listenToBackground listenToForeground]
rename_functions = SpriteFrameCache::[addSpriteFramesWithFile=addSpriteFrames getSpriteFrameByName=getSpriteFrame],
MenuItemFont::[setFontNameObj=setFontName setFontSizeObj=setFontSize getFontSizeObj=getFontSize getFontNameObj=getFontName],

View File

@ -112,7 +112,8 @@ skip = Node::[setGLServerState description getUserObject .*UserData getGLServerS
EGLViewProtocol::[setTouchDelegate],
EGLView::[end swapBuffers],
NewTextureAtlas::[*],
DisplayLinkDirector::[mainLoop setAnimationInterval startAnimation stopAnimation]
DisplayLinkDirector::[mainLoop setAnimationInterval startAnimation stopAnimation],
RenderTexture::[listenToBackground listenToForeground]
rename_functions = SpriteFrameCache::[addSpriteFramesWithFile=addSpriteFrames getSpriteFrameByName=getSpriteFrame],
ProgressTimer::[setReverseProgress=setReverseDirection],