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