Cleanup CPathFindArea

This commit is contained in:
Phillip Stephens 2019-10-24 22:44:37 -07:00
parent 18382e5bb6
commit 246e233dce
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
3 changed files with 27 additions and 28 deletions

View File

@ -10,8 +10,8 @@ CPFAreaOctree::CPFAreaOctree(CMemoryInStream& in) {
x0_isLeaf = in.readUint32Big(); x0_isLeaf = in.readUint32Big();
x4_aabb.readBoundingBoxBig(in); x4_aabb.readBoundingBoxBig(in);
x1c_center.readBig(in); x1c_center.readBig(in);
for (int i = 0; i < 8; ++i) for (auto& ptr : x28_children)
x28_children[i] = reinterpret_cast<CPFAreaOctree*>(in.readUint32Big()); ptr = reinterpret_cast<CPFAreaOctree*>(in.readUint32Big());
x48_regions.set_size(in.readUint32Big()); x48_regions.set_size(in.readUint32Big());
x48_regions.set_data(reinterpret_cast<CPFRegion**>(in.readUint32Big())); x48_regions.set_data(reinterpret_cast<CPFRegion**>(in.readUint32Big()));
} }
@ -25,22 +25,22 @@ void CPFAreaOctree::Fixup(CPFArea& area) {
return; return;
} }
for (int i = 0; i < 8; ++i) { for (auto & ptr : x28_children) {
if ((reinterpret_cast<uintptr_t>(x28_children[i]) & 0x80000000) == 0) if ((reinterpret_cast<uintptr_t>(ptr) & 0x80000000) == 0)
x28_children[i] = &area.x158_octree[reinterpret_cast<uintptr_t>(x28_children[i])]; ptr = &area.x158_octree[reinterpret_cast<uintptr_t>(ptr)];
else else
x28_children[i] = nullptr; ptr = nullptr;
} }
} }
int CPFAreaOctree::GetChildIndex(const zeus::CVector3f& point) const { u32 CPFAreaOctree::GetChildIndex(const zeus::CVector3f& point) const {
int idx = 0x0; u32 idx = 0x0u;
if (point.x() > x1c_center.x()) if (point.x() > x1c_center.x())
idx = 0x1; idx = 0x1u;
if (point.y() > x1c_center.y()) if (point.y() > x1c_center.y())
idx |= 0x2; idx |= 0x2u;
if (point.z() > x1c_center.z()) if (point.z() > x1c_center.z())
idx |= 0x4; idx |= 0x4u;
return idx; return idx;
} }
@ -60,8 +60,7 @@ void CPFAreaOctree::GetRegionListList(rstl::reserved_vector<rstl::prereserved_ve
return; return;
} }
for (int i = 0; i < 8; ++i) { for (CPFAreaOctree* ch : x28_children) {
CPFAreaOctree* ch = x28_children[i];
if (ch->IsPointInsidePaddedAABox(point, padding)) if (ch->IsPointInsidePaddedAABox(point, padding))
ch->GetRegionListList(listOut, point, padding); ch->GetRegionListList(listOut, point, padding);
} }
@ -184,10 +183,10 @@ rstl::prereserved_vector<CPFRegion*>* CPFArea::GetOctreeRegionList(const zeus::C
u32 CPFArea::FindRegions(rstl::reserved_vector<CPFRegion*, 4>& regions, const zeus::CVector3f& point, u32 flags, u32 CPFArea::FindRegions(rstl::reserved_vector<CPFRegion*, 4>& regions, const zeus::CVector3f& point, u32 flags,
u32 indexMask) { u32 indexMask) {
bool isFlyer = (flags & 0x2) != 0; bool isFlyer = (flags & 0x2u) != 0;
bool isSwimmer = (flags & 0x4) != 0; bool isSwimmer = (flags & 0x4u) != 0;
for (CPFRegion* region : *GetOctreeRegionList(point)) { for (CPFRegion* region : *GetOctreeRegionList(point)) {
if (region->GetFlags() & 0xff & flags && (region->GetFlags() >> 16) & 0xff & indexMask && if (region->GetFlags() & 0xffu & flags && (region->GetFlags() >> 16u) & 0xffu & indexMask &&
region->IsPointInside(point) && (isFlyer || isSwimmer || region->PointHeight(point) < 3.f)) { region->IsPointInside(point) && (isFlyer || isSwimmer || region->PointHeight(point) < 3.f)) {
regions.push_back(region); regions.push_back(region);
if (regions.size() == regions.capacity()) if (regions.size() == regions.capacity())
@ -200,12 +199,12 @@ u32 CPFArea::FindRegions(rstl::reserved_vector<CPFRegion*, 4>& regions, const ze
CPFRegion* CPFArea::FindClosestRegion(const zeus::CVector3f& point, u32 flags, u32 indexMask, float padding) { CPFRegion* CPFArea::FindClosestRegion(const zeus::CVector3f& point, u32 flags, u32 indexMask, float padding) {
rstl::reserved_vector<rstl::prereserved_vector<CPFRegion*>*, 32> regionListList; rstl::reserved_vector<rstl::prereserved_vector<CPFRegion*>*, 32> regionListList;
x158_octree.back().GetRegionListList(regionListList, point, padding); x158_octree.back().GetRegionListList(regionListList, point, padding);
bool isFlyer = (flags & 0x2) != 0; bool isFlyer = (flags & 0x2u) != 0;
CPFRegion* ret = nullptr; CPFRegion* ret = nullptr;
for (rstl::prereserved_vector<CPFRegion*>* list : regionListList) { for (rstl::prereserved_vector<CPFRegion*>* list : regionListList) {
for (CPFRegion* region : *list) { for (CPFRegion* region : *list) {
if (region->Data()->GetCookie() != x34_regionFindCookie) { if (region->Data()->GetCookie() != x34_regionFindCookie) {
if (region->GetFlags() & 0xff & flags && (region->GetFlags() >> 16) & 0xff & indexMask && if (region->GetFlags() & 0xffu & flags && (region->GetFlags() >> 16u) & 0xffu & indexMask &&
region->IsPointInsidePaddedAABox(point, padding) && (isFlyer || region->PointHeight(point) < 3.f)) { region->IsPointInsidePaddedAABox(point, padding) && (isFlyer || region->PointHeight(point) < 3.f)) {
if (region->FindBestPoint(x10_tmpPolyPoints, point, flags, padding * padding)) { if (region->FindBestPoint(x10_tmpPolyPoints, point, flags, padding * padding)) {
ret = region; ret = region;
@ -228,7 +227,7 @@ zeus::CVector3f CPFArea::FindClosestReachablePoint(rstl::reserved_vector<CPFRegi
zeus::CVector3f ret; zeus::CVector3f ret;
float closestDistSq = FLT_MAX; float closestDistSq = FLT_MAX;
for (CPFRegion& reg : x150_regions) { for (CPFRegion& reg : x150_regions) {
if (reg.GetFlags() & 0xff & flags && (reg.GetFlags() >> 16) & 0xff & indexMask) { if (reg.GetFlags() & 0xffu & flags && (reg.GetFlags() >> 16u) & 0xffu & indexMask) {
for (CPFRegion* oreg : regs) { for (CPFRegion* oreg : regs) {
if (PathExists(oreg, &reg, flags)) { if (PathExists(oreg, &reg, flags)) {
float distSq = (reg.GetCentroid() - point).magSquared(); float distSq = (reg.GetCentroid() - point).magSquared();
@ -245,7 +244,7 @@ zeus::CVector3f CPFArea::FindClosestReachablePoint(rstl::reserved_vector<CPFRegi
} }
bool CPFArea::PathExists(const CPFRegion* r1, const CPFRegion* r2, u32 flags) const { bool CPFArea::PathExists(const CPFRegion* r1, const CPFRegion* r2, u32 flags) const {
if (r1 == r2 || (flags & 0x4) != 0) if (r1 == r2 || (flags & 0x4u) != 0)
return true; return true;
u32 i1 = r1->GetIndex(); u32 i1 = r1->GetIndex();
@ -259,14 +258,14 @@ bool CPFArea::PathExists(const CPFRegion* r1, const CPFRegion* r2, u32 flags) co
u32 bit = totalConnections - remConnections + i2 - (i1 + 1); u32 bit = totalConnections - remConnections + i2 - (i1 + 1);
auto d = std::div(bit, 32); auto d = std::div(bit, 32);
if ((flags & 0x2) != 0) if ((flags & 0x2u) != 0)
return ((x170_connectionsFlyers[d.quot] >> d.rem) & 0x1) != 0; return ((x170_connectionsFlyers[d.quot] >> u32(d.rem)) & 0x1u) != 0;
else else
return ((x168_connectionsGround[d.quot] >> d.rem) & 0x1) != 0; return ((x168_connectionsGround[d.quot] >> u32(d.rem)) & 0x1u) != 0;
} }
CFactoryFnReturn FPathFindAreaFactory(const urde::SObjectTag& tag, std::unique_ptr<u8[]>&& in, u32 len, CFactoryFnReturn FPathFindAreaFactory(const urde::SObjectTag& tag, std::unique_ptr<u8[]>&& in, u32 len,
const urde::CVParamTransfer& vparms, CObjectReference* selfRef) { const urde::CVParamTransfer& vparms, CObjectReference*) {
return TToken<CPFArea>::GetIObjObjectFor(std::make_unique<CPFArea>(std::move(in), len)); return TToken<CPFArea>::GetIObjObjectFor(std::make_unique<CPFArea>(std::move(in), len));
} }
} // namespace urde } // namespace urde

View File

@ -33,13 +33,13 @@ class CPFAreaOctree {
u32 x0_isLeaf; u32 x0_isLeaf;
zeus::CAABox x4_aabb; zeus::CAABox x4_aabb;
zeus::CVector3f x1c_center; zeus::CVector3f x1c_center;
CPFAreaOctree* x28_children[8]; std::array<CPFAreaOctree*, 8> x28_children {};
rstl::prereserved_vector<CPFRegion*> x48_regions; rstl::prereserved_vector<CPFRegion*> x48_regions;
public: public:
CPFAreaOctree(CMemoryInStream& in); explicit CPFAreaOctree(CMemoryInStream& in);
void Fixup(CPFArea& area); void Fixup(CPFArea& area);
int GetChildIndex(const zeus::CVector3f& point) const; u32 GetChildIndex(const zeus::CVector3f& point) const;
rstl::prereserved_vector<CPFRegion*>* GetRegionList(const zeus::CVector3f& point); rstl::prereserved_vector<CPFRegion*>* GetRegionList(const zeus::CVector3f& point);
void GetRegionListList(rstl::reserved_vector<rstl::prereserved_vector<CPFRegion*>*, 32>& listOut, void GetRegionListList(rstl::reserved_vector<rstl::prereserved_vector<CPFRegion*>*, 32>& listOut,
const zeus::CVector3f& point, float padding); const zeus::CVector3f& point, float padding);

2
hecl

@ -1 +1 @@
Subproject commit 43b41583ab274059d430e2444276b0f78d023364 Subproject commit cf4501561648cb8e7b86b84c7950d163091b4ef9