Merge branch 'develop' of https://github.com/cocos2d/cocos2d-x into cocos-console-test

This commit is contained in:
shujunqiao 2014-03-28 13:41:18 +08:00
commit ff4b83813c
37 changed files with 413 additions and 76 deletions

View File

@ -54,6 +54,7 @@ Developers:
Add ccDrawSolidCircle
Add Rect::unionWithRect
Fix a memory leak in Set::removeAllObjects.
Fixed potential crashes in event dispatch while using SceneGraphPriroity listeners and added helper function to check it
silverscania
Pass correct parameter to glPixelStorei when creating a texture

View File

@ -1 +1 @@
63f931258263a5cf78f2e7d478324a57ccdc9794
a3a8c79daf8c98f2aea9b8ed339e11ff81a0f1ce

View File

@ -130,6 +130,16 @@ bool EventDispatcher::EventListenerVector::empty() const
void EventDispatcher::EventListenerVector::push_back(EventListener* listener)
{
#if CC_NODE_DEBUG_VERIFY_EVENT_LISTENERS
CCASSERT(_sceneGraphListeners == nullptr ||
std::count(_sceneGraphListeners->begin(), _sceneGraphListeners->end(), listener) == 0,
"Listener should not be added twice!");
CCASSERT(_fixedListeners == nullptr ||
std::count(_fixedListeners->begin(), _fixedListeners->end(), listener) == 0,
"Listener should not be added twice!");
#endif
if (listener->getFixedPriority() == 0)
{
if (_sceneGraphListeners == nullptr)
@ -314,6 +324,11 @@ void EventDispatcher::resumeEventListenersForTarget(Node* target, bool recursive
void EventDispatcher::removeEventListenersForTarget(Node* target, bool recursive/* = false */)
{
// Ensure the node is removed from these immediately also.
// Don't want any dangling pointers or the possibility of dealing with deleted objects..
_nodePriorityMap.erase(target);
_dirtyNodes.erase(target);
auto listenerIter = _nodeListenersMap.find(target);
if (listenerIter != _nodeListenersMap.end())
{
@ -440,6 +455,69 @@ void EventDispatcher::addEventListenerWithSceneGraphPriority(EventListener* list
addEventListener(listener);
}
#if CC_NODE_DEBUG_VERIFY_EVENT_LISTENERS && COCOS2D_DEBUG > 0
void EventDispatcher::debugCheckNodeHasNoEventListenersOnDestruction(Node* node)
{
// Check the listeners map
for (const auto & keyValuePair : _listenerMap)
{
const EventListenerVector * eventListenerVector = keyValuePair.second;
if (eventListenerVector)
{
if (eventListenerVector->getSceneGraphPriorityListeners())
{
for (EventListener * listener : *eventListenerVector->getSceneGraphPriorityListeners())
{
CCASSERT(!listener ||
listener->getSceneGraphPriority() != node,
"Node should have no event listeners registered for it upon destruction!");
}
}
}
}
// Check the node listeners map
for (const auto & keyValuePair : _nodeListenersMap)
{
CCASSERT(keyValuePair.first != node, "Node should have no event listeners registered for it upon destruction!");
if (keyValuePair.second)
{
for (EventListener * listener : *keyValuePair.second)
{
CCASSERT(listener->getSceneGraphPriority() != node,
"Node should have no event listeners registered for it upon destruction!");
}
}
}
// Check the node priority map
for (const auto & keyValuePair : _nodePriorityMap)
{
CCASSERT(keyValuePair.first != node,
"Node should have no event listeners registered for it upon destruction!");
}
// Check the to be added list
for (EventListener * listener : _toAddedListeners)
{
CCASSERT(listener->getSceneGraphPriority() != node,
"Node should have no event listeners registered for it upon destruction!");
}
// Check the dirty nodes set
for (Node * dirtyNode : _dirtyNodes)
{
CCASSERT(dirtyNode != node,
"Node should have no event listeners registered for it upon destruction!");
}
}
#endif // #if CC_NODE_DEBUG_VERIFY_EVENT_LISTENERS && COCOS2D_DEBUG > 0
void EventDispatcher::addEventListenerWithFixedPriority(EventListener* listener, int fixedPriority)
{
CCASSERT(listener, "Invalid parameters.");
@ -485,6 +563,7 @@ void EventDispatcher::removeEventListener(EventListener* listener)
if (l->getSceneGraphPriority() != nullptr)
{
dissociateNodeAndEventListener(l->getSceneGraphPriority(), l);
l->setSceneGraphPriority(nullptr); // NULL out the node pointer so we don't have any dangling pointers to destroyed nodes.
}
if (_inDispatch == 0)
@ -519,6 +598,18 @@ void EventDispatcher::removeEventListener(EventListener* listener)
setDirty(listener->getListenerID(), DirtyFlag::FIXED_PRIORITY);
}
}
#if CC_NODE_DEBUG_VERIFY_EVENT_LISTENERS
CCASSERT(_inDispatch != 0 ||
!sceneGraphPriorityListeners ||
std::count(sceneGraphPriorityListeners->begin(), sceneGraphPriorityListeners->end(), listener) == 0,
"Listener should be in no lists after this is done if we're not currently in dispatch mode.");
CCASSERT(_inDispatch != 0 ||
!fixedPriorityListeners ||
std::count(fixedPriorityListeners->begin(), fixedPriorityListeners->end(), listener) == 0,
"Listener should be in no lists after this is done if we're not currently in dispatch mode.");
#endif
if (iter->second->empty())
{
@ -1127,6 +1218,7 @@ void EventDispatcher::removeEventListenersForListenerID(const EventListener::Lis
if (l->getSceneGraphPriority() != nullptr)
{
dissociateNodeAndEventListener(l->getSceneGraphPriority(), l);
l->setSceneGraphPriority(nullptr); // NULL out the node pointer so we don't have any dangling pointers to destroyed nodes.
}
if (_inDispatch == 0)

View File

@ -140,6 +140,16 @@ public:
/** Destructor of EventDispatcher */
~EventDispatcher();
#if CC_NODE_DEBUG_VERIFY_EVENT_LISTENERS && COCOS2D_DEBUG > 0
/**
* To help track down event listener issues in debug builds.
* Verifies that the node has no event listeners associated with it when destroyed.
*/
void debugCheckNodeHasNoEventListenersOnDestruction(Node* node);
#endif
protected:
friend class Node;

View File

@ -39,6 +39,14 @@ FT_Library FontFreeType::_FTlibrary;
bool FontFreeType::_FTInitialized = false;
const int FontFreeType::DistanceMapSpread = 3;
typedef struct _DataRef
{
Data data;
unsigned int referenceCount;
}DataRef;
static std::unordered_map<std::string, DataRef> s_cacheFontData;
FontFreeType * FontFreeType::create(const std::string &fontName, int fontSize, GlyphCollection glyphs, const char *customGlyphs,bool distanceFieldEnabled /* = false */,int outline /* = 0 */)
{
FontFreeType *tempFont = new FontFreeType(distanceFieldEnabled,outline);
@ -105,16 +113,28 @@ FontFreeType::FontFreeType(bool distanceFieldEnabled /* = false */,int outline /
bool FontFreeType::createFontObject(const std::string &fontName, int fontSize)
{
FT_Face face;
// save font name locally
_fontName = fontName;
_ttfData = FileUtils::getInstance()->getDataFromFile(fontName);
auto it = s_cacheFontData.find(fontName);
if (it != s_cacheFontData.end())
{
(*it).second.referenceCount += 1;
}
else
{
s_cacheFontData[fontName].referenceCount = 1;
s_cacheFontData[fontName].data = FileUtils::getInstance()->getDataFromFile(fontName);
if (s_cacheFontData[fontName].data.isNull())
{
return false;
}
}
if (FT_New_Memory_Face(getFTLibrary(), s_cacheFontData[fontName].data.getBytes(), s_cacheFontData[fontName].data.getSize(), 0, &face ))
return false;
if (_ttfData.isNull())
return false;
// create the face from the data
if (FT_New_Memory_Face(getFTLibrary(), _ttfData.getBytes(), _ttfData.getSize(), 0, &face ))
return false;
//we want to use unicode
if (FT_Select_Charmap(face, FT_ENCODING_UNICODE))
return false;
@ -128,9 +148,6 @@ bool FontFreeType::createFontObject(const std::string &fontName, int fontSize)
// store the face globally
_fontRef = face;
// save font name locally
_fontName = fontName;
// done and good
return true;
}
@ -145,6 +162,12 @@ FontFreeType::~FontFreeType()
{
FT_Done_Face(_fontRef);
}
s_cacheFontData[_fontName].referenceCount -= 1;
if (s_cacheFontData[_fontName].referenceCount == 0)
{
s_cacheFontData.erase(_fontName);
}
}
FontAtlas * FontFreeType::createFontAtlas()

View File

@ -26,9 +26,6 @@
#ifndef _FontFreetype_h_
#define _FontFreetype_h_
#include "CCFont.h"
#include "CCData.h"
@ -91,7 +88,6 @@ private:
FT_Face _fontRef;
FT_Stroker _stroker;
std::string _fontName;
Data _ttfData;
bool _distanceFieldEnabled;
int _outlineSize;
};

View File

@ -1364,6 +1364,13 @@ const Size& Label::getContentSize() const
return Node::getContentSize();
}
Rect Label::getBoundingBox() const
{
const_cast<Label*>(this)->getContentSize();
return Node::getBoundingBox();
}
void Label::listenToBackground(EventCustom *event)
{
#if CC_ENABLE_CACHE_TEXTURE_DATA

View File

@ -243,6 +243,8 @@ public:
virtual const Size& getContentSize() const override;
virtual Rect getBoundingBox() const;
FontAtlas* getFontAtlas() { return _fontAtlas; }
/** Listen "come to background" message
It only has effect on Android.

View File

@ -154,15 +154,15 @@ Node::~Node()
}
#endif
CC_SAFE_RELEASE(_actionManager);
CC_SAFE_RELEASE(_scheduler);
CC_SAFE_RELEASE_NULL(_actionManager);
CC_SAFE_RELEASE_NULL(_scheduler);
_eventDispatcher->removeEventListenersForTarget(this);
CC_SAFE_RELEASE(_eventDispatcher);
// attributes
CC_SAFE_RELEASE(_shaderProgram);
CC_SAFE_RELEASE(_userObject);
CC_SAFE_RELEASE_NULL(_shaderProgram);
CC_SAFE_RELEASE_NULL(_userObject);
for (auto& child : _children)
{
@ -175,7 +175,14 @@ Node::~Node()
#if CC_USE_PHYSICS
setPhysicsBody(nullptr);
#endif
#if CC_NODE_DEBUG_VERIFY_EVENT_LISTENERS && COCOS2D_DEBUG > 0
_eventDispatcher->debugCheckNodeHasNoEventListenersOnDestruction(this);
#endif
CC_SAFE_RELEASE(_eventDispatcher);
}
bool Node::init()

View File

@ -685,7 +685,6 @@ void ParticleSystem::update(float dt)
currentPosition = _position;
}
if (_visible)
{
while (_particleIdx < _particleCount)
{
@ -826,7 +825,9 @@ void ParticleSystem::update(float dt)
} //while
_transformSystemDirty = false;
}
if (! _batchNode)
// only update gl buffer when visible
if (_visible && ! _batchNode)
{
postStep();
}

View File

@ -360,7 +360,7 @@ void ParticleSystemQuad::postStep()
// overriding draw method
void ParticleSystemQuad::draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated)
{
CCASSERT( _particleIdx == _particleCount, "Abnormal error in particle quad");
CCASSERT( _particleIdx == 0 || _particleIdx == _particleCount, "Abnormal error in particle quad");
//quad command
if(_particleIdx > 0)
{

View File

@ -240,6 +240,17 @@ To enable set it to a value different than 0. Disabled by default.
#define CC_LABELATLAS_DEBUG_DRAW 0
#endif
/** @def CC_NODE_DEBUG_VERIFY_EVENT_LISTENERS
If enabled (in conjunction with assertion macros) will verify on Node destruction that the node being destroyed has no event
listeners still associated with it in the event dispatcher. This can be used to track down problems where the event dispatch
system has dangling pointers to destroyed nodes.
Note: event listener verification will always be disabled in builds where assertions are disabled regardless of this setting.
*/
#ifndef CC_NODE_DEBUG_VERIFY_EVENT_LISTENERS
#define CC_NODE_DEBUG_VERIFY_EVENT_LISTENERS 0
#endif
/** @def CC_ENABLE_PROFILERS
If enabled, will activate various profilers within cocos2d. This statistical data will be output to the console
once per second showing average time (in milliseconds) required to execute the specific routine(s).

View File

@ -31,7 +31,7 @@ NS_CC_BEGIN
const char* cocos2dVersion()
{
return "3.0-rc0";
return "3.0-rc1";
}
NS_CC_END

View File

@ -12,7 +12,7 @@ namespace cocosbuilder {
void LabelBMFontLoader::onHandlePropTypeColor3(Node * pNode, Node * pParent, const char * pPropertyName, Color3B pColor3B, CCBReader * ccbReader) {
if(strcmp(pPropertyName, PROPERTY_COLOR) == 0) {
((LabelBMFont *)pNode)->setColor(pColor3B);
((Label *)pNode)->setColor(pColor3B);
} else {
NodeLoader::onHandlePropTypeColor3(pNode, pParent, pPropertyName, pColor3B, ccbReader);
}
@ -20,7 +20,7 @@ void LabelBMFontLoader::onHandlePropTypeColor3(Node * pNode, Node * pParent, con
void LabelBMFontLoader::onHandlePropTypeByte(Node * pNode, Node * pParent, const char * pPropertyName, unsigned char pByte, CCBReader * ccbReader) {
if(strcmp(pPropertyName, PROPERTY_OPACITY) == 0) {
((LabelBMFont *)pNode)->setOpacity(pByte);
((Label *)pNode)->setOpacity(pByte);
} else {
NodeLoader::onHandlePropTypeByte(pNode, pParent, pPropertyName, pByte, ccbReader);
}
@ -28,7 +28,7 @@ void LabelBMFontLoader::onHandlePropTypeByte(Node * pNode, Node * pParent, const
void LabelBMFontLoader::onHandlePropTypeBlendFunc(Node * pNode, Node * pParent, const char * pPropertyName, BlendFunc pBlendFunc, CCBReader * ccbReader) {
if(strcmp(pPropertyName, PROPERTY_BLENDFUNC) == 0) {
((LabelBMFont *)pNode)->setBlendFunc(pBlendFunc);
((Label *)pNode)->setBlendFunc(pBlendFunc);
} else {
NodeLoader::onHandlePropTypeBlendFunc(pNode, pParent, pPropertyName, pBlendFunc, ccbReader);
}
@ -36,7 +36,7 @@ void LabelBMFontLoader::onHandlePropTypeBlendFunc(Node * pNode, Node * pParent,
void LabelBMFontLoader::onHandlePropTypeFntFile(Node * pNode, Node * pParent, const char * pPropertyName, const char* pFntFile, CCBReader * ccbReader) {
if(strcmp(pPropertyName, PROPERTY_FNTFILE) == 0) {
((LabelBMFont *)pNode)->setFntFile(pFntFile);
((Label *)pNode)->setBMFontFilePath(pFntFile);
} else {
NodeLoader::onHandlePropTypeFntFile(pNode, pParent, pPropertyName, pFntFile, ccbReader);
}
@ -44,7 +44,7 @@ void LabelBMFontLoader::onHandlePropTypeFntFile(Node * pNode, Node * pParent, co
void LabelBMFontLoader::onHandlePropTypeText(Node * pNode, Node * pParent, const char * pPropertyName, const char* pText, CCBReader * ccbReader) {
if(strcmp(pPropertyName, PROPERTY_STRING) == 0) {
((LabelBMFont *)pNode)->setString(pText);
((Label *)pNode)->setString(pText);
} else {
NodeLoader::onHandlePropTypeText(pNode, pParent, pPropertyName, pText, ccbReader);
}

View File

@ -2,7 +2,7 @@
#define _CCB_CCLABELBMFONTLOADER_H_
#include "CCRef.h"
#include "CCLabelBMFont.h"
#include "CCLabel.h"
#include "CCNodeLoader.h"
@ -21,7 +21,7 @@ public:
CCB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(LabelBMFontLoader, loader);
protected:
CCB_VIRTUAL_NEW_AUTORELEASE_CREATECCNODE_METHOD(cocos2d::LabelBMFont);
CCB_VIRTUAL_NEW_AUTORELEASE_CREATECCNODE_METHOD(cocos2d::Label);
virtual void onHandlePropTypeColor3(cocos2d::Node * pNode, cocos2d::Node * pParent, const char * pPropertyName, cocos2d::Color3B pColor3B, CCBReader * ccbReader);
virtual void onHandlePropTypeByte(cocos2d::Node * pNode, cocos2d::Node * pParent, const char * pPropertyName, unsigned char pByte, CCBReader * ccbReader);

View File

@ -94,6 +94,11 @@
-- @param self
-- @return FontDefinition#FontDefinition ret (return value: cc.FontDefinition)
--------------------------------
-- @function [parent=#Label] getBoundingBox
-- @param self
-- @return rect_table#rect_table ret (return value: rect_table)
--------------------------------
-- @function [parent=#Label] getFontName
-- @param self

View File

@ -1 +1 @@
491f36052e7ee592286d55bcb9b0425b7ca95332
506177408f7bc44ccba9d2518adbf47e8994bc83

View File

@ -1561,6 +1561,7 @@ int register_all_cocos2dx(lua_State* tolua_S);
#endif // __cocos2dx_h__

View File

@ -59,7 +59,7 @@ TextBMFont* TextBMFont::create()
void TextBMFont::initRenderer()
{
_labelBMFontRenderer = cocos2d::LabelBMFont::create();
_labelBMFontRenderer = cocos2d::Label::create();
addProtectedChild(_labelBMFontRenderer, LABELBMFONT_RENDERER_Z, -1);
}
@ -70,7 +70,7 @@ void TextBMFont::setFntFile(const char *fileName)
return;
}
_fntFileName = fileName;
_labelBMFontRenderer->initWithString("", fileName);
_labelBMFontRenderer->setBMFontFilePath(fileName);
updateAnchorPoint();
labelBMFontScaleChangedWithSize();
_fntFileHasInit = true;

View File

@ -81,7 +81,7 @@ protected:
virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override;
protected:
cocos2d::LabelBMFont* _labelBMFontRenderer;
cocos2d::Label* _labelBMFontRenderer;
bool _fntFileHasInit;
std::string _fntFileName;
std::string _stringValue;

View File

@ -90,14 +90,14 @@ bool ControlButton::initWithLabelAndBackgroundSprite(Node* node, Scale9Sprite* b
// Set the default anchor point
ignoreAnchorPointForPosition(false);
setAnchorPoint(Point(0.5f, 0.5f));
setAnchorPoint(Point::ANCHOR_MIDDLE);
// Set the nodes
setTitleLabel(node);
setBackgroundSprite(backgroundSprite);
// Set the default color and opacity
setColor(Color3B(255.0f, 255.0f, 255.0f));
setColor(Color3B::WHITE);
setOpacity(255.0f);
setOpacityModifyRGB(true);
@ -108,7 +108,7 @@ bool ControlButton::initWithLabelAndBackgroundSprite(Node* node, Scale9Sprite* b
setTitleLabelForState(node, Control::State::NORMAL);
setBackgroundSpriteForState(backgroundSprite, Control::State::NORMAL);
setLabelAnchorPoint(Point(0.5f, 0.5f));
setLabelAnchorPoint(Point::ANCHOR_MIDDLE);
// Layout update
needsLayout();
@ -409,16 +409,16 @@ float ControlButton::getTitleTTFSizeForState(State state)
void ControlButton::setTitleBMFontForState(const std::string& fntFile, State state)
{
std::string title = this->getTitleForState(state);
this->setTitleLabelForState(LabelBMFont::create(title, fntFile), state);
this->setTitleLabelForState(Label::createWithBMFont(fntFile, title), state);
}
const std::string& ControlButton::getTitleBMFontForState(State state)
{
LabelProtocol* label = dynamic_cast<LabelProtocol*>(this->getTitleLabelForState(state));
LabelBMFont* labelBMFont = dynamic_cast<LabelBMFont*>(label);
auto labelBMFont = dynamic_cast<Label*>(label);
if(labelBMFont != 0)
{
return labelBMFont->getFntFile();
return labelBMFont->getBMFontFilePath();
}
static std::string ret("");

View File

@ -134,7 +134,7 @@ public:
virtual float getTitleTTFSizeForState(State state);
/**
* Sets the font of the label, changes the label to a LabelBMFont if neccessary.
* Sets the font of the label, changes the label to a BMFont if neccessary.
* @param fntFile The name of the font to change to
* @param state The state that uses the specified fntFile. The values are described
* in "CCControlState".

View File

@ -24,7 +24,7 @@ Control::Handler ButtonTestLayer::onResolveCCBCCControlSelector(Ref * pTarget, c
}
bool ButtonTestLayer::onAssignCCBMemberVariable(Ref * pTarget, const char * pMemberVariableName, Node * pNode) {
CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mCCControlEventLabel", LabelBMFont *, this->mControlEventLabel);
CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mCCControlEventLabel", Label *, this->mControlEventLabel);
return false;
}

View File

@ -23,7 +23,7 @@ public:
void onControlButtonClicked(cocos2d::Ref * sender, cocos2d::extension::Control::EventType pControlEvent);
private:
cocos2d::LabelBMFont * mControlEventLabel;
cocos2d::Label * mControlEventLabel;
};
#endif

View File

@ -5,7 +5,7 @@ USING_NS_CC_EXT;
using namespace cocosbuilder;
MenuTestLayer::MenuTestLayer()
: mMenuItemStatusLabelBMFont(NULL)
: mMenuItemStatusLabelBMFont(nullptr)
{}
MenuTestLayer::~MenuTestLayer()
@ -18,15 +18,15 @@ SEL_MenuHandler MenuTestLayer::onResolveCCBCCMenuItemSelector(Ref * pTarget, con
CCB_SELECTORRESOLVER_CCMENUITEM_GLUE(this, "onMenuItemBClicked", MenuTestLayer::onMenuItemBClicked);
CCB_SELECTORRESOLVER_CCMENUITEM_GLUE(this, "onMenuItemCClicked", MenuTestLayer::onMenuItemCClicked);
return NULL;
return nullptr;
}
Control::Handler MenuTestLayer::onResolveCCBCCControlSelector(Ref * pTarget, const char * pSelectorName) {
return NULL;
return nullptr;
}
bool MenuTestLayer::onAssignCCBMemberVariable(Ref * pTarget, const char * pMemberVariableName, Node * pNode) {
CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mMenuItemStatusLabelBMFont", LabelBMFont *, this->mMenuItemStatusLabelBMFont);
CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mMenuItemStatusLabelBMFont", Label *, this->mMenuItemStatusLabelBMFont);
return false;
}

View File

@ -25,7 +25,7 @@ class MenuTestLayer
void onMenuItemCClicked(cocos2d::Ref * sender);
private:
cocos2d::LabelBMFont * mMenuItemStatusLabelBMFont;
cocos2d::Label * mMenuItemStatusLabelBMFont;
};
#endif

View File

@ -24,11 +24,11 @@ IntervalLayer::IntervalLayer()
this->addChild(sun);
// timers
_label0 = LabelBMFont::create("0", "fonts/bitmapFontTest4.fnt");
_label1 = LabelBMFont::create("0", "fonts/bitmapFontTest4.fnt");
_label2 = LabelBMFont::create("0", "fonts/bitmapFontTest4.fnt");
_label3 = LabelBMFont::create("0", "fonts/bitmapFontTest4.fnt");
_label4 = LabelBMFont::create("0", "fonts/bitmapFontTest4.fnt");
_label0 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0");
_label1 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0");
_label2 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0");
_label3 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0");
_label4 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0");
scheduleUpdate();
schedule(schedule_selector(IntervalLayer::step1));

View File

@ -6,11 +6,11 @@
class IntervalLayer : public Layer
{
protected:
LabelBMFont* _label0;
LabelBMFont* _label1;
LabelBMFont* _label2;
LabelBMFont* _label3;
LabelBMFont* _label4;
Label* _label0;
Label* _label1;
Label* _label2;
Label* _label3;
Label* _label4;
float _time0, _time1, _time2, _time3, _time4;

View File

@ -134,7 +134,7 @@ void LayerTestCascadingOpacityA::onEnter()
auto sister1 = Sprite::create("Images/grossinis_sister1.png");
auto sister2 = Sprite::create("Images/grossinis_sister2.png");
auto label = LabelBMFont::create("Test", "fonts/bitmapFontTest.fnt");
auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Test");
layer1->addChild(sister1);
layer1->addChild(sister2);
@ -186,7 +186,7 @@ void LayerTestCascadingOpacityB::onEnter()
auto sister1 = Sprite::create("Images/grossinis_sister1.png");
auto sister2 = Sprite::create("Images/grossinis_sister2.png");
auto label = LabelBMFont::create("Test", "fonts/bitmapFontTest.fnt");
auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Test");
layer1->addChild(sister1);
layer1->addChild(sister2);
@ -239,7 +239,7 @@ void LayerTestCascadingOpacityC::onEnter()
auto sister1 = Sprite::create("Images/grossinis_sister1.png");
auto sister2 = Sprite::create("Images/grossinis_sister2.png");
auto label = LabelBMFont::create("Test", "fonts/bitmapFontTest.fnt");
auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Test");
layer1->addChild(sister1);
layer1->addChild(sister2);
@ -287,7 +287,7 @@ void LayerTestCascadingColorA::onEnter()
auto sister1 = Sprite::create("Images/grossinis_sister1.png");
auto sister2 = Sprite::create("Images/grossinis_sister2.png");
auto label = LabelBMFont::create("Test", "fonts/bitmapFontTest.fnt");
auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Test");
layer1->addChild(sister1);
layer1->addChild(sister2);
@ -340,7 +340,7 @@ void LayerTestCascadingColorB::onEnter()
auto sister1 = Sprite::create("Images/grossinis_sister1.png");
auto sister2 = Sprite::create("Images/grossinis_sister2.png");
auto label = LabelBMFont::create("Test", "fonts/bitmapFontTest.fnt");
auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Test");
layer1->addChild(sister1);
layer1->addChild(sister2);
@ -392,7 +392,7 @@ void LayerTestCascadingColorC::onEnter()
auto sister1 = Sprite::create("Images/grossinis_sister1.png");
auto sister2 = Sprite::create("Images/grossinis_sister2.png");
auto label = LabelBMFont::create("Test", "fonts/bitmapFontTest.fnt");
auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Test");
layer1->addChild(sister1);
layer1->addChild(sister2);

View File

@ -84,7 +84,7 @@ MenuLayerMainMenu::MenuLayerMainMenu()
item4->setFontName("fonts/Marker Felt.ttf");
// Label Item (LabelBMFont)
auto label = LabelBMFont::create("configuration", "fonts/bitmapFontTest3.fnt");
auto label = Label::createWithBMFont("fonts/bitmapFontTest3.fnt", "configuration");
auto item5 = MenuItemLabel::create(label, CC_CALLBACK_1(MenuLayerMainMenu::menuCallbackConfig, this));
// Testing issue #500
@ -323,7 +323,7 @@ MenuLayer3::MenuLayer3()
MenuItemFont::setFontName("fonts/Marker Felt.ttf");
MenuItemFont::setFontSize(28);
auto label = LabelBMFont::create("Enable AtlasItem", "fonts/bitmapFontTest3.fnt");
auto label = Label::createWithBMFont("fonts/bitmapFontTest3.fnt", "Enable AtlasItem");
auto item1 = MenuItemLabel::create(label, [&](Ref *sender) {
//CCLOG("Label clicked. Toogling AtlasSprite");
_disabledItem->setEnabled( ! _disabledItem->isEnabled() );
@ -435,7 +435,7 @@ MenuLayer4::MenuLayer4()
MenuItemFont::setFontName( "fonts/Marker Felt.ttf" );
MenuItemFont::setFontSize( 34 );
auto label = LabelBMFont::create( "go back", "fonts/bitmapFontTest3.fnt" );
auto label = Label::createWithBMFont("fonts/bitmapFontTest3.fnt", "go back");
auto back = MenuItemLabel::create(label, CC_CALLBACK_1(MenuLayer4::backCallback, this) );
auto menu = Menu::create(

View File

@ -26,7 +26,8 @@ std::function<Layer*()> createFunctions[] =
CL(StopPropagationTest),
CL(PauseResumeTargetTest),
CL(Issue4129),
CL(Issue4160)
CL(Issue4160),
CL(DanglingNodePointersTest)
};
unsigned int TEST_CASE_COUNT = sizeof(createFunctions) / sizeof(createFunctions[0]);
@ -1278,3 +1279,131 @@ std::string Issue4160::subtitle() const
{
return "Touch the red block twice \n should not crash and the red one couldn't be touched";
}
// DanglingNodePointersTest
class DanglingNodePointersTestSprite : public Sprite
{
public:
typedef std::function<void (DanglingNodePointersTestSprite * sprite)> TappedCallback;
static DanglingNodePointersTestSprite * create(const TappedCallback & tappedCallback)
{
auto ret = new DanglingNodePointersTestSprite(tappedCallback);
if (ret && ret->init())
{
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);
return nullptr;
}
protected:
DanglingNodePointersTestSprite(const TappedCallback & tappedCallback)
:
_eventListener(nullptr),
_tappedCallback(tappedCallback)
{
}
public:
void onEnter() override
{
Sprite::onEnter();
_eventListener = EventListenerTouchOneByOne::create();
_eventListener->setSwallowTouches(false);
_eventListener->onTouchBegan = [this](Touch* touch, Event* event) -> bool
{
_tappedCallback(this);
return false; // Don't claim the touch so it can propagate
};
_eventListener->onTouchEnded = [](Touch* touch, Event* event)
{
// Do nothing
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(_eventListener, this);
}
void onExit() override
{
_eventDispatcher->removeEventListenersForTarget(this);
_eventListener = nullptr;
Sprite::onExit();
}
private:
EventListenerTouchOneByOne * _eventListener;
int _fixedPriority;
TappedCallback _tappedCallback;
};
DanglingNodePointersTest::DanglingNodePointersTest()
{
#if CC_NODE_DEBUG_VERIFY_EVENT_LISTENERS == 1 && COCOS2D_DEBUG > 0
Point origin = Director::getInstance()->getVisibleOrigin();
Size size = Director::getInstance()->getVisibleSize();
auto callback2 = [](DanglingNodePointersTestSprite * sprite2)
{
CCASSERT(false, "This should never be called because the sprite gets removed from it's parent and destroyed!");
exit(1);
};
auto callback1 = [callback2, origin, size](DanglingNodePointersTestSprite * sprite1)
{
DanglingNodePointersTestSprite * sprite2 = dynamic_cast<DanglingNodePointersTestSprite*>(sprite1->getChildren().at(0));
CCASSERT(sprite2, "The first child of sprite 1 should be sprite 2!");
CCASSERT(sprite2->getReferenceCount() == 1, "There should only be 1 reference to sprite 1, from it's parent node. Hence removing it will destroy it!");
sprite1->removeAllChildren(); // This call should cause sprite 2 to be destroyed
// Recreate sprite 1 again
sprite2 = DanglingNodePointersTestSprite::create(callback2);
sprite2->setTexture("Images/MagentaSquare.png");
sprite2->setPosition(origin+Point(size.width/2, size.height/2));
sprite1->addChild(sprite2, -20);
};
auto sprite1 = DanglingNodePointersTestSprite::create(callback1); // Sprite 1 will receive touch before sprite 2
sprite1->setTexture("Images/CyanSquare.png");
sprite1->setPosition(origin+Point(size.width/2, size.height/2));
addChild(sprite1, -10);
auto sprite2 = DanglingNodePointersTestSprite::create(callback2); // Sprite 2 will be removed when sprite 1 is touched, should never receive an event.
sprite2->setTexture("Images/MagentaSquare.png");
sprite2->setPosition(origin+Point(size.width/2, size.height/2));
sprite1->addChild(sprite2, -20);
#endif
}
DanglingNodePointersTest::~DanglingNodePointersTest()
{
}
std::string DanglingNodePointersTest::title() const
{
return "DanglingNodePointersTest";
}
std::string DanglingNodePointersTest::subtitle() const
{
#if CC_NODE_DEBUG_VERIFY_EVENT_LISTENERS == 1 && COCOS2D_DEBUG > 0
return "Tap the square - should not crash!";
#else
return "For test to work, must be compiled with:\n"
"CC_NODE_DEBUG_VERIFY_EVENT_LISTENERS == 1\n&& COCOS2D_DEBUG > 0";
#endif
}

View File

@ -206,4 +206,15 @@ public:
private:
};
class DanglingNodePointersTest : public EventDispatcherTestDemo
{
public:
CREATE_FUNC(DanglingNodePointersTest);
DanglingNodePointersTest();
virtual ~DanglingNodePointersTest();
virtual std::string title() const override;
virtual std::string subtitle() const override;
};
#endif /* defined(__samples__NewEventDispatcherTest__) */

View File

@ -1009,13 +1009,14 @@ Layer* createParticleLayer(int nIndex)
case 43: return new PremultipliedAlphaTest2();
case 44: return new Issue3990();
case 45: return new ParticleAutoBatching();
case 46: return new ParticleVisibleTest();
default:
break;
}
return NULL;
}
#define MAX_LAYER 46
#define MAX_LAYER 47
Layer* nextParticleAction()
@ -1939,6 +1940,37 @@ std::string Issue3990::subtitle() const
}
// ParticleVisibleTest
void ParticleVisibleTest::onEnter()
{
ParticleDemo::onEnter();
_emitter = ParticleFireworks::create();
_emitter->retain();
_background->addChild(_emitter, 10);
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_stars1) );
schedule(schedule_selector(ParticleVisibleTest::callback), 1);
setEmitterPosition();
}
std::string ParticleVisibleTest::title() const
{
return "Issue4573";
}
std::string ParticleVisibleTest::subtitle() const
{
return "Visible enable/disable";
}
void ParticleVisibleTest::callback(float delta)
{
_emitter->setVisible(!_emitter->isVisible());
}
//
// ParticleAutoBatching
//

View File

@ -310,6 +310,15 @@ public:
virtual std::string subtitle() const override;
};
class ParticleVisibleTest : public ParticleDemo
{
public:
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
void callback(float delta);
};
class ParticleAutoBatching : public ParticleDemo
{
public:

View File

@ -204,7 +204,7 @@ void LabelMainScene::onIncrease(Ref* sender)
case kCaseLabelBMFontUpdate:
for( int i=0;i< kNodesIncrease;i++)
{
auto label = LabelBMFont::create("LabelBMFont", "fonts/bitmapFontTest3.fnt");
auto label = Label::createWithBMFont("fonts/bitmapFontTest3.fnt","LabelBMFont");
label->setPosition(Point((size.width/2 + rand() % 50), ((int)size.height/2 + rand() % 50)));
_labelContainer->addChild(label, 1, _quantityNodes);
@ -227,7 +227,7 @@ void LabelMainScene::onIncrease(Ref* sender)
case kCaseLabelBMFontBigLabels:
for( int i=0;i< kNodesIncrease;i++)
{
auto label = LabelBMFont::create(LongSentencesExample, "fonts/bitmapFontTest3.fnt");
auto label = Label::createWithBMFont("fonts/bitmapFontTest3.fnt", LongSentencesExample);
label->setPosition(Point((size.width/2 + rand() % 50), ((int)size.height/2 + rand() % 50)));
_labelContainer->addChild(label, 1, _quantityNodes);
@ -329,7 +329,7 @@ void LabelMainScene::updateText(float dt)
break;
case kCaseLabelBMFontUpdate:
for(const auto &child : children) {
LabelBMFont* label = (LabelBMFont*)child;
auto label = (Label*)child;
label->setString(text);
}
break;

View File

@ -79,7 +79,7 @@ void TouchesMainScene::onEnter()
scheduleUpdate();
_plabel = LabelBMFont::create("00.0", "fonts/arial16.fnt");
_plabel = Label::createWithBMFont("fonts/arial16.fnt","00.0");
_plabel->setPosition(Point(s.width/2, s.height/2));
addChild(_plabel);

View File

@ -18,7 +18,7 @@ public:
virtual void update(float dt) override;
protected:
LabelBMFont * _plabel;
Label * _plabel;
int numberOfTouchesB;
int numberOfTouchesM;
int numberOfTouchesE;