CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
Unreal
CarlaUnreal
Plugins
Carla
Source
Carla
Lights
CarlaLightSubsystem.h
Go to the documentation of this file.
1
// Copyright (c) 2026 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
#pragma once
8
9
#include "
Carla.h
"
10
#include "
CarlaLight.h
"
11
12
#include <
util/disable-ue4-macros.h
>
13
#include <
carla/rpc/LightState.h
>
14
#include <
util/enable-ue4-macros.h
>
15
16
#include <util/ue-header-guard-begin.h>
17
#include "CoreMinimal.h"
18
#include "Subsystems/WorldSubsystem.h"
19
#include <util/ue-header-guard-end.h>
20
21
#include <vector>
22
23
#include "CarlaLightSubsystem.generated.h"
24
25
/**
26
*
27
*/
28
29
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam
(FDayTimeChanged,
bool
, bIsDay);
30
31
UCLASS(Blueprintable, BlueprintType)
32
class CARLA_API
UCarlaLightSubsystem
: public
UWorldSubsystem
33
{
34
GENERATED_BODY()
35
36
//using cr = carla::rpc;
37
38
public
:
39
40
// Begin USubsystem
41
void
Initialize
(FSubsystemCollectionBase& Collection)
override
;
42
// End USubsystem
43
void
Deinitialize
()
override
;
44
45
void
RegisterLight
(UCarlaLight* CarlaLight);
46
47
void
UnregisterLight
(UCarlaLight* CarlaLight);
48
49
UFUNCTION(BlueprintCallable)
50
bool
IsUpdatePending
()
const
;
51
52
UFUNCTION(BlueprintCallable)
53
int32
NumLights
()
const
{
54
return
Lights
.Num();
55
}
56
57
std::vector<carla::rpc::LightState> GetLights(FString Client);
58
59
void
SetLights(
60
FString Client,
61
std::vector<carla::rpc::LightState> LightsToSet,
62
bool
DiscardClient =
false
);
63
64
UCarlaLight* GetLight(
int
Id);
65
66
TMap<int, UCarlaLight* >&
GetLights
()
67
{
68
return
Lights
;
69
}
70
71
void
SetDayNightCycle(
const
bool
active);
72
73
bool
GetDayNightCycle
()
const
74
{
75
return
bDayNightCycle
;
76
}
77
78
/// The day/night state last broadcast, if any.
79
bool
GetDayTimeState
(
bool
&bOutIsDay)
const
80
{
81
bOutIsDay =
bLastIsDay
;
82
return
bHasDayTimeState
;
83
}
84
85
UPROPERTY(BlueprintCallable, BlueprintAssignable, Category =
"DayTimeChangeEvent"
)
86
FDayTimeChanged
DayTimeChangeEvent
;
87
88
/// Broadcast a day/night change and then re-apply the UE4->UE5 component
89
/// intensity conversion on every registered light. Use this instead of
90
/// broadcasting DayTimeChangeEvent directly: blueprint-bound handlers push
91
/// raw authored intensities into the light components, undoing any
92
/// conversion applied earlier in the same broadcast.
93
void
NotifyDayTimeChange
(
bool
bIsDay);
94
95
/// Flag every registered client (except ClientThatUpdate) so their
96
/// LightManager re-queries light states. Must be called after any
97
/// server-side state change made outside a client request (day/night
98
/// broadcast, recorder replay), or clients keep serving stale cached
99
/// values.
100
void
SetClientStatesdirty
(FString ClientThatUpdate);
101
102
private:
103
104
// UPROPERTY so the GC can see these references: a bare map dangles when
105
// World Partition streams out a lamp before its EndPlay unregisters it.
106
UPROPERTY()
107
TMap<
int
, UCarlaLight* >
Lights
;
108
109
// Last state NotifyDayTimeChange broadcast, applied (next tick) to lights registering later.
110
void
ScheduleDayTimeState
(UCarlaLight* CarlaLight);
111
bool
bHasDayTimeState
= false;
112
bool
bLastIsDay
= true;
113
// set_day_night_cycle from the client; off, day/night changes are ignored.
114
bool
bDayNightCycle
= true;
115
TSet<TWeakObjectPtr<UCarlaLight>>
PendingDayTimeLights
;
116
117
// Flag for each client to tell if an update needs to be done
118
TMap<FString,
bool
>
ClientStates
;
119
// Since the clients doesn't have a proper id on the simulation,
120
// I use the host : port pair.
121
122
};
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnEpisodeInitialisedDelegate, UCarlaEpisode *, InitialisedEpisode)
CarlaLight.h
Carla.h
UCarlaLightSubsystem
Definition
CarlaLightSubsystem.h:33
UCarlaLightSubsystem::SetClientStatesdirty
void SetClientStatesdirty(FString ClientThatUpdate)
Flag every registered client (except ClientThatUpdate) so their LightManager re-queries light states.
Definition
CarlaLightSubsystem.cpp:228
UCarlaLightSubsystem::Initialize
void Initialize(FSubsystemCollectionBase &Collection) override
Definition
CarlaLightSubsystem.cpp:17
UCarlaLightSubsystem::Lights
TMap< int, UCarlaLight * > Lights
Definition
CarlaLightSubsystem.h:107
UCarlaLightSubsystem::GetLights
TMap< int, UCarlaLight * > & GetLights()
Definition
CarlaLightSubsystem.h:66
UCarlaLightSubsystem::bHasDayTimeState
bool bHasDayTimeState
Definition
CarlaLightSubsystem.h:111
UCarlaLightSubsystem::Deinitialize
void Deinitialize() override
Definition
CarlaLightSubsystem.cpp:22
UCarlaLightSubsystem::ClientStates
TMap< FString, bool > ClientStates
Definition
CarlaLightSubsystem.h:118
UCarlaLightSubsystem::GetDayTimeState
bool GetDayTimeState(bool &bOutIsDay) const
The day/night state last broadcast, if any.
Definition
CarlaLightSubsystem.h:79
UCarlaLightSubsystem::RegisterLight
void RegisterLight(UCarlaLight *CarlaLight)
Definition
CarlaLightSubsystem.cpp:27
UCarlaLightSubsystem::DayTimeChangeEvent
FDayTimeChanged DayTimeChangeEvent
Definition
CarlaLightSubsystem.h:86
UCarlaLightSubsystem::NotifyDayTimeChange
void NotifyDayTimeChange(bool bIsDay)
Broadcast a day/night change and then re-apply the UE4->UE5 component intensity conversion on every r...
Definition
CarlaLightSubsystem.cpp:109
UCarlaLightSubsystem::UnregisterLight
void UnregisterLight(UCarlaLight *CarlaLight)
Definition
CarlaLightSubsystem.cpp:99
UCarlaLightSubsystem::PendingDayTimeLights
TSet< TWeakObjectPtr< UCarlaLight > > PendingDayTimeLights
Definition
CarlaLightSubsystem.h:115
UCarlaLightSubsystem::ScheduleDayTimeState
void ScheduleDayTimeState(UCarlaLight *CarlaLight)
Definition
CarlaLightSubsystem.cpp:68
UCarlaLightSubsystem::GetDayNightCycle
bool GetDayNightCycle() const
Definition
CarlaLightSubsystem.h:73
UCarlaLightSubsystem::bDayNightCycle
bool bDayNightCycle
Definition
CarlaLightSubsystem.h:114
UCarlaLightSubsystem::NumLights
int32 NumLights() const
Definition
CarlaLightSubsystem.h:53
UCarlaLightSubsystem::IsUpdatePending
bool IsUpdatePending() const
Definition
CarlaLightSubsystem.cpp:143
UCarlaLightSubsystem::bLastIsDay
bool bLastIsDay
Definition
CarlaLightSubsystem.h:112
UWorldSubsystem
disable-ue4-macros.h
enable-ue4-macros.h
LightState.h
Generated by
1.18.0