Fixes that an actor could be respawned before the Episode is ready

This commit is contained in:
bernatx 2019-05-21 18:46:08 +02:00
parent ce3ea1c463
commit 58f00c9a3d
3 changed files with 46 additions and 49 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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;
}
}
}