summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ZAPD/Globals.cpp5
-rw-r--r--ZAPD/Globals.h7
-rw-r--r--ZAPD/ZDisplayList.cpp30
-rw-r--r--ZAPD/ZDisplayList.h1
-rw-r--r--ZAPD/ZFile.cpp17
-rw-r--r--ZAPD/ZRoom/ZRoom.cpp13
-rw-r--r--ZAPD/ZRoom/ZRoom.h1
-rw-r--r--ZAPD/ZTexture.cpp61
-rw-r--r--ZAPD/ZTexture.h5
9 files changed, 85 insertions, 55 deletions
diff --git a/ZAPD/Globals.cpp b/ZAPD/Globals.cpp
index e46320b..93e7fdf 100644
--- a/ZAPD/Globals.cpp
+++ b/ZAPD/Globals.cpp
@@ -152,8 +152,11 @@ void Globals::ReadTexturePool(const std::string& texturePoolXmlPath)
{
string crcStr = string(child->Attribute("CRC"));
string texPath = string(child->Attribute("Path"));
+ string texName = "";
- cfg.texturePool[strtol(crcStr.c_str(), NULL, 16)] = texPath;
+ uint32_t crc = strtoul(crcStr.c_str(), NULL, 16);
+
+ cfg.texturePool[crc].path = texPath;
}
}
}
diff --git a/ZAPD/Globals.h b/ZAPD/Globals.h
index 7bf4314..f9c5295 100644
--- a/ZAPD/Globals.h
+++ b/ZAPD/Globals.h
@@ -14,6 +14,11 @@ enum VerbosityLevel
VERBOSITY_DEBUG
};
+struct TexturePoolEntry
+{
+ std::string path = ""; // Path to Shared Texture
+};
+
class GameConfig
{
public:
@@ -22,7 +27,7 @@ public:
std::map<uint32_t, std::string> symbolMap;
std::vector<std::string> actorList;
std::vector<std::string> objectList;
- std::map<uint32_t, std::string> texturePool; // Key = CRC, Value = Path to Shared Texture
+ std::map<uint32_t, TexturePoolEntry> texturePool; // Key = CRC
// ZBackground
uint32_t bgScreenWidth = 320, bgScreenHeight = 240;
diff --git a/ZAPD/ZDisplayList.cpp b/ZAPD/ZDisplayList.cpp
index 762d6f4..afdd05c 100644
--- a/ZAPD/ZDisplayList.cpp
+++ b/ZAPD/ZDisplayList.cpp
@@ -1632,7 +1632,7 @@ static int32_t GfxdCallback_Vtx(uint32_t seg, int32_t count)
return 1;
}
-static int32_t GfxdCallback_Texture(uint32_t seg, int32_t fmt, int32_t siz, int32_t width,
+static int32_t GfxdCallback_Texture(segptr_t seg, int32_t fmt, int32_t siz, int32_t width,
int32_t height, int32_t pal)
{
ZDisplayList* instance = ZDisplayList::Instance;
@@ -1642,7 +1642,7 @@ static int32_t GfxdCallback_Texture(uint32_t seg, int32_t fmt, int32_t siz, int3
string texName = "";
if (instance->parent != nullptr &&
- texSegNum != 2) // HACK: Until we have declarations use segment addresses, we'll exclude
+ texSegNum != SEGMENT_SCENE) // HACK: Until we have declarations use segment addresses, we'll exclude
// scene references...
{
texDecl = instance->parent->GetDeclaration(texOffset);
@@ -1672,6 +1672,7 @@ static int32_t GfxdCallback_Texture(uint32_t seg, int32_t fmt, int32_t siz, int3
instance->lastTexIsPalette = false;
instance->TextureGenCheck(instance->curPrefix);
+
gfxd_puts(texName.c_str());
return 1;
@@ -1959,8 +1960,12 @@ string ZDisplayList::GetSourceOutputCode(const std::string& prefix)
{
if (parent->GetDeclaration(item.first) == nullptr)
{
+ // TEXTURE POOL CHECK
+ std::string texOutPath = item.second->GetPoolOutPath(Globals::Instance->outputPath);
+ std::string texOutName = item.second->GetName();
+
auto start = chrono::steady_clock::now();
- item.second->Save(Globals::Instance->outputPath);
+ item.second->Save(texOutPath);
auto end = chrono::steady_clock::now();
auto diff = chrono::duration_cast<chrono::milliseconds>(end - start).count();
@@ -1969,18 +1974,10 @@ string ZDisplayList::GetSourceOutputCode(const std::string& prefix)
(int32_t)diff);
std::string incStr = StringHelper::Sprintf(
- "%s/%s.%s.inc.c", Globals::Instance->outputPath.c_str(),
- Path::GetFileNameWithoutExtension(item.second->GetName()).c_str(),
+ "%s/%s.%s.inc.c", texOutPath.c_str(),
+ Path::GetFileNameWithoutExtension(texOutName).c_str(),
item.second->GetExternalExtension().c_str());
- std::string texName =
- StringHelper::Sprintf("%sTex_%06X", prefix.c_str(), item.first);
-
- if (Globals::Instance->cfg.texturePool.find(item.second->hash) !=
- Globals::Instance->cfg.texturePool.end())
- {
- incStr = Globals::Instance->cfg.texturePool[item.second->hash];
- texName = Path::GetFileNameWithoutExtension(incStr);
- }
+ std::string texName = StringHelper::Sprintf("%sTex_%06X", prefix.c_str(), item.first);
parent->AddDeclarationIncludeArray(
item.first, incStr, item.second->GetRawDataSize(), "u64", texName, 0);
@@ -2305,11 +2302,6 @@ ZResourceType ZDisplayList::GetResourceType()
return ZResourceType::DisplayList;
}
-vector<uint8_t> ZDisplayList::GetRawData()
-{
- return rawData;
-}
-
size_t ZDisplayList::GetRawDataSize()
{
return instructions.size() * 8;
diff --git a/ZAPD/ZDisplayList.h b/ZAPD/ZDisplayList.h
index 6d401cd..6cedb77 100644
--- a/ZAPD/ZDisplayList.h
+++ b/ZAPD/ZDisplayList.h
@@ -383,7 +383,6 @@ public:
bool texIsPalette);
static int32_t GetDListLength(std::vector<uint8_t> rawData, uint32_t rawDataIndex, DListType dListType);
- std::vector<uint8_t> GetRawData() override;
size_t GetRawDataSize() override;
std::string GetSourceOutputHeader(const std::string& prefix) override;
std::string GetSourceOutputCode(const std::string& prefix) override;
diff --git a/ZAPD/ZFile.cpp b/ZAPD/ZFile.cpp
index c8e6b71..96d2651 100644
--- a/ZAPD/ZFile.cpp
+++ b/ZAPD/ZFile.cpp
@@ -578,12 +578,18 @@ void ZFile::GenerateSourceFiles(string outputDir)
{
ZTexture* tex = (ZTexture*)res;
- // POOL CHECK
+ tex->CalcHash();
+
+ if (res->GetRawDataIndex() == 0xF0A0)
+ {
+ int bp = 0;
+ }
+
+ // TEXTURE POOL CHECK
if (Globals::Instance->cfg.texturePool.find(tex->hash) !=
Globals::Instance->cfg.texturePool.end())
{
- incStr = Globals::Instance->cfg.texturePool[tex->hash];
- res->SetName(Path::GetFileNameWithoutExtension(incStr));
+ incStr = Globals::Instance->cfg.texturePool[tex->hash].path + "." + res->GetExternalExtension() + ".inc";
}
incStr += ".c";
@@ -880,11 +886,10 @@ string ZFile::ProcessDeclarations()
if (diff > 0)
{
std::string unaccountedPrefix = "unaccounted";
+
if (diff < 16 && !nonZeroUnaccounted)
- {
unaccountedPrefix = "possiblePadding";
- }
-
+
Declaration* decl = AddDeclarationArray(
unaccountedAddress, DeclarationAlignment::None, diff, "static u8",
StringHelper::Sprintf("%s_%06X", unaccountedPrefix.c_str(),
diff --git a/ZAPD/ZRoom/ZRoom.cpp b/ZAPD/ZRoom/ZRoom.cpp
index eed01aa..6b151bb 100644
--- a/ZAPD/ZRoom/ZRoom.cpp
+++ b/ZAPD/ZRoom/ZRoom.cpp
@@ -529,14 +529,16 @@ string ZRoom::GetSourceOutputCode(const std::string& prefix)
declaration += item.second->GetSourceOutputCode(prefix);
+ std::string outPath = item.second->GetPoolOutPath(Globals::Instance->outputPath);
+
if (Globals::Instance->verbosity >= VERBOSITY_DEBUG)
- printf("SAVING IMAGE TO %s\n", Globals::Instance->outputPath.c_str());
+ printf("SAVING IMAGE TO %s\n", outPath.c_str());
- item.second->Save(Globals::Instance->outputPath);
+ item.second->Save(outPath);
parent->AddDeclarationIncludeArray(
item.first,
- StringHelper::Sprintf("%s/%s.%s.inc.c", Globals::Instance->outputPath.c_str(),
+ StringHelper::Sprintf("%s/%s.%s.inc.c", outPath.c_str(),
Path::GetFileNameWithoutExtension(item.second->GetName()).c_str(),
item.second->GetExternalExtension().c_str()),
item.second->GetRawDataSize(), "u64",
@@ -546,11 +548,6 @@ string ZRoom::GetSourceOutputCode(const std::string& prefix)
return sourceOutput;
}
-vector<uint8_t> ZRoom::GetRawData()
-{
- return rawData;
-}
-
size_t ZRoom::GetRawDataSize()
{
size_t size = 0;
diff --git a/ZAPD/ZRoom/ZRoom.h b/ZAPD/ZRoom/ZRoom.h
index a05e52e..b1fe869 100644
--- a/ZAPD/ZRoom/ZRoom.h
+++ b/ZAPD/ZRoom/ZRoom.h
@@ -36,7 +36,6 @@ public:
size_t GetDeclarationSizeFromNeighbor(int32_t declarationAddress);
size_t GetCommandSizeFromNeighbor(ZRoomCommand* cmd);
ZRoomCommand* FindCommandOfType(RoomCommand cmdType);
- std::vector<uint8_t> GetRawData() override;
size_t GetRawDataSize() override;
virtual ZResourceType GetResourceType() override;
virtual void Save(const std::string& outFolder) override;
diff --git a/ZAPD/ZTexture.cpp b/ZAPD/ZTexture.cpp
index e8a05e8..003ab72 100644
--- a/ZAPD/ZTexture.cpp
+++ b/ZAPD/ZTexture.cpp
@@ -26,6 +26,7 @@ ZTexture::ZTexture(ZFile* nParent) : ZResource(nParent)
height = 0;
type = TextureType::Error;
isPalette = false;
+ isRawDataFixed = false;
}
ZTexture::~ZTexture()
@@ -77,6 +78,7 @@ ZTexture* ZTexture::FromBinary(TextureType nType, std::vector<uint8_t> nRawData,
tex->rawData = vector<uint8_t>(nRawData.data() + tex->rawDataIndex, nRawData.data() + dataEnd);
tex->FixRawData();
+ tex->CalcHash();
tex->PrepareBitmap();
return tex;
@@ -208,12 +210,25 @@ void ZTexture::FixRawData()
rawData[i + 1] = tmp;
}
}
+
+ isRawDataFixed = !isRawDataFixed;
}
void ZTexture::PrepareBitmap()
{
- bmpRgb = new uint8_t[width * height * 3];
- bmpRgba = new uint8_t[width * height * 4];
+ switch (type)
+ {
+ case TextureType::RGBA16bpp:
+ case TextureType::RGBA32bpp:
+ case TextureType::GrayscaleAlpha4bpp:
+ case TextureType::GrayscaleAlpha8bpp:
+ case TextureType::GrayscaleAlpha16bpp:
+ bmpRgba = new uint8_t[width * height * 4];
+ break;
+ default:
+ bmpRgb = new uint8_t[width * height * 3];
+ break;
+ }
switch (type)
{
@@ -695,11 +710,6 @@ float ZTexture::GetPixelMultiplyer()
}
}
-vector<uint8_t> ZTexture::GetRawData()
-{
- return rawData;
-}
-
size_t ZTexture::GetRawDataSize()
{
return (width * height * GetPixelMultiplyer());
@@ -775,17 +785,21 @@ TextureType ZTexture::GetTextureType()
void ZTexture::Save(const std::string& outFolder)
{
- CalcHash();
-
- std::string outPath = outFolder;
+ //CalcHash();
- // POOL CHECK
- if (Globals::Instance->cfg.texturePool.find(hash) != Globals::Instance->cfg.texturePool.end())
+ // 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->testMode)
{
- outPath = Path::GetDirectoryName(Globals::Instance->cfg.texturePool[hash]);
- outName = Path::GetFileNameWithoutExtension(Globals::Instance->cfg.texturePool[hash]);
+ if (hash != 0)
+ {
+ File::WriteAllText(StringHelper::Sprintf("%s/%s.txt", Globals::Instance->outputPath.c_str(),
+ outName.c_str()), StringHelper::Sprintf("%08lX", hash));
+ hash = 0;
+ }
}
+ std::string outPath = GetPoolOutPath(outFolder);
+
if (!Directory::Exists(outPath))
Directory::CreateDirectory(outPath);
@@ -867,9 +881,16 @@ std::string ZTexture::GetSourceTypeName()
void ZTexture::CalcHash()
{
+ // Make sure raw data is fixed before we calc the hash...
+ bool fixFlag = !isRawDataFixed;
+
+ if (fixFlag)
+ FixRawData();
+
hash = CRC32B(rawData.data(), GetRawDataSize());
- // File::WriteAllText(StringHelper::Sprintf("%s/%s.txt", Globals::Instance->outputPath.c_str(),
- // outName.c_str()), StringHelper::Sprintf("%08lX", hash)); hash = 0;
+
+ if (fixFlag)
+ FixRawData();
}
std::string ZTexture::GetExternalExtension()
@@ -899,6 +920,14 @@ std::string ZTexture::GetExternalExtension()
}
}
+std::string ZTexture::GetPoolOutPath(std::string defaultValue)
+{
+ if (Globals::Instance->cfg.texturePool.find(hash) != Globals::Instance->cfg.texturePool.end())
+ return Path::GetDirectoryName(Globals::Instance->cfg.texturePool[hash].path);
+
+ return defaultValue;
+}
+
string ZTexture::GetSourceOutputHeader(const std::string& prefix)
{
return "";
diff --git a/ZAPD/ZTexture.h b/ZAPD/ZTexture.h
index 391f906..63ecf64 100644
--- a/ZAPD/ZTexture.h
+++ b/ZAPD/ZTexture.h
@@ -28,6 +28,7 @@ protected:
uint8_t* bmpRgb;
uint8_t* bmpRgba;
+ bool isRawDataFixed;
void ParseXML(tinyxml2::XMLElement* reader) override;
void FixRawData();
@@ -56,7 +57,6 @@ protected:
void PrepareRawDataPalette4(std::string palPath);
void PrepareRawDataPalette8(std::string palPath);
float GetPixelMultiplyer();
- void CalcHash() override;
public:
ZTexture(ZFile* nParent);
@@ -77,7 +77,6 @@ public:
std::string GetSourceOutputCode(const std::string& prefix) override;
std::string GetSourceOutputHeader(const std::string& prefix) override;
- std::vector<uint8_t> GetRawData() override;
size_t GetRawDataSize() override;
std::string GetIMFmtFromType();
std::string GetIMSizFromType();
@@ -88,6 +87,8 @@ public:
TextureType GetTextureType();
void Save(const std::string& outFolder) override;
std::string GetExternalExtension() override;
+ std::string GetPoolOutPath(std::string defaultValue);
+ void CalcHash() override;
bool IsExternalResource() override;
std::string GetSourceTypeName() override;