MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / get_controller_value

Method get_controller_value

linux/lnxcontroller.cpp:268–439  ·  view source on GitHub ↗

returns the value of a requested controller type. make sure you flush the controller before polling.

Source from the content-addressed store, hash-verified

266
267// returns the value of a requested controller type. make sure you flush the controller before polling.
268ct_config_data lnxgameController::get_controller_value(ct_type type_req) {
269 // will return the current value of a requested control type.
270 ct_config_data val = MAKE_CONFIG_DATA(INVALID_CONTROLLER_INFO, NULL_BINDING);
271 int i, j;
272
273 switch (type_req) {
274 int pov_n;
275
276 case ctNone:
277 break;
278 case ctKey:
279 val = makeword(0, ddio_KeyInKey());
280 break;
281
282 case ctButton:
283 for (i = 2; i < m_NumControls; i++) {
284 for (j = 0; j < m_ControlList[i].buttons; j++) {
285 if (m_ExtCtlStates[m_ControlList[i].id].btnpresses[j] &&
286 !(m_ExtCtlStates[m_ControlList[i].id].buttons & (1 << j))) {
287 val = MAKE_CONFIG_DATA(CONTROLLER_CTL_INFO(i, NULL_CONTROLLER), CONTROLLER_CTL_VALUE(j + 1, NULL_BINDING));
288 return val;
289 }
290 }
291 }
292 break;
293
294 case ctMouseButton:
295 for (j = 0; j < CT_MAX_BUTTONS; j++) {
296 if (ddio_MouseBtnUpCount(j)) {
297 // mprintf(0, "MseBtn %d down\n", j);
298 val = MAKE_CONFIG_DATA(CONTROLLER_CTL_INFO(1, NULL_CONTROLLER), CONTROLLER_CTL_VALUE(j + 1, NULL_BINDING));
299 return val;
300 }
301 }
302 break;
303
304 case ctAxis:
305 for (i = 2; i < m_NumControls; i++) {
306 float pos;
307 float limit;
308 unsigned ctl = CONTROLLER_CTL_INFO(i, NULL_CONTROLLER);
309
310 if (m_ControlList[i].flags & CTF_V_AXIS) {
311 limit = (m_ControlList[i].sens[CT_V_AXIS - 1] > 1.5f) ? 0.95f
312 : (m_ControlList[i].sens[CT_V_AXIS - 1] > 1.0f) ? 0.80f
313 : (m_ControlList[i].sens[CT_V_AXIS - 1] / 2);
314 pos = get_axis_value(i, CT_V_AXIS, ctAnalog);
315 if (fabs(pos) > limit)
316 val = MAKE_CONFIG_DATA(ctl, CONTROLLER_CTL_VALUE(CT_V_AXIS, NULL_BINDING));
317 }
318 if (m_ControlList[i].flags & CTF_U_AXIS) {
319 limit = (m_ControlList[i].sens[CT_U_AXIS - 1] > 1.5f) ? 0.95f
320 : (m_ControlList[i].sens[CT_U_AXIS - 1] > 1.0f) ? 0.80f
321 : (m_ControlList[i].sens[CT_U_AXIS - 1] / 2);
322 pos = get_axis_value(i, CT_U_AXIS, ctAnalog);
323 if (fabs(pos) > limit)
324 val = MAKE_CONFIG_DATA(ctl, CONTROLLER_CTL_VALUE(CT_U_AXIS, NULL_BINDING));
325 }

Callers 1

DoUIMethod · 0.45

Calls 2

ddio_KeyInKeyFunction · 0.85
ddio_MouseBtnUpCountFunction · 0.85

Tested by

no test coverage detected