#pragma once #include "core/config.hpp" #include #include #include #include namespace top_octane { struct CraftInput { float steer = 0.0f; // -1.0 (left) .. +1.0 (right) float throttle = 0.0f; // 0.0 .. 1.0 float brake = 0.0f; // 0.0 .. 1.0 bool boost = false; bool fire_minigun = false; bool fire_missile = false; bool toggle_autopilot_pressed = false; bool cycle_camera_pressed = false; }; struct MenuInput { bool up = false; bool down = false; bool left = false; bool right = false; bool confirm = false; bool back = false; bool pause = false; bool any_pressed = false; }; class InputManager { public: static constexpr int kMaxGamepads = 4; bool init(); void shutdown(); // Call before SDL_PollEvent loop each frame void begin_frame(); // Feed every polled SDL_Event here void handle_event(const SDL_Event& ev, GameConfig& cfg, bool& out_quit, bool& out_toggle_fullscreen); // Call after SDL_PollEvent loop each frame to update states void end_frame(const GameConfig& cfg); CraftInput craft_input(int player_idx, const GameConfig& cfg, bool allow_arrow_fallback = true) const; const MenuInput& menu_input() const { return menu_; } // Live key rebinding support void start_rebind() { rebind_active_ = true; captured_scancode_ = 0; } void cancel_rebind() { rebind_active_ = false; captured_scancode_ = 0; } bool is_rebinding() const { return rebind_active_; } bool consume_rebound_scancode(int& out_scancode); // Live text input capture for player name entry void start_text_input(); void stop_text_input(); bool is_text_input_active() const { return text_input_active_; } const std::string& text_input_chars() const { return text_chars_; } bool text_backspace_pressed() const { return text_backspace_; } bool text_confirm_pressed() const { return text_confirm_; } bool text_cancel_pressed() const { return text_cancel_; } // Rumble / Haptics void trigger_rumble(int player_idx, float low_freq, float high_freq, uint32_t duration_ms, const GameConfig& cfg); int connected_gamepad_count() const; std::string gamepad_name(int slot) const; static std::string scancode_name(int scancode); private: void open_gamepad_by_device_index(int device_index); void close_gamepad_by_instance_id(SDL_JoystickID instance_id); SDL_GameController* get_player_gamepad(int player_idx, const GameConfig& cfg) const; std::array gamepads_{}; std::array gamepad_ids_{{-1, -1, -1, -1}}; std::array prev_keys_{}; std::array curr_keys_{}; std::array prev_gp_buttons_{}; std::array curr_gp_buttons_{}; float mouse_steer_accum_ = 0.0f; MenuInput menu_{}; bool rebind_active_ = false; int captured_scancode_ = 0; bool text_input_active_ = false; std::string text_chars_; bool text_backspace_ = false; bool text_confirm_ = false; bool text_cancel_ = false; }; } // namespace top_octane