From ba964932b701dbee9bd7ceda1006c309b71e63ac Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Sat, 19 Jul 2025 22:08:18 -0700 Subject: [PATCH] feat: debug for all physics components and fix inspect by ldf key (#1848) --- dGame/EntityManager.cpp | 2 + .../ControllablePhysicsComponent.cpp | 56 +++++++++++++++++++ .../ControllablePhysicsComponent.h | 14 +++-- .../HavokVehiclePhysicsComponent.cpp | 34 +++++++++++ .../HavokVehiclePhysicsComponent.h | 2 + dGame/dComponents/PhantomPhysicsComponent.cpp | 43 ++++++++++++++ dGame/dComponents/PhantomPhysicsComponent.h | 4 +- dGame/dComponents/PhysicsComponent.cpp | 26 ++++++++- dGame/dComponents/PhysicsComponent.h | 6 ++ .../RigidbodyPhantomPhysicsComponent.cpp | 13 ++++- .../RigidbodyPhantomPhysicsComponent.h | 2 + dGame/dComponents/SimplePhysicsComponent.cpp | 21 +++++++ dGame/dComponents/SimplePhysicsComponent.h | 2 + dGame/dGameMessages/GameMessages.h | 1 + .../SlashCommands/DEVGMCommands.cpp | 1 + 15 files changed, 217 insertions(+), 10 deletions(-) diff --git a/dGame/EntityManager.cpp b/dGame/EntityManager.cpp index 36eabb63..762529f3 100644 --- a/dGame/EntityManager.cpp +++ b/dGame/EntityManager.cpp @@ -281,6 +281,8 @@ std::vector EntityManager::GetEntitiesByComponent(const eReplicaCompone withComp.push_back(entity); } + } else { + for (auto* const entity : m_Entities | std::views::values) withComp.push_back(entity); } return withComp; } diff --git a/dGame/dComponents/ControllablePhysicsComponent.cpp b/dGame/dComponents/ControllablePhysicsComponent.cpp index 1a05020b..ccc5a7e2 100644 --- a/dGame/dComponents/ControllablePhysicsComponent.cpp +++ b/dGame/dComponents/ControllablePhysicsComponent.cpp @@ -14,8 +14,12 @@ #include "dZoneManager.h" #include "LevelProgressionComponent.h" #include "eStateChangeType.h" +#include "StringifiedEnum.h" +#include "Amf3.h" ControllablePhysicsComponent::ControllablePhysicsComponent(Entity* entity, int32_t componentId) : PhysicsComponent(entity, componentId) { + RegisterMsg(MessageType::Game::GET_OBJECT_REPORT_INFO, this, &ControllablePhysicsComponent::OnGetObjectReportInfo); + m_Velocity = {}; m_AngularVelocity = {}; m_InJetpackMode = false; @@ -354,3 +358,55 @@ void ControllablePhysicsComponent::SetStunImmunity( bImmuneToStunUseItem ); } + +bool ControllablePhysicsComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { + PhysicsComponent::OnGetObjectReportInfo(msg); + auto& reportInfo = static_cast(msg); + auto& info = reportInfo.subCategory->PushDebug("Controllable Info"); + + auto& vel = info.PushDebug("Velocity"); + vel.PushDebug("x") = m_Velocity.x; + vel.PushDebug("y") = m_Velocity.y; + vel.PushDebug("z") = m_Velocity.z; + + auto& angularVelocity = info.PushDebug("Angular Velocity"); + angularVelocity.PushDebug("x") = m_AngularVelocity.x; + angularVelocity.PushDebug("y") = m_AngularVelocity.y; + angularVelocity.PushDebug("z") = m_AngularVelocity.z; + + info.PushDebug("Is On Ground") = m_IsOnGround; + info.PushDebug("Is On Rail") = m_IsOnRail; + info.PushDebug("Is In Jetpack Mode") = m_InJetpackMode; + info.PushDebug("Is Jetpack Flying") = m_JetpackFlying; + info.PushDebug("Is Bypassing Jetpack Checks") = m_JetpackBypassChecks; + info.PushDebug("Jetpack Effect ID") = m_JetpackEffectID; + info.PushDebug("Speed Multiplier") = m_SpeedMultiplier; + info.PushDebug("Gravity Scale") = m_GravityScale; + info.PushDebug("Is Static") = m_Static; + + auto& pickupRadii = info.PushDebug("Active Pickup Radius Scales"); + for (const auto& scale : m_ActivePickupRadiusScales) { + pickupRadii.PushDebug(std::to_string(scale)) = ""; + } + + info.PushDebug("Largest Pickup Radius") = m_PickupRadius; + info.PushDebug("Is Teleporting") = m_IsTeleporting; + + auto& activeSpeedBoosts = info.PushDebug("Active Speed Boosts"); + for (const auto& boost : m_ActiveSpeedBoosts) { + activeSpeedBoosts.PushDebug(std::to_string(boost)) = ""; + } + + info.PushDebug("Speed Boost") = m_SpeedBoost; + info.PushDebug("Is In Bubble") = m_IsInBubble; + info.PushDebug("Bubble Type") = StringifiedEnum::ToString(m_BubbleType).data(); + info.PushDebug("Special Anims") = m_SpecialAnims; + info.PushDebug("Immune To Stun Attack Count") = m_ImmuneToStunAttackCount; + info.PushDebug("Immune To Stun Equip Count") = m_ImmuneToStunEquipCount; + info.PushDebug("Immune To Stun Interact Count") = m_ImmuneToStunInteractCount; + info.PushDebug("Immune To Stun Jump Count") = m_ImmuneToStunJumpCount; + info.PushDebug("Immune To Stun Move Count") = m_ImmuneToStunMoveCount; + info.PushDebug("Immune To Stun Turn Count") = m_ImmuneToStunTurnCount; + info.PushDebug("Immune To Stun UseItem Count") = m_ImmuneToStunUseItemCount; + return true; +} diff --git a/dGame/dComponents/ControllablePhysicsComponent.h b/dGame/dComponents/ControllablePhysicsComponent.h index 31a6bb30..9a90628d 100644 --- a/dGame/dComponents/ControllablePhysicsComponent.h +++ b/dGame/dComponents/ControllablePhysicsComponent.h @@ -1,16 +1,18 @@ #ifndef CONTROLLABLEPHYSICSCOMPONENT_H #define CONTROLLABLEPHYSICSCOMPONENT_H +#include "PhysicsComponent.h" +#include "eReplicaComponentType.h" #include "dCommonVars.h" #include "RakNetTypes.h" #include "NiPoint3.h" #include "NiQuaternion.h" -#include "tinyxml2.h" -#include "PhysicsComponent.h" #include "dpCollisionChecks.h" -#include "PhantomPhysicsComponent.h" #include "eBubbleType.h" -#include "eReplicaComponentType.h" + +namespace tinyxml2 { + class XMLDocument; +} class Entity; class dpEntity; @@ -281,6 +283,8 @@ public: const bool GetImmuneToStunUseItem() { return m_ImmuneToStunUseItemCount > 0;}; private: + + bool OnGetObjectReportInfo(GameMessages::GameMsg& msg); /** * The entity that owns this component */ @@ -374,7 +378,7 @@ private: /** * The active speed boost for this entity */ - float m_SpeedBoost; + float m_SpeedBoost = 500.0f; /* * If Bubble info is dirty diff --git a/dGame/dComponents/HavokVehiclePhysicsComponent.cpp b/dGame/dComponents/HavokVehiclePhysicsComponent.cpp index e977f952..50638880 100644 --- a/dGame/dComponents/HavokVehiclePhysicsComponent.cpp +++ b/dGame/dComponents/HavokVehiclePhysicsComponent.cpp @@ -1,7 +1,10 @@ #include "HavokVehiclePhysicsComponent.h" #include "EntityManager.h" +#include "Amf3.h" HavokVehiclePhysicsComponent::HavokVehiclePhysicsComponent(Entity* parent, int32_t componentId) : PhysicsComponent(parent, componentId) { + RegisterMsg(MessageType::Game::GET_OBJECT_REPORT_INFO, this, &HavokVehiclePhysicsComponent::OnGetObjectReportInfo); + m_Velocity = NiPoint3Constant::ZERO; m_AngularVelocity = NiPoint3Constant::ZERO; m_IsOnGround = true; @@ -98,3 +101,34 @@ void HavokVehiclePhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bo outBitStream.Write0(); } + +bool HavokVehiclePhysicsComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { + PhysicsComponent::OnGetObjectReportInfo(msg); + auto& reportInfo = static_cast(msg); + if (!reportInfo.subCategory) { + return false; + } + + auto& info = reportInfo.subCategory->PushDebug("Havok Vehicle Physics Info"); + + auto& velocity = info.PushDebug("Velocity"); + velocity.PushDebug("x") = m_Velocity.x; + velocity.PushDebug("y") = m_Velocity.y; + velocity.PushDebug("z") = m_Velocity.z; + + auto& angularVelocity = info.PushDebug("Angular Velocity"); + angularVelocity.PushDebug("x") = m_AngularVelocity.x; + angularVelocity.PushDebug("y") = m_AngularVelocity.y; + angularVelocity.PushDebug("z") = m_AngularVelocity.z; + + info.PushDebug("Is On Ground") = m_IsOnGround; + info.PushDebug("Is On Rail") = m_IsOnRail; + info.PushDebug("End Behavior") = m_EndBehavior; + + auto& remoteInputInfo = info.PushDebug("Remote Input Info"); + remoteInputInfo.PushDebug("Remote Input X") = m_RemoteInputInfo.m_RemoteInputX; + remoteInputInfo.PushDebug("Remote Input Y") = m_RemoteInputInfo.m_RemoteInputY; + remoteInputInfo.PushDebug("Is Powersliding") = m_RemoteInputInfo.m_IsPowersliding; + remoteInputInfo.PushDebug("Is Modified") = m_RemoteInputInfo.m_IsModified; + return true; +} diff --git a/dGame/dComponents/HavokVehiclePhysicsComponent.h b/dGame/dComponents/HavokVehiclePhysicsComponent.h index ad6087a7..5e4a1a65 100644 --- a/dGame/dComponents/HavokVehiclePhysicsComponent.h +++ b/dGame/dComponents/HavokVehiclePhysicsComponent.h @@ -68,6 +68,8 @@ public: void SetRemoteInputInfo(const RemoteInputInfo&); private: + bool OnGetObjectReportInfo(GameMessages::GameMsg& msg); + NiPoint3 m_Velocity; NiPoint3 m_AngularVelocity; diff --git a/dGame/dComponents/PhantomPhysicsComponent.cpp b/dGame/dComponents/PhantomPhysicsComponent.cpp index be7fe774..531a6e77 100644 --- a/dGame/dComponents/PhantomPhysicsComponent.cpp +++ b/dGame/dComponents/PhantomPhysicsComponent.cpp @@ -21,6 +21,7 @@ #include "CDPhysicsComponentTable.h" #include "dServer.h" #include "EntityInfo.h" +#include "Amf3.h" #include "dpWorld.h" #include "dpEntity.h" @@ -28,6 +29,8 @@ #include "dpShapeSphere.h" PhantomPhysicsComponent::PhantomPhysicsComponent(Entity* parent, int32_t componentId) : PhysicsComponent(parent, componentId) { + RegisterMsg(MessageType::Game::GET_OBJECT_REPORT_INFO, this, &PhantomPhysicsComponent::OnGetObjectReportInfo); + m_Position = m_Parent->GetDefaultPosition(); m_Rotation = m_Parent->GetDefaultRotation(); m_Scale = m_Parent->GetDefaultScale(); @@ -238,3 +241,43 @@ void PhantomPhysicsComponent::SetRotation(const NiQuaternion& rot) { PhysicsComponent::SetRotation(rot); if (m_dpEntity) m_dpEntity->SetRotation(rot); } + +bool PhantomPhysicsComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { + PhysicsComponent::OnGetObjectReportInfo(msg); + auto& reportInfo = static_cast(msg); + if (!reportInfo.subCategory) { + return false; + } + auto& info = reportInfo.subCategory->PushDebug("Phantom Physics Info"); + info.PushDebug("Scale") = m_Scale; + info.PushDebug("Is Physics Effect Active") = m_IsPhysicsEffectActive; + info.PushDebug("Effect Type") = static_cast(m_EffectType); + info.PushDebug("Directional Multiplier") = m_DirectionalMultiplier; + info.PushDebug("Is Directional") = m_IsDirectional; + auto& direction = info.PushDebug("Direction"); + direction.PushDebug("x") = m_Direction.x; + direction.PushDebug("y") = m_Direction.y; + direction.PushDebug("z") = m_Direction.z; + + if (m_MinMax) { + auto& minMaxInfo = info.PushDebug("Min Max Info"); + minMaxInfo.PushDebug("Min") = m_Min; + minMaxInfo.PushDebug("Max") = m_Max; + } + + if (m_IsRespawnVolume) { + auto& respawnInfo = info.PushDebug("Respawn Info"); + respawnInfo.PushDebug("Is Respawn Volume") = m_IsRespawnVolume; + auto& respawnPos = respawnInfo.PushDebug("Respawn Position"); + respawnPos.PushDebug("x") = m_RespawnPos.x; + respawnPos.PushDebug("y") = m_RespawnPos.y; + respawnPos.PushDebug("z") = m_RespawnPos.z; + auto& respawnRot = respawnInfo.PushDebug("Respawn Rotation"); + respawnRot.PushDebug("w") = m_RespawnRot.w; + respawnRot.PushDebug("x") = m_RespawnRot.x; + respawnRot.PushDebug("y") = m_RespawnRot.y; + respawnRot.PushDebug("z") = m_RespawnRot.z; + } + + return true; +} diff --git a/dGame/dComponents/PhantomPhysicsComponent.h b/dGame/dComponents/PhantomPhysicsComponent.h index cd54587b..ce8113ec 100644 --- a/dGame/dComponents/PhantomPhysicsComponent.h +++ b/dGame/dComponents/PhantomPhysicsComponent.h @@ -9,8 +9,6 @@ #include "NiQuaternion.h" #include "BitStream.h" #include -#include "CppScripts.h" -#include "InvalidScript.h" #include "eReplicaComponentType.h" #include "PhysicsComponent.h" @@ -118,6 +116,8 @@ public: void SetMax(uint32_t max); private: + bool OnGetObjectReportInfo(GameMessages::GameMsg& msg); + /** * A scale to apply to the size of the physics object */ diff --git a/dGame/dComponents/PhysicsComponent.cpp b/dGame/dComponents/PhysicsComponent.cpp index d0401f50..e7e87287 100644 --- a/dGame/dComponents/PhysicsComponent.cpp +++ b/dGame/dComponents/PhysicsComponent.cpp @@ -13,6 +13,7 @@ #include "dpShapeSphere.h" #include "EntityInfo.h" +#include "Amf3.h" PhysicsComponent::PhysicsComponent(Entity* parent, int32_t componentId) : Component(parent) { m_Position = NiPoint3Constant::ZERO; @@ -97,9 +98,9 @@ dpEntity* PhysicsComponent::CreatePhysicsEntity(eReplicaComponentType type) { } else if (info->physicsAsset == "env\\GFTrack_DeathVolume2_RoadGaps.hkx") { toReturn = new dpEntity(m_Parent->GetObjectID(), 48.386536f, 50.363434f, 259.361755f); } */ else { - // LOG_DEBUG("This one is supposed to have %s", info->physicsAsset.c_str()); + // LOG_DEBUG("This one is supposed to have %s", info->physicsAsset.c_str()); - //add fallback cube: + //add fallback cube: toReturn = new dpEntity(m_Parent->GetObjectID(), 2.0f, 2.0f, 2.0f); } return toReturn; @@ -243,3 +244,24 @@ void PhysicsComponent::SpawnVertices(dpEntity* entity) const { Game::entityManager->ConstructEntity(newEntity); } } + +bool PhysicsComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { + auto& reportInfo = static_cast(msg); + auto& info = reportInfo.info->PushDebug("Physics"); + reportInfo.subCategory = &info; + + auto& pos = info.PushDebug("Position"); + pos.PushDebug("x") = m_Position.x; + pos.PushDebug("y") = m_Position.y; + pos.PushDebug("z") = m_Position.z; + + auto& rot = info.PushDebug("Rotation"); + rot.PushDebug("w") = m_Rotation.w; + rot.PushDebug("x") = m_Rotation.x; + rot.PushDebug("y") = m_Rotation.y; + rot.PushDebug("z") = m_Rotation.z; + + info.PushDebug("CollisionGroup") = m_CollisionGroup; + + return true; +} diff --git a/dGame/dComponents/PhysicsComponent.h b/dGame/dComponents/PhysicsComponent.h index 4d93f018..f80a51dd 100644 --- a/dGame/dComponents/PhysicsComponent.h +++ b/dGame/dComponents/PhysicsComponent.h @@ -5,6 +5,10 @@ #include "NiPoint3.h" #include "NiQuaternion.h" +namespace GameMessages { + struct GetObjectReportInfo; +}; + namespace Raknet { class BitStream; }; @@ -29,6 +33,8 @@ public: int32_t GetCollisionGroup() const noexcept { return m_CollisionGroup; } void SetCollisionGroup(int32_t group) noexcept { m_CollisionGroup = group; } protected: + bool OnGetObjectReportInfo(GameMessages::GameMsg& msg); + dpEntity* CreatePhysicsEntity(eReplicaComponentType type); dpEntity* CreatePhysicsLnv(const float scale, const eReplicaComponentType type) const; diff --git a/dGame/dComponents/RigidbodyPhantomPhysicsComponent.cpp b/dGame/dComponents/RigidbodyPhantomPhysicsComponent.cpp index d0f8caeb..60b816f8 100644 --- a/dGame/dComponents/RigidbodyPhantomPhysicsComponent.cpp +++ b/dGame/dComponents/RigidbodyPhantomPhysicsComponent.cpp @@ -10,9 +10,12 @@ #include "dpWorld.h" #include "dpShapeBox.h" #include "dpShapeSphere.h" -#include"EntityInfo.h" +#include "EntityInfo.h" +#include "Amf3.h" RigidbodyPhantomPhysicsComponent::RigidbodyPhantomPhysicsComponent(Entity* parent, int32_t componentId) : PhysicsComponent(parent, componentId) { + RegisterMsg(MessageType::Game::GET_OBJECT_REPORT_INFO, this, &RigidbodyPhantomPhysicsComponent::OnGetObjectReportInfo); + m_Position = m_Parent->GetDefaultPosition(); m_Rotation = m_Parent->GetDefaultRotation(); m_Scale = m_Parent->GetDefaultScale(); @@ -55,3 +58,11 @@ void RigidbodyPhantomPhysicsComponent::SpawnVertices() const { } PhysicsComponent::SpawnVertices(m_dpEntity); } + +bool RigidbodyPhantomPhysicsComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { + PhysicsComponent::OnGetObjectReportInfo(msg); + auto& reportInfo = static_cast(msg); + auto& info = reportInfo.subCategory->PushDebug("Rigidbody Phantom Info"); + info.PushDebug("Scale") = m_Scale; + return true; +} diff --git a/dGame/dComponents/RigidbodyPhantomPhysicsComponent.h b/dGame/dComponents/RigidbodyPhantomPhysicsComponent.h index e7ce93d6..1ad19846 100644 --- a/dGame/dComponents/RigidbodyPhantomPhysicsComponent.h +++ b/dGame/dComponents/RigidbodyPhantomPhysicsComponent.h @@ -29,6 +29,8 @@ public: void SpawnVertices() const; private: + bool OnGetObjectReportInfo(GameMessages::GameMsg& msg); + float m_Scale{}; dpEntity* m_dpEntity{}; diff --git a/dGame/dComponents/SimplePhysicsComponent.cpp b/dGame/dComponents/SimplePhysicsComponent.cpp index 64034412..3651c10f 100644 --- a/dGame/dComponents/SimplePhysicsComponent.cpp +++ b/dGame/dComponents/SimplePhysicsComponent.cpp @@ -12,8 +12,12 @@ #include "CDPhysicsComponentTable.h" #include "Entity.h" +#include "StringifiedEnum.h" +#include "Amf3.h" SimplePhysicsComponent::SimplePhysicsComponent(Entity* parent, int32_t componentID) : PhysicsComponent(parent, componentID) { + RegisterMsg(MessageType::Game::GET_OBJECT_REPORT_INFO, this, &SimplePhysicsComponent::OnGetObjectReportInfo); + m_Position = m_Parent->GetDefaultPosition(); m_Rotation = m_Parent->GetDefaultRotation(); @@ -71,3 +75,20 @@ void SimplePhysicsComponent::SetPhysicsMotionState(uint32_t value) { m_DirtyPhysicsMotionState = m_PhysicsMotionState != value; m_PhysicsMotionState = value; } + +bool SimplePhysicsComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) { + PhysicsComponent::OnGetObjectReportInfo(msg); + auto& reportInfo = static_cast(msg); + auto& info = reportInfo.subCategory->PushDebug("Simple Physics Info"); + auto& velocity = info.PushDebug("Velocity"); + velocity.PushDebug("x") = m_Velocity.x; + velocity.PushDebug("y") = m_Velocity.y; + velocity.PushDebug("z") = m_Velocity.z; + auto& angularVelocity = info.PushDebug("Angular Velocity"); + angularVelocity.PushDebug("x") = m_AngularVelocity.x; + angularVelocity.PushDebug("y") = m_AngularVelocity.y; + angularVelocity.PushDebug("z") = m_AngularVelocity.z; + info.PushDebug("Physics Motion State") = m_PhysicsMotionState; + info.PushDebug("Climbable Type") = StringifiedEnum::ToString(m_ClimbableType).data(); + return true; +} diff --git a/dGame/dComponents/SimplePhysicsComponent.h b/dGame/dComponents/SimplePhysicsComponent.h index e669dea8..f8db9197 100644 --- a/dGame/dComponents/SimplePhysicsComponent.h +++ b/dGame/dComponents/SimplePhysicsComponent.h @@ -86,6 +86,8 @@ public: void SetClimbableType(const eClimbableType& value) { m_ClimbableType = value; } private: + bool OnGetObjectReportInfo(GameMessages::GameMsg& msg); + /** * The current velocity of the entity */ diff --git a/dGame/dGameMessages/GameMessages.h b/dGame/dGameMessages/GameMessages.h index 20d0eb82..83f7ea9f 100644 --- a/dGame/dGameMessages/GameMessages.h +++ b/dGame/dGameMessages/GameMessages.h @@ -791,6 +791,7 @@ namespace GameMessages { struct GetObjectReportInfo : public GameMsg { AMFArrayValue* info{}; + AMFArrayValue* subCategory{}; bool bVerbose{}; GetObjectReportInfo() : GameMsg(MessageType::Game::GET_OBJECT_REPORT_INFO, eGameMasterLevel::DEVELOPER) {} diff --git a/dGame/dUtilities/SlashCommands/DEVGMCommands.cpp b/dGame/dUtilities/SlashCommands/DEVGMCommands.cpp index 34ebf982..8b2ffe17 100644 --- a/dGame/dUtilities/SlashCommands/DEVGMCommands.cpp +++ b/dGame/dUtilities/SlashCommands/DEVGMCommands.cpp @@ -44,6 +44,7 @@ #include "SkillComponent.h" #include "TriggerComponent.h" #include "RigidbodyPhantomPhysicsComponent.h" +#include "PhantomPhysicsComponent.h" // Enums #include "eGameMasterLevel.h"