Skip to content

Commit

Permalink
Fixed macro and painting sm64 factories
Browse files Browse the repository at this point in the history
  • Loading branch information
KiritoDv committed Jan 27, 2025
1 parent 7bb9fed commit ec017e0
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 20 deletions.
56 changes: 39 additions & 17 deletions src/factories/sm64/MacroFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ExportResult SM64::MacroCodeExporter::Export(std::ostream &write, std::shared_pt
}

write << object.preset << ", ";
write << "CONVERT_YAW(" << object.yaw << "), ";
write << (object.yaw / 1.41) << ", ";
write << object.posX << ", ";
write << object.posY << ", ";
write << object.posZ;
Expand All @@ -58,46 +58,68 @@ ExportResult SM64::MacroCodeExporter::Export(std::ostream &write, std::shared_pt

ExportResult SM64::MacroBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
auto writer = LUS::BinaryWriter();
auto macro = std::static_pointer_cast<SM64::MacroData>(raw);
auto macro = std::static_pointer_cast<SM64::MacroDataAlt>(raw);

WriteHeader(writer, Torch::ResourceType::MacroObject, 0);

writer.Write((uint32_t) macro->mMacroData.size());

for(auto &entry : macro->mMacroData){
writer.Write(entry);
}
/*
for (auto &object : macro->mMacroData) {
writer.Write(static_cast<int16_t>(object.preset));
writer.Write((int16_t) std::round(object.yaw * 1.41));
writer.Write(object.yaw);
writer.Write(object.posX);
writer.Write(object.posY);
writer.Write(object.posZ);
writer.Write(object.behParam);
}

*/

writer.Finish(write);
return std::nullopt;
}

std::optional<std::shared_ptr<IParsedData>> SM64::MacroFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) {
std::vector<MacroObject> macroData;
auto [_, segment] = Decompressor::AutoDecode(node, buffer);
LUS::BinaryReader reader(segment.data, segment.size);
reader.SetEndianness(Torch::Endianness::Big);

while (true) {
auto presetYaw = reader.ReadInt16();
if (presetYaw == 0x1E) {
std::vector<int16_t> entries;

while(true) {
int16_t raw = reader.ReadInt16();
if(raw == 0x1E){
break;
}

int16_t yaw = ((presetYaw >> 9) & 0x7F) << 1;
int16_t preset = (presetYaw & 0x1FF) - 0x1F;

auto posX = reader.ReadInt16();
auto posY = reader.ReadInt16();
auto posZ = reader.ReadInt16();
auto behParam = reader.ReadInt16();
macroData.emplace_back(static_cast<MacroPresets>(preset), yaw, posX, posY, posZ, behParam);
entries.push_back(raw);
}

return std::make_shared<SM64::MacroData>(macroData);
/*
std::vector<MacroObject> macroData;
while (true) {
int16_t presetID = reader.ReadInt16();
if(presetID < 0) {
break;
}
int16_t yRot = reader.ReadInt16();
int16_t xObj = reader.ReadInt16();
int16_t yObj = reader.ReadInt16();
int16_t zObj = reader.ReadInt16();
int16_t params = reader.ReadInt16();
macroData.emplace_back(static_cast<MacroPresets>(presetID), yRot, xObj, yObj, zObj, params);
}
macroData.emplace_back(MacroPresets::macro_invalid, -1, -1, -1, -1, -1);
return std::make_shared<SM64::MacroData>(macroData);
*/

return std::make_shared<SM64::MacroDataAlt>(entries);
}
9 changes: 8 additions & 1 deletion src/factories/sm64/MacroFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ class MacroData : public IParsedData {
MacroData(std::vector<MacroObject> macroData) : mMacroData(std::move(macroData)) {}
};

class MacroDataAlt : public IParsedData {
public:
std::vector<int16_t> mMacroData;

MacroDataAlt(std::vector<int16_t> macroData) : mMacroData(std::move(macroData)) {}
};

class MacroHeaderExporter : public BaseExporter {
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};
Expand All @@ -40,7 +47,7 @@ class MacroFactory : public BaseFactory {
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, MacroCodeExporter)
// REGISTER(Code, MacroCodeExporter)
REGISTER(Header, MacroHeaderExporter)
REGISTER(Binary, MacroBinaryExporter)
};
Expand Down
2 changes: 1 addition & 1 deletion src/factories/sm64/PaintingMapFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ExportResult SM64::PaintingMapCodeExporter::Export(std::ostream &write, std::sha

for (auto &group : paintingData->mPaintingGroups) {
write << fourSpaceTab;
write << group.x << ", " << group.y << ", " << group.z << ", " << ",\n";
write << group.x << ", " << group.y << ", " << group.z << ",\n";
}

write << "};\n";
Expand Down
3 changes: 2 additions & 1 deletion src/factories/sm64/macro/MacroPresets.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ enum class MacroPresets {
macro_empty_362,
macro_empty_363,
macro_empty_364,
macro_empty_365
macro_empty_365,
macro_invalid = -1
};

inline std::ostream& operator<<(std::ostream& out, const MacroPresets& preset) {
Expand Down

0 comments on commit ec017e0

Please sign in to comment.