From 1782d95d999df0aa0f5cdac3f6f5289f843ab7d5 Mon Sep 17 00:00:00 2001 From: def Date: Sun, 28 Jun 2020 11:48:25 +0200 Subject: [PATCH] Client tells server its zoom level (fixes #2087) and server adapts the visible distance to it --- datasrc/network.py | 5 +++++ src/game/client/gameclient.cpp | 14 ++++++++++++++ src/game/client/render.cpp | 13 +++++++++---- src/game/client/render.h | 1 + src/game/server/entities/character.cpp | 8 ++++---- src/game/server/gamecontext.cpp | 5 +++++ src/game/server/player.cpp | 1 + src/game/server/player.h | 1 + 8 files changed, 40 insertions(+), 8 deletions(-) diff --git a/datasrc/network.py b/datasrc/network.py index 6ed2a8395..0d546c808 100644 --- a/datasrc/network.py +++ b/datasrc/network.py @@ -425,4 +425,9 @@ Messages = [ NetMessageEx("Sv_MyOwnMessage", "my-own-message@heinrich5991.de", [ NetIntAny("m_Test"), ]), + + NetMessageEx("Cl_ShowDistance", "show-distance@netmsg.ddnet.tw", [ + NetIntAny("m_X"), + NetIntAny("m_Y"), + ]), ] diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index d5c49c8b0..3a401808d 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -1552,6 +1552,20 @@ void CGameClient::OnNewSnapshot() m_ShowOthers[g_Config.m_ClDummy] = g_Config.m_ClShowOthers; } + static float LastZoom = .0; + static float LastScreenAspect = .0; + if(m_pCamera->m_Zoom != LastZoom || Graphics()->ScreenAspect() != LastScreenAspect) + { + LastZoom = m_pCamera->m_Zoom; + LastScreenAspect = Graphics()->ScreenAspect(); + CNetMsg_Cl_ShowDistance Msg; + float x, y; + RenderTools()->CalcScreenParams(Graphics()->ScreenAspect(), m_pCamera->m_Zoom, &x, &y); + Msg.m_X = x; + Msg.m_Y = y; + Client()->SendPackMsg(&Msg, MSGFLAG_VITAL); + } + m_pGhost->OnNewSnapshot(); m_pRaceDemo->OnNewSnapshot(); diff --git a/src/game/client/render.cpp b/src/game/client/render.cpp index dfee6aab0..607d0b794 100644 --- a/src/game/client/render.cpp +++ b/src/game/client/render.cpp @@ -420,8 +420,12 @@ void CRenderTools::RenderTee(CAnimState *pAnim, CTeeRenderInfo *pInfo, int Emote } -static void CalcScreenParams(float Amount, float WMax, float HMax, float Aspect, float *w, float *h) +void CRenderTools::CalcScreenParams(float Aspect, float Zoom, float *w, float *h) { + const float Amount = 1150 * 1000; + const float WMax = 1500; + const float HMax = 1050; + float f = sqrtf(Amount) / sqrtf(Aspect); *w = f*Aspect; *h = f; @@ -438,17 +442,18 @@ static void CalcScreenParams(float Amount, float WMax, float HMax, float Aspect, *h = HMax; *w = *h*Aspect; } + + *w *= Zoom; + *h *= Zoom; } void CRenderTools::MapscreenToWorld(float CenterX, float CenterY, float ParallaxX, float ParallaxY, float OffsetX, float OffsetY, float Aspect, float Zoom, float *pPoints) { float Width, Height; - CalcScreenParams(1150*1000, 1500, 1050, Aspect, &Width, &Height); + CalcScreenParams(Aspect, Zoom, &Width, &Height); CenterX *= ParallaxX/100.0f; CenterY *= ParallaxY/100.0f; - Width *= Zoom; - Height *= Zoom; pPoints[0] = OffsetX+CenterX-Width/2; pPoints[1] = OffsetY+CenterY-Height/2; pPoints[2] = pPoints[0]+Width; diff --git a/src/game/client/render.h b/src/game/client/render.h index 459b0d107..1d5cb0d50 100644 --- a/src/game/client/render.h +++ b/src/game/client/render.h @@ -90,6 +90,7 @@ public: void RenderTileRectangle(int RectX, int RectY, int RectW, int RectH, unsigned char IndexIn, unsigned char IndexOut, float Scale, ColorRGBA Color, int RenderFlags, ENVELOPE_EVAL pfnEval, void *pUser, int ColorEnv, int ColorEnvOffset); // helpers + void CalcScreenParams(float Aspect, float Zoom, float *w, float *h); void MapscreenToWorld(float CenterX, float CenterY, float ParallaxX, float ParallaxY, float OffsetX, float OffsetY, float Aspect, float Zoom, float *pPoints); diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 213f407f0..3af763384 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -1285,13 +1285,13 @@ int CCharacter::NetworkClipped(int SnappingClient, vec2 CheckPos) return 0; float dx = GameServer()->m_apPlayers[SnappingClient]->m_ViewPos.x-CheckPos.x; + if(absolute(dx) > GameServer()->m_apPlayers[SnappingClient]->m_ShowDistance.y) + return 1; + float dy = GameServer()->m_apPlayers[SnappingClient]->m_ViewPos.y-CheckPos.y; - - if(absolute(dx) > 1000.0f || absolute(dy) > 800.0f) + if(absolute(dy) > GameServer()->m_apPlayers[SnappingClient]->m_ShowDistance.y) return 1; - if(distance(GameServer()->m_apPlayers[SnappingClient]->m_ViewPos, CheckPos) > 4000.0f) - return 1; return 0; } diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 0eb52b793..d1fc9444e 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -2035,6 +2035,11 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) pPlayer->m_ShowOthers = (bool)pMsg->m_Show; } } + else if (MsgID == NETMSGTYPE_CL_SHOWDISTANCE) + { + CNetMsg_Cl_ShowDistance *pMsg = (CNetMsg_Cl_ShowDistance *)pRawMsg; + pPlayer->m_ShowDistance = vec2(pMsg->m_X, pMsg->m_Y); + } else if (MsgID == NETMSGTYPE_CL_SETSPECTATORMODE && !m_World.m_Paused) { CNetMsg_Cl_SetSpectatorMode *pMsg = (CNetMsg_Cl_SetSpectatorMode *)pRawMsg; diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index d00febd0b..9eac4c620 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -108,6 +108,7 @@ void CPlayer::Reset() m_ShowOthers = g_Config.m_SvShowOthersDefault; m_ShowAll = g_Config.m_SvShowAllDefault; + m_ShowDistance = vec2(2000, 1500); m_SpecTeam = 0; m_NinjaJetpack = false; diff --git a/src/game/server/player.h b/src/game/server/player.h index 48b46dd08..9a0199f14 100644 --- a/src/game/server/player.h +++ b/src/game/server/player.h @@ -163,6 +163,7 @@ public: int64 m_Last_Team; bool m_ShowOthers; bool m_ShowAll; + vec2 m_ShowDistance; bool m_SpecTeam; bool m_NinjaJetpack; bool m_Afk;