CARLA
Loading...
Searching...
No Matches
FrameData.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
34
35#include <util/ue-header-guard-begin.h>
36#include "Templates/Function.h"
37#include <util/ue-header-guard-end.h>
38
46
47#include <optional>
48#include <sstream>
49#include <unordered_map>
50#include <unordered_set>
51#include <utility>
52#include <vector>
53
54class UCarlaEpisode;
55class FCarlaActor;
56
57/// What a Multi-GPU secondary keeps between the primary frames it plays.
59{
60 /// Local ids of the mirrors this secondary spawned, as opposed to map actors
61 /// it reused (traffic lights, the spectator): only these may be swept.
62 std::unordered_set<uint32_t> CreatedIds;
63
64 /// Attachments not replayed yet, as (child, parent) primary ids: one of the
65 /// two is not mirrored yet.
66 std::vector<std::pair<uint32_t, uint32_t>> PendingParents;
67
68 /// The poses the last frame played set, by local id, to check before the
69 /// capture that nothing moved a mirror in between.
70 std::vector<std::pair<uint32_t, FTransform>> PlayedPoses;
71
72 /// The environment objects the primary has disabled (sorted), once a frame
73 /// said so, and the registration of this server's objects they were last
74 /// applied to: one in a map layer still streaming in is disabled once it
75 /// is registered.
76 std::optional<std::vector<uint64_t>> DisabledObjects;
78
79 void Reset()
80 {
81 CreatedIds.clear();
82 PendingParents.clear();
83 PlayedPoses.clear();
84 DisabledObjects.reset();
86 }
87};
88
89/// An actor's appearance, as a Multi-GPU primary last sent it.
91{
92 bool bCollisions = true;
93 bool bHidden = false;
94 FVector Scale = FVector::OneVector;
95
97 {
98 return (bCollisions == Other.bCollisions) && (bHidden == Other.bHidden) &&
99 Scale.Equals(Other.Scale, 0.0);
100 }
101};
102
103/// What a Multi-GPU primary remembers between the frames it sends, to send
104/// the world state only when it changes.
106{
107 /// AWeather::GetApplySerial() of the weather last sent.
108 uint64 WeatherSerial = 0u;
109
110 /// ACarlaGameModeBase::GetEnvironmentObjectsSerial() of the set last sent.
112
113 /// The scene lights changed since the last frame sent, by light id.
114 TSet<int32> ChangedLights;
115
116 /// The appearance last sent, by actor id.
117 std::unordered_map<uint32_t, FMirroredAppearance> Appearances;
118};
119
121{
122 // structures
143 // Multi-GPU: the weather applied in this frame.
145 // Multi-GPU only: the primary's clocks and settings for this frame.
146 std::optional<carla::multigpu::FrameTime> MultiGpuFrameTime;
147 // Multi-GPU only: every live actor's pose, rotations as quaternions.
149 // Multi-GPU only: the wheels and open doors of every vehicle.
151 // Multi-GPU only: the sensors that tick in this frame, and the state they
152 // start from.
155 bool bHasSensorTicks = false;
156 // Multi-GPU only: world-wide state, map objects and actor appearance.
157 std::optional<carla::multigpu::WorldGlobals> MirrorWorldGlobals;
160
161public:
162
163 void SetEpisode(UCarlaEpisode* ThisEpisode) {Episode = ThisEpisode;}
164
165 void GetFrameData(UCarlaEpisode *ThisEpisode, bool bAdditionalData = false, bool bIncludeActorsAgain = false);
166
167 /// @a OnActorAdded receives (primary actor id, local actor id, whether it
168 /// was just created rather than reused) for every actor created or reused;
169 /// @a OnActorRemoved the primary id of every actor destroyed.
170 void PlayFrameData(
171 UCarlaEpisode *ThisEpisode,
172 std::unordered_map<uint32_t, uint32_t>& MappedId,
173 FMirrorState &MirrorState,
174 TFunctionRef<void(uint32_t, uint32_t, bool)> OnActorAdded,
175 TFunctionRef<void(uint32_t)> OnActorRemoved);
176
177 void Clear();
178
179 void Write(std::ostream& OutStream);
180
181 /// Parses one SEND_FRAME payload. Only a complete frame
182 /// (FrameDataReadResult::IsComplete) may be played.
183 carla::multigpu::FrameDataReadResult Read(const uint8_t *Data, size_t Size);
184
185 uint64_t GetFrameNumber() const { return FrameCounter.FrameCounter; }
186
187 /// Whether the frame says which sensors tick (only older builds do not).
188 bool HasSensorTicks() const { return bHasSensorTicks; }
189
191
192 /// The primary's clocks and settings of this frame; null for a frame from
193 /// an older primary.
195 {
196 return MultiGpuFrameTime ? &*MultiGpuFrameTime : nullptr;
197 }
198
199 // record functions
201 uint32_t DatabaseId,
202 uint8_t Type,
203 const FTransform &Transform,
204 FActorDescription ActorDescription,
205 bool bAddOtherRelatedInfo = true);
206 void AddEvent(const CarlaRecorderEventAdd &Event);
207 void AddEvent(const CarlaRecorderEventDel &Event);
208 void AddEvent(const CarlaRecorderEventParent &Event);
209
210private:
211 void AddCollision(AActor *Actor1, AActor *Actor2);
215 void AddAnimWalker(const CarlaRecorderAnimWalker &Walker);
216 void AddAnimBiker(const CarlaRecorderAnimBiker &Biker);
217 void AddLightVehicle(const CarlaRecorderLightVehicle &LightVehicle);
218 void AddEventLightSceneChanged(const UCarlaLight* Light);
219 void AddKinematics(const CarlaRecorderKinematics &ActorKinematics);
220 void AddBoundingBox(const CarlaRecorderActorBoundingBox &ActorBoundingBox);
221 void AddTriggerVolume(const ATrafficSignBase &TrafficSign);
224
225 void AddActorPosition(FCarlaActor *CarlaActor);
226 void AddWalkerAnimation(FCarlaActor *CarlaActor);
228 void AddVehicleAnimation(FCarlaActor *CarlaActor);
229 // packet 32 and, for two-wheeled vehicles, packet 22
230 void AddVehicleParts(FCarlaActor *CarlaActor);
231 void AddTrafficLightState(FCarlaActor *CarlaActor);
232 void AddVehicleLight(FCarlaActor *CarlaActor);
233 void AddActorKinematics(FCarlaActor *CarlaActor);
234 void AddActorBoundingBox(FCarlaActor *CarlaActor);
235 void AddSensorTick(FCarlaActor *CarlaActor);
236 // packet 30 for an actor whose appearance changed since the last frame
237 void AddActorAppearance(FCarlaActor *CarlaActor, bool bFullResync);
238 // the weather, packets 28 and 29, and the scene lights that changed
239 void AddWorldState(bool bFullResync);
240
241 void GetFrameCounter();
242
243 std::pair<int, FCarlaActor*> CreateOrReuseActor(
244 FVector &Location,
245 FVector &Rotation,
246 FActorDescription &ActorDesc,
247 uint32_t DesiredId,
248 bool SpawnSensors,
249 std::unordered_map<uint32_t, uint32_t>& MappedId);
250
251 // replay event for creating actor
252 std::pair<int, uint32_t> ProcessReplayerEventAdd(
253 FVector Location,
254 FVector Rotation,
256 uint32_t DesiredId,
257 bool bIgnoreHero,
258 bool ReplaySensors,
259 std::unordered_map<uint32_t, uint32_t>& MappedId);
260
261 // replay event for removing actor
262 bool ProcessReplayerEventDel(uint32_t DatabaseId);
263 // replay event for parenting actors, by primary ids; false while one of
264 // the two is not mirrored yet
266 uint32_t ChildId,
267 uint32_t ParentId,
268 const std::unordered_map<uint32_t, uint32_t>& MappedId);
269 // a mirror never moves or acts on its own: the primary's frames move it
270 void PrepareMirroredActor(FCarlaActor *CarlaActor, uint32_t PrimaryActorId);
271 // apply packet 34, parents before their children
272 void PlayPositions(const std::unordered_map<uint32_t, uint32_t>& MappedId, FMirrorState &MirrorState);
273 // move a mirror to the primary's pose, keeping its own scale
274 void PlaceMirror(FCarlaActor &CarlaActor, FTransform Transform);
275 // apply packet 12: the primary's velocities of every moving mirror
276 void PlayKinematics(const std::unordered_map<uint32_t, uint32_t>& MappedId);
277 // apply packet 32, once the vehicles are in place
278 void PlayVehicleParts(const std::unordered_map<uint32_t, uint32_t>& MappedId);
279 // load and unload the map layers the primary did
280 void PlayMapLayers();
281 // apply packet 30
282 void PlayAppearances(const std::unordered_map<uint32_t, uint32_t>& MappedId);
283 // apply the weather and packets 28 and 29
284 void PlayWorldState(FMirrorState &MirrorState);
285 // reposition actors
287 CarlaRecorderPosition Pos2, double Per, double DeltaTime);
288 // replay event for traffic light state
290 // set the animation for Vehicles
292 // set the animation for walkers
294 // set the animation for bikers
296 // set the vehicle light
298 // set scene lights
300 // replay finish
301 bool ProcessReplayerFinish(bool bApplyAutopilot, bool bIgnoreHero,
302 std::unordered_map<uint32_t, bool> &IsHero);
303 // set the camera position to follow an actor
304 bool SetCameraPosition(uint32_t Id, FVector Offset, FQuat Rotation);
305 // set the velocity of the actor
306 void SetActorVelocity(FCarlaActor *CarlaActor, FVector Velocity);
307 // set the animation speed for walkers
308 void SetWalkerSpeed(uint32_t ActorId, float Speed);
309 // enable / disable physics for an actor
310 bool SetActorSimulatePhysics(FCarlaActor *CarlaActor, bool bEnabled);
311
312 void SetFrameCounter();
313
314 FCarlaActor* FindTrafficSignAt(FVector Location);
315
316 void AddExistingActors(void);
317
319};
320
321/// Copies the episode settings into a FrameTime and back. The secondary keeps
322/// its own no-rendering mode.
void FrameTimeFromSettings(const FEpisodeSettings &Settings, carla::multigpu::FrameTime &Time)
Copies the episode settings into a FrameTime and back.
void SettingsFromFrameTime(const carla::multigpu::FrameTime &Time, FEpisodeSettings &Settings)
Base class for CARLA wheeled vehicles.
A view over an actor and its properties.
Definition CarlaActor.h:25
void AddPhysicsControl(const ACarlaWheeledVehicle &Vehicle)
void AddAnimVehicle(const CarlaRecorderAnimVehicle &Vehicle)
CarlaRecorderEventsDel EventsDel
Definition FrameData.h:126
void ProcessReplayerLightVehicle(CarlaRecorderLightVehicle LightVehicle)
bool ProcessReplayerEventDel(uint32_t DatabaseId)
CarlaRecorderLightVehicles LightVehicles
Definition FrameData.h:134
void GetFrameData(UCarlaEpisode *ThisEpisode, bool bAdditionalData=false, bool bIncludeActorsAgain=false)
Definition FrameData.cpp:33
CarlaRecorderCollisions Collisions
Definition FrameData.h:128
CarlaRecorderWeathers Weathers
Definition FrameData.h:144
std::pair< int, FCarlaActor * > CreateOrReuseActor(FVector &Location, FVector &Rotation, FActorDescription &ActorDesc, uint32_t DesiredId, bool SpawnSensors, std::unordered_map< uint32_t, uint32_t > &MappedId)
CarlaRecorderInfo Info
Definition FrameData.h:123
void SetActorVelocity(FCarlaActor *CarlaActor, FVector Velocity)
void AddBikerAnimation(FCarlaActor *CarlaActor)
carla::multigpu::MirroredVehicleParts MirrorVehicleParts
Definition FrameData.h:150
bool ProcessReplayerStateTrafficLight(CarlaRecorderStateTrafficLight State)
CarlaRecorderEventsParent EventsParent
Definition FrameData.h:127
bool ProcessReplayerPosition(CarlaRecorderPosition Pos1, CarlaRecorderPosition Pos2, double Per, double DeltaTime)
void AddActorBoundingBox(FCarlaActor *CarlaActor)
bool ProcessReplayerFinish(bool bApplyAutopilot, bool bIgnoreHero, std::unordered_map< uint32_t, bool > &IsHero)
void PlaceMirror(FCarlaActor &CarlaActor, FTransform Transform)
void Write(std::ostream &OutStream)
void ProcessReplayerLightScene(CarlaRecorderLightScene LightScene)
void AddExistingActors(void)
void AddAnimBiker(const CarlaRecorderAnimBiker &Biker)
CarlaRecorderLightScenes LightScenes
Definition FrameData.h:135
void AddVehicleParts(FCarlaActor *CarlaActor)
CarlaRecorderActorTriggerVolumes TriggerVolumes
Definition FrameData.h:138
carla::multigpu::MirroredPositions MirrorPositions
Definition FrameData.h:148
void PlayKinematics(const std::unordered_map< uint32_t, uint32_t > &MappedId)
void PlayWorldState(FMirrorState &MirrorState)
CarlaRecorderAnimBikers Bikers
Definition FrameData.h:133
void SetFrameCounter()
bool SetActorSimulatePhysics(FCarlaActor *CarlaActor, bool bEnabled)
void AddState(const CarlaRecorderStateTrafficLight &State)
void ProcessReplayerAnimVehicle(CarlaRecorderAnimVehicle Vehicle)
CarlaRecorderActorBoundingBoxes BoundingBoxes
Definition FrameData.h:137
void AddCollision(AActor *Actor1, AActor *Actor2)
void AddLightVehicle(const CarlaRecorderLightVehicle &LightVehicle)
void AddVehicleAnimation(FCarlaActor *CarlaActor)
CarlaRecorderFrames Frames
Definition FrameData.h:124
void AddVehicleLight(FCarlaActor *CarlaActor)
bool bHasSensorTicks
Definition FrameData.h:155
CarlaRecorderTrafficLightTimes TrafficLightTimes
Definition FrameData.h:141
void AddTriggerVolume(const ATrafficSignBase &TrafficSign)
void SetFrameTime(const carla::multigpu::FrameTime &Time)
Definition FrameData.h:190
CarlaRecorderAnimVehicles Vehicles
Definition FrameData.h:131
void AddSensorTick(FCarlaActor *CarlaActor)
void PlayAppearances(const std::unordered_map< uint32_t, uint32_t > &MappedId)
void ProcessReplayerAnimBiker(CarlaRecorderAnimBiker Biker)
bool HasSensorTicks() const
Whether the frame says which sensors tick (only older builds do not).
Definition FrameData.h:188
CarlaRecorderFrameCounter FrameCounter
Definition FrameData.h:142
CarlaRecorderEventsAdd EventsAdd
Definition FrameData.h:125
bool ProcessReplayerEventParent(uint32_t ChildId, uint32_t ParentId, const std::unordered_map< uint32_t, uint32_t > &MappedId)
carla::multigpu::WorldObjects MirrorWorldObjects
Definition FrameData.h:158
void AddActorPosition(FCarlaActor *CarlaActor)
std::optional< carla::multigpu::FrameTime > MultiGpuFrameTime
Definition FrameData.h:146
void AddWalkerAnimation(FCarlaActor *CarlaActor)
void AddActorAppearance(FCarlaActor *CarlaActor, bool bFullResync)
bool SetCameraPosition(uint32_t Id, FVector Offset, FQuat Rotation)
carla::multigpu::SensorStates MirrorSensorStates
Definition FrameData.h:154
void AddTrafficLightTime(const ATrafficLightBase &TrafficLight)
void AddPosition(const CarlaRecorderPosition &Position)
void SetWalkerSpeed(uint32_t ActorId, float Speed)
CarlaRecorderPositions Positions
Definition FrameData.h:129
void PrepareMirroredActor(FCarlaActor *CarlaActor, uint32_t PrimaryActorId)
void AddActorKinematics(FCarlaActor *CarlaActor)
CarlaRecorderPhysicsControls PhysicsControls
Definition FrameData.h:140
uint64_t GetFrameNumber() const
Definition FrameData.h:185
carla::multigpu::FrameDataReadResult Read(const uint8_t *Data, size_t Size)
Parses one SEND_FRAME payload.
CarlaRecorderStates States
Definition FrameData.h:130
void SetEpisode(UCarlaEpisode *ThisEpisode)
Definition FrameData.h:163
void ProcessReplayerAnimWalker(CarlaRecorderAnimWalker Walker)
CarlaRecorderActorsKinematics Kinematics
Definition FrameData.h:136
void AddEvent(const CarlaRecorderEventAdd &Event)
FCarlaActor * FindTrafficSignAt(FVector Location)
CarlaRecorderAnimWalkers Walkers
Definition FrameData.h:132
carla::multigpu::ActorAppearances MirrorAppearances
Definition FrameData.h:159
void GetFrameCounter()
void CreateRecorderEventAdd(uint32_t DatabaseId, uint8_t Type, const FTransform &Transform, FActorDescription ActorDescription, bool bAddOtherRelatedInfo=true)
const carla::multigpu::FrameTime * GetFrameTime() const
The primary's clocks and settings of this frame; null for a frame from an older primary.
Definition FrameData.h:194
std::pair< int, uint32_t > ProcessReplayerEventAdd(FVector Location, FVector Rotation, CarlaRecorderActorDescription Description, uint32_t DesiredId, bool bIgnoreHero, bool ReplaySensors, std::unordered_map< uint32_t, uint32_t > &MappedId)
void AddWorldState(bool bFullResync)
UCarlaEpisode * Episode
Definition FrameData.h:318
void PlayMapLayers()
void PlayPositions(const std::unordered_map< uint32_t, uint32_t > &MappedId, FMirrorState &MirrorState)
std::optional< carla::multigpu::WorldGlobals > MirrorWorldGlobals
Definition FrameData.h:157
void AddEventLightSceneChanged(const UCarlaLight *Light)
CarlaRecorderPlatformTime PlatformTime
Definition FrameData.h:139
void AddAnimWalker(const CarlaRecorderAnimWalker &Walker)
void AddKinematics(const CarlaRecorderKinematics &ActorKinematics)
void PlayVehicleParts(const std::unordered_map< uint32_t, uint32_t > &MappedId)
void AddTrafficLightState(FCarlaActor *CarlaActor)
carla::multigpu::SensorTicks MirrorSensorTicks
Definition FrameData.h:153
void Clear()
void PlayFrameData(UCarlaEpisode *ThisEpisode, std::unordered_map< uint32_t, uint32_t > &MappedId, FMirrorState &MirrorState, TFunctionRef< void(uint32_t, uint32_t, bool)> OnActorAdded, TFunctionRef< void(uint32_t)> OnActorRemoved)
OnActorAdded receives (primary actor id, local actor id, whether it was just created rather than reus...
void AddBoundingBox(const CarlaRecorderActorBoundingBox &ActorBoundingBox)
A simulation episode.
A description of a Carla Actor with all its variation.
What a Multi-GPU secondary keeps between the primary frames it plays.
Definition FrameData.h:59
uint64 DisabledObjectsRegistrations
Definition FrameData.h:77
std::vector< std::pair< uint32_t, FTransform > > PlayedPoses
The poses the last frame played set, by local id, to check before the capture that nothing moved a mi...
Definition FrameData.h:70
std::optional< std::vector< uint64_t > > DisabledObjects
The environment objects the primary has disabled (sorted), once a frame said so, and the registration...
Definition FrameData.h:76
void Reset()
Definition FrameData.h:79
std::vector< std::pair< uint32_t, uint32_t > > PendingParents
Attachments not replayed yet, as (child, parent) primary ids: one of the two is not mirrored yet.
Definition FrameData.h:66
std::unordered_set< uint32_t > CreatedIds
Local ids of the mirrors this secondary spawned, as opposed to map actors it reused (traffic lights,...
Definition FrameData.h:62
An actor's appearance, as a Multi-GPU primary last sent it.
Definition FrameData.h:91
bool operator==(const FMirroredAppearance &Other) const
Definition FrameData.h:96
What a Multi-GPU primary remembers between the frames it sends, to send the world state only when it ...
Definition FrameData.h:106
uint64 WeatherSerial
AWeather::GetApplySerial() of the weather last sent.
Definition FrameData.h:108
TSet< int32 > ChangedLights
The scene lights changed since the last frame sent, by light id.
Definition FrameData.h:114
uint64 EnvironmentObjectsSerial
ACarlaGameModeBase::GetEnvironmentObjectsSerial() of the set last sent.
Definition FrameData.h:111
std::unordered_map< uint32_t, FMirroredAppearance > Appearances
The appearance last sent, by actor id.
Definition FrameData.h:117
Frame data packet 30, on change and on every full resync.
Definition worldState.h:148
Frame data packet 25: the primary's clocks and episode settings for one frame.
Definition frameTime.h:20
Frame data packet 34: every live actor's pose in this frame.
Frame data packet 32, every frame: the moving parts of every vehicle.
Frame data packet 27, for the sensors of packet 26 that carry state.
Definition sensorSync.h:108
Frame data packet 26: every sensor of the primary that ticks in this frame.
Definition sensorSync.h:34
Frame data packet 29, on change and on every full resync: map objects whose state is not part of any ...
Definition worldState.h:84