bool CGameClientInput::OpenJoystick(const std::string &portAddress, const ControllerPtr &controller) { using namespace JOYSTICK; if (!controller) { CLog::Log(LOGERROR, "Failed to open port \"%s\", no controller given", portAddress.c_str()); return false; } const CControllerPortNode &port = m_controllers.GetPort(portAddress); if (!port.IsControllerAccepted(portAddress, controller->ID())) { CLog::Log(LOGERROR, "Failed to open port: Invalid controller \"%s\" on port \"%s\"", controller->ID().c_str(), portAddress.c_str()); return false; } std::string strId = controller->ID(); game_controller controllerStruct{}; controllerStruct.controller_id = strId.c_str(); controllerStruct.provides_input = controller->Topology().ProvidesInput(); controllerStruct.digital_button_count = controller->FeatureCount(FEATURE_TYPE::SCALAR, INPUT_TYPE::DIGITAL); controllerStruct.analog_button_count = controller->FeatureCount(FEATURE_TYPE::SCALAR, INPUT_TYPE::ANALOG); controllerStruct.analog_stick_count = controller->FeatureCount(FEATURE_TYPE::ANALOG_STICK); controllerStruct.accelerometer_count = controller->FeatureCount(FEATURE_TYPE::ACCELEROMETER); controllerStruct.key_count = controller->FeatureCount(FEATURE_TYPE::KEY); controllerStruct.rel_pointer_count = controller->FeatureCount(FEATURE_TYPE::RELPOINTER); controllerStruct.abs_pointer_count = controller->FeatureCount(FEATURE_TYPE::ABSPOINTER); controllerStruct.motor_count = controller->FeatureCount(FEATURE_TYPE::MOTOR); bool bSuccess = false; { CSingleLock lock(m_clientAccess); if (m_gameClient.Initialized()) { try { bSuccess = m_struct.toAddon.ConnectController(true, portAddress.c_str(), &controllerStruct); } catch (...) { m_gameClient.LogException("ConnectController()"); } } } if (bSuccess) { m_joysticks[portAddress].reset(new CGameClientJoystick(m_gameClient, portAddress, controller, m_struct.toAddon)); ProcessJoysticks(); return true; } return false; }
bool CGameClientInput::OpenMouse(const ControllerPtr &controller) { using namespace JOYSTICK; if (!controller) { CLog::Log(LOGERROR, "Failed to open mouse, no controller given"); return false; } //! @todo Move to player manager PERIPHERALS::PeripheralVector mice; CServiceBroker::GetPeripherals().GetPeripheralsWithFeature(mice, PERIPHERALS::FEATURE_MOUSE); if (mice.empty()) return false; std::string controllerId = controller->ID(); game_controller controllerStruct{}; controllerStruct.controller_id = controllerId.c_str(); controllerStruct.digital_button_count = controller->FeatureCount(FEATURE_TYPE::SCALAR, INPUT_TYPE::DIGITAL); controllerStruct.analog_button_count = controller->FeatureCount(FEATURE_TYPE::SCALAR, INPUT_TYPE::ANALOG); controllerStruct.analog_stick_count = controller->FeatureCount(FEATURE_TYPE::ANALOG_STICK); controllerStruct.accelerometer_count = controller->FeatureCount(FEATURE_TYPE::ACCELEROMETER); controllerStruct.key_count = controller->FeatureCount(FEATURE_TYPE::KEY); controllerStruct.rel_pointer_count = controller->FeatureCount(FEATURE_TYPE::RELPOINTER); controllerStruct.abs_pointer_count = controller->FeatureCount(FEATURE_TYPE::ABSPOINTER); controllerStruct.motor_count = controller->FeatureCount(FEATURE_TYPE::MOTOR); bool bSuccess = false; { CSingleLock lock(m_clientAccess); if (m_gameClient.Initialized()) { try { bSuccess = m_struct.toAddon.EnableMouse(true, &controllerStruct); } catch (...) { m_gameClient.LogException("EnableMouse()"); } } } if (bSuccess) { m_mouse.reset(new CGameClientMouse(m_gameClient, controllerId, m_struct.toAddon, mice.at(0).get())); return true; } return false; }
void CGameClient::UpdatePort(unsigned int port, const ControllerPtr& controller) { using namespace JOYSTICK; CSingleLock lock(m_critSection); if (Initialized()) { if (controller != CController::EmptyPtr) { std::string strId = controller->ID(); game_controller controllerStruct; controllerStruct.controller_id = strId.c_str(); controllerStruct.digital_button_count = controller->FeatureCount(FEATURE_TYPE::SCALAR, INPUT_TYPE::DIGITAL); controllerStruct.analog_button_count = controller->FeatureCount(FEATURE_TYPE::SCALAR, INPUT_TYPE::ANALOG); controllerStruct.analog_stick_count = controller->FeatureCount(FEATURE_TYPE::ANALOG_STICK); controllerStruct.accelerometer_count = controller->FeatureCount(FEATURE_TYPE::ACCELEROMETER); controllerStruct.key_count = 0; //! @todo controllerStruct.rel_pointer_count = controller->FeatureCount(FEATURE_TYPE::RELPOINTER); controllerStruct.abs_pointer_count = controller->FeatureCount(FEATURE_TYPE::ABSPOINTER); controllerStruct.motor_count = controller->FeatureCount(FEATURE_TYPE::MOTOR); try { m_struct.toAddon.UpdatePort(port, true, &controllerStruct); } catch (...) { LogException("UpdatePort()"); } } else { try { m_struct.toAddon.UpdatePort(port, false, nullptr); } catch (...) { LogException("UpdatePort()"); } } } }