summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpetrie911 <69443847+petrie911@users.noreply.github.com>2024-03-13 15:56:30 -0500
committerGitHub <noreply@github.com>2024-03-13 14:56:30 -0600
commit92e7076647d2da64e8f90aa66974c4a3dba03a06 (patch)
tree968573727b890d6b0cf74a6ae354fffd98999af0
parent2338cab8df24d483a4a1eaf8bd23a997a4beffb8 (diff)
Add vector classes and SF64 colpoly factory. Also fix enum parsing (#39)
* 3D * and env * so much to fix
-rw-r--r--src/Companion.cpp16
-rw-r--r--src/factories/sf64/ColPolyFactory.cpp147
-rw-r--r--src/factories/sf64/ColPolyFactory.h51
-rw-r--r--src/factories/sf64/EnvSettingsFactory.cpp15
-rw-r--r--src/factories/sf64/EnvSettingsFactory.h7
-rw-r--r--src/factories/sf64/HitboxFactory.cpp24
-rw-r--r--src/factories/sf64/ObjInitFactory.cpp2
-rw-r--r--src/factories/sf64/ObjInitFactory.h6
-rw-r--r--src/factories/sf64/ScriptFactory.cpp21
-rw-r--r--src/factories/sf64/SkeletonFactory.cpp23
-rw-r--r--src/factories/sf64/SkeletonFactory.h15
-rw-r--r--src/factories/sm64/geo/GeoCommand.h38
-rw-r--r--src/types/Vec3D.cpp57
-rw-r--r--src/types/Vec3D.h64
14 files changed, 391 insertions, 95 deletions
diff --git a/src/Companion.cpp b/src/Companion.cpp
index 5ae17ee..3ab7267 100644
--- a/src/Companion.cpp
+++ b/src/Companion.cpp
@@ -28,6 +28,7 @@
#include <fstream>
#include <iostream>
#include <filesystem>
+#include "factories/sf64/ColPolyFactory.h"
#include "factories/sf64/MessageFactory.h"
#include "factories/sf64/MessageLookupFactory.h"
#include "factories/sf64/SkeletonFactory.h"
@@ -82,6 +83,7 @@ void Companion::Init(const ExportType type) {
this->RegisterFactory("SF64:HITBOX", std::make_shared<SF64::HitboxFactory>());
this->RegisterFactory("SF64:ENV_SETTINGS", std::make_shared<SF64::EnvSettingsFactory>());
this->RegisterFactory("SF64:OBJECT_INIT", std::make_shared<SF64::ObjInitFactory>());
+ this->RegisterFactory("SF64:COLPOLY", std::make_shared<SF64::ColPolyFactory>());
this->Process();
}
@@ -100,11 +102,12 @@ void Companion::ParseEnums(std::string& header) {
std::string enumName;
bool inEnum = false;
-
+ int enumIndex;
while (std::getline(file, line)) {
if (!inEnum && std::regex_search(line, match, enumRegex) && match.size() > 1) {
enumName = match.str(1);
inEnum = true;
+ enumIndex = -1;
continue;
}
@@ -118,15 +121,18 @@ void Companion::ParseEnums(std::string& header) {
}
// Remove any comments and non-alphanumeric characters
- line = std::regex_replace(line, std::regex(R"((/\*.*?\*/)|([^a-zA-Z0-9=_\-\.]))"), "");
+ line = std::regex_replace(line, std::regex(R"((/\*.*?\*/)|(//.*$)|([^a-zA-Z0-9=_\-\.]))"), "");
if(line.find("=") != std::string::npos) {
- auto name = line.substr(0, line.find("="));
auto value = line.substr(line.find("=") + 1);
- this->gEnums[enumName][value.starts_with("-") ? -std::stoi(value.substr(1)) : std::stoi(value)] = name;
+ auto name = line.substr(0, line.find("="));
+ enumIndex = std::stoi(value);
+ this->gEnums[enumName][enumIndex] = name;
} else {
- this->gEnums[enumName][this->gEnums[enumName].size()] = line;
+ enumIndex++;
+ this->gEnums[enumName][enumIndex] = line;
}
+
}
}
diff --git a/src/factories/sf64/ColPolyFactory.cpp b/src/factories/sf64/ColPolyFactory.cpp
new file mode 100644
index 0000000..3cff5c6
--- /dev/null
+++ b/src/factories/sf64/ColPolyFactory.cpp
@@ -0,0 +1,147 @@
+#include "ColPolyFactory.h"
+#include "spdlog/spdlog.h"
+
+#include "Companion.h"
+#include "utils/Decompressor.h"
+#include "utils/TorchUtils.h"
+
+
+#define NUM(x, w) std::dec << std::setfill(' ') << std::setw(w) << x
+
+SF64::ColPolyData::ColPolyData(std::vector<SF64::CollisionPoly> polys, std::vector<Vec3s> mesh): mPolys(polys), mMesh(mesh) {
+
+}
+
+void SF64::ColPolyHeaderExporter::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;
+ }
+
+ write << "extern CollisionPoly " << symbol << "[];\n";
+}
+
+void SF64::ColPolyCodeExporter::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 colpolys = std::static_pointer_cast<SF64::ColPolyData>(raw);
+ auto off = offset;
+ int i;
+ if(IS_SEGMENTED(off)) {
+ off = SEGMENT_OFFSET(off);
+ }
+ if (Companion::Instance->IsDebug()) {
+ write << "// 0x" << std::uppercase << std::hex << off << "\n";
+ }
+
+ write << "CollisionPoly " << symbol << "[] = {";
+ int width = std::log10(colpolys->mMesh.size()) + 1;
+ // i = 0;
+ for(SF64::CollisionPoly poly : colpolys->mPolys) {
+ // if((i++ % 2) == 0) {
+ write << "\n" << fourSpaceTab;
+ // }
+ write << "{ {" << NUM(poly.tri[0], width) << ", " << NUM(poly.tri[1], width) << ", " << NUM(poly.tri[2], width) << "}, ";
+ if (poly.unk_06 == 0) {
+ write << "0, ";
+ } else {
+ SPDLOG_INFO("SF64:COLPOLY alert: Nonzero value of unk_06");
+ write << "/* ALERT: NONZERO */ " << poly.unk_06 << ", ";
+ }
+ write << NUM(poly.norm, 6) << ", ";
+ if(poly.unk_0E != 0) {
+ SPDLOG_ERROR("SF64:COLPOLY error: Nonzero value found in padding");
+ write << "/* ALERT: NONZERO PAD */ ";
+ }
+ write << NUM(poly.dist, 6) << "}, ";
+ }
+
+ write << "\n};\n";
+
+ if (Companion::Instance->IsDebug()) {
+ write << "// CollisionPoly count: " << colpolys->mPolys.size() << "\n";
+ write << "// 0x" << std::uppercase << std::hex << off + colpolys->mPolys.size() * sizeof(SF64::CollisionPoly) << "\n";
+ }
+
+ write << "\n";
+
+ std::ostringstream defaultMeshSymbol;
+ auto defaultMeshOffset = offset + colpolys->mPolys.size() * sizeof(SF64::CollisionPoly);
+ const auto meshOffset = GetSafeNode(node, "mesh_offset", defaultMeshOffset);
+ if (meshOffset != defaultMeshOffset) {
+ write << "// SF64:COLPOLY alert: Gap detected between polys and mesh\n\n";
+ }
+ off = meshOffset;
+ if(IS_SEGMENTED(off)) {
+ off = SEGMENT_OFFSET(off);
+ }
+ defaultMeshSymbol << symbol << "_mesh_" << std::uppercase << std::hex << off;
+ const auto meshSymbol = GetSafeNode(node, "mesh_symbol", defaultMeshSymbol.str());
+ if (Companion::Instance->IsDebug()) {
+ write << "// 0x" << std::uppercase << std::hex << off << "\n";
+ }
+
+ write << "Vec3s " << meshSymbol << "[] = {";
+ i = 0;
+ for(Vec3s vtx : colpolys->mMesh) {
+ if((i++ % 4) == 0) {
+ write << "\n" << fourSpaceTab;
+ }
+ write << NUM(vtx, 6) << ", ";
+ }
+
+ write << "\n};\n";
+
+ if (Companion::Instance->IsDebug()) {
+ write << "// Mesh vertex count: " << colpolys->mMesh.size() << "\n";
+ write << "// 0x" << std::uppercase << std::hex << off + colpolys->mMesh.size() * sizeof(Vec3s) << "\n";
+ }
+
+ write << "\n";
+
+}
+
+void SF64::ColPolyBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
+
+}
+
+std::optional<std::shared_ptr<IParsedData>> SF64::ColPolyFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) {
+ const auto offset = GetSafeNode<uint32_t>(node, "offset");
+ const auto count = GetSafeNode<uint32_t>(node, "count");
+ std::vector<SF64::CollisionPoly> polys;
+ std::vector<Vec3s> mesh;
+ int meshCount = 0;
+ auto [_, segment] = Decompressor::AutoDecode(node, buffer, count * sizeof(SF64::CollisionPoly));
+ LUS::BinaryReader reader(segment.data, segment.size);
+ reader.SetEndianness(LUS::Endianness::Big);
+
+ for(int i = 0; i < count; i++) {
+ int16_t v0 = reader.ReadInt16();
+ meshCount = std::max(meshCount, (int)v0);
+ int16_t v1 = reader.ReadInt16();
+ meshCount = std::max(meshCount, (int)v1);
+ int16_t v2 = reader.ReadInt16();
+ meshCount = std::max(meshCount, (int)v2);
+ int16_t pad1 = reader.ReadInt16();
+ int16_t nx = reader.ReadInt16();
+ int16_t ny = reader.ReadInt16();
+ int16_t nz = reader.ReadInt16();
+ int16_t pad2 = reader.ReadInt16();
+ int16_t dist = reader.ReadInt32();
+
+ polys.push_back(CollisionPoly({{v0, v1, v2}, pad1, {nx, ny, nz}, pad2, dist}));
+ }
+
+ const auto meshOffset = GetSafeNode<uint32_t>(node, "mesh_offset", offset + count * sizeof(SF64::CollisionPoly));
+ auto [__, meshSegment] = Decompressor::AutoDecode(node, buffer, meshCount * sizeof(Vec3s));
+ LUS::BinaryReader meshReader(meshSegment.data, meshSegment.size);
+ meshReader.SetEndianness(LUS::Endianness::Big);
+
+ for(int i = 0; i < meshCount; i++) {
+ mesh.push_back(Vec3s(meshReader.ReadInt16(), meshReader.ReadInt16(), meshReader.ReadInt16()));
+ }
+
+ return std::make_shared<SF64::ColPolyData>(polys, mesh);
+}
diff --git a/src/factories/sf64/ColPolyFactory.h b/src/factories/sf64/ColPolyFactory.h
new file mode 100644
index 0000000..45ff045
--- /dev/null
+++ b/src/factories/sf64/ColPolyFactory.h
@@ -0,0 +1,51 @@
+#pragma once
+
+#include "../BaseFactory.h"
+#include "types/Vec3D.h"
+
+namespace SF64 {
+
+struct CollisionPoly {
+ int16_t tri[3];
+ int16_t unk_06;
+ Vec3s norm;
+ int16_t unk_0E;
+ int32_t dist;
+};
+
+class ColPolyData : public IParsedData {
+public:
+ std::vector<CollisionPoly> mPolys;
+ std::vector<Vec3s> mMesh;
+
+ ColPolyData(std::vector<CollisionPoly> polys, std::vector<Vec3s> mesh);
+};
+
+class ColPolyHeaderExporter : public BaseExporter {
+ void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
+};
+
+class ColPolyBinaryExporter : public BaseExporter {
+ void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
+};
+
+class ColPolyCodeExporter : public BaseExporter {
+ void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
+};
+
+class ColPolyFactory : public BaseFactory {
+public:
+ std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override;
+ std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override {
+ return std::nullopt;
+ }
+ inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override {
+ return {
+ REGISTER(Code, ColPolyCodeExporter)
+ REGISTER(Header, ColPolyHeaderExporter)
+ REGISTER(Binary, ColPolyBinaryExporter)
+ };
+ }
+ bool SupportModdedAssets() override { return false; }
+};
+}
diff --git a/src/factories/sf64/EnvSettingsFactory.cpp b/src/factories/sf64/EnvSettingsFactory.cpp
index 7fd6613..8ed654a 100644
--- a/src/factories/sf64/EnvSettingsFactory.cpp
+++ b/src/factories/sf64/EnvSettingsFactory.cpp
@@ -5,7 +5,7 @@
#include "utils/Decompressor.h"
#include "utils/TorchUtils.h"
-SF64::EnvSettingsData::EnvSettingsData(int32_t type, int32_t unk_04, uint16_t bgColor, uint16_t seqId, int32_t fogR, int32_t fogG, int32_t fogB, int32_t fogN, int32_t fogF, float unk_20x, float unk_20y, float unk_20z, int32_t lightR, int32_t lightG, int32_t lightB, int32_t ambR, int32_t ambG, int32_t ambB): mType(type), mUnk_04(unk_04), mBgColor(bgColor), mSeqId(seqId), mFogR(fogR), mFogG(fogG), mFogB(fogB), mFogN(fogN), mFogF(fogF), mUnk_20x(unk_20x), mUnk_20y(unk_20y), mUnk_20z(unk_20z), mLightR(lightR), mLightG(lightG), mLightB(lightB), mAmbR(ambR), mAmbG(ambG), mAmbB(ambB) {
+SF64::EnvSettingsData::EnvSettingsData(int32_t type, int32_t unk_04, uint16_t bgColor, uint16_t seqId, int32_t fogR, int32_t fogG, int32_t fogB, int32_t fogN, int32_t fogF, Vec3f unk_20, int32_t lightR, int32_t lightG, int32_t lightB, int32_t ambR, int32_t ambG, int32_t ambB): mType(type), mUnk_04(unk_04), mBgColor(bgColor), mSeqId(seqId), mFogR(fogR), mFogG(fogG), mFogB(fogB), mFogN(fogN), mFogF(fogF), mUnk_20(unk_20), mLightR(lightR), mLightG(lightG), mLightB(lightB), mAmbR(ambR), mAmbG(ambG), mAmbB(ambB) {
}
@@ -46,9 +46,7 @@ void SF64::EnvSettingsCodeExporter::Export(std::ostream &write, std::shared_ptr<
write << env->mFogB << ", ";
write << env->mFogN << ", ";
write << env->mFogF << ", ";
- write << "{" << env->mUnk_20x << ", ";
- write << env->mUnk_20y << ", ";
- write << env->mUnk_20z << "}, ";
+ write << env->mUnk_20 << ", ";
write << env->mLightR << ", ";
write << env->mLightG << ", ";
write << env->mLightB << ", ";
@@ -70,6 +68,7 @@ std::optional<std::shared_ptr<IParsedData>> SF64::EnvSettingsFactory::parse(std:
auto [_, segment] = Decompressor::AutoDecode(node, buffer, sizeof(SF64::EnvSettingsData));
LUS::BinaryReader reader(segment.data, segment.size);
reader.SetEndianness(LUS::Endianness::Big);
+ Vec3f unk_20;
int32_t type = reader.ReadInt32();
int32_t unk_04 = reader.ReadInt32();
uint16_t bgColor = reader.ReadUInt16();
@@ -79,9 +78,9 @@ std::optional<std::shared_ptr<IParsedData>> SF64::EnvSettingsFactory::parse(std:
int32_t fogB = reader.ReadInt32();
int32_t fogN = reader.ReadInt32();
int32_t fogF = reader.ReadInt32();
- float unk_20x = reader.ReadFloat();
- float unk_20y = reader.ReadFloat();
- float unk_20z = reader.ReadFloat();
+ unk_20.x = reader.ReadFloat();
+ unk_20.y = reader.ReadFloat();
+ unk_20.z = reader.ReadFloat();
int32_t lightR = reader.ReadInt32();
int32_t lightG = reader.ReadInt32();
int32_t lightB = reader.ReadInt32();
@@ -89,5 +88,5 @@ std::optional<std::shared_ptr<IParsedData>> SF64::EnvSettingsFactory::parse(std:
int32_t ambG = reader.ReadInt32();
int32_t ambB = reader.ReadInt32();
- return std::make_shared<SF64::EnvSettingsData>(type, unk_04, bgColor, seqId, fogR, fogG, fogB, fogN, fogF, unk_20x, unk_20y, unk_20z, lightR, lightG, lightB, ambR, ambG, ambB);
+ return std::make_shared<SF64::EnvSettingsData>(type, unk_04, bgColor, seqId, fogR, fogG, fogB, fogN, fogF, unk_20, lightR, lightG, lightB, ambR, ambG, ambB);
}
diff --git a/src/factories/sf64/EnvSettingsFactory.h b/src/factories/sf64/EnvSettingsFactory.h
index 985a391..59cd78f 100644
--- a/src/factories/sf64/EnvSettingsFactory.h
+++ b/src/factories/sf64/EnvSettingsFactory.h
@@ -1,6 +1,7 @@
#pragma once
#include "../BaseFactory.h"
+#include "types/Vec3D.h"
namespace SF64 {
@@ -15,9 +16,7 @@ public:
int32_t mFogB;
int32_t mFogN;
int32_t mFogF;
- float mUnk_20x;
- float mUnk_20y;
- float mUnk_20z;
+ Vec3f mUnk_20;
int32_t mLightR;
int32_t mLightG;
int32_t mLightB;
@@ -25,7 +24,7 @@ public:
int32_t mAmbG;
int32_t mAmbB;
- EnvSettingsData(int32_t type, int32_t unk_04, uint16_t bgColor, uint16_t seqId, int32_t fogR, int32_t fogG, int32_t fogB, int32_t fogN, int32_t fogF, float unk_20x, float unk_20y, float unk_20z, int32_t lightR, int32_t lightG, int32_t lightB, int32_t ambR, int32_t ambG, int32_t ambB);
+ EnvSettingsData(int32_t type, int32_t unk_04, uint16_t bgColor, uint16_t seqId, int32_t fogR, int32_t fogG, int32_t fogB, int32_t fogN, int32_t fogF, Vec3f unk_20, int32_t lightR, int32_t lightG, int32_t lightB, int32_t ambR, int32_t ambG, int32_t ambB);
};
class EnvSettingsHeaderExporter : public BaseExporter {
diff --git a/src/factories/sf64/HitboxFactory.cpp b/src/factories/sf64/HitboxFactory.cpp
index 2266b86..69d5ef1 100644
--- a/src/factories/sf64/HitboxFactory.cpp
+++ b/src/factories/sf64/HitboxFactory.cpp
@@ -5,6 +5,8 @@
#include "utils/Decompressor.h"
#include "utils/TorchUtils.h"
+#define FLOAT(x, w) std::dec << std::setfill(' ') << (((int) x == x) ? "" : " ") << std::setw(w - 2) << x << (((int) x == x) ? ".0f" : "f")
+
SF64::HitboxData::HitboxData(std::vector<float> data, std::vector<int> types): mData(data), mTypes(types) {
}
@@ -26,11 +28,18 @@ void SF64::HitboxCodeExporter::Export(std::ostream &write, std::shared_ptr<IPars
auto hitbox = std::static_pointer_cast<SF64::HitboxData>(raw);
auto index = 0;
auto count = hitbox->mData[index++];
+ auto hasType2 = false;
auto off = offset;
+
if(IS_SEGMENTED(off)) {
off = SEGMENT_OFFSET(off);
}
-
+ for(int type : hitbox->mTypes) {
+ if(type == 2) {
+ hasType2 = true;
+ break;
+ }
+ }
if (Companion::Instance->IsDebug()) {
write << "// 0x" << std::uppercase << std::hex << off << "\n";
}
@@ -45,17 +54,24 @@ void SF64::HitboxCodeExporter::Export(std::ostream &write, std::shared_ptr<IPars
write << fourSpaceTab << "HITBOX_TYPE_3, ";
index++;
} else if (hitbox->mTypes[i] == 2) {
- write << fourSpaceTab << "HITBOX_TYPE_2, ";
+ write << fourSpaceTab << "HITBOX_TYPE_2, ";
index++;
for(int j = 0; j < 3; j++) {
- write << hitbox->mData[index++] << ", ";
+ auto tempf = hitbox->mData[index++];
+ write << FLOAT(tempf, 6) << ", ";
}
write << fourSpaceTab;
} else {
write << " /* HITBOX_TYPE_1 */ ";
}
+ if(hasType2 && hitbox->mTypes[i] != 2) {
+ for(int j = 0; j < 8; j++) {
+ write << fourSpaceTab;
+ }
+ }
for(int j = 0; j < 6; j++) {
- write << hitbox->mData[index++] << ", ";
+ auto tempf = hitbox->mData[index++];
+ write << FLOAT(tempf, 7) << ", ";
}
write << "\n";
}
diff --git a/src/factories/sf64/ObjInitFactory.cpp b/src/factories/sf64/ObjInitFactory.cpp
index 9421fee..3e4294d 100644
--- a/src/factories/sf64/ObjInitFactory.cpp
+++ b/src/factories/sf64/ObjInitFactory.cpp
@@ -25,7 +25,7 @@ void SF64::ObjInitCodeExporter::Export(std::ostream &write, std::shared_ptr<IPar
write << NUM(obj.zPos2, 7) << ", ";
write << NUM(obj.xPos, 7) << ", ";
write << NUM(obj.yPos, 7) << ", ";
- write << "{ " << NUM(obj.rot.x, 3) << ", " << NUM(obj.rot.y, 3) << ", " << NUM(obj.rot.z, 3) << " }, ";
+ write << NUM(obj.rot, 3) << ", ";
write << enumName << " },\n";
}
write << "};\n";
diff --git a/src/factories/sf64/ObjInitFactory.h b/src/factories/sf64/ObjInitFactory.h
index a6aba31..fcaff69 100644
--- a/src/factories/sf64/ObjInitFactory.h
+++ b/src/factories/sf64/ObjInitFactory.h
@@ -1,13 +1,9 @@
#pragma once
#include "../BaseFactory.h"
+#include "types/Vec3D.h"
namespace SF64 {
-struct Vec3s {
- /* 0x0 */ int16_t x;
- /* 0x2 */ int16_t y;
- /* 0x4 */ int16_t z;
-}; // size = 0x6;
struct ObjectInit {
/* 0x00 */ float zPos1;
diff --git a/src/factories/sf64/ScriptFactory.cpp b/src/factories/sf64/ScriptFactory.cpp
index 8cba314..6385836 100644
--- a/src/factories/sf64/ScriptFactory.cpp
+++ b/src/factories/sf64/ScriptFactory.cpp
@@ -25,7 +25,9 @@ std::string MakeScriptCmd(uint16_t s1, uint16_t s2) {
auto arg1 = s1 & 0x1FF;
std::ostringstream cmd;
- cmd << "EVENT_CMD(EVOP_" << std::left << std::setw(3) << std::dec << opcode << ", " << std::right << std::setw(3) << std::dec << arg1 << ", " << std::setw(5) << std::dec << s2 << ")";
+ auto enumName = Companion::Instance->GetEnumFromValue("EventOpcode", opcode).value_or("/* EVOP_UNK */ " + std::to_string(opcode));
+
+ cmd << "EVENT_CMD(" << enumName << ", " << std::right << std::setw(3) << std::dec << arg1 << ", " << std::setw(5) << std::dec << s2 << ")";
return cmd.str();
}
@@ -46,27 +48,27 @@ void SF64::ScriptCodeExporter::Export(std::ostream &write, std::shared_ptr<IPars
for(int i = 0; i < sortedPtrs.size(); i++) {
std::ostringstream scriptDefaultName;
- scriptDefaultName << symbol << "_cmds_" << std::uppercase << std::hex << cmdOff + 2 * cmdIndex;
+ scriptDefaultName << symbol << "_cmds_" << std::uppercase << std::hex << cmdOff;
+
if (Companion::Instance->IsDebug()) {
- if (IS_SEGMENTED(cmdOff)) {
- cmdOff = SEGMENT_OFFSET(cmdOff);
- }
write << "// 0x" << std::hex << std::uppercase << cmdOff << "\n";
}
write << "u16 " << scriptDefaultName.str() << "[] = {";
- for(int j = 0; j < script->mSizeMap[sortedPtrs[i]] / 2; j++, cmdIndex+=2) {
+ auto cmdCount = script->mSizeMap[sortedPtrs[i]] / 2;
+ for(int j = 0; j < cmdCount; j++, cmdIndex+=2) {
if((j % 3) == 0) {
write << "\n" << fourSpaceTab;
}
write << MakeScriptCmd(script->mCmds[cmdIndex], script->mCmds[cmdIndex + 1]) << ", ";
}
scriptNames.push_back(scriptDefaultName.str());
- write << "\n};";
+ write << "\n};\n";
+ cmdOff += 4 * cmdCount;
if (Companion::Instance->IsDebug()) {
- write << "// count: " << std::to_string(sortedPtrs.size()) << " Events\n";
- write << "// 0x" << std::hex << std::uppercase << (cmdOff + (sortedPtrs.size() * sizeof(uint16_t))) << "\n";
+ write << "// count: " << cmdCount << " commands\n";
+ write << "// 0x" << std::hex << std::uppercase << cmdOff << "\n";
}
write << "\n";
@@ -89,6 +91,7 @@ void SF64::ScriptCodeExporter::Export(std::ostream &write, std::shared_ptr<IPars
write << "\n};\n";
if (Companion::Instance->IsDebug()) {
+ write << "// count: " << script->mPtrs.size() << " events\n";
write << "// 0x" << std::hex << std::uppercase << (offset + (sizeof(uint32_t) * script->mPtrs.size())) << "\n";
}
diff --git a/src/factories/sf64/SkeletonFactory.cpp b/src/factories/sf64/SkeletonFactory.cpp
index fe0fab0..31d402b 100644
--- a/src/factories/sf64/SkeletonFactory.cpp
+++ b/src/factories/sf64/SkeletonFactory.cpp
@@ -8,7 +8,7 @@
#define NUM(x) std::dec << std::setfill(' ') << std::setw(7) << x
#define NUM_JOINT(x) std::dec << std::setfill(' ') << std::setw(5) << x
-SF64::LimbData::LimbData(uint32_t addr, uint32_t dList, float tx, float ty, float tz, float rx, float ry, float rz, uint32_t sibling, uint32_t child, int index): mAddr(addr), mDList(dList), mTx(tx), mTy(ty), mTz(tz), mRx(rx), mRy(ry), mRz(rz), mSibling(sibling), mChild(child), mIndex(index) {
+SF64::LimbData::LimbData(uint32_t addr, uint32_t dList, Vec3f trans, Vec3s rot, uint32_t sibling, uint32_t child, int index): mAddr(addr), mDList(dList), mTrans(trans), mRot(rot), mSibling(sibling), mChild(child), mIndex(index) {
}
@@ -64,8 +64,8 @@ void SF64::SkeletonCodeExporter::Export(std::ostream &write, std::shared_ptr<IPa
write << "0x" << std::uppercase << std::hex << limb.mDList << ", ";
}
}
- write << "{ " << limb.mTx << ", " << limb.mTy << ", " << limb.mTz << "}, ";
- write << "{ " << std::dec << limb.mRx << ", " << limb.mRy << ", " << limb.mRz << "}, ";
+ write << limb.mTrans << ", ";
+ write << std::dec << limb.mRot << ", ";
write << ((limb.mSibling != 0) ? "&" : "") << limbDict[limb.mSibling] << ", ";
write << ((limb.mChild != 0) ? "&" : "") << limbDict[limb.mChild] << ",\n";
write << "};\n\n";
@@ -112,18 +112,19 @@ std::optional<std::shared_ptr<IParsedData>> SF64::SkeletonFactory::parse(std::ve
while(limbAddr != 0) {
limbNode["offset"] = limbAddr;
-
+ Vec3f trans;
+ Vec3s rot;
DecompressedData limbDataRaw = Decompressor::AutoDecode(limbNode, buffer, 0x20);
LUS::BinaryReader limbReader(limbDataRaw.segment.data, limbDataRaw.segment.size);
limbReader.SetEndianness(LUS::Endianness::Big);
auto dListAddr = limbReader.ReadUInt32();
- auto tx = limbReader.ReadFloat();
- auto ty = limbReader.ReadFloat();
- auto tz = limbReader.ReadFloat();
- auto rx = limbReader.ReadInt16();
- auto ry = limbReader.ReadInt16();
- auto rz = limbReader.ReadInt16();
+ trans.x = limbReader.ReadFloat();
+ trans.y = limbReader.ReadFloat();
+ trans.z = limbReader.ReadFloat();
+ rot.x = limbReader.ReadInt16();
+ rot.y = limbReader.ReadInt16();
+ rot.z = limbReader.ReadInt16();
auto rw = limbReader.ReadInt16();
auto siblingAddr = limbReader.ReadUInt32();
auto childAddr = limbReader.ReadUInt32();
@@ -166,7 +167,7 @@ std::optional<std::shared_ptr<IParsedData>> SF64::SkeletonFactory::parse(std::ve
}
}
- skeleton.push_back(LimbData(limbAddr, dListAddr, tx, ty, tz, rx, ry, rz, siblingAddr, childAddr, limbIndex));
+ skeleton.push_back(LimbData(limbAddr, dListAddr, trans, rot, siblingAddr, childAddr, limbIndex));
limbAddr = reader.ReadUInt32();
limbIndex++;
}
diff --git a/src/factories/sf64/SkeletonFactory.h b/src/factories/sf64/SkeletonFactory.h
index 2d5da4e..f949793 100644
--- a/src/factories/sf64/SkeletonFactory.h
+++ b/src/factories/sf64/SkeletonFactory.h
@@ -1,28 +1,21 @@
#pragma once
#include "../BaseFactory.h"
+#include "types/Vec3D.h"
namespace SF64 {
class LimbData : public IParsedData {
public:
uint32_t mAddr;
- // std::string mSymbol;
- // uint32_t mDList;
- // float mTranslation[3];
- // int16_t mRotation[3];
uint32_t mDList;
- float mTx;
- float mTy;
- float mTz;
- int16_t mRx;
- int16_t mRy;
- int16_t mRz;
+ Vec3f mTrans;
+ Vec3s mRot;
uint32_t mSibling;
uint32_t mChild;
int mIndex;
- LimbData(uint32_t addr, uint32_t dList, float tx, float ty, float tz, float rx, float ry, float rz, uint32_t sibling, uint32_t child, int index);
+ LimbData(uint32_t addr, uint32_t dList, Vec3f trans, Vec3s rot, uint32_t sibling, uint32_t child, int index);
};
class SkeletonData : public IParsedData {
diff --git a/src/factories/sm64/geo/GeoCommand.h b/src/factories/sm64/geo/GeoCommand.h
index 2bad32d..e7b2966 100644
--- a/src/factories/sm64/geo/GeoCommand.h
+++ b/src/factories/sm64/geo/GeoCommand.h
@@ -6,43 +6,7 @@
#include <spdlog/spdlog.h>
#include <spdlog/fmt/ostr.h>
#include <binarytools/BinaryWriter.h>
-
-struct Vec2f {
- float x;
- float y;
-};
-
-struct Vec3f {
- float x;
- float y;
- float z;
-};
-
-struct Vec3s {
- int16_t x;
- int16_t y;
- int16_t z;
-};
-
-struct Vec3i {
- int32_t x;
- int32_t y;
- int32_t z;
-};
-
-struct Vec4f {
- float x;
- float y;
- float z;
- float w;
-};
-
-struct Vec4s {
- int16_t x;
- int16_t y;
- int16_t z;
- int16_t w;
-};
+#include <types/Vec3D.h>
enum class GeoOpcode {
BranchAndLink,
diff --git a/src/types/Vec3D.cpp b/src/types/Vec3D.cpp
new file mode 100644
index 0000000..0d75e88
--- /dev/null
+++ b/src/types/Vec3D.cpp
@@ -0,0 +1,57 @@
+#include "Vec3D.h"
+#include <iomanip>
+
+Vec3f::Vec3f(float xv, float yv, float zv) : x(xv), y(yv), z(zv) {}
+
+std::ostream& operator<< (std::ostream& stream, const Vec3f& vec) {
+ int width = stream.width();
+
+ stream << std::setw(0) << "{" << std::setw(width) << vec.x << ", " << std::setw(width) << vec.y << ", " << std::setw(width) << vec.z << "}";
+
+ return stream;
+}
+
+Vec3s::Vec3s(int16_t xv, int16_t yv, int16_t zv) : x(xv), y(yv), z(zv) {}
+
+std::ostream& operator<< (std::ostream& stream, const Vec3s& vec) {
+ int width = stream.width();
+
+ stream << std::setw(0) << "{" << std::setw(width) << vec.x << ", " << std::setw(width) << vec.y << ", " << std::setw(width) << vec.z << "}";
+ return stream;
+}
+
+Vec3i::Vec3i(int32_t xv, int32_t yv, int32_t zv) : x(xv), y(yv), z(zv) {}
+
+std::ostream& operator<< (std::ostream& stream, const Vec3i& vec) {
+ int width = stream.width();
+
+ stream << std::setw(0) << "{" << std::setw(width) << vec.x << ", " << std::setw(width) << vec.y << ", " << std::setw(width) << vec.z << "}";
+ return stream;
+}
+
+Vec2f::Vec2f(float xv, float zv) : x(xv), z(zv) {}
+
+std::ostream& operator<< (std::ostream& stream, const Vec2f& vec) {
+ int width = stream.width();
+
+ stream << std::setw(0) << "{" << std::setw(width) << vec.x << ", " << std::setw(width) << vec.z << "}";
+ return stream;
+}
+
+Vec4f::Vec4f(float xv, float yv, float zv, float wv) : x(xv), y(yv), z(zv), w(wv) {}
+
+std::ostream& operator<< (std::ostream& stream, const Vec4f& vec) {
+ int width = stream.width();
+
+ stream << std::setw(0) << "{" << std::setw(width) << vec.x << ", " << std::setw(width) << vec.y << ", " << std::setw(width) << vec.z << ", " << std::setw(width) << vec.w << "}";
+ return stream;
+}
+
+Vec4s::Vec4s(int16_t xv, int16_t yv, int16_t zv, int16_t wv) : x(xv), y(yv), z(zv), w(wv) {}
+
+std::ostream& operator<< (std::ostream& stream, const Vec4s& vec) {
+ int width = stream.width();
+
+ stream << std::setw(0) << "{" << std::setw(width) << vec.x << ", " << std::setw(width) << vec.y << ", " << std::setw(width) << vec.z << ", " << std::setw(width) << vec.w << "}";
+ return stream;
+}
diff --git a/src/types/Vec3D.h b/src/types/Vec3D.h
new file mode 100644
index 0000000..e861f12
--- /dev/null
+++ b/src/types/Vec3D.h
@@ -0,0 +1,64 @@
+#pragma once
+
+#include "../factories/BaseFactory.h"
+
+class Vec3f : public IParsedData {
+public:
+ float x;
+ float y;
+ float z;
+
+ Vec3f(float xv = 0, float yv = 0, float zv = 0);
+ friend std::ostream& operator<< (std::ostream& stream, const Vec3f& vec);
+};
+
+class Vec3s : public IParsedData {
+public:
+ int16_t x;
+ int16_t y;
+ int16_t z;
+
+ Vec3s(int16_t xv = 0, int16_t yv = 0, int16_t zv = 0);
+ friend std::ostream& operator<< (std::ostream& stream, const Vec3s& vec);
+};
+
+class Vec3i : public IParsedData {
+public:
+ int32_t x;
+ int32_t y;
+ int32_t z;
+
+ Vec3i(int32_t xv = 0, int32_t yv = 0, int32_t zv = 0);
+ friend std::ostream& operator<< (std::ostream& stream, const Vec3i& vec);
+};
+
+class Vec2f : public IParsedData {
+public:
+ float x;
+ float z;
+
+ Vec2f(float xv = 0, float zv = 0);
+ friend std::ostream& operator<< (std::ostream& stream, const Vec2f& vec);
+};
+
+class Vec4f : public IParsedData {
+public:
+ float x;
+ float y;
+ float z;
+ float w;
+
+ Vec4f(float xv = 0, float yv = 0, float zv = 0, float wv = 0);
+ friend std::ostream& operator<< (std::ostream& stream, const Vec4f& vec);
+};
+
+class Vec4s : public IParsedData {
+public:
+ int16_t x;
+ int16_t y;
+ int16_t z;
+ int16_t w;
+
+ Vec4s(int16_t xv = 0, int16_t yv = 0, int16_t zv = 0, int16_t wv = 0);
+ friend std::ostream& operator<< (std::ostream& stream, const Vec4s& vec);
+}; \ No newline at end of file