diff --git a/CHANGELOG.md b/CHANGELOG.md index 66bc24194..e8d8c2f52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ * Fixed bug causing the TM's unstuck logic to incorrectly remove the vehicles in some situations. * Fixed the extra data in Directx textures, so we need to copy row by row on Windows to remove extra bytes on images * Restored gamma value to 2.2 instead of 2.4 + * Added API function to avoid replaying the spectator + * `Client.set_replayer_ignore_spectator(bool)` + * `start_replaying.py` using flag `--move-spectator` ## CARLA 0.9.14 diff --git a/LibCarla/source/carla/client/Client.h b/LibCarla/source/carla/client/Client.h index 4b540a5dc..a78bea0c2 100644 --- a/LibCarla/source/carla/client/Client.h +++ b/LibCarla/source/carla/client/Client.h @@ -137,6 +137,10 @@ namespace client { _simulator->SetReplayerIgnoreHero(ignore_hero); } + void SetReplayerIgnoreSpectator(bool ignore_spectator) { + _simulator->SetReplayerIgnoreSpectator(ignore_spectator); + } + void ApplyBatch( std::vector commands, bool do_tick_cue = false) const { diff --git a/LibCarla/source/carla/client/detail/Client.cpp b/LibCarla/source/carla/client/detail/Client.cpp index 960f6e329..b335a7d87 100644 --- a/LibCarla/source/carla/client/detail/Client.cpp +++ b/LibCarla/source/carla/client/detail/Client.cpp @@ -574,6 +574,10 @@ namespace detail { _pimpl->AsyncCall("set_replayer_ignore_hero", ignore_hero); } + void Client::SetReplayerIgnoreSpectator(bool ignore_spectator) { + _pimpl->AsyncCall("set_replayer_ignore_spectator", ignore_spectator); + } + void Client::SubscribeToStream( const streaming::Token &token, std::function callback) { diff --git a/LibCarla/source/carla/client/detail/Client.h b/LibCarla/source/carla/client/detail/Client.h index 83da380ab..21f3ca310 100644 --- a/LibCarla/source/carla/client/detail/Client.h +++ b/LibCarla/source/carla/client/detail/Client.h @@ -362,6 +362,8 @@ namespace detail { void SetReplayerIgnoreHero(bool ignore_hero); + void SetReplayerIgnoreSpectator(bool ignore_spectator); + void StopReplayer(bool keep_actors); void SubscribeToStream( diff --git a/LibCarla/source/carla/client/detail/Simulator.h b/LibCarla/source/carla/client/detail/Simulator.h index e770c714d..cc8082586 100644 --- a/LibCarla/source/carla/client/detail/Simulator.h +++ b/LibCarla/source/carla/client/detail/Simulator.h @@ -576,6 +576,10 @@ namespace detail { _client.SetReplayerIgnoreHero(ignore_hero); } + void SetReplayerIgnoreSpectator(bool ignore_spectator) { + _client.SetReplayerIgnoreSpectator(ignore_spectator); + } + void StopReplayer(bool keep_actors) { _client.StopReplayer(keep_actors); } diff --git a/PythonAPI/carla/source/libcarla/Client.cpp b/PythonAPI/carla/source/libcarla/Client.cpp index 748e2c5ad..2a725a629 100644 --- a/PythonAPI/carla/source/libcarla/Client.cpp +++ b/PythonAPI/carla/source/libcarla/Client.cpp @@ -210,6 +210,7 @@ void export_client() { .def("stop_replayer", &cc::Client::StopReplayer, (arg("keep_actors"))) .def("set_replayer_time_factor", &cc::Client::SetReplayerTimeFactor, (arg("time_factor"))) .def("set_replayer_ignore_hero", &cc::Client::SetReplayerIgnoreHero, (arg("ignore_hero"))) + .def("set_replayer_ignore_spectator", &cc::Client::SetReplayerIgnoreSpectator, (arg("ignore_spectator"))) .def("apply_batch", &ApplyBatchCommands, (arg("commands"), arg("do_tick")=false)) .def("apply_batch_sync", &ApplyBatchCommandsSync, (arg("commands"), arg("do_tick")=false)) .def("get_trafficmanager", CONST_CALL_WITHOUT_GIL_1(cc::Client, GetInstanceTM, uint16_t), (arg("port")=ctm::TM_DEFAULT_PORT)) diff --git a/PythonAPI/examples/start_replaying.py b/PythonAPI/examples/start_replaying.py index 564696050..bd8f30e76 100755 --- a/PythonAPI/examples/start_replaying.py +++ b/PythonAPI/examples/start_replaying.py @@ -71,6 +71,10 @@ def main(): '-i', '--ignore-hero', action='store_true', help='ignore hero vehicles') + argparser.add_argument( + '--move-spectator', + action='store_true', + help='move spectator camera') argparser.add_argument( '--spawn-sensors', action='store_true', @@ -88,6 +92,9 @@ def main(): # set to ignore the hero vehicles or not client.set_replayer_ignore_hero(args.ignore_hero) + # set to ignore the spectator camera or not + client.set_replayer_ignore_spectator(not args.move_spectator) + # replay the session print(client.replay_file(args.recorder_filename, args.start, args.duration, args.camera, args.spawn_sensors)) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorder.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorder.cpp index 8486e7492..ae4b77ba9 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorder.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorder.cpp @@ -73,6 +73,11 @@ void ACarlaRecorder::SetReplayerIgnoreHero(bool IgnoreHero) Replayer.SetIgnoreHero(IgnoreHero); } +void ACarlaRecorder::SetReplayerIgnoreSpectator(bool IgnoreSpectator) +{ + Replayer.SetIgnoreSpectator(IgnoreSpectator); +} + void ACarlaRecorder::StopReplayer(bool KeepActors) { Replayer.Stop(KeepActors); diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorder.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorder.h index b22de8894..f6662d254 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorder.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorder.h @@ -166,6 +166,7 @@ public: uint32_t FollowId, bool ReplaySensors); void SetReplayerTimeFactor(double TimeFactor); void SetReplayerIgnoreHero(bool IgnoreHero); + void SetReplayerIgnoreSpectator(bool IgnoreSpectator); void StopReplayer(bool KeepActors = false); void Ticking(float DeltaSeconds); diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayer.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayer.cpp index 8448d3bfc..0e0122c85 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayer.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayer.cpp @@ -175,6 +175,12 @@ std::string CarlaReplayer::ReplayFile(std::string Filename, double TimeStart, do Info << "Replaying from " << TimeStart << " s - " << TimeToStop << " s (" << TotalTime << " s) at " << std::setprecision(1) << std::fixed << TimeFactor << "x" << std::endl; + if (IgnoreHero) + Info << "Ignoring Hero vehicle" << std::endl; + + if (IgnoreSpectator) + Info << "Ignoring Spectator camera" << std::endl; + // set the follow Id FollowId = ThisFollowId; @@ -446,6 +452,7 @@ void CarlaReplayer::ProcessEventsAdd(void) EventAdd.Description, EventAdd.DatabaseId, IgnoreHero, + IgnoreSpectator, bReplaySensors); switch (Result.first) @@ -466,10 +473,16 @@ void CarlaReplayer::ProcessEventsAdd(void) // mapping id (say desired Id is mapped to what) MappedId[EventAdd.DatabaseId] = Result.second; break; + + // actor ignored (either Hero or Spectator) + case 3: + UE_LOG(LogCarla, Log, TEXT("ignoring actor from replayer (Hero or Spectator)")); + break; + } // check to mark if actor is a hero vehicle or not - if (Result.first > 0) + if (Result.first > 0 && Result.first < 3) { // init IsHeroMap[Result.second] = false; @@ -727,8 +740,9 @@ void CarlaReplayer::UpdatePositions(double Per, double DeltaTime) // go through each actor and update for (auto &Pos : CurrPos) { - // check if ignore this actor - if (!(IgnoreHero && IsHeroMap[Pos.DatabaseId])) + // check if ignore this actor (hero) or the spectator (id == 1) + if (!(IgnoreHero && IsHeroMap[Pos.DatabaseId]) && + !(IgnoreSpectator && Pos.DatabaseId == 1)) { // check if exist a previous position auto Result = TempMap.find(Pos.DatabaseId); diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayer.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayer.h index cacc3f460..f1e73f05e 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayer.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayer.h @@ -86,6 +86,12 @@ public: IgnoreHero = InIgnoreHero; } + // set ignore spectator + void SetIgnoreSpectator(bool InIgnoreSpectator) + { + IgnoreSpectator = InIgnoreSpectator; + } + // check if after a map is loaded, we need to replay void CheckPlayAfterMapLoaded(void); @@ -119,6 +125,7 @@ private: double TimeFactor { 1.0 }; // ignore hero vehicles bool IgnoreHero { false }; + bool IgnoreSpectator { true }; std::unordered_map IsHeroMap; // utils @@ -157,4 +164,4 @@ private: void UpdatePositions(double Per, double DeltaTime); void InterpolatePosition(const CarlaRecorderPosition &Start, const CarlaRecorderPosition &End, double Per, double DeltaTime); -}; \ No newline at end of file +}; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.cpp index 7eb81d332..0588ffcd5 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.cpp @@ -179,6 +179,7 @@ std::pair CarlaReplayerHelper::ProcessReplayerEventAdd( CarlaRecorderActorDescription Description, uint32_t DesiredId, bool bIgnoreHero, + bool bIgnoreSpectator, bool ReplaySensors) { check(Episode != nullptr); @@ -200,6 +201,13 @@ std::pair CarlaReplayerHelper::ProcessReplayerEventAdd( IsHero = true; } + // check to ignore Hero or Spectator + if ((bIgnoreHero && IsHero) || + (bIgnoreSpectator && ActorDesc.Id.StartsWith("spectator"))) + { + return std::make_pair(3, 0); + } + auto result = TryToCreateReplayerActor( Location, Rotation, diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.h index 15c8a5b8b..01cfa2384 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.h @@ -38,6 +38,7 @@ public: CarlaRecorderActorDescription Description, uint32_t DesiredId, bool bIgnoreHero, + bool bIgnoreSpectator, bool ReplaySensors); // replay event for removing actor diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp index 885af2fe8..d5f745b22 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp @@ -2232,6 +2232,13 @@ void FCarlaServer::FPimpl::BindActions() return R::Success(); }; + BIND_SYNC(set_replayer_ignore_spectator) << [this](bool ignore_spectator) -> R + { + REQUIRE_CARLA_EPISODE(); + Episode->GetRecorder()->SetReplayerIgnoreSpectator(ignore_spectator); + return R::Success(); + }; + BIND_SYNC(stop_replayer) << [this](bool keep_actors) -> R { REQUIRE_CARLA_EPISODE();