MCPcopy Create free account
hub / github.com/SFML/SFML / update

Method update

src/SFML/Window/Android/JoystickImpl.cpp:207–242  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

205
206////////////////////////////////////////////////////////////
207JoystickState JoystickImpl::update() const
208{
209 // Retrieve activity states
210 ActivityStates& states = getActivity();
211 const std::lock_guard lock(states.mutex);
212
213 auto jni = Jni::attachCurrentThread(*states.activity);
214 if (!jni)
215 {
216 err() << "Failed to initialize JNI" << std::endl;
217 return {false};
218 }
219
220 auto inputDeviceClass = JniInputDeviceClass::findClass(jni->getEnv());
221 if (!inputDeviceClass)
222 {
223 return {false};
224 }
225
226 if (!m_currentDeviceIdx)
227 {
228 // Should never happen
229 return {false};
230 }
231
232 const bool isConnected = inputDeviceClass->getDevice(*m_currentDeviceIdx).has_value();
233 if (states.joystickStates.find(*m_currentDeviceIdx) == states.joystickStates.end())
234 {
235 // This technically shouldn't happen, but when I have connect physical gamepad
236 // and then connect/disconnect a bluetooth one, states for the physical one
237 // disappears for a frame and then it reconnects.
238 return {false};
239 }
240
241 return {isConnected, states.joystickStates[*m_currentDeviceIdx].axes, states.joystickStates[*m_currentDeviceIdx].buttons};
242}
243
244
245////////////////////////////////////////////////////////////

Callers

nothing calls this directly

Calls 3

findMethod · 0.80
getDeviceMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected