MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / ProcessJoystick_SDL

Function ProcessJoystick_SDL

engine/Poseidon/Input/InputProcessingSdl.cpp:422–643  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

420 DWORD now = GlobalTickCount();
421 SDLInput_BufferKeyEvent(SDL_SCANCODE_ESCAPE, true, now);
422 SDLInput_BufferKeyEvent(SDL_SCANCODE_ESCAPE, false, now + 1);
423 }
424 SDLInput_BufferControllerUiAction(ControllerUiAction::Cancel, true);
425 }
426 if (GInput.gamepad.stickButtonsToDo[2])
427 SDLInput_BufferControllerUiAction(ControllerUiAction::Preview, false);
428 if (GInput.gamepad.stickButtonsToDo[3])
429 SDLInput_BufferControllerUiAction(ControllerUiAction::Delete, false);
430 if (GInput.gamepad.stickButtonsToDo[4])
431 SDLInput_BufferControllerUiAction(ControllerUiAction::PreviousTab, false);
432 if (GInput.gamepad.stickButtonsToDo[5])
433 SDLInput_BufferControllerUiAction(ControllerUiAction::NextTab, false);
434 if (GInput.gamepad.stickButtonsToDo[6])
435 SDLInput_BufferControllerUiAction(ControllerUiAction::PagePrevious, true);
436 if (GInput.gamepad.stickButtonsToDo[7])
437 SDLInput_BufferControllerUiAction(ControllerUiAction::PageNext, true);
438 if (GInput.gamepad.stickButtonsToDo[9])
439 SDLInput_BufferControllerUiAction(ControllerUiAction::Pause, false);
440}
441
442// ProcessJoystick — called from GameLoop after ProcessKeyboard
443
444void ProcessJoystick_SDL()
445{
446 for (int i = 0; i < N_JOYSTICK_BUTTONS; i++)
447 {
448 GInput.gamepad.stickButtons[i] = 0;
449 GInput.gamepad.stickButtonsToDo[i] = false;
450 }
451 for (int i = 0; i < N_JOYSTICK_POV; i++)
452 {
453 GInput.gamepad.stickPov[i] = false;
454 GInput.gamepad.stickPovToDo[i] = false;
455 }
456 for (int i = 0; i < N_JOYSTICK_AXES; i++)
457 GInput.gamepad.stickAxis[i] = 0;
458
459 if (!sGamepad)
460 {
461 // Graphics backends call SDL_Init(SDL_INIT_VIDEO) only, so the
462 // gamepad subsystem isn't running by default — without this
463 // SDL_HasGamepad always returns false and the pad is invisible
464 // even when physically connected. Init once, lazily.
465 if (!SDL_WasInit(SDL_INIT_GAMEPAD))
466 SDL_InitSubSystem(SDL_INIT_GAMEPAD);
467 // Auto-open first available gamepad if not yet opened
468 if (SDL_HasGamepad())
469 {
470 int count = 0;
471 SDL_JoystickID* ids = SDL_GetGamepads(&count);
472 if (ids && count > 0)
473 sGamepad = SDL_OpenGamepad(ids[0]);
474 SDL_free(ids);
475 }
476 }
477
478 float syntheticLx = 0.0f;
479 float syntheticLy = 0.0f;

Callers 1

ProcessJoystickFunction · 0.85

Calls 12

ApplyDeadzoneFunction · 0.85
CircleToSquareFunction · 0.85
saturatefFunction · 0.85
absFunction · 0.85
GetSyntheticLeftStickMethod · 0.80
IsUserInputEnabledMethod · 0.80
ResetDirectionsMethod · 0.80
UpdateMethod · 0.45

Tested by

no test coverage detected