mirror of
https://github.com/izzy2lost/Torch.git
synced 2026-07-06 00:18:35 -07:00
Viewport Factory (#154)
* Viewport Factory * newline * dont make static * reformat to valid c
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include "factories/Vec3fFactory.h"
|
||||
#include "factories/Vec3sFactory.h"
|
||||
#include "factories/AssetArrayFactory.h"
|
||||
#include "factories/ViewportFactory.h"
|
||||
|
||||
#include "factories/sm64/AnimationFactory.h"
|
||||
#include "factories/sm64/BehaviorScriptFactory.h"
|
||||
@@ -95,6 +96,7 @@ void Companion::Init(const ExportType type) {
|
||||
this->RegisterFactory("VEC3S", std::make_shared<Vec3sFactory>());
|
||||
this->RegisterFactory("ARRAY", std::make_shared<GenericArrayFactory>());
|
||||
this->RegisterFactory("ASSET_ARRAY", std::make_shared<AssetArrayFactory>());
|
||||
this->RegisterFactory("VP", std::make_shared<ViewportFactory>());
|
||||
|
||||
// SM64 specific
|
||||
this->RegisterFactory("SM64:DIALOG", std::make_shared<SM64::DialogFactory>());
|
||||
|
||||
@@ -127,6 +127,7 @@ ExportResult DListCodeExporter::Export(std::ostream &write, std::shared_ptr<IPar
|
||||
gfxd_tlut_callback(GFXDOverride::Palette);
|
||||
gfxd_lightsn_callback(GFXDOverride::Lights);
|
||||
gfxd_light_callback(GFXDOverride::Light);
|
||||
gfxd_vp_callback(GFXDOverride::Viewport);
|
||||
GFXDSetGBIVersion();
|
||||
|
||||
gfxd_puts(("Gfx " + symbol + "[] = {\n").c_str());
|
||||
|
||||
@@ -167,6 +167,21 @@ int DisplayList(uint32_t ptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Viewport(uint32_t ptr) {
|
||||
auto dec = Companion::Instance->GetNodeByAddr(ptr);
|
||||
|
||||
if(dec.has_value()){
|
||||
auto node = std::get<1>(dec.value());
|
||||
auto symbol = GetSafeNode<std::string>(node, "symbol");
|
||||
SPDLOG_INFO("Found Viewport: 0x{:X} Symbol: {}", ptr, symbol);
|
||||
gfxd_puts(("&" + symbol).c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
SPDLOG_WARN("Could not find viewport to override at 0x{:X}", ptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::optional<std::tuple<std::string, YAML::Node>> GetVtxOverlap(uint32_t ptr){
|
||||
if(mVtxOverlaps.contains(ptr)){
|
||||
SPDLOG_INFO("Found overlap for ptr 0x{:X}", ptr);
|
||||
|
||||
@@ -45,6 +45,7 @@ int Palette(uint32_t tlut, int32_t idx, int32_t count);
|
||||
int Lights(uint32_t lightsn, int32_t count);
|
||||
int Light(uint32_t light);
|
||||
int DisplayList(uint32_t dl);
|
||||
int Viewport(uint32_t vp);
|
||||
void RegisterVTXOverlap(uint32_t ptr, std::tuple<std::string, YAML::Node>& vtx);
|
||||
std::optional<std::tuple<std::string, YAML::Node>> GetVtxOverlap(uint32_t ptr);
|
||||
void ClearVtx();
|
||||
|
||||
@@ -23,6 +23,7 @@ enum class ResourceType {
|
||||
Vec3s = 0x56433353, // VC3S
|
||||
GenericArray = 0x47415252, // GARR
|
||||
AssetArray = 0x41415252, // AARR
|
||||
Viewport = 0x4F565054, // OVPT
|
||||
|
||||
// SM64
|
||||
Anim = 0x414E494D, // ANIM
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
#include "ViewportFactory.h"
|
||||
|
||||
#include "utils/Decompressor.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "Companion.h"
|
||||
|
||||
ExportResult ViewportHeaderExporter::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 ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
write << "extern Vp " << symbol << ";\n";
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
ExportResult ViewportCodeExporter::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 viewport = std::static_pointer_cast<VpData>(raw);
|
||||
|
||||
write << "Vp " << symbol << " = {\n";
|
||||
|
||||
write << fourSpaceTab;
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
write << viewport->mViewport.vscale[i];
|
||||
if (i != 3) {
|
||||
write << ", ";
|
||||
}
|
||||
}
|
||||
write << ",\n";
|
||||
|
||||
write << fourSpaceTab;
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
write << viewport->mViewport.vtrans[i];
|
||||
if (i != 3) {
|
||||
write << ", ";
|
||||
}
|
||||
}
|
||||
write << ",\n";
|
||||
|
||||
write << "};\n\n";
|
||||
|
||||
return offset + sizeof(VpRaw);
|
||||
}
|
||||
|
||||
ExportResult ViewportBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
|
||||
auto writer = LUS::BinaryWriter();
|
||||
auto viewport = std::static_pointer_cast<VpData>(raw);
|
||||
|
||||
WriteHeader(writer, Torch::ResourceType::Viewport, 0);
|
||||
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
writer.Write(viewport->mViewport.vscale[i]);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
writer.Write(viewport->mViewport.vtrans[i]);
|
||||
}
|
||||
|
||||
writer.Finish(write);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<IParsedData>> ViewportFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) {
|
||||
auto [_, segment] = Decompressor::AutoDecode(node, buffer);
|
||||
LUS::BinaryReader reader(segment.data, segment.size);
|
||||
VpRaw viewport;
|
||||
|
||||
reader.SetEndianness(Torch::Endianness::Big);
|
||||
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
viewport.vscale[i] = reader.ReadInt16();
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
viewport.vtrans[i] = reader.ReadInt16();
|
||||
}
|
||||
|
||||
return std::make_shared<VpData>(viewport);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseFactory.h"
|
||||
|
||||
typedef struct {
|
||||
int16_t vscale[4]; /* scale */
|
||||
int16_t vtrans[4]; /* translate */
|
||||
} VpRaw;
|
||||
|
||||
class VpData : public IParsedData {
|
||||
public:
|
||||
VpRaw mViewport;
|
||||
|
||||
VpData(VpRaw viewport) : mViewport(std::move(viewport)) {}
|
||||
};
|
||||
|
||||
class ViewportHeaderExporter : public BaseExporter {
|
||||
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
|
||||
};
|
||||
|
||||
class ViewportBinaryExporter : public BaseExporter {
|
||||
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
|
||||
};
|
||||
|
||||
class ViewportCodeExporter : public BaseExporter {
|
||||
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
|
||||
};
|
||||
|
||||
class ViewportFactory : 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, ViewportCodeExporter)
|
||||
REGISTER(Header, ViewportHeaderExporter)
|
||||
REGISTER(Binary, ViewportBinaryExporter)
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user