mirror of https://github.com/axmolengine/axmol.git
Merge pull request #5156 from minggo/deprecate-function
deprecated some functions in Object
This commit is contained in:
commit
9c6a65baba
|
@ -218,7 +218,7 @@ bool FontAtlasCache::releaseFontAtlas(FontAtlas *atlas)
|
|||
{
|
||||
if ( item.second == atlas )
|
||||
{
|
||||
if( atlas->isSingleReference() )
|
||||
if (atlas->getReferenceCount() == 1)
|
||||
{
|
||||
_atlasMap.erase(item.first);
|
||||
}
|
||||
|
|
|
@ -293,7 +293,7 @@ void SpriteFrameCache::removeUnusedSpriteFrames()
|
|||
for (auto iter = _spriteFrames.begin(); iter != _spriteFrames.end(); ++iter)
|
||||
{
|
||||
SpriteFrame* spriteFrame = iter->second;
|
||||
if( spriteFrame->retainCount() == 1 )
|
||||
if( spriteFrame->getReferenceCount() == 1 )
|
||||
{
|
||||
toRemoveFrames.push_back(iter->first);
|
||||
CCLOG("cocos2d: SpriteFrameCache: removing unused frame: %s", iter->first.c_str());
|
||||
|
|
|
@ -386,7 +386,7 @@ void TextureCache::removeUnusedTextures()
|
|||
{
|
||||
for( auto it=_textures.cbegin(); it!=_textures.cend(); /* nothing */) {
|
||||
Texture2D *tex = it->second;
|
||||
if( tex->retainCount() == 1 ) {
|
||||
if( tex->getReferenceCount() == 1 ) {
|
||||
CCLOG("cocos2d: TextureCache: removing unused texture: %s", it->first.c_str());
|
||||
|
||||
tex->release();
|
||||
|
@ -485,7 +485,7 @@ std::string TextureCache::getCachedTextureInfo() const
|
|||
count++;
|
||||
snprintf(buftmp,sizeof(buftmp)-1,"\"%s\" rc=%lu id=%lu %lu x %lu @ %ld bpp => %lu KB\n",
|
||||
it->first.c_str(),
|
||||
(long)tex->retainCount(),
|
||||
(long)tex->getReferenceCount(),
|
||||
(long)tex->getName(),
|
||||
(long)tex->getPixelsWide(),
|
||||
(long)tex->getPixelsHigh(),
|
||||
|
|
|
@ -69,7 +69,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->retainCount());
|
||||
CCLOG("%20p%20u%20u\n", obj, obj->_ID, obj->getReferenceCount());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ NS_CC_BEGIN
|
|||
|
||||
Object::Object()
|
||||
: _luaID(0)
|
||||
, _reference(1) // when the object is created, the reference count of it is 1
|
||||
, _referenceCount(1) // when the object is created, the reference count of it is 1
|
||||
{
|
||||
static unsigned int uObjectCount = 0;
|
||||
|
||||
|
@ -65,12 +65,12 @@ Object* Object::autorelease()
|
|||
|
||||
bool Object::isSingleReference() const
|
||||
{
|
||||
return _reference == 1;
|
||||
return _referenceCount == 1;
|
||||
}
|
||||
|
||||
unsigned int Object::retainCount() const
|
||||
unsigned int Object::getReferenceCount() const
|
||||
{
|
||||
return _reference;
|
||||
return _referenceCount;
|
||||
}
|
||||
|
||||
bool Object::isEqual(const Object *object)
|
||||
|
|
|
@ -76,7 +76,7 @@ public:
|
|||
int _luaID;
|
||||
protected:
|
||||
/// count of references
|
||||
unsigned int _reference;
|
||||
unsigned int _referenceCount;
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -105,10 +105,10 @@ public:
|
|||
*/
|
||||
inline void release()
|
||||
{
|
||||
CCASSERT(_reference > 0, "reference count should greater than 0");
|
||||
--_reference;
|
||||
CCASSERT(_referenceCount > 0, "reference count should greater than 0");
|
||||
--_referenceCount;
|
||||
|
||||
if (_reference == 0)
|
||||
if (_referenceCount == 0)
|
||||
delete this;
|
||||
}
|
||||
|
||||
|
@ -122,8 +122,8 @@ public:
|
|||
*/
|
||||
inline void retain()
|
||||
{
|
||||
CCASSERT(_reference > 0, "reference count should greater than 0");
|
||||
++_reference;
|
||||
CCASSERT(_referenceCount > 0, "reference count should greater than 0");
|
||||
++_referenceCount;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -150,7 +150,7 @@ public:
|
|||
* @returns Whether the object's reference count is 1.
|
||||
* @js NA
|
||||
*/
|
||||
bool isSingleReference() const;
|
||||
CC_DEPRECATED_ATTRIBUTE bool isSingleReference() const;
|
||||
|
||||
/**
|
||||
* Returns the object's current reference count.
|
||||
|
@ -158,7 +158,8 @@ public:
|
|||
* @returns The object's reference count.
|
||||
* @js NA
|
||||
*/
|
||||
unsigned int retainCount() const;
|
||||
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
|
||||
|
|
|
@ -65,7 +65,7 @@ DisplayManager::~DisplayManager()
|
|||
if( _displayRenderNode )
|
||||
{
|
||||
_displayRenderNode->removeFromParentAndCleanup(true);
|
||||
if(_displayRenderNode->retainCount() > 0)
|
||||
if(_displayRenderNode->getReferenceCount() > 0)
|
||||
CC_SAFE_RELEASE_NULL(_displayRenderNode);
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ void Bug422Layer::check(Node* t)
|
|||
{
|
||||
auto& children = t->getChildren();
|
||||
for(const auto &child : children) {
|
||||
log("%p, rc: %d", child, child->retainCount());
|
||||
log("%p, rc: %d", child, child->getReferenceCount());
|
||||
check(child);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -459,16 +459,16 @@ std::string StressTest2::title() const
|
|||
SchedulerTest1::SchedulerTest1()
|
||||
{
|
||||
auto layer = Layer::create();
|
||||
//CCLOG("retain count after init is %d", layer->retainCount()); // 1
|
||||
//CCLOG("retain count after init is %d", layer->getReferenceCount()); // 1
|
||||
|
||||
addChild(layer, 0);
|
||||
//CCLOG("retain count after addChild is %d", layer->retainCount()); // 2
|
||||
//CCLOG("retain count after addChild is %d", layer->getReferenceCount()); // 2
|
||||
|
||||
layer->schedule( schedule_selector(SchedulerTest1::doSomething) );
|
||||
//CCLOG("retain count after schedule is %d", layer->retainCount()); // 3 : (object-c viersion), but win32 version is still 2, because Timer class don't save target.
|
||||
//CCLOG("retain count after schedule is %d", layer->getReferenceCount()); // 3 : (object-c viersion), but win32 version is still 2, because Timer class don't save target.
|
||||
|
||||
layer->unschedule(schedule_selector(SchedulerTest1::doSomething));
|
||||
//CCLOG("retain count after unschedule is %d", layer->retainCount()); // STILL 3! (win32 is '2')
|
||||
//CCLOG("retain count after unschedule is %d", layer->getReferenceCount()); // STILL 3! (win32 is '2')
|
||||
}
|
||||
|
||||
void SchedulerTest1::doSomething(float dt)
|
||||
|
|
|
@ -33,12 +33,12 @@ void ReleasePoolTestScene::runThisTest()
|
|||
|
||||
TestObject *obj = new TestObject("testobj");
|
||||
obj->autorelease();
|
||||
assert(obj->retainCount() == 1);
|
||||
assert(obj->getReferenceCount() == 1);
|
||||
|
||||
// should retain first before invoking autorelease
|
||||
obj->retain();
|
||||
obj->autorelease();
|
||||
assert(obj->retainCount() == 2);
|
||||
assert(obj->getReferenceCount() == 2);
|
||||
|
||||
// create an autorelease pool in stack
|
||||
|
||||
|
@ -48,19 +48,19 @@ void ReleasePoolTestScene::runThisTest()
|
|||
// can invoke autorelease more than once
|
||||
obj->retain();
|
||||
obj->autorelease();
|
||||
assert(obj->retainCount() == 3);
|
||||
assert(obj->getReferenceCount() == 3);
|
||||
obj->retain();
|
||||
obj->autorelease();
|
||||
assert(obj->retainCount() == 4);
|
||||
assert(obj->getReferenceCount() == 4);
|
||||
|
||||
// retain, release can work together with autorelease pool
|
||||
obj->retain();
|
||||
assert(obj->retainCount() == 5);
|
||||
assert(obj->getReferenceCount() == 5);
|
||||
obj->release();
|
||||
assert(obj->retainCount() == 4);
|
||||
assert(obj->getReferenceCount() == 4);
|
||||
}
|
||||
|
||||
assert(obj->retainCount() == 2);
|
||||
assert(obj->getReferenceCount() == 2);
|
||||
|
||||
// example of using temple autorelease pool
|
||||
{
|
||||
|
|
|
@ -103,7 +103,7 @@ void TemplateVectorTest::onEnter()
|
|||
auto node1 = Node::create();
|
||||
node1->setTag(1);
|
||||
vec.pushBack(node1);
|
||||
CCASSERT(node1->retainCount() == 2, "");
|
||||
CCASSERT(node1->getReferenceCount() == 2, "");
|
||||
|
||||
auto node2 = Node::create();
|
||||
node2->setTag(2);
|
||||
|
@ -125,8 +125,8 @@ void TemplateVectorTest::onEnter()
|
|||
for (ssize_t i = 0; i < size; ++i)
|
||||
{
|
||||
CCASSERT(vec2.at(i) == vec.at(i), "");
|
||||
CCASSERT(vec.at(i)->retainCount() == 3, "");
|
||||
CCASSERT(vec2.at(i)->retainCount() == 3, "");
|
||||
CCASSERT(vec.at(i)->getReferenceCount() == 3, "");
|
||||
CCASSERT(vec2.at(i)->getReferenceCount() == 3, "");
|
||||
}
|
||||
|
||||
// Test copy assignment operator
|
||||
|
@ -137,9 +137,9 @@ void TemplateVectorTest::onEnter()
|
|||
for (ssize_t i = 0; i < size; ++i)
|
||||
{
|
||||
CCASSERT(vec3.at(i) == vec2.at(i), "");
|
||||
CCASSERT(vec3.at(i)->retainCount() == 4, "");
|
||||
CCASSERT(vec2.at(i)->retainCount() == 4, "");
|
||||
CCASSERT(vec.at(i)->retainCount() == 4, "");
|
||||
CCASSERT(vec3.at(i)->getReferenceCount() == 4, "");
|
||||
CCASSERT(vec2.at(i)->getReferenceCount() == 4, "");
|
||||
CCASSERT(vec.at(i)->getReferenceCount() == 4, "");
|
||||
}
|
||||
|
||||
// Test move constructor
|
||||
|
@ -164,7 +164,7 @@ void TemplateVectorTest::onEnter()
|
|||
Vector<Node*> vec4(createVector());
|
||||
for (const auto& child : vec4)
|
||||
{
|
||||
CCASSERT(child->retainCount() == 2, "");
|
||||
CCASSERT(child->getReferenceCount() == 2, "");
|
||||
}
|
||||
|
||||
// Test init Vector<T> with capacity
|
||||
|
@ -178,16 +178,16 @@ void TemplateVectorTest::onEnter()
|
|||
|
||||
auto toRemovedNode = Node::create();
|
||||
vec5.pushBack(toRemovedNode);
|
||||
CCASSERT(toRemovedNode->retainCount() == 2, "");
|
||||
CCASSERT(toRemovedNode->getReferenceCount() == 2, "");
|
||||
|
||||
// Test move assignment operator
|
||||
vec5 = createVector();
|
||||
CCASSERT(toRemovedNode->retainCount() == 1, "");
|
||||
CCASSERT(toRemovedNode->getReferenceCount() == 1, "");
|
||||
CCASSERT(vec5.size() == 20, "size should be 20");
|
||||
|
||||
for (const auto& child : vec5)
|
||||
{
|
||||
CCASSERT(child->retainCount() == 2, "");
|
||||
CCASSERT(child->getReferenceCount() == 2, "");
|
||||
}
|
||||
|
||||
// Test Vector<T>::find
|
||||
|
@ -238,7 +238,7 @@ void TemplateVectorTest::onEnter()
|
|||
CCASSERT(vec7.size() == 20, "");
|
||||
for (const auto& child : vec7)
|
||||
{
|
||||
CCASSERT(child->retainCount() == 2, "");
|
||||
CCASSERT(child->getReferenceCount() == 2, "");
|
||||
}
|
||||
|
||||
// Sort
|
||||
|
@ -294,7 +294,7 @@ void TemplateVectorTest::onEnter()
|
|||
|
||||
for (const auto& child : vecSelfAssign)
|
||||
{
|
||||
CCASSERT(child->retainCount() == 2, "");
|
||||
CCASSERT(child->getReferenceCount() == 2, "");
|
||||
}
|
||||
|
||||
vecSelfAssign = std::move(vecSelfAssign);
|
||||
|
@ -302,7 +302,7 @@ void TemplateVectorTest::onEnter()
|
|||
|
||||
for (const auto& child : vecSelfAssign)
|
||||
{
|
||||
CCASSERT(child->retainCount() == 2, "");
|
||||
CCASSERT(child->getReferenceCount() == 2, "");
|
||||
}
|
||||
|
||||
// const at
|
||||
|
@ -350,14 +350,14 @@ void TemplateMapTest::onEnter()
|
|||
Map<std::string, Node*> map2 = createMap();
|
||||
for (const auto& e : map2)
|
||||
{
|
||||
CCASSERT(e.second->retainCount() == 2, "");
|
||||
CCASSERT(e.second->getReferenceCount() == 2, "");
|
||||
}
|
||||
|
||||
// Copy constructor
|
||||
Map<std::string, Node*> map3(map2);
|
||||
for (const auto& e : map3)
|
||||
{
|
||||
CCASSERT(e.second->retainCount() == 3, "");
|
||||
CCASSERT(e.second->getReferenceCount() == 3, "");
|
||||
}
|
||||
|
||||
// Move assignment operator
|
||||
|
@ -365,10 +365,10 @@ void TemplateMapTest::onEnter()
|
|||
auto unusedNode = Node::create();
|
||||
map4.insert("unused",unusedNode);
|
||||
map4 = createMap();
|
||||
CCASSERT(unusedNode->retainCount() == 1, "");
|
||||
CCASSERT(unusedNode->getReferenceCount() == 1, "");
|
||||
for (const auto& e : map4)
|
||||
{
|
||||
CCASSERT(e.second->retainCount() == 2, "");
|
||||
CCASSERT(e.second->getReferenceCount() == 2, "");
|
||||
}
|
||||
|
||||
// Copy assignment operator
|
||||
|
@ -376,7 +376,7 @@ void TemplateMapTest::onEnter()
|
|||
map5 = map4;
|
||||
for (const auto& e : map5)
|
||||
{
|
||||
CCASSERT(e.second->retainCount() == 3, "");
|
||||
CCASSERT(e.second->getReferenceCount() == 3, "");
|
||||
}
|
||||
|
||||
// Check size
|
||||
|
@ -441,9 +441,9 @@ void TemplateMapTest::onEnter()
|
|||
map6.insert("insert02", node2);
|
||||
map6.insert("insert03", node3);
|
||||
|
||||
CCASSERT(node1->retainCount() == 2, "");
|
||||
CCASSERT(node2->retainCount() == 2, "");
|
||||
CCASSERT(node3->retainCount() == 2, "");
|
||||
CCASSERT(node1->getReferenceCount() == 2, "");
|
||||
CCASSERT(node2->getReferenceCount() == 2, "");
|
||||
CCASSERT(node3->getReferenceCount() == 2, "");
|
||||
CCASSERT(map6.at("insert01") == node1, "");
|
||||
CCASSERT(map6.at("insert02") == node2, "");
|
||||
CCASSERT(map6.at("insert03") == node3, "");
|
||||
|
@ -472,7 +472,7 @@ void TemplateMapTest::onEnter()
|
|||
|
||||
for (const auto& e : mapForClearCopy)
|
||||
{
|
||||
CCASSERT(e.second->retainCount() == 2, "");
|
||||
CCASSERT(e.second->getReferenceCount() == 2, "");
|
||||
}
|
||||
|
||||
// get random object
|
||||
|
@ -493,7 +493,7 @@ void TemplateMapTest::onEnter()
|
|||
|
||||
for (const auto& e : mapForSelfAssign)
|
||||
{
|
||||
CCASSERT(e.second->retainCount() == 2, "");
|
||||
CCASSERT(e.second->getReferenceCount() == 2, "");
|
||||
}
|
||||
|
||||
mapForSelfAssign = std::move(mapForSelfAssign);
|
||||
|
@ -501,7 +501,7 @@ void TemplateMapTest::onEnter()
|
|||
|
||||
for (const auto& e : mapForSelfAssign)
|
||||
{
|
||||
CCASSERT(e.second->retainCount() == 2, "");
|
||||
CCASSERT(e.second->getReferenceCount() == 2, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue