mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-06-25 21:53:28 +00:00
CGameArea: PostConstructArea fixes
This commit is contained in:
parent
b0a711d5e2
commit
0400388fa6
@ -885,23 +885,19 @@ std::pair<const u8*, u32> CGameArea::GetLayerScriptBuffer(int layer) const {
|
|||||||
void CGameArea::PostConstructArea() {
|
void CGameArea::PostConstructArea() {
|
||||||
SMREAHeader header = VerifyHeader();
|
SMREAHeader header = VerifyHeader();
|
||||||
|
|
||||||
auto secIt = m_resolvedBufs.begin() + 2;
|
|
||||||
|
|
||||||
/* Materials */
|
/* Materials */
|
||||||
++secIt;
|
x12c_postConstructed->x10ec_firstMatSection = 2;
|
||||||
|
|
||||||
u32 sec = 3;
|
|
||||||
|
|
||||||
/* Models */
|
/* Models */
|
||||||
|
auto secIt = m_resolvedBufs.begin() + 3;
|
||||||
x12c_postConstructed->x4c_insts.resize(header.modelCount);
|
x12c_postConstructed->x4c_insts.resize(header.modelCount);
|
||||||
for (u32 i = 0; i < header.modelCount; ++i) {
|
for (u32 i = 0; i < header.modelCount; ++i) {
|
||||||
u32 surfCount = CBasics::SwapBytes(*reinterpret_cast<const u32*>((secIt + 4)->first));
|
u32 surfCount = CBasics::SwapBytes(*reinterpret_cast<const u32*>((secIt + 6)->first));
|
||||||
secIt += 5 + surfCount;
|
secIt += 7 + surfCount;
|
||||||
sec += 5 + surfCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Render octree */
|
/* Render octree */
|
||||||
if (header.version == 15 && header.arotSecIdx != -1) {
|
if (header.version > 14 && header.arotSecIdx != -1) {
|
||||||
x12c_postConstructed->xc_octTree.emplace(secIt->first);
|
x12c_postConstructed->xc_octTree.emplace(secIt->first);
|
||||||
++secIt;
|
++secIt;
|
||||||
}
|
}
|
||||||
@ -912,11 +908,7 @@ void CGameArea::PostConstructArea() {
|
|||||||
++secIt;
|
++secIt;
|
||||||
|
|
||||||
/* Collision section */
|
/* Collision section */
|
||||||
std::unique_ptr<CAreaOctTree> collision = CAreaOctTree::MakeFromMemory(secIt->first, secIt->second);
|
x12c_postConstructed->x0_collision = CAreaOctTree::MakeFromMemory(secIt->first, secIt->second);
|
||||||
if (collision) {
|
|
||||||
x12c_postConstructed->x0_collision = std::move(collision);
|
|
||||||
x12c_postConstructed->x8_collisionSize = secIt->second;
|
|
||||||
}
|
|
||||||
++secIt;
|
++secIt;
|
||||||
|
|
||||||
/* Unknown section */
|
/* Unknown section */
|
||||||
@ -950,14 +942,16 @@ void CGameArea::PostConstructArea() {
|
|||||||
/* PVS section */
|
/* PVS section */
|
||||||
if (header.version > 7) {
|
if (header.version > 7) {
|
||||||
CMemoryInStream r(secIt->first, secIt->second, CMemoryInStream::EOwnerShip::NotOwned);
|
CMemoryInStream r(secIt->first, secIt->second, CMemoryInStream::EOwnerShip::NotOwned);
|
||||||
u32 magic = r.ReadLong();
|
if (secIt->second > 0) { // TODO this works around CMemoryInStream inf loop on 0 len
|
||||||
if (magic == 'VISI') {
|
u32 magic = r.ReadLong();
|
||||||
x12c_postConstructed->x10a8_pvsVersion = r.ReadLong();
|
if (magic == 'VISI') {
|
||||||
if (x12c_postConstructed->x10a8_pvsVersion == 2) {
|
x12c_postConstructed->x10a8_pvsVersion = r.ReadLong();
|
||||||
x12c_postConstructed->x1108_29_pvsHasActors = r.ReadBool();
|
if (x12c_postConstructed->x10a8_pvsVersion == 2) {
|
||||||
x12c_postConstructed->x1108_30_ = r.ReadBool();
|
x12c_postConstructed->x1108_29_pvsHasActors = r.ReadBool();
|
||||||
x12c_postConstructed->xa0_pvs =
|
x12c_postConstructed->x1108_30_ = r.ReadBool();
|
||||||
std::make_unique<CPVSAreaSet>(secIt->first + r.GetReadPosition(), secIt->second - r.GetReadPosition());
|
x12c_postConstructed->xa0_pvs =
|
||||||
|
std::make_unique<CPVSAreaSet>(secIt->first + r.GetReadPosition(), secIt->second - r.GetReadPosition());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -978,13 +972,13 @@ void CGameArea::PostConstructArea() {
|
|||||||
x12c_postConstructed->x10c4_areaFog = std::make_unique<CAreaFog>();
|
x12c_postConstructed->x10c4_areaFog = std::make_unique<CAreaFog>();
|
||||||
|
|
||||||
/* URDE addition: preemptively fill in area models so shaders may be polled for completion */
|
/* URDE addition: preemptively fill in area models so shaders may be polled for completion */
|
||||||
if (!x12c_postConstructed->x1108_25_modelsConstructed)
|
// if (!x12c_postConstructed->x1108_25_modelsConstructed)
|
||||||
FillInStaticGeometry();
|
// FillInStaticGeometry();
|
||||||
|
|
||||||
xf0_24_postConstructed = true;
|
xf0_24_postConstructed = true;
|
||||||
|
|
||||||
/* Resolve layer pointers */
|
/* 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 r(x12c_postConstructed->x10c8_sclyBuf, x12c_postConstructed->x10d0_sclySize,
|
||||||
CMemoryInStream::EOwnerShip::NotOwned);
|
CMemoryInStream::EOwnerShip::NotOwned);
|
||||||
FourCC magic;
|
FourCC magic;
|
||||||
@ -1005,7 +999,7 @@ void CGameArea::PostConstructArea() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CGameArea::FillInStaticGeometry() {
|
void CGameArea::FillInStaticGeometry() {
|
||||||
u32 start = x12c_postConstructed->x10ec_;
|
u32 start = x12c_postConstructed->x10ec_firstMatSection;
|
||||||
x12c_postConstructed->x10d4_firstMatPtr = x110_mreaSecBufs[start].first.get();
|
x12c_postConstructed->x10d4_firstMatPtr = x110_mreaSecBufs[start].first.get();
|
||||||
|
|
||||||
// Clear the instances without resizing
|
// 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);
|
CMemoryInStream r(x110_mreaSecBufs[0].first.get() + 4, x110_mreaSecBufs[0].second - 4);
|
||||||
u32 version = r.ReadLong();
|
u32 version = r.ReadLong();
|
||||||
if ((version & 0x10000) == 0) {
|
if ((version & 0x10000) != 0) {
|
||||||
Log.report(logvisor::Fatal, FMT_STRING("Attempted to load non-URDE MREA"));
|
Log.report(logvisor::Fatal, FMT_STRING("Attempted to load non-retail MREA"));
|
||||||
}
|
}
|
||||||
version &= ~0x10000;
|
|
||||||
|
|
||||||
SMREAHeader header;
|
SMREAHeader header;
|
||||||
header.version = (version >= 12 && version <= 15) ? version : 0;
|
header.version = (version >= 12 && version <= 15) ? version : 0;
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
namespace metaforce {
|
namespace metaforce {
|
||||||
class CStateManager;
|
class CStateManager;
|
||||||
class CScriptAreaAttributes;
|
class CScriptAreaAttributes;
|
||||||
|
|
||||||
|
// Metaforce addition: store byte-swapped data for later use
|
||||||
struct SMREAHeader {
|
struct SMREAHeader {
|
||||||
u32 version = 0;
|
u32 version = 0;
|
||||||
zeus::CTransform xf;
|
zeus::CTransform xf;
|
||||||
@ -195,8 +197,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct CPostConstructed {
|
struct CPostConstructed {
|
||||||
std::unique_ptr<CAreaOctTree> x0_collision;
|
std::unique_ptr<CAreaOctTree> x0_collision; // was rstl::optional_object<CAreaOctTree*>
|
||||||
u32 x8_collisionSize = 0;
|
|
||||||
std::optional<CAreaRenderOctTree> xc_octTree;
|
std::optional<CAreaRenderOctTree> xc_octTree;
|
||||||
std::vector<CMetroidModelInstance> x4c_insts;
|
std::vector<CMetroidModelInstance> x4c_insts;
|
||||||
// std::unique_ptr<from unknown, pointless MREA section> x5c_;
|
// std::unique_ptr<from unknown, pointless MREA section> x5c_;
|
||||||
@ -217,7 +218,7 @@ public:
|
|||||||
CPFArea* x10bc_pathArea = nullptr;
|
CPFArea* x10bc_pathArea = nullptr;
|
||||||
std::unique_ptr<CAreaObjectList> x10c0_areaObjs;
|
std::unique_ptr<CAreaObjectList> x10c0_areaObjs;
|
||||||
std::unique_ptr<CAreaFog> x10c4_areaFog;
|
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;
|
u32 x10d0_sclySize = 0;
|
||||||
const u8* x10d4_firstMatPtr = nullptr;
|
const u8* x10d4_firstMatPtr = nullptr;
|
||||||
const CScriptAreaAttributes* x10d8_areaAttributes = nullptr;
|
const CScriptAreaAttributes* x10d8_areaAttributes = nullptr;
|
||||||
@ -225,7 +226,7 @@ public:
|
|||||||
u32 x10e0_ = 0;
|
u32 x10e0_ = 0;
|
||||||
float x10e4_occludedTime = 5.f;
|
float x10e4_occludedTime = 5.f;
|
||||||
u32 x10e8_ = -1;
|
u32 x10e8_ = -1;
|
||||||
u32 x10ec_ = 0;
|
u32 x10ec_firstMatSection = 0;
|
||||||
// std::vector<CAramToken> x10f0_tokens;
|
// std::vector<CAramToken> x10f0_tokens;
|
||||||
u32 x1100_ = 0;
|
u32 x1100_ = 0;
|
||||||
u32 x1104_ = 0;
|
u32 x1104_ = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user