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

Method InitMultiView

src/game/client/gameclient.cpp:4962–5069  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4960}
4961
4962bool CGameClient::InitMultiView(int Team)
4963{
4964 float Width, Height;
4965 CleanMultiViewIds();
4966 m_MultiView.m_IsInit = true;
4967
4968 // get the current view coordinates
4969 Graphics()->CalcScreenParams(Graphics()->ScreenAspect(), m_Camera.m_Zoom, &Width, &Height);
4970 vec2 AxisX = vec2(m_Camera.m_Center.x - (Width / 2.0f), m_Camera.m_Center.x + (Width / 2.0f));
4971 vec2 AxisY = vec2(m_Camera.m_Center.y - (Height / 2.0f), m_Camera.m_Center.y + (Height / 2.0f));
4972
4973 if(Team > 0)
4974 {
4975 m_MultiViewTeam = Team;
4976 for(int ClientId = 0; ClientId < MAX_CLIENTS; ClientId++)
4977 m_aMultiViewId[ClientId] = m_Teams.Team(ClientId) == Team;
4978 }
4979 else
4980 {
4981 // we want to allow spectating players in teams directly if there is no other team on screen
4982 // to do that, -1 is used temporarily for "we don't know which team to spectate yet"
4983 m_MultiViewTeam = -1;
4984
4985 int Count = 0;
4986 for(int ClientId = 0; ClientId < MAX_CLIENTS; ClientId++)
4987 {
4988 vec2 PlayerPos;
4989
4990 // get the position of the player
4991 if(m_Snap.m_aCharacters[ClientId].m_Active)
4992 PlayerPos = vec2(m_Snap.m_aCharacters[ClientId].m_Cur.m_X, m_Snap.m_aCharacters[ClientId].m_Cur.m_Y);
4993 else if(m_aClients[ClientId].m_Spec)
4994 PlayerPos = m_aClients[ClientId].m_SpecChar;
4995 else
4996 continue;
4997
4998 if(PlayerPos.x == 0 || PlayerPos.y == 0)
4999 continue;
5000
5001 // skip players that aren't in view
5002 if(PlayerPos.x <= AxisX.x || PlayerPos.x >= AxisX.y || PlayerPos.y <= AxisY.x || PlayerPos.y >= AxisY.y)
5003 continue;
5004
5005 if(m_MultiViewTeam == -1)
5006 {
5007 // use the current player's team for now, but it might switch to team 0 if any other team is found
5008 m_MultiViewTeam = m_Teams.Team(ClientId);
5009 }
5010 else if(m_MultiViewTeam != 0 && m_Teams.Team(ClientId) != m_MultiViewTeam)
5011 {
5012 // mismatched teams; remove all previously added players again and switch to team 0 instead
5013 std::fill_n(m_aMultiViewId, ClientId, false);
5014 m_MultiViewTeam = 0;
5015 }
5016
5017 m_aMultiViewId[ClientId] = true;
5018 Count++;
5019 }

Callers

nothing calls this directly

Calls 6

GraphicsFunction · 0.85
distanceFunction · 0.85
CalcScreenParamsMethod · 0.80
ScreenAspectMethod · 0.80
SpectateMethod · 0.80
TeamMethod · 0.45

Tested by

no test coverage detected