From 58f00c9a3d11386124ad608c7cb2bc4305045a6c Mon Sep 17 00:00:00 2001 From: bernatx Date: Tue, 21 May 2019 18:46:08 +0200 Subject: [PATCH] Fixes that an actor could be respawned before the Episode is ready --- .../Carla/Source/Carla/Game/CarlaEpisode.cpp | 3 - .../Source/Carla/Game/CarlaGameModeBase.cpp | 4 + .../Source/Carla/Recorder/CarlaReplayer.cpp | 88 +++++++++---------- 3 files changed, 46 insertions(+), 49 deletions(-) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaEpisode.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaEpisode.cpp index 2e00738f6..259785fed 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaEpisode.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaEpisode.cpp @@ -201,9 +201,6 @@ void UCarlaEpisode::InitializeAtBeginPlay() ActorDispatcher->RegisterActor(*Actor, Description); } } - - // check if replayer is waiting to autostart - Recorder->GetReplayer()->CheckPlayAfterMapLoaded(); } void UCarlaEpisode::EndPlay(void) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp index a937f4749..df12a40f7 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp @@ -108,6 +108,10 @@ void ACarlaGameModeBase::BeginPlay() Episode->InitializeAtBeginPlay(); GameInstance->NotifyBeginEpisode(*Episode); + + /// @todo Recorder should not tick here, FCarlaEngine should do it. + // check if replayer is waiting to autostart + if (Recorder) Recorder->GetReplayer()->CheckPlayAfterMapLoaded(); } void ACarlaGameModeBase::Tick(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 520aa04bc..611e0ee87 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayer.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayer.cpp @@ -386,55 +386,51 @@ void CarlaReplayer::ProcessEventsAdd(void) { EventAdd.Read(File); - // avoid sensor events - if (!EventAdd.Description.Id.StartsWith("sensor.")) + // show log + // Info.str(""); + // Info << " Create " << EventAdd.DatabaseId << ": " << TCHAR_TO_UTF8(*EventAdd.Description.Id) << " (" << + // EventAdd.Description.UId << ") at (" << EventAdd.Location.X << ", " << + // EventAdd.Location.Y << ", " << EventAdd.Location.Z << ")" << std::endl; + // for (auto &Att : EventAdd.Description.Attributes) + // { + // Info << " " << TCHAR_TO_UTF8(*Att.Id) << " = " << TCHAR_TO_UTF8(*Att.Value) << std::endl; + // } + // UE_LOG(LogCarla, Log, TEXT("%s"), Info.str().c_str()); + + // auto Result = CallbackEventAdd( + auto Result = Helper.ProcessReplayerEventAdd( + EventAdd.Location, + EventAdd.Rotation, + std::move(EventAdd.Description), + EventAdd.DatabaseId); + + switch (Result.first) { - // show log - // Info.str(""); - // Info << " Create " << EventAdd.DatabaseId << ": " << TCHAR_TO_UTF8(*EventAdd.Description.Id) << " (" << - // EventAdd.Description.UId << ") at (" << EventAdd.Location.X << ", " << - // EventAdd.Location.Y << ", " << EventAdd.Location.Z << ")" << std::endl; - // for (auto &Att : EventAdd.Description.Attributes) - // { - // Info << " " << TCHAR_TO_UTF8(*Att.Id) << " = " << TCHAR_TO_UTF8(*Att.Value) << std::endl; - // } - // UE_LOG(LogCarla, Log, TEXT("%s"), Info.str().c_str()); + // actor not created + case 0: + UE_LOG(LogCarla, Log, TEXT("actor could not be created")); + break; - // auto Result = CallbackEventAdd( - auto Result = Helper.ProcessReplayerEventAdd( - EventAdd.Location, - EventAdd.Rotation, - std::move(EventAdd.Description), - EventAdd.DatabaseId); + // actor created but with different id + case 1: + // if (Result.second != EventAdd.DatabaseId) + // { + // UE_LOG(LogCarla, Log, TEXT("actor created but with different id")); + // } + // else + // { + // UE_LOG(LogCarla, Log, TEXT("actor created with same id")); + // } + // mapping id (recorded Id is a new Id in replayer) + MappedId[EventAdd.DatabaseId] = Result.second; + break; - switch (Result.first) - { - // actor not created - case 0: - UE_LOG(LogCarla, Log, TEXT("actor could not be created")); - break; - - // actor created but with different id - case 1: - // if (Result.second != EventAdd.DatabaseId) - // { - // UE_LOG(LogCarla, Log, TEXT("actor created but with different id")); - // } - // else - // { - // UE_LOG(LogCarla, Log, TEXT("actor created with same id")); - // } - // mapping id (recorded Id is a new Id in replayer) - MappedId[EventAdd.DatabaseId] = Result.second; - break; - - // actor reused from existing - case 2: - // UE_LOG(LogCarla, Log, TEXT("actor already exist, not created")); - // mapping id (say desired Id is mapped to what) - MappedId[EventAdd.DatabaseId] = Result.second; - break; - } + // actor reused from existing + case 2: + // UE_LOG(LogCarla, Log, TEXT("actor already exist, not created")); + // mapping id (say desired Id is mapped to what) + MappedId[EventAdd.DatabaseId] = Result.second; + break; } } }