CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
multigpu
frameGate.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 <cmath>
8
#include <cstdint>
9
#include <optional>
10
11
namespace
carla
{
12
namespace
multigpu
{
13
14
/// What a secondary does at the start of an engine frame, before the engine
15
/// computes the frame's time step.
16
enum class
BeginFrameAction
{
17
/// Not connected to a primary: run on this server's own clock.
18
OwnClock
,
19
/// Connected, but this frame must not block (no episode yet, or a map load
20
/// or travel is under way, during which the primary waits for this server).
21
DontWait
,
22
/// Wait for the primary's next frame and take its time step.
23
Wait
24
};
25
26
struct
BeginFrameState
{
27
bool
connected
=
false
;
28
bool
has_episode
=
false
;
29
bool
travel_pending
=
false
;
30
bool
load_map_pending
=
false
;
31
bool
exit_requested
=
false
;
32
};
33
34
inline
BeginFrameAction
DecideBeginFrame
(
const
BeginFrameState
&state) {
35
if
(!state.
connected
) {
36
return
BeginFrameAction::OwnClock
;
37
}
38
if
(!state.
has_episode
|| state.
travel_pending
|| state.
load_map_pending
|| state.
exit_requested
) {
39
return
BeginFrameAction::DontWait
;
40
}
41
return
BeginFrameAction::Wait
;
42
}
43
44
/// What a secondary does when its world starts ticking.
45
enum class
PreTickAction
{
46
/// Open the map the primary loaded; nothing else this frame.
47
OpenLevel
,
48
/// Play the primary frame prepared for this engine frame.
49
Play
,
50
/// No primary frame: let the frame pass without simulation time.
51
Skip
52
};
53
54
inline
PreTickAction
DecidePreTick
(
55
bool
load_map_pending,
56
bool
has_episode,
57
bool
frame_prepared,
58
bool
episode_world) {
59
if
(load_map_pending && has_episode) {
60
return
PreTickAction::OpenLevel
;
61
}
62
if
(!frame_prepared || !has_episode || !episode_world) {
63
return
PreTickAction::Skip
;
64
}
65
return
PreTickAction::Play
;
66
}
67
68
/// Whether @a frame directly follows the last frame this secondary played.
69
inline
bool
IsConsecutive
(std::optional<uint64_t> last_played, uint64_t frame) {
70
return
last_played.has_value() && (frame == *last_played + 1u);
71
}
72
73
/// Whether playing @a frame shows that this secondary missed primary state
74
/// (a frame went missing) that only a full resync gives back.
75
inline
bool
NeedsResync
(std::optional<uint64_t> last_played, uint64_t frame,
bool
full_resync) {
76
return
!full_resync && last_played.has_value() && !
IsConsecutive
(last_played, frame);
77
}
78
79
/// Whether a primary's delta can be this engine frame's time step.
80
inline
bool
IsUsableDelta
(
float
delta_seconds) {
81
return
std::isfinite(delta_seconds) && (delta_seconds >= 0.0f);
82
}
83
84
}
// namespace multigpu
85
}
// namespace carla
carla::multigpu
Definition
commands.h:17
carla::multigpu::IsConsecutive
bool IsConsecutive(std::optional< uint64_t > last_played, uint64_t frame)
Whether frame directly follows the last frame this secondary played.
Definition
frameGate.h:69
carla::multigpu::IsUsableDelta
bool IsUsableDelta(float delta_seconds)
Whether a primary's delta can be this engine frame's time step.
Definition
frameGate.h:80
carla::multigpu::DecideBeginFrame
BeginFrameAction DecideBeginFrame(const BeginFrameState &state)
Definition
frameGate.h:34
carla::multigpu::DecidePreTick
PreTickAction DecidePreTick(bool load_map_pending, bool has_episode, bool frame_prepared, bool episode_world)
Definition
frameGate.h:54
carla::multigpu::BeginFrameAction
BeginFrameAction
What a secondary does at the start of an engine frame, before the engine computes the frame's time st...
Definition
frameGate.h:16
carla::multigpu::BeginFrameAction::OwnClock
@ OwnClock
Not connected to a primary: run on this server's own clock.
Definition
frameGate.h:18
carla::multigpu::BeginFrameAction::Wait
@ Wait
Wait for the primary's next frame and take its time step.
Definition
frameGate.h:23
carla::multigpu::BeginFrameAction::DontWait
@ DontWait
Connected, but this frame must not block (no episode yet, or a map load or travel is under way,...
Definition
frameGate.h:21
carla::multigpu::NeedsResync
bool NeedsResync(std::optional< uint64_t > last_played, uint64_t frame, bool full_resync)
Whether playing frame shows that this secondary missed primary state (a frame went missing) that only...
Definition
frameGate.h:75
carla::multigpu::PreTickAction
PreTickAction
What a secondary does when its world starts ticking.
Definition
frameGate.h:45
carla::multigpu::PreTickAction::Skip
@ Skip
No primary frame: let the frame pass without simulation time.
Definition
frameGate.h:51
carla::multigpu::PreTickAction::OpenLevel
@ OpenLevel
Open the map the primary loaded; nothing else this frame.
Definition
frameGate.h:47
carla::multigpu::PreTickAction::Play
@ Play
Play the primary frame prepared for this engine frame.
Definition
frameGate.h:49
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
carla::multigpu::BeginFrameState
Definition
frameGate.h:26
carla::multigpu::BeginFrameState::exit_requested
bool exit_requested
Definition
frameGate.h:31
carla::multigpu::BeginFrameState::connected
bool connected
Definition
frameGate.h:27
carla::multigpu::BeginFrameState::travel_pending
bool travel_pending
Definition
frameGate.h:29
carla::multigpu::BeginFrameState::has_episode
bool has_episode
Definition
frameGate.h:28
carla::multigpu::BeginFrameState::load_map_pending
bool load_map_pending
Definition
frameGate.h:30
Generated by
1.18.0