summaryrefslogtreecommitdiff
path: root/src/factories/TextureFactory.cpp
diff options
context:
space:
mode:
authorKiritoDv <kiritodev01@gmail.com>2024-03-10 23:41:36 -0600
committerLywx <kiritodev01@gmail.com>2024-03-11 00:05:16 -0600
commit0277b06b4787f099ed0289eb95ceab98175cc8c4 (patch)
tree7d305d5f8cfe57cbef73c1d1cc3fcf8519b16c47 /src/factories/TextureFactory.cpp
parent595f7512d49b582e9ef2c4d082aa775d2ae600f4 (diff)
Fully implemented tables and message factories
Diffstat (limited to 'src/factories/TextureFactory.cpp')
-rw-r--r--src/factories/TextureFactory.cpp53
1 files changed, 35 insertions, 18 deletions
diff --git a/src/factories/TextureFactory.cpp b/src/factories/TextureFactory.cpp
index 7c9ec4f..6e3142f 100644
--- a/src/factories/TextureFactory.cpp
+++ b/src/factories/TextureFactory.cpp
@@ -9,6 +9,8 @@ extern "C" {
#include "BaseFactory.h"
}
+bool isTable = false;
+
static const std::unordered_map <std::string, TextureFormat> gTextureFormats = {
{ "RGBA16", { TextureType::RGBA16bpp, 16 } },
{ "RGBA32", { TextureType::RGBA32bpp, 32 } },
@@ -138,29 +140,44 @@ void TextureCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedDat
write << "// 0x" << std::hex << std::uppercase << offset << "\n";
}
- if (Companion::Instance->GetGBIMinorVersion() == GBIMinorVersion::Mk64) {
- write << "u8 " << symbol << "[] = {\n";
- } else {
- if(node["ctype"]) {
- write << node["ctype"].as<std::string>() << " " << symbol << "[] = {\n";
- } else {
- write << "static const u8 " << symbol << "[] = {\n";
+ const auto searchTable = Companion::Instance->SearchTable(offset);
+
+ if(searchTable.has_value()){
+ const auto [name, start, end, mode] = searchTable.value();
+
+ if(mode != TableMode::Append){
+ throw std::runtime_error("Reference mode is not supported for now");
}
- }
- write << tab << "#include \"" << Companion::Instance->GetOutputPath() + "/" << (*replacement) << ".inc.c\"\n";
- write << "};\n";
- if (Companion::Instance->IsDebug()) {
- const auto sz = data.size();
+ if(start == offset){
+ write << GetSafeNode<std::string>(node, "ctype", "static const u8") << " " << name << "[][0x" << texture->mBuffer.size() << std::hex << std::uppercase << "] = {\n";
+ }
- write << "// size: 0x" << std::hex << std::uppercase << sz << "\n";
- if (IS_SEGMENTED(offset)) {
- offset = SEGMENT_OFFSET(offset);
+ write << tab << "{\n";
+ write << tab << tab << "#include \"" << Companion::Instance->GetOutputPath() + "/" << *replacement << ".inc.c\"\n";
+ write << tab << "},\n";
+
+ if(end == offset){
+ write << "};\n";
}
- write << "// 0x" << std::hex << std::uppercase << (offset + sz) << "\n";
- }
+ } else {
+ write << GetSafeNode<std::string>(node, "ctype", "static const u8") << " " << symbol << "[] = {\n";
+
+ write << tab << "#include \"" << Companion::Instance->GetOutputPath() + "/" << *replacement << ".inc.c\"\n";
+ write << "};\n";
+
+ if (Companion::Instance->IsDebug()) {
+ const auto sz = data.size();
- write << "\n";
+ write << "// size: 0x" << std::hex << std::uppercase << sz << "\n";
+ if (IS_SEGMENTED(offset)) {
+ offset = SEGMENT_OFFSET(offset);
+ }
+ write << "// 0x" << std::hex << std::uppercase << (offset + sz) << "\n";
+ }
+
+ write << "\n";
+ }
}
void TextureBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) {