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
This commit is contained in:
AltoXorg
2024-04-20 10:25:02 -06:00
committed by Lywx
parent 8abeb379e4
commit fb9a018feb
3 changed files with 78 additions and 39 deletions
+54 -30
View File
@@ -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";
}
}
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::ofstream file(outinc, std::ios::binary);
if(!this->gFileHeader.empty()) {
file << this->gFileHeader << std::endl;
}
file << stream.str();
stream.str("");
stream.seekp(0);
file.close();
}
}
this->gWriteMap.clear();
std::string buffer = stream.str();
if (this->gConfig.exporterType != ExportType::Code || this->gSingleCodeFile) {
std::string buffer = stream.str();
if(buffer.empty()) {
continue;
}
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());
}
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;
if(buffer.empty()) {
continue;
}
file << buffer;
file << std::endl << "#endif" << std::endl;
} else {
if(!this->gFileHeader.empty()) {
file << this->gFileHeader << std::endl;
}
file << buffer;
}
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());
}
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) {
+3
View File
@@ -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;
+21 -9
View File
@@ -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();