59 lines
2.1 KiB
C++
59 lines
2.1 KiB
C++
#pragma once
|
|
#include "evo/client/input.hpp"
|
|
#include "evo/render/frame.hpp"
|
|
#include <cstdint>
|
|
#include <expected>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
namespace evo::client {
|
|
enum class Error : std::uint8_t {
|
|
invalid_config,
|
|
already_open,
|
|
initialization,
|
|
window,
|
|
renderer,
|
|
surface,
|
|
draw,
|
|
device_lost
|
|
};
|
|
enum class Step : std::uint8_t { rendered, paused, closed };
|
|
struct Config {
|
|
int width{960}, height{640};
|
|
bool hidden{false};
|
|
std::string renderer; // Empty selects SDL's supported default; explicit names must succeed.
|
|
};
|
|
struct WindowState {
|
|
int logical_width{}, logical_height{}, pixel_width{}, pixel_height{};
|
|
float content_scale{1};
|
|
bool focused{}, minimized{}, hidden{}, closed{}, failed{};
|
|
[[nodiscard]] bool accepts_input() const noexcept {
|
|
return focused && !minimized && !hidden && !closed && !failed && logical_width > 0 &&
|
|
logical_height > 0 && pixel_width > 0 && pixel_height > 0;
|
|
}
|
|
};
|
|
// One owner, process main thread only (including destruction). No SDL owner may coexist.
|
|
class Application {
|
|
public:
|
|
[[nodiscard]] static std::expected<std::unique_ptr<Application>, Error>
|
|
open(const Config& config);
|
|
~Application();
|
|
Application(const Application&) = delete;
|
|
Application& operator=(const Application&) = delete;
|
|
[[nodiscard]] WindowState state() const noexcept;
|
|
[[nodiscard]] std::expected<void, Error> poll_events();
|
|
[[nodiscard]] std::expected<Step, Error> present(const render::Frame& frame);
|
|
void set_ui_capture(bool captured) noexcept;
|
|
[[nodiscard]] bool ui_captured() const noexcept;
|
|
[[nodiscard]] Navigation take_navigation() noexcept;
|
|
[[nodiscard]] std::expected<Intention, InputError> sample_intention(std::uint64_t tick);
|
|
// Borrows the immutable frame for this call only. Errors latch until destruction.
|
|
[[nodiscard]] std::expected<Step, Error> step(const render::Frame& frame);
|
|
|
|
private:
|
|
struct Impl;
|
|
explicit Application(std::unique_ptr<Impl> impl);
|
|
std::unique_ptr<Impl> impl_;
|
|
};
|
|
} // namespace evo::client
|