metaforce/Runtime/CSimplePool.cpp

81 lines
1.9 KiB
C++
Raw Normal View History

#include "CSimplePool.hpp"
2015-08-22 01:58:41 +00:00
#include "IVParamObj.hpp"
#include "CToken.hpp"
2016-03-04 23:04:53 +00:00
namespace urde
{
CSimplePool::CSimplePool(IFactory& factory)
2017-01-22 04:32:53 +00:00
: x18_factory(factory), x1c_paramXfer(new TObjOwnerParam<IObjectStore*>(this))
{}
CToken CSimplePool::GetObj(const SObjectTag& tag, const CVParamTransfer& paramXfer)
{
if (!tag)
return {};
2017-01-22 04:32:53 +00:00
auto iter = x8_resources.find(tag);
if (iter != x8_resources.end())
2016-02-05 05:57:46 +00:00
return CToken(iter->second);
2016-04-01 01:00:37 +00:00
CObjectReference* ret = new CObjectReference(*this, std::unique_ptr<IObj>(), tag, paramXfer);
2017-01-22 04:32:53 +00:00
x8_resources.emplace(std::make_pair<SObjectTag, CObjectReference*>((SObjectTag)tag, std::move(ret)));
2016-04-01 01:00:37 +00:00
return CToken(ret);
}
CToken CSimplePool::GetObj(const SObjectTag& tag)
{
2017-01-22 04:32:53 +00:00
return GetObj(tag, x1c_paramXfer);
}
2017-11-13 06:19:18 +00:00
CToken CSimplePool::GetObj(std::string_view resourceName)
{
2017-01-22 04:32:53 +00:00
return GetObj(resourceName, x1c_paramXfer);
}
2017-11-13 06:19:18 +00:00
CToken CSimplePool::GetObj(std::string_view resourceName, const CVParamTransfer& paramXfer)
{
2017-01-22 04:32:53 +00:00
const SObjectTag* tag = x18_factory.GetResourceIdByName(resourceName);
if (!tag)
return {};
return GetObj(*tag, paramXfer);
}
bool CSimplePool::HasObject(const SObjectTag& tag) const
{
2017-01-22 04:32:53 +00:00
auto iter = x8_resources.find(tag);
if (iter != x8_resources.cend())
2016-04-15 03:02:21 +00:00
return true;
2017-01-22 04:32:53 +00:00
return x18_factory.CanBuild(tag);
}
2016-04-15 03:02:21 +00:00
bool CSimplePool::ObjectIsLive(const SObjectTag& tag) const
{
2017-01-22 04:32:53 +00:00
auto iter = x8_resources.find(tag);
if (iter == x8_resources.cend())
2016-04-15 03:02:21 +00:00
return false;
return iter->second->IsLoaded();
}
void CSimplePool::Flush()
{
}
void CSimplePool::ObjectUnreferenced(const SObjectTag& tag)
{
2017-01-22 04:32:53 +00:00
auto iter = x8_resources.find(tag);
if (iter != x8_resources.end())
x8_resources.erase(iter);
}
2017-02-12 03:17:18 +00:00
std::vector<SObjectTag> CSimplePool::GetReferencedTags() const
{
std::vector<SObjectTag> ret;
ret.reserve(x8_resources.size());
for (const auto& obj : x8_resources)
ret.push_back(obj.first);
return ret;
}
}