2015-08-17 22:05:00 +00:00
|
|
|
#include "CSimplePool.hpp"
|
2015-08-22 01:58:41 +00:00
|
|
|
#include "IVParamObj.hpp"
|
2016-02-05 01:27:03 +00:00
|
|
|
#include "CToken.hpp"
|
2019-06-12 02:05:17 +00:00
|
|
|
#include <cassert>
|
2015-08-17 22:05:00 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2015-08-17 22:05:00 +00:00
|
|
|
|
2016-02-05 01:27:03 +00:00
|
|
|
CSimplePool::CSimplePool(IFactory& factory)
|
2018-12-08 05:30:43 +00:00
|
|
|
: x18_factory(factory), x1c_paramXfer(new TObjOwnerParam<IObjectStore*>(this)) {}
|
2016-02-05 01:27:03 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CSimplePool::~CSimplePool() { assert(x8_resources.empty() && "Dangling CSimplePool resources detected"); }
|
2018-05-20 06:14:57 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CToken CSimplePool::GetObj(const SObjectTag& tag, const CVParamTransfer& paramXfer) {
|
2019-09-12 03:50:38 +00:00
|
|
|
if (!tag) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return {};
|
2019-09-12 03:50:38 +00:00
|
|
|
}
|
2016-10-08 20:32:36 +00:00
|
|
|
|
2019-09-12 03:50:38 +00:00
|
|
|
const auto iter = x8_resources.find(tag);
|
|
|
|
if (iter != x8_resources.end()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return CToken(iter->second);
|
2019-09-12 03:50:38 +00:00
|
|
|
}
|
2016-02-05 05:52:05 +00:00
|
|
|
|
2019-09-12 03:50:38 +00:00
|
|
|
auto* const ret = new CObjectReference(*this, nullptr, tag, paramXfer);
|
|
|
|
x8_resources.emplace(tag, ret);
|
2018-12-08 05:30:43 +00:00
|
|
|
return CToken(ret);
|
2016-02-05 01:27:03 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CToken CSimplePool::GetObj(const SObjectTag& tag) { return GetObj(tag, x1c_paramXfer); }
|
2016-02-05 01:27:03 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CToken CSimplePool::GetObj(std::string_view resourceName) { return GetObj(resourceName, x1c_paramXfer); }
|
2016-02-05 01:27:03 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CToken CSimplePool::GetObj(std::string_view resourceName, const CVParamTransfer& paramXfer) {
|
|
|
|
const SObjectTag* tag = x18_factory.GetResourceIdByName(resourceName);
|
|
|
|
if (!tag)
|
|
|
|
return {};
|
|
|
|
return GetObj(*tag, paramXfer);
|
2016-02-05 01:27:03 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CSimplePool::HasObject(const SObjectTag& tag) const {
|
|
|
|
auto iter = x8_resources.find(tag);
|
|
|
|
if (iter != x8_resources.cend())
|
|
|
|
return true;
|
|
|
|
return x18_factory.CanBuild(tag);
|
2016-02-05 01:27:03 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CSimplePool::ObjectIsLive(const SObjectTag& tag) const {
|
|
|
|
auto iter = x8_resources.find(tag);
|
|
|
|
if (iter == x8_resources.cend())
|
|
|
|
return false;
|
|
|
|
return iter->second->IsLoaded();
|
2016-02-05 01:27:03 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CSimplePool::Flush() {}
|
2016-02-05 01:27:03 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CSimplePool::ObjectUnreferenced(const SObjectTag& tag) {
|
|
|
|
auto iter = x8_resources.find(tag);
|
|
|
|
if (iter != x8_resources.end())
|
|
|
|
x8_resources.erase(iter);
|
2016-02-05 01:27:03 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +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;
|
2017-02-12 03:17:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|