10#include <util/ue-header-guard-begin.h>
11#include "Kismet/GameplayStatics.h"
12#include "TimerManager.h"
13#include <util/ue-header-guard-end.h>
35 if (
const int* ExistingId =
Lights.FindKey(CarlaLight))
37 CarlaLight->SetId(*ExistingId);
39 auto LightId = CarlaLight->GetId();
40 if (
Lights.Contains(LightId) &&
Lights[LightId] != CarlaLight)
47 while (
Lights.Contains(LightId))
51 CarlaLight->SetId(LightId);
53 Lights.Add(LightId, CarlaLight);
70 UWorld* World = GetWorld();
71 if (World ==
nullptr || !World->IsGameWorld())
81 World->GetTimerManager().SetTimerForNextTick(FTimerDelegate::CreateWeakLambda(
this, [
this]()
85 for (
const TWeakObjectPtr<UCarlaLight>& Weak : Pending)
87 UCarlaLight* Light = Weak.Get();
92 Light->ApplyLegacyComponentConversion();
103 Lights.Remove(CarlaLight->GetId());
130 for (
auto& LightPair :
Lights)
132 if (UCarlaLight* CarlaLight = LightPair.Value)
134 CarlaLight->ApplyLegacyComponentConversion();
157 std::vector<carla::rpc::LightState> result;
163 UCarlaLight* CarlaLight = Light.Value;
171 result.push_back(CarlaLight->GetLightState());
178 std::vector<carla::rpc::LightState> LightsToSet,
184 for(
auto& LightState : LightsToSet) {
185 UCarlaLight* CarlaLight =
Lights.FindRef(LightState._id);
187 CarlaLight->SetLightState(LightState);
217 TArray<AActor*> WeatherActors;
218 UGameplayStatics::GetAllActorsOfClass(GetWorld(), AWeather::StaticClass(), WeatherActors);
219 if (WeatherActors.Num())
221 if (
AWeather* WeatherActor = Cast<AWeather>(WeatherActors[0]))
223 WeatherActor->SetDayNightCycle(active);
232 if(Client.Key != ClientThatUpdate)
static bool IsValid(const ACarlaWheeledVehicle *Vehicle)
void SetClientStatesdirty(FString ClientThatUpdate)
Flag every registered client (except ClientThatUpdate) so their LightManager re-queries light states.
void Initialize(FSubsystemCollectionBase &Collection) override
TMap< int, UCarlaLight * > Lights
TMap< int, UCarlaLight * > & GetLights()
void Deinitialize() override
TMap< FString, bool > ClientStates
void SetLights(FString Client, std::vector< carla::rpc::LightState > LightsToSet, bool DiscardClient=false)
void RegisterLight(UCarlaLight *CarlaLight)
FDayTimeChanged DayTimeChangeEvent
void NotifyDayTimeChange(bool bIsDay)
Broadcast a day/night change and then re-apply the UE4->UE5 component intensity conversion on every r...
void UnregisterLight(UCarlaLight *CarlaLight)
TSet< TWeakObjectPtr< UCarlaLight > > PendingDayTimeLights
void ScheduleDayTimeState(UCarlaLight *CarlaLight)
void SetDayNightCycle(const bool active)
bool IsUpdatePending() const
UCarlaLight * GetLight(int Id)