Add CStateManager area_sorter

This commit is contained in:
Henrique Gemignani Passos Lima 2022-11-28 01:26:24 +02:00
parent 26621f44eb
commit 5af3c20f3c
No known key found for this signature in database
GPG Key ID: E224F951761145F8
8 changed files with 119 additions and 12 deletions

View File

@ -161,6 +161,7 @@ public:
static void StreamEnd(); static void StreamEnd();
static const CViewport& GetViewport() { return mViewport; } static const CViewport& GetViewport() { return mViewport; }
static const CVector3f& GetViewpoint() { return mViewpoint; }
static const CTransform4f& GetViewMatrix() { return mViewMatrix; } static const CTransform4f& GetViewMatrix() { return mViewMatrix; }
static const CTransform4f& GetModelMatrix() { return mModelMatrix; } static const CTransform4f& GetModelMatrix() { return mModelMatrix; }
static void SetViewPointMatrix(const CTransform4f&); static void SetViewPointMatrix(const CTransform4f&);
@ -200,6 +201,7 @@ private:
static CTransform4f mViewMatrix; static CTransform4f mViewMatrix;
static CTransform4f mModelMatrix; static CTransform4f mModelMatrix;
static CViewport mViewport; static CViewport mViewport;
static CVector3f mViewpoint;
static float mBrightness; static float mBrightness;
}; };

View File

@ -11,23 +11,23 @@
class CAABox; class CAABox;
class CSphere; class CSphere;
class CPlane {
private:
float x;
float y;
float z;
float d;
};
class CFrustumPlanes { class CFrustumPlanes {
public: public:
class SPlane {
private:
float x;
float y;
float z;
float d;
};
bool BoxInFrustumPlanes(const CAABox& box) const; bool BoxInFrustumPlanes(const CAABox& box) const;
bool BoxInFrustumPlanes(const rstl::optional_object< CAABox >& box) const; bool BoxInFrustumPlanes(const rstl::optional_object< CAABox >& box) const;
bool SphereInFrustumPlanes(const CSphere& sphere) const; bool SphereInFrustumPlanes(const CSphere& sphere) const;
bool PointInFrustumPlanes(const CVector3f& point) const; bool PointInFrustumPlanes(const CVector3f& point) const;
private: private:
rstl::reserved_vector< CPlane, 6 > x0_planes; rstl::reserved_vector< SPlane, 6 > x0_planes;
}; };
#endif // _CFRUSTUMPLANES #endif // _CFRUSTUMPLANES

View File

@ -33,6 +33,15 @@ public:
virtual rstl::pair< rstl::auto_ptr< uchar >, int > IGetScriptingMemoryAlways() const = 0; virtual rstl::pair< rstl::auto_ptr< uchar >, int > IGetScriptingMemoryAlways() const = 0;
}; };
enum EChain {
kC_Invalid = -1,
kC_ToDeallocate,
kC_Deallocated,
kC_Loading,
kC_Alive,
kC_AliveJudgement,
};
class Dock; class Dock;
class CToken; class CToken;
class IDvdRequest; class IDvdRequest;
@ -67,6 +76,22 @@ public:
void DisableFog(); void DisableFog();
}; };
class CConstChainIterator {
const CGameArea* m_area;
public:
CConstChainIterator() : m_area(nullptr) {}
explicit CConstChainIterator(const CGameArea* area) : m_area(area) {}
const CGameArea& operator*() const { return *m_area; }
const CGameArea* operator->() const { return m_area; }
CConstChainIterator& operator++() {
m_area = m_area->GetNext();
return *this;
}
bool operator!=(const CConstChainIterator& other) const { return m_area != other.m_area; }
bool operator==(const CConstChainIterator& other) const { return m_area == other.m_area; }
};
~CGameArea(); ~CGameArea();
const CTransform4f& IGetTM() const override; const CTransform4f& IGetTM() const override;
CAssetId IGetStringTableAssetId() const override; CAssetId IGetStringTableAssetId() const override;
@ -77,9 +102,12 @@ public:
int IGetAreaSaveId() const override; int IGetAreaSaveId() const override;
rstl::pair< rstl::auto_ptr< uchar >, int > IGetScriptingMemoryAlways() const override; rstl::pair< rstl::auto_ptr< uchar >, int > IGetScriptingMemoryAlways() const override;
TAreaId GetId() const { return x4_selfIdx; }
const CTransform4f& GetTM() const { return xc_transform; } const CTransform4f& GetTM() const { return xc_transform; }
bool IsLoaded() const { return xf0_24_postConstructed; } bool IsLoaded() const { return xf0_24_postConstructed; }
bool IsActive() const { return xf0_25_active; } bool IsActive() const { return xf0_25_active; }
const CAABox& GetAABB() const { return x6c_aabb; }
CGameArea* GetNext() const; // { return x130_next; }
void SetXRaySpeedAndTarget(float speed, float target); void SetXRaySpeedAndTarget(float speed, float target);
void SetThermalSpeedAndTarget(float speed, float target); void SetThermalSpeedAndTarget(float speed, float target);

