metaforce/Runtime/CResFactory.hpp

113 lines
4.0 KiB
C++
Raw Normal View History

2018-10-07 03:42:33 +00:00
#pragma once
2015-08-17 20:33:58 +00:00
#include <list>
#include <memory>
2015-08-23 06:42:29 +00:00
#include <unordered_map>
#include <vector>
#include "Runtime/CResLoader.hpp"
#include "Runtime/CToken.hpp"
#include "Runtime/IFactory.hpp"
#include "Runtime/IVParamObj.hpp"
#include "Runtime/MP1/MP1OriginalIDs.hpp"
2015-08-18 05:54:43 +00:00
2018-12-08 05:30:43 +00:00
namespace urde {
class IDvdRequest;
class CSimplePool;
2018-12-08 05:30:43 +00:00
class CResFactory : public IFactory {
CResLoader x4_loader;
CFactoryMgr x5c_factoryMgr;
2018-04-07 20:55:57 +00:00
#if RUNTIME_ORIGINAL_IDS
2018-12-08 05:30:43 +00:00
TLockedToken<MP1OriginalIDs> m_origIds;
2018-04-07 20:55:57 +00:00
#endif
2015-08-22 01:58:41 +00:00
public:
2018-12-08 05:30:43 +00:00
struct SLoadingData {
SObjectTag x0_tag;
std::shared_ptr<IDvdRequest> x8_dvdReq;
std::unique_ptr<IObj>* xc_targetPtr = nullptr;
std::unique_ptr<u8[]> x10_loadBuffer;
u32 x14_resSize = 0;
CVParamTransfer x18_cvXfer;
bool m_compressed = false;
CObjectReference* m_selfRef = nullptr;
SLoadingData() = default;
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:
2018-12-08 05:30:43 +00:00
std::list<SLoadingData> m_loadList;
std::unordered_map<SObjectTag, std::list<SLoadingData>::iterator> m_loadMap;
2019-03-09 08:58:27 +00:00
std::vector<CToken> m_nonWorldTokens; /* URDE: always keep non-world resources resident */
2018-12-08 05:30:43 +00:00
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:
2018-12-08 05:30:43 +00:00
CResLoader& GetLoader() { return x4_loader; }
std::unique_ptr<IObj> Build(const SObjectTag&, const CVParamTransfer&, CObjectReference* selfRef) override;
void BuildAsync(const SObjectTag&, const CVParamTransfer&, std::unique_ptr<IObj>*,
CObjectReference* selfRef) override;
void AsyncIdle() override;
void CancelBuild(const SObjectTag&) override;
2018-12-08 05:30:43 +00:00
bool CanBuild(const SObjectTag& tag) override { return x4_loader.ResourceExists(tag); }
2018-12-08 05:30:43 +00:00
u32 ResourceSize(const urde::SObjectTag& tag) override { return x4_loader.ResourceSize(tag); }
2018-12-08 05:30:43 +00:00
std::unique_ptr<u8[]> LoadResourceSync(const urde::SObjectTag& tag) override {
return x4_loader.LoadResourceSync(tag);
}
2018-12-08 05:30:43 +00:00
std::unique_ptr<u8[]> LoadNewResourcePartSync(const urde::SObjectTag& tag, u32 off, u32 size) override {
2018-12-08 05:30:43 +00:00
return x4_loader.LoadNewResourcePartSync(tag, off, size);
}
void GetTagListForFile(const char* pakName, std::vector<SObjectTag>& out) const override {
2018-12-08 05:30:43 +00:00
return x4_loader.GetTagListForFile(pakName, out);
}
std::shared_ptr<IDvdRequest> LoadResourceAsync(const urde::SObjectTag& tag, void* target) override {
2018-12-08 05:30:43 +00:00
return x4_loader.LoadResourceAsync(tag, target);
}
2015-08-17 20:33:58 +00:00
std::shared_ptr<IDvdRequest> LoadResourcePartAsync(const urde::SObjectTag& tag, u32 off, u32 size,
void* target) override {
2018-12-08 05:30:43 +00:00
return x4_loader.LoadResourcePartAsync(tag, off, size, target);
}
const SObjectTag* GetResourceIdByName(std::string_view name) const override {
return x4_loader.GetResourceIdByName(name);
}
2018-12-08 05:30:43 +00:00
FourCC GetResourceTypeById(CAssetId id) const override { return x4_loader.GetResourceTypeById(id); }
2018-12-08 05:30:43 +00:00
std::vector<std::pair<std::string, SObjectTag>> GetResourceIdToNameList() const {
return x4_loader.GetResourceIdToNameList();
}
void EnumerateResources(const std::function<bool(const SObjectTag&)>& lambda) const override {
2018-12-08 05:30:43 +00:00
return x4_loader.EnumerateResources(lambda);
}
void EnumerateNamedResources(const std::function<bool(std::string_view, const SObjectTag&)>& lambda) const override {
2018-12-08 05:30:43 +00:00
return x4_loader.EnumerateNamedResources(lambda);
}
2019-03-09 08:58:27 +00:00
void LoadPersistentResources(CSimplePool& sp);
void UnloadPersistentResources() { m_nonWorldTokens.clear(); }
void LoadOriginalIDs(CSimplePool& sp) override;
CAssetId TranslateOriginalToNew(CAssetId id) const override;
CAssetId TranslateNewToOriginal(CAssetId id) const override;
2018-12-08 05:30:43 +00:00
CResLoader* GetResLoader() override { return &x4_loader; }
CFactoryMgr* GetFactoryMgr() override { return &x5c_factoryMgr; }
2018-12-08 05:30:43 +00:00
};
2018-12-08 05:30:43 +00:00
} // namespace urde