CGameArea: PostConstructArea fixes

This commit is contained in:
Luke Street 2022-03-02 19:16:48 -05:00
parent b0a711d5e2
commit 0400388fa6
2 changed files with 27 additions and 33 deletions

View File

@ -885,23 +885,19 @@ std::pair<const u8*, u32> CGameArea::GetLayerScriptBuffer(int layer) const {
void CGameArea::PostConstructArea() {
SMREAHeader header = VerifyHeader();
auto secIt = m_resolvedBufs.begin() + 2;
/* Materials */
++secIt;
u32 sec = 3;
x12c_postConstructed->x10ec_firstMatSection = 2;
/* Models */
auto secIt = m_resolvedBufs.begin() + 3;
x12c_postConstructed->x4c_insts.resize(header.modelCount);
for (u32 i = 0; i < header.modelCount; ++i) {
u32 surfCount = CBasics::SwapBytes(*reinterpret_cast<const u32*>((secIt + 4)->first));
secIt += 5 + surfCount;
sec += 5 + surfCount;
u32 surfCount = CBasics::SwapBytes(*reinterpret_cast<const u32*>((secIt + 6)->first));
secIt += 7 + surfCount;
}
/* Render octree */
if (header.version == 15 && header.arotSecIdx != -1) {
if (header.version > 14 && header.arotSecIdx != -1) {
x12c_postConstructed->xc_octTree.emplace(secIt->first);
++secIt;
}
@ -912,11 +908,7 @@ void CGameArea::PostConstructArea() {
++secIt;
/* Collision section */
std::unique_ptr<CAreaOctTree> collision = CAreaOctTree::MakeFromMemory(secIt->first, secIt->second);
if (collision) {
x12c_postConstructed->x0_collision = std::move(collision);
x12c_postConstructed->x8_collisionSize = secIt->second;
}
x12c_postConstructed->x0_collision = CAreaOctTree::MakeFromMemory(secIt->first, secIt->second);
++secIt;
/* Unknown section */
@ -950,6 +942,7 @@ void CGameArea::PostConstructArea() {
/* PVS section */
if (header.version > 7) {
CMemoryInStream r(secIt->first, secIt->second, CMemoryInStream::EOwnerShip::NotOwned);
if (secIt->second > 0) { // TODO this works around CMemoryInStream inf loop on 0 len
u32 magic = r.ReadLong();
if (magic == 'VISI') {
x12c_postConstructed->x10a8_pvsVersion = r.ReadLong();
@ -960,6 +953,7 @@ void CGameArea::PostConstructArea() {
std::make_unique<CPVSAreaSet>(secIt->first + r.GetReadPosition(), secIt->second - r.GetReadPosition());
}
}
}
++secIt;
}
@ -978,13 +972,13 @@ void CGameArea::PostConstructArea() {
x12c_postConstructed->x10c4_areaFog = std::make_unique<CAreaFog>();
/* URDE addition: preemptively fill in area models so shaders may be polled for completion */
if (!x12c_postConstructed->x1108_25_modelsConstructed)
FillInStaticGeometry();
// if (!x12c_postConstructed->x1108_25_modelsConstructed)
// FillInStaticGeometry();
xf0_24_postConstructed = true;
/* Resolve layer pointers */
if (x12c_postConstructed->x10c8_sclyBuf) {
if (x12c_postConstructed->x10c8_sclyBuf != nullptr) {
CMemoryInStream r(x12c_postConstructed->x10c8_sclyBuf, x12c_postConstructed->x10d0_sclySize,
CMemoryInStream::EOwnerShip::NotOwned);
FourCC magic;
@ -1005,7 +999,7 @@ void CGameArea::PostConstructArea() {
}
void CGameArea::FillInStaticGeometry() {
u32 start = x12c_postConstructed->x10ec_;
u32 start = x12c_postConstructed->x10ec_firstMatSection;
x12c_postConstructed->x10d4_firstMatPtr = x110_mreaSecBufs[start].first.get();
// Clear the instances without resizing
@ -1088,10 +1082,9 @@ SMREAHeader CGameArea::VerifyHeader() const {
CMemoryInStream r(x110_mreaSecBufs[0].first.get() + 4, x110_mreaSecBufs[0].second - 4);
u32 version = r.ReadLong();
if ((version & 0x10000) == 0) {
Log.report(logvisor::Fatal, FMT_STRING("Attempted to load non-URDE MREA"));
if ((version & 0x10000) != 0) {
Log.report(logvisor::Fatal, FMT_STRING("Attempted to load non-retail MREA"));
}
version &= ~0x10000;
SMREAHeader header;
header.version = (version >= 12 && version <= 15) ? version : 0;

View File

@ -24,6 +24,8 @@
namespace metaforce {
class CStateManager;
class CScriptAreaAttributes;
// Metaforce addition: store byte-swapped data for later use
struct SMREAHeader {
u32 version = 0;
zeus::CTransform xf;
@ -195,8 +197,7 @@ public:
};
struct CPostConstructed {
std::unique_ptr<CAreaOctTree> x0_collision;
u32 x8_collisionSize = 0;
std::unique_ptr<CAreaOctTree> x0_collision; // was rstl::optional_object<CAreaOctTree*>
std::optional<CAreaRenderOctTree> xc_octTree;
std::vector<CMetroidModelInstance> x4c_insts;
// std::unique_ptr<from unknown, pointless MREA section> x5c_;
@ -217,7 +218,7 @@ public:
CPFArea* x10bc_pathArea = nullptr;
std::unique_ptr<CAreaObjectList> x10c0_areaObjs;
std::unique_ptr<CAreaFog> x10c4_areaFog;
const u8* x10c8_sclyBuf = nullptr;
const u8* x10c8_sclyBuf = nullptr; // was rstl::optional_object<void*>
u32 x10d0_sclySize = 0;
const u8* x10d4_firstMatPtr = nullptr;
const CScriptAreaAttributes* x10d8_areaAttributes = nullptr;
@ -225,7 +226,7 @@ public:
u32 x10e0_ = 0;
float x10e4_occludedTime = 5.f;
u32 x10e8_ = -1;
u32 x10ec_ = 0;
u32 x10ec_firstMatSection = 0;
// std::vector<CAramToken> x10f0_tokens;
u32 x1100_ = 0;
u32 x1104_ = 0;