MCPcopy Create free account
hub / github.com/ddnet/ddnet / UpdateButtonsGame

Method UpdateButtonsGame

src/game/client/components/touch_controls.cpp:977–1178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

975}
976
977void CTouchControls::UpdateButtonsGame(const std::vector<IInput::CTouchFingerState> &vTouchFingerStates)
978{
979 // Update cached button visibilities and store time that buttons become visible.
980 for(CTouchButton &TouchButton : m_vTouchButtons)
981 {
982 TouchButton.UpdateVisibilityGame();
983 }
984
985 const int DirectTouchAction = NextDirectTouchAction();
986 const vec2 ScreenSize = CalculateScreenSize();
987
988 std::vector<IInput::CTouchFingerState> vRemainingTouchFingerStates = vTouchFingerStates;
989
990 if(!m_vStaleFingers.empty())
991 {
992 // Remove stale fingers that are not pressed anymore.
993 m_vStaleFingers.erase(
994 std::remove_if(m_vStaleFingers.begin(), m_vStaleFingers.end(), [&](const IInput::CTouchFinger &Finger) {
995 return std::find_if(vRemainingTouchFingerStates.begin(), vRemainingTouchFingerStates.end(), [&](const IInput::CTouchFingerState &TouchFingerState) {
996 return TouchFingerState.m_Finger == Finger;
997 }) == vRemainingTouchFingerStates.end();
998 }),
999 m_vStaleFingers.end());
1000 // Prevent stale fingers from activating touch buttons and direct touch.
1001 vRemainingTouchFingerStates.erase(
1002 std::remove_if(vRemainingTouchFingerStates.begin(), vRemainingTouchFingerStates.end(), [&](const IInput::CTouchFingerState &TouchFingerState) {
1003 return std::find_if(m_vStaleFingers.begin(), m_vStaleFingers.end(), [&](const IInput::CTouchFinger &Finger) {
1004 return TouchFingerState.m_Finger == Finger;
1005 }) != m_vStaleFingers.end();
1006 }),
1007 vRemainingTouchFingerStates.end());
1008 }
1009
1010 // Remove remaining finger states for fingers which are responsible for active actions
1011 // and release action when the finger responsible for it is not pressed down anymore.
1012 bool GotDirectFingerState = false; // Whether DirectFingerState is valid
1013 IInput::CTouchFingerState DirectFingerState{}; // The finger that will be used to update the mouse position
1014 for(int Action = ACTION_AIM; Action < NUM_ACTIONS; ++Action)
1015 {
1016 if(!m_aDirectTouchActionStates[Action].m_Active)
1017 {
1018 continue;
1019 }
1020
1021 const auto ActiveFinger = std::find_if(vRemainingTouchFingerStates.begin(), vRemainingTouchFingerStates.end(), [&](const IInput::CTouchFingerState &TouchFingerState) {
1022 return TouchFingerState.m_Finger == m_aDirectTouchActionStates[Action].m_Finger;
1023 });
1024 if(ActiveFinger == vRemainingTouchFingerStates.end() || DirectTouchAction == NUM_ACTIONS)
1025 {
1026 m_aDirectTouchActionStates[Action].m_Active = false;
1027 if(Action != ACTION_AIM)
1028 {
1029 Console()->ExecuteLineStroked(0, ACTION_COMMANDS[Action], IConsole::CLIENT_ID_UNSPECIFIED);
1030 }
1031 }
1032 else
1033 {
1034 if(Action == m_DirectTouchLastAction)

Callers

nothing calls this directly

Calls 14

GraphicsFunction · 0.85
UpdateVisibilityGameMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
ExecuteLineStrokedMethod · 0.80
IsVisibleMethod · 0.80
IsInsideMethod · 0.80
CalcScreenParamsMethod · 0.80
ScreenAspectMethod · 0.80
GetWidthMethod · 0.80
GetHeightMethod · 0.80
IsActiveMethod · 0.45

Tested by

no test coverage detected