2016-03-26 00:51:59 +00:00
|
|
|
#ifndef URDE_PROJECT_RESOURCE_FACTORY_BASE_HPP
|
|
|
|
#define URDE_PROJECT_RESOURCE_FACTORY_BASE_HPP
|
|
|
|
|
2016-03-27 20:43:04 +00:00
|
|
|
#include "hecl/ClientProcess.hpp"
|
2016-03-28 04:36:55 +00:00
|
|
|
#include "hecl/Database.hpp"
|
2016-03-26 00:51:59 +00:00
|
|
|
#include "Runtime/IFactory.hpp"
|
|
|
|
#include "Runtime/CFactoryMgr.hpp"
|
|
|
|
#include "Runtime/CResFactory.hpp"
|
2017-10-25 07:47:49 +00:00
|
|
|
#include "DataSpec/SpecBase.hpp"
|
2016-03-26 02:25:04 +00:00
|
|
|
#include "optional.hpp"
|
2016-03-26 00:51:59 +00:00
|
|
|
|
|
|
|
#include <thread>
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
2016-09-25 01:58:20 +00:00
|
|
|
class ProjectResourceFactoryBase : public IFactory
|
2016-03-26 00:51:59 +00:00
|
|
|
{
|
2016-04-05 01:51:25 +00:00
|
|
|
friend class ProjectResourcePool;
|
2016-03-27 20:43:04 +00:00
|
|
|
hecl::ClientProcess& m_clientProc;
|
2016-03-26 00:51:59 +00:00
|
|
|
|
2016-08-08 04:48:18 +00:00
|
|
|
public:
|
2017-10-27 10:10:32 +00:00
|
|
|
struct AsyncTask : urde::IDvdRequest
|
2016-03-28 04:36:55 +00:00
|
|
|
{
|
|
|
|
ProjectResourceFactoryBase& m_parent;
|
|
|
|
|
|
|
|
SObjectTag x0_tag;
|
2016-04-06 01:44:07 +00:00
|
|
|
//IDvdRequest* x8_dvdReq = nullptr;
|
2016-07-23 21:41:18 +00:00
|
|
|
std::unique_ptr<u8[]>* xc_targetDataPtr = nullptr;
|
2017-02-27 05:25:14 +00:00
|
|
|
u8* xc_targetDataRawPtr = nullptr;
|
2017-10-26 10:09:51 +00:00
|
|
|
std::unique_ptr<IObj>* xc_targetObjPtr = nullptr;
|
2016-03-28 04:36:55 +00:00
|
|
|
std::unique_ptr<u8[]> x10_loadBuffer;
|
2016-07-23 21:41:18 +00:00
|
|
|
u32 x14_resSize = UINT32_MAX;
|
|
|
|
u32 x14_resOffset = 0;
|
2016-03-28 04:36:55 +00:00
|
|
|
CVParamTransfer x18_cvXfer;
|
2016-09-02 19:32:57 +00:00
|
|
|
CObjectReference* m_selfRef = nullptr;
|
2016-03-28 04:36:55 +00:00
|
|
|
|
|
|
|
hecl::ProjectPath m_workingPath;
|
|
|
|
hecl::ProjectPath m_cookedPath;
|
2016-04-19 00:17:49 +00:00
|
|
|
std::shared_ptr<const hecl::ClientProcess::CookTransaction> m_cookTransaction;
|
|
|
|
std::shared_ptr<const hecl::ClientProcess::BufferTransaction> m_bufTransaction;
|
2016-03-28 04:36:55 +00:00
|
|
|
bool m_failed = false;
|
2016-03-28 21:38:48 +00:00
|
|
|
bool m_complete = false;
|
2016-03-28 04:36:55 +00:00
|
|
|
|
2016-07-23 21:41:18 +00:00
|
|
|
AsyncTask(ProjectResourceFactoryBase& parent, const SObjectTag& tag,
|
|
|
|
std::unique_ptr<u8[]>& ptr)
|
|
|
|
: m_parent(parent), x0_tag(tag), xc_targetDataPtr(&ptr) {}
|
|
|
|
|
|
|
|
AsyncTask(ProjectResourceFactoryBase& parent, const SObjectTag& tag,
|
|
|
|
std::unique_ptr<u8[]>& ptr, u32 size, u32 off)
|
|
|
|
: m_parent(parent), x0_tag(tag), xc_targetDataPtr(&ptr), x14_resSize(size),
|
|
|
|
x14_resOffset(off) {}
|
|
|
|
|
2017-10-27 10:10:32 +00:00
|
|
|
AsyncTask(ProjectResourceFactoryBase& parent, const SObjectTag& tag,
|
|
|
|
u8* ptr)
|
|
|
|
: m_parent(parent), x0_tag(tag), xc_targetDataRawPtr(ptr) {}
|
|
|
|
|
2017-02-27 05:25:14 +00:00
|
|
|
AsyncTask(ProjectResourceFactoryBase& parent, const SObjectTag& tag,
|
|
|
|
u8* ptr, u32 size, u32 off)
|
|
|
|
: m_parent(parent), x0_tag(tag), xc_targetDataRawPtr(ptr), x14_resSize(size),
|
|
|
|
x14_resOffset(off) {}
|
|
|
|
|
2016-03-28 04:36:55 +00:00
|
|
|
AsyncTask(ProjectResourceFactoryBase& parent, const SObjectTag& tag,
|
2017-10-26 10:09:51 +00:00
|
|
|
std::unique_ptr<IObj>* ptr, const CVParamTransfer& xfer, CObjectReference* selfRef)
|
2016-09-02 19:32:57 +00:00
|
|
|
: m_parent(parent), x0_tag(tag), xc_targetObjPtr(ptr), x18_cvXfer(xfer), m_selfRef(selfRef) {}
|
2016-03-28 04:36:55 +00:00
|
|
|
|
2017-10-22 06:11:22 +00:00
|
|
|
/* Cook only */
|
|
|
|
AsyncTask(ProjectResourceFactoryBase& parent, const SObjectTag& tag)
|
|
|
|
: m_parent(parent), x0_tag(tag) {}
|
|
|
|
|
2016-03-31 21:06:41 +00:00
|
|
|
void EnsurePath(const urde::SObjectTag& tag,
|
|
|
|
const hecl::ProjectPath& path);
|
2016-03-28 04:36:55 +00:00
|
|
|
void CookComplete();
|
|
|
|
bool AsyncPump();
|
2017-10-27 10:10:32 +00:00
|
|
|
void WaitUntilComplete();
|
|
|
|
bool IsComplete() { return m_complete; }
|
|
|
|
void PostCancelRequest() {}
|
|
|
|
EMediaType GetMediaType() const { return EMediaType::Real; }
|
2016-03-28 04:36:55 +00:00
|
|
|
};
|
2016-08-08 04:48:18 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
const hecl::Database::Project* m_proj = nullptr;
|
|
|
|
const hecl::Database::DataSpecEntry* m_origSpec = nullptr;
|
|
|
|
const hecl::Database::DataSpecEntry* m_pcSpec = nullptr;
|
|
|
|
/* Used to resolve cooked paths */
|
|
|
|
std::unique_ptr<hecl::Database::IDataSpec> m_cookSpec;
|
|
|
|
urde::CFactoryMgr m_factoryMgr;
|
|
|
|
|
2017-10-22 06:11:22 +00:00
|
|
|
std::list<std::shared_ptr<AsyncTask>> m_asyncLoadList;
|
|
|
|
std::unordered_map<SObjectTag, std::list<std::shared_ptr<AsyncTask>>::iterator> m_asyncLoadMap;
|
|
|
|
std::shared_ptr<AsyncTask>
|
|
|
|
_AddTask(const std::shared_ptr<AsyncTask>& ptr);
|
|
|
|
std::list<std::shared_ptr<AsyncTask>>::iterator
|
|
|
|
_RemoveTask(std::list<std::shared_ptr<AsyncTask>>::iterator it);
|
|
|
|
std::unordered_map<SObjectTag, std::list<std::shared_ptr<AsyncTask>>::iterator>::iterator
|
|
|
|
_RemoveTask(std::unordered_map<SObjectTag,
|
|
|
|
std::list<std::shared_ptr<AsyncTask>>::iterator>::iterator it);
|
|
|
|
std::unordered_map<SObjectTag, std::list<std::shared_ptr<AsyncTask>>::iterator>::iterator
|
|
|
|
_RemoveTask(const SObjectTag& tag);
|
|
|
|
|
|
|
|
static AsyncTask& _GetAsyncTask(std::list<std::shared_ptr<AsyncTask>>::iterator it)
|
|
|
|
{
|
|
|
|
return **it;
|
|
|
|
}
|
|
|
|
static AsyncTask& _GetAsyncTask(
|
|
|
|
std::unordered_map<SObjectTag, std::list<std::shared_ptr<AsyncTask>>::iterator>::iterator it)
|
|
|
|
{
|
|
|
|
return **it->second;
|
|
|
|
}
|
2016-03-26 00:51:59 +00:00
|
|
|
|
2016-07-23 21:41:18 +00:00
|
|
|
bool
|
|
|
|
PrepForReadSync(const SObjectTag& tag,
|
|
|
|
const hecl::ProjectPath& path,
|
|
|
|
std::experimental::optional<athena::io::FileReader>& fr);
|
|
|
|
|
2017-10-25 07:47:49 +00:00
|
|
|
bool WaitForTagReady(const urde::SObjectTag& tag, const hecl::ProjectPath*& pathOut)
|
|
|
|
{
|
|
|
|
return static_cast<DataSpec::SpecBase&>(*m_cookSpec).waitForTagReady(tag, pathOut);
|
|
|
|
}
|
|
|
|
SObjectTag TagFromPath(const hecl::ProjectPath& path, hecl::BlenderToken& btok) const
|
|
|
|
{
|
|
|
|
return static_cast<DataSpec::SpecBase&>(*m_cookSpec).tagFromPath(path, btok);
|
|
|
|
}
|
2016-10-02 22:41:36 +00:00
|
|
|
SObjectTag BuildTagFromPath(const hecl::ProjectPath& path, hecl::BlenderToken& btok) const
|
|
|
|
{
|
2017-10-25 07:47:49 +00:00
|
|
|
return static_cast<DataSpec::SpecBase&>(*m_cookSpec).buildTagFromPath(path, btok);
|
|
|
|
}
|
|
|
|
void GetTagListForFile(const char* pakName, std::vector<SObjectTag>& out) const
|
|
|
|
{
|
|
|
|
return static_cast<DataSpec::SpecBase&>(*m_cookSpec).getTagListForFile(pakName, out);
|
|
|
|
}
|
|
|
|
void CancelBackgroundIndex()
|
|
|
|
{
|
|
|
|
if (m_cookSpec)
|
|
|
|
return static_cast<DataSpec::SpecBase&>(*m_cookSpec).cancelBackgroundIndex();
|
2016-10-02 22:41:36 +00:00
|
|
|
}
|
2016-03-28 04:36:55 +00:00
|
|
|
void BeginBackgroundIndex(hecl::Database::Project& proj,
|
2017-10-25 07:47:49 +00:00
|
|
|
const hecl::Database::DataSpecEntry& origSpec,
|
|
|
|
const hecl::Database::DataSpecEntry& pcSpec);
|
2016-03-26 00:51:59 +00:00
|
|
|
|
2016-03-28 04:36:55 +00:00
|
|
|
bool SyncCook(const hecl::ProjectPath& working);
|
2016-03-29 23:14:14 +00:00
|
|
|
CFactoryFnReturn BuildSync(const SObjectTag& tag, const hecl::ProjectPath& path,
|
2016-09-02 19:32:57 +00:00
|
|
|
const CVParamTransfer& paramXfer, CObjectReference* selfRef);
|
2017-10-26 10:09:51 +00:00
|
|
|
std::shared_ptr<AsyncTask> BuildAsyncInternal(const urde::SObjectTag&, const urde::CVParamTransfer&, std::unique_ptr<urde::IObj>*, CObjectReference* selfRef);
|
2016-03-26 00:51:59 +00:00
|
|
|
|
|
|
|
public:
|
2016-03-27 20:43:04 +00:00
|
|
|
ProjectResourceFactoryBase(hecl::ClientProcess& clientProc) : m_clientProc(clientProc) {}
|
2016-09-02 19:32:57 +00:00
|
|
|
std::unique_ptr<urde::IObj> Build(const urde::SObjectTag&, const urde::CVParamTransfer&, CObjectReference* selfRef);
|
2017-10-26 10:09:51 +00:00
|
|
|
void BuildAsync(const urde::SObjectTag&, const urde::CVParamTransfer&, std::unique_ptr<urde::IObj>*, CObjectReference* selfRef);
|
2016-03-26 00:51:59 +00:00
|
|
|
void CancelBuild(const urde::SObjectTag&);
|
|
|
|
bool CanBuild(const urde::SObjectTag&);
|
|
|
|
const urde::SObjectTag* GetResourceIdByName(const char*) const;
|
2017-08-13 05:26:14 +00:00
|
|
|
FourCC GetResourceTypeById(CAssetId id) const;
|
2017-10-25 07:47:49 +00:00
|
|
|
hecl::ProjectPath GetCookedPath(const hecl::ProjectPath& working, bool pcTarget) const
|
|
|
|
{
|
|
|
|
return static_cast<DataSpec::SpecBase&>(*m_cookSpec).getCookedPath(working, pcTarget);
|
|
|
|
}
|
2016-03-26 00:51:59 +00:00
|
|
|
|
2016-09-25 01:58:20 +00:00
|
|
|
void EnumerateResources(const std::function<bool(const SObjectTag&)>& lambda) const;
|
|
|
|
void EnumerateNamedResources(const std::function<bool(const std::string&, const SObjectTag&)>& lambda) const;
|
|
|
|
|
2016-07-23 21:41:18 +00:00
|
|
|
u32 ResourceSize(const SObjectTag& tag);
|
2017-10-27 10:10:32 +00:00
|
|
|
std::shared_ptr<urde::IDvdRequest> LoadResourceAsync(const urde::SObjectTag& tag, void* target);
|
2017-11-05 02:08:05 +00:00
|
|
|
std::shared_ptr<urde::IDvdRequest> LoadResourcePartAsync(const urde::SObjectTag& tag, u32 off, u32 size, void* target);
|
2016-07-23 21:41:18 +00:00
|
|
|
std::unique_ptr<u8[]> LoadResourceSync(const urde::SObjectTag& tag);
|
2017-11-05 02:08:05 +00:00
|
|
|
std::unique_ptr<u8[]> LoadNewResourcePartSync(const urde::SObjectTag& tag, u32 off, u32 size);
|
2016-07-23 21:41:18 +00:00
|
|
|
|
2017-10-22 06:11:22 +00:00
|
|
|
std::shared_ptr<AsyncTask> CookResourceAsync(const urde::SObjectTag& tag);
|
|
|
|
|
|
|
|
template <typename ItType>
|
|
|
|
bool AsyncPumpTask(ItType& it);
|
2016-03-26 00:51:59 +00:00
|
|
|
void AsyncIdle();
|
2017-10-22 06:11:22 +00:00
|
|
|
void Shutdown() { CancelBackgroundIndex(); }
|
|
|
|
bool IsBusy() const { return m_asyncLoadMap.size() != 0; }
|
2016-03-28 22:39:56 +00:00
|
|
|
|
2016-04-19 21:25:26 +00:00
|
|
|
SObjectTag TagFromPath(const hecl::SystemChar* path) const
|
|
|
|
{
|
|
|
|
return TagFromPath(hecl::ProjectPath(*(hecl::Database::Project*)m_proj, path),
|
|
|
|
hecl::SharedBlenderToken);
|
|
|
|
}
|
|
|
|
|
2016-03-28 22:39:56 +00:00
|
|
|
~ProjectResourceFactoryBase() {Shutdown();}
|
2016-03-26 00:51:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // URDE_PROJECT_RESOURCE_FACTORY_BASE_HPP
|