summaryrefslogtreecommitdiff
path: root/ZAPD/ZTexture.cpp
diff options
context:
space:
mode:
authorbriaguya <70942617+briaguya-ai@users.noreply.github.com>2023-10-17 22:04:12 -0400
committerbriaguya <70942617+briaguya-ai@users.noreply.github.com>2023-10-17 22:04:12 -0400
commite9f4fc638ed904cc0dcdac24ea7708c9a220a702 (patch)
tree114c3d432697e04831741e623ae2340f6239bbe9 /ZAPD/ZTexture.cpp
parentdcf56d93ecbd4db3bfd8a4832d7f991467964b98 (diff)
update to latest version used by SoH
Diffstat (limited to 'ZAPD/ZTexture.cpp')
-rw-r--r--ZAPD/ZTexture.cpp73
1 files changed, 50 insertions, 23 deletions
diff --git a/ZAPD/ZTexture.cpp b/ZAPD/ZTexture.cpp
index 74b7c7d..5184b83 100644
--- a/ZAPD/ZTexture.cpp
+++ b/ZAPD/ZTexture.cpp
@@ -6,7 +6,7 @@
#include "Globals.h"
#include "Utils/BitConverter.h"
#include "Utils/Directory.h"
-#include "Utils/File.h"
+#include <Utils/DiskFile.h>
#include "Utils/Path.h"
#include "WarningHandler.h"
@@ -17,6 +17,7 @@ ZTexture::ZTexture(ZFile* nParent) : ZResource(nParent)
width = 0;
height = 0;
dWordAligned = true;
+ genOTRDef = true;
splitTlut = false;
RegisterRequiredAttribute("Width");
@@ -26,6 +27,13 @@ ZTexture::ZTexture(ZFile* nParent) : ZResource(nParent)
RegisterOptionalAttribute("ExternalTlut");
RegisterOptionalAttribute("ExternalTlutOffset");
RegisterOptionalAttribute("SplitTlut");
+
+ // Dummy property added by https://github.com/HarbourMasters/Shipwright/pull/3161
+ // Used to indicate if a resource definition was added through a script
+ // and to enable easy removal/re-add of the definitions when introducing new rom support
+ // Can be removed once we feel it is no longer useful
+ // This is not used in ZAPD itself, the registration is to prevent missing attribute errors
+ RegisterOptionalAttribute("AddedByScript");
}
void ZTexture::ExtractFromBinary(uint32_t nRawDataIndex, int32_t nWidth, int32_t nHeight,
@@ -423,7 +431,7 @@ void ZTexture::PrepareRawDataFromFile(const fs::path& pngFilePath)
height = textureData.GetHeight();
textureDataRaw.clear();
- textureDataRaw.resize(ALIGN8(GetRawDataSize()));
+ textureDataRaw.resize(GetRawDataSize());
switch (format)
{
@@ -719,16 +727,21 @@ TextureType ZTexture::GetTextureType() const
return format;
}
+
void ZTexture::Save(const fs::path& outFolder)
{
// Optionally generate text file containing CRC information. This is going to be a one time
// process for generating the Texture Pool XML.
if (Globals::Instance->outputCrc)
{
- File::WriteAllText((Globals::Instance->outputPath / (outName + ".txt")).string(),
+ DiskFile::WriteAllText((Globals::Instance->outputPath / (outName + ".txt")).string(),
StringHelper::Sprintf("%08lX", hash));
}
+ // Do not save png files if we're making an OTR file. They're not needed...
+ if (Globals::Instance->otrMode)
+ return;
+
auto outPath = GetPoolOutPath(outFolder);
if (!Directory::Exists(outPath.string()))
@@ -761,6 +774,10 @@ Declaration* ZTexture::DeclareVar(const std::string& prefix,
std::string auxName = name;
std::string auxOutName = outName;
std::string incStr;
+
+ //if (Globals::Instance->otrMode)
+ //return nullptr;
+
if (auxName == "")
auxName = GetDefaultName(prefix);
@@ -804,25 +821,32 @@ Declaration* ZTexture::DeclareVar(const std::string& prefix,
std::string ZTexture::GetBodySourceCode() const
{
std::string sourceOutput;
- size_t texSizeInc = (dWordAligned) ? 8 : 4;
- for (size_t i = 0; i < textureDataRaw.size(); i += texSizeInc)
- {
- if (i % 32 == 0)
- sourceOutput += " ";
- if (dWordAligned)
- sourceOutput +=
- StringHelper::Sprintf("0x%016llX, ", BitConverter::ToUInt64BE(textureDataRaw, i));
- else
- sourceOutput +=
- StringHelper::Sprintf("0x%08llX, ", BitConverter::ToUInt32BE(textureDataRaw, i));
- if (i % 32 == 24)
- sourceOutput += StringHelper::Sprintf(" // 0x%06X \n", rawDataIndex + ((i / 32) * 32));
- }
- // Ensure there's always a trailing line feed to prevent dumb warnings.
- // Please don't remove this line, unless you somehow made a way to prevent
- // that warning when building the OoT repo.
- sourceOutput += "\n";
+ if (!Globals::Instance->otrMode)
+ {
+ size_t texSizeInc = (dWordAligned) ? 8 : 4;
+ for (size_t i = 0; i < textureDataRaw.size(); i += texSizeInc)
+ {
+ if (i % 32 == 0)
+ sourceOutput += " ";
+ if (dWordAligned)
+ sourceOutput += StringHelper::Sprintf("0x%016llX, ",
+ BitConverter::ToUInt64BE(textureDataRaw, i));
+ else
+ sourceOutput += StringHelper::Sprintf("0x%08llX, ",
+ BitConverter::ToUInt32BE(textureDataRaw, i));
+ if (i % 32 == 24)
+ sourceOutput +=
+ StringHelper::Sprintf(" // 0x%06X \n", rawDataIndex + ((i / 32) * 32));
+ }
+
+ // Ensure there's always a trailing line feed to prevent dumb warnings.
+ // Please don't remove this line, unless you somehow made a way to prevent
+ // that warning when building the OoT repo.
+ sourceOutput += "\n";
+ } else if (Globals::Instance->buildRawTexture) {
+ sourceOutput += std::string(textureDataRaw.begin(), textureDataRaw.end());
+ }
return sourceOutput;
}
@@ -844,8 +868,11 @@ std::string ZTexture::GetSourceTypeName() const
void ZTexture::CalcHash()
{
- auto parentRawData = parent->GetRawData();
- hash = CRC32B(parentRawData.data() + rawDataIndex, GetRawDataSize());
+ //if (hash == 0)
+ {
+ const auto& parentRawData = parent->GetRawData();
+ hash = CRC32B(parentRawData.data() + rawDataIndex, GetRawDataSize());
+ }
}
std::string ZTexture::GetExternalExtension() const