| 1338 | } |
| 1339 | |
| 1340 | void ProcessInputSources(const xr::System::Session::Frame& frame, Napi::Env env) |
| 1341 | { |
| 1342 | // Figure out the new state. |
| 1343 | std::set<xr::System::Session::Frame::InputSource::Identifier> added{}; |
| 1344 | std::set<xr::System::Session::Frame::InputSource::Identifier> current{}; |
| 1345 | std::set<xr::System::Session::Frame::InputSource::Identifier> removed{}; |
| 1346 | for (auto& inputSource : frame.InputSources) |
| 1347 | { |
| 1348 | if (!inputSource.TrackedThisFrame) |
| 1349 | { |
| 1350 | continue; |
| 1351 | } |
| 1352 | |
| 1353 | current.insert(inputSource.ID); |
| 1354 | |
| 1355 | auto found = m_idToInputSource.find(inputSource.ID); |
| 1356 | if (found == m_idToInputSource.end()) |
| 1357 | { |
| 1358 | // Create the new input source, which will have the correct spaces associated with it. |
| 1359 | m_idToInputSource.insert({inputSource.ID, CreateXRInputSource(inputSource, env)}); |
| 1360 | |
| 1361 | added.insert(inputSource.ID); |
| 1362 | } |
| 1363 | else |
| 1364 | { |
| 1365 | // Ensure the correct spaces are associated with the existing input source. |
| 1366 | auto val = found->second.Value(); |
| 1367 | SetXRInputSourceSpaces(val, inputSource); |
| 1368 | } |
| 1369 | } |
| 1370 | for (const auto& [id, ref] : m_idToInputSource) |
| 1371 | { |
| 1372 | if (current.find(id) == current.end()) |
| 1373 | { |
| 1374 | // Do not update space association since said spaces no longer exist. |
| 1375 | removed.insert(id); |
| 1376 | } |
| 1377 | } |
| 1378 | |
| 1379 | // Only need to do more if there's been a change. Note that this block of code assumes |
| 1380 | // that ALL known input sources -- including ones added AND REMOVED this frame -- are |
| 1381 | // currently up-to-date and accessible though m_idToInputSource. |
| 1382 | if (added.size() > 0 || removed.size() > 0) |
| 1383 | { |
| 1384 | // Update the input sources array. |
| 1385 | auto jsCurrent = Napi::Array::New(env); |
| 1386 | for (const auto id : current) |
| 1387 | { |
| 1388 | jsCurrent.Set(jsCurrent.Length(), m_idToInputSource[id].Value()); |
| 1389 | } |
| 1390 | m_jsInputSources = Napi::Persistent(jsCurrent); |
| 1391 | |
| 1392 | // Create and send the sources changed event. |
| 1393 | Napi::Array jsAdded = Napi::Array::New(env); |
| 1394 | for (const auto id : added) |
| 1395 | { |
| 1396 | jsAdded.Set(jsAdded.Length(), m_idToInputSource[id].Value()); |
| 1397 | } |
nothing calls this directly
no test coverage detected