Extra2D/Extra2D/include/extra2d/platform/input_module.h

78 lines
1.6 KiB
C++

#pragma once
#include <extra2d/core/module.h>
#include <extra2d/platform/iinput.h>
#include <extra2d/platform/window_module.h>
#include <typeindex>
namespace extra2d {
/**
* @brief 输入模块
* 管理输入设备
*/
class InputModule : public Module {
public:
/**
* @brief 配置结构
*/
struct Cfg {
float deadzone;
float mouseSensitivity;
bool enableVibration;
int maxGamepads;
int priority;
Cfg()
: deadzone(0.15f)
, mouseSensitivity(1.0f)
, enableVibration(true)
, maxGamepads(4)
, priority(20)
{}
};
/**
* @brief 构造函数
* @param cfg 配置
*/
explicit InputModule(const Cfg& cfg = Cfg{});
/**
* @brief 析构函数
*/
~InputModule() override;
bool init() override;
void shutdown() override;
bool ok() const override { return initialized_; }
const char* name() const override { return "input"; }
int priority() const override { return cfg_.priority; }
/**
* @brief 获取依赖
* @return 依赖模块类型列表
*/
std::vector<std::type_index> deps() const override {
return {std::type_index(typeid(WindowModule))};
}
/**
* @brief 获取输入接口
* @return 输入接口指针
*/
IInput* input() const { return input_; }
/**
* @brief 更新输入状态
*/
void update();
private:
Cfg cfg_;
IInput* input_ = nullptr;
bool initialized_ = false;
};
} // namespace extra2d