|
@@ -14,6 +14,7 @@
|
|
#include <AzCore/Settings/SettingsRegistry.h>
|
|
#include <AzCore/Settings/SettingsRegistry.h>
|
|
#include <AzFramework/Components/ConsoleBus.h>
|
|
#include <AzFramework/Components/ConsoleBus.h>
|
|
#include <AzFramework/Physics/PhysicsSystem.h>
|
|
#include <AzFramework/Physics/PhysicsSystem.h>
|
|
|
|
+#include <DebugDraw/DebugDrawBus.h>
|
|
#include <SimulationInterfaces/SimulationFeaturesAggregatorRequestBus.h>
|
|
#include <SimulationInterfaces/SimulationFeaturesAggregatorRequestBus.h>
|
|
#include <SimulationInterfaces/SimulationInterfacesTypeIds.h>
|
|
#include <SimulationInterfaces/SimulationInterfacesTypeIds.h>
|
|
#include <simulation_interfaces/msg/simulator_features.hpp>
|
|
#include <simulation_interfaces/msg/simulator_features.hpp>
|
|
@@ -22,8 +23,27 @@ namespace SimulationInterfaces
|
|
{
|
|
{
|
|
namespace
|
|
namespace
|
|
{
|
|
{
|
|
|
|
+
|
|
|
|
+ const AZStd::unordered_map<SimulationState, AZStd::string> SimulationStateToString = {
|
|
|
|
+ { simulation_interfaces::msg::SimulationState::STATE_PAUSED, "STATE_PAUSED" },
|
|
|
|
+ { simulation_interfaces::msg::SimulationState::STATE_PLAYING, "STATE_PLAYING" },
|
|
|
|
+ { simulation_interfaces::msg::SimulationState::STATE_QUITTING, "STATE_QUITTING" },
|
|
|
|
+ { simulation_interfaces::msg::SimulationState::STATE_STOPPED, "STATE_STOPPED" }
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ constexpr AZStd::string_view PrintStateName = "/SimulationInterfaces/PrintStateNameInGui";
|
|
constexpr AZStd::string_view StartInStoppedStateKey = "/SimulationInterfaces/StartInStoppedState";
|
|
constexpr AZStd::string_view StartInStoppedStateKey = "/SimulationInterfaces/StartInStoppedState";
|
|
|
|
|
|
|
|
+ AZStd::string GetStateName(SimulationState state)
|
|
|
|
+ {
|
|
|
|
+ auto it = SimulationStateToString.find(state);
|
|
|
|
+ if (it != SimulationStateToString.end())
|
|
|
|
+ {
|
|
|
|
+ return it->second;
|
|
|
|
+ }
|
|
|
|
+ return AZStd::string::format("Unknown state: %d", aznumeric_cast<int>(state));
|
|
|
|
+ }
|
|
|
|
+
|
|
bool StartInStoppedState()
|
|
bool StartInStoppedState()
|
|
{
|
|
{
|
|
AZ::SettingsRegistryInterface* settingsRegistry = AZ::SettingsRegistry::Get();
|
|
AZ::SettingsRegistryInterface* settingsRegistry = AZ::SettingsRegistry::Get();
|
|
@@ -32,6 +52,15 @@ namespace SimulationInterfaces
|
|
settingsRegistry->Get(output, StartInStoppedStateKey);
|
|
settingsRegistry->Get(output, StartInStoppedStateKey);
|
|
return output;
|
|
return output;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ bool PrintStateNameInGui()
|
|
|
|
+ {
|
|
|
|
+ AZ::SettingsRegistryInterface* settingsRegistry = AZ::SettingsRegistry::Get();
|
|
|
|
+ AZ_Assert(settingsRegistry, "Settings Registry is not available");
|
|
|
|
+ bool output = true;
|
|
|
|
+ settingsRegistry->Get(output, PrintStateName);
|
|
|
|
+ return output;
|
|
|
|
+ }
|
|
} // namespace
|
|
} // namespace
|
|
|
|
|
|
AZ_COMPONENT_IMPL(SimulationManager, "SimulationManager", SimulationManagerTypeId);
|
|
AZ_COMPONENT_IMPL(SimulationManager, "SimulationManager", SimulationManagerTypeId);
|
|
@@ -63,6 +92,7 @@ namespace SimulationInterfaces
|
|
void SimulationManager::GetDependentServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& dependent)
|
|
void SimulationManager::GetDependentServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& dependent)
|
|
{
|
|
{
|
|
dependent.push_back(AZ_CRC_CE("SimulationFeaturesAggregator"));
|
|
dependent.push_back(AZ_CRC_CE("SimulationFeaturesAggregator"));
|
|
|
|
+ dependent.push_back(AZ_CRC_CE("DebugDrawTextService"));
|
|
}
|
|
}
|
|
|
|
|
|
SimulationManager::SimulationManager()
|
|
SimulationManager::SimulationManager()
|
|
@@ -112,6 +142,10 @@ namespace SimulationInterfaces
|
|
simulation_interfaces::msg::SimulatorFeatures::STEP_SIMULATION_ACTION,
|
|
simulation_interfaces::msg::SimulatorFeatures::STEP_SIMULATION_ACTION,
|
|
simulation_interfaces::msg::SimulatorFeatures::SIMULATION_STATE_SETTING,
|
|
simulation_interfaces::msg::SimulatorFeatures::SIMULATION_STATE_SETTING,
|
|
simulation_interfaces::msg::SimulatorFeatures::SIMULATION_STATE_GETTING });
|
|
simulation_interfaces::msg::SimulatorFeatures::SIMULATION_STATE_GETTING });
|
|
|
|
+ if (PrintStateNameInGui())
|
|
|
|
+ {
|
|
|
|
+ AZ::TickBus::Handler::BusConnect();
|
|
|
|
+ }
|
|
AZ::SystemTickBus::QueueFunction(
|
|
AZ::SystemTickBus::QueueFunction(
|
|
[this]()
|
|
[this]()
|
|
{
|
|
{
|
|
@@ -121,6 +155,7 @@ namespace SimulationInterfaces
|
|
|
|
|
|
void SimulationManager::Deactivate()
|
|
void SimulationManager::Deactivate()
|
|
{
|
|
{
|
|
|
|
+ AZ::TickBus::Handler::BusDisconnect();
|
|
SimulationManagerRequestBus::Handler::BusDisconnect();
|
|
SimulationManagerRequestBus::Handler::BusDisconnect();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -246,11 +281,24 @@ namespace SimulationInterfaces
|
|
"Simulation is already in requested state, transition unecessary"));
|
|
"Simulation is already in requested state, transition unecessary"));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (IsTransitionForbiddenInEditor(stateToSet))
|
|
|
|
+ {
|
|
|
|
+ const auto stateToSetName = GetStateName(stateToSet);
|
|
|
|
+ const auto currentStateName = GetStateName(m_simulationState);
|
|
|
|
+ return AZ::Failure(FailedResult(
|
|
|
|
+ simulation_interfaces::srv::SetSimulationState::Response::INCORRECT_TRANSITION,
|
|
|
|
+ AZStd::string::format(
|
|
|
|
+ "Requested transition (%s -> %s) is forbidden in the Editor. It is available in GameLauncher.",
|
|
|
|
+ currentStateName.c_str(),
|
|
|
|
+ stateToSetName.c_str())));
|
|
|
|
+ }
|
|
if (IsTransitionForbidden(stateToSet))
|
|
if (IsTransitionForbidden(stateToSet))
|
|
{
|
|
{
|
|
|
|
+ const auto stateToSetName = GetStateName(stateToSet);
|
|
|
|
+ const auto currentStateName = GetStateName(m_simulationState);
|
|
return AZ::Failure(FailedResult(
|
|
return AZ::Failure(FailedResult(
|
|
simulation_interfaces::srv::SetSimulationState::Response::INCORRECT_TRANSITION,
|
|
simulation_interfaces::srv::SetSimulationState::Response::INCORRECT_TRANSITION,
|
|
- AZStd::string::format("Requested transition (%d -> %d) is forbidden", m_simulationState, stateToSet)));
|
|
|
|
|
|
+ AZStd::string::format("Requested transition (%s -> %s) is forbidden", currentStateName.c_str(), stateToSetName.c_str())));
|
|
}
|
|
}
|
|
|
|
|
|
switch (stateToSet)
|
|
switch (stateToSet)
|
|
@@ -299,6 +347,23 @@ namespace SimulationInterfaces
|
|
return AZ::Success();
|
|
return AZ::Success();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ bool SimulationManager::IsTransitionForbiddenInEditor(SimulationState requestedState)
|
|
|
|
+ {
|
|
|
|
+ // in the Editor we cannot reload level, so going to STOPPED state is forbidden, we cannot quit the editor so going to QUITTING
|
|
|
|
+ // state is forbidden
|
|
|
|
+ AZ::ApplicationTypeQuery appType;
|
|
|
|
+ AZ::ComponentApplicationBus::Broadcast(&AZ::ComponentApplicationBus::Events::QueryApplicationType, appType);
|
|
|
|
+ if (appType.IsValid() && !appType.IsGame())
|
|
|
|
+ {
|
|
|
|
+ if (requestedState == simulation_interfaces::msg::SimulationState::STATE_STOPPED ||
|
|
|
|
+ requestedState == simulation_interfaces::msg::SimulationState::STATE_QUITTING)
|
|
|
|
+ {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
bool SimulationManager::IsTransitionForbidden(SimulationState requestedState)
|
|
bool SimulationManager::IsTransitionForbidden(SimulationState requestedState)
|
|
{
|
|
{
|
|
AZStd::pair<SimulationState, SimulationState> desireTransition{ m_simulationState, requestedState };
|
|
AZStd::pair<SimulationState, SimulationState> desireTransition{ m_simulationState, requestedState };
|
|
@@ -306,4 +371,13 @@ namespace SimulationInterfaces
|
|
return it != m_forbiddenStatesTransitions.end();
|
|
return it != m_forbiddenStatesTransitions.end();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ void SimulationManager::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
|
|
|
|
+ {
|
|
|
|
+ DebugDraw::DebugDrawRequestBus::Broadcast(
|
|
|
|
+ &DebugDraw::DebugDrawRequests::DrawTextOnScreen,
|
|
|
|
+ AZStd::string::format("Simulation state: %s", GetStateName(m_simulationState).c_str()),
|
|
|
|
+ AZ::Color(1.0f, 1.0f, 1.0f, 1.0f),
|
|
|
|
+ 0.f);
|
|
|
|
+ }
|
|
|
|
+
|
|
} // namespace SimulationInterfaces
|
|
} // namespace SimulationInterfaces
|