Exemplo n.º 1
0
static bool rwebpad_joypad_init(void *data)
{
   int supported = emscripten_get_num_gamepads();
   (void)data;

   if (supported == EMSCRIPTEN_RESULT_NOT_SUPPORTED)
      return false;

   if (!g_rwebpad_initialized)
   {
      EMSCRIPTEN_RESULT r;
      g_rwebpad_initialized = true;

      /* callbacks needs to be registered for gamepads to connect */
      r = emscripten_set_gamepadconnected_callback(NULL, false,
         rwebpad_gamepad_cb);
      if (r != EMSCRIPTEN_RESULT_SUCCESS)
      {
         RARCH_ERR(
            "[EMSCRIPTEN/PAD] failed to create connect callback: %d\n", r);
      }

      r = emscripten_set_gamepaddisconnected_callback(NULL, false,
         rwebpad_gamepad_cb);
      if (r != EMSCRIPTEN_RESULT_SUCCESS)
      {
         RARCH_ERR(
            "[EMSCRIPTEN/PAD] failed to create disconnect callback: %d\n", r);
      }
   }

   return true;
}
Exemplo n.º 2
0
/* Function to scan the system for joysticks.
 * It should return 0, or -1 on an unrecoverable fatal error.
 */
int
SDL_SYS_JoystickInit(void)
{
    int retval, i, numjs;
    EmscriptenGamepadEvent gamepadState;

    numjoysticks = 0;
    numjs = emscripten_get_num_gamepads();

    /* Check if gamepad is supported by browser */
    if (numjs == EMSCRIPTEN_RESULT_NOT_SUPPORTED) {
        return SDL_SetError("Gamepads not supported");
    }

    /* handle already connected gamepads */
    if (numjs > 0) {
        for(i = 0; i < numjs; i++) {
            retval = emscripten_get_gamepad_status(i, &gamepadState);
            if (retval == EMSCRIPTEN_RESULT_SUCCESS) {
                Emscripten_JoyStickConnected(EMSCRIPTEN_EVENT_GAMEPADCONNECTED,
                                             &gamepadState,
                                             NULL);
            }
        }
    }

    retval = emscripten_set_gamepadconnected_callback(NULL,
                                                      0,
                                                      Emscripten_JoyStickConnected);

    if(retval != EMSCRIPTEN_RESULT_SUCCESS) {
        SDL_SYS_JoystickQuit();
        return SDL_SetError("Could not set gamepad connect callback");
    }

    retval = emscripten_set_gamepaddisconnected_callback(NULL,
                                                         0,
                                                         Emscripten_JoyStickDisconnected);
    if(retval != EMSCRIPTEN_RESULT_SUCCESS) {
        SDL_SYS_JoystickQuit();
        return SDL_SetError("Could not set gamepad disconnect callback");
    }

    return 0;
}
Exemplo n.º 3
0
bool Input::update()
{
	m_uLastInput	= m_uCurrentInput;

	if (false == m_bJoystickAttached)
	{
		int	iGamePads	= emscripten_get_num_gamepads();

		Log::instance()->logMessage("Gamepads %d", iGamePads);

		if (iGamePads > 0)
		{
			m_bJoystickAttached	= true;
		}
	}

	return	true;
}
Exemplo n.º 4
0
void FHTML5InputInterface::SendControllerEvents()
{
#if PLATFORM_HTML5_BROWSER
	// game pads can only be polled.
	static int PrevNumGamepads = 0;
	static bool GamepadSupported = true;

	const double CurrentTime = FPlatformTime::Seconds();

	if (GamepadSupported)
	{
		int NumGamepads = emscripten_get_num_gamepads();
		if (NumGamepads != PrevNumGamepads)
		{
			if (NumGamepads == EMSCRIPTEN_RESULT_NOT_SUPPORTED)
			{
				GamepadSupported = false;
				return;
			}
		}

		for(int CurrentGamePad = 0; CurrentGamePad < NumGamepads && CurrentGamePad < 5; ++CurrentGamePad) // max 5 game pads.
		{
			EmscriptenGamepadEvent GamePadEvent;
			int Failed = emscripten_get_gamepad_status(CurrentGamePad, &GamePadEvent);
			if (!Failed)
			{
				check(CurrentGamePad == GamePadEvent.index);
				for(int CurrentAxis = 0; CurrentAxis < GamePadEvent.numAxes; ++CurrentAxis)
				{
					if (GamePadEvent.axis[CurrentAxis] != PrevGamePadState[CurrentGamePad].axis[CurrentAxis])
					{

						MessageHandler->OnControllerAnalog(AxisMapping[CurrentAxis],CurrentGamePad, Reversed[CurrentAxis]*GamePadEvent.axis[CurrentAxis]);
					}
				}
				// edge trigger. 
				for(int CurrentButton = 0; CurrentButton < GamePadEvent.numButtons; ++CurrentButton)
				{
					// trigger for digital buttons. 
					if ( GamePadEvent.digitalButton[CurrentButton]   != PrevGamePadState[CurrentGamePad].digitalButton[CurrentButton] )
					{
						bool Triggered = GamePadEvent.digitalButton[CurrentButton] != 0;
						if ( Triggered )
						{
							MessageHandler->OnControllerButtonPressed(ButtonMapping[CurrentButton],CurrentGamePad, false); 
							LastPressedTime[CurrentGamePad][CurrentButton] = CurrentTime;
						}
						else 
						{
							MessageHandler->OnControllerButtonReleased(ButtonMapping[CurrentButton],CurrentGamePad, false); 
						}
					}
				}
				// repeat trigger. 
				const float RepeatDelta = 0.2f; 
				for(int CurrentButton = 0; CurrentButton < GamePadEvent.numButtons; ++CurrentButton)
				{
					if ( GamePadEvent.digitalButton[CurrentButton]  )
					{
						if (CurrentTime - LastPressedTime[CurrentGamePad][CurrentButton] > RepeatDelta) 
						{
							MessageHandler->OnControllerButtonPressed(ButtonMapping[CurrentButton],CurrentGamePad, true); 
							LastPressedTime[CurrentGamePad][CurrentButton] = CurrentTime; 
						}
					}
				}
				PrevGamePadState[CurrentGamePad] = GamePadEvent;
			}
		}
	}

#endif

}
Exemplo n.º 5
0
static void rwebpad_joypad_poll(void)
{
   /* this call makes emscripten poll gamepad state */
   (void)emscripten_get_num_gamepads();
}