From d3a358448642a181878b62aab4eb014cac13ab5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pe=C5=82ka?= Date: Thu, 5 Dec 2024 12:58:41 +0100 Subject: [PATCH] Added Physx stuff MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Pełka --- .../Clients/SensorDebugSystemComponent.cpp | 38 ++++++++++++------- .../Clients/SensorDebugSystemComponent.h | 8 +--- .../SensorDebugEditorSystemComponent.cpp | 6 ++- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/Gems/SensorDebug/Code/Source/Clients/SensorDebugSystemComponent.cpp b/Gems/SensorDebug/Code/Source/Clients/SensorDebugSystemComponent.cpp index 2da7e855..e13b9eef 100644 --- a/Gems/SensorDebug/Code/Source/Clients/SensorDebugSystemComponent.cpp +++ b/Gems/SensorDebug/Code/Source/Clients/SensorDebugSystemComponent.cpp @@ -168,7 +168,7 @@ namespace SensorDebug auto* physicsSystemConfigurationPtr = physicsSystem->GetConfiguration(); auto* physicsSystemConfiguration = azdynamic_cast(physicsSystemConfigurationPtr); AZ_Assert(physicsSystemConfiguration, "Invalid physics system configuration pointer, a new Physics system in O3DE????"); - physicsSystem->UpdateConfiguration(&ModifiedPhysXConfig, true); + physicsSystem->UpdateConfiguration(&m_modifiedPhysXConfig, true); } void SensorDebugSystemComponent::GetPhysXConfig() @@ -178,33 +178,45 @@ namespace SensorDebug auto* physicsSystemConfigurationPtr = physicsSystem->GetConfiguration(); auto* physicsSystemConfiguration = azdynamic_cast(physicsSystemConfigurationPtr); AZ_Assert(physicsSystemConfiguration, "Invalid physics system configuration pointer, a new Physics system in O3DE????"); - ModifiedPhysXConfig = *physicsSystemConfiguration; + m_modifiedPhysXConfig = *physicsSystemConfiguration; } + AZStd::string GetSecondAnimation(double value) + { + double part = value - AZStd::floor(value); + size_t numStars = static_cast(part * 60); + + AZStd::string anim (61, ' '); + numStars = AZStd::min(numStars, anim.length()); + for (size_t i = 0; i GetROSTimestamp(); + const auto ros2Intreface = ROS2::ROS2Interface::Get(); + auto ros2ts = ros2Intreface ? ROS2::ROS2Interface::Get()->GetROSTimestamp() : builtin_interfaces::msg::Time(); const float ros2tsSec = ros2ts.sec + ros2ts.nanosec / 1e9; - auto ros2Node = ROS2::ROS2Interface::Get()->GetNode(); - - auto nodeTime = ros2Node->now(); - const float ros2nodetsSec = nodeTime.seconds() + nodeTime.nanoseconds() / 1e9; + auto ros2Node = ros2Intreface ? ROS2::ROS2Interface::Get()->GetNode() : nullptr; + auto nodeTime = ros2Node ? ros2Node->now() : rclcpp::Time(0, 0); + const double ros2nodetsSec = nodeTime.seconds() + nodeTime.nanoseconds() / 1e9; auto timeSystem = AZ::Interface::Get(); const auto elapsedTime = timeSystem ? static_cast(timeSystem->GetElapsedTimeUs()) / 1e6 : 0.0; - ImGui::Text("Current ROS 2 time (Gem) : %f", ros2tsSec); - ImGui::Text("Current ROS 2 time (Node) : %f", ros2nodetsSec); - ImGui::Text("Current O3DE time : %f", elapsedTime); + ImGui::Text("Current ROS 2 time (Gem) : %f %s", ros2tsSec, GetSecondAnimation(ros2tsSec).c_str()); + ImGui::Text("Current ROS 2 time (Node) : %f %s", ros2nodetsSec, GetSecondAnimation(ros2nodetsSec).c_str()); + ImGui::Text("Current O3DE time : %f %s", elapsedTime, GetSecondAnimation(elapsedTime).c_str()); ImGui::Separator(); ImGui::Text("PhysX"); - ImGui::InputFloat("Fixed timestamp", &ModifiedPhysXConfig.m_fixedTimestep, 0.0f, 0.0f, "%.6f"); - ImGui::InputFloat("Max timestamp", &ModifiedPhysXConfig.m_maxTimestep, 0.0f, 0.0f, "%.6f"git a); + ImGui::InputFloat("Fixed timestamp", &m_modifiedPhysXConfig.m_fixedTimestep, 0.0f, 0.0f, "%.6f"); + ImGui::InputFloat("Max timestamp", &m_modifiedPhysXConfig.m_maxTimestep, 0.0f, 0.0f, "%.6f"); if (ImGui::Button("Update PhysX Config")) { UpdatePhysXConfig(); diff --git a/Gems/SensorDebug/Code/Source/Clients/SensorDebugSystemComponent.h b/Gems/SensorDebug/Code/Source/Clients/SensorDebugSystemComponent.h index 0b2ec7cd..58b59427 100644 --- a/Gems/SensorDebug/Code/Source/Clients/SensorDebugSystemComponent.h +++ b/Gems/SensorDebug/Code/Source/Clients/SensorDebugSystemComponent.h @@ -16,8 +16,7 @@ namespace SensorDebug { - // Hate to do this global, but we need to access this config after this component is deactivated and destroyed - static PhysX::PhysXSystemConfiguration ModifiedPhysXConfig; + class SensorDebugSystemComponent : public AZ::Component @@ -62,10 +61,7 @@ namespace SensorDebug AZStd::vector m_appFrequencies; float m_maxFPS = 60.0f; int m_historySize = 1000; - - - - AzPhysics::Scene* m_scene = nullptr; + PhysX::PhysXSystemConfiguration m_modifiedPhysXConfig; }; } // namespace SensorDebug diff --git a/Gems/SensorDebug/Code/Source/Tools/SensorDebugEditorSystemComponent.cpp b/Gems/SensorDebug/Code/Source/Tools/SensorDebugEditorSystemComponent.cpp index d3b257b1..631270fa 100644 --- a/Gems/SensorDebug/Code/Source/Tools/SensorDebugEditorSystemComponent.cpp +++ b/Gems/SensorDebug/Code/Source/Tools/SensorDebugEditorSystemComponent.cpp @@ -19,23 +19,25 @@ namespace SensorDebug void SensorDebugEditorSystemComponent::Activate() { - SensorDebugSystemComponent::Activate(); + AzToolsFramework::EditorEntityContextNotificationBus::Handler::BusConnect(); } void SensorDebugEditorSystemComponent::Deactivate() { AzToolsFramework::EditorEntityContextNotificationBus::Handler::BusDisconnect(); - SensorDebugSystemComponent::Deactivate(); + } void SensorDebugEditorSystemComponent::OnStartPlayInEditorBegin() { ClearSensors(); + SensorDebugSystemComponent::Activate(); } void SensorDebugEditorSystemComponent::OnStopPlayInEditor() { ClearSensors(); + SensorDebugSystemComponent::Deactivate(); } } // namespace SensorDebug