diff options
| author | Anghelo Carvajal <angheloalf95@gmail.com> | 2021-04-28 05:19:50 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-28 05:19:50 -0400 |
| commit | b9120803e6094a54192ed67d9585ab046101c816 (patch) | |
| tree | df259449343cd0c5230dd2a5e1e9d5293d20c563 /ZAPD/Main.cpp | |
| parent | 50ad2fe786af4cf66998028a08c767e16a416a60 (diff) | |
Use OutputFormatter for every C and H file, to improve the generated output (#122)
* Small changes in collision
* Use outputformatter to write C files
* Outputformatter for .h files
* Use more fs::path
* Use gfxd_udata_set and gfxd_udata_get instead of an instance
* Fix merge issues and warnings
* run format
Diffstat (limited to 'ZAPD/Main.cpp')
| -rw-r--r-- | ZAPD/Main.cpp | 57 |
1 files changed, 25 insertions, 32 deletions
diff --git a/ZAPD/Main.cpp b/ZAPD/Main.cpp index f044f34..a1dfb21 100644 --- a/ZAPD/Main.cpp +++ b/ZAPD/Main.cpp @@ -26,15 +26,14 @@ using namespace tinyxml2; using namespace std; -bool Parse(const std::string& xmlFilePath, const std::string& basePath, const std::string& outPath, +bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path& outPath, ZFileMode fileMode); -void BuildAssetTexture(const std::string& pngFilePath, TextureType texType, - const std::string& outPath); -void BuildAssetBackground(const std::string& imageFilePath, const std::string& outPath); -void BuildAssetBlob(const std::string& blobFilePath, const std::string& outPath); -void BuildAssetModelIntermediette(const std::string& outPath); -void BuildAssetAnimationIntermediette(const std::string& animPath, const std::string& outPath); +void BuildAssetTexture(const fs::path& pngFilePath, TextureType texType, const fs::path& outPath); +void BuildAssetBackground(const fs::path& imageFilePath, const fs::path& outPath); +void BuildAssetBlob(const fs::path& blobFilePath, const fs::path& outPath); +void BuildAssetModelIntermediette(const fs::path& outPath); +void BuildAssetAnimationIntermediette(const fs::path& animPath, const fs::path& outPath); #if !defined(_MSC_VER) && !defined(__CYGWIN__) void ErrorHandler(int sig) @@ -44,6 +43,9 @@ void ErrorHandler(int sig) size_t size = backtrace(array, nMaxFrames); char** symbols = backtrace_symbols(array, nMaxFrames); + // To prevent unused parameter warning + (void)sig; + for (size_t i = 1; i < size; i++) { Dl_info info; @@ -169,7 +171,8 @@ int main(int argc, char* argv[]) i++; } else if (arg == - "-uer") // Split resources into their individual components (enabled by default) TODO: We may wish to make this a part of the config file... + "-uer") // Split resources into their individual components (enabled by default) + // TODO: We may wish to make this a part of the config file... { Globals::Instance->useExternalResources = string(argv[i + 1]) == "1"; i++; @@ -179,7 +182,8 @@ int main(int argc, char* argv[]) Globals::Instance->texType = ZTexture::GetTextureTypeFromString(argv[i + 1]); i++; } - else if (arg == "-cfg") // Set cfg path (for overlays) TODO: Change the name of this to something else so it doesn't get confused with XML config files. + else if (arg == "-cfg") // Set cfg path (for overlays) + // TODO: Change the name of this to something else so it doesn't get confused with XML config files. { Globals::Instance->cfgPath = argv[i + 1]; i++; @@ -225,24 +229,16 @@ int main(int argc, char* argv[]) else if (fileMode == ZFileMode::BuildTexture) { TextureType texType = Globals::Instance->texType; - string pngFilePath = Globals::Instance->inputPath; - string outFilePath = Globals::Instance->outputPath; - BuildAssetTexture(pngFilePath, texType, outFilePath); + BuildAssetTexture(Globals::Instance->inputPath, texType, Globals::Instance->outputPath); } else if (fileMode == ZFileMode::BuildBackground) { - string imageFilePath = Globals::Instance->inputPath; - string outFilePath = Globals::Instance->outputPath; - - BuildAssetBackground(imageFilePath, outFilePath); + BuildAssetBackground(Globals::Instance->inputPath, Globals::Instance->outputPath); } else if (fileMode == ZFileMode::BuildBlob) { - string blobFilePath = Globals::Instance->inputPath; - string outFilePath = Globals::Instance->outputPath; - - BuildAssetBlob(blobFilePath, outFilePath); + BuildAssetBlob(Globals::Instance->inputPath, Globals::Instance->outputPath); } else if (fileMode == ZFileMode::BuildModelIntermediette) { @@ -271,7 +267,7 @@ int main(int argc, char* argv[]) return 0; } -bool Parse(const std::string& xmlFilePath, const std::string& basePath, const std::string& outPath, +bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path& outPath, ZFileMode fileMode) { XMLDocument doc; @@ -325,11 +321,10 @@ bool Parse(const std::string& xmlFilePath, const std::string& basePath, const st return true; } -void BuildAssetTexture(const std::string& pngFilePath, TextureType texType, - const std::string& outPath) +void BuildAssetTexture(const fs::path& pngFilePath, TextureType texType, const fs::path& outPath) { - vector<string> split = StringHelper::Split(outPath, "/"); - string name = StringHelper::Split(split[split.size() - 1], ".")[0]; + string name = outPath.stem(); + ZTexture* tex = ZTexture::FromPNG(pngFilePath, texType); string cfgPath = StringHelper::Split(pngFilePath, ".")[0] + ".cfg"; @@ -343,7 +338,7 @@ void BuildAssetTexture(const std::string& pngFilePath, TextureType texType, delete tex; } -void BuildAssetBackground(const std::string& imageFilePath, const std::string& outPath) +void BuildAssetBackground(const fs::path& imageFilePath, const fs::path& outPath) { ZBackground background(nullptr); background.ParseBinaryFile(imageFilePath, false); @@ -351,11 +346,10 @@ void BuildAssetBackground(const std::string& imageFilePath, const std::string& o File::WriteAllText(outPath, background.GetBodySourceCode()); } -void BuildAssetBlob(const std::string& blobFilePath, const std::string& outPath) +void BuildAssetBlob(const fs::path& blobFilePath, const fs::path& outPath) { - vector<string> split = StringHelper::Split(outPath, "/"); ZBlob* blob = ZBlob::FromFile(blobFilePath); - string name = StringHelper::Split(split[split.size() - 1], ".")[0]; + string name = outPath.stem(); // filename without extension string src = blob->GetSourceOutputCode(name); @@ -364,11 +358,10 @@ void BuildAssetBlob(const std::string& blobFilePath, const std::string& outPath) delete blob; } -void BuildAssetModelIntermediette(const std::string& outPath) +void BuildAssetModelIntermediette(const fs::path& outPath) { XMLDocument doc; - vector<string> split = StringHelper::Split(outPath, "/"); HLModelIntermediette* mdl = HLModelIntermediette::FromXML(doc.RootElement()); string output = mdl->OutputCode(); @@ -377,7 +370,7 @@ void BuildAssetModelIntermediette(const std::string& outPath) delete mdl; } -void BuildAssetAnimationIntermediette(const std::string& animPath, const std::string& outPath) +void BuildAssetAnimationIntermediette(const fs::path& animPath, const fs::path& outPath) { vector<string> split = StringHelper::Split(outPath, "/"); ZFile* file = new ZFile("", split[split.size() - 2]); |
