metaforce/Runtime/CSimplePool.cpp

78 lines
2.0 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)
: x30_factory(factory), x34_paramXfer(new TObjOwnerParam<IObjectStore*>(this))
{}
CToken CSimplePool::GetObj(const SObjectTag& tag, const CVParamTransfer& paramXfer)
{
2016-02-16 05:50:41 +00:00
auto iter = std::find_if(x4_resources.begin(), x4_resources.end(),
[&tag](std::pair<SObjectTag, CObjectReference*> pair) -> bool
{
return pair.first == tag;
});
if (iter != x4_resources.end())
2016-02-05 05:57:46 +00:00
return CToken(iter->second);
// TODO: There is some logic missing here, need to figure out what it's doing
2016-02-05 05:57:46 +00:00
CObjectReference* ret = new CObjectReference(*this, x30_factory.Build(tag, paramXfer), tag, paramXfer);
2016-02-16 07:01:55 +00:00
if (ret->GetObject())
2016-02-16 07:09:57 +00:00
{
x4_resources.push_back(std::make_pair<SObjectTag, CObjectReference*>((SObjectTag)tag, std::move(ret)));
2016-02-16 07:01:55 +00:00
return CToken(ret);
2016-02-16 07:09:57 +00:00
}
2016-02-16 07:09:57 +00:00
delete ret;
2016-02-16 07:01:55 +00:00
return CToken();
}
CToken CSimplePool::GetObj(const SObjectTag& tag)
{
return GetObj(tag, x34_paramXfer);
}
CToken CSimplePool::GetObj(char const* resourceName)
{
return GetObj(resourceName, x34_paramXfer);
}
CToken CSimplePool::GetObj(char const* resourceName, const CVParamTransfer& paramXfer)
{
const SObjectTag* tag = x30_factory.GetResourceIdByName(resourceName);
return GetObj(*tag, paramXfer);
}
bool CSimplePool::HasObject(const SObjectTag& tag) const
{
auto iter = std::find_if(x4_resources.begin(), x4_resources.end(), [&tag](std::pair<SObjectTag, CObjectReference*> pair)->bool{
return pair.first == tag;
});
return iter != x4_resources.end();
}
bool CSimplePool::ObjectIsLive(const SObjectTag&) const
{
return false;
}
void CSimplePool::Flush()
{
}
void CSimplePool::ObjectUnreferenced(const SObjectTag& tag)
{
auto iter = std::find_if(x4_resources.begin(), x4_resources.end(), [&tag](std::pair<SObjectTag, CObjectReference*> pair)->bool{
return pair.first == tag;
});
if (iter != x4_resources.end())
x4_resources.erase(iter);
}
}