CARLA
Loading...
Searching...
No Matches
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
8
9#include <cstdint>
10#include <istream>
11#include <optional>
12#include <ostream>
13
14namespace carla {
15namespace 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
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;
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;
54 int32_t max_substeps = 10;
57 float tile_streaming_distance = 300000.0f;
58 float actor_active_distance = 200000.0f;
59 bool spectator_as_ego = true;
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
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) &&
112 reader.Read(fixed_delta) &&
114 reader.Read(max_substeps) &&
115 reader.Read(max_culling_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 {
134 kFixedDelta = 1u << 1u,
135 kSubstepping = 1u << 2u,
137 kSpectatorAsEgo = 1u << 4u,
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;
149 flags |= spectator_as_ego ? kSpectatorAsEgo : 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;
160 spectator_as_ego = (flags & kSpectatorAsEgo) != 0u;
162 no_rendering_mode = (flags & kNoRenderingMode) != 0u;
163 full_resync = (flags & kFullResync) != 0u;
164 }
165 };
166
167} // namespace multigpu
168} // namespace carla
Reads the fields of one packet (or one record inside it) without ever consuming more than its declare...
void WritePod(std::ostream &out, const T &value)
void WriteFrameDataHeader(std::ostream &out, uint8_t id, uint32_t payload_size)
constexpr uint8_t kMultiGpuProtocolVersion
Version of the whole Multi-GPU wire format, carried in every frame.
This file contains definitions of common data structures used in traffic manager.
Frame data packet 25: the primary's clocks and episode settings for one frame.
Definition frameTime.h:20
void Write(std::ostream &out) const
Definition frameTime.h:69
bool synchronous_mode
The primary's episode settings after frame N (FEpisodeSettings, in UE units).
Definition frameTime.h:49
bool Read(std::istream &in, uint32_t size)
Reads a payload of size bytes.
Definition frameTime.h:93
double elapsed_game_time
UCarlaEpisode clocks at the end of frame N.
Definition frameTime.h:37
float delta_seconds
The raw DeltaSeconds that UWorld::Tick(N) received, before time dilation and clamping.
Definition frameTime.h:34
uint64_t frame
Frame counter of frame N; equal to the frame's FrameCounter packet.
Definition frameTime.h:30
static constexpr uint32_t kPayloadSizeV1
Size of the version 1 payload; later versions only append fields.
Definition frameTime.h:25
bool full_resync
Set on the frame that rebuilds a secondary from scratch (a new or reconnected secondary,...
Definition frameTime.h:67
float time_dilation
AWorldSettings::GetEffectiveTimeDilation() of frame N.
Definition frameTime.h:63
uint8_t PackFlags() const
Definition frameTime.h:143
double world_time_seconds
UWorld clocks at the start of frame N, before UWorld::Tick adds the delta to them.
Definition frameTime.h:42
void UnpackFlags(uint8_t flags)
Definition frameTime.h:156
static constexpr uint8_t kPacketId
Definition frameTime.h:22
std::optional< double > fixed_delta_seconds
Definition frameTime.h:51