Fixed recorder for traffic lights in standalone mode.
This commit is contained in:
parent
fda71fe6e0
commit
3ef383157d
|
@ -70,8 +70,8 @@ static auto FWorldObserver_GetActorState(const FActorView &View, const FActorReg
|
||||||
auto TrafficLight = Cast<ATrafficLightBase>(View.GetActor());
|
auto TrafficLight = Cast<ATrafficLightBase>(View.GetActor());
|
||||||
if (TrafficLight != nullptr)
|
if (TrafficLight != nullptr)
|
||||||
{
|
{
|
||||||
UTrafficLightComponent* TrafficLightComponent =
|
auto* TrafficLightComponent =
|
||||||
Cast<UTrafficLightComponent>(TrafficLight->FindComponentByClass<UTrafficLightComponent>());
|
TrafficLight->GetTrafficLightComponent();
|
||||||
|
|
||||||
using TLS = carla::rpc::TrafficLightState;
|
using TLS = carla::rpc::TrafficLightState;
|
||||||
|
|
||||||
|
@ -89,8 +89,8 @@ static auto FWorldObserver_GetActorState(const FActorView &View, const FActorReg
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UTrafficLightController* Controller = TrafficLightComponent->GetController();
|
const UTrafficLightController* Controller = TrafficLightComponent->GetController();
|
||||||
ATrafficLightGroup* Group = TrafficLightComponent->GetGroup();
|
const ATrafficLightGroup* Group = TrafficLightComponent->GetGroup();
|
||||||
|
|
||||||
if (!Controller)
|
if (!Controller)
|
||||||
{
|
{
|
||||||
|
|
|
@ -53,7 +53,7 @@ void ATrafficLightBase::Tick(float DeltaSeconds)
|
||||||
{
|
{
|
||||||
Super::Tick(DeltaSeconds);
|
Super::Tick(DeltaSeconds);
|
||||||
|
|
||||||
if (TimeIsFrozen)
|
if (TimeIsFrozen || TrafficLightComponent)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -103,14 +103,26 @@ void ATrafficLightBase::PostEditChangeProperty(FPropertyChangedEvent &Event)
|
||||||
}
|
}
|
||||||
#endif // WITH_EDITOR
|
#endif // WITH_EDITOR
|
||||||
|
|
||||||
|
ETrafficLightState ATrafficLightBase::GetTrafficLightState() const
|
||||||
|
{
|
||||||
|
if (TrafficLightComponent)
|
||||||
|
{
|
||||||
|
return TrafficLightComponent->GetLightState();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return State;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ATrafficLightBase::SetTrafficLightState(const ETrafficLightState InState)
|
void ATrafficLightBase::SetTrafficLightState(const ETrafficLightState InState)
|
||||||
{
|
{
|
||||||
UTrafficLightComponent* TrafficLightComponent =
|
if(TrafficLightComponent)
|
||||||
Cast<UTrafficLightComponent>(FindComponentByClass<UTrafficLightComponent>());
|
{
|
||||||
|
|
||||||
if(TrafficLightComponent) {
|
|
||||||
TrafficLightComponent->SetLightState(InState);
|
TrafficLightComponent->SetLightState(InState);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ElapsedTime = 0.0f;
|
ElapsedTime = 0.0f;
|
||||||
State = InState;
|
State = InState;
|
||||||
SetTrafficSignState(ToTrafficSignState(State));
|
SetTrafficSignState(ToTrafficSignState(State));
|
||||||
|
@ -185,83 +197,128 @@ void ATrafficLightBase::UnNotifyWheeledVehicle(ACarlaWheeledVehicle *Vehicle)
|
||||||
|
|
||||||
void ATrafficLightBase::SetGreenTime(float InGreenTime)
|
void ATrafficLightBase::SetGreenTime(float InGreenTime)
|
||||||
{
|
{
|
||||||
UTrafficLightComponent* TrafficLightComponent =
|
if(TrafficLightComponent)
|
||||||
Cast<UTrafficLightComponent>(FindComponentByClass<UTrafficLightComponent>());
|
{
|
||||||
|
|
||||||
if(TrafficLightComponent) {
|
|
||||||
UTrafficLightController* TrafficLightController =
|
UTrafficLightController* TrafficLightController =
|
||||||
TrafficLightComponent->GetController();
|
TrafficLightComponent->GetController();
|
||||||
check(TrafficLightController)
|
check(TrafficLightController)
|
||||||
TrafficLightController->SetGreenTime(InGreenTime);
|
TrafficLightController->SetGreenTime(InGreenTime);
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
GreenTime = InGreenTime;
|
GreenTime = InGreenTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float ATrafficLightBase::GetGreenTime() const
|
float ATrafficLightBase::GetGreenTime() const
|
||||||
|
{
|
||||||
|
if (TrafficLightComponent)
|
||||||
|
{
|
||||||
|
auto* Controller = TrafficLightComponent->GetController();
|
||||||
|
check(Controller);
|
||||||
|
return Controller->GetGreenTime();
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
return GreenTime;
|
return GreenTime;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ATrafficLightBase::SetYellowTime(float InYellowTime)
|
void ATrafficLightBase::SetYellowTime(float InYellowTime)
|
||||||
{
|
{
|
||||||
UTrafficLightComponent* TrafficLightComponent =
|
if(TrafficLightComponent)
|
||||||
Cast<UTrafficLightComponent>(FindComponentByClass<UTrafficLightComponent>());
|
{
|
||||||
|
|
||||||
if(TrafficLightComponent) {
|
|
||||||
UTrafficLightController* TrafficLightController =
|
UTrafficLightController* TrafficLightController =
|
||||||
TrafficLightComponent->GetController();
|
TrafficLightComponent->GetController();
|
||||||
check(TrafficLightController)
|
check(TrafficLightController)
|
||||||
TrafficLightController->SetYellowTime(InYellowTime);
|
TrafficLightController->SetYellowTime(InYellowTime);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
YellowTime = InYellowTime;
|
YellowTime = InYellowTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float ATrafficLightBase::GetYellowTime() const
|
float ATrafficLightBase::GetYellowTime() const
|
||||||
|
{
|
||||||
|
if (TrafficLightComponent)
|
||||||
|
{
|
||||||
|
auto* Controller = TrafficLightComponent->GetController();
|
||||||
|
check(Controller);
|
||||||
|
return Controller->GetYellowTime();
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
return YellowTime;
|
return YellowTime;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ATrafficLightBase::SetRedTime(float InRedTime)
|
void ATrafficLightBase::SetRedTime(float InRedTime)
|
||||||
{
|
{
|
||||||
UTrafficLightComponent* TrafficLightComponent =
|
if(TrafficLightComponent)
|
||||||
Cast<UTrafficLightComponent>(FindComponentByClass<UTrafficLightComponent>());
|
{
|
||||||
|
|
||||||
if(TrafficLightComponent) {
|
|
||||||
UTrafficLightController* TrafficLightController =
|
UTrafficLightController* TrafficLightController =
|
||||||
TrafficLightComponent->GetController();
|
TrafficLightComponent->GetController();
|
||||||
check(TrafficLightController)
|
check(TrafficLightController)
|
||||||
TrafficLightController->SetRedTime(InRedTime);
|
TrafficLightController->SetRedTime(InRedTime);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
RedTime = InRedTime;
|
RedTime = InRedTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float ATrafficLightBase::GetRedTime() const
|
float ATrafficLightBase::GetRedTime() const
|
||||||
|
{
|
||||||
|
if (TrafficLightComponent)
|
||||||
|
{
|
||||||
|
auto* Controller = TrafficLightComponent->GetController();
|
||||||
|
check(Controller);
|
||||||
|
return Controller->GetRedTime();
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
return RedTime;
|
return RedTime;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
float ATrafficLightBase::GetElapsedTime() const
|
float ATrafficLightBase::GetElapsedTime() const
|
||||||
|
{
|
||||||
|
if (TrafficLightComponent)
|
||||||
|
{
|
||||||
|
auto* Group = TrafficLightComponent->GetGroup();
|
||||||
|
check(Group);
|
||||||
|
return Group->GetElapsedTime();
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
return ElapsedTime;
|
return ElapsedTime;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ATrafficLightBase::SetElapsedTime(float InElapsedTime)
|
void ATrafficLightBase::SetElapsedTime(float InElapsedTime)
|
||||||
|
{
|
||||||
|
if (TrafficLightComponent)
|
||||||
|
{
|
||||||
|
auto* Group = TrafficLightComponent->GetGroup();
|
||||||
|
check(Group);
|
||||||
|
return Group->SetElapsedTime(InElapsedTime);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
ElapsedTime = InElapsedTime;
|
ElapsedTime = InElapsedTime;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ATrafficLightBase::SetTimeIsFrozen(bool InTimeIsFrozen)
|
void ATrafficLightBase::SetTimeIsFrozen(bool InTimeIsFrozen)
|
||||||
{
|
{
|
||||||
UTrafficLightComponent* TrafficLightComponent =
|
if(TrafficLightComponent)
|
||||||
Cast<UTrafficLightComponent>(FindComponentByClass<UTrafficLightComponent>());
|
{
|
||||||
|
|
||||||
if(TrafficLightComponent) {
|
|
||||||
TrafficLightComponent->SetFrozenGroup(InTimeIsFrozen);
|
TrafficLightComponent->SetFrozenGroup(InTimeIsFrozen);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
TimeIsFrozen = InTimeIsFrozen;
|
TimeIsFrozen = InTimeIsFrozen;
|
||||||
if (!TimeIsFrozen)
|
if (!TimeIsFrozen)
|
||||||
{
|
{
|
||||||
|
@ -272,6 +329,12 @@ void ATrafficLightBase::SetTimeIsFrozen(bool InTimeIsFrozen)
|
||||||
|
|
||||||
bool ATrafficLightBase::GetTimeIsFrozen() const
|
bool ATrafficLightBase::GetTimeIsFrozen() const
|
||||||
{
|
{
|
||||||
|
if(TrafficLightComponent)
|
||||||
|
{
|
||||||
|
auto* Group = TrafficLightComponent->GetGroup();
|
||||||
|
check(Group);
|
||||||
|
return Group->IsFrozen();
|
||||||
|
}
|
||||||
return TimeIsFrozen;
|
return TimeIsFrozen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,10 +350,8 @@ int ATrafficLightBase::GetPoleIndex() const
|
||||||
|
|
||||||
TArray<ATrafficLightBase *> ATrafficLightBase::GetGroupTrafficLights() const
|
TArray<ATrafficLightBase *> ATrafficLightBase::GetGroupTrafficLights() const
|
||||||
{
|
{
|
||||||
UTrafficLightComponent* TrafficLightComponent =
|
if(TrafficLightComponent)
|
||||||
Cast<UTrafficLightComponent>(FindComponentByClass<UTrafficLightComponent>());
|
{
|
||||||
|
|
||||||
if(TrafficLightComponent) {
|
|
||||||
TArray<ATrafficLightBase *> result;
|
TArray<ATrafficLightBase *> result;
|
||||||
|
|
||||||
ATrafficLightGroup* Group = TrafficLightComponent->GetGroup();
|
ATrafficLightGroup* Group = TrafficLightComponent->GetGroup();
|
||||||
|
@ -313,3 +374,22 @@ void ATrafficLightBase::SetGroupTrafficLights(TArray<ATrafficLightBase *> InGrou
|
||||||
{
|
{
|
||||||
GroupTrafficLights = InGroupTrafficLights;
|
GroupTrafficLights = InGroupTrafficLights;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UTrafficLightComponent* ATrafficLightBase::CreateTrafficLightComponent()
|
||||||
|
{
|
||||||
|
TrafficLightComponent = NewObject<UTrafficLightComponent>(RootComponent);
|
||||||
|
TrafficLightComponent->RegisterComponent();
|
||||||
|
TrafficLightComponent->AttachToComponent(
|
||||||
|
GetRootComponent(),
|
||||||
|
FAttachmentTransformRules::KeepRelativeTransform);
|
||||||
|
return TrafficLightComponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
UTrafficLightComponent* ATrafficLightBase::GetTrafficLightComponent()
|
||||||
|
{
|
||||||
|
return TrafficLightComponent;
|
||||||
|
}
|
||||||
|
const UTrafficLightComponent* ATrafficLightBase::GetTrafficLightComponent() const
|
||||||
|
{
|
||||||
|
return TrafficLightComponent;
|
||||||
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "Traffic/TrafficSignBase.h"
|
#include "Traffic/TrafficSignBase.h"
|
||||||
|
|
||||||
#include "Traffic/TrafficLightState.h"
|
#include "Traffic/TrafficLightState.h"
|
||||||
|
#include "Traffic/TrafficLightComponent.h"
|
||||||
|
|
||||||
#include "TrafficLightBase.generated.h"
|
#include "TrafficLightBase.generated.h"
|
||||||
|
|
||||||
|
@ -39,10 +40,7 @@ protected:
|
||||||
public:
|
public:
|
||||||
|
|
||||||
UFUNCTION(Category = "Traffic Light", BlueprintCallable)
|
UFUNCTION(Category = "Traffic Light", BlueprintCallable)
|
||||||
ETrafficLightState GetTrafficLightState() const
|
ETrafficLightState GetTrafficLightState() const;
|
||||||
{
|
|
||||||
return State;
|
|
||||||
}
|
|
||||||
|
|
||||||
UFUNCTION(Category = "Traffic Light", BlueprintCallable)
|
UFUNCTION(Category = "Traffic Light", BlueprintCallable)
|
||||||
void SetTrafficLightState(ETrafficLightState State);
|
void SetTrafficLightState(ETrafficLightState State);
|
||||||
|
@ -99,6 +97,11 @@ public:
|
||||||
// used from replayer
|
// used from replayer
|
||||||
void SetElapsedTime(float InElapsedTime);
|
void SetElapsedTime(float InElapsedTime);
|
||||||
|
|
||||||
|
UTrafficLightComponent* CreateTrafficLightComponent();
|
||||||
|
|
||||||
|
UTrafficLightComponent* GetTrafficLightComponent();
|
||||||
|
const UTrafficLightComponent* GetTrafficLightComponent() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
UFUNCTION(Category = "Traffic Light", BlueprintImplementableEvent)
|
UFUNCTION(Category = "Traffic Light", BlueprintImplementableEvent)
|
||||||
|
@ -132,4 +135,7 @@ private:
|
||||||
|
|
||||||
UPROPERTY(Category = "Traffic Light", VisibleAnywhere)
|
UPROPERTY(Category = "Traffic Light", VisibleAnywhere)
|
||||||
TArray<ATrafficLightBase *> GroupTrafficLights;
|
TArray<ATrafficLightBase *> GroupTrafficLights;
|
||||||
|
|
||||||
|
UPROPERTY(Category = "Traffic Light", EditAnywhere)
|
||||||
|
UTrafficLightComponent * TrafficLightComponent = nullptr;
|
||||||
};
|
};
|
||||||
|
|
|
@ -114,11 +114,21 @@ ATrafficLightGroup* UTrafficLightComponent::GetGroup()
|
||||||
return TrafficLightGroup;
|
return TrafficLightGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ATrafficLightGroup* UTrafficLightComponent::GetGroup() const
|
||||||
|
{
|
||||||
|
return TrafficLightGroup;
|
||||||
|
}
|
||||||
|
|
||||||
UTrafficLightController* UTrafficLightComponent::GetController()
|
UTrafficLightController* UTrafficLightComponent::GetController()
|
||||||
{
|
{
|
||||||
return TrafficLightController;
|
return TrafficLightController;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const UTrafficLightController* UTrafficLightComponent::GetController() const
|
||||||
|
{
|
||||||
|
return TrafficLightController;
|
||||||
|
}
|
||||||
|
|
||||||
void UTrafficLightComponent::OnOverlapTriggerBox(UPrimitiveComponent *OverlappedComp,
|
void UTrafficLightComponent::OnOverlapTriggerBox(UPrimitiveComponent *OverlappedComp,
|
||||||
AActor *OtherActor,
|
AActor *OtherActor,
|
||||||
UPrimitiveComponent *OtherComp,
|
UPrimitiveComponent *OtherComp,
|
||||||
|
|
|
@ -41,9 +41,13 @@ public:
|
||||||
UFUNCTION(Category = "Traffic Light", BlueprintPure)
|
UFUNCTION(Category = "Traffic Light", BlueprintPure)
|
||||||
ATrafficLightGroup* GetGroup();
|
ATrafficLightGroup* GetGroup();
|
||||||
|
|
||||||
|
const ATrafficLightGroup* GetGroup() const;
|
||||||
|
|
||||||
UFUNCTION(Category = "Traffic Light", BlueprintPure)
|
UFUNCTION(Category = "Traffic Light", BlueprintPure)
|
||||||
UTrafficLightController* GetController();
|
UTrafficLightController* GetController();
|
||||||
|
|
||||||
|
const UTrafficLightController* GetController() const;
|
||||||
|
|
||||||
virtual void InitializeSign(const carla::road::Map &Map) override;
|
virtual void InitializeSign(const carla::road::Map &Map) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -22,7 +22,7 @@ void ATrafficLightGroup::SetFrozenGroup(bool InFreeze)
|
||||||
bIsFrozen = InFreeze;
|
bIsFrozen = InFreeze;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ATrafficLightGroup::IsFrozen()
|
bool ATrafficLightGroup::IsFrozen() const
|
||||||
{
|
{
|
||||||
return bIsFrozen;
|
return bIsFrozen;
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,11 @@ float ATrafficLightGroup::GetElapsedTime() const
|
||||||
return (CurrentStateTimer - Timer);
|
return (CurrentStateTimer - Timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ATrafficLightGroup::SetElapsedTime(float ElapsedTime)
|
||||||
|
{
|
||||||
|
Timer = CurrentStateTimer - ElapsedTime;
|
||||||
|
}
|
||||||
|
|
||||||
// Called every frame
|
// Called every frame
|
||||||
void ATrafficLightGroup::Tick(float DeltaTime)
|
void ATrafficLightGroup::Tick(float DeltaTime)
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,7 +35,7 @@ public:
|
||||||
void SetFrozenGroup(bool InFreeze);
|
void SetFrozenGroup(bool InFreeze);
|
||||||
|
|
||||||
UFUNCTION(Category = "Traffic Group", BlueprintCallable)
|
UFUNCTION(Category = "Traffic Group", BlueprintCallable)
|
||||||
bool IsFrozen();
|
bool IsFrozen() const;
|
||||||
|
|
||||||
UFUNCTION(Category = "Traffic Group", BlueprintPure)
|
UFUNCTION(Category = "Traffic Group", BlueprintPure)
|
||||||
int GetJunctionId() const;
|
int GetJunctionId() const;
|
||||||
|
@ -46,6 +46,9 @@ public:
|
||||||
UFUNCTION(Category = "Traffic Group", BlueprintCallable)
|
UFUNCTION(Category = "Traffic Group", BlueprintCallable)
|
||||||
float GetElapsedTime() const;
|
float GetElapsedTime() const;
|
||||||
|
|
||||||
|
UFUNCTION(Category = "Traffic Group", BlueprintCallable)
|
||||||
|
void SetElapsedTime(float ElapsedTime);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Called every frame
|
// Called every frame
|
||||||
virtual void Tick(float DeltaTime) override;
|
virtual void Tick(float DeltaTime) override;
|
||||||
|
|
|
@ -213,11 +213,11 @@ void ATrafficLightManager::ResetTrafficLightObjects()
|
||||||
}
|
}
|
||||||
TrafficControllers.Empty();
|
TrafficControllers.Empty();
|
||||||
|
|
||||||
for (TActorIterator<ATrafficSignBase> It(GetWorld()); It; ++It)
|
for (TActorIterator<ATrafficLightBase> It(GetWorld()); It; ++It)
|
||||||
{
|
{
|
||||||
ATrafficSignBase* trafficSignBase = (*It);
|
ATrafficLightBase* trafficSignBase = (*It);
|
||||||
UTrafficLightComponent* TrafficLightComponent =
|
UTrafficLightComponent* TrafficLightComponent =
|
||||||
trafficSignBase->FindComponentByClass<UTrafficLightComponent>();
|
trafficSignBase->GetTrafficLightComponent();
|
||||||
|
|
||||||
if(TrafficLightComponent)
|
if(TrafficLightComponent)
|
||||||
{
|
{
|
||||||
|
@ -290,13 +290,8 @@ void ATrafficLightManager::SpawnTrafficLights()
|
||||||
|
|
||||||
TrafficSigns.Add(TrafficLight);
|
TrafficSigns.Add(TrafficLight);
|
||||||
|
|
||||||
UTrafficLightComponent *TrafficLightComponent =
|
UTrafficLightComponent *TrafficLightComponent = TrafficLight->CreateTrafficLightComponent();
|
||||||
NewObject<UTrafficLightComponent>(TrafficLight);
|
|
||||||
TrafficLightComponent->SetSignId(SignalId.c_str());
|
TrafficLightComponent->SetSignId(SignalId.c_str());
|
||||||
TrafficLightComponent->RegisterComponent();
|
|
||||||
TrafficLightComponent->AttachToComponent(
|
|
||||||
TrafficLight->GetRootComponent(),
|
|
||||||
FAttachmentTransformRules::KeepRelativeTransform);
|
|
||||||
|
|
||||||
auto ClosestWaypointToSignal =
|
auto ClosestWaypointToSignal =
|
||||||
GetMap()->GetClosestWaypointOnRoad(CarlaTransform.location);
|
GetMap()->GetClosestWaypointOnRoad(CarlaTransform.location);
|
||||||
|
|
Loading…
Reference in New Issue