metaforce/DataSpec/SpecBase.hpp

245 lines
12 KiB
C++
Raw Normal View History

2015-07-01 23:50:39 +00:00
#ifndef SPECBASE_HPP
#define SPECBASE_HPP
#include <functional>
#include <thread>
2015-07-01 23:50:39 +00:00
2017-12-29 08:08:12 +00:00
#include "hecl/Database.hpp"
#include "hecl/Blender/Token.hpp"
#include "Runtime/RetroTypes.hpp"
2016-10-02 22:41:36 +00:00
2017-12-29 08:08:12 +00:00
namespace nod
{
class DiscBase;
class Node;
}
namespace athena::io
{
class FileWriter;
class YAMLDocWriter;
}
2016-02-13 09:02:47 +00:00
namespace DataSpec
2015-07-01 23:50:39 +00:00
{
template <typename IDType>
class IDRestorer
{
std::vector<std::pair<IDType, IDType>> m_newToOrig;
std::vector<std::pair<IDType, IDType>> m_origToNew;
public:
IDRestorer(const hecl::ProjectPath& yamlPath, const hecl::Database::Project& project);
IDType newToOriginal(IDType id) const;
IDType originalToNew(IDType id) const;
};
2016-03-04 23:04:53 +00:00
struct SpecBase : hecl::Database::IDataSpec
2015-07-01 23:50:39 +00:00
{
2015-10-04 05:08:56 +00:00
/* HECL Adaptors */
void setThreadProject();
2015-10-04 05:08:56 +00:00
bool canExtract(const ExtractPassInfo& info, std::vector<ExtractReport>& reps);
2018-03-23 21:56:17 +00:00
void doExtract(const ExtractPassInfo& info, const hecl::MultiProgressPrinter& progress);
2015-07-01 23:50:39 +00:00
2018-04-02 04:27:24 +00:00
bool canCook(const hecl::ProjectPath& path, hecl::blender::Token& btok, int cookPass);
const hecl::Database::DataSpecEntry* overrideDataSpec(const hecl::ProjectPath& path,
const hecl::Database::DataSpecEntry* oldEntry,
2017-12-29 08:08:12 +00:00
hecl::blender::Token& btok) const;
void doCook(const hecl::ProjectPath& path, const hecl::ProjectPath& cookedPath,
2017-12-29 08:08:12 +00:00
bool fast, hecl::blender::Token& btok, FCookProgress progress);
2015-07-01 23:50:39 +00:00
bool canPackage(const hecl::ProjectPath& path);
void doPackage(const hecl::ProjectPath& path, const hecl::Database::DataSpecEntry* entry,
2018-03-23 21:56:17 +00:00
bool fast, hecl::blender::Token& btok, const hecl::MultiProgressPrinter& progress,
hecl::ClientProcess* cp);
2015-07-01 23:50:39 +00:00
2018-05-26 03:07:29 +00:00
void interruptCook();
2015-10-04 05:08:56 +00:00
/* Extract handlers */
2015-07-14 01:07:15 +00:00
virtual bool checkStandaloneID(const char* id) const=0;
2016-03-04 23:04:53 +00:00
virtual bool checkFromStandaloneDisc(nod::DiscBase& disc,
const hecl::SystemString& regstr,
const std::vector<hecl::SystemString>& args,
2015-10-04 05:08:56 +00:00
std::vector<ExtractReport>& reps)=0;
2016-03-04 23:04:53 +00:00
virtual bool checkFromTrilogyDisc(nod::DiscBase& disc,
const hecl::SystemString& regstr,
const std::vector<hecl::SystemString>& args,
2015-10-04 05:08:56 +00:00
std::vector<ExtractReport>& reps)=0;
2016-03-04 23:04:53 +00:00
virtual bool extractFromDisc(nod::DiscBase& disc, bool force,
2018-03-23 21:56:17 +00:00
const hecl::MultiProgressPrinter& progress)=0;
2015-07-01 23:50:39 +00:00
2016-10-02 22:41:36 +00:00
/* Convert path to object tag */
virtual urde::SObjectTag buildTagFromPath(const hecl::ProjectPath& path,
2017-12-29 08:08:12 +00:00
hecl::blender::Token& btok) const=0;
2016-10-02 22:41:36 +00:00
/* Even if PC spec is being cooked, this will return the vanilla GCN spec */
virtual const hecl::Database::DataSpecEntry& getOriginalSpec() const=0;
/* This will return a pseudo-spec for unmodified resources */
virtual const hecl::Database::DataSpecEntry& getUnmodifiedSpec() const=0;
2015-10-04 05:08:56 +00:00
/* Basic path check (game directory matching) */
2016-10-01 23:20:20 +00:00
virtual bool checkPathPrefix(const hecl::ProjectPath& path) const=0;
2015-10-04 05:08:56 +00:00
/* Pre-cook handlers */
2016-08-22 03:47:48 +00:00
virtual bool validateYAMLDNAType(athena::io::IStreamReader& fp) const=0;
2015-07-01 23:50:39 +00:00
2015-10-04 05:08:56 +00:00
/* Cook handlers */
2017-12-29 08:08:12 +00:00
using BlendStream = hecl::blender::DataStream;
using Mesh = hecl::blender::Mesh;
using ColMesh = hecl::blender::ColMesh;
2018-02-25 08:23:27 +00:00
using PathMesh = hecl::blender::PathMesh;
2017-12-29 08:08:12 +00:00
using Light = hecl::blender::Light;
using Actor = hecl::blender::Actor;
2015-10-04 05:08:56 +00:00
virtual void cookMesh(const hecl::ProjectPath& out, const hecl::ProjectPath& in,
2017-12-29 08:08:12 +00:00
BlendStream& ds, bool fast, hecl::blender::Token& btok,
2016-04-10 04:49:02 +00:00
FCookProgress progress)=0;
2017-10-17 05:51:53 +00:00
virtual void cookColMesh(const hecl::ProjectPath& out, const hecl::ProjectPath& in,
2017-12-29 08:08:12 +00:00
BlendStream& ds, bool fast, hecl::blender::Token& btok,
2017-10-17 05:51:53 +00:00
FCookProgress progress)=0;
2018-02-25 08:23:27 +00:00
virtual void cookPathMesh(const hecl::ProjectPath& out, const hecl::ProjectPath& in,
BlendStream& ds, bool fast, hecl::blender::Token& btok,
FCookProgress progress)=0;
virtual void cookActor(const hecl::ProjectPath& out, const hecl::ProjectPath& in,
2017-12-29 08:08:12 +00:00
BlendStream& ds, bool fast, hecl::blender::Token& btok,
2016-04-10 04:49:02 +00:00
FCookProgress progress)=0;
virtual void cookArea(const hecl::ProjectPath& out, const hecl::ProjectPath& in,
2017-12-29 08:08:12 +00:00
BlendStream& ds, bool fast, hecl::blender::Token& btok,
2016-04-10 04:49:02 +00:00
FCookProgress progress)=0;
virtual void cookWorld(const hecl::ProjectPath& out, const hecl::ProjectPath& in,
2017-12-29 08:08:12 +00:00
BlendStream& ds, bool fast, hecl::blender::Token& btok,
FCookProgress progress)=0;
virtual void cookGuiFrame(const hecl::ProjectPath& out, const hecl::ProjectPath& in,
2017-12-29 08:08:12 +00:00
BlendStream& ds, hecl::blender::Token& btok,
FCookProgress progress)=0;
virtual void cookYAML(const hecl::ProjectPath& out, const hecl::ProjectPath& in,
2016-08-22 03:47:48 +00:00
athena::io::IStreamReader& fin, FCookProgress progress)=0;
2016-09-18 23:47:48 +00:00
virtual void cookAudioGroup(const hecl::ProjectPath& out, const hecl::ProjectPath& in,
FCookProgress progress)=0;
virtual void cookSong(const hecl::ProjectPath& out, const hecl::ProjectPath& in,
FCookProgress progress)=0;
2017-03-20 05:09:53 +00:00
virtual void cookMapArea(const hecl::ProjectPath& out, const hecl::ProjectPath& in,
2017-12-29 08:08:12 +00:00
BlendStream& ds, hecl::blender::Token& btok,
2017-03-20 05:09:53 +00:00
FCookProgress progress)=0;
virtual void cookMapUniverse(const hecl::ProjectPath& out, const hecl::ProjectPath& in,
2017-12-29 08:08:12 +00:00
BlendStream& ds, hecl::blender::Token& btok,
2017-03-20 05:09:53 +00:00
FCookProgress progress)=0;
2015-10-04 05:08:56 +00:00
2016-10-02 22:41:36 +00:00
/* Dependency flatteners */
void flattenDependencies(const hecl::ProjectPath& in,
std::vector<hecl::ProjectPath>& pathsOut,
hecl::blender::Token& btok,
int charIdx = -1);
void flattenDependencies(const class UniqueID32& id, std::vector<hecl::ProjectPath>& pathsOut, int charIdx = -1);
void flattenDependencies(const class UniqueID64& id, std::vector<hecl::ProjectPath>& pathsOut, int charIdx = -1);
void flattenDependenciesBlend(const hecl::ProjectPath& in,
std::vector<hecl::ProjectPath>& pathsOut,
hecl::blender::Token& btok,
int charIdx = -1);
2016-10-02 22:41:36 +00:00
virtual void flattenDependenciesYAML(athena::io::IStreamReader& fin, std::vector<hecl::ProjectPath>& pathsOut)=0;
virtual void flattenDependenciesANCSYAML(athena::io::IStreamReader& fin,
std::vector<hecl::ProjectPath>& pathsOut,
int charIdx = -1)=0;
2016-10-02 22:41:36 +00:00
virtual void buildWorldPakList(const hecl::ProjectPath& worldPath,
const hecl::ProjectPath& worldPathCooked,
2017-12-29 08:08:12 +00:00
hecl::blender::Token& btok,
athena::io::FileWriter& w,
std::vector<urde::SObjectTag>& listOut,
2018-04-02 04:27:24 +00:00
atUint64& resTableOffset,
std::unordered_map<urde::CAssetId, std::vector<uint8_t>>& mlvlData) {}
2017-12-29 08:08:12 +00:00
virtual void buildPakList(hecl::blender::Token& btok,
athena::io::FileWriter& w,
const std::vector<urde::SObjectTag>& list,
const std::vector<std::pair<urde::SObjectTag, std::string>>& nameList,
atUint64& resTableOffset) {}
virtual void writePakFileIndex(athena::io::FileWriter& w,
const std::vector<urde::SObjectTag>& tags,
const std::vector<std::tuple<size_t, size_t, bool>>& index,
atUint64 resTableOffset) {}
virtual std::pair<std::unique_ptr<uint8_t[]>, size_t>
compressPakData(const urde::SObjectTag& tag, const uint8_t* data, size_t len) { return {}; }
2016-03-04 23:04:53 +00:00
const hecl::ProjectPath& getMasterShaderPath() const {return m_masterShader;}
2015-08-05 21:46:07 +00:00
2015-11-10 02:07:15 +00:00
/* Support functions for resolving paths from IDs */
2016-03-04 23:04:53 +00:00
virtual hecl::ProjectPath getWorking(class UniqueID32&) {return hecl::ProjectPath();}
virtual hecl::ProjectPath getWorking(class UniqueID64&) {return hecl::ProjectPath();}
2015-11-10 02:07:15 +00:00
hecl::ProjectPath getCookedPath(const hecl::ProjectPath& working, bool pcTarget) const;
2015-11-10 02:07:15 +00:00
/* Project accessor */
2016-03-05 00:03:41 +00:00
hecl::Database::Project& getProject() const {return m_project;}
2015-11-10 02:07:15 +00:00
2017-06-01 05:34:24 +00:00
/* Extract RandomStatic entropy */
void extractRandomStaticEntropy(const uint8_t* buf, const hecl::ProjectPath& noAramPath);
/* Tag cache functions */
2017-12-29 08:08:12 +00:00
urde::SObjectTag tagFromPath(const hecl::ProjectPath& path, hecl::blender::Token& btok) const;
hecl::ProjectPath pathFromTag(const urde::SObjectTag& tag) const;
bool waitForTagReady(const urde::SObjectTag& tag, const hecl::ProjectPath*& pathOut);
2017-11-13 06:19:18 +00:00
const urde::SObjectTag* getResourceIdByName(std::string_view name) const;
hecl::FourCC getResourceTypeById(urde::CAssetId id) const;
void enumerateResources(const std::function<bool(const urde::SObjectTag&)>& lambda) const;
void enumerateNamedResources(
2017-11-13 06:19:18 +00:00
const std::function<bool(std::string_view, const urde::SObjectTag&)>& lambda) const;
void cancelBackgroundIndex();
void beginBackgroundIndex();
bool backgroundIndexRunning() const { return m_backgroundRunning; }
void waitForIndexComplete() const;
virtual void getTagListForFile(const char* pakName, std::vector<urde::SObjectTag>& out) const {}
2017-06-01 05:34:24 +00:00
SpecBase(const hecl::Database::DataSpecEntry* specEntry, hecl::Database::Project& project, bool pc);
~SpecBase();
2015-08-05 21:46:07 +00:00
protected:
2016-03-04 23:04:53 +00:00
hecl::Database::Project& m_project;
bool m_pc;
2016-03-04 23:04:53 +00:00
hecl::ProjectPath m_masterShader;
std::unordered_map<urde::SObjectTag, hecl::ProjectPath> m_tagToPath;
std::unordered_map<hecl::Hash, urde::SObjectTag> m_pathToTag;
std::unordered_map<std::string, urde::SObjectTag> m_catalogNameToTag;
2018-04-02 04:27:24 +00:00
std::unordered_map<urde::SObjectTag, std::unordered_set<std::string>> m_catalogTagToNames;
void clearTagCache();
2018-04-07 20:55:57 +00:00
2017-12-29 08:08:12 +00:00
hecl::blender::Token m_backgroundBlender;
std::thread m_backgroundIndexTh;
std::mutex m_backgroundIndexMutex;
bool m_backgroundRunning = false;
void readCatalog(const hecl::ProjectPath& catalogPath,
athena::io::YAMLDocWriter& nameWriter);
bool addFileToIndex(const hecl::ProjectPath& path,
athena::io::YAMLDocWriter& cacheWriter);
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);
void backgroundIndexProc();
void recursiveBuildResourceList(std::vector<urde::SObjectTag>& listOut,
2017-10-26 05:37:46 +00:00
std::unordered_set<urde::SObjectTag>& addedTags,
const hecl::ProjectPath& path,
2017-12-29 08:08:12 +00:00
hecl::blender::Token& btok);
void copyBuildListData(std::vector<std::tuple<size_t, size_t, bool>>& fileIndex,
const std::vector<urde::SObjectTag>& buildList,
const hecl::Database::DataSpecEntry* entry,
2018-03-23 21:56:17 +00:00
bool fast, const hecl::MultiProgressPrinter& progress,
2018-04-02 04:27:24 +00:00
athena::io::FileWriter& pakOut,
const std::unordered_map<urde::CAssetId, std::vector<uint8_t>>& mlvlData);
2016-03-04 23:04:53 +00:00
std::unique_ptr<nod::DiscBase> m_disc;
bool m_isWii;
bool m_standalone;
2015-07-01 23:50:39 +00:00
};
}
#endif // SPECBASE_HPP