18#include "Runtime/Core/Public/Misc/App.h"
19#include "PhysicsEngine/PhysicsSettings.h"
44 return std::max(std::thread::hardware_concurrency(), 4u) - 2u;
49 return FApp::IsBenchmarking() ? FApp::GetFixedDeltaTime() : TOptional<double>{};
54 FApp::SetBenchmarking(FixedDeltaSeconds.IsSet());
55 FApp::SetFixedDeltaTime(FixedDeltaSeconds.Get(0.0));
66 #if defined(WITH_ROS2)
68 if (ROS2->IsEnabled())
79 TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
84 const auto PrimaryIP = Settings.
PrimaryIP;
105 if (!PrimaryIP.empty())
112 struct CarlaStreamBuffer :
public std::streambuf
114 CarlaStreamBuffer(
char *buf, std::size_t size) { setg(buf, buf, buf + size); }
121 TRACE_CPUPROFILER_EVENT_SCOPE_STR(
"MultiGPUCommand::SEND_FRAME");
123 CarlaStreamBuffer TempStream((
char *) Data.data(), Data.size());
124 std::istream InStream(&TempStream);
127 TRACE_CPUPROFILER_EVENT_SCOPE_STR(
"FramesToProcess.emplace_back");
138 FString FinalPath((
char *) Data.data());
152 carla::Buffer buf(
reinterpret_cast<unsigned char *
>(&token), (
size_t)
sizeof(token));
159 std::string msg(
"Yes, I'm alive");
160 carla::Buffer buf((
unsigned char *) msg.c_str(), (
size_t) msg.size());
173 carla::Buffer buf(
reinterpret_cast<unsigned char *
>(&res), (
size_t)
sizeof(
bool));
186 carla::Buffer buf(
reinterpret_cast<unsigned char *
>(&res), (
size_t)
sizeof(
bool));
197 carla::Buffer buf(
reinterpret_cast<unsigned char *
>(&res), (
size_t)
sizeof(
bool));
205 Secondary = std::make_shared<carla::multigpu::Secondary>(PrimaryIP, PrimaryPort, CommandExecutor);
218 UE_LOG(LogCarla, Log, TEXT(
"New secondary connection detected"));
224 #if defined(WITH_ROS2)
237 TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
281 TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
282 if (TickType == ELevelTick::LEVELTICK_All)
324 TRACE_CPUPROFILER_EVENT_SCOPE_STR(
"FramesToProcess.PlayFrameData");
337 TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
346 std::ostringstream OutStream;
350 std::string Tmp(OutStream.str());
360 EpisodeRecorder->
Ticking(DeltaSeconds);
364 if ((TickType == ELevelTick::LEVELTICK_All) && (
CurrentEpisode !=
nullptr))
367 bool LightUpdatePending =
false;
371 if (CarlaLightSubsystem)
390 if (GEngine && GEngine->GameViewport)
398 UPhysicsSettings* PhysSett = UPhysicsSettings::Get();
static void FCarlaEngine_SetFixedDeltaSeconds(TOptional< double > FixedDeltaSeconds)
static uint32 FCarlaEngine_GetNumberOfThreadsForRPCServer()
static TOptional< double > FCarlaEngine_GetFixedDeltaSeconds()
void Ticking(float DeltaSeconds)
CarlaReplayer * GetReplayer(void)
void SetEpisode(UCarlaEpisode *ThisEpisode)
float GetLayerStreamingDistance() const
void SetActorStreamingDistance(float Distance)
void SetLayerStreamingDistance(float Distance)
float GetActorStreamingDistance() const
void CheckPlayAfterMapLoaded(void)
void OnEpisodeSettingsChanged(const FEpisodeSettings &Settings)
FDelegateHandle OnEpisodeSettingsChangeHandle
std::shared_ptr< carla::multigpu::Router > SecondaryServer
std::mutex FrameToProcessMutex
void OnPreTick(UWorld *World, ELevelTick TickType, float DeltaSeconds)
static uint64_t FrameCounter
void ResetSimulationState()
FWorldObserver WorldObserver
static void ResetFrameCounter(uint64_t Value=0)
std::unordered_map< uint32_t, uint32_t > MappedId
FEpisodeSettings CurrentSettings
static uint64_t UpdateFrameCounter()
UCarlaEpisode * CurrentEpisode
std::vector< FFrameData > FramesToProcess
void NotifyBeginEpisode(UCarlaEpisode &Episode)
void NotifyInitGame(const UCarlaSettings &Settings)
ACarlaRecorder * Recorder
FDelegateHandle OnPreTickHandle
FDelegateHandle OnPostTickHandle
std::shared_ptr< carla::multigpu::Secondary > Secondary
UCarlaEpisode * GetCurrentEpisode()
void OnPostTick(UWorld *World, ELevelTick TickType, float DeltaSeconds)
std::shared_ptr< carla::multigpu::Router > GetSecondaryServer()
void RunSome(uint32 Milliseconds)
carla::streaming::Server & GetStreamingServer()
void NotifyBeginEpisode(UCarlaEpisode &Episode)
FDataMultiStream Start(uint16_t RPCPort, uint16_t StreamingPort, uint16_t SecondaryPort)
void AsyncRun(uint32 NumberOfWorkerThreads)
static FOnEpisodeSettingsChange OnEpisodeSettingsChange
void GetFrameData(UCarlaEpisode *ThisEpisode, bool bAdditionalData=false, bool bIncludeActorsAgain=false)
void Read(std::istream &InStream)
void Write(std::ostream &OutStream)
void PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaSeconds)
void SetStream(FDataMultiStream InStream)
Replace the Stream associated with this sensor.
void BroadcastTick(const UCarlaEpisode &Episode, float DeltaSeconds, bool MapChange, bool PendingLightUpdate)
Send a message to every connected client with the info about the given Episode.
FFrameData & GetFrameData()
FEpisodeSettings EpisodeSettings
void ApplySettings(const FEpisodeSettings &Settings)
void SetRecorder(ACarlaRecorder *Rec)
void TickTimers(float DeltaSeconds)
ACarlaRecorder * GetRecorder() const
FSensorManager & GetSensorManager()
bool IsUpdatePending() const
Global settings for CARLA.
uint32 StreamingPort
setting for the streaming port.
std::string PrimaryIP
setting for the IP and Port of the primary server to connect.
uint32 RPCPort
World port to listen for client connections.
uint32 SecondaryPort
setting for the secondary servers port.
static ALargeMapManager * GetLargeMapManager(const UObject *WorldContextObject)
static std::shared_ptr< ROS2 > GetInstance()
token_type GetToken(stream_id sensor_id)
bool IsEnabledForROS(stream_id sensor_id)
void EnableForROS(stream_id sensor_id)
void DisableForROS(stream_id sensor_id)
Serializes a stream endpoint.
static void log_info(Args &&... args)
float TileStreamingDistance
float ActorActiveDistance
double MaxSubstepDeltaTime
TOptional< double > FixedDeltaSeconds