summaryrefslogtreecommitdiff
path: root/ZAPD/ZTexture.cpp
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2021-10-05 13:55:55 -0300
committerGitHub <noreply@github.com>2021-10-05 12:55:55 -0400
commit4994e732406ffa2942f9c9ea6ff14c424cd0b896 (patch)
tree0b40b20db17139c58f5c205643940494c20cbc43 /ZAPD/ZTexture.cpp
parent17fca1e0cdda5476c4158940ca405b7eb250ec72 (diff)
ZResource cleanup (#178)
* Add some general use methods to ZResource * change zarray * adapt ztexture * Clean up ZCollision, ZPath, ZScalar and ZVector * cleanup background * cleanup zmtx * Clean up skeleton and limb * mark GetSourceTypeName as abstract * Remove redundant ExtractFromXML * Reorder stuff to minimize changes in github * remove extra ZDisplayList constructor * Remove using namespace tinyxml2; * run formatter * Add some brief descriptions, and remove some methods * Remove trivials GetSourceOutputCode and a bit of cleanup * Add more descriptions to methods * Fix blob build * improve descriptions a bit * Run formatter * Now builds * Add attributes and fix some warnings * format * fix merge issues * fix merge issues and some clang warnings * format * Run formatter * Fix merge issues * Format * add SEGMENTED_NULL * Fix merge issues * Run format * dumb fix * whoops * format * whoops
Diffstat (limited to 'ZAPD/ZTexture.cpp')
-rw-r--r--ZAPD/ZTexture.cpp42
1 files changed, 24 insertions, 18 deletions
diff --git a/ZAPD/ZTexture.cpp b/ZAPD/ZTexture.cpp
index 6a929c4..72014f6 100644
--- a/ZAPD/ZTexture.cpp
+++ b/ZAPD/ZTexture.cpp
@@ -1,6 +1,7 @@
#include "ZTexture.h"
#include <cassert>
+
#include "CRC32.h"
#include "Globals.h"
#include "Utils/BitConverter.h"
@@ -21,22 +22,8 @@ ZTexture::ZTexture(ZFile* nParent) : ZResource(nParent)
RegisterOptionalAttribute("TlutOffset");
}
-void ZTexture::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
-{
- ZResource::ExtractFromXML(reader, nRawDataIndex);
-
- auto filepath = Globals::Instance->outputPath / fs::path(name).stem();
-
- std::string incStr =
- StringHelper::Sprintf("%s.%s.inc.c", filepath.c_str(), GetExternalExtension().c_str());
-
- Declaration* decl = parent->AddDeclarationIncludeArray(
- rawDataIndex, incStr, GetRawDataSize(), GetSourceTypeName(), name, GetRawDataSize() / 8);
- decl->staticConf = staticConf;
-}
-
-void ZTexture::FromBinary(uint32_t nRawDataIndex, int32_t nWidth, int32_t nHeight,
- TextureType nType, bool nIsPalette)
+void ZTexture::ExtractFromBinary(uint32_t nRawDataIndex, int32_t nWidth, int32_t nHeight,
+ TextureType nType, bool nIsPalette)
{
width = nWidth;
height = nHeight;
@@ -345,7 +332,7 @@ void ZTexture::DeclareReferences([[maybe_unused]] const std::string& prefix)
GetExternalExtension().c_str());
tlut = new ZTexture(parent);
- tlut->FromBinary(tlutOffset, tlutDim, tlutDim, TextureType::RGBA16bpp, true);
+ tlut->ExtractFromBinary(tlutOffset, tlutDim, tlutDim, TextureType::RGBA16bpp, true);
parent->AddTextureResource(tlutOffset, tlut);
parent->AddDeclarationIncludeArray(tlutOffset, incStr, tlut->GetRawDataSize(),
tlut->GetSourceTypeName(), tlut->GetName(), 0);
@@ -686,7 +673,7 @@ std::string ZTexture::GetIMSizFromType()
}
}
-std::string ZTexture::GetDefaultName(const std::string& prefix)
+std::string ZTexture::GetDefaultName(const std::string& prefix) const
{
const char* suffix = "Tex";
if (isPalette)
@@ -747,6 +734,25 @@ void ZTexture::Save(const fs::path& outFolder)
#endif
}
+Declaration* ZTexture::DeclareVar(const std::string& prefix,
+ [[maybe_unused]] const std::string& bodyStr)
+{
+ std::string auxName = name;
+
+ if (name == "")
+ auxName = GetDefaultName(prefix);
+
+ auto filepath = Globals::Instance->outputPath / fs::path(auxName).stem();
+
+ std::string incStr =
+ StringHelper::Sprintf("%s.%s.inc.c", filepath.c_str(), GetExternalExtension().c_str());
+
+ Declaration* decl = parent->AddDeclarationIncludeArray(rawDataIndex, incStr, GetRawDataSize(),
+ GetSourceTypeName(), auxName, 0);
+ decl->staticConf = staticConf;
+ return decl;
+}
+
std::string ZTexture::GetBodySourceCode() const
{
std::string sourceOutput = "";