mirror of
https://github.com/izzy2lost/Torch.git
synced 2026-07-06 00:18:35 -07:00
Painting Mapping Factory (#104)
* Painting Factory * update factory naming --------- Co-authored-by: Lywx <kiritodev01@gmail.com>
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
#include "factories/sm64/MacroFactory.h"
|
||||
#include "factories/sm64/MovtexFactory.h"
|
||||
#include "factories/sm64/MovtexQuadFactory.h"
|
||||
#include "factories/sm64/PaintingMapFactory.h"
|
||||
#include "factories/sm64/TrajectoryFactory.h"
|
||||
|
||||
#include "factories/mk64/CourseVtx.h"
|
||||
@@ -98,6 +99,7 @@ void Companion::Init(const ExportType type) {
|
||||
this->RegisterFactory("SM64:MACRO", std::make_shared<SM64::MacroFactory>());
|
||||
this->RegisterFactory("SM64:MOVTEX_QUAD", std::make_shared<SM64::MovtexQuadFactory>());
|
||||
this->RegisterFactory("SM64:MOVTEX", std::make_shared<SM64::MovtexFactory>());
|
||||
this->RegisterFactory("SM64:PAINTING_MAP", std::make_shared<SM64::PaintingMapFactory>());
|
||||
this->RegisterFactory("SM64:TRAJECTORY", std::make_shared<SM64::TrajectoryFactory>());
|
||||
|
||||
// MK64 specific
|
||||
|
||||
@@ -32,6 +32,7 @@ enum class ResourceType {
|
||||
MacroObject = 0x4D41434F, // MACO
|
||||
Movtex = 0x4D4F5654, // MOVT
|
||||
MovtexQuad = 0x4D4F5651, // MOVQ
|
||||
PaintingData = 0x5041494E, // PAIN
|
||||
Trajectory = 0x5452414A, // TRAJ
|
||||
|
||||
// MK64
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
#include "PaintingMapFactory.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
#include "Companion.h"
|
||||
#include "utils/Decompressor.h"
|
||||
#include "utils/TorchUtils.h"
|
||||
#include <regex>
|
||||
|
||||
#define FORMAT_INT(x, w) std::dec << std::setfill(' ') << std::setw(w) << x
|
||||
|
||||
ExportResult SM64::PaintingMapHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) {
|
||||
const auto symbol = GetSafeNode(node, "symbol", entryName);
|
||||
|
||||
if(Companion::Instance->IsOTRMode()){
|
||||
write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
write << "extern PaintingData " << symbol << "[];\n";
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
ExportResult SM64::PaintingMapCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
|
||||
const auto symbol = GetSafeNode(node, "symbol", entryName);
|
||||
const auto offset = GetSafeNode<uint32_t>(node, "offset");
|
||||
|
||||
auto paintingData = std::static_pointer_cast<SM64::PaintingData>(raw);
|
||||
|
||||
write << "static const PaintingData " << symbol << "[] = {\n";
|
||||
|
||||
write << fourSpaceTab << paintingData->mPaintingMappings.size() << ",\n";
|
||||
|
||||
for (auto &mapping : paintingData->mPaintingMappings) {
|
||||
write << fourSpaceTab;
|
||||
write << FORMAT_INT(mapping.vtxId << "," << mapping.texX << "," << mapping.texY, 6) << ",\n";
|
||||
}
|
||||
|
||||
write << fourSpaceTab << paintingData->mPaintingMappings.size() << ",\n";
|
||||
|
||||
for (auto &group : paintingData->mPaintingGroups) {
|
||||
write << fourSpaceTab;
|
||||
write << FORMAT_INT(group, 4) << ",\n";
|
||||
}
|
||||
|
||||
write << "};\n";
|
||||
|
||||
size_t size = (paintingData->mPaintingMappings.size() + paintingData->mPaintingGroups.size()) * 3 * sizeof(int16_t) + 2;
|
||||
|
||||
return offset + size;
|
||||
}
|
||||
|
||||
ExportResult SM64::PaintingMapBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
|
||||
auto writer = LUS::BinaryWriter();
|
||||
auto paintingData = std::static_pointer_cast<SM64::PaintingData>(raw);
|
||||
|
||||
WriteHeader(writer, LUS::ResourceType::PaintingData, 0);
|
||||
|
||||
writer.Write((int16_t)paintingData->mPaintingMappings.size());
|
||||
|
||||
for (auto &mapping : paintingData->mPaintingMappings) {
|
||||
writer.Write(mapping.vtxId);
|
||||
writer.Write(mapping.texX);
|
||||
writer.Write(mapping.texY);
|
||||
}
|
||||
|
||||
writer.Write((int16_t)paintingData->mPaintingGroups.size());
|
||||
|
||||
for (auto &group : paintingData->mPaintingGroups) {
|
||||
writer.Write(group.x);
|
||||
writer.Write(group.y);
|
||||
writer.Write(group.z);
|
||||
}
|
||||
|
||||
writer.Finish(write);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<IParsedData>> SM64::PaintingMapFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) {
|
||||
std::vector<PaintingMapping> paintingMappings;
|
||||
std::vector<Vec3s> paintingGroups;
|
||||
auto [_, segment] = Decompressor::AutoDecode(node, buffer);
|
||||
LUS::BinaryReader reader(segment.data, segment.size);
|
||||
reader.SetEndianness(LUS::Endianness::Big);
|
||||
|
||||
auto mappingsSize = reader.ReadInt16();
|
||||
|
||||
for (int16_t i = 0; i < mappingsSize; ++i) {
|
||||
auto vtxId = reader.ReadInt16();
|
||||
auto texX = reader.ReadInt16();
|
||||
auto texY = reader.ReadInt16();
|
||||
paintingMappings.emplace_back(vtxId, texX, texY);
|
||||
}
|
||||
|
||||
auto groupSize = reader.ReadInt16();
|
||||
|
||||
for (int16_t i = 0; i < groupSize; ++i) {
|
||||
auto x = reader.ReadInt16();
|
||||
auto y = reader.ReadInt16();
|
||||
auto z = reader.ReadInt16();
|
||||
paintingGroups.emplace_back(x, y, z);
|
||||
}
|
||||
|
||||
return std::make_shared<SM64::PaintingData>(paintingMappings, paintingGroups);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "factories/BaseFactory.h"
|
||||
#include "types/Vec3D.h"
|
||||
|
||||
namespace SM64 {
|
||||
|
||||
struct PaintingMapping {
|
||||
int16_t vtxId;
|
||||
int16_t texX;
|
||||
int16_t texY;
|
||||
PaintingMapping(int16_t vtxId, int16_t texX, int16_t texY) : vtxId(vtxId), texX(texX), texY(texY) {}
|
||||
};
|
||||
|
||||
class PaintingData : public IParsedData {
|
||||
public:
|
||||
std::vector<PaintingMapping> mPaintingMappings;
|
||||
std::vector<Vec3s> mPaintingGroups;
|
||||
|
||||
PaintingData(std::vector<PaintingMapping> paintingMappings, std::vector<Vec3s> paintingGroups) : mPaintingMappings(std::move(paintingMappings)), mPaintingGroups(std::move(paintingGroups)) {}
|
||||
};
|
||||
|
||||
class PaintingMapHeaderExporter : public BaseExporter {
|
||||
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
|
||||
};
|
||||
|
||||
class PaintingMapBinaryExporter : public BaseExporter {
|
||||
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
|
||||
};
|
||||
|
||||
class PaintingMapCodeExporter : public BaseExporter {
|
||||
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
|
||||
};
|
||||
|
||||
class PaintingMapFactory : public BaseFactory {
|
||||
public:
|
||||
std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override;
|
||||
inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override {
|
||||
return {
|
||||
REGISTER(Code, PaintingMapCodeExporter)
|
||||
REGISTER(Header, PaintingMapHeaderExporter)
|
||||
REGISTER(Binary, PaintingMapBinaryExporter)
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user