载入中...
搜索中...
未找到
Time.cpp
浏览该文件的文档.
17 if (!std::isfinite(seconds)) return Result<Duration>::failure(invalidTime("duration seconds must be finite"));
20 constexpr long double minimum = static_cast<long double>(std::numeric_limits<std::int64_t>::min());
21 constexpr long double maximum = static_cast<long double>(std::numeric_limits<std::int64_t>::max());
28double Duration::seconds() const noexcept { return static_cast<double>(nanoseconds_) / 1000000000.0; }
31 if ((other.nanoseconds_ > 0 && nanoseconds_ > std::numeric_limits<std::int64_t>::max() - other.nanoseconds_) ||
40 const long double nanoseconds = static_cast<long double>(nanoseconds_) * static_cast<long double>(rate);
41 constexpr long double minimum = static_cast<long double>(std::numeric_limits<std::int64_t>::min());
42 constexpr long double maximum = static_cast<long double>(std::numeric_limits<std::int64_t>::max());
65SimulationClock::SimulationClock(ITimeSource& source, Duration fixedStep) : source_(source), fixedStep_(fixedStep) {
120 Diagnostic::error(DiagnosticCode::InvariantViolation, "simulation catch-up step limit exceeded"));
123 Diagnostic::error(DiagnosticCode::InvariantViolation, "simulation duration multiplication overflow"));
128 Diagnostic::error(DiagnosticCode::InvariantViolation, "simulation remainder exceeds Duration range"));
132 for (std::uint64_t i = 0; i < stepCount; ++i) steps.push_back({SimulationTick(tick_.value() + i + 1), fixedStep_});
#define EV_ASSERT(cond,...)
Assert an internal engine invariant (state that must always hold).
Definition Assert.h:37
Common time values and an injectable deterministic simulation clock.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
constexpr std::int64_t nanoseconds() const noexcept
Return the exact signed nanosecond representation.
Definition Time.h:69
Result< Duration > tryAdd(Duration other) const
Add two durations with overflow validation.
Definition Time.cpp:30
static Result< Duration > fromSeconds(double seconds)
Convert finite seconds to the nearest nanosecond.
Definition Time.cpp:16
static constexpr Duration fromNanoseconds(std::int64_t nanoseconds) noexcept
Construct an exact duration from nanoseconds.
Definition Time.h:55
double seconds() const noexcept
Return this duration as seconds for legacy/presentation APIs.
Definition Time.cpp:28
Result< Duration > scaled(double rate) const
Scale a duration by a finite non-negative rate.
Definition Time.cpp:37
virtual MonotonicTimestamp monotonicNow() const =0
Read the non-decreasing source-relative timestamp.
Result< Duration > since(MonotonicTimestamp earlier) const
Compute elapsed duration from an earlier timestamp.
Definition Time.cpp:48
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
Result< void > setRate(double rate)
Set a finite non-negative simulation rate (1 is normal speed).
Definition Time.cpp:77
void reset(SimulationTick tick=SimulationTick::zero()) noexcept
Reset deterministic state to a supplied tick without reading a clock.
Definition Time.cpp:159
Result< std::vector< SimulationStep > > advance(Duration realDelta)
Advance from supplied monotonic elapsed duration without reading a clock.
Definition Time.cpp:84
Result< std::vector< SimulationStep > > sample()
Read the source and emit deterministic steps for one frame.
Definition Time.cpp:141
SimulationClock(ITimeSource &source, Duration fixedStep=Duration::fromNanoseconds(16666667))
Construct a fixed-step clock without reading the source.
Definition Time.cpp:65
Result< void > setFixedStep(Duration fixedStep)
Set the positive fixed-step duration; accumulated time is preserved.
Definition Time.cpp:70
constexpr std::optional< StrongUint64 > incremented() const noexcept
Returns the next value, or empty instead of unsigned wraparound.
Definition StrongUint64.h:30
constexpr std::uint64_t value() const noexcept
Returns the underlying value at an explicit protocol boundary.
Definition StrongUint64.h:26
static constexpr StrongUint64 zero() noexcept
Returns the zero value for this strong type.
Definition StrongUint64.h:24
@ InvalidArgument
@ PreconditionViolation
@ InvariantViolation
detail::StrongUint64< detail::SimulationTickTag > SimulationTick
Deterministic simulation time step; it is not wall-clock time.
Definition Time.h:31