Make netclipping of entities and events respect shown distance (fixes #3420)

This commit is contained in:
def 2021-01-11 18:28:14 +01:00
parent 460f2190f5
commit cbda5b720a
6 changed files with 32 additions and 44 deletions

View file

@ -1293,27 +1293,6 @@ void CCharacter::Snap(int SnappingClient)
pDDNetCharacter->m_StrongWeakID = m_StrongWeakID;
}
int CCharacter::NetworkClipped(int SnappingClient)
{
return NetworkClipped(SnappingClient, m_Pos);
}
int CCharacter::NetworkClipped(int SnappingClient, vec2 CheckPos)
{
if(SnappingClient == -1 || GameServer()->m_apPlayers[SnappingClient]->m_ShowAll)
return 0;
float dx = GameServer()->m_apPlayers[SnappingClient]->m_ViewPos.x - CheckPos.x;
if(absolute(dx) > GameServer()->m_apPlayers[SnappingClient]->m_ShowDistance.x)
return 1;
float dy = GameServer()->m_apPlayers[SnappingClient]->m_ViewPos.y - CheckPos.y;
if(absolute(dy) > GameServer()->m_apPlayers[SnappingClient]->m_ShowDistance.y)
return 1;
return 0;
}
// DDRace
bool CCharacter::CanCollide(int ClientID)

View file

@ -40,8 +40,6 @@ public:
virtual void TickDefered();
virtual void TickPaused();
virtual void Snap(int SnappingClient);
virtual int NetworkClipped(int SnappingClient);
virtual int NetworkClipped(int SnappingClient, vec2 CheckPos);
bool IsGrounded();

View file

@ -29,25 +29,14 @@ CEntity::~CEntity()
Server()->SnapFreeID(m_ID);
}
int CEntity::NetworkClipped(int SnappingClient)
bool CEntity::NetworkClipped(int SnappingClient)
{
return NetworkClipped(SnappingClient, m_Pos);
return ::NetworkClipped(GameServer(), SnappingClient, m_Pos);
}
int CEntity::NetworkClipped(int SnappingClient, vec2 CheckPos)
bool CEntity::NetworkClipped(int SnappingClient, vec2 CheckPos)
{
if(SnappingClient == -1)
return 0;
float dx = GameServer()->m_apPlayers[SnappingClient]->m_ViewPos.x - CheckPos.x;
float dy = GameServer()->m_apPlayers[SnappingClient]->m_ViewPos.y - CheckPos.y;
if(absolute(dx) > 1000.0f || absolute(dy) > 800.0f)
return 1;
if(distance(GameServer()->m_apPlayers[SnappingClient]->m_ViewPos, CheckPos) > 4000.0f)
return 1;
return 0;
return ::NetworkClipped(GameServer(), SnappingClient, CheckPos);
}
bool CEntity::GameLayerClipped(vec2 CheckPos)
@ -96,3 +85,19 @@ bool CEntity::GetNearestAirPosPlayer(vec2 PlayerPos, vec2 *OutPos)
}
return false;
}
bool NetworkClipped(CGameContext *pGameServer, int SnappingClient, vec2 CheckPos)
{
if(SnappingClient == -1 || pGameServer->m_apPlayers[SnappingClient]->m_ShowAll)
return false;
float dx = pGameServer->m_apPlayers[SnappingClient]->m_ViewPos.x - CheckPos.x;
if(absolute(dx) > pGameServer->m_apPlayers[SnappingClient]->m_ShowDistance.x)
return true;
float dy = pGameServer->m_apPlayers[SnappingClient]->m_ViewPos.y - CheckPos.y;
if(absolute(dy) > pGameServer->m_apPlayers[SnappingClient]->m_ShowDistance.y)
return true;
return false;
}

View file

@ -6,6 +6,7 @@
#include <base/vmath.h>
#include "alloc.h"
#include "gamecontext.h"
#include "gameworld.h"
/*
@ -119,7 +120,7 @@ public:
virtual void Snap(int SnappingClient) {}
/*
Function: networkclipped(int snapping_client)
Function: NetworkClipped
Performs a series of test to see if a client can see the
entity.
@ -130,10 +131,10 @@ public:
recording.
Returns:
Non-zero if the entity doesn't have to be in the snapshot.
True if the entity doesn't have to be in the snapshot.
*/
virtual int NetworkClipped(int SnappingClient);
virtual int NetworkClipped(int SnappingClient, vec2 CheckPos);
bool NetworkClipped(int SnappingClient);
bool NetworkClipped(int SnappingClient, vec2 CheckPos);
bool GameLayerClipped(vec2 CheckPos);
@ -146,4 +147,6 @@ public:
int m_Layer;
};
bool NetworkClipped(CGameContext *pGameServer, int SnappingClient, vec2 CheckPos);
#endif

View file

@ -1,6 +1,8 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include "eventhandler.h"
#include "entity.h"
#include "gamecontext.h"
#include "player.h"
@ -48,7 +50,7 @@ void CEventHandler::Snap(int SnappingClient)
if(SnappingClient == -1 || CmaskIsSet(m_aClientMasks[i], SnappingClient))
{
CNetEvent_Common *ev = (CNetEvent_Common *)&m_aData[m_aOffsets[i]];
if(SnappingClient == -1 || distance(GameServer()->m_apPlayers[SnappingClient]->m_ViewPos, vec2(ev->m_X, ev->m_Y)) < 1500.0f)
if(!NetworkClipped(GameServer(), SnappingClient, vec2(ev->m_X, ev->m_Y)))
{
int Type = m_aTypes[i];
int Size = m_aSizes[i];

View file

@ -4,7 +4,8 @@
#define GAME_SERVER_EVENTHANDLER_H
#include <base/system.h>
//
#include <base/vmath.h>
class CEventHandler
{
static const int MAX_EVENTS = 128;