View File

@ -8,6 +8,7 @@
#include "Kyoto/Input/CFinalInput.hpp" #include "Kyoto/Input/CFinalInput.hpp"
#include "Kyoto/Math/CVector2f.hpp" #include "Kyoto/Math/CVector2f.hpp"
#include "Kyoto/Math/CVector2i.hpp" #include "Kyoto/Math/CVector2i.hpp"
#include "Kyoto/Math/CFrustumPlanes.hpp"
#include "Kyoto/TOneStatic.hpp" #include "Kyoto/TOneStatic.hpp"
#include "Kyoto/TToken.hpp" #include "Kyoto/TToken.hpp"
@ -56,6 +57,7 @@ class CWorldLayerState;
class CLight; class CLight;
class CDamageInfo; class CDamageInfo;
class CTexture; class CTexture;
class CViewport;
namespace SL { namespace SL {
class CSortedListManager; class CSortedListManager;
@ -157,6 +159,7 @@ public:
void SetActorAreaId(CActor& actor, TAreaId); void SetActorAreaId(CActor& actor, TAreaId);
TAreaId GetNextAreaId() const { return x8cc_nextAreaId; } TAreaId GetNextAreaId() const { return x8cc_nextAreaId; }
void SetCurrentAreaId(TAreaId); void SetCurrentAreaId(TAreaId);
TAreaId GetVisAreaId() const;
bool CanCreateProjectile(TUniqueId, EWeaponType, int) const; bool CanCreateProjectile(TUniqueId, EWeaponType, int) const;
@ -238,6 +241,10 @@ public:
void RemoveWeaponId(TUniqueId, EWeaponType); void RemoveWeaponId(TUniqueId, EWeaponType);
void AddWeaponId(TUniqueId, EWeaponType); void AddWeaponId(TUniqueId, EWeaponType);
// Draw
CFrustumPlanes SetupViewForDraw(const CViewport&) const;
void DrawWorld() const;
// State transitions // State transitions
void DeferStateTransition(EStateManagerTransition t); void DeferStateTransition(EStateManagerTransition t);
void EnterMapScreen() { DeferStateTransition(kSMT_MapScreen); } void EnterMapScreen() { DeferStateTransition(kSMT_MapScreen); }

View File

@ -75,6 +75,7 @@ public:
int IGetAreaCount() const override; int IGetAreaCount() const override;
void SetLoadPauseState(bool); void SetLoadPauseState(bool);
void TouchSky() const;
const CGameArea& GetAreaAlways(TAreaId id) const { return *x18_areas[id.Value()]; } const CGameArea& GetAreaAlways(TAreaId id) const { return *x18_areas[id.Value()]; }
CGameArea* Area(TAreaId id) { return x18_areas[id.Value()].get(); } CGameArea* Area(TAreaId id) { return x18_areas[id.Value()].get(); }
@ -88,6 +89,9 @@ public:
static void PropogateAreaChain(CGameArea::EOcclusionState occlusionState, CGameArea* area, static void PropogateAreaChain(CGameArea::EOcclusionState occlusionState, CGameArea* area,
CWorld* world); CWorld* world);
CGameArea::CConstChainIterator GetChainHead(EChain chain) const { return CGameArea::CConstChainIterator(x4c_chainHeads[size_t(chain)]); }
static CGameArea::CConstChainIterator GetAliveAreasEnd();
private: private:
enum Phase { enum Phase {
kP_Loading, kP_Loading,

View File

@ -21,7 +21,7 @@ typename It::difference_type __distance(It first, It last, forward_iterator_tag)
} }
template < typename It > template < typename It >
typename It::difference_type distance(It first, It last) { inline typename It::difference_type distance(It first, It last) {
return __distance(first, last, typename It::iterator_category()); return __distance(first, last, typename It::iterator_category());
} }

View File

@ -21,13 +21,44 @@
#include "Kyoto/Basics/RAssertDolphin.hpp" #include "Kyoto/Basics/RAssertDolphin.hpp"
#include "Kyoto/CARAMManager.hpp" #include "Kyoto/CARAMManager.hpp"
#include "Kyoto/CARAMToken.hpp" #include "Kyoto/CARAMToken.hpp"
#include "Kyoto/CTimeProvider.hpp"
#include "Kyoto/Graphics/CLight.hpp" #include "Kyoto/Graphics/CLight.hpp"
#include "MetaRender/CCubeRenderer.hpp" #include "MetaRender/CCubeRenderer.hpp"
#include "rstl/algorithm.hpp"
extern "C" { extern "C" {
void sub_8036ccfc(); void sub_8036ccfc();
} }
namespace {
class area_sorter {
public:
area_sorter(CVector3f ref, TAreaId aid) : reference(ref), visAreaId(aid) {}
bool operator()(const CGameArea* a, const CGameArea* b) const;
private:
CVector3f reference;
TAreaId visAreaId;
};
bool area_sorter::operator()(const CGameArea* a, const CGameArea* b) const {
if (a->GetId() == b->GetId()) {
return false;
}
if (visAreaId == a->GetId()) {
return false;
}
if (visAreaId == b->GetId()) {
return true;
}
return CVector3f::Dot(reference, a->GetAABB().GetCenterPoint()) >
CVector3f::Dot(reference, b->GetAABB().GetCenterPoint());
}
} // namespace
CStateManager::CStateManager(const rstl::ncrc_ptr< CScriptMailbox >& mailbox, CStateManager::CStateManager(const rstl::ncrc_ptr< CScriptMailbox >& mailbox,
const rstl::ncrc_ptr< CMapWorldInfo >& mwInfo, const rstl::ncrc_ptr< CMapWorldInfo >& mwInfo,
const rstl::ncrc_ptr< CPlayerState >& playerState, const rstl::ncrc_ptr< CPlayerState >& playerState,
@ -340,3 +371,37 @@ bool CStateManager::SwapOutAllPossibleMemory() {
} }
void CStateManager::RendererDrawCallback(const void*, const void*, int) {} void CStateManager::RendererDrawCallback(const void*, const void*, int) {}
void CStateManager::DrawWorld() const {
const CTimeProvider timeProvider(xf14_curTimeMod900);
const CViewport backupViewport = CGraphics::GetViewport();
/* Area camera is in (not necessarily player) */
const TAreaId visAreaId = GetVisAreaId();
x850_world->TouchSky();
const CFrustumPlanes frustum = SetupViewForDraw(CGraphics::GetViewport());
const CTransform4f backupViewMatrix = CGraphics::GetViewMatrix();
int areaCount = 0;
const CGameArea* areaArr[10];
CGameArea::CConstChainIterator it = x850_world->GetChainHead(kC_Alive);
CGameArea::CConstChainIterator end = x850_world->GetAliveAreasEnd();
for (; it != end; ++it) {
if (areaCount == 10) {
break;
}
CGameArea::EOcclusionState occState = CGameArea::kOS_Occluded;
if (it->IsLoaded()) {
occState = it->GetOcclusionState();
}
if (occState == CGameArea::kOS_Visible) {
areaArr[areaCount++] = &*it;
}
}
rstl::sort(&areaArr[0], &areaArr[areaCount], area_sorter(CGraphics::GetViewpoint(), visAreaId));
}

View File

@ -11,6 +11,7 @@
#include "MetroidPrime/Player/CGameState.hpp" #include "MetroidPrime/Player/CGameState.hpp"
#include "MetroidPrime/Player/CPlayer.hpp" #include "MetroidPrime/Player/CPlayer.hpp"
#include "MetroidPrime/Player/CPlayerState.hpp" #include "MetroidPrime/Player/CPlayerState.hpp"
#include "MetroidPrime/Player/CWorldLayerState.hpp"
#include "MetroidPrime/ScriptObjects/CScriptPlatform.hpp" #include "MetroidPrime/ScriptObjects/CScriptPlatform.hpp"
#include "MetroidPrime/TCastTo.hpp" #include "MetroidPrime/TCastTo.hpp"
#include "MetroidPrime/Weapons/CEnergyProjectile.hpp" #include "MetroidPrime/Weapons/CEnergyProjectile.hpp"
@ -28,9 +29,9 @@
#include "Kyoto/Math/CVector2i.hpp" #include "Kyoto/Math/CVector2i.hpp"
#include "Kyoto/Math/CloseEnough.hpp" #include "Kyoto/Math/CloseEnough.hpp"
#include "rstl/math.hpp"
#include "rstl/iterator.hpp"
#include "rstl/algorithm.hpp" #include "rstl/algorithm.hpp"
#include "rstl/iterator.hpp"
#include "rstl/math.hpp"
#include "math.h" #include "math.h"