Attach AWorldObserver sensor to UCarlaEpisode
This commit is contained in:
parent
817aac38dd
commit
7722f112ba
|
@ -17,6 +17,24 @@ UCarlaEpisode::UCarlaEpisode(const FObjectInitializer &ObjectInitializer)
|
|||
return ++COUNTER;
|
||||
}()) {}
|
||||
|
||||
const AWorldObserver *UCarlaEpisode::StartWorldObserver(carla::streaming::MultiStream Stream)
|
||||
{
|
||||
UE_LOG(LogCarla, Log, TEXT("Starting AWorldObserver sensor"));
|
||||
check(WorldObserver != nullptr);
|
||||
auto *World = GetWorld();
|
||||
check(World != nullptr);
|
||||
WorldObserver = World->SpawnActorDeferred<AWorldObserver>(
|
||||
AWorldObserver::StaticClass(),
|
||||
FTransform(),
|
||||
nullptr,
|
||||
nullptr,
|
||||
ESpawnActorCollisionHandlingMethod::AlwaysSpawn);
|
||||
WorldObserver->SetEpisode(*this);
|
||||
WorldObserver->SetStream(std::move(Stream));
|
||||
UGameplayStatics::FinishSpawningActor(WorldObserver, FTransform());
|
||||
return WorldObserver;
|
||||
}
|
||||
|
||||
void UCarlaEpisode::InitializeAtBeginPlay()
|
||||
{
|
||||
auto World = GetWorld();
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "Carla/Actor/ActorDispatcher.h"
|
||||
#include "Carla/Sensor/WorldObserver.h"
|
||||
#include "Carla/Weather/Weather.h"
|
||||
|
||||
#include "CarlaEpisode.generated.h"
|
||||
|
@ -93,6 +94,13 @@ public:
|
|||
return ActorDispatcher.GetActorRegistry();
|
||||
}
|
||||
|
||||
const AWorldObserver *StartWorldObserver(carla::streaming::MultiStream Stream);
|
||||
|
||||
const AWorldObserver *GetWorldObserver() const
|
||||
{
|
||||
return WorldObserver;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
friend class ATheNewCarlaGameModeBase;
|
||||
|
@ -116,4 +124,7 @@ private:
|
|||
|
||||
UPROPERTY(VisibleAnywhere)
|
||||
AWeather *Weather = nullptr;
|
||||
|
||||
UPROPERTY(VisibleAnywhere)
|
||||
AWorldObserver *WorldObserver = nullptr;
|
||||
};
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
|
||||
#include "GameFramework/Actor.h"
|
||||
|
||||
#include "Carla/Game/CarlaEpisode.h"
|
||||
|
||||
#include <compiler/disable-ue4-macros.h>
|
||||
#include <carla/Optional.h>
|
||||
#include <carla/streaming/Stream.h>
|
||||
|
@ -17,6 +15,8 @@
|
|||
|
||||
#include "WorldObserver.generated.h"
|
||||
|
||||
class UCarlaEpisode;
|
||||
|
||||
/// Serializes and sends all the actors in a UCarlaEpisode.
|
||||
UCLASS()
|
||||
class CARLA_API AWorldObserver : public AActor
|
||||
|
@ -42,6 +42,12 @@ public:
|
|||
Stream = std::move(InStream);
|
||||
}
|
||||
|
||||
auto GetStreamToken() const
|
||||
{
|
||||
check(Stream.has_value());
|
||||
return (*Stream).token();
|
||||
}
|
||||
|
||||
void BeginPlay() final;
|
||||
|
||||
void Tick(float DeltaSeconds) final;
|
||||
|
|
|
@ -138,7 +138,11 @@ void FTheNewCarlaServer::FPimpl::BindActions()
|
|||
|
||||
Server.BindSync("get_episode_info", [this]() -> cr::EpisodeInfo {
|
||||
RequireEpisode();
|
||||
return {Episode->GetId(), cr::FromFString(Episode->GetMapName())};
|
||||
auto WorldObserver = Episode->GetWorldObserver();
|
||||
if (WorldObserver == nullptr) {
|
||||
WorldObserver = Episode->StartWorldObserver(StreamingServer.MakeMultiStream());
|
||||
}
|
||||
return {Episode->GetId(), cr::FromFString(Episode->GetMapName()), WorldObserver->GetStreamToken()};
|
||||
});
|
||||
|
||||
Server.BindSync("get_actor_definitions", [this]() {
|
||||
|
|
Loading…
Reference in New Issue