diff options
| author | Nicholas Estelami <NEstelami@users.noreply.github.com> | 2021-08-05 05:11:24 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-05 05:11:24 -0400 |
| commit | 82bd27604a4c8f8c1f01f9c2f54c87fab103c39f (patch) | |
| tree | 282b189bd2d6113bf134a8b34d7ddc518369f3bb /ZAPD/ZFile.cpp | |
| parent | 469285b3e1f7885b42905fbfb9b4448f51ea20b3 (diff) | |
Exporter Support Added (#127)
* Initial exporter implementation
* Updated to use static library.
* minor cleanup
* Cleaned things up a bit
* Fixed merge issues
* Minor commenting
* Added Begin and End functions, and removed HL stuff (to be turned into an exporter at a later date)
* Cleaned some stuff up
* Additional cleanup
* Removed some commented out code
* Fixed compilation issues
* Cleanup
* Fixed merge issues
* Got rid of unused windows.h includes
* Cleanup
* Fixed warning
* Removed additional redundancies
* Cleanup
* Fixed merge issues
* Fixed some compiler issues, added makefile for exportertest.
* Removed redundancies and clang formatted
* Made sure exportertest compiles with C++17
* Moved certain files into new "Utils" folder.
* GetExporterMap uses a reference now
* Minor fixes and updates.
Co-authored-by: Jack Walker <7463599+Jack-Walker@users.noreply.github.com>
Diffstat (limited to 'ZAPD/ZFile.cpp')
| -rw-r--r-- | ZAPD/ZFile.cpp | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/ZAPD/ZFile.cpp b/ZAPD/ZFile.cpp index b09dc55..34b8083 100644 --- a/ZAPD/ZFile.cpp +++ b/ZAPD/ZFile.cpp @@ -1,13 +1,14 @@ #include "ZFile.h" +#include <Utils/BinaryWriter.h> +#include <Utils/MemoryStream.h> #include <algorithm> #include <cassert> #include <unordered_set> -#include "Directory.h" -#include "File.h" +#include "Utils/Directory.h" +#include "Utils/File.h" #include "Globals.h" -#include "HighLevel/HLModelIntermediette.h" #include "OutputFormatter.h" -#include "Path.h" +#include "Utils/Path.h" #include "ZAnimation.h" #include "ZArray.h" #include "ZBackground.h" @@ -235,7 +236,7 @@ void ZFile::DeclareResourceSubReferences() void ZFile::BuildSourceFile() { if (!Directory::Exists(Globals::Instance->outputPath)) - Directory::CreateDirectory(Globals::Instance->outputPath); + Directory::CreateDirectory(Globals::Instance->outputPath.string()); GenerateSourceFiles(Globals::Instance->outputPath); } @@ -269,7 +270,7 @@ const std::vector<uint8_t>& ZFile::GetRawData() const void ZFile::ExtractResources() { if (!Directory::Exists(Globals::Instance->outputPath)) - Directory::CreateDirectory(Globals::Instance->outputPath); + Directory::CreateDirectory(Globals::Instance->outputPath.string()); if (!Directory::Exists(GetSourceOutputFolderPath().string())) Directory::CreateDirectory(GetSourceOutputFolderPath().string()); @@ -280,16 +281,39 @@ void ZFile::ExtractResources() if (Globals::Instance->genSourceFile) GenerateSourceFiles(Globals::Instance->outputPath); + MemoryStream* memStream = new MemoryStream(); + BinaryWriter writer = BinaryWriter(memStream); + + ExporterSet* exporterSet = Globals::Instance->GetExporterSet(); + + if (exporterSet != nullptr && exporterSet->beginFileFunc != nullptr) + exporterSet->beginFileFunc(this); + for (ZResource* res : resources) { if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_INFO) printf("Saving resource %s\n", res->GetName().c_str()); - res->Save(Globals::Instance->outputPath); + res->CalcHash(); + res->Save(Globals::Instance->outputPath.string()); + + // Check if we have an exporter "registered" for this resource type + ZResourceExporter* exporter = Globals::Instance->GetExporter(res->GetResourceType()); + + if (exporter != nullptr) + exporter->Save(res, Globals::Instance->outputPath.string(), &writer); } - if (Globals::Instance->testMode) - GenerateHLIntermediette(); + if (memStream->GetLength() > 0) + { + File::WriteAllBytes(StringHelper::Sprintf("%s.bin", GetName().c_str()), + memStream->ToVector()); + } + + writer.Close(); + + if (exporterSet != nullptr && exporterSet->endFileFunc != nullptr) + exporterSet->endFileFunc(this); } void ZFile::AddResource(ZResource* res) @@ -598,7 +622,7 @@ void ZFile::GenerateSourceFiles(fs::path outputDir) Globals::Instance->cfg.texturePool.end()) { incStr = Globals::Instance->cfg.texturePool[tex->hash].path.string() + "." + - res->GetExternalExtension() + ".inc"; + res->GetExternalExtension() + ".inc"; } } @@ -660,22 +684,6 @@ void ZFile::GenerateSourceHeaderFiles() File::WriteAllText(headerFilename, formatter.GetOutput()); } -void ZFile::GenerateHLIntermediette() -{ - // This is kinda hacky but it gets the job done for now... - HLModelIntermediette* mdl = new HLModelIntermediette(); - - for (ZResource* res : resources) - { - if (res->GetResourceType() == ZResourceType::DisplayList || - res->GetResourceType() == ZResourceType::Skeleton) - res->GenerateHLIntermediette(*mdl); - } - - // std::string test = mdl->ToOBJFile(); - // std::string test2 = mdl->ToAssimpFile(); -} - std::string ZFile::GetHeaderInclude() { return StringHelper::Sprintf("#include \"%s\"\n\n", @@ -1029,9 +1037,7 @@ std::string ZFile::ProcessDeclarations() for (std::pair<uint32_t, Declaration*> item : declarations) { if (item.first < rangeStart || item.first >= rangeEnd) - { continue; - } if (item.second->includePath != "") { |
