From 0781307c49ff9d38fa4c38f6f604b07555501589 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sat, 16 Jan 2021 19:33:03 -0800 Subject: [PATCH] Add debug rendering for CScriptPlatform (CVar: debugTool.drawPlatformCollision) --- Editor/ViewManager.cpp | 26 ++++++++++++++------------ Runtime/CStateManager.cpp | 8 +++++++- Runtime/World/CScriptPlatform.cpp | 8 ++++++++ Runtime/World/CScriptPlatform.hpp | 4 ++++ hecl | 2 +- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/Editor/ViewManager.cpp b/Editor/ViewManager.cpp index c6e46b4fa..5de3b657d 100644 --- a/Editor/ViewManager.cpp +++ b/Editor/ViewManager.cpp @@ -75,19 +75,21 @@ void ViewManager::TestGameView::think() { auto pt = std::div(igt, 3600); overlayText += fmt::format(FMT_STRING("PlayTime: {:02d}:{:02d}:{:02d}.{:03d}\n"), pt.quot, pt.rem / 60, pt.rem % 60, ms); - if (g_StateManager->GetCurrentArea() != nullptr) { - if (m_currentRoom != g_StateManager->GetCurrentArea()) { - m_currentRoom = static_cast(g_StateManager->GetCurrentArea()); - m_lastRoomTime = igt - m_currentRoomStart; - m_currentRoomStart = igt; - } - double currentRoomTime = igt - m_currentRoomStart; - u32 curFrames = std::round(u32(currentRoomTime * 60)); - u32 lastFrames = std::round(u32(m_lastRoomTime * 60)); - overlayText += fmt::format(FMT_STRING("Room Time:{:8.3f}/{:6d}| Last Room:{:8.3f}/{:6d}\n"), - currentRoomTime, curFrames, - m_lastRoomTime, lastFrames); + } + + if (g_StateManager->GetCurrentArea() != nullptr && m_cvarCommons.m_debugOverlayShowRoomTimer->toBoolean()) { + double igt = g_GameState->GetTotalPlayTime(); + if (m_currentRoom != g_StateManager->GetCurrentArea()) { + m_currentRoom = static_cast(g_StateManager->GetCurrentArea()); + m_lastRoomTime = igt - m_currentRoomStart; + m_currentRoomStart = igt; } + double currentRoomTime = igt - m_currentRoomStart; + u32 curFrames = std::round(u32(currentRoomTime * 60)); + u32 lastFrames = std::round(u32(m_lastRoomTime * 60)); + overlayText += fmt::format(FMT_STRING("Room Time:{:8.3f}/{:6d}| Last Room:{:8.3f}/{:6d}\n"), + currentRoomTime, curFrames, + m_lastRoomTime, lastFrames); } if (g_StateManager->Player() && m_cvarCommons.m_debugOverlayPlayerInfo->toBoolean()) { diff --git a/Runtime/CStateManager.cpp b/Runtime/CStateManager.cpp index 9dea24e3a..5bb1cdc8e 100644 --- a/Runtime/CStateManager.cpp +++ b/Runtime/CStateManager.cpp @@ -58,6 +58,7 @@ hecl::CVar* debugToolDrawAiPath = nullptr; hecl::CVar* debugToolDrawLighting = nullptr; hecl::CVar* debugToolDrawCollisionActors = nullptr; hecl::CVar* debugToolDrawMazePath = nullptr; +hecl::CVar* debugToolDrawPlatformCollision = nullptr; hecl::CVar* sm_logScripting = nullptr; } // namespace logvisor::Module LogModule("urde::CStateManager"); @@ -547,11 +548,12 @@ void CStateManager::DrawDebugStuff() const { // FIXME: Add proper globals for CVars if (debugToolDrawAiPath == nullptr || debugToolDrawCollisionActors == nullptr || debugToolDrawLighting == nullptr || - debugToolDrawMazePath == nullptr) { + debugToolDrawMazePath == nullptr || debugToolDrawPlatformCollision == 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"); + debugToolDrawPlatformCollision = hecl::CVarManager::instance()->findCVar("debugTool.drawPlatformCollision"); return; } @@ -574,6 +576,10 @@ void CStateManager::DrawDebugStuff() const { if (debugToolDrawCollisionActors->toBoolean()) { colAct->DebugDraw(); } + } else if (const TCastToPtr plat = ent) { + if (debugToolDrawPlatformCollision->toBoolean() && plat->GetActive()) { + plat->DebugDraw(); + } } } diff --git a/Runtime/World/CScriptPlatform.cpp b/Runtime/World/CScriptPlatform.cpp index 188a3d7e4..9cfeff8da 100644 --- a/Runtime/World/CScriptPlatform.cpp +++ b/Runtime/World/CScriptPlatform.cpp @@ -560,4 +560,12 @@ zeus::CQuaternion CScriptPlatform::Move(float dt, CStateManager& mgr) { return zeus::CQuaternion(); } +void CScriptPlatform::DebugDraw() { + if (!m_boxFilter) { + m_boxFilter = {CAABoxShader()}; + } + + m_boxFilter->setAABB(*GetTouchBounds()); + m_boxFilter->draw({1.f, 0.f, 1.f, .5f}); +} } // namespace urde diff --git a/Runtime/World/CScriptPlatform.hpp b/Runtime/World/CScriptPlatform.hpp index c4020896e..fad6da894 100644 --- a/Runtime/World/CScriptPlatform.hpp +++ b/Runtime/World/CScriptPlatform.hpp @@ -12,6 +12,7 @@ #include "Runtime/World/CDamageVulnerability.hpp" #include "Runtime/World/CHealthInfo.hpp" #include "Runtime/World/CPhysicsActor.hpp" +#include "Runtime/Graphics/Shaders/CAABoxShader.hpp" #include #include @@ -72,6 +73,7 @@ class CScriptPlatform : public CPhysicsActor { static rstl::reserved_vector BuildNearListFromRiders(CStateManager& mgr, const std::vector& movedRiders); + std::optional m_boxFilter; public: CScriptPlatform(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const CActorParameters& actParms, const zeus::CAABox& aabb, float speed, @@ -114,5 +116,7 @@ public: virtual void SplashThink(const zeus::CAABox&, const CFluidPlane&, float, CStateManager&) const; virtual zeus::CQuaternion Move(float, CStateManager&); + + void DebugDraw(); }; } // namespace urde diff --git a/hecl b/hecl index 892bc4a19..4b30bc1ff 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit 892bc4a196aeea96bf9ba836126914d2d44667a2 +Subproject commit 4b30bc1ffe6499755b2d1c219cee01ef3e18848d