summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAltoXorg <atrl101@yahoo.com>2024-04-19 12:02:37 +0800
committerLywx <kiritodev01@gmail.com>2024-04-20 10:25:02 -0600
commitfb9a018feb83cd0b9e7e4a1145c6e9e9252ae381 (patch)
tree3bb0d899d7c4e23c263a1ec9a07ba95b33fe865c /src
parent8abeb379e42af05adb1fef7a9625f37037b767d8 (diff)
individual data incs option
The option creates a similar way that is found in splat's gfx & vtx segment where it parses and outputs the data in their individual ".inc.c" files
Diffstat (limited to 'src')
-rw-r--r--src/Companion.cpp78
-rw-r--r--src/Companion.h3
-rw-r--r--src/factories/TextureFactory.cpp30
3 files changed, 75 insertions, 36 deletions
diff --git a/src/Companion.cpp b/src/Companion.cpp
index 5703078..a350a79 100644
--- a/src/Companion.cpp
+++ b/src/Companion.cpp
@@ -354,6 +354,7 @@ void Companion::ParseCurrentFileConfig(YAML::Node node) {
this->gEnablePadGen = GetSafeNode<bool>(node, "autopads", true);
this->gNodeForceProcessing = GetSafeNode<bool>(node, "force", false);
+ this->gSingleCodeFile = !GetSafeNode<bool>(node, "individual_data_incs", false);
}
void Companion::ParseHash() {
@@ -840,6 +841,7 @@ void Companion::Process() {
auto alignment = GetSafeNode<uint32_t>(result.node, "alignment", impl->GetAlignment());
if(!endptr.has_value()) {
wEntry = {
+ result.name,
result.node["offset"].as<uint32_t>(),
alignment,
stream.str(),
@@ -849,6 +851,7 @@ void Companion::Process() {
switch (endptr->index()) {
case 0:
wEntry = {
+ result.name,
result.node["offset"].as<uint32_t>(),
alignment,
stream.str(),
@@ -858,6 +861,7 @@ void Companion::Process() {
case 1: {
const auto oentry = std::get<OffsetEntry>(endptr.value());
wEntry = {
+ result.name,
oentry.start,
alignment,
stream.str(),
@@ -948,7 +952,7 @@ void Companion::Process() {
stream << "// 0x" << std::hex << std::uppercase << ASSET_PTR(result.endptr.value()) << "\n\n";
}
- if(hasSize && i < entries.size() - 1 && this->gConfig.exporterType == ExportType::Code){
+ if(hasSize && i < entries.size() - 1 && this->gConfig.exporterType == ExportType::Code && this->gSingleCodeFile){
int32_t startptr = ASSET_PTR(result.endptr.value());
int32_t end = ASSET_PTR(entries[i + 1].addr);
@@ -980,42 +984,62 @@ void Companion::Process() {
stream << "// WARNING: Gap detected between 0x" << std::hex << startptr << " and 0x" << end << " with size 0x" << gap << "\n";
}
}
- }
- this->gWriteMap.clear();
+ if (this->gConfig.exporterType == ExportType::Code && !this->gSingleCodeFile) {
+ fs::path outinc = fs::path(this->gConfig.outputPath) / this->gCurrentDirectory.parent_path() / (result.name + ".inc.c");
+
+ if(!exists(outinc.parent_path())){
+ create_directories(outinc.parent_path());
+ }
- std::string buffer = stream.str();
+ std::ofstream file(outinc, std::ios::binary);
- if(buffer.empty()) {
- continue;
+ if(!this->gFileHeader.empty()) {
+ file << this->gFileHeader << std::endl;
+ }
+ file << stream.str();
+ stream.str("");
+ stream.seekp(0);
+ file.close();
+ }
}
- std::string output = fsout.string();
- std::replace(output.begin(), output.end(), '\\', '/');
- if(!exists(fs::path(output).parent_path())){
- create_directories(fs::path(output).parent_path());
- }
+ this->gWriteMap.clear();
- std::ofstream file(output, std::ios::binary);
+ if (this->gConfig.exporterType != ExportType::Code || this->gSingleCodeFile) {
+ std::string buffer = stream.str();
- if(this->gConfig.exporterType == ExportType::Header) {
- std::string symbol = entry.path().stem().string();
- std::transform(symbol.begin(), symbol.end(), symbol.begin(), toupper);
- file << "#ifndef " << symbol << "_H" << std::endl;
- file << "#define " << symbol << "_H" << std::endl << std::endl;
- if(!this->gFileHeader.empty()) {
- file << this->gFileHeader << std::endl;
+ if(buffer.empty()) {
+ continue;
}
- file << buffer;
- file << std::endl << "#endif" << std::endl;
- } else {
- if(!this->gFileHeader.empty()) {
- file << this->gFileHeader << std::endl;
+
+ std::string output = fsout.string();
+ std::replace(output.begin(), output.end(), '\\', '/');
+ if(!exists(fs::path(output).parent_path())){
+ create_directories(fs::path(output).parent_path());
}
- file << buffer;
- }
- file.close();
+ std::ofstream file(output, std::ios::binary);
+
+ if(this->gConfig.exporterType == ExportType::Header) {
+ std::string symbol = entry.path().stem().string();
+ std::transform(symbol.begin(), symbol.end(), symbol.begin(), toupper);
+ file << "#ifndef " << symbol << "_H" << std::endl;
+ file << "#define " << symbol << "_H" << std::endl << std::endl;
+ if(!this->gFileHeader.empty()) {
+ file << this->gFileHeader << std::endl;
+ }
+ file << buffer;
+ file << std::endl << "#endif" << std::endl;
+ } else {
+ if(!this->gFileHeader.empty()) {
+ file << this->gFileHeader << std::endl;
+ }
+ file << buffer;
+ }
+
+ file.close();
+ }
}
if(this->gConfig.exporterType != ExportType::Binary) {
diff --git a/src/Companion.h b/src/Companion.h
index 5f31ae7..487cbac 100644
--- a/src/Companion.h
+++ b/src/Companion.h
@@ -53,6 +53,7 @@ struct VRAMEntry {
};
struct WriteEntry {
+ std::string name;
uint32_t addr;
uint32_t alignment;
std::string buffer;
@@ -117,6 +118,7 @@ public:
GBIMinorVersion GetGBIMinorVersion() const { return this->gConfig.gbi.subversion; }
std::unordered_map<std::string, std::vector<YAML::Node>> GetCourseMetadata() { return this->gCourseMetadata; }
std::optional<std::string> GetEnumFromValue(const std::string& key, int id);
+ bool IsSingleCodeFile() const { return this->gSingleCodeFile; }
std::optional<ParseResultData> GetParseDataByAddr(uint32_t addr);
std::optional<ParseResultData> GetParseDataBySymbol(const std::string& symbol);
@@ -152,6 +154,7 @@ private:
std::vector<uint8_t> gRomData;
std::filesystem::path gRomPath;
bool gNodeForceProcessing = false;
+ bool gSingleCodeFile = true;
YAML::Node gHashNode;
std::shared_ptr<N64::Cartridge> gCartridge;
std::unordered_map<std::string, std::vector<YAML::Node>> gCourseMetadata;
diff --git a/src/factories/TextureFactory.cpp b/src/factories/TextureFactory.cpp
index 6dfb3e7..d3bc923 100644
--- a/src/factories/TextureFactory.cpp
+++ b/src/factories/TextureFactory.cpp
@@ -137,7 +137,7 @@ ExportResult TextureCodeExporter::Export(std::ostream &write, std::shared_ptr<IP
create_directories(fs::path(dpath).parent_path());
}
- std::ofstream file(dpath + ".inc.c", std::ios::binary);
+ std::ostringstream imgstream;
size_t byteSize = std::max(1, (int) (texture->mFormat.depth / 8));
@@ -145,20 +145,24 @@ ExportResult TextureCodeExporter::Export(std::ostream &write, std::shared_ptr<IP
for (int i = 0; i < data.size(); i+=byteSize) {
if (i % 16 == 0 && i != 0) {
- file << std::endl;
+ imgstream << std::endl;
}
- file << "0x";
+ imgstream << "0x";
for (int j = 0; j < byteSize; j++) {
- file << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(data[i + j]);
+ imgstream << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(data[i + j]);
}
- file << ", ";
+ imgstream << ", ";
}
- file << std::endl;
+ imgstream << std::endl;
- file.close();
+ if (Companion::Instance->IsSingleCodeFile()){
+ std::ofstream file(dpath + ".inc.c", std::ios::binary);
+ file << imgstream.str();
+ file.close();
+ }
const auto searchTable = Companion::Instance->SearchTable(offset);
@@ -174,7 +178,11 @@ ExportResult TextureCodeExporter::Export(std::ostream &write, std::shared_ptr<IP
}
write << tab << "{\n";
- write << tab << tab << "#include \"" << Companion::Instance->GetOutputPath() + "/" << *replacement << ".inc.c\"\n";
+ if (Companion::Instance->IsSingleCodeFile()){
+ write << tab << tab << "#include \"" << Companion::Instance->GetOutputPath() + "/" << *replacement << ".inc.c\"\n";
+ } else {
+ write << imgstream.str();
+ }
write << tab << "},\n";
if(end == offset){
@@ -186,7 +194,11 @@ ExportResult TextureCodeExporter::Export(std::ostream &write, std::shared_ptr<IP
} else {
write << GetSafeNode<std::string>(node, "ctype", "u8") << " " << symbol << "[] = {\n";
- write << tab << "#include \"" << Companion::Instance->GetOutputPath() + "/" << *replacement << ".inc.c\"\n";
+ if (Companion::Instance->IsSingleCodeFile()){
+ write << tab << "#include \"" << Companion::Instance->GetOutputPath() + "/" << *replacement << ".inc.c\"\n";
+ } else {
+ write << imgstream.str();
+ }
write << "};\n";
const auto sz = data.size();