62 File.seekg(0, std::ios::beg);
78 std::streampos Current =
File.tellg();
102 File.seekg(Current, std::ios::beg);
107 std::string Filename,
110 uint32_t ThisFollowId,
111 const FTransform& Offset,
114 std::string MapOverride)
116 std::stringstream Info;
128 Info <<
"Replaying File: " << Filename2 << std::endl;
131 File.open(Filename2, std::ios::binary);
134 Info <<
"File " << Filename2 <<
" not found on server\n";
142 if (!MapOverride.empty())
150 Info <<
"Could not load mapfile " << TCHAR_TO_UTF8(*
RecInfo.
Mapfile) << std::endl;
154 Info <<
"Loading map " << TCHAR_TO_UTF8(*
RecInfo.
Mapfile) << std::endl;
155 Info <<
"Replayer will start after map is loaded..." << std::endl;
172 Info <<
"Total time recorded: " <<
TotalTime << std::endl;
175 if (TimeStart < 0.0f)
178 if (TimeStart < 0.0f)
188 Info <<
"Replaying from " << TimeStart <<
" s - " <<
TimeToStop <<
" s (" <<
TotalTime <<
" s) at " <<
189 std::setprecision(1) << std::fixed <<
TimeFactor <<
"x" << std::endl;
192 Info <<
"Ignoring Hero vehicle" << std::endl;
195 Info <<
"Ignoring Spectator camera" << std::endl;
247 if (TimeStart < 0.0f)
250 if (TimeStart < 0.0f)
283 bool bFrameFound =
false;
284 bool bExitAtNextFrame =
false;
285 bool bExitLoop =
false;
296 while (!
File.eof() && !bExitLoop)
474 ReadValue<uint16_t>(
File, Total);
475 for (i = 0; i < Total; ++i)
489 switch (Result.first)
493 UE_LOG(LogCarla, Log, TEXT(
"actor could not be created"));
510 UE_LOG(LogCarla, Log, TEXT(
"ignoring actor from replayer (Hero or Spectator)"));
516 if (Result.first > 0 && Result.first < 3)
520 for (
const auto &Item :
EventAdd.Description.Attributes)
522 if (Item.Id ==
"role_name" && Item.Value ==
"hero")
539 ReadValue<uint16_t>(
File, Total);
540 for (i = 0; i < Total; ++i)
552 std::stringstream Info;
555 ReadValue<uint16_t>(
File, Total);
556 for (i = 0; i < Total; ++i)
567 std::stringstream Info;
570 ReadValue<uint16_t>(
File, Total);
571 for (i = 0; i < Total; ++i)
580 TEXT(
"callback state traffic light %d called but didn't work"),
590 std::stringstream Info;
593 ReadValue<uint16_t>(
File, Total);
594 for (i = 0; i < Total; ++i)
614 ReadValue<uint16_t>(
File, Total);
617 for (i = 0; i < Total; ++i)
635 std::stringstream Info;
638 ReadValue<uint16_t>(
File, Total);
639 for (i = 0; i < Total; ++i)
655 std::stringstream Info;
657 ReadValue<uint16_t>(
File, Total);
658 for (i = 0; i < Total; ++i)
675 ReadValue<uint16_t>(
File, Total);
676 for (uint16_t i = 0; i < Total; ++i)
694 ReadValue<uint16_t>(
File, Total);
695 for (uint16_t i = 0; i < Total; ++i)
713 ReadValue<uint16_t>(
File, Total);
714 for (uint16_t i = 0; i < Total; ++i)
730 ReadValue<uint16_t>(
File, Total);
731 for (uint16_t i = 0; i < Total; ++i)
746 ReadValue<uint16_t>(
File, Total);
749 for (i = 0; i < Total; ++i)
760 UE_LOG(LogCarla, Log, TEXT(
"Actor not found when trying to move from replayer (id. %d)"), Pos.
DatabaseId);
761 CurrPos.push_back(std::move(Pos));
775 std::stringstream Info;
778 ReadValue<uint16_t>(
File, Total);
779 for (i = 0; i < Total; ++i)
794 uint32_t NewFollowId = 0;
795 std::unordered_map<int, int> TempMap;
798 for (i = 0; i <
PrevPos.size(); ++i)
800 TempMap[
PrevPos[i].DatabaseId] = i;
809 NewFollowId = NewId->second;
821 auto Result = TempMap.find(Pos.DatabaseId);
822 if (Result != TempMap.end())
841 if (NewFollowId != 0)
849 std::unordered_map<uint32_t, const CarlaRecorderAnimWheels *> PrevWheelsById;
852 PrevWheelsById[Wheels.DatabaseId] = &Wheels;
854 std::unordered_map<uint32_t, const CarlaRecorderPosition *> PrevPosById, CurrPosById;
857 PrevPosById[Pos.DatabaseId] = &Pos;
861 CurrPosById[Pos.DatabaseId] = &Pos;
871 auto Prev = PrevWheelsById.find(Wheels.DatabaseId);
872 if (Prev == PrevWheelsById.end())
881 auto Pos1 = PrevPosById.find(Wheels.DatabaseId);
882 auto Pos2 = CurrPosById.find(Wheels.DatabaseId);
883 if (Pos1 != PrevPosById.end() && Pos2 != CurrPosById.end())
885 const FVector Forward = FRotator::MakeFromEuler(Pos1->second->Rotation).Vector();
886 Travel = FVector::DotProduct(Pos2->second->Location - Pos1->second->Location, Forward);
std::string GetRecorderFilename(std::string Filename)
void ProcessReplayerWalkerBones(const CarlaRecorderWalkerBones &Walker)
bool ProcessReplayerFinish(bool bApplyAutopilot, bool bIgnoreHero, std::unordered_map< uint32_t, bool > &IsHero)
void ProcessReplayerAnimVehicleWheels(const CarlaRecorderAnimWheels &Wheels1, const CarlaRecorderAnimWheels &Wheels2, double Per, float Travel)
void ProcessReplayerLightScene(CarlaRecorderLightScene LightScene)
void ProcessReplayerDoorVehicle(CarlaRecorderDoorVehicle DoorVehicle)
void ProcessReplayerAnimWalker(CarlaRecorderAnimWalker Walker)
bool ProcessReplayerStateTrafficLight(CarlaRecorderStateTrafficLight State)
bool ProcessReplayerEventParent(uint32_t ChildId, uint32_t ParentId)
void ProcessReplayerAnimVehicle(CarlaRecorderAnimVehicle Vehicle)
bool ProcessReplayerEventDel(uint32_t DatabaseId)
void ProcessReplayerLightVehicle(CarlaRecorderLightVehicle LightVehicle)
std::pair< int, uint32_t > ProcessReplayerEventAdd(FVector Location, FVector Rotation, CarlaRecorderActorDescription Description, uint32_t DesiredId, bool bIgnoreHero, bool bIgnoreSpectator, bool ReplaySensors)
void ProcessReplayerAnimBiker(CarlaRecorderAnimBiker Biker)
bool ProcessReplayerPosition(CarlaRecorderPosition Pos1, CarlaRecorderPosition Pos2, double Per, double DeltaTime)
void ProcessReplayerWeather(const CarlaRecorderWeather &Weather)
bool SetCameraPosition(uint32_t Id, FVector Offset, FQuat Rotation)
void ProcessEventsDel(void)
void ProcessDoorVehicle(void)
std::vector< CarlaRecorderPosition > PrevPos
void ProcessVisualTime(void)
void ProcessLightVehicle(void)
double GetTotalTime(void)
std::vector< CarlaRecorderPosition > CurrPos
std::vector< CarlaRecorderAnimWheels > PrevWheels
void InterpolatePosition(const CarlaRecorderPosition &Start, const CarlaRecorderPosition &End, double Per, double DeltaTime)
void ProcessAnimVehicle(void)
void ProcessWalkerBones(void)
void ProcessPositions(bool IsFirstTime=false)
void ProcessEventsParent(void)
std::string ReplayFile(std::string Filename, double TimeStart=0.0f, double Duration=0.0f, uint32_t FollowId=0, const FTransform &Offset=FTransform(), bool ReplaySensors=false, bool ReplayWeather=false, std::string MapOverride="")
void ProcessWeather(void)
void UpdatePositions(double Per, double DeltaTime)
void ProcessEventsAdd(void)
static PlayAfterLoadMap Autoplay
void UpdateWheels(double Per)
void ProcessAnimWalker(void)
void ProcessAnimBiker(void)
std::vector< CarlaRecorderAnimWheels > CurrWheels
CarlaRecorderInfo RecInfo
CarlaReplayerHelper Helper
void ProcessLightScene(void)
void CheckPlayAfterMapLoaded(void)
std::unordered_map< uint32_t, bool > IsHeroMap
void ProcessToTime(double Time, bool IsFirstTime=false)
std::unordered_map< uint32_t, uint32_t > MappedId
void Stop(bool KeepActors=false)
void ProcessAnimVehicleWheels(bool IsFirstTime=false)
const FString & GetMapName() const
void SetVisualGameTime(double Time)
bool LoadNewEpisode(const FString &MapString, bool ResetSettings=true)
Load a new map and start a new episode.
void Read(std::istream &InFile)
void Read(std::istream &InFile)
void Read(std::istream &InFile)
void Read(std::istream &InFile)
void Read(std::istream &InFile)
void Read(std::istream &File)
void Read(std::istream &InFile)
void Read(std::istream &InFile)
void Read(std::istream &InFile)
void Read(std::istream &InFile)
void Read(std::ifstream &InFile)
void Read(std::ifstream &InFile)