Added spectator_as_ego settings

This commit is contained in:
Guillermo 2023-04-06 17:01:39 +02:00 committed by bernat
parent 8be9fd22dd
commit 1501a13b1e
7 changed files with 53 additions and 10 deletions

View File

@ -47,9 +47,11 @@ namespace rpc {
float actor_active_distance = 2000.f; // 2km
float spectator_as_ego = true;
MSGPACK_DEFINE_ARRAY(synchronous_mode, no_rendering_mode, fixed_delta_seconds, substepping,
max_substep_delta_time, max_substeps, max_culling_distance, deterministic_ragdolls,
tile_stream_distance, actor_active_distance);
tile_stream_distance, actor_active_distance, spectator_as_ego);
// =========================================================================
// -- Constructors ---------------------------------------------------------
@ -67,7 +69,8 @@ namespace rpc {
float max_culling_distance = 0.0f,
bool deterministic_ragdolls = true,
float tile_stream_distance = 3000.f,
float actor_active_distance = 2000.f)
float actor_active_distance = 2000.f,
bool spectator_as_ego = true)
: synchronous_mode(synchronous_mode),
no_rendering_mode(no_rendering_mode),
fixed_delta_seconds(
@ -78,7 +81,8 @@ namespace rpc {
max_culling_distance(max_culling_distance),
deterministic_ragdolls(deterministic_ragdolls),
tile_stream_distance(tile_stream_distance),
actor_active_distance(actor_active_distance) {}
actor_active_distance(actor_active_distance),
spectator_as_ego(spectator_as_ego) {}
// =========================================================================
// -- Comparison operators -------------------------------------------------
@ -95,7 +99,8 @@ namespace rpc {
(max_culling_distance == rhs.max_culling_distance) &&
(deterministic_ragdolls == rhs.deterministic_ragdolls) &&
(tile_stream_distance == tile_stream_distance) &&
(actor_active_distance == actor_active_distance);
(actor_active_distance == actor_active_distance) &&
(spectator_as_ego == spectator_as_ego);
}
bool operator!=(const EpisodeSettings &rhs) const {
@ -119,7 +124,8 @@ namespace rpc {
Settings.MaxCullingDistance,
Settings.bDeterministicRagdolls,
Settings.TileStreamingDistance,
Settings.ActorActiveDistance) {
Settings.ActorActiveDistance,
Settings.SpectatorAsEgo) {
constexpr float CMTOM = 1.f/100.f;
tile_stream_distance = CMTOM * Settings.TileStreamingDistance;
actor_active_distance = CMTOM * Settings.ActorActiveDistance;
@ -140,6 +146,7 @@ namespace rpc {
Settings.bDeterministicRagdolls = deterministic_ragdolls;
Settings.TileStreamingDistance = MTOCM * tile_stream_distance;
Settings.ActorActiveDistance = MTOCM * actor_active_distance;
Settings.SpectatorAsEgo = spectator_as_ego;
return Settings;
}

View File

@ -163,7 +163,8 @@ void export_world() {
arg("max_culling_distance")=0.0f,
arg("deterministic_ragdolls")=false,
arg("tile_stream_distance")=3000.f,
arg("actor_active_distance")=2000.f)))
arg("actor_active_distance")=2000.f,
arg("spectator_as_ego")=true)))
.def_readwrite("synchronous_mode", &cr::EpisodeSettings::synchronous_mode)
.def_readwrite("no_rendering_mode", &cr::EpisodeSettings::no_rendering_mode)
.def_readwrite("substepping", &cr::EpisodeSettings::substepping)
@ -181,6 +182,7 @@ void export_world() {
})
.def_readwrite("tile_stream_distance", &cr::EpisodeSettings::tile_stream_distance)
.def_readwrite("actor_active_distance", &cr::EpisodeSettings::actor_active_distance)
.def_readwrite("spectator_as_ego", &cr::EpisodeSettings::spectator_as_ego)
.def("__eq__", &cr::EpisodeSettings::operator==)
.def("__ne__", &cr::EpisodeSettings::operator!=)
.def(self_ns::str(self_ns::self))

View File

@ -224,6 +224,7 @@ void ACarlaGameModeBase::BeginPlay()
if (LMManager) {
LMManager->RegisterInitialObjects();
LMManager->ConsiderSpectatorAsEgo(Episode->GetSettings().SpectatorAsEgo);
}
// Manually run begin play on lights as it may not run on sublevels

View File

@ -431,7 +431,7 @@ void ALargeMapManager::GenerateMap(FString InAssetsPath)
GEngine->ForceGarbageCollection(true);
ActorsToConsider.Reset();
if (Spectator)
if (SpectatorAsEgo && Spectator)
{
ActorsToConsider.Add(Spectator);
}
@ -738,7 +738,7 @@ void ALargeMapManager::RemovePendingActorsToRemove()
{
ActorsToConsider.Remove(ActorToRemove);
}
if(ActorsToConsider.Num() == 0 && Spectator)
if(ActorsToConsider.Num() == 0 && SpectatorAsEgo && Spectator)
{
ActorsToConsider.Add(Spectator);
}
@ -1118,3 +1118,18 @@ void ALargeMapManager::PrintMapInfo()
}
}
}
void ALargeMapManager::ConsiderSpectatorAsEgo(bool _SpectatorAsEgo)
{
SpectatorAsEgo = _SpectatorAsEgo;
if(SpectatorAsEgo && ActorsToConsider.Num() == 0 && Spectator)
{
// Activating the spectator in an empty world
ActorsToConsider.Add(Spectator);
}
if (!SpectatorAsEgo && ActorsToConsider.Num() == 1 && ActorsToConsider.Contains(Spectator))
{
// Deactivating the spectator in a world with no other egos
ActorsToConsider.Reset();
}
}

View File

@ -202,6 +202,11 @@ public:
ACarlaWheeledVehicle* GetHeroVehicle();
// The spectator is treated as an ego vehicle by default when no other egos are around,
// but this can be changed from the Python API, which ends up in this function.
bool SpectatorAsEgo = false;
void ConsiderSpectatorAsEgo(bool _SpectatorAsEgo);
protected:
void RemoveLandscapeCollisionIfHaveTerraMechanics(ULevel* InLevel);
@ -343,5 +348,4 @@ protected:
UPROPERTY(VisibleAnywhere, Category = "Large Map Manager")
bool bHasTerramechanics = false;
};

View File

@ -539,6 +539,18 @@ void FCarlaServer::FPimpl::BindActions()
REQUIRE_CARLA_EPISODE();
Episode->ApplySettings(settings);
StreamingServer.SetSynchronousMode(settings.synchronous_mode);
ACarlaGameModeBase* GameMode = UCarlaStatics::GetGameMode(Episode->GetWorld());
if (!GameMode)
{
RESPOND_ERROR("unable to find CARLA game mode");
}
ALargeMapManager* LargeMap = GameMode->GetLMManager();
if (LargeMap)
{
LargeMap->ConsiderSpectatorAsEgo(settings.spectator_as_ego);
}
return FCarlaEngine::GetFrameCounter();
};

View File

@ -35,6 +35,8 @@ struct CARLA_API FEpisodeSettings
float TileStreamingDistance = 300000.f; // 3km
float ActorActiveDistance = 200000.f; // 3km
float ActorActiveDistance = 200000.f; // 2km
float SpectatorAsEgo = true;
};