summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmaro Martínez <xoas@airmail.cc>2023-03-02 09:37:47 -0500
committerGitHub <noreply@github.com>2023-03-02 15:37:47 +0100
commit2cb9df0be10a4361c4cddce67afdfc95c5276bb2 (patch)
tree6d51a5e1c556cbcb1450d796c11c23e010920a6a
parent8ac0f4e8409b27f90870c8bdaa639ff4356256e0 (diff)
Simplify Asset Headers (#2474)
-rw-r--r--ZAPD/ZFile.cpp21
-rw-r--r--ZAPD/ZResource.cpp24
2 files changed, 21 insertions, 24 deletions
diff --git a/ZAPD/ZFile.cpp b/ZAPD/ZFile.cpp
index a1d9978..4626473 100644
--- a/ZAPD/ZFile.cpp
+++ b/ZAPD/ZFile.cpp
@@ -800,19 +800,22 @@ void ZFile::GenerateSourceHeaderFiles()
{
OutputFormatter formatter;
- formatter.Write("#pragma once\n");
+ formatter.Write("#pragma once\n\n");
+ formatter.Write("#include \"align_asset_macro.h\"\n");
std::set<std::string> nameSet;
for (ZResource* res : resources)
{
std::string resSrc = res->GetSourceOutputHeader("", &nameSet);
- formatter.Write(resSrc);
-
- if (resSrc != "")
- formatter.Write("\n");
+ if (!resSrc.empty())
+ {
+ formatter.Write(resSrc.front() == '\n' ? resSrc : "\n" + resSrc);
+ formatter.Write(res == resources.back() ? "" : "\n");
+ }
}
for (auto& sym : symbolResources)
{
+ formatter.Write("\n\n");
formatter.Write(sym.second->GetSourceOutputHeader("", &nameSet));
}
@@ -823,8 +826,12 @@ void ZFile::GenerateSourceHeaderFiles()
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_INFO)
printf("Writing H file: %s\n", headerFilename.c_str());
+ std::string output = formatter.GetOutput();
+ while (output.back() == '\n')
+ output.pop_back();
+
if (Globals::Instance->fileMode != ZFileMode::ExtractDirectory)
- File::WriteAllText(headerFilename, formatter.GetOutput());
+ File::WriteAllText(headerFilename, output);
else if (Globals::Instance->sourceOutputPath != "")
{
std::string xmlPath = xmlFilePath.string();
@@ -849,7 +856,7 @@ void ZFile::GenerateSourceHeaderFiles()
outPath += "/";
}
- File::WriteAllText(outPath, formatter.GetOutput());
+ File::WriteAllText(outPath, output);
}
}
diff --git a/ZAPD/ZResource.cpp b/ZAPD/ZResource.cpp
index 9afd704..dd7a458 100644
--- a/ZAPD/ZResource.cpp
+++ b/ZAPD/ZResource.cpp
@@ -309,7 +309,7 @@ std::string ZResource::GetSourceOutputHeader([[maybe_unused]] const std::string&
{
if (Globals::Instance->otrMode && genOTRDef)
{
- std::string str = "";;
+ std::string str = "";
std::string nameStr = StringHelper::Strip(StringHelper::Strip(name, "\n"), "\r");
std::string outName = parent->GetOutName();
@@ -344,18 +344,13 @@ std::string ZResource::GetSourceOutputHeader([[maybe_unused]] const std::string&
if (prefix != "") {
str += StringHelper::Sprintf("#define d%s \"__OTR__%s/%s/%s\"", name.c_str(), prefix.c_str(), outName.c_str(), nameStr.c_str());
- }
+ }
else
str += StringHelper::Sprintf("#define d%s \"__OTR__%s/%s\"", name.c_str(), outName.c_str(), nameStr.c_str());
if (nameSet && nameSet->find(name) == nameSet->end()) {
- str += StringHelper::Sprintf(R"(
-#ifdef _WIN32
-static const __declspec(align(2)) char %s[] = d%s;
-#else
-static const char %s[] __attribute__((aligned (2))) = d%s;
-#endif
- )", name.c_str(), name.c_str(), name.c_str(), name.c_str());
+ str += StringHelper::Sprintf("\n");
+ str += StringHelper::Sprintf(R"(static const ALIGN_ASSET(2) char %s[] = d%s;)", name.c_str(), name.c_str());
if (nameSet) {
nameSet->insert(name);
@@ -366,16 +361,11 @@ static const char %s[] __attribute__((aligned (2))) = d%s;
{
std::string addName = "gTitleZeldaShieldLogoTex";
nameStr = StringHelper::Strip(StringHelper::Strip(addName, "\n"), "\r");
- str += StringHelper::Sprintf("\n#define d%s \"__OTR__%s/%s/%s\"", addName.c_str(), prefix.c_str(), outName.c_str(), nameStr.c_str());
+ str += StringHelper::Sprintf("\n\n#define d%s \"__OTR__%s/%s/%s\"", addName.c_str(), prefix.c_str(), outName.c_str(), nameStr.c_str());
if (nameSet && nameSet->find(addName) == nameSet->end())
{
- str += StringHelper::Sprintf(R"(
-#ifdef _WIN32
-static const __declspec(align(2)) char %s[] = d%s;
-#else
-static const char %s[] __attribute__((aligned (2))) = d%s;
-#endif
- )", addName.c_str(), addName.c_str(), addName.c_str(), addName.c_str());
+ str += StringHelper::Sprintf("\n");
+ str += StringHelper::Sprintf(R"(static const ALIGN_ASSET(2) char %s[] = d%s;)", addName.c_str(), addName.c_str());
if (nameSet)
{