Add recommended start transforms to map info message

This commit is contained in:
nsubiron 2018-10-24 20:41:11 +02:00
parent 4f92ec758c
commit 6b7ad14665
4 changed files with 33 additions and 2 deletions

View File

@ -7,6 +7,10 @@
#pragma once
#include "carla/MsgPack.h"
#include "carla/geom/Transform.h"
#include <string>
#include <vector>
namespace carla {
namespace rpc {
@ -18,7 +22,9 @@ namespace rpc {
std::string open_drive_file;
MSGPACK_DEFINE_ARRAY(name, open_drive_file);
std::vector<geom::Transform> recommended_start_transforms;
MSGPACK_DEFINE_ARRAY(name, open_drive_file, recommended_start_transforms);
};
} // namespace rpc

View File

@ -7,6 +7,8 @@
#include "Carla.h"
#include "Carla/Game/CarlaEpisode.h"
#include "Carla/Vehicle/VehicleSpawnPoint.h"
#include "EngineUtils.h"
#include "GameFramework/SpectatorPawn.h"
@ -36,6 +38,15 @@ UCarlaEpisode::UCarlaEpisode(const FObjectInitializer &ObjectInitializer)
return ++COUNTER;
}()) {}
TArray<FTransform> UCarlaEpisode::GetRecommendedStartTransforms() const
{
TArray<FTransform> SpawnPoints;
for (TActorIterator<AVehicleSpawnPoint> It(GetWorld()); It; ++It) {
SpawnPoints.Add(It->GetActorTransform());
}
return SpawnPoints;
}
const AWorldObserver *UCarlaEpisode::StartWorldObserver(carla::streaming::MultiStream Stream)
{
UE_LOG(LogCarla, Log, TEXT("Starting AWorldObserver sensor"));

View File

@ -55,6 +55,10 @@ public:
return ActorDispatcher.GetActorDefinitions();
}
/// Return the list of recommended start positions.
UFUNCTION(BlueprintCallable)
TArray<FTransform> GetRecommendedStartTransforms() const;
/// Spawns an actor based on @a ActorDescription at @a Transform. To properly
/// despawn an actor created with this function call DestroyActor.
///

View File

@ -194,7 +194,17 @@ void FTheNewCarlaServer::FPimpl::BindActions()
Server.BindSync("get_map_info", [this]() -> cr::MapInfo {
RequireEpisode();
auto FileContents = FOpenDrive::Load(Episode->GetMapName());
return {cr::FromFString(Episode->GetMapName()), cr::FromFString(FileContents)};
const auto &SpawnPoints = Episode->GetRecommendedStartTransforms();
std::vector<carla::geom::Transform> spawn_points;
spawn_points.reserve(SpawnPoints.Num());
for (const auto &Transform : SpawnPoints)
{
spawn_points.emplace_back(Transform);
}
return {
cr::FromFString(Episode->GetMapName()),
cr::FromFString(FileContents),
spawn_points};
});
Server.BindSync("get_actor_definitions", [this]() {