MCPcopy Create free account
hub / github.com/ClassicOldSong/Apollo / alloc_gamepad

Function alloc_gamepad

src/platform/windows/input.cpp:1175–1227  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1173 }
1174
1175 int alloc_gamepad(input_t &input, const gamepad_id_t &id, const gamepad_arrival_t &metadata, feedback_queue_t feedback_queue) {
1176 auto raw = (input_raw_t *) input.get();
1177
1178 if (!raw->vigem) {
1179 return 0;
1180 }
1181
1182 VIGEM_TARGET_TYPE selectedGamepadType;
1183
1184 if (config::input.gamepad == "x360"sv) {
1185 BOOST_LOG(info) << "Gamepad " << id.globalIndex << " will be Xbox 360 controller (manual selection)"sv;
1186 selectedGamepadType = Xbox360Wired;
1187 } else if (config::input.gamepad == "ds4"sv) {
1188 BOOST_LOG(info) << "Gamepad " << id.globalIndex << " will be DualShock 4 controller (manual selection)"sv;
1189 selectedGamepadType = DualShock4Wired;
1190 } else if (metadata.type == LI_CTYPE_PS) {
1191 BOOST_LOG(info) << "Gamepad " << id.globalIndex << " will be DualShock 4 controller (auto-selected by client-reported type)"sv;
1192 selectedGamepadType = DualShock4Wired;
1193 } else if (metadata.type == LI_CTYPE_XBOX) {
1194 BOOST_LOG(info) << "Gamepad " << id.globalIndex << " will be Xbox 360 controller (auto-selected by client-reported type)"sv;
1195 selectedGamepadType = Xbox360Wired;
1196 } else if (config::input.motion_as_ds4 && (metadata.capabilities & (LI_CCAP_ACCEL | LI_CCAP_GYRO))) {
1197 BOOST_LOG(info) << "Gamepad " << id.globalIndex << " will be DualShock 4 controller (auto-selected by motion sensor presence)"sv;
1198 selectedGamepadType = DualShock4Wired;
1199 } else if (config::input.touchpad_as_ds4 && (metadata.capabilities & LI_CCAP_TOUCHPAD)) {
1200 BOOST_LOG(info) << "Gamepad " << id.globalIndex << " will be DualShock 4 controller (auto-selected by touchpad presence)"sv;
1201 selectedGamepadType = DualShock4Wired;
1202 } else {
1203 BOOST_LOG(info) << "Gamepad " << id.globalIndex << " will be Xbox 360 controller (default)"sv;
1204 selectedGamepadType = Xbox360Wired;
1205 }
1206
1207 if (selectedGamepadType == Xbox360Wired) {
1208 if (metadata.capabilities & (LI_CCAP_ACCEL | LI_CCAP_GYRO)) {
1209 BOOST_LOG(warning) << "Gamepad " << id.globalIndex << " has motion sensors, but they are not usable when emulating an Xbox 360 controller"sv;
1210 }
1211 if (metadata.capabilities & LI_CCAP_TOUCHPAD) {
1212 BOOST_LOG(warning) << "Gamepad " << id.globalIndex << " has a touchpad, but it is not usable when emulating an Xbox 360 controller"sv;
1213 }
1214 if (metadata.capabilities & LI_CCAP_RGB_LED) {
1215 BOOST_LOG(warning) << "Gamepad " << id.globalIndex << " has an RGB LED, but it is not usable when emulating an Xbox 360 controller"sv;
1216 }
1217 } else if (selectedGamepadType == DualShock4Wired) {
1218 if (!(metadata.capabilities & (LI_CCAP_ACCEL | LI_CCAP_GYRO))) {
1219 BOOST_LOG(warning) << "Gamepad " << id.globalIndex << " is emulating a DualShock 4 controller, but the client gamepad doesn't have motion sensors active"sv;
1220 }
1221 if (!(metadata.capabilities & LI_CCAP_TOUCHPAD)) {
1222 BOOST_LOG(warning) << "Gamepad " << id.globalIndex << " is emulating a DualShock 4 controller, but the client gamepad doesn't have a touchpad"sv;
1223 }
1224 }
1225
1226 return raw->vigem->alloc_gamepad_internal(id, feedback_queue, selectedGamepadType);
1227 }
1228
1229 void free_gamepad(input_t &input, int nr) {
1230 auto raw = (input_raw_t *) input.get();

Callers

nothing calls this directly

Calls 2

getMethod · 0.45

Tested by

no test coverage detected