axmol/extensions/fairygui/GObjectPool.cpp

41 lines
710 B
C++
Raw Normal View History

2020-08-04 12:31:33 +08:00
#include "GObjectPool.h"
#include "GObject.h"
#include "UIPackage.h"
NS_FGUI_BEGIN
USING_NS_AX;
2020-08-04 12:31:33 +08:00
GObjectPool::GObjectPool()
{
}
GObjectPool::~GObjectPool()
{
}
GObject* GObjectPool::getObject(const std::string & url)
{
std::string url2 = UIPackage::normalizeURL(url);
if (url2.length() == 0)
return nullptr;
GObject* ret;
Vector<GObject*>& arr = _pool[url2];
if (!arr.empty())
{
ret = arr.back();
ret->retain();
arr.popBack();
ret->autorelease();
}
else
ret = UIPackage::createObjectFromURL(url2);
return ret;
}
void GObjectPool::returnObject(GObject* obj)
{
_pool[obj->getResourceURL()].pushBack(obj);
}
NS_FGUI_END