CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
multigpu
frameTime.h
Go to the documentation of this file.
1
// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma de Barcelona (UAB).
2
// This work is licensed under the terms of the MIT license.
3
// For a copy, see <https://opensource.org/licenses/MIT>.
4
5
#pragma once
6
7
#include "
carla/multigpu/frameDataCodec.h
"
8
9
#include <cstdint>
10
#include <istream>
11
#include <optional>
12
#include <ostream>
13
14
namespace
carla
{
15
namespace
multigpu
{
16
17
/// Frame data packet 25: the primary's clocks and episode settings for one
18
/// frame. A secondary plays frame N with exactly this delta and these times,
19
/// so whatever it computes is stamped and integrated like on the primary.
20
struct
FrameTime
{
21
22
static
constexpr
uint8_t
kPacketId
= 25u;
23
24
/// Size of the version 1 payload; later versions only append fields.
25
static
constexpr
uint32_t
kPayloadSizeV1
= 98u;
26
27
uint8_t
protocol_version
=
kMultiGpuProtocolVersion
;
28
29
/// Frame counter of frame N; equal to the frame's FrameCounter packet.
30
uint64_t
frame
= 0u;
31
32
/// The raw DeltaSeconds that UWorld::Tick(N) received, before time
33
/// dilation and clamping.
34
float
delta_seconds
= 0.0f;
35
36
/// UCarlaEpisode clocks at the end of frame N.
37
double
elapsed_game_time
= 0.0;
38
double
visual_game_time
= 0.0;
39
40
/// UWorld clocks at the start of frame N, before UWorld::Tick adds the
41
/// delta to them.
42
double
world_time_seconds
= 0.0;
43
double
world_unpaused_time_seconds
= 0.0;
44
double
world_real_time_seconds
= 0.0;
45
double
world_audio_time_seconds
= 0.0;
46
47
/// The primary's episode settings after frame N (FEpisodeSettings, in UE
48
/// units). no_rendering_mode is informational: secondaries keep their own.
49
bool
synchronous_mode
=
false
;
50
bool
no_rendering_mode
=
false
;
51
std::optional<double>
fixed_delta_seconds
;
52
bool
substepping
=
true
;
53
double
max_substep_delta_time
= 0.01;
54
int32_t
max_substeps
= 10;
55
float
max_culling_distance
= 0.0f;
56
bool
deterministic_ragdolls
=
true
;
57
float
tile_streaming_distance
= 300000.0f;
58
float
actor_active_distance
= 200000.0f;
59
bool
spectator_as_ego
=
true
;
60
bool
adjust_signs_height_to_ground
=
false
;
61
62
/// AWorldSettings::GetEffectiveTimeDilation() of frame N.
63
float
time_dilation
= 1.0f;
64
65
/// Set on the frame that rebuilds a secondary from scratch (a new or
66
/// reconnected secondary, or the first frame after a map load).
67
bool
full_resync
=
false
;
68
69
void
Write
(std::ostream &out)
const
{
70
WriteFrameDataHeader
(out,
kPacketId
,
kPayloadSizeV1
);
71
detail::WritePod
(out,
protocol_version
);
72
detail::WritePod
(out,
PackFlags
());
73
detail::WritePod
(out,
frame
);
74
detail::WritePod
(out,
delta_seconds
);
75
detail::WritePod
(out,
elapsed_game_time
);
76
detail::WritePod
(out,
visual_game_time
);
77
detail::WritePod
(out,
world_time_seconds
);
78
detail::WritePod
(out,
world_unpaused_time_seconds
);
79
detail::WritePod
(out,
world_real_time_seconds
);
80
detail::WritePod
(out,
world_audio_time_seconds
);
81
detail::WritePod
(out,
fixed_delta_seconds
.value_or(0.0));
82
detail::WritePod
(out,
max_substep_delta_time
);
83
detail::WritePod
(out,
max_substeps
);
84
detail::WritePod
(out,
max_culling_distance
);
85
detail::WritePod
(out,
tile_streaming_distance
);
86
detail::WritePod
(out,
actor_active_distance
);
87
detail::WritePod
(out,
time_dilation
);
88
}
89
90
/// Reads a payload of @a size bytes. Fails (and fails @a in) on a payload
91
/// shorter than version 1; bytes beyond the fields known here are left for
92
/// the packet loop to skip.
93
bool
Read
(std::istream &in, uint32_t size) {
94
if
(size <
kPayloadSizeV1
) {
95
in.setstate(std::ios_base::failbit);
96
return
false
;
97
}
98
BoundedReader
reader(in, size);
99
uint8_t flags = 0u;
100
double
fixed_delta = 0.0;
101
const
bool
ok =
102
reader.
Read
(
protocol_version
) &&
103
reader.
Read
(flags) &&
104
reader.
Read
(
frame
) &&
105
reader.
Read
(
delta_seconds
) &&
106
reader.
Read
(
elapsed_game_time
) &&
107
reader.
Read
(
visual_game_time
) &&
108
reader.
Read
(
world_time_seconds
) &&
109
reader.
Read
(
world_unpaused_time_seconds
) &&
110
reader.
Read
(
world_real_time_seconds
) &&
111
reader.
Read
(
world_audio_time_seconds
) &&
112
reader.
Read
(fixed_delta) &&
113
reader.
Read
(
max_substep_delta_time
) &&
114
reader.
Read
(
max_substeps
) &&
115
reader.
Read
(
max_culling_distance
) &&
116
reader.
Read
(
tile_streaming_distance
) &&
117
reader.
Read
(
actor_active_distance
) &&
118
reader.
Read
(
time_dilation
);
119
if
(!ok) {
120
return
false
;
121
}
122
UnpackFlags
(flags);
123
fixed_delta_seconds
.reset();
124
if
((flags &
kFixedDelta
) != 0u) {
125
fixed_delta_seconds
= fixed_delta;
126
}
127
return
true
;
128
}
129
130
private
:
131
132
enum
Flag
: uint8_t {
133
kSynchronousMode
= 1u << 0u,
134
kFixedDelta
= 1u << 1u,
135
kSubstepping
= 1u << 2u,
136
kDeterministicRagdolls
= 1u << 3u,
137
kSpectatorAsEgo
= 1u << 4u,
138
kAdjustSignsHeight
= 1u << 5u,
139
kNoRenderingMode
= 1u << 6u,
140
kFullResync
= 1u << 7u
141
};
142
143
uint8_t
PackFlags
()
const
{
144
uint8_t flags = 0u;
145
flags |=
synchronous_mode
?
kSynchronousMode
: 0u;
146
flags |=
fixed_delta_seconds
.has_value() ?
kFixedDelta
: 0u;
147
flags |=
substepping
?
kSubstepping
: 0u;
148
flags |=
deterministic_ragdolls
?
kDeterministicRagdolls
: 0u;
149
flags |=
spectator_as_ego
?
kSpectatorAsEgo
: 0u;
150
flags |=
adjust_signs_height_to_ground
?
kAdjustSignsHeight
: 0u;
151
flags |=
no_rendering_mode
?
kNoRenderingMode
: 0u;
152
flags |=
full_resync
?
kFullResync
: 0u;
153
return
flags;
154
}
155
156
void
UnpackFlags
(uint8_t flags) {
157
synchronous_mode
= (flags &
kSynchronousMode
) != 0u;
158
substepping
= (flags &
kSubstepping
) != 0u;
159
deterministic_ragdolls
= (flags &
kDeterministicRagdolls
) != 0u;
160
spectator_as_ego
= (flags &
kSpectatorAsEgo
) != 0u;
161
adjust_signs_height_to_ground
= (flags &
kAdjustSignsHeight
) != 0u;
162
no_rendering_mode
= (flags &
kNoRenderingMode
) != 0u;
163
full_resync
= (flags &
kFullResync
) != 0u;
164
}
165
};
166
167
}
// namespace multigpu
168
}
// namespace carla
carla::multigpu::BoundedReader
Reads the fields of one packet (or one record inside it) without ever consuming more than its declare...
Definition
frameDataCodec.h:200
carla::multigpu::BoundedReader::Read
bool Read(T &value)
Definition
frameDataCodec.h:208
frameDataCodec.h
carla::multigpu::detail::WritePod
void WritePod(std::ostream &out, const T &value)
Definition
frameDataCodec.h:98
carla::multigpu
Definition
commands.h:17
carla::multigpu::WriteFrameDataHeader
void WriteFrameDataHeader(std::ostream &out, uint8_t id, uint32_t payload_size)
Definition
frameDataCodec.h:112
carla::multigpu::kMultiGpuProtocolVersion
constexpr uint8_t kMultiGpuProtocolVersion
Version of the whole Multi-GPU wire format, carried in every frame.
Definition
frameDataCodec.h:32
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
carla::multigpu::FrameTime
Frame data packet 25: the primary's clocks and episode settings for one frame.
Definition
frameTime.h:20
carla::multigpu::FrameTime::max_substeps
int32_t max_substeps
Definition
frameTime.h:54
carla::multigpu::FrameTime::world_audio_time_seconds
double world_audio_time_seconds
Definition
frameTime.h:45
carla::multigpu::FrameTime::spectator_as_ego
bool spectator_as_ego
Definition
frameTime.h:59
carla::multigpu::FrameTime::Write
void Write(std::ostream &out) const
Definition
frameTime.h:69
carla::multigpu::FrameTime::synchronous_mode
bool synchronous_mode
The primary's episode settings after frame N (FEpisodeSettings, in UE units).
Definition
frameTime.h:49
carla::multigpu::FrameTime::protocol_version
uint8_t protocol_version
Definition
frameTime.h:27
carla::multigpu::FrameTime::Read
bool Read(std::istream &in, uint32_t size)
Reads a payload of size bytes.
Definition
frameTime.h:93
carla::multigpu::FrameTime::max_substep_delta_time
double max_substep_delta_time
Definition
frameTime.h:53
carla::multigpu::FrameTime::tile_streaming_distance
float tile_streaming_distance
Definition
frameTime.h:57
carla::multigpu::FrameTime::Flag
Flag
Definition
frameTime.h:132
carla::multigpu::FrameTime::kAdjustSignsHeight
@ kAdjustSignsHeight
Definition
frameTime.h:138
carla::multigpu::FrameTime::kSynchronousMode
@ kSynchronousMode
Definition
frameTime.h:133
carla::multigpu::FrameTime::kSubstepping
@ kSubstepping
Definition
frameTime.h:135
carla::multigpu::FrameTime::kSpectatorAsEgo
@ kSpectatorAsEgo
Definition
frameTime.h:137
carla::multigpu::FrameTime::kFullResync
@ kFullResync
Definition
frameTime.h:140
carla::multigpu::FrameTime::kDeterministicRagdolls
@ kDeterministicRagdolls
Definition
frameTime.h:136
carla::multigpu::FrameTime::kNoRenderingMode
@ kNoRenderingMode
Definition
frameTime.h:139
carla::multigpu::FrameTime::kFixedDelta
@ kFixedDelta
Definition
frameTime.h:134
carla::multigpu::FrameTime::elapsed_game_time
double elapsed_game_time
UCarlaEpisode clocks at the end of frame N.
Definition
frameTime.h:37
carla::multigpu::FrameTime::world_unpaused_time_seconds
double world_unpaused_time_seconds
Definition
frameTime.h:43
carla::multigpu::FrameTime::delta_seconds
float delta_seconds
The raw DeltaSeconds that UWorld::Tick(N) received, before time dilation and clamping.
Definition
frameTime.h:34
carla::multigpu::FrameTime::frame
uint64_t frame
Frame counter of frame N; equal to the frame's FrameCounter packet.
Definition
frameTime.h:30
carla::multigpu::FrameTime::kPayloadSizeV1
static constexpr uint32_t kPayloadSizeV1
Size of the version 1 payload; later versions only append fields.
Definition
frameTime.h:25
carla::multigpu::FrameTime::substepping
bool substepping
Definition
frameTime.h:52
carla::multigpu::FrameTime::full_resync
bool full_resync
Set on the frame that rebuilds a secondary from scratch (a new or reconnected secondary,...
Definition
frameTime.h:67
carla::multigpu::FrameTime::actor_active_distance
float actor_active_distance
Definition
frameTime.h:58
carla::multigpu::FrameTime::no_rendering_mode
bool no_rendering_mode
Definition
frameTime.h:50
carla::multigpu::FrameTime::time_dilation
float time_dilation
AWorldSettings::GetEffectiveTimeDilation() of frame N.
Definition
frameTime.h:63
carla::multigpu::FrameTime::adjust_signs_height_to_ground
bool adjust_signs_height_to_ground
Definition
frameTime.h:60
carla::multigpu::FrameTime::PackFlags
uint8_t PackFlags() const
Definition
frameTime.h:143
carla::multigpu::FrameTime::max_culling_distance
float max_culling_distance
Definition
frameTime.h:55
carla::multigpu::FrameTime::world_real_time_seconds
double world_real_time_seconds
Definition
frameTime.h:44
carla::multigpu::FrameTime::world_time_seconds
double world_time_seconds
UWorld clocks at the start of frame N, before UWorld::Tick adds the delta to them.
Definition
frameTime.h:42
carla::multigpu::FrameTime::visual_game_time
double visual_game_time
Definition
frameTime.h:38
carla::multigpu::FrameTime::UnpackFlags
void UnpackFlags(uint8_t flags)
Definition
frameTime.h:156
carla::multigpu::FrameTime::kPacketId
static constexpr uint8_t kPacketId
Definition
frameTime.h:22
carla::multigpu::FrameTime::deterministic_ragdolls
bool deterministic_ragdolls
Definition
frameTime.h:56
carla::multigpu::FrameTime::fixed_delta_seconds
std::optional< double > fixed_delta_seconds
Definition
frameTime.h:51
Generated by
1.18.0