载入中...
搜索中...
未找到
AnimationTime.h
浏览该文件的文档.
1#pragma once
2
3#include "common/Time.h"
4
5#include <cmath>
6#include <optional>
7#include <string>
8#include <utility>
9
11
14 eve::SimulationTick lastTick, const char* owner) {
15 if (step.delta.nanoseconds() < 0)
18 eve::DiagnosticCode::InvalidArgument, std::string(owner) + " simulation delta must be non-negative"));
19 if (hasLastTick && step.tick <= lastTick)
22 eve::DiagnosticCode::Conflict, std::string(owner) + " simulation tick must advance monotonically"));
23
24 const float seconds = static_cast<float>(step.delta.seconds());
25 if (!std::isfinite(seconds))
28 eve::DiagnosticCode::InvalidArgument, std::string(owner) + " simulation delta is outside float range"));
30 return eve::Result<float>::success(seconds);
31}
32
34inline eve::Result<eve::SimulationStep> legacyStep(float seconds, bool hasLastTick, eve::SimulationTick lastTick,
35 const char* owner) {
38 auto nextTick = hasLastTick ? lastTick.incremented() : std::optional<eve::SimulationTick>(eve::SimulationTick(1));
39 if (!nextTick)
42 eve::DiagnosticCode::InvariantViolation, std::string(owner) + " simulation tick overflow"));
44 return eve::Result<eve::SimulationStep>::success(eve::SimulationStep{*nextTick, std::move(duration).takeValue()});
45}
46
47} // namespace eve::animation::detail
float duration
Common time values and an injectable deterministic simulation clock.
float step
Definition TreeMesh.cpp:314
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
static Result< Duration > fromSeconds(double seconds)
Convert finite seconds to the nearest nanosecond.
Definition Time.cpp:16
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
constexpr std::optional< StrongUint64 > incremented() const noexcept
Returns the next value, or empty instead of unsigned wraparound.
eve::Result< eve::SimulationStep > legacyStep(float seconds, bool hasLastTick, eve::SimulationTick lastTick, const char *owner)
Convert a legacy seconds call to the next local scheduler step.
eve::Result< float > secondsForStep(const eve::SimulationStep &step, bool hasLastTick, eve::SimulationTick lastTick, const char *owner)
Validate a scheduler step before an animation object mutates state.
One deterministic fixed-step emitted by SimulationClock.
Definition Time.h:158