Added scene light events to recorder.
This commit is contained in:
parent
8374172415
commit
41c870438e
|
@ -6,7 +6,11 @@
|
|||
|
||||
#include "CarlaLight.h"
|
||||
#include "CarlaLightSubsystem.h"
|
||||
#include "Carla/Game/CarlaStatics.h"
|
||||
|
||||
#include <compiler/disable-ue4-macros.h>
|
||||
#include <boost/container_hash/hash.hpp>
|
||||
#include <compiler/enable-ue4-macros.h>
|
||||
|
||||
UCarlaLight::UCarlaLight()
|
||||
{
|
||||
|
@ -46,7 +50,7 @@ void UCarlaLight::SetLightIntensity(float Intensity)
|
|||
UpdateLights();
|
||||
}
|
||||
|
||||
float UCarlaLight::GetLightIntensity()
|
||||
float UCarlaLight::GetLightIntensity() const
|
||||
{
|
||||
return LightIntensity;
|
||||
}
|
||||
|
@ -55,9 +59,10 @@ void UCarlaLight::SetLightColor(FLinearColor Color)
|
|||
{
|
||||
LightColor = Color;
|
||||
UpdateLights();
|
||||
RecordLightChange();
|
||||
}
|
||||
|
||||
FLinearColor UCarlaLight::GetLightColor()
|
||||
FLinearColor UCarlaLight::GetLightColor() const
|
||||
{
|
||||
return LightColor;
|
||||
}
|
||||
|
@ -66,9 +71,10 @@ void UCarlaLight::SetLightOn(bool bOn)
|
|||
{
|
||||
bLightOn = bOn;
|
||||
UpdateLights();
|
||||
RecordLightChange();
|
||||
}
|
||||
|
||||
bool UCarlaLight::GetLightOn()
|
||||
bool UCarlaLight::GetLightOn() const
|
||||
{
|
||||
return bLightOn;
|
||||
}
|
||||
|
@ -78,7 +84,7 @@ void UCarlaLight::SetLightType(ELightType Type)
|
|||
LightType = Type;
|
||||
}
|
||||
|
||||
ELightType UCarlaLight::GetLightType()
|
||||
ELightType UCarlaLight::GetLightType() const
|
||||
{
|
||||
return LightType;
|
||||
}
|
||||
|
@ -105,6 +111,7 @@ void UCarlaLight::SetLightState(carla::rpc::LightState LightState)
|
|||
LightType = static_cast<ELightType>(LightState._group);
|
||||
bLightOn = LightState._active;
|
||||
UpdateLights();
|
||||
RecordLightChange();
|
||||
}
|
||||
|
||||
FVector UCarlaLight::GetLocation() const
|
||||
|
@ -112,7 +119,22 @@ FVector UCarlaLight::GetLocation() const
|
|||
return GetOwner()->GetActorLocation();
|
||||
}
|
||||
|
||||
uint32 UCarlaLight::GetId() const
|
||||
int UCarlaLight::GetId() const
|
||||
{
|
||||
return GetUniqueID();
|
||||
return Id;
|
||||
}
|
||||
|
||||
void UCarlaLight::SetId(int InId)
|
||||
{
|
||||
Id = InId;
|
||||
}
|
||||
|
||||
void UCarlaLight::RecordLightChange() const
|
||||
{
|
||||
auto* Episode = UCarlaStatics::GetCurrentEpisode(GetWorld());
|
||||
auto* Recorder = Episode->GetRecorder();
|
||||
if (Recorder && Recorder->IsEnabled())
|
||||
{
|
||||
Recorder->AddEventLightSceneChanged(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,25 +52,25 @@ public:
|
|||
void SetLightIntensity(float Intensity);
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Carla Light")
|
||||
float GetLightIntensity();
|
||||
float GetLightIntensity() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Carla Light")
|
||||
void SetLightColor(FLinearColor Color);
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Carla Light")
|
||||
FLinearColor GetLightColor();
|
||||
FLinearColor GetLightColor() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Carla Light")
|
||||
void SetLightOn(bool bOn);
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Carla Light")
|
||||
bool GetLightOn();
|
||||
bool GetLightOn() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Carla Light")
|
||||
void SetLightType(ELightType Type);
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Carla Light")
|
||||
ELightType GetLightType();
|
||||
ELightType GetLightType() const;
|
||||
|
||||
carla::rpc::LightState GetLightState();
|
||||
|
||||
|
@ -78,7 +78,11 @@ public:
|
|||
|
||||
FVector GetLocation() const;
|
||||
|
||||
uint32 GetId() const;
|
||||
UFUNCTION(BlueprintPure, Category = "Carla Light")
|
||||
int GetId() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Carla Light")
|
||||
void SetId(int InId);
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -94,4 +98,10 @@ protected:
|
|||
UPROPERTY(EditAnywhere, Category = "Carla Light")
|
||||
bool bLightOn;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Carla Light")
|
||||
int Id = -1;
|
||||
|
||||
private:
|
||||
|
||||
void RecordLightChange() const;
|
||||
};
|
||||
|
|
|
@ -22,7 +22,13 @@ void UCarlaLightSubsystem::RegisterLight(UCarlaLight* CarlaLight)
|
|||
{
|
||||
if(CarlaLight)
|
||||
{
|
||||
Lights.Add(CarlaLight->GetId(), CarlaLight);
|
||||
auto LightId = CarlaLight->GetId();
|
||||
if (Lights.Contains(LightId))
|
||||
{
|
||||
UE_LOG(LogCarla, Warning, TEXT("Light Id overlapping"));
|
||||
return;
|
||||
}
|
||||
Lights.Add(LightId, CarlaLight);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,6 +91,15 @@ void UCarlaLightSubsystem::SetLights(
|
|||
|
||||
}
|
||||
|
||||
UCarlaLight* UCarlaLightSubsystem::GetLight(int Id)
|
||||
{
|
||||
if (Lights.Contains(Id))
|
||||
{
|
||||
return Lights[Id];
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void UCarlaLightSubsystem::SetClientStatesdirty(FString ClientThatUpdate)
|
||||
{
|
||||
for(auto& Client : ClientStates)
|
||||
|
|
|
@ -55,11 +55,12 @@ public:
|
|||
std::vector<carla::rpc::LightState> LightsToSet,
|
||||
bool DiscardClient = false);
|
||||
|
||||
UCarlaLight* GetLight(int Id);
|
||||
private:
|
||||
|
||||
void SetClientStatesdirty(FString ClientThatUpdate);
|
||||
|
||||
TMap<uint32, UCarlaLight* > Lights;
|
||||
TMap<int, UCarlaLight* > Lights;
|
||||
|
||||
// Flag for each client to tell if an update needs to be done
|
||||
TMap<FString, bool> ClientStates;
|
||||
|
|
|
@ -297,6 +297,7 @@ void ACarlaRecorder::Clear(void)
|
|||
Vehicles.Clear();
|
||||
Walkers.Clear();
|
||||
LightVehicles.Clear();
|
||||
LightScenes.Clear();
|
||||
}
|
||||
|
||||
void ACarlaRecorder::Write(double DeltaSeconds)
|
||||
|
@ -321,6 +322,7 @@ void ACarlaRecorder::Write(double DeltaSeconds)
|
|||
Vehicles.Write(File);
|
||||
Walkers.Write(File);
|
||||
LightVehicles.Write(File);
|
||||
LightScenes.Write(File);
|
||||
|
||||
// end
|
||||
Frames.WriteEnd(File);
|
||||
|
@ -425,6 +427,23 @@ void ACarlaRecorder::AddLightVehicle(const CarlaRecorderLightVehicle &LightVehic
|
|||
}
|
||||
}
|
||||
|
||||
void ACarlaRecorder::AddEventLightSceneChanged(const UCarlaLight* Light)
|
||||
{
|
||||
if (Enabled)
|
||||
{
|
||||
CarlaRecorderLightScene LightScene =
|
||||
{
|
||||
Light->GetId(),
|
||||
Light->GetLightIntensity(),
|
||||
Light->GetLightColor(),
|
||||
Light->GetLightOn(),
|
||||
static_cast<uint8>(Light->GetLightType())
|
||||
};
|
||||
|
||||
LightScenes.Add(LightScene);
|
||||
}
|
||||
}
|
||||
|
||||
void ACarlaRecorder::AddExistingActors(void)
|
||||
{
|
||||
// registring all existing actors in first frame
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "Carla/Actor/ActorDescription.h"
|
||||
|
||||
#include "CarlaRecorderLightScene.h"
|
||||
#include "CarlaRecorderLightVehicle.h"
|
||||
#include "CarlaRecorderAnimVehicle.h"
|
||||
#include "CarlaRecorderAnimWalker.h"
|
||||
|
@ -30,7 +31,7 @@
|
|||
class AActor;
|
||||
class UCarlaEpisode;
|
||||
class ACarlaWheeledVehicle;
|
||||
struct FVehicleLightState;
|
||||
class UCarlaLight;
|
||||
|
||||
enum class CarlaRecorderPacketId : uint8_t
|
||||
{
|
||||
|
@ -96,6 +97,8 @@ public:
|
|||
|
||||
void AddLightVehicle(const CarlaRecorderLightVehicle &LightVehicle);
|
||||
|
||||
void AddEventLightSceneChanged(const UCarlaLight* Light);
|
||||
|
||||
// set episode
|
||||
void SetEpisode(UCarlaEpisode *ThisEpisode)
|
||||
{
|
||||
|
@ -150,6 +153,7 @@ private:
|
|||
CarlaRecorderAnimVehicles Vehicles;
|
||||
CarlaRecorderAnimWalkers Walkers;
|
||||
CarlaRecorderLightVehicles LightVehicles;
|
||||
CarlaRecorderLightScenes LightScenes;
|
||||
|
||||
// replayer
|
||||
CarlaReplayer Replayer;
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
// Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma
|
||||
// de Barcelona (UAB).
|
||||
//
|
||||
// This work is licensed under the terms of the MIT license.
|
||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
#include "CarlaRecorderLightScene.h"
|
||||
#include "CarlaRecorder.h"
|
||||
#include "CarlaRecorderHelpers.h"
|
||||
|
||||
|
||||
void CarlaRecorderLightScene::Write(std::ofstream &OutFile)
|
||||
{
|
||||
WriteValue<int>(OutFile, this->LightId);
|
||||
WriteValue<float>(OutFile, this->Intensity);
|
||||
WriteValue<FLinearColor>(OutFile, this->Color);
|
||||
WriteValue<bool>(OutFile, this->bOn);
|
||||
WriteValue<uint8>(OutFile, this->Type);
|
||||
}
|
||||
void CarlaRecorderLightScene::Read(std::ifstream &InFile)
|
||||
{
|
||||
ReadValue<int>(InFile, this->LightId);
|
||||
ReadValue<float>(InFile, this->Intensity);
|
||||
ReadValue<FLinearColor>(InFile, this->Color);
|
||||
ReadValue<bool>(InFile, this->bOn);
|
||||
ReadValue<uint8>(InFile, this->Type);
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
|
||||
void CarlaRecorderLightScenes::Clear(void)
|
||||
{
|
||||
Lights.clear();
|
||||
}
|
||||
|
||||
void CarlaRecorderLightScenes::Add(const CarlaRecorderLightScene &Vehicle)
|
||||
{
|
||||
Lights.push_back(Vehicle);
|
||||
}
|
||||
|
||||
void CarlaRecorderLightScenes::Write(std::ofstream &OutFile)
|
||||
{
|
||||
// write the packet id
|
||||
WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::SceneLight));
|
||||
|
||||
std::streampos PosStart = OutFile.tellp();
|
||||
|
||||
// write a dummy packet size
|
||||
uint32_t Total = 0;
|
||||
WriteValue<uint32_t>(OutFile, Total);
|
||||
|
||||
// write total records
|
||||
Total = Lights.size();
|
||||
WriteValue<uint16_t>(OutFile, Total);
|
||||
|
||||
for (uint16_t i=0; i<Total; ++i)
|
||||
Lights[i].Write(OutFile);
|
||||
|
||||
// write the real packet size
|
||||
std::streampos PosEnd = OutFile.tellp();
|
||||
Total = PosEnd - PosStart - sizeof(uint32_t);
|
||||
OutFile.seekp(PosStart, std::ios::beg);
|
||||
WriteValue<uint32_t>(OutFile, Total);
|
||||
OutFile.seekp(PosEnd, std::ios::beg);
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
// Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma
|
||||
// de Barcelona (UAB).
|
||||
//
|
||||
// This work is licensed under the terms of the MIT license.
|
||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <type_traits>
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct CarlaRecorderLightScene
|
||||
{
|
||||
|
||||
int LightId;
|
||||
float Intensity;
|
||||
FLinearColor Color;
|
||||
bool bOn;
|
||||
uint8 Type;
|
||||
|
||||
void Read(std::ifstream &InFile);
|
||||
|
||||
void Write(std::ofstream &OutFile);
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
struct CarlaRecorderLightScenes
|
||||
{
|
||||
public:
|
||||
|
||||
void Add(const CarlaRecorderLightScene &InObj);
|
||||
|
||||
void Clear(void);
|
||||
|
||||
void Write(std::ofstream &OutFile);
|
||||
|
||||
private:
|
||||
|
||||
std::vector<CarlaRecorderLightScene> Lights;
|
||||
};
|
|
@ -341,6 +341,14 @@ void CarlaReplayer::ProcessToTime(double Time, bool IsFirstTime)
|
|||
SkipPacket();
|
||||
break;
|
||||
|
||||
// scene lights animation
|
||||
case static_cast<char>(CarlaRecorderPacketId::SceneLight):
|
||||
if (bFrameFound)
|
||||
ProcessLightScene();
|
||||
else
|
||||
SkipPacket();
|
||||
break;
|
||||
|
||||
// frame end
|
||||
case static_cast<char>(CarlaRecorderPacketId::FrameEnd):
|
||||
if (bFrameFound)
|
||||
|
@ -542,6 +550,20 @@ void CarlaReplayer::ProcessLightVehicle(void)
|
|||
}
|
||||
}
|
||||
|
||||
void CarlaReplayer::ProcessLightScene(void)
|
||||
{
|
||||
uint16_t Total;
|
||||
CarlaRecorderLightScene LightScene;
|
||||
|
||||
// read Total walkers
|
||||
ReadValue<uint16_t>(File, Total);
|
||||
for (uint16_t i = 0; i < Total; ++i)
|
||||
{
|
||||
LightScene.Read(File);
|
||||
Helper.ProcessReplayerLightScene(LightScene);
|
||||
}
|
||||
}
|
||||
|
||||
void CarlaReplayer::ProcessPositions(bool IsFirstTime)
|
||||
{
|
||||
uint16_t i, Total;
|
||||
|
|
|
@ -142,6 +142,7 @@ private:
|
|||
void ProcessAnimWalker(void);
|
||||
|
||||
void ProcessLightVehicle(void);
|
||||
void ProcessLightScene(void);
|
||||
|
||||
// positions
|
||||
void UpdatePositions(double Per, double DeltaTime);
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
#include "Carla/Vehicle/WheeledVehicleAIController.h"
|
||||
#include "Carla/Walker/WalkerControl.h"
|
||||
#include "Carla/Walker/WalkerController.h"
|
||||
#include "Carla/Lights/CarlaLight.h"
|
||||
#include "Carla/Lights/CarlaLightSubsystem.h"
|
||||
|
||||
// create or reuse an actor for replaying
|
||||
std::pair<int, FActorView>CarlaReplayerHelper::TryToCreateReplayerActor(
|
||||
|
@ -349,6 +351,28 @@ void CarlaReplayerHelper::ProcessReplayerLightVehicle(CarlaRecorderLightVehicle
|
|||
}
|
||||
}
|
||||
|
||||
void CarlaReplayerHelper::ProcessReplayerLightScene(CarlaRecorderLightScene LightScene)
|
||||
{
|
||||
check(Episode != nullptr);
|
||||
UWorld* World = Episode->GetWorld();
|
||||
if(World)
|
||||
{
|
||||
UCarlaLightSubsystem* CarlaLightSubsystem = World->GetSubsystem<UCarlaLightSubsystem>();
|
||||
if (!CarlaLightSubsystem)
|
||||
{
|
||||
return;
|
||||
}
|
||||
auto* CarlaLight = CarlaLightSubsystem->GetLight(LightScene.LightId);
|
||||
if (CarlaLight)
|
||||
{
|
||||
CarlaLight->SetLightIntensity(LightScene.Intensity);
|
||||
CarlaLight->SetLightColor(LightScene.Color);
|
||||
CarlaLight->SetLightOn(LightScene.bOn);
|
||||
CarlaLight->SetLightType(static_cast<ELightType>(LightScene.Type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set the animation for walkers
|
||||
void CarlaReplayerHelper::ProcessReplayerAnimWalker(CarlaRecorderAnimWalker Walker)
|
||||
{
|
||||
|
|
|
@ -50,6 +50,9 @@ public:
|
|||
// set the vehicle light
|
||||
void ProcessReplayerLightVehicle(CarlaRecorderLightVehicle LightVehicle);
|
||||
|
||||
// set scene lights
|
||||
void ProcessReplayerLightScene(CarlaRecorderLightScene LightScene);
|
||||
|
||||
// replay finish
|
||||
bool ProcessReplayerFinish(bool bApplyAutopilot, bool bIgnoreHero, std::unordered_map<uint32_t, bool> &IsHero);
|
||||
|
||||
|
|
Loading…
Reference in New Issue