Skip to content

Commit d3a3584

Browse files
committed
Added Physx stuff
Signed-off-by: Michał Pełka <[email protected]>
1 parent cfe25f2 commit d3a3584

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

Gems/SensorDebug/Code/Source/Clients/SensorDebugSystemComponent.cpp

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ namespace SensorDebug
168168
auto* physicsSystemConfigurationPtr = physicsSystem->GetConfiguration();
169169
auto* physicsSystemConfiguration = azdynamic_cast<const PhysX::PhysXSystemConfiguration*>(physicsSystemConfigurationPtr);
170170
AZ_Assert(physicsSystemConfiguration, "Invalid physics system configuration pointer, a new Physics system in O3DE????");
171-
physicsSystem->UpdateConfiguration(&ModifiedPhysXConfig, true);
171+
physicsSystem->UpdateConfiguration(&m_modifiedPhysXConfig, true);
172172
}
173173

174174
void SensorDebugSystemComponent::GetPhysXConfig()
@@ -178,33 +178,45 @@ namespace SensorDebug
178178
auto* physicsSystemConfigurationPtr = physicsSystem->GetConfiguration();
179179
auto* physicsSystemConfiguration = azdynamic_cast<const PhysX::PhysXSystemConfiguration*>(physicsSystemConfigurationPtr);
180180
AZ_Assert(physicsSystemConfiguration, "Invalid physics system configuration pointer, a new Physics system in O3DE????");
181-
ModifiedPhysXConfig = *physicsSystemConfiguration;
181+
m_modifiedPhysXConfig = *physicsSystemConfiguration;
182182
}
183183

184+
AZStd::string GetSecondAnimation(double value)
185+
{
186+
double part = value - AZStd::floor(value);
187+
size_t numStars = static_cast<size_t>(part * 60);
188+
189+
AZStd::string anim (61, ' ');
190+
numStars = AZStd::min(numStars, anim.length());
191+
for (size_t i = 0; i <numStars; i++)
192+
{
193+
anim[i] = '*';
194+
}
195+
return anim;
196+
}
184197
void SensorDebugSystemComponent::OnImGuiUpdate()
185198
{
186199
ImGui::Begin("ROS2 SensorDebugger");
187200
ImGui::Separator();
188201
ImGui::Text("TimeyWimey Stuff");
189-
190-
auto ros2ts = ROS2::ROS2Interface::Get()->GetROSTimestamp();
202+
const auto ros2Intreface = ROS2::ROS2Interface::Get();
203+
auto ros2ts = ros2Intreface ? ROS2::ROS2Interface::Get()->GetROSTimestamp() : builtin_interfaces::msg::Time();
191204
const float ros2tsSec = ros2ts.sec + ros2ts.nanosec / 1e9;
192-
auto ros2Node = ROS2::ROS2Interface::Get()->GetNode();
193-
194-
auto nodeTime = ros2Node->now();
195-
const float ros2nodetsSec = nodeTime.seconds() + nodeTime.nanoseconds() / 1e9;
205+
auto ros2Node = ros2Intreface ? ROS2::ROS2Interface::Get()->GetNode() : nullptr;
206+
auto nodeTime = ros2Node ? ros2Node->now() : rclcpp::Time(0, 0);
207+
const double ros2nodetsSec = nodeTime.seconds() + nodeTime.nanoseconds() / 1e9;
196208

197209
auto timeSystem = AZ::Interface<AZ::ITime>::Get();
198210
const auto elapsedTime = timeSystem ? static_cast<double>(timeSystem->GetElapsedTimeUs()) / 1e6 : 0.0;
199211

200-
ImGui::Text("Current ROS 2 time (Gem) : %f", ros2tsSec);
201-
ImGui::Text("Current ROS 2 time (Node) : %f", ros2nodetsSec);
202-
ImGui::Text("Current O3DE time : %f", elapsedTime);
212+
ImGui::Text("Current ROS 2 time (Gem) : %f %s", ros2tsSec, GetSecondAnimation(ros2tsSec).c_str());
213+
ImGui::Text("Current ROS 2 time (Node) : %f %s", ros2nodetsSec, GetSecondAnimation(ros2nodetsSec).c_str());
214+
ImGui::Text("Current O3DE time : %f %s", elapsedTime, GetSecondAnimation(elapsedTime).c_str());
203215

204216
ImGui::Separator();
205217
ImGui::Text("PhysX");
206-
ImGui::InputFloat("Fixed timestamp", &ModifiedPhysXConfig.m_fixedTimestep, 0.0f, 0.0f, "%.6f");
207-
ImGui::InputFloat("Max timestamp", &ModifiedPhysXConfig.m_maxTimestep, 0.0f, 0.0f, "%.6f"git a);
218+
ImGui::InputFloat("Fixed timestamp", &m_modifiedPhysXConfig.m_fixedTimestep, 0.0f, 0.0f, "%.6f");
219+
ImGui::InputFloat("Max timestamp", &m_modifiedPhysXConfig.m_maxTimestep, 0.0f, 0.0f, "%.6f");
208220
if (ImGui::Button("Update PhysX Config"))
209221
{
210222
UpdatePhysXConfig();

Gems/SensorDebug/Code/Source/Clients/SensorDebugSystemComponent.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
namespace SensorDebug
1818
{
19-
// Hate to do this global, but we need to access this config after this component is deactivated and destroyed
20-
static PhysX::PhysXSystemConfiguration ModifiedPhysXConfig;
19+
2120

2221
class SensorDebugSystemComponent
2322
: public AZ::Component
@@ -62,10 +61,7 @@ namespace SensorDebug
6261
AZStd::vector<float> m_appFrequencies;
6362
float m_maxFPS = 60.0f;
6463
int m_historySize = 1000;
65-
66-
67-
68-
6964
AzPhysics::Scene* m_scene = nullptr;
65+
PhysX::PhysXSystemConfiguration m_modifiedPhysXConfig;
7066
};
7167
} // namespace SensorDebug

Gems/SensorDebug/Code/Source/Tools/SensorDebugEditorSystemComponent.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,25 @@ namespace SensorDebug
1919

2020
void SensorDebugEditorSystemComponent::Activate()
2121
{
22-
SensorDebugSystemComponent::Activate();
22+
2323
AzToolsFramework::EditorEntityContextNotificationBus::Handler::BusConnect();
2424
}
2525

2626
void SensorDebugEditorSystemComponent::Deactivate()
2727
{
2828
AzToolsFramework::EditorEntityContextNotificationBus::Handler::BusDisconnect();
29-
SensorDebugSystemComponent::Deactivate();
29+
3030
}
3131

3232
void SensorDebugEditorSystemComponent::OnStartPlayInEditorBegin()
3333
{
3434
ClearSensors();
35+
SensorDebugSystemComponent::Activate();
3536
}
3637

3738
void SensorDebugEditorSystemComponent::OnStopPlayInEditor()
3839
{
3940
ClearSensors();
41+
SensorDebugSystemComponent::Deactivate();
4042
}
4143
} // namespace SensorDebug

0 commit comments

Comments
 (0)