Add debugging tool CVars

This commit is contained in:
Phillip Stephens 2021-01-10 18:44:42 -08:00
parent 386d6ef527
commit cede47be4d
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
6 changed files with 49 additions and 44 deletions

View File

@ -53,7 +53,13 @@
#include <zeus/CMRay.hpp>
namespace urde {
namespace {
hecl::CVar* debugToolDrawAiPath = nullptr;
hecl::CVar* debugToolDrawLighting = nullptr;
hecl::CVar* debugToolDrawCollisionActors = nullptr;
hecl::CVar* debugToolDrawMazePath = nullptr;
hecl::CVar* sm_logScripting = nullptr;
} // namespace
logvisor::Module LogModule("urde::CStateManager");
CStateManager::CStateManager(const std::weak_ptr<CRelayTracker>& relayTracker,
const std::weak_ptr<CMapWorldInfo>& mwInfo, const std::weak_ptr<CPlayerState>& playerState,
@ -118,7 +124,8 @@ CStateManager::CStateManager(const std::weak_ptr<CRelayTracker>& relayTracker,
x90c_loaderFuncs[size_t(EScriptObjectType::GrapplePoint)] = ScriptLoader::LoadGrapplePoint;
x90c_loaderFuncs[size_t(EScriptObjectType::PuddleSpore)] = ScriptLoader::LoadPuddleSpore;
x90c_loaderFuncs[size_t(EScriptObjectType::DebugCameraWaypoint)] = ScriptLoader::LoadDebugCameraWaypoint;
x90c_loaderFuncs[size_t(EScriptObjectType::SpiderBallAttractionSurface)] = ScriptLoader::LoadSpiderBallAttractionSurface;
x90c_loaderFuncs[size_t(EScriptObjectType::SpiderBallAttractionSurface)] =
ScriptLoader::LoadSpiderBallAttractionSurface;
x90c_loaderFuncs[size_t(EScriptObjectType::PuddleToadGamma)] = ScriptLoader::LoadPuddleToadGamma;
x90c_loaderFuncs[size_t(EScriptObjectType::DistanceFog)] = ScriptLoader::LoadDistanceFog;
x90c_loaderFuncs[size_t(EScriptObjectType::FireFlea)] = ScriptLoader::LoadFireFlea;
@ -428,9 +435,7 @@ void CStateManager::SetupParticleHook(const CActor& actor) const {
void CStateManager::MurderScriptInstanceNames() { xb40_uniqueInstanceNames.clear(); }
std::string CStateManager::HashInstanceName(CInputStream& in) {
return in.readString();
}
std::string CStateManager::HashInstanceName(CInputStream& in) { return in.readString(); }
void CStateManager::SetActorAreaId(CActor& actor, TAreaId aid) {
const TAreaId actorAid = actor.GetAreaIdAlways();
@ -535,42 +540,51 @@ void CStateManager::BuildDynamicLightListForWorld() {
}
}
}
void CStateManager::DrawDebugStuff() const {
if (hecl::com_developer != nullptr && !hecl::com_developer->toBoolean()) {
return;
}
// FIXME: Add proper globals for CVars
if (debugToolDrawAiPath == nullptr || debugToolDrawCollisionActors == nullptr || debugToolDrawLighting == nullptr ||
debugToolDrawMazePath == nullptr) {
debugToolDrawAiPath = hecl::CVarManager::instance()->findCVar("debugTool.drawAiPath");
debugToolDrawMazePath = hecl::CVarManager::instance()->findCVar("debugTool.drawMazePath");
debugToolDrawCollisionActors = hecl::CVarManager::instance()->findCVar("debugTool.drawCollisionActors");
debugToolDrawLighting = hecl::CVarManager::instance()->findCVar("debugTool.drawLighting");
return;
}
CGraphics::SetModelMatrix(zeus::CTransform());
#ifndef NDEBUG
for (CEntity* ent : GetActorObjectList()) {
if (const TCastToPtr<CPatterned> ai = ent) {
if (CPathFindSearch* path = ai->GetSearchPath()) {
path->DebugDraw();
if (debugToolDrawAiPath->toBoolean()) {
path->DebugDraw();
}
}
} else if (const TCastToPtr<CGameLight> light = ent) {
light->DebugDraw();
if (debugToolDrawLighting->toBoolean()) {
light->DebugDraw();
}
} else if (const TCastToPtr<CCollisionActor> colAct = ent) {
if (colAct->GetUniqueId() == x870_cameraManager->GetBallCamera()->GetCollisionActorId()) {
continue;
}
colAct->DebugDraw();
if (debugToolDrawCollisionActors->toBoolean()) {
colAct->DebugDraw();
}
}
}
auto* gameArea = x850_world->GetArea(x850_world->GetCurrentAreaId());
if (gameArea != nullptr) {
if (gameArea != nullptr && debugToolDrawLighting->toBoolean()) {
gameArea->DebugDraw();
}
if (xf70_currentMaze) {
if (xf70_currentMaze && debugToolDrawMazePath->toBoolean()) {
xf70_currentMaze->DebugRender();
}
for (CEntity* ent : GetActorObjectList()) {
if (const TCastToPtr<CCollisionActor> colAct = ent) {
if (colAct->GetUniqueId() == x870_cameraManager->GetBallCamera()->GetCollisionActorId()) {
continue;
}
colAct->DebugDraw();
}
}
#endif
}
void CStateManager::RenderCamerasAndAreaLights() {
@ -1507,7 +1521,9 @@ std::pair<TEditorId, TUniqueId> CStateManager::LoadScriptObject(TAreaId aid, ESc
ScriptObjectTypeToStr(type), name);
return {kInvalidEditorId, kInvalidUniqueId};
} else {
#ifndef NDEBUG
LogModule.report(logvisor::Info, FMT_STRING("Loaded {} in area {}"), ent->GetName(), ent->GetAreaIdAlways());
#endif
return {id, ent->GetUniqueId()};
}
}
@ -1610,7 +1626,8 @@ void CStateManager::KnockBackPlayer(CPlayer& player, const zeus::CVector3f& pos,
usePower = power * 1000.f;
const auto surface =
player.x2b0_outOfWaterTicks == 2 ? player.x2ac_surfaceRestraint : CPlayer::ESurfaceRestraints::Water;
if (surface != CPlayer::ESurfaceRestraints::Normal && player.GetOrbitState() == CPlayer::EPlayerOrbitState::NoOrbit) {
if (surface != CPlayer::ESurfaceRestraints::Normal &&
player.GetOrbitState() == CPlayer::EPlayerOrbitState::NoOrbit) {
usePower /= 7.f;
}
} else {
@ -1722,7 +1739,8 @@ void CStateManager::ApplyRadiusDamage(const CActor& a1, const zeus::CVector3f& p
}
}
const CDamageVulnerability* vuln = rad > 0.f ? a2.GetDamageVulnerability(pos, delta, info) : a2.GetDamageVulnerability();
const CDamageVulnerability* vuln =
rad > 0.f ? a2.GetDamageVulnerability(pos, delta, info) : a2.GetDamageVulnerability();
if (vuln->WeaponHurts(info.GetWeaponMode(), true)) {
const float dam = info.GetRadiusDamage(*vuln);

View File

@ -1956,7 +1956,7 @@ void CMorphBall::CollidedWith(TUniqueId id, const CCollisionInfoList& list, CSta
if (wakeMaterial == EMaterialTypes::NoStepLogic) {
if (info.GetMaterialLeft().HasMaterial(EMaterialTypes::Floor)) {
EMaterialTypes tmpMaterial;
EMaterialTypes tmpMaterial = EMaterialTypes::NoStepLogic;
if (info.GetMaterialLeft().HasMaterial(EMaterialTypes::Dirt)) {
tmpMaterial = EMaterialTypes::Dirt;
} else {
@ -2169,12 +2169,11 @@ float CMorphBall::CalculateSurfaceFriction() const {
}
void CMorphBall::ApplyGravity(const CStateManager& mgr) {
const float mass = x0_player.GetMass();
const bool hasGravitySuit = mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::GravitySuit);
const bool useWaterGravity = x0_player.CheckSubmerged() && !hasGravitySuit;
const float gravity = useWaterGravity ? g_tweakBall->GetBallWaterGravity() : g_tweakBall->GetBallGravity();
x0_player.SetMomentumWR(zeus::CVector3f(0.f, 0.f, gravity * mass));
if (!x0_player.CheckSubmerged() || mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::GravitySuit)) {
x0_player.SetMomentumWR({0.f, 0.f, x0_player.GetMass() * g_tweakBall->GetBallGravity()});
} else {
x0_player.SetMomentumWR({0.f, 0.f, x0_player.GetMass() * g_tweakBall->GetBallWaterGravity()});
}
}
void CMorphBall::SpinToSpeed(float holdMag, const zeus::CVector3f& torque, float mag) {

View File

@ -11,9 +11,7 @@ namespace urde {
std::array<s32, 300> sMazeSeeds;
#ifndef NDEBUG
std::array<zeus::CVector3f, skMazeRows * skMazeCols> sDebugCellPos;
#endif
CScriptMazeNode::CScriptMazeNode(TUniqueId uid, std::string_view name, const CEntityInfo& info,
const zeus::CTransform& xf, bool active, s32 col, s32 row, s32 side,
@ -163,14 +161,12 @@ void CScriptMazeNode::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, C
maze->GenerateObstacles();
mgr.SetCurrentMaze(std::move(maze));
}
#ifndef NDEBUG
if (xf0_side == ESide::Right) {
sDebugCellPos[xe8_col + xec_row * skMazeCols] = GetTranslation();
} else if (xe8_col == skMazeCols - 1) {
// Last column does not have right nodes, but we can infer the position
sDebugCellPos[xe8_col + xec_row * skMazeCols] = GetTranslation() - zeus::CVector3f{1.1875f, -0.1215f, 1.2187f};
}
#endif
}
}
// URDE change: used to be in the above if branch
@ -356,11 +352,9 @@ void CMazeState::Initialize() {
auto& cell = GetCell(*idx);
if (cell.x1_26_checked) {
cell.x1_25_onPath = true;
#ifndef NDEBUG
if (pathLength > 0) {
m_path.push_back(*idx);
}
#endif
}
}
x94_24_initialized = true;
@ -467,7 +461,6 @@ void CMazeState::GenerateObstacles() {
};
}
#ifndef NDEBUG
void CMazeState::DebugRender() {
m_renderer.Reset();
m_renderer.AddVertex(sDebugCellPos[skEnterCol + skEnterRow * skMazeCols], zeus::skBlue, 2.f);
@ -484,5 +477,4 @@ void CMazeState::DebugRender() {
}
m_renderer.Render();
}
#endif
} // namespace urde

View File

@ -54,10 +54,8 @@ class CMazeState {
s32 x90_targetRow;
bool x94_24_initialized : 1 = false;
#ifndef NDEBUG
std::vector<s32> m_path;
CLineRenderer m_renderer = {CLineRenderer::EPrimitiveMode::LineStrip, skMazeRows * skMazeCols, {}, true};
#endif
public:
CMazeState(s32 enterCol, s32 enterRow, s32 targetCol, s32 targetRow)
@ -66,9 +64,7 @@ public:
void Initialize();
void GenerateObstacles();
#ifndef NDEBUG
void DebugRender();
#endif
[[nodiscard]] SMazeCell& GetCell(u32 col, u32 row) {
#ifndef NDEBUG

View File

@ -54,7 +54,7 @@ void CScriptTrigger::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CS
}
}
CEntity::AcceptScriptMsg(msg, uid, mgr);
CActor::AcceptScriptMsg(msg, uid, mgr);
}
CScriptTrigger::CObjectTracker* CScriptTrigger::FindObject(TUniqueId id) {

2
hecl

@ -1 +1 @@
Subproject commit 660e2f3b3feb6eb3b7529dfdc0c3bdcee2a134eb
Subproject commit 892bc4a196aeea96bf9ba836126914d2d44667a2