mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-14 09:26:09 +00:00
More refactoring, decouple tweaks from hecl
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#include "Runtime/Collision/CAreaOctTree.hpp"
|
||||
|
||||
#include "Runtime/CBasics.hpp"
|
||||
#include "Runtime/Collision/CMaterialFilter.hpp"
|
||||
#include "IOStreams.hpp"
|
||||
#include "Runtime/Streams/IOStreams.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <cfloat>
|
||||
@@ -479,27 +480,27 @@ CAreaOctTree::Node CAreaOctTree::Node::GetChild(int idx) const {
|
||||
void CAreaOctTree::SwapTreeNode(u8* ptr, Node::ETreeType type) {
|
||||
if (type == Node::ETreeType::Branch) {
|
||||
u16* typeBits = reinterpret_cast<u16*>(ptr);
|
||||
*typeBits = hecl::SBig(*typeBits);
|
||||
*typeBits = CBasics::SwapBytes(*typeBits);
|
||||
u32* offsets = reinterpret_cast<u32*>(ptr + 4);
|
||||
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
Node::ETreeType ctype = Node::ETreeType((*typeBits >> (2 * i)) & 0x3);
|
||||
offsets[i] = hecl::SBig(offsets[i]);
|
||||
offsets[i] = CBasics::SwapBytes(offsets[i]);
|
||||
SwapTreeNode(ptr + offsets[i] + 36, ctype);
|
||||
}
|
||||
} else if (type == Node::ETreeType::Leaf) {
|
||||
float* aabb = reinterpret_cast<float*>(ptr);
|
||||
aabb[0] = hecl::SBig(aabb[0]);
|
||||
aabb[1] = hecl::SBig(aabb[1]);
|
||||
aabb[2] = hecl::SBig(aabb[2]);
|
||||
aabb[3] = hecl::SBig(aabb[3]);
|
||||
aabb[4] = hecl::SBig(aabb[4]);
|
||||
aabb[5] = hecl::SBig(aabb[5]);
|
||||
aabb[0] = CBasics::SwapBytes(aabb[0]);
|
||||
aabb[1] = CBasics::SwapBytes(aabb[1]);
|
||||
aabb[2] = CBasics::SwapBytes(aabb[2]);
|
||||
aabb[3] = CBasics::SwapBytes(aabb[3]);
|
||||
aabb[4] = CBasics::SwapBytes(aabb[4]);
|
||||
aabb[5] = CBasics::SwapBytes(aabb[5]);
|
||||
|
||||
u16* countIdxs = reinterpret_cast<u16*>(ptr + 24);
|
||||
*countIdxs = hecl::SBig(*countIdxs);
|
||||
*countIdxs = CBasics::SwapBytes(*countIdxs);
|
||||
for (u16 i = 0; i < *countIdxs; ++i)
|
||||
countIdxs[i + 1] = hecl::SBig(countIdxs[i + 1]);
|
||||
countIdxs[i + 1] = CBasics::SwapBytes(countIdxs[i + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -525,16 +526,16 @@ CAreaOctTree::CAreaOctTree(const zeus::CAABox& aabb, Node::ETreeType treeType, c
|
||||
SwapTreeNode(const_cast<u8*>(x20_treeBuf), treeType);
|
||||
|
||||
for (u32 i = 0; i < matCount; ++i)
|
||||
const_cast<u32*>(x28_materials)[i] = hecl::SBig(x28_materials[i]);
|
||||
const_cast<u32*>(x28_materials)[i] = CBasics::SwapBytes(x28_materials[i]);
|
||||
|
||||
for (u32 i = 0; i < edgeCount; ++i)
|
||||
const_cast<CCollisionEdge*>(x3c_edges)[i].swapBig();
|
||||
|
||||
for (u32 i = 0; i < polyCount; ++i)
|
||||
const_cast<u16*>(x44_polyEdges)[i] = hecl::SBig(x44_polyEdges[i]);
|
||||
const_cast<u16*>(x44_polyEdges)[i] = CBasics::SwapBytes(x44_polyEdges[i]);
|
||||
|
||||
for (u32 i = 0; i < vertCount * 3; ++i)
|
||||
const_cast<float*>(x4c_verts)[i] = hecl::SBig(x4c_verts[i]);
|
||||
const_cast<float*>(x4c_verts)[i] = CBasics::SwapBytes(x4c_verts[i]);
|
||||
}
|
||||
|
||||
std::unique_ptr<CAreaOctTree> CAreaOctTree::MakeFromMemory(const u8* buf, unsigned int size) {
|
||||
@@ -549,37 +550,37 @@ std::unique_ptr<CAreaOctTree> CAreaOctTree::MakeFromMemory(const u8* buf, unsign
|
||||
const u8* treeBuf = cur;
|
||||
cur += treeSize;
|
||||
|
||||
u32 matCount = hecl::SBig(*reinterpret_cast<const u32*>(cur));
|
||||
u32 matCount = CBasics::SwapBytes(*reinterpret_cast<const u32*>(cur));
|
||||
cur += 4;
|
||||
const u32* matBuf = reinterpret_cast<const u32*>(cur);
|
||||
cur += 4 * matCount;
|
||||
|
||||
u32 vertMatsCount = hecl::SBig(*reinterpret_cast<const u32*>(cur));
|
||||
u32 vertMatsCount = CBasics::SwapBytes(*reinterpret_cast<const u32*>(cur));
|
||||
cur += 4;
|
||||
const u8* vertMatsBuf = cur;
|
||||
cur += vertMatsCount;
|
||||
|
||||
u32 edgeMatsCount = hecl::SBig(*reinterpret_cast<const u32*>(cur));
|
||||
u32 edgeMatsCount = CBasics::SwapBytes(*reinterpret_cast<const u32*>(cur));
|
||||
cur += 4;
|
||||
const u8* edgeMatsBuf = cur;
|
||||
cur += edgeMatsCount;
|
||||
|
||||
u32 polyMatsCount = hecl::SBig(*reinterpret_cast<const u32*>(cur));
|
||||
u32 polyMatsCount = CBasics::SwapBytes(*reinterpret_cast<const u32*>(cur));
|
||||
cur += 4;
|
||||
const u8* polyMatsBuf = cur;
|
||||
cur += polyMatsCount;
|
||||
|
||||
u32 edgeCount = hecl::SBig(*reinterpret_cast<const u32*>(cur));
|
||||
u32 edgeCount = CBasics::SwapBytes(*reinterpret_cast<const u32*>(cur));
|
||||
cur += 4;
|
||||
const CCollisionEdge* edgeBuf = reinterpret_cast<const CCollisionEdge*>(cur);
|
||||
cur += edgeCount * sizeof(edgeCount);
|
||||
|
||||
u32 polyCount = hecl::SBig(*reinterpret_cast<const u32*>(cur));
|
||||
u32 polyCount = CBasics::SwapBytes(*reinterpret_cast<const u32*>(cur));
|
||||
cur += 4;
|
||||
const u16* polyBuf = reinterpret_cast<const u16*>(cur);
|
||||
cur += polyCount * 2;
|
||||
|
||||
u32 vertCount = hecl::SBig(*reinterpret_cast<const u32*>(cur));
|
||||
u32 vertCount = CBasics::SwapBytes(*reinterpret_cast<const u32*>(cur));
|
||||
cur += 4;
|
||||
const float* vertBuf = reinterpret_cast<const float*>(cur);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user