2016-04-13 06:07:23 +00:00
|
|
|
#ifndef __URDE_CRESFACTORY_HPP__
|
|
|
|
#define __URDE_CRESFACTORY_HPP__
|
2015-08-17 20:33:58 +00:00
|
|
|
|
2015-08-23 06:42:29 +00:00
|
|
|
#include <unordered_map>
|
2015-08-18 05:54:43 +00:00
|
|
|
#include "IFactory.hpp"
|
2015-08-23 06:42:29 +00:00
|
|
|
#include "CResLoader.hpp"
|
2016-02-05 01:27:03 +00:00
|
|
|
#include "IVParamObj.hpp"
|
2017-10-26 10:09:51 +00:00
|
|
|
#include "MP1/MP1OriginalIDs.hpp"
|
|
|
|
#include "CToken.hpp"
|
2015-08-18 05:54:43 +00:00
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
namespace urde
|
2015-08-17 22:05:00 +00:00
|
|
|
{
|
2015-10-29 07:52:15 +00:00
|
|
|
class IDvdRequest;
|
2017-10-26 10:09:51 +00:00
|
|
|
class CSimplePool;
|
2015-08-17 22:05:00 +00:00
|
|
|
|
2015-08-18 05:54:43 +00:00
|
|
|
class CResFactory : public IFactory
|
2015-08-17 20:33:58 +00:00
|
|
|
{
|
2015-08-23 06:42:29 +00:00
|
|
|
CResLoader x4_loader;
|
2017-10-26 10:09:51 +00:00
|
|
|
CFactoryMgr x5c_factoryMgr;
|
|
|
|
TLockedToken<MP1OriginalIDs> m_origIds;
|
|
|
|
|
2015-08-22 01:58:41 +00:00
|
|
|
public:
|
2015-08-23 06:42:29 +00:00
|
|
|
struct SLoadingData
|
|
|
|
{
|
2016-02-05 01:27:03 +00:00
|
|
|
SObjectTag x0_tag;
|
2017-10-26 10:09:51 +00:00
|
|
|
std::shared_ptr<IDvdRequest> x8_dvdReq;
|
|
|
|
std::unique_ptr<IObj>* xc_targetPtr = nullptr;
|
|
|
|
std::unique_ptr<u8[]> x10_loadBuffer;
|
2016-03-26 00:51:59 +00:00
|
|
|
u32 x14_resSize = 0;
|
2016-02-05 01:27:03 +00:00
|
|
|
CVParamTransfer x18_cvXfer;
|
2017-10-26 10:09:51 +00:00
|
|
|
bool m_compressed = false;
|
|
|
|
CObjectReference* m_selfRef = nullptr;
|
2016-03-26 00:51:59 +00:00
|
|
|
|
|
|
|
SLoadingData() = default;
|
2017-10-26 10:09:51 +00:00
|
|
|
SLoadingData(const SObjectTag& tag, std::unique_ptr<IObj>* ptr, const CVParamTransfer& xfer,
|
|
|
|
bool compressed, CObjectReference* selfRef)
|
|
|
|
: x0_tag(tag), xc_targetPtr(ptr), x18_cvXfer(xfer), m_compressed(compressed), m_selfRef(selfRef) {}
|
2015-08-23 06:42:29 +00:00
|
|
|
};
|
|
|
|
private:
|
2017-10-26 10:09:51 +00:00
|
|
|
std::list<SLoadingData> m_loadList;
|
|
|
|
std::unordered_map<SObjectTag, std::list<SLoadingData>::iterator> m_loadMap;
|
|
|
|
void AddToLoadList(SLoadingData&& data);
|
|
|
|
CFactoryFnReturn BuildSync(const SObjectTag&, const CVParamTransfer&, CObjectReference* selfRef);
|
|
|
|
bool PumpResource(SLoadingData& data);
|
2015-08-23 06:42:29 +00:00
|
|
|
public:
|
2015-08-27 00:23:46 +00:00
|
|
|
CResLoader& GetLoader() {return x4_loader;}
|
2017-10-26 10:09:51 +00:00
|
|
|
std::unique_ptr<IObj> Build(const SObjectTag&, const CVParamTransfer&, CObjectReference* selfRef);
|
|
|
|
void BuildAsync(const SObjectTag&, const CVParamTransfer&, std::unique_ptr<IObj>*, CObjectReference* selfRef);
|
|
|
|
void AsyncIdle();
|
2015-08-22 01:58:41 +00:00
|
|
|
void CancelBuild(const SObjectTag&);
|
2016-03-26 00:51:59 +00:00
|
|
|
|
|
|
|
bool CanBuild(const SObjectTag& tag)
|
|
|
|
{
|
|
|
|
return x4_loader.ResourceExists(tag);
|
|
|
|
}
|
|
|
|
|
2017-10-26 10:09:51 +00:00
|
|
|
u32 ResourceSize(const urde::SObjectTag& tag)
|
|
|
|
{
|
|
|
|
return x4_loader.ResourceSize(tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<u8[]> LoadResourceSync(const urde::SObjectTag& tag)
|
|
|
|
{
|
|
|
|
return x4_loader.LoadResourceSync(tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<u8[]> LoadResourcePartSync(const urde::SObjectTag& tag, u32 size, u32 off)
|
|
|
|
{
|
|
|
|
return x4_loader.LoadResourcePartSync(tag, size, off);
|
|
|
|
}
|
|
|
|
|
2017-10-28 07:08:48 +00:00
|
|
|
void GetTagListForFile(const char* pakName, std::vector<SObjectTag>& out) const
|
|
|
|
{
|
|
|
|
return x4_loader.GetTagListForFile(pakName, out);
|
|
|
|
}
|
|
|
|
|
2017-10-27 10:10:32 +00:00
|
|
|
std::shared_ptr<IDvdRequest> LoadResourceAsync(const urde::SObjectTag& tag, void* target)
|
|
|
|
{
|
|
|
|
return x4_loader.LoadResourceAsync(tag, target);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<IDvdRequest> LoadResourcePartAsync(const urde::SObjectTag& tag, u32 size, u32 off, void* target)
|
|
|
|
{
|
|
|
|
return x4_loader.LoadResourcePartAsync(tag, size, off, target);
|
|
|
|
}
|
|
|
|
|
2016-03-26 00:51:59 +00:00
|
|
|
const SObjectTag* GetResourceIdByName(const char* name) const
|
|
|
|
{
|
|
|
|
return x4_loader.GetResourceIdByName(name);
|
|
|
|
}
|
2015-08-23 06:42:29 +00:00
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
FourCC GetResourceTypeById(CAssetId id) const
|
2016-04-14 21:42:47 +00:00
|
|
|
{
|
|
|
|
return x4_loader.GetResourceTypeById(id);
|
|
|
|
}
|
|
|
|
|
2015-08-23 06:42:29 +00:00
|
|
|
std::vector<std::pair<std::string, SObjectTag>> GetResourceIdToNameList() const
|
|
|
|
{
|
2017-10-26 10:09:51 +00:00
|
|
|
return x4_loader.GetResourceIdToNameList();
|
2015-08-23 06:42:29 +00:00
|
|
|
}
|
2016-09-25 01:58:20 +00:00
|
|
|
|
2017-10-26 10:09:51 +00:00
|
|
|
void EnumerateResources(const std::function<bool(const SObjectTag&)>& lambda) const
|
2016-09-25 01:58:20 +00:00
|
|
|
{
|
2017-10-26 10:09:51 +00:00
|
|
|
return x4_loader.EnumerateResources(lambda);
|
2016-09-25 01:58:20 +00:00
|
|
|
}
|
|
|
|
|
2017-10-26 10:09:51 +00:00
|
|
|
void EnumerateNamedResources(const std::function<bool(const std::string&, const SObjectTag&)>& lambda) const
|
2016-09-25 01:58:20 +00:00
|
|
|
{
|
2017-10-26 10:09:51 +00:00
|
|
|
return x4_loader.EnumerateNamedResources(lambda);
|
2016-09-25 01:58:20 +00:00
|
|
|
}
|
2017-10-26 10:09:51 +00:00
|
|
|
|
|
|
|
void LoadOriginalIDs(CSimplePool& sp);
|
|
|
|
CAssetId TranslateOriginalToNew(CAssetId id) const;
|
|
|
|
CAssetId TranslateNewToOriginal(CAssetId id) const;
|
2017-10-27 10:10:32 +00:00
|
|
|
|
|
|
|
CResLoader* GetResLoader() { return &x4_loader; }
|
|
|
|
CFactoryMgr* GetFactoryMgr() { return &x5c_factoryMgr; }
|
2015-08-17 20:33:58 +00:00
|
|
|
};
|
|
|
|
|
2015-08-17 22:05:00 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 06:07:23 +00:00
|
|
|
#endif // __URDE_CRESFACTORY_HPP__
|