Replayer now will load the required map automatically. Also a bug fix.
This commit is contained in:
parent
be37d22335
commit
702474f764
|
@ -200,6 +200,9 @@ void UCarlaEpisode::InitializeAtBeginPlay()
|
|||
ActorDispatcher->RegisterActor(*Actor, Description);
|
||||
}
|
||||
}
|
||||
|
||||
// check if replayer is waiting to autostart
|
||||
Recorder->GetReplayer()->CheckPlayAfterMapLoaded();
|
||||
}
|
||||
|
||||
void UCarlaEpisode::EndPlay(void)
|
||||
|
|
|
@ -10,6 +10,9 @@
|
|||
#include <ctime>
|
||||
#include <sstream>
|
||||
|
||||
// structure to save replaying info when need to load a new map (static member by now)
|
||||
CarlaReplayer::PlayAfterLoadMap CarlaReplayer::Autoplay { false, "", "", 0.0, 0.0, 0, 1.0 };
|
||||
|
||||
void CarlaReplayer::Stop(bool bKeepActors)
|
||||
{
|
||||
if (Enabled)
|
||||
|
@ -22,20 +25,11 @@ void CarlaReplayer::Stop(bool bKeepActors)
|
|||
ProcessToTime(TotalTime);
|
||||
}
|
||||
|
||||
File.close();
|
||||
|
||||
// callback
|
||||
Helper.ProcessReplayerFinish(bKeepActors);
|
||||
}
|
||||
|
||||
if (!bKeepActors)
|
||||
{
|
||||
UE_LOG(LogCarla, Log, TEXT("Replayer stop"));
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogCarla, Log, TEXT("Replayer stop (keeping actors)"));
|
||||
}
|
||||
File.close();
|
||||
}
|
||||
|
||||
bool CarlaReplayer::ReadHeader()
|
||||
|
@ -73,8 +67,6 @@ void CarlaReplayer::Rewind(void)
|
|||
|
||||
// read geneal Info
|
||||
RecInfo.Read(File);
|
||||
|
||||
// UE_LOG(LogCarla, Log, TEXT("Replayer rewind"));
|
||||
}
|
||||
|
||||
// read last frame in File and return the Total time recorded
|
||||
|
@ -126,49 +118,126 @@ std::string CarlaReplayer::ReplayFile(std::string Filename, double TimeStart, do
|
|||
if (!File.is_open())
|
||||
{
|
||||
Info << "File " << Filename << " not found on server\n";
|
||||
Stop();
|
||||
return Info.str();
|
||||
}
|
||||
|
||||
// from start
|
||||
Rewind();
|
||||
|
||||
// check to load map if different
|
||||
if (Episode->GetMapName() != RecInfo.Mapfile)
|
||||
{
|
||||
if (!Episode->LoadNewEpisode(RecInfo.Mapfile))
|
||||
{
|
||||
Info << "Could not load mapfile " << TCHAR_TO_UTF8(*RecInfo.Mapfile) << std::endl;
|
||||
Stop();
|
||||
return Info.str();
|
||||
}
|
||||
Info << "Loading map " << TCHAR_TO_UTF8(*RecInfo.Mapfile) << std::endl;
|
||||
Info << "Replayer will start after map is loaded..." << std::endl;
|
||||
|
||||
// prepare autoplay after map is loaded
|
||||
Autoplay.Enabled = true;
|
||||
Autoplay.Filename = Filename;
|
||||
Autoplay.Mapfile = RecInfo.Mapfile;
|
||||
Autoplay.TimeStart = TimeStart;
|
||||
Autoplay.Duration = Duration;
|
||||
Autoplay.FollowId = FollowId;
|
||||
Autoplay.TimeFactor = TimeFactor;
|
||||
}
|
||||
|
||||
// get Total time of recorder
|
||||
TotalTime = GetTotalTime();
|
||||
Info << "Total time recorded: " << TotalTime << std::endl;
|
||||
|
||||
// set time to start replayer
|
||||
if (TimeStart < 0.0f)
|
||||
{
|
||||
TimeStart = TotalTime + TimeStart;
|
||||
if (TimeStart < 0.0f)
|
||||
TimeStart = 0.0f;
|
||||
}
|
||||
|
||||
// set time to stop replayer
|
||||
if (Duration > 0.0f)
|
||||
TimeToStop = TimeStart + Duration;
|
||||
else
|
||||
TimeToStop = TotalTime;
|
||||
|
||||
Info << "Replaying from " << TimeStart << " s - " << TimeToStop << " s (" << TotalTime << " s)" <<
|
||||
std::endl;
|
||||
|
||||
// set the follow Id
|
||||
FollowId = ThisFollowId;
|
||||
|
||||
// if we don't need to load a new map, then start
|
||||
if (!Autoplay.Enabled)
|
||||
{
|
||||
// process all events until the time
|
||||
ProcessToTime(TimeStart);
|
||||
// mark as enabled
|
||||
Enabled = true;
|
||||
}
|
||||
|
||||
return Info.str();
|
||||
}
|
||||
|
||||
void CarlaReplayer::CheckPlayAfterMapLoaded(void)
|
||||
{
|
||||
|
||||
// check if the autoplay is enabled (means waiting until map is loaded)
|
||||
if (!Autoplay.Enabled)
|
||||
return;
|
||||
|
||||
// disable
|
||||
Autoplay.Enabled = false;
|
||||
|
||||
// check to stop if we are replaying another
|
||||
if (Enabled)
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
|
||||
// try to open
|
||||
File.open(Autoplay.Filename, std::ios::binary);
|
||||
if (!File.is_open())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// from start
|
||||
Rewind();
|
||||
|
||||
// get Total time of recorder
|
||||
TotalTime = GetTotalTime();
|
||||
Info << "Total time recorded: " << TotalTime << std::endl;
|
||||
|
||||
// set time to start replayer
|
||||
double TimeStart = Autoplay.TimeStart;
|
||||
if (TimeStart < 0.0f)
|
||||
{
|
||||
TimeStart = TotalTime + TimeStart;
|
||||
TimeStart = TotalTime + Autoplay.TimeStart;
|
||||
if (TimeStart < 0.0f)
|
||||
{
|
||||
TimeStart = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
// set time to stop replayer
|
||||
if (Duration > 0.0f)
|
||||
{
|
||||
TimeToStop = TimeStart + Duration;
|
||||
}
|
||||
if (Autoplay.Duration > 0.0f)
|
||||
TimeToStop = TimeStart + Autoplay.Duration;
|
||||
else
|
||||
{
|
||||
TimeToStop = TotalTime;
|
||||
}
|
||||
Info << "Replaying from " << TimeStart << " s - " << TimeToStop << " s (" << TotalTime << " s)" <<
|
||||
std::endl;
|
||||
|
||||
// set the follow Id
|
||||
FollowId = Autoplay.FollowId;
|
||||
|
||||
// apply time factor
|
||||
TimeFactor = Autoplay.TimeFactor;
|
||||
|
||||
// process all events until the time
|
||||
ProcessToTime(TimeStart);
|
||||
|
||||
// set the follow Id
|
||||
if (ThisFollowId != 0)
|
||||
FollowId = ThisFollowId;
|
||||
else
|
||||
FollowId = 0;
|
||||
|
||||
// mark as enabled
|
||||
Enabled = true;
|
||||
|
||||
return Info.str();
|
||||
}
|
||||
|
||||
void CarlaReplayer::ProcessToTime(double Time)
|
||||
|
@ -302,18 +371,15 @@ void CarlaReplayer::ProcessEventsAdd(void)
|
|||
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, "%s", Info.str().c_str());
|
||||
*/
|
||||
// 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(
|
||||
|
@ -331,10 +397,14 @@ void CarlaReplayer::ProcessEventsAdd(void)
|
|||
|
||||
// actor created but with different id
|
||||
case 1:
|
||||
if (Result.second != EventAdd.DatabaseId)
|
||||
{
|
||||
// UE_LOG(LogCarla, Log, TEXT("actor created but with different id"));
|
||||
}
|
||||
// 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;
|
||||
|
@ -433,6 +503,8 @@ void CarlaReplayer::ProcessPositions(void)
|
|||
{
|
||||
Pos.DatabaseId = NewId->second;
|
||||
}
|
||||
else
|
||||
UE_LOG(LogCarla, Log, TEXT("Actor not found when trying to move from replayer (id. %d)"), Pos.DatabaseId);
|
||||
CurrPos.push_back(std::move(Pos));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,18 @@ class CarlaReplayer
|
|||
#pragma pack(pop)
|
||||
|
||||
public:
|
||||
struct PlayAfterLoadMap
|
||||
{
|
||||
bool Enabled;
|
||||
std::string Filename;
|
||||
FString Mapfile;
|
||||
double TimeStart;
|
||||
double Duration;
|
||||
uint32_t FollowId;
|
||||
double TimeFactor;
|
||||
};
|
||||
|
||||
static PlayAfterLoadMap Autoplay;
|
||||
|
||||
CarlaReplayer() {};
|
||||
~CarlaReplayer() { Stop(); };
|
||||
|
@ -63,6 +75,9 @@ public:
|
|||
// playback speed (time factor)
|
||||
void SetSpeed(double NewTimeFactor);
|
||||
|
||||
// check if after a map is loaded, we need to replay
|
||||
void CheckPlayAfterMapLoaded(void);
|
||||
|
||||
// tick for the replayer
|
||||
void Tick(float Time);
|
||||
|
||||
|
|
Loading…
Reference in New Issue