diff options
| author | Nicholas Estelami <NEstelami@users.noreply.github.com> | 2020-09-30 15:29:48 -0400 |
|---|---|---|
| committer | Nicholas Estelami <NEstelami@users.noreply.github.com> | 2020-09-30 15:29:48 -0400 |
| commit | 19ae94e8018248542e38559083c8ea4631d9c0c9 (patch) | |
| tree | 8ae01ba1503a4bae5f950174ead43220f514709c /ZAP2/Main.cpp | |
| parent | 14a8777d8187febb35df4f0f3c56cdd5662f3778 (diff) | |
- Updated how declarations are defined, removing the need for externs and allowing for more "intelligent" decisions to be made by the program depending on the contents of the declaration.
- Added in ZHierarchies, used for object skeletons.
- Textures are now compiled into .c.inc files and #include'd
- Added intermediette file formats to simplify file conversion process (for eventual modding support).
- Simplified various DList Macros
- Cleaned up a bunch of code, removing redundancies.
Diffstat (limited to 'ZAP2/Main.cpp')
| -rw-r--r-- | ZAP2/Main.cpp | 154 |
1 files changed, 134 insertions, 20 deletions
diff --git a/ZAP2/Main.cpp b/ZAP2/Main.cpp index 9e3b906..b8699ca 100644 --- a/ZAP2/Main.cpp +++ b/ZAP2/Main.cpp @@ -1,7 +1,9 @@ -// TODO: Instead of having a fixed number of arguments for each build mode, allow parameters to be modified with a set of "commands" - #include "ZFile.h" #include "ZTexture.h" +#include "ZBlob.h" +#include "ZAnimation.h" +#include "HighLevel/HLModelIntermediette.h" +#include "HighLevel/HLAnimationIntermediette.h" #include "Overlays/ZOverlay.h" #include "Path.h" #include "File.h" @@ -17,13 +19,18 @@ #include "tinyxml2.h" extern void ModelTest(); +extern void ModelTest2(); using namespace tinyxml2; using namespace std; bool Parse(string xmlFilePath, string basePath, string outPath, ZFileMode fileMode); + void BuildAssetTexture(string pngFilePath, TextureType texType, string outPath); -int OldMain(int argc, char* argv[]); +void BuildAssetBlob(string blobFilePath, string outPath); +void BuildAssetModelIntermediette(string mdlPath, string outPath); +void BuildAssetAnimationIntermediette(string animPath, string outPath); + int NewMain(int argc, char* argv[]); #ifndef _MSC_VER @@ -50,20 +57,12 @@ void ErrorHandler(int sig) int main(int argc, char* argv[]) { #ifndef _MSC_VER - signal(SIGSEGV, ErrorHandler); + //signal(SIGSEGV, ErrorHandler); #endif Globals* g = new Globals(); - // TEST TEST -#if _MSC_VER && _DEBUG - //ModelTest(); - //return 0; -#endif - return NewMain(argc, argv); - - return 0; } int NewMain(int argc, char* argv[]) @@ -81,12 +80,20 @@ int NewMain(int argc, char* argv[]) fileMode = ZFileMode::BuildTexture; else if (buildMode == "bovl") fileMode = ZFileMode::BuildOverlay; - else + else if (buildMode == "bsf") + fileMode = ZFileMode::BuildSourceFile; + else if (buildMode == "bblb") + fileMode = ZFileMode::BuildBlob; + else if (buildMode == "bmdlintr") + fileMode = ZFileMode::BuildModelIntermediette; + else if (buildMode == "bamnintr") + fileMode = ZFileMode::BuildAnimationIntermediette; + else if (buildMode == "e") fileMode = ZFileMode::Extract; if (fileMode == ZFileMode::Invalid) { - cout << "Error: Invalid file mode.\n"; + printf("Error: Invalid file mode '%s'\n", buildMode.c_str()); return 1; } @@ -110,11 +117,31 @@ int NewMain(int argc, char* argv[]) Globals::Instance->baseRomPath = argv[i + 1]; i++; } - else if (arg == "-gsf") // Generate source file + else if (arg == "-gsf") // Generate source file during extraction { Globals::Instance->genSourceFile = string(argv[i + 1]) == "1"; i++; } + else if (arg == "-ifp") // Include file prefix in generated symbols + { + Globals::Instance->includeFilePrefix = string(argv[i + 1]) == "1"; + i++; + } + else if (arg == "-tm") // Test Mode + { + Globals::Instance->testMode = string(argv[i + 1]) == "1"; + i++; + } + else if (arg == "-profile") // Profile + { + Globals::Instance->profile = string(argv[i + 1]) == "1"; + i++; + } + else if (arg == "-uer") // Split resources into their individual components (enabled by default) + { + Globals::Instance->useExternalResources = string(argv[i + 1]) == "1"; + i++; + } else if (arg == "-tt") // Set texture type { Globals::Instance->texType = ZTexture::GetTextureTypeFromString(argv[i + 1]); @@ -130,9 +157,23 @@ int NewMain(int argc, char* argv[]) Globals::Instance->GenSymbolMap(argv[i + 1]); i++; } + else if (arg == "-al") // Set actor list + { + i++; + } + else if (arg == "-ol") // Set object list + { + i++; + } + else if (arg == "-eh") // Enable Error Handler + { +#ifndef _MSC_VER + signal(SIGSEGV, ErrorHandler); +#endif + } } - if (fileMode == ZFileMode::Build || fileMode == ZFileMode::Extract) + if (fileMode == ZFileMode::Build || fileMode == ZFileMode::Extract || fileMode == ZFileMode::BuildSourceFile) { Parse(Globals::Instance->inputPath, Globals::Instance->baseRomPath, Globals::Instance->outputPath, fileMode); } @@ -144,6 +185,21 @@ int NewMain(int argc, char* argv[]) BuildAssetTexture(pngFilePath, texType, outFilePath); } + else if (fileMode == ZFileMode::BuildBlob) + { + string blobFilePath = Globals::Instance->inputPath; + string outFilePath = Globals::Instance->outputPath; + + BuildAssetBlob(blobFilePath, outFilePath); + } + else if (fileMode == ZFileMode::BuildModelIntermediette) + { + BuildAssetModelIntermediette(Globals::Instance->inputPath, Globals::Instance->outputPath); + } + else if (fileMode == ZFileMode::BuildAnimationIntermediette) + { + BuildAssetAnimationIntermediette(Globals::Instance->inputPath, Globals::Instance->outputPath); + } else if (fileMode == ZFileMode::BuildOverlay) { ZOverlay* overlay = ZOverlay::FromBuild(Path::GetDirectoryName(Globals::Instance->inputPath), Path::GetDirectoryName(Globals::Instance->cfgPath)); @@ -160,7 +216,6 @@ int NewMain(int argc, char* argv[]) bool Parse(string xmlFilePath, string basePath, string outPath, ZFileMode fileMode) { XMLDocument doc; - XMLError eResult = doc.LoadFile(xmlFilePath.c_str()); if (eResult != tinyxml2::XML_SUCCESS) @@ -177,9 +232,7 @@ bool Parse(string xmlFilePath, string basePath, string outPath, ZFileMode fileMo { if (string(child->Name()) == "File") { - //ZFile* file = new ZFile(fileMode, child, Path::GetDirectoryName(xmlFilePath)); ZFile* file = new ZFile(fileMode, child, basePath, outPath); - files.push_back(file); } } @@ -188,6 +241,8 @@ bool Parse(string xmlFilePath, string basePath, string outPath, ZFileMode fileMo { if (fileMode == ZFileMode::Build) file->BuildResources(); + else if (fileMode == ZFileMode::BuildSourceFile) + file->BuildSourceFile(outPath); else file->ExtractResources(outPath); } @@ -202,8 +257,67 @@ bool Parse(string xmlFilePath, string basePath, string outPath, ZFileMode fileMo void BuildAssetTexture(string pngFilePath, TextureType texType, string outPath) { + vector<string> split = StringHelper::Split(outPath, "/"); + string name = StringHelper::Split(split[split.size() - 1], ".")[0]; ZTexture* tex = ZTexture::FromPNG(pngFilePath, texType); - File::WriteAllBytes(outPath, tex->GetRawData()); + + string src = StringHelper::Sprintf("u64 %s[] = \n{\n", name.c_str()) + tex->GetSourceOutputCode(name) + "};\n"; + + File::WriteAllText(outPath, src); delete tex; +} + +void BuildAssetBlob(string blobFilePath, string outPath) +{ + vector<string> split = StringHelper::Split(outPath, "/"); + ZBlob* blob = ZBlob::FromFile(blobFilePath); + string name = StringHelper::Split(split[split.size() - 1], ".")[0]; + + string src = StringHelper::Sprintf("u8 %s[] = \n{\n", name.c_str()) + blob->GetSourceOutputCode(name) + "};\n"; + + File::WriteAllText(outPath, src); + + delete blob; +} + +void BuildAssetModelIntermediette(string mdlPath, string outPath) +{ + XMLDocument doc; + XMLError eResult = doc.LoadFile(mdlPath.c_str()); + + vector<string> split = StringHelper::Split(outPath, "/"); + HLModelIntermediette* mdl = HLModelIntermediette::FromXML(doc.RootElement()); + + string output = ""; + + output += mdl->OutputCode(); + + File::WriteAllText(outPath, output); + + delete mdl; +} + +void BuildAssetAnimationIntermediette(string animPath, string outPath) +{ + vector<string> split = StringHelper::Split(outPath, "/"); + ZFile* file = new ZFile("", split[split.size() - 2]); + HLAnimationIntermediette* anim = HLAnimationIntermediette::FromXML(animPath); + ZAnimation* zAnim = anim->ToZAnimation(); + zAnim->SetName(Path::GetFileNameWithoutExtension(split[split.size() - 1])); + zAnim->parent = file; + zAnim->rotationIndicesSeg = 1; + zAnim->rotationValuesSeg = 2; + + zAnim->GetSourceOutputCode(split[split.size() - 2]); + string output = ""; + + output += file->declarations[2]->text + "\n"; + output += file->declarations[1]->text + "\n"; + output += file->declarations[0]->text + "\n"; + + File::WriteAllText(outPath, output); + + delete zAnim; + delete file; }
\ No newline at end of file |
