Exemple #1
0
bool CGameClient::OpenPort(unsigned int port)
{
  // Fail if port is already open
  if (m_ports.find(port) != m_ports.end())
    return false;

  // Ensure hardware is open to receive events from the port
  if (!m_hardware)
    m_hardware.reset(new CGameClientHardware(this));

  ControllerVector controllers = GetControllers();
  if (!controllers.empty())
  {
    //! @todo Choose controller
    ControllerPtr& controller = controllers[0];

    m_ports[port].reset(new CGameClientJoystick(this, port, controller, &m_struct.toAddon));

    // If keyboard input is being captured by this add-on, force the port type to PERIPHERAL_JOYSTICK
    PERIPHERALS::PeripheralType device = PERIPHERALS::PERIPHERAL_UNKNOWN;
    if (m_bSupportsKeyboard)
      device = PERIPHERALS::PERIPHERAL_JOYSTICK;

    CServiceBroker::GetGameServices().PortManager().OpenPort(m_ports[port].get(), m_hardware.get(), this, port, device);

    UpdatePort(port, controller);

    return true;
  }

  return false;
}
Exemple #2
0
ControllerVector CGameClient::GetControllers(void) const
{
  using namespace ADDON;

  ControllerVector controllers;

  CGameServices& gameServices = CServiceBroker::GetGameServices();

  const ADDONDEPS& dependencies = GetDeps();
  for (ADDONDEPS::const_iterator it = dependencies.begin(); it != dependencies.end(); ++it)
  {
    ControllerPtr controller = gameServices.GetController(it->first);
    if (controller)
      controllers.push_back(controller);
  }

  if (controllers.empty())
  {
    // Use the default controller
    ControllerPtr controller = gameServices.GetDefaultController();
    if (controller)
      controllers.push_back(controller);
  }

  return controllers;
}
Exemple #3
0
ControllerVector CGameClientInput::GetControllers(const CGameClient &gameClient)
{
  using namespace ADDON;

  ControllerVector controllers;

  CGameServices& gameServices = CServiceBroker::GetGameServices();

  const auto& dependencies = gameClient.GetDependencies();
  for (auto it = dependencies.begin(); it != dependencies.end(); ++it)
  {
    ControllerPtr controller = gameServices.GetController(it->id);
    if (controller)
      controllers.push_back(controller);
  }

  if (controllers.empty())
  {
    // Use the default controller
    ControllerPtr controller = gameServices.GetDefaultController();
    if (controller)
      controllers.push_back(controller);
  }

  return controllers;
}