载入中...
搜索中...
未找到
ClimbingInput.cpp
浏览该文件的文档.
2
3#include <algorithm>
4#include <limits>
5#include <utility>
6
7namespace eve::climbing {
8namespace {
9
10bool commandLess(const BufferedClimbingCommand& lhs, const BufferedClimbingCommand& rhs) {
11 if (lhs.pressedTick != rhs.pressedTick) return lhs.pressedTick < rhs.pressedTick;
12 return static_cast<std::uint8_t>(lhs.command) < static_cast<std::uint8_t>(rhs.command);
13}
14
15} // namespace
16
18 eve::SimulationTick pressedTick, std::uint64_t bufferTicks) {
19 if (bufferTicks == 0)
21 "input buffer must contain at least one tick",
22 "bufferTicks", {}, "climbing.input"));
23 if (pressedTick.value() > std::numeric_limits<std::uint64_t>::max() - bufferTicks)
25 "input expiry tick would overflow", "pressedTick", {},
26 "climbing.input"));
27 (void)prune(intent, pressedTick);
28 if (std::any_of(intent.commands.begin(), intent.commands.end(),
29 [&](const auto& entry) { return entry.command == command && entry.pressedTick == pressedTick; }))
31 "duplicate edge command for the same tick", "command",
32 {}, "climbing.input"));
33 if (intent.commands.size() >= MaxBufferedCommands)
35 "climbing input buffer is full", "commands", {},
36 "climbing.input"));
37 intent.commands.push_back(
38 {command, pressedTick, eve::SimulationTick(pressedTick.value() + bufferTicks), ClimbingExecutionId::zero()});
39 std::stable_sort(intent.commands.begin(), intent.commands.end(), commandLess);
41}
42
44 eve::SimulationTick pressedTick,
45 const ClimbingProfileDefinition& profile) {
46 return submit(intent, command, pressedTick, profile.inputBufferTicks);
47}
48
49std::size_t ClimbingInputSystem::prune(ClimbingIntent& intent, eve::SimulationTick currentTick) noexcept {
50 const std::size_t before = intent.commands.size();
51 std::erase_if(intent.commands, [&](const BufferedClimbingCommand& entry) {
52 return !entry.consumedExecutionId.isZero() || entry.expiryTick < currentTick;
53 });
54 return before - intent.commands.size();
55}
56
58 ClimbingCommand command,
59 eve::SimulationTick currentTick,
61 if (executionId.isZero())
63 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "consuming execution id must be non-zero",
64 "executionId", {}, "climbing.input"));
65 (void)prune(intent, currentTick);
66 const auto found = std::find_if(intent.commands.begin(), intent.commands.end(), [&](const auto& entry) {
67 return entry.command == command && entry.pressedTick <= currentTick && currentTick <= entry.expiryTick &&
68 entry.consumedExecutionId.isZero();
69 });
70 if (found == intent.commands.end())
73 found->consumedExecutionId = executionId;
76}
77
78std::optional<BufferedClimbingCommand> ClimbingInputSystem::peek(const ClimbingIntent& intent, ClimbingCommand command,
79 eve::SimulationTick currentTick) noexcept {
80 const auto found = std::find_if(intent.commands.begin(), intent.commands.end(), [&](const auto& entry) {
81 return entry.command == command && entry.pressedTick <= currentTick && currentTick <= entry.expiryTick &&
82 entry.consumedExecutionId.isZero();
83 });
84 return found == intent.commands.end() ? std::nullopt : std::optional<BufferedClimbingCommand>(*found);
85}
86
88 eve::SimulationTick lastGroundedTick,
89 std::uint64_t coyoteTicks) noexcept {
90 if (currentTick < lastGroundedTick) return ClimbingCoyoteState::Outside;
91 return currentTick.value() - lastGroundedTick.value() <= coyoteTicks ? ClimbingCoyoteState::Eligible
93}
94
95} // namespace eve::climbing
eve::action::ActionExecutionId executionId
Tick-addressed command buffering for deterministic climbing input.
bool found
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
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
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.h:81
static std::size_t prune(ClimbingIntent &intent, eve::SimulationTick currentTick) noexcept
Remove expired and already-consumed records; returns the number removed.
static constexpr std::size_t MaxBufferedCommands
Hard safety bound preventing an untrusted producer from growing intent indefinitely.
static ClimbingCoyoteState coyoteWindowState(eve::SimulationTick currentTick, eve::SimulationTick lastGroundedTick, std::uint64_t coyoteTicks) noexcept
Evaluate a grounded grace window without reading wall clock.
static eve::Result< void > submit(ClimbingIntent &intent, ClimbingCommand command, eve::SimulationTick pressedTick, std::uint64_t bufferTicks)
Queue one edge command with expiry derived from an exact tick budget.
static eve::Result< std::optional< BufferedClimbingCommand > > consume(ClimbingIntent &intent, ClimbingCommand command, eve::SimulationTick currentTick, ClimbingExecutionId executionId)
Atomically mark the oldest eligible command consumed by one committed execution.
static std::optional< BufferedClimbingCommand > peek(const ClimbingIntent &intent, ClimbingCommand command, eve::SimulationTick currentTick) noexcept
Observe the oldest eligible command without consuming or pruning intent.
constexpr std::uint64_t value() const noexcept
Returns the underlying value at an explicit protocol boundary.
static constexpr StrongUint64 zero() noexcept
Returns the zero value for this strong type.
constexpr bool isZero() const noexcept
Returns whether this value is zero.
ClimbingCoyoteState
Named result of evaluating the deterministic grounded grace window.
ClimbingCommand
Edge and held commands understood by the climbing input phase.
detail::StrongUint64< detail::SimulationTickTag > SimulationTick
Deterministic simulation time step; it is not wall-clock time.
Definition Time.h:31
One owning edge command with deterministic lifetime and consumption evidence.
Hot authoritative intent component; contains no device or callback pointers.
std::vector< BufferedClimbingCommand > commands
Runtime profile controlling capsule geometry and probe limits.
Definition Climbing.h:218