CARLA
Loading...
Searching...
No Matches
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
11namespace carla {
12namespace 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.
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).
22 /// Wait for the primary's next frame and take its time step.
23 Wait
24 };
25
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
35 if (!state.connected) {
37 }
38 if (!state.has_episode || state.travel_pending || state.load_map_pending || state.exit_requested) {
40 }
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.
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
55 bool load_map_pending,
56 bool has_episode,
57 bool frame_prepared,
58 bool episode_world) {
59 if (load_map_pending && has_episode) {
61 }
62 if (!frame_prepared || !has_episode || !episode_world) {
64 }
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
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
bool IsUsableDelta(float delta_seconds)
Whether a primary's delta can be this engine frame's time step.
Definition frameGate.h:80
BeginFrameAction DecideBeginFrame(const BeginFrameState &state)
Definition frameGate.h:34
PreTickAction DecidePreTick(bool load_map_pending, bool has_episode, bool frame_prepared, bool episode_world)
Definition frameGate.h:54
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
@ OwnClock
Not connected to a primary: run on this server's own clock.
@ Wait
Wait for the primary's next frame and take its time step.
@ DontWait
Connected, but this frame must not block (no episode yet, or a map load or travel is under way,...
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
PreTickAction
What a secondary does when its world starts ticking.
Definition frameGate.h:45
@ Skip
No primary frame: let the frame pass without simulation time.
@ OpenLevel
Open the map the primary loaded; nothing else this frame.
@ Play
Play the primary frame prepared for this engine frame.
This file contains definitions of common data structures used in traffic manager.