Fixed merge issues
This commit is contained in:
parent
f34b884fc1
commit
346a513099
|
@ -304,8 +304,6 @@ TArray<ATrafficLightBase *> ATrafficLightBase::GetGroupTrafficLights() const
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
return GroupTrafficLights;
|
||||
|
|
|
@ -17,38 +17,6 @@ UTrafficLightComponent::UTrafficLightComponent()
|
|||
{
|
||||
}
|
||||
|
||||
// Called when the game starts
|
||||
void UTrafficLightComponent::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
// Search the Traffic Light Manager
|
||||
TArray<AActor*> TrafficLightManagerArray;
|
||||
UGameplayStatics::GetAllActorsOfClass(
|
||||
GetWorld(),
|
||||
ATrafficLightManager::StaticClass(),
|
||||
TrafficLightManagerArray);
|
||||
|
||||
// Create it if missing
|
||||
if (!TrafficLightManagerArray.Num())
|
||||
{
|
||||
TrafficLightManagerArray.Add(
|
||||
GetWorld()->SpawnActor<ATrafficLightManager>());
|
||||
}
|
||||
|
||||
// Register this component
|
||||
ATrafficLightManager *TrafficLightManager =
|
||||
Cast<ATrafficLightManager>(TrafficLightManagerArray.Top());
|
||||
|
||||
TrafficLightManager->RegisterLightComponent(this);
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
void UTrafficLightComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
||||
{
|
||||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||
}
|
||||
|
||||
void UTrafficLightComponent::SetLightState(ETrafficLightState NewState)
|
||||
{
|
||||
LightState = NewState;
|
||||
|
|
|
@ -43,13 +43,6 @@ public:
|
|||
UFUNCTION(Category = "Traffic Light", BlueprintPure)
|
||||
UTrafficLightController* GetController();
|
||||
|
||||
protected:
|
||||
// Called when the game starts
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
// Called every frame
|
||||
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
||||
|
||||
private:
|
||||
|
||||
friend ATrafficLightManager;
|
||||
|
|
|
@ -34,7 +34,11 @@ void ATrafficLightGroup::ResetGroup()
|
|||
Controller->ResetState();
|
||||
}
|
||||
CurrentController = 0;
|
||||
Timer = Controllers[CurrentController]->NextState();
|
||||
if(Controllers.Num() > 0) {
|
||||
Timer = Controllers[CurrentController]->NextState();
|
||||
} else {
|
||||
Timer = 0.0f;
|
||||
}
|
||||
CurrentStateTimer = Timer;
|
||||
}
|
||||
|
||||
|
@ -43,13 +47,6 @@ float ATrafficLightGroup::GetElapsedTime() const
|
|||
return (CurrentStateTimer - Timer);
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
void ATrafficLightGroup::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
void ATrafficLightGroup::Tick(float DeltaTime)
|
||||
{
|
||||
|
|
|
@ -47,9 +47,6 @@ public:
|
|||
float GetElapsedTime() const;
|
||||
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
// Called every frame
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
|
|
|
@ -76,14 +76,12 @@ void ATrafficLightManager::RegisterLightComponent(UTrafficLightComponent * Traff
|
|||
TrafficLightComponent->TrafficLightGroup = TrafficLightGroup;
|
||||
TrafficLightComponent->TrafficLightController = TrafficLightController;
|
||||
|
||||
std::cout << "ATrafficLightManager::RegisterLightComponent TrafficLightController" << TrafficLightController << std::endl;
|
||||
|
||||
// Add signal to controller
|
||||
TrafficLightController->AddTrafficLight(TrafficLightComponent);
|
||||
TrafficLightController->ResetState();
|
||||
|
||||
// Add signal to map
|
||||
TrafficLights.Add(TrafficLight->GetSignId(), TrafficLight);
|
||||
TrafficLightComponents.Add(TrafficLightComponent->GetSignId(), TrafficLightComponent);
|
||||
|
||||
TrafficLightGroup->ResetGroup();
|
||||
}
|
||||
|
@ -95,8 +93,7 @@ const boost::optional<carla::road::Map>& ATrafficLightManager::GetMap()
|
|||
FString MapName = GetWorld()->GetName();
|
||||
std::string opendrive_xml = carla::rpc::FromFString(UOpenDrive::LoadXODR(MapName));
|
||||
Map = carla::opendrive::OpenDriveParser::Load(opendrive_xml);
|
||||
if (!Map.has_value())
|
||||
{
|
||||
if (!Map.has_value()) {
|
||||
UE_LOG(LogCarla, Error, TEXT("Invalid Map"));
|
||||
}
|
||||
}
|
||||
|
@ -105,46 +102,51 @@ const boost::optional<carla::road::Map>& ATrafficLightManager::GetMap()
|
|||
|
||||
void ATrafficLightManager::GenerateTrafficLights()
|
||||
{
|
||||
if(!TrafficLightModel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& Signals = GetMap()->GetSignals();
|
||||
for(const auto& ControllerPair : GetMap()->GetControllers())
|
||||
{
|
||||
const auto& Controller = ControllerPair.second;
|
||||
for(const auto& SignalId : Controller->GetSignals())
|
||||
if(!TrafficLightsGenerated){
|
||||
if(!TrafficLightModel)
|
||||
{
|
||||
const auto& Signal = Signals.at(SignalId);
|
||||
auto CarlaTransform = Signal->GetTransform();
|
||||
FTransform SpawnTransform(CarlaTransform);
|
||||
UE_LOG(LogCarla, Error, TEXT("Missing TrafficLightModel"));
|
||||
return;
|
||||
}
|
||||
const auto& Signals = GetMap()->GetSignals();
|
||||
for(const auto& ControllerPair : GetMap()->GetControllers())
|
||||
{
|
||||
const auto& Controller = ControllerPair.second;
|
||||
for(const auto& SignalId : Controller->GetSignals())
|
||||
{
|
||||
const auto& Signal = Signals.at(SignalId);
|
||||
auto CarlaTransform = Signal->GetTransform();
|
||||
FTransform SpawnTransform(CarlaTransform);
|
||||
|
||||
FVector SpawnLocation = SpawnTransform.GetLocation();
|
||||
FRotator SpawnRotation(SpawnTransform.GetRotation());
|
||||
SpawnRotation.Yaw += 90;
|
||||
FVector SpawnLocation = SpawnTransform.GetLocation();
|
||||
FRotator SpawnRotation(SpawnTransform.GetRotation());
|
||||
SpawnRotation.Yaw += 90;
|
||||
|
||||
FActorSpawnParameters SpawnParams;
|
||||
SpawnParams.Owner = this;
|
||||
SpawnParams.SpawnCollisionHandlingOverride =
|
||||
ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||
AActor * TrafficLight = GetWorld()->SpawnActor<AActor>(
|
||||
TrafficLightModel,
|
||||
SpawnLocation,
|
||||
SpawnRotation,
|
||||
SpawnParams);
|
||||
FActorSpawnParameters SpawnParams;
|
||||
SpawnParams.Owner = this;
|
||||
SpawnParams.SpawnCollisionHandlingOverride =
|
||||
ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||
ATrafficLightBase * TrafficLight = GetWorld()->SpawnActor<ATrafficLightBase>(
|
||||
TrafficLightModel,
|
||||
SpawnLocation,
|
||||
SpawnRotation,
|
||||
SpawnParams);
|
||||
|
||||
UTrafficLightComponent *TrafficLightComponent =
|
||||
NewObject<UTrafficLightComponent>(TrafficLight);
|
||||
TrafficLightComponent->SetSignId(SignalId.c_str());
|
||||
TrafficLightComponent->RegisterComponent();
|
||||
TrafficLightComponent->AttachToComponent(
|
||||
TrafficSigns.Add(TrafficLight);
|
||||
|
||||
UTrafficLightComponent *TrafficLightComponent =
|
||||
NewObject<UTrafficLightComponent>(TrafficLight);
|
||||
TrafficLightComponent->SetSignId(SignalId.c_str());
|
||||
TrafficLightComponent->RegisterComponent();
|
||||
TrafficLightComponent->AttachToComponent(
|
||||
TrafficLight->GetRootComponent(),
|
||||
FAttachmentTransformRules::KeepRelativeTransform);
|
||||
}
|
||||
}
|
||||
|
||||
TrafficLightsGenerated = true;
|
||||
RegisterLightComponent(TrafficLightComponent);
|
||||
}
|
||||
}
|
||||
TrafficLightsGenerated = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ATrafficLightManager::RemoveGeneratedTrafficLights()
|
||||
|
@ -173,29 +175,7 @@ void ATrafficLightManager::BeginPlay()
|
|||
|
||||
if (TrafficLightsGenerated)
|
||||
{
|
||||
for(auto& It : TrafficControllers)
|
||||
{
|
||||
UTrafficLightController* Controller = It.Value;
|
||||
Controller->EmptyTrafficLights();
|
||||
}
|
||||
|
||||
for(auto& It : TrafficGroups)
|
||||
{
|
||||
ATrafficLightGroup* Group = It.Value;
|
||||
Group->GetControllers().Empty();
|
||||
}
|
||||
|
||||
for (TActorIterator<ATrafficSignBase> It(GetWorld()); It; ++It)
|
||||
{
|
||||
ATrafficSignBase* trafficSignBase = (*It);
|
||||
UTrafficLightComponent* TrafficLightComponent =
|
||||
trafficSignBase->FindComponentByClass<UTrafficLightComponent>();
|
||||
|
||||
if(TrafficLightComponent)
|
||||
{
|
||||
RegisterLightComponent(TrafficLightComponent);
|
||||
}
|
||||
}
|
||||
ResetTrafficLightObjects();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -204,6 +184,46 @@ void ATrafficLightManager::BeginPlay()
|
|||
|
||||
}
|
||||
|
||||
void ATrafficLightManager::ResetTrafficLightObjects()
|
||||
{
|
||||
// Update TrafficLightGroups
|
||||
for(auto& It : TrafficGroups)
|
||||
{
|
||||
ATrafficLightGroup* Group = It.Value;
|
||||
Group->GetControllers().Empty();
|
||||
}
|
||||
TrafficGroups.Empty();
|
||||
TArray<AActor*> TrafficGroupsArray;
|
||||
UGameplayStatics::GetAllActorsOfClass(
|
||||
GetWorld(),
|
||||
ATrafficLightGroup::StaticClass(),
|
||||
TrafficGroupsArray);
|
||||
|
||||
for(auto& Actor : TrafficGroupsArray) {
|
||||
ATrafficLightGroup* TrafficLightGroup = Cast<ATrafficLightGroup>(Actor);
|
||||
TrafficGroups.Add(TrafficLightGroup->JunctionId, TrafficLightGroup);
|
||||
}
|
||||
|
||||
for(auto& It : TrafficControllers)
|
||||
{
|
||||
UTrafficLightController* Controller = It.Value;
|
||||
Controller->EmptyTrafficLights();
|
||||
}
|
||||
TrafficControllers.Empty();
|
||||
|
||||
for (TActorIterator<ATrafficSignBase> It(GetWorld()); It; ++It)
|
||||
{
|
||||
ATrafficSignBase* trafficSignBase = (*It);
|
||||
UTrafficLightComponent* TrafficLightComponent =
|
||||
trafficSignBase->FindComponentByClass<UTrafficLightComponent>();
|
||||
|
||||
if(TrafficLightComponent)
|
||||
{
|
||||
RegisterLightComponent(TrafficLightComponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ATrafficLightGroup* ATrafficLightManager::GetTrafficGroup(carla::road::JuncId JunctionId)
|
||||
{
|
||||
if (TrafficGroups.Contains(JunctionId))
|
||||
|
|
|
@ -50,6 +50,8 @@ protected:
|
|||
|
||||
private:
|
||||
|
||||
void ResetTrafficLightObjects();
|
||||
|
||||
// Cached Carla Game Mode
|
||||
UPROPERTY()
|
||||
ACarlaGameModeBase *GameMode = 0;
|
||||
|
|
Loading…
Reference in New Issue