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());
139 UGameplayStatics::OpenLevel(
CurrentEpisode->GetWorld(), *FinalPath,
true);
148 carla::Buffer buf(reinterpret_cast<unsigned char *>(&token), (
size_t)
sizeof(token));
149 carla::log_info(
"responding with a token for port ", token.get_port());
155 std::string msg(
"Yes, I'm alive");
156 carla::Buffer buf((
unsigned char *) msg.c_str(), (size_t) msg.size());
169 carla::Buffer buf(reinterpret_cast<unsigned char *>(&res), (
size_t)
sizeof(
bool));
182 carla::Buffer buf(reinterpret_cast<unsigned char *>(&res), (
size_t)
sizeof(
bool));
193 carla::Buffer buf(reinterpret_cast<unsigned char *>(&res), (
size_t)
sizeof(
bool));
201 Secondary = std::make_shared<carla::multigpu::Secondary>(PrimaryIP, PrimaryPort, CommandExecutor);
214 UE_LOG(LogCarla, Log, TEXT(
"New secondary connection detected"));
220 #if defined(WITH_ROS2) 233 TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
277 TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
278 if (TickType == ELevelTick::LEVELTICK_All)
320 TRACE_CPUPROFILER_EVENT_SCOPE_STR(
"FramesToProcess.PlayFrameData");
333 TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
342 std::ostringstream OutStream;
346 std::string Tmp(OutStream.str());
356 EpisodeRecorder->
Ticking(DeltaSeconds);
360 if ((TickType == ELevelTick::LEVELTICK_All) && (
CurrentEpisode !=
nullptr))
363 bool LightUpdatePending =
false;
367 if (CarlaLightSubsystem)
386 if (GEngine && GEngine->GameViewport)
void CheckPlayAfterMapLoaded(void)
void PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaSeconds)
carla::streaming::Server & GetStreamingServer()
bool IsUpdatePending() const
UCarlaEpisode * GetCurrentEpisode()
void DisableForROS(stream_id sensor_id)
void OnEpisodeSettingsChanged(const FEpisodeSettings &Settings)
uint32 SecondaryPort
setting for the secondary servers port.
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.
FDelegateHandle OnEpisodeSettingsChangeHandle
FSensorManager & GetSensorManager()
std::shared_ptr< carla::multigpu::Router > SecondaryServer
void SetEpisode(UCarlaEpisode *ThisEpisode)
static void FCarlaEngine_SetFixedDeltaSeconds(TOptional< double > FixedDeltaSeconds)
std::vector< FFrameData > FramesToProcess
uint32 StreamingPort
setting for the streaming port.
float TileStreamingDistance
static uint32 FCarlaEngine_GetNumberOfThreadsForRPCServer()
float ActorActiveDistance
FDataMultiStream Start(uint16_t RPCPort, uint16_t StreamingPort, uint16_t SecondaryPort)
static FOnEpisodeSettingsChange OnEpisodeSettingsChange
static uint64_t UpdateFrameCounter()
FDelegateHandle OnPostTickHandle
void SetStream(FDataMultiStream InStream)
Replace the Stream associated with this sensor.
FWorldObserver WorldObserver
bool IsEnabledForROS(stream_id sensor_id)
CarlaReplayer * GetReplayer(void)
static T Get(carla::rpc::Response< T > &response)
void Write(std::ostream &OutStream)
static void ResetFrameCounter(uint64_t Value=0)
void NotifyInitGame(const UCarlaSettings &Settings)
void OnPostTick(UWorld *World, ELevelTick TickType, float DeltaSeconds)
token_type GetToken(stream_id sensor_id)
static uint64_t FrameCounter
void RunSome(uint32 Milliseconds)
void EnableForROS(stream_id sensor_id)
std::mutex FrameToProcessMutex
Serializes a stream endpoint.
void NotifyBeginEpisode(UCarlaEpisode &Episode)
ACarlaRecorder * Recorder
std::shared_ptr< carla::multigpu::Router > GetSecondaryServer()
std::string PrimaryIP
setting for the IP and Port of the primary server to connect.
std::unordered_map< uint32_t, uint32_t > MappedId
FEpisodeSettings CurrentSettings
void GetFrameData(UCarlaEpisode *ThisEpisode, bool bAdditionalData=false, bool bIncludeActorsAgain=false)
void SetActorStreamingDistance(float Distance)
Global settings for CARLA.
UCarlaEpisode * CurrentEpisode
void ResetSimulationState()
static void log_info(Args &&... args)
ACarlaRecorder * GetRecorder() const
void SetLayerStreamingDistance(float Distance)
void Ticking(float DeltaSeconds)
void SetRecorder(ACarlaRecorder *Rec)
FFrameData & GetFrameData()
void OnPreTick(UWorld *World, ELevelTick TickType, float DeltaSeconds)
float GetActorStreamingDistance() const
float GetLayerStreamingDistance() const
static TOptional< double > FCarlaEngine_GetFixedDeltaSeconds()
static ALargeMapManager * GetLargeMapManager(const UObject *WorldContextObject)
uint32 RPCPort
World port to listen for client connections.
void Read(std::istream &InStream)
double MaxSubstepDeltaTime
FEpisodeSettings EpisodeSettings
static std::shared_ptr< ROS2 > GetInstance()
TOptional< double > FixedDeltaSeconds
std::shared_ptr< carla::multigpu::Secondary > Secondary
void AsyncRun(uint32 NumberOfWorkerThreads)
FDelegateHandle OnPreTickHandle
void TickTimers(float DeltaSeconds)
void ApplySettings(const FEpisodeSettings &Settings)
void NotifyBeginEpisode(UCarlaEpisode &Episode)