mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 22:48:18 +00:00
Make netclipping of entities and events respect shown distance (fixes #3420)
This commit is contained in:
parent
460f2190f5
commit
cbda5b720a
|
@ -1293,27 +1293,6 @@ void CCharacter::Snap(int SnappingClient)
|
||||||
pDDNetCharacter->m_StrongWeakID = m_StrongWeakID;
|
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
|
// DDRace
|
||||||
|
|
||||||
bool CCharacter::CanCollide(int ClientID)
|
bool CCharacter::CanCollide(int ClientID)
|
||||||
|
|
|
@ -40,8 +40,6 @@ public:
|
||||||
virtual void TickDefered();
|
virtual void TickDefered();
|
||||||
virtual void TickPaused();
|
virtual void TickPaused();
|
||||||
virtual void Snap(int SnappingClient);
|
virtual void Snap(int SnappingClient);
|
||||||
virtual int NetworkClipped(int SnappingClient);
|
|
||||||
virtual int NetworkClipped(int SnappingClient, vec2 CheckPos);
|
|
||||||
|
|
||||||
bool IsGrounded();
|
bool IsGrounded();
|
||||||
|
|
||||||
|
|
|
@ -29,25 +29,14 @@ CEntity::~CEntity()
|
||||||
Server()->SnapFreeID(m_ID);
|
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 ::NetworkClipped(GameServer(), SnappingClient, CheckPos);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CEntity::GameLayerClipped(vec2 CheckPos)
|
bool CEntity::GameLayerClipped(vec2 CheckPos)
|
||||||
|
@ -96,3 +85,19 @@ bool CEntity::GetNearestAirPosPlayer(vec2 PlayerPos, vec2 *OutPos)
|
||||||
}
|
}
|
||||||
return false;
|
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 <base/vmath.h>
|
||||||
|
|
||||||
#include "alloc.h"
|
#include "alloc.h"
|
||||||
|
#include "gamecontext.h"
|
||||||
#include "gameworld.h"
|
#include "gameworld.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -119,7 +120,7 @@ public:
|
||||||
virtual void Snap(int SnappingClient) {}
|
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
|
Performs a series of test to see if a client can see the
|
||||||
entity.
|
entity.
|
||||||
|
|
||||||
|
@ -130,10 +131,10 @@ public:
|
||||||
recording.
|
recording.
|
||||||
|
|
||||||
Returns:
|
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);
|
bool NetworkClipped(int SnappingClient);
|
||||||
virtual int NetworkClipped(int SnappingClient, vec2 CheckPos);
|
bool NetworkClipped(int SnappingClient, vec2 CheckPos);
|
||||||
|
|
||||||
bool GameLayerClipped(vec2 CheckPos);
|
bool GameLayerClipped(vec2 CheckPos);
|
||||||
|
|
||||||
|
@ -146,4 +147,6 @@ public:
|
||||||
int m_Layer;
|
int m_Layer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool NetworkClipped(CGameContext *pGameServer, int SnappingClient, vec2 CheckPos);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
/* (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. */
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
||||||
#include "eventhandler.h"
|
#include "eventhandler.h"
|
||||||
|
|
||||||
|
#include "entity.h"
|
||||||
#include "gamecontext.h"
|
#include "gamecontext.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
|
||||||
|
@ -48,7 +50,7 @@ void CEventHandler::Snap(int SnappingClient)
|
||||||
if(SnappingClient == -1 || CmaskIsSet(m_aClientMasks[i], SnappingClient))
|
if(SnappingClient == -1 || CmaskIsSet(m_aClientMasks[i], SnappingClient))
|
||||||
{
|
{
|
||||||
CNetEvent_Common *ev = (CNetEvent_Common *)&m_aData[m_aOffsets[i]];
|
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 Type = m_aTypes[i];
|
||||||
int Size = m_aSizes[i];
|
int Size = m_aSizes[i];
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
#define GAME_SERVER_EVENTHANDLER_H
|
#define GAME_SERVER_EVENTHANDLER_H
|
||||||
|
|
||||||
#include <base/system.h>
|
#include <base/system.h>
|
||||||
//
|
#include <base/vmath.h>
|
||||||
|
|
||||||
class CEventHandler
|
class CEventHandler
|
||||||
{
|
{
|
||||||
static const int MAX_EVENTS = 128;
|
static const int MAX_EVENTS = 128;
|
||||||
|
|
Loading…
Reference in a new issue