Add to config

This commit is contained in:
inspectredc
2025-03-09 17:26:40 -06:00
committed by Lywx
parent 359ad0d884
commit 445b7dad7d
4 changed files with 37 additions and 23 deletions
+2
View File
@@ -1158,6 +1158,8 @@ void Companion::Process() {
}
}
this->gConfig.textureDefines = cfg["textures"] && (cfg["textures"].as<std::string>() == "ADDITIONAL_DEFINES");
this->ParseHash();
SPDLOG_INFO("------------------------------------------------");
+4
View File
@@ -90,6 +90,7 @@ struct TorchConfig {
ArchiveType otrMode;
bool debug;
bool modding;
bool textureDefines;
};
struct ParseResultData {
@@ -116,6 +117,7 @@ public:
this->gConfig.otrMode = otr;
this->gConfig.debug = debug;
this->gConfig.modding = modding;
this->gConfig.textureDefines = false;
}
explicit Companion(std::vector<uint8_t> rom, const ArchiveType otr, const bool debug, const bool modding = false) : gCartridge(nullptr) {
@@ -123,6 +125,7 @@ public:
this->gConfig.otrMode = otr;
this->gConfig.debug = debug;
this->gConfig.modding = modding;
this->gConfig.textureDefines = false;
}
void Init(ExportType type);
@@ -133,6 +136,7 @@ public:
bool IsOTRMode() const { return (this->gConfig.otrMode != ArchiveType::None); }
bool IsDebug() const { return this->gConfig.debug; }
bool AddTextureDefines() const { return this->gConfig.textureDefines; }
N64::Cartridge* GetCartridge() const { return this->gCartridge.get(); }
std::vector<uint8_t>& GetRomData() { return this->gRomData; }
+23 -19
View File
@@ -68,29 +68,33 @@ ExportResult CompressedTextureHeaderExporter::Export(std::ostream &write, std::s
} else {
if(isOTR){
write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
write << "#define _" << symbol << "_WIDTH 0x" << std::hex << texture->mWidth << std::dec << "\n";
write << "#define _" << symbol << "_HEIGHT 0x" << std::hex << texture->mHeight << std::dec << "\n";
if (Companion::Instance->AddTextureDefines()) {
write << "#define _" << symbol << "_WIDTH 0x" << std::hex << texture->mWidth << std::dec << "\n";
write << "#define _" << symbol << "_HEIGHT 0x" << std::hex << texture->mHeight << std::dec << "\n";
}
} else {
write << "extern " << "u8 " << symbol << "[];\n";
// Allocate worse case size
uint8_t* compressedData;
size_t compressedSize;
size_t worstSize;
if (Companion::Instance->AddTextureDefines()) {
// Allocate worse case size
uint8_t* compressedData;
size_t compressedSize;
size_t worstSize;
switch (texture->mCompressionType) {
case CompressionType::MIO0:
worstSize = MIO0_HEADER_LENGTH + ((data.size()+7)/8) + data.size();
compressedData = static_cast<uint8_t*>(std::calloc(worstSize, sizeof(uint8_t)));
compressedSize = mio0_encode(data.data(), data.size(), compressedData);
break;
default:
// UNIMPLEMENTED
throw std::runtime_error("Unsupported Compressed Texture Type");
break;
switch (texture->mCompressionType) {
case CompressionType::MIO0:
worstSize = MIO0_HEADER_LENGTH + ((data.size()+7)/8) + data.size();
compressedData = static_cast<uint8_t*>(std::calloc(worstSize, sizeof(uint8_t)));
compressedSize = mio0_encode(data.data(), data.size(), compressedData);
break;
default:
// UNIMPLEMENTED
throw std::runtime_error("Unsupported Compressed Texture Type");
break;
}
write << "#define _" << symbol << "_COMPRESSED_SIZE 0x" << std::hex << compressedSize << std::dec << "\n";
write << "#define _" << symbol << "_WIDTH 0x" << std::hex << texture->mWidth << std::dec << "\n";
write << "#define _" << symbol << "_HEIGHT 0x" << std::hex << texture->mHeight << std::dec << "\n";
}
write << "#define _" << symbol << "_COMPRESSED_SIZE 0x" << std::hex << compressedSize << std::dec << "\n";
write << "#define _" << symbol << "_WIDTH 0x" << std::hex << texture->mWidth << std::dec << "\n";
write << "#define _" << symbol << "_HEIGHT 0x" << std::hex << texture->mHeight << std::dec << "\n";
}
}
+8 -4
View File
@@ -61,12 +61,16 @@ ExportResult TextureHeaderExporter::Export(std::ostream &write, std::shared_ptr<
} else {
if(isOTR){
write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
write << "#define _" << symbol << "_WIDTH 0x" << std::hex << texture->mWidth << std::dec << "\n";
write << "#define _" << symbol << "_HEIGHT 0x" << std::hex << texture->mHeight << std::dec << "\n";
if (Companion::Instance->AddTextureDefines()) {
write << "#define _" << symbol << "_WIDTH 0x" << std::hex << texture->mWidth << std::dec << "\n";
write << "#define _" << symbol << "_HEIGHT 0x" << std::hex << texture->mHeight << std::dec << "\n";
}
} else {
write << "extern " << GetSafeNode<std::string>(node, "ctype", "u8") << " " << symbol << "[];\n";
write << "#define _" << symbol << "_WIDTH 0x" << std::hex << texture->mWidth << std::dec << "\n";
write << "#define _" << symbol << "_HEIGHT 0x" << std::hex << texture->mHeight << std::dec << "\n";
if (Companion::Instance->AddTextureDefines()) {
write << "#define _" << symbol << "_WIDTH 0x" << std::hex << texture->mWidth << std::dec << "\n";
write << "#define _" << symbol << "_HEIGHT 0x" << std::hex << texture->mHeight << std::dec << "\n";
}
}
}