mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-09 01:07:43 +00:00
Correct rstl::prereserved_vector implementation
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include <stdlib.h>
|
||||
#include "CPathFindArea.hpp"
|
||||
#include "IVParamObj.hpp"
|
||||
#include "CToken.hpp"
|
||||
@@ -8,12 +9,12 @@ namespace urde
|
||||
CPFAreaOctree::CPFAreaOctree(CMemoryInStream& in)
|
||||
{
|
||||
x0_isLeaf = in.readUint32Big();
|
||||
for (int i=0 ; i<3 ; ++i)
|
||||
x4_points[i] = in.readVec3fBig();
|
||||
x4_aabb.readBoundingBoxBig(in);
|
||||
x1c_center.readBig(in);
|
||||
for (int i=0 ; i<8 ; ++i)
|
||||
x28_children[i] = reinterpret_cast<CPFAreaOctree*>(in.readUint32Big());
|
||||
x48_regionCount = in.readUint32Big();
|
||||
x4c_regions = reinterpret_cast<CPFRegion**>(in.readUint32Big());
|
||||
x48_regions.set_size(in.readUint32Big());
|
||||
x48_regions.set_data(reinterpret_cast<CPFRegion**>(in.readUint32Big()));
|
||||
}
|
||||
|
||||
void CPFAreaOctree::Fixup(CPFArea& area)
|
||||
@@ -21,9 +22,9 @@ void CPFAreaOctree::Fixup(CPFArea& area)
|
||||
x0_isLeaf = x0_isLeaf != 0 ? 1 : 0;
|
||||
if (x0_isLeaf)
|
||||
{
|
||||
if (!x48_regionCount)
|
||||
if (x48_regions.empty())
|
||||
return;
|
||||
x4c_regions = &area.x160_octreeRegionLookup[reinterpret_cast<uintptr_t>(x4c_regions)];
|
||||
x48_regions.set_data(&area.x160_octreeRegionLookup[reinterpret_cast<uintptr_t>(x48_regions.data())]);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,6 +37,18 @@ void CPFAreaOctree::Fixup(CPFArea& area)
|
||||
}
|
||||
}
|
||||
|
||||
int CPFAreaOctree::GetChildIndex(const zeus::CVector3f& point) const
|
||||
{
|
||||
int idx = 0x0;
|
||||
if (point.x > x1c_center.x)
|
||||
idx = 0x1;
|
||||
if (point.y > x1c_center.y)
|
||||
idx |= 0x2;
|
||||
if (point.z > x1c_center.z)
|
||||
idx |= 0x4;
|
||||
return idx;
|
||||
}
|
||||
|
||||
CPFOpenList::CPFOpenList()
|
||||
{
|
||||
|
||||
@@ -75,12 +88,12 @@ CPFArea::CPFArea(std::unique_ptr<u8[]>&& buf, u32 len)
|
||||
x10_.reserve(maxRegionNodes);
|
||||
|
||||
u32 numBitfieldWords = (numRegions * (numRegions - 1) / 2 + 31) / 32;
|
||||
x168_connectionsA.reserve(numBitfieldWords);
|
||||
x168_connectionsGround.reserve(numBitfieldWords);
|
||||
for (u32 i=0 ; i<numBitfieldWords ; ++i)
|
||||
x168_connectionsA.push_back(r.readUint32Big());
|
||||
x170_connectionsB.reserve(numBitfieldWords);
|
||||
x168_connectionsGround.push_back(r.readUint32Big());
|
||||
x170_connectionsFlyers.reserve(numBitfieldWords);
|
||||
for (u32 i=0 ; i<numBitfieldWords ; ++i)
|
||||
x170_connectionsB.push_back(r.readUint32Big());
|
||||
x170_connectionsFlyers.push_back(r.readUint32Big());
|
||||
|
||||
r.seek(((((numRegions * numRegions) + 31) / 32) - numBitfieldWords) * 2 * sizeof(u32));
|
||||
|
||||
@@ -101,6 +114,28 @@ CPFArea::CPFArea(std::unique_ptr<u8[]>&& buf, u32 len)
|
||||
node.Fixup(*this);
|
||||
}
|
||||
|
||||
bool CPFArea::PathExists(const CPFRegion* r1, const CPFRegion* r2, u32 flags) const
|
||||
{
|
||||
if (r1 == r2 || (flags & 0x4) != 0)
|
||||
return true;
|
||||
|
||||
u32 i1 = r1->GetIndex();
|
||||
u32 i2 = r2->GetIndex();
|
||||
if (i1 > i2)
|
||||
std::swap(i1, i2);
|
||||
|
||||
u32 remRegions = u32(x150_regions.size()) - i1;
|
||||
u32 remConnections = remRegions * (remRegions - 1) / 2;
|
||||
u32 totalConnections = u32(x150_regions.size()) * (u32(x150_regions.size()) - 1) / 2;
|
||||
u32 bit = totalConnections - remConnections + i2 - (i1 + 1);
|
||||
|
||||
auto d = std::div(bit, 32);
|
||||
if ((flags & 0x2) != 0)
|
||||
return ((x170_connectionsFlyers[d.quot] >> d.rem) & 0x1) == 0x1;
|
||||
else
|
||||
return ((x168_connectionsGround[d.quot] >> d.rem) & 0x1) == 0x1;
|
||||
}
|
||||
|
||||
CFactoryFnReturn FPathFindAreaFactory(const urde::SObjectTag& tag,
|
||||
std::unique_ptr<u8[]>&& in, u32 len,
|
||||
const urde::CVParamTransfer& vparms,
|
||||
|
||||
Reference in New Issue
Block a user