1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
enum : u32 { BindingLimit = 3 };
struct InputMapping {
enum class Qualifier : u32 { None, Lo, Hi, Rumble };
auto bind() -> void;
auto bind(u32 binding, string assignment) -> void;
auto unbind() -> void;
auto unbind(u32 binding) -> void;
virtual auto bind(u32 binding, shared_pointer<HID::Device>, u32 groupID, u32 inputID, s16 oldValue, s16 newValue) -> bool = 0;
virtual auto value() -> s16 = 0;
virtual auto pressed() -> bool { return false; }
string assignments[BindingLimit];
struct Binding {
auto icon() -> multiFactorImage;
auto text() -> string;
shared_pointer<HID::Device> device;
u64 deviceID;
u32 groupID;
u32 inputID;
Qualifier qualifier = Qualifier::None;
};
Binding bindings[BindingLimit];
};
//0 or 1
struct InputDigital : InputMapping {
using InputMapping::bind;
auto bind(u32 binding, shared_pointer<HID::Device>, u32 groupID, u32 inputID, s16 oldValue, s16 newValue) -> bool override;
auto value() -> s16 override;
auto pressed() -> bool override;
};
//0 ... +32767
struct InputAnalog : InputMapping {
using InputMapping::bind;
auto bind(u32 binding, shared_pointer<HID::Device>, u32 groupID, u32 inputID, s16 oldValue, s16 newValue) -> bool override;
auto value() -> s16 override;
auto pressed() -> bool override;
};
//-32768 ... +32767
struct InputAbsolute : InputMapping {
using InputMapping::bind;
auto bind(u32 binding, shared_pointer<HID::Device>, u32 groupID, u32 inputID, s16 oldValue, s16 newValue) -> bool override;
auto value() -> s16 override;
};
//-32768 ... +32767
struct InputRelative : InputMapping {
using InputMapping::bind;
auto bind(u32 binding, shared_pointer<HID::Device>, u32 groupID, u32 inputID, s16 oldValue, s16 newValue) -> bool override;
auto value() -> s16 override;
};
//specifies a target joypad for force feedback
struct InputRumble : InputMapping {
using InputMapping::bind;
auto bind(u32 binding, shared_pointer<HID::Device>, u32 groupID, u32 inputID, s16 oldValue, s16 newValue) -> bool override;
auto value() -> s16 override;
auto rumble(bool enable) -> void;
};
struct InputHotkey : InputDigital {
InputHotkey(string name) : name(name) {}
auto& onPress(function<void ()> press) { return this->press = press, *this; }
auto& onRelease(function<void ()> release) { return this->release = release, *this; }
const string name;
private:
function<void ()> press;
function<void ()> release;
s16 state = 0;
friend class InputManager;
};
struct InputNode {
enum class Type : u32 { Digital, Analog, Absolute, Relative, Rumble };
Type type;
string name;
InputMapping* mapping;
};
struct InputPair {
enum class Type : u32 { Analog };
Type type;
string name;
InputMapping* mappingLo;
InputMapping* mappingHi;
};
struct InputDevice {
auto digital(string name, InputMapping& mapping) -> void {
inputs.append({InputNode::Type::Digital, name, &mapping});
}
auto analog(string name, InputMapping& mapping) -> void {
inputs.append({InputNode::Type::Analog, name, &mapping});
}
auto absolute(string name, InputMapping& mapping) -> void {
inputs.append({InputNode::Type::Absolute, name, &mapping});
}
auto relative(string name, InputMapping& mapping) -> void {
inputs.append({InputNode::Type::Relative, name, &mapping});
}
auto rumble(string name, InputMapping& mapping) -> void {
inputs.append({InputNode::Type::Rumble, name, &mapping});
}
auto analog(string name, InputMapping& mappingLo, InputMapping& mappingHi) -> void {
pairs.append({InputPair::Type::Analog, name, &mappingLo, &mappingHi});
}
string name;
vector<InputNode> inputs;
vector<InputPair> pairs;
};
struct InputPort {
auto append(const InputDevice& device) -> void {
devices.append(device);
}
string name;
vector<InputDevice> devices;
};
struct VirtualPad : InputDevice {
VirtualPad();
InputDigital up;
InputDigital down;
InputDigital left;
InputDigital right;
InputDigital select;
InputDigital start;
InputDigital a;
InputDigital b;
InputDigital c;
InputDigital x;
InputDigital y;
InputDigital z;
InputDigital l1;
InputDigital r1;
InputDigital l2;
InputDigital r2;
InputDigital lt;
InputDigital rt;
InputAnalog lup;
InputAnalog ldown;
InputAnalog lleft;
InputAnalog lright;
InputAnalog rup;
InputAnalog rdown;
InputAnalog rleft;
InputAnalog rright;
InputRumble rumble;
};
struct VirtualMouse : InputDevice {
VirtualMouse();
InputRelative x;
InputRelative y;
InputDigital left;
InputDigital middle;
InputDigital right;
};
struct VirtualPort {
VirtualPad pad;
VirtualMouse mouse;
};
struct InputManager {
auto create() -> void;
auto bind() -> void;
auto poll(bool force = false) -> void;
auto eventInput(shared_pointer<HID::Device>, u32 groupID, u32 inputID, s16 oldValue, s16 newValue) -> void;
//hotkeys.cpp
auto createHotkeys() -> void;
auto pollHotkeys() -> void;
vector<shared_pointer<HID::Device>> devices;
vector<InputHotkey> hotkeys;
u64 pollFrequency = 5;
u64 lastPoll = 0;
};
extern VirtualPort virtualPorts[5];
extern InputManager inputManager;
|