mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge #2401
2401: Client tells server its zoom level (fixes #2087) r=heinrich5991 a=def- and server adapts the visible distance to it Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
commit
a79b1265df
|
@ -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"),
|
||||
]),
|
||||
]
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue