CARLA
 
载入中...
搜索中...
未找到
TrafficLightGroup.cpp
浏览该文件的文档.
1// Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#include "Carla.h"
9#include "TrafficLightGroup.h"
10
11
12// Sets default values
14{
15 // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
16 PrimaryActorTick.bCanEverTick = true;
17 SceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
18 RootComponent = SceneComponent;
19}
20
22{
23 bIsFrozen = InFreeze;
24}
25
27{
28 return bIsFrozen;
29}
30
32{
33 for(auto * Controller : Controllers)
34 {
35 Controller->ResetState();
36 }
39 controller->StartCycle();
40}
41
42// Called every frame
43void ATrafficLightGroup::Tick(float DeltaTime)
44{
45 TRACE_CPUPROFILER_EVENT_SCOPE(ATrafficLightGroup::Tick);
46 Super::Tick(DeltaTime);
47
48 // Do not update if the replayer is replaying
49 auto* Episode = UCarlaStatics::GetCurrentEpisode(GetWorld());
50 if (Episode)
51 {
52 auto* Replayer = Episode->GetReplayer();
53 if (Replayer)
54 {
55 if(Replayer->IsEnabled())
56 {
57 return;
58 }
59 }
60 }
61
62 if (bIsFrozen)
63 {
64 return;
65 }
66
68 if (controller->AdvanceTimeAndCycleFinished(DeltaTime))
69 {
71 }
72}
73
80
82{
83 return JunctionId;
84}
85
87{
88 Controllers.Add(Controller);
89 Controller->SetGroup(this);
90}
virtual void Tick(float DeltaTime) override
void SetFrozenGroup(bool InFreeze)
TArray< UTrafficLightController * > Controllers
void AddController(UTrafficLightController *Controller)
USceneComponent * SceneComponent
static UCarlaEpisode * GetCurrentEpisode(const UObject *WorldContextObject)
Maps a controller from OpenDrive.
void SetGroup(ATrafficLightGroup *Group)
bool AdvanceTimeAndCycleFinished(float DeltaTime)