Files
aevolution/include/evo/client/input.hpp
T
dingoandClaude Opus 5.5 897055883a Add M9.8c launcher, legend, labelled inspector and click selection
Toolkit-independent launcher, selection, label and outcome-log models with
bounded inputs and fixed error text; Dear ImGui overlay in the native adapter
with toolkit-first event routing and capture; engineering panels for fixture vs
dev region, legend, inspector, session outcomes, notices and dialog. Additive
SessionClient::unreachable_attempts() bounds unreachable connects. Docs, CI
targets and validation evidence updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 10:09:11 -04:00

61 lines
2.2 KiB
C++

#pragma once
#include "evo/client/camera.hpp"
#include <array>
#include <cstdint>
#include <expected>
#include <optional>
namespace evo::client {
enum class Key : std::uint8_t { left, right, up, down, pan_left, pan_right, pan_up, pan_down };
enum class InputError : std::uint8_t {
invalid_key,
invalid_pointer,
invalid_wheel,
stale_tick,
exhausted
};
struct Intention {
std::uint64_t sequence{}, tick{};
std::int16_t move_x{}, move_y{}; // Signed unit vector *1000, local XY (+Y up).
};
struct Navigation {
int x{}, y{};
double wheel{};
ScreenPoint pointer{};
// One primary click on the world (press and release, not taken by the UI), consumed
// once. Used for presentation selection only; never an authoritative command.
std::optional<ScreenPoint> click;
};
// Main-thread value state; no event queue or authoritative position.
class InputState {
public:
// Host-owned sequence seed, for local streams/tests; not a session resume grant.
explicit InputState(std::uint64_t last_sequence = 0) : sequence_{last_sequence} {}
void admit(bool enabled) noexcept;
void capture(bool captured) noexcept;
[[nodiscard]] bool captured() const noexcept {
return captured_;
}
[[nodiscard]] bool enabled() const noexcept {
return admitted_ && !captured_;
}
[[nodiscard]] std::expected<void, InputError> key(Key key, bool down, bool repeat = false);
[[nodiscard]] std::expected<void, InputError> pointer(ScreenPoint point);
[[nodiscard]] std::expected<void, InputError> wheel(double steps);
// Records a world click while input is admitted and not captured; otherwise ignored.
[[nodiscard]] std::expected<void, InputError> click(ScreenPoint point);
[[nodiscard]] Navigation take_navigation() noexcept;
[[nodiscard]] std::expected<Intention, InputError> sample(std::uint64_t tick);
private:
void clear() noexcept;
std::array<bool, 8> keys_{};
bool admitted_{false}, captured_{false};
ScreenPoint pointer_{};
double wheel_{};
std::optional<ScreenPoint> click_;
std::uint64_t sequence_{};
std::optional<std::uint64_t> tick_;
};
} // namespace evo::client