init commit
This commit is contained in:
commit
15ab48343a
187 files changed
+12644
No files matched your search
@@ -0,0 +1,83 @@
|
||||
#pragma once
|
||||
|
||||
#include "core/config.hpp"
|
||||
|
||||
#include <SDL.h>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
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);
|
||||
|
||||
// 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<SDL_GameController*, kMaxGamepads> gamepads_{};
|
||||
std::array<SDL_JoystickID, kMaxGamepads> gamepad_ids_{{-1, -1, -1, -1}};
|
||||
std::array<uint8_t, SDL_NUM_SCANCODES> prev_keys_{};
|
||||
std::array<uint8_t, SDL_NUM_SCANCODES> curr_keys_{};
|
||||
std::array<bool, 16> prev_gp_buttons_{};
|
||||
std::array<bool, 16> curr_gp_buttons_{};
|
||||
|
||||
float mouse_steer_accum_ = 0.0f;
|
||||
MenuInput menu_{};
|
||||
bool rebind_active_ = false;
|
||||
int captured_scancode_ = 0;
|
||||
};
|
||||
|
||||
} // namespace top_octane
|
||||
Reference in new issue
Block a user