ReplaySource¶
class nmeasim::core::simulation::ReplaySource · Library API
Replays the entries of a log as the replay clock passes their offsets.
#include <nmeasim/core/simulation/replay_source.hpp>
Inherits nmeasim::core::simulation::Source
Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp (line 59)
The replay clock is simulated time since the first entry, advanced by advance. An entry is due when its offset is at or before the clock; each due entry is queued, unchanged, for take_sentences and decoded into the vessel state, so that the dashboard and the map follow the replay. The state's time_utc therefore follows the time fields inside the sentences, not the replay clock. A line that does not parse is still sent, with an empty id, and leaves the state unchanged.
Pausing is the host's business: it stops calling advance. step_once emits exactly the next entry, and seek moves the clock, rebuilding the state from the entries before the new position without sending them.
At the end, a stopping replay holds the clock at the last offset and becomes finished. A looping replay starts again from the seed state and the first entry, carrying all the time that ran past the last entry into the next pass: should the carried time reach the end of the new pass as well, that pass is played too, as often as dt spans passes, as a looping TrackSource does. A looping log whose entries all share one offset has no duration to carry time over and is played once per advance. An empty log produces nothing and is finished from the start, whatever its end behaviour, so that a run of it ends at once.
Summary¶
Public member functions
| Name | Description |
|---|---|
ReplaySource() |
Creates a replay positioned before the first entry, with the state set to config.seed. |
advance() |
Advances the replay clock by dt and queues every entry it passes. |
current() |
Returns the state decoded so far. |
reset() |
Returns to the start: clock zero, no entry played, the seed state, and no queued sentences; not finished, unless the log is empty. |
finished() |
Returns whether a stopping replay has played its last entry. |
duration() |
Returns the length of the replay. |
position() |
Returns the replay clock. |
seek() |
Moves the replay clock and rebuilds the state for the new position without sending anything. |
provides_sentences() |
Returns true: a replay provides recorded sentences, and the sentence schedule stays idle. |
take_sentences() |
Hands over the queued sentences. |
step_once() |
Plays exactly the next entry and moves the replay clock to its offset. |
entry_index() |
Returns the index of the next entry to play. |
entry_count() |
Returns the number of entries in the log. |
config() |
Returns the configuration the source was built with. |
Private member functions
| Name | Description |
|---|---|
emit_entry() |
Decodes one entry into the state and queues it for take_sentences. |
rewind() |
Moves the cursor to the first entry and restores the seed state, leaving the clock, the queue and finished_ as they are. |
Private data members
| Name | Description |
|---|---|
config_ |
The log, seed and end behaviour. |
state_ |
The state decoded from the entries played in the current pass, on top of the seed. |
pending_ |
Sentences played but not yet collected by take_sentences. |
clock_ |
The replay clock: simulated time since the first entry of the current pass. |
cursor_ |
Index of the next entry to play. |
finished_ |
Whether a stopping replay has played its last entry, or the log is empty. |
Public member functions¶
ReplaySource()¶
explicit ReplaySource(ReplayConfig config)
Creates a replay positioned before the first entry, with the state set to config.seed.
Nothing is decoded or queued until the first advance, step_once or seek. A replay of an empty log is finished at once.
Parameters
| Name | Type | Description |
|---|---|---|
config |
ReplayConfig |
The log, the seed state and the end behaviour. |
Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp:68 · defined in src/core/src/simulation/replay_source.cpp:14
advance()¶
const model::VesselState& advance(std::chrono::milliseconds dt) override
Advances the replay clock by dt and queues every entry it passes.
Entries accumulate until take_sentences collects them. A finished replay and an empty log ignore the call.
Parameters
| Name | Type | Description |
|---|---|---|
dt |
std::chrono::milliseconds |
Simulated time to advance the replay clock by. With zero, the entries at the current offset that have not been played yet are still played. |
Returns const model::VesselState&: The state after decoding the entries played.
Preconditions
dtis not negative.
Overrides advance · Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp:79 · defined in src/core/src/simulation/replay_source.cpp:32
current()¶
const model::VesselState& current() const noexcept override
Returns the state decoded so far.
Returns const model::VesselState&: The state owned by the source, valid for its lifetime.
Overrides current · Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp:83
reset()¶
void reset() override
Returns to the start: clock zero, no entry played, the seed state, and no queued sentences; not finished, unless the log is empty.
Unlike seek to zero, the entries at offset zero have not been played afterwards and are sent by the next advance.
Overrides reset · Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp:89 · defined in src/core/src/simulation/replay_source.cpp:91
finished()¶
bool finished() const noexcept override
Returns whether a stopping replay has played its last entry.
Returns bool: True after the last entry of a replay configured with EndBehaviour::Stop has been played, or after a seek to its end; always true for an empty log and always false for a looping replay of a log with entries.
Overrides finished · Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp:95
duration()¶
std::optional<std::chrono::milliseconds> duration() const noexcept override
Returns the length of the replay.
Returns std::optional<std::chrono::milliseconds>: The offset of the last entry, zero for an empty log. Never std::nullopt.
Overrides duration · Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp:99 · defined in src/core/src/simulation/replay_source.cpp:98
position()¶
std::chrono::milliseconds position() const noexcept override
Returns the replay clock.
Returns std::chrono::milliseconds: The time since the first entry, in [0, duration()]. After a loop it counts from zero again.
Overrides position · Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp:104 · defined in src/core/src/simulation/replay_source.cpp:102
seek()¶
void seek(std::chrono::milliseconds position) override
Moves the replay clock and rebuilds the state for the new position without sending anything.
The queued sentences are discarded, the state returns to the seed, and every entry whose offset is at or before the new position is decoded into the state and counts as played, so that the instruments show the right values the moment the replay continues. Seeking to the end of a stopping replay finishes it; seeking anywhere else clears finished(), except for an empty log, which stays finished.
Parameters
| Name | Type | Description |
|---|---|---|
position |
std::chrono::milliseconds |
Time since the first entry, clamped to [0, duration()]. |
Overrides seek · Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp:115 · defined in src/core/src/simulation/replay_source.cpp:106
provides_sentences()¶
bool provides_sentences() const noexcept override
Returns true: a replay provides recorded sentences, and the sentence schedule stays idle.
Returns bool: Always true.
Overrides provides_sentences · Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp:121
take_sentences()¶
std::vector<EmittedSentence> take_sentences() override
Hands over the queued sentences.
Returns std::vector<EmittedSentence>: The entries played since the previous call, in log order, each with the formatter decoded from it as id (empty when the line does not parse) and the recorded line as text. The queue is empty afterwards.
Overrides take_sentences · Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp:127 · defined in src/core/src/simulation/replay_source.cpp:87
step_once()¶
void step_once() override
Plays exactly the next entry and moves the replay clock to its offset.
After the last entry, a stopping replay does nothing but report finished(), and a looping one starts again from the seed state with the first entry. An empty log ignores the call.
Overrides step_once · Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp:133 · defined in src/core/src/simulation/replay_source.cpp:66
entry_index()¶
std::size_t entry_index() const noexcept
Returns the index of the next entry to play.
Returns std::size_t: An index into the log's entries, equal to entry_count() once every entry of the current pass has been played.
Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp:139
entry_count()¶
std::size_t entry_count() const noexcept
Returns the number of entries in the log.
Returns std::size_t: The number of entries.
Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp:143
config()¶
const ReplayConfig& config() const noexcept
Returns the configuration the source was built with.
Returns const ReplayConfig&: The configuration, unchanged since construction.
Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp:147
Private member functions¶
emit_entry()¶
void emit_entry(std::size_t index)
Decodes one entry into the state and queues it for take_sentences.
Parameters
| Name | Type | Description |
|---|---|---|
index |
std::size_t |
Index of the entry in the log. |
Preconditions
indexis less thanentry_count().
Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp:154 · defined in src/core/src/simulation/replay_source.cpp:17
rewind()¶
void rewind()
Moves the cursor to the first entry and restores the seed state, leaving the clock, the queue and finished_ as they are.
Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp:157 · defined in src/core/src/simulation/replay_source.cpp:27
Private data members¶
config_¶
ReplayConfig config_
The log, seed and end behaviour.
Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp:160
state_¶
model::VesselState state_
The state decoded from the entries played in the current pass, on top of the seed.
Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp:162
pending_¶
std::vector<EmittedSentence> pending_
Sentences played but not yet collected by take_sentences.
Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp:164
clock_¶
std::chrono::milliseconds clock_{0}
The replay clock: simulated time since the first entry of the current pass.
Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp:166
cursor_¶
std::size_t cursor_{0}
Index of the next entry to play.
Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp:168
finished_¶
bool finished_{false}
Whether a stopping replay has played its last entry, or the log is empty.
Declared in src/core/include/nmeasim/core/simulation/replay_source.hpp:170
Inherited members¶
From nmeasim::core::simulation::ReplaySource: operator=(), operator=(), set_destination(), Source(), Source(), Source(), ~Source()