Implement M9.3 camera navigation and bounded input intentions
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
#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{};
|
||||
};
|
||||
// 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);
|
||||
[[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::uint64_t sequence_{};
|
||||
std::optional<std::uint64_t> tick_;
|
||||
};
|
||||
} // namespace evo::client
|
||||
Reference in New Issue
Block a user