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"
|
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
|
|
|
|
{
|
|
|
|
|
|
|
|
class ProjectResourceFactoryBase : public urde::IFactory
|
|
|
|
{
|
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
|
|
|
protected:
|
|
|
|
std::unordered_map<urde::SObjectTag, hecl::ProjectPath> m_tagToPath;
|
|
|
|
std::unordered_map<std::string, urde::SObjectTag> m_catalogNameToTag;
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
const hecl::Database::Project* m_proj = nullptr;
|
|
|
|
const hecl::Database::DataSpecEntry* m_origSpec = nullptr;
|
|
|
|
const hecl::Database::DataSpecEntry* m_pcSpec = nullptr;
|
2016-03-28 04:36:55 +00:00
|
|
|
/* Used to resolve cooked paths */
|
|
|
|
std::unique_ptr<hecl::Database::IDataSpec> m_cookSpec;
|
2016-03-26 00:51:59 +00:00
|
|
|
urde::CFactoryMgr m_factoryMgr;
|
|
|
|
|
2016-03-31 21:06:41 +00:00
|
|
|
hecl::BlenderToken m_backgroundBlender;
|
2016-03-26 00:51:59 +00:00
|
|
|
std::thread m_backgroundIndexTh;
|
|
|
|
std::mutex m_backgroundIndexMutex;
|
|
|
|
bool m_backgroundRunning = false;
|
|
|
|
|
2016-03-28 04:36:55 +00:00
|
|
|
struct AsyncTask
|
|
|
|
{
|
|
|
|
ProjectResourceFactoryBase& m_parent;
|
|
|
|
|
|
|
|
SObjectTag x0_tag;
|
2016-04-06 01:44:07 +00:00
|
|
|
//IDvdRequest* x8_dvdReq = nullptr;
|
2016-03-28 04:36:55 +00:00
|
|
|
IObj** xc_targetPtr = nullptr;
|
|
|
|
std::unique_ptr<u8[]> x10_loadBuffer;
|
|
|
|
u32 x14_resSize = 0;
|
|
|
|
CVParamTransfer x18_cvXfer;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
AsyncTask(ProjectResourceFactoryBase& parent, const SObjectTag& tag,
|
|
|
|
IObj** ptr, const CVParamTransfer& xfer)
|
|
|
|
: m_parent(parent), x0_tag(tag), xc_targetPtr(ptr), x18_cvXfer(xfer) {}
|
|
|
|
|
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();
|
|
|
|
};
|
|
|
|
std::unordered_map<SObjectTag, AsyncTask> m_asyncLoadList;
|
2016-03-26 00:51:59 +00:00
|
|
|
|
2016-03-31 21:06:41 +00:00
|
|
|
virtual SObjectTag TagFromPath(const hecl::ProjectPath& path, hecl::BlenderToken& btok) const=0;
|
2016-03-26 00:51:59 +00:00
|
|
|
|
2016-03-28 21:38:48 +00:00
|
|
|
void ReadCatalog(const hecl::ProjectPath& catalogPath,
|
|
|
|
athena::io::YAMLDocWriter& nameWriter);
|
|
|
|
void BackgroundIndexRecursiveProc(const hecl::ProjectPath& path,
|
|
|
|
athena::io::YAMLDocWriter& cacheWriter,
|
|
|
|
athena::io::YAMLDocWriter& nameWriter,
|
|
|
|
int level);
|
|
|
|
void BackgroundIndexRecursiveCatalogs(const hecl::ProjectPath& path,
|
|
|
|
athena::io::YAMLDocWriter& nameWriter,
|
|
|
|
int level);
|
2016-03-26 00:51:59 +00:00
|
|
|
void BackgroundIndexProc();
|
|
|
|
void CancelBackgroundIndex();
|
2016-03-28 04:36:55 +00:00
|
|
|
void BeginBackgroundIndex(hecl::Database::Project& proj,
|
2016-03-26 00:51:59 +00:00
|
|
|
const hecl::Database::DataSpecEntry& origSpec,
|
|
|
|
const hecl::Database::DataSpecEntry& pcSpec);
|
|
|
|
|
2016-03-28 04:36:55 +00:00
|
|
|
hecl::ProjectPath GetCookedPath(const hecl::ProjectPath& working, bool pcTarget) const;
|
|
|
|
bool SyncCook(const hecl::ProjectPath& working);
|
2016-03-29 23:14:14 +00:00
|
|
|
CFactoryFnReturn BuildSync(const SObjectTag& tag, const hecl::ProjectPath& path,
|
|
|
|
const CVParamTransfer& paramXfer);
|
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-03-26 00:51:59 +00:00
|
|
|
std::unique_ptr<urde::IObj> Build(const urde::SObjectTag&, const urde::CVParamTransfer&);
|
|
|
|
void BuildAsync(const urde::SObjectTag&, const urde::CVParamTransfer&, urde::IObj**);
|
|
|
|
void CancelBuild(const urde::SObjectTag&);
|
|
|
|
bool CanBuild(const urde::SObjectTag&);
|
|
|
|
const urde::SObjectTag* GetResourceIdByName(const char*) const;
|
2016-04-14 21:42:47 +00:00
|
|
|
FourCC GetResourceTypeById(ResId id) const;
|
2016-03-26 00:51:59 +00:00
|
|
|
|
|
|
|
void AsyncIdle();
|
2016-03-28 04:36:55 +00:00
|
|
|
void Shutdown() {CancelBackgroundIndex();}
|
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
|