metaforce/Runtime/World/CPathFindArea.hpp

116 lines
4.4 KiB
C++
Raw Normal View History

2018-10-07 03:42:33 +00:00
#pragma once
2016-03-16 19:53:06 +00:00
#include "IObj.hpp"
#include "zeus/CTransform.hpp"
#include "zeus/CAABox.hpp"
2018-02-14 07:51:18 +00:00
#include "IFactory.hpp"
#include "CPathFindRegion.hpp"
2016-03-16 19:53:06 +00:00
namespace urde
{
class CVParamTransfer;
2018-02-14 07:51:18 +00:00
class CObjectReference;
2016-03-16 19:53:06 +00:00
2016-08-10 16:05:14 +00:00
class CPFBitSet
2016-03-16 19:53:06 +00:00
{
2018-03-03 05:49:13 +00:00
u32 x0_bitmap[16] = {};
2016-08-10 16:05:14 +00:00
public:
2018-03-03 05:49:13 +00:00
void Clear() { for (u32& w : x0_bitmap) w = 0; }
void Add(s32 i) { x0_bitmap[i / 32] |= (1 << (i % 32)); }
bool Test(s32 i) const { return (x0_bitmap[i / 32] & (1 << (i % 32))) != 0; }
void Rmv(s32 i) { x0_bitmap[i / 32] &= ~(1 << (i % 32)); }
2016-03-16 19:53:06 +00:00
};
2018-02-14 07:51:18 +00:00
class CPFAreaOctree
2017-07-30 11:00:30 +00:00
{
2018-02-14 07:51:18 +00:00
u32 x0_isLeaf;
zeus::CAABox x4_aabb;
zeus::CVector3f x1c_center;
2018-02-14 07:51:18 +00:00
CPFAreaOctree* x28_children[8];
rstl::prereserved_vector<CPFRegion*> x48_regions;
2017-07-30 11:00:30 +00:00
public:
2018-02-14 07:51:18 +00:00
CPFAreaOctree(CMemoryInStream& in);
void Fixup(CPFArea& area);
int GetChildIndex(const zeus::CVector3f& point) const;
2018-03-03 05:49:13 +00:00
rstl::prereserved_vector<CPFRegion*>* GetRegionList(const zeus::CVector3f& point);
2018-03-01 06:17:16 +00:00
void GetRegionListList(rstl::reserved_vector<rstl::prereserved_vector<CPFRegion*>*, 32>& listOut,
const zeus::CVector3f& point, float padding);
bool IsPointInsidePaddedAABox(const zeus::CVector3f& point, float padding) const;
2018-02-14 07:51:18 +00:00
void Render();
};
class CPFOpenList
{
friend class CPFArea;
2018-03-03 05:49:13 +00:00
CPFBitSet x0_bitSet;
2018-02-14 07:51:18 +00:00
CPFRegion x40_region;
CPFRegionData x90_regionData;
public:
void Clear();
2018-03-03 05:49:13 +00:00
void Push(CPFRegion* reg);
CPFRegion* Pop();
void Pop(CPFRegion* reg);
bool Test(CPFRegion* reg);
2017-07-30 11:00:30 +00:00
};
2016-08-10 16:05:14 +00:00
class CPFArea
2016-03-16 19:53:06 +00:00
{
2018-02-14 07:51:18 +00:00
friend class CPFRegion;
friend class CPFAreaOctree;
2018-03-01 06:17:16 +00:00
friend class CPathFindSearch;
2018-02-14 07:51:18 +00:00
2016-08-10 16:05:14 +00:00
float x0_ = FLT_MAX;
2018-03-03 05:49:13 +00:00
zeus::CVector3f x4_closestPoint;
2018-03-01 06:17:16 +00:00
std::vector<zeus::CVector3f> x10_tmpPolyPoints;
2018-03-03 05:49:13 +00:00
rstl::prereserved_vector<CPFRegion*>* x20_cachedRegionList = nullptr;
zeus::CVector3f x24_cachedRegionListPoint;
bool x30_hasCachedRegionList = false;
s32 x34_curCookie = 0;
CPFBitSet x38_closedSet;
CPFOpenList x78_openList;
//u32 x138_;
2018-02-14 07:51:18 +00:00
//std::unique_ptr<u8[]> x13c_data;
/* Used to be prereserved_vectors backed by x13c_data
* This has been changed to meet storage requirements of
* modern systems */
2018-02-14 07:51:18 +00:00
std::vector<CPFNode> x140_nodes; // x140: count, x144: ptr
std::vector<CPFLink> x148_links; // x148: count, x14c: ptr
std::vector<CPFRegion> x150_regions; // x150: count, x154: ptr
std::vector<CPFAreaOctree> x158_octree; // x158: count, x15c: ptr
std::vector<CPFRegion*> x160_octreeRegionLookup; // x160: count, x164: ptr
std::vector<u32> x168_connectionsGround; // x168: word_count, x16c: ptr
std::vector<u32> x170_connectionsFlyers; // x170: word_count, x174: ptr
2018-02-14 07:51:18 +00:00
std::vector<CPFRegionData> x178_regionDatas;
2017-07-30 11:00:30 +00:00
zeus::CTransform x188_transform;
2016-03-16 19:53:06 +00:00
public:
2018-02-14 07:51:18 +00:00
CPFArea(std::unique_ptr<u8[]>&& buf, u32 len);
2017-07-30 11:00:30 +00:00
void SetTransform(const zeus::CTransform& xf) { x188_transform = xf; }
const zeus::CTransform& GetTransform() const { return x188_transform; }
2018-02-14 07:51:18 +00:00
const CPFRegion& GetRegion(s32 i) const { return x150_regions[i]; }
2018-03-03 05:49:13 +00:00
const zeus::CVector3f& GetClosestPoint() const { return x4_closestPoint; }
CPFOpenList& OpenList() { return x78_openList; }
CPFBitSet& ClosedSet() { return x38_closedSet; }
2018-02-14 07:51:18 +00:00
const CPFRegionData& GetRegionData(s32 i) const { return x178_regionDatas[i]; }
const CPFLink& GetLink(s32 i) const { return x148_links[i]; }
const CPFNode& GetNode(s32 i) const { return x140_nodes[i]; }
const CPFAreaOctree& GetOctree(s32 i) const { return x158_octree[i]; }
const CPFRegion* GetOctreeRegionPtrs(s32 i) const { return x160_octreeRegionLookup[i]; }
2018-03-03 05:49:13 +00:00
rstl::prereserved_vector<CPFRegion*>* GetOctreeRegionList(const zeus::CVector3f& point);
u32 FindRegions(rstl::reserved_vector<CPFRegion*, 4>& regions, const zeus::CVector3f& point,
2018-03-01 06:17:16 +00:00
u32 flags, u32 indexMask);
CPFRegion* FindClosestRegion(const zeus::CVector3f& point, u32 flags, u32 indexMask, float padding);
2018-03-03 05:49:13 +00:00
zeus::CVector3f FindClosestReachablePoint(rstl::reserved_vector<CPFRegion*, 4>& regs,
const zeus::CVector3f& point, u32 flags, u32 indexMask);
bool PathExists(const CPFRegion* r1, const CPFRegion* r2, u32 flags) const;
2016-03-16 19:53:06 +00:00
};
2018-02-14 07:51:18 +00:00
CFactoryFnReturn FPathFindAreaFactory(const urde::SObjectTag& tag,
std::unique_ptr<u8[]>&& in, u32 len,
const urde::CVParamTransfer& vparms,
CObjectReference* selfRef);
2016-03-16 19:53:06 +00:00
}