mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-20 15:08:19 +00:00
Merge #3498
3498: Make netclipping of entities and events respect shown distance (fixes #3420) r=heinrich5991 a=def- <!-- What is the motivation for the changes of this pull request --> ## Checklist - [x] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test if it works standalone, system.c especially - [ ] Considered possible null pointers and out of bounds array indexing - [ ] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
commit
5d45f061fa
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue