ddnet/src/game/server/eventhandler.cpp

61 lines
1.6 KiB
C++
Raw Normal View History

2010-11-20 10:37:14 +00:00
/* (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. */
2010-05-29 07:25:38 +00:00
#include "eventhandler.h"
#include "gamecontext.h"
//////////////////////////////////////////////////
// Event handler
//////////////////////////////////////////////////
2010-05-29 07:25:38 +00:00
CEventHandler::CEventHandler()
{
2010-05-29 07:25:38 +00:00
m_pGameServer = 0;
Clear();
}
2010-05-29 07:25:38 +00:00
void CEventHandler::SetGameServer(CGameContext *pGameServer)
{
2010-05-29 07:25:38 +00:00
m_pGameServer = pGameServer;
}
void *CEventHandler::Create(int Type, int Size, int Mask)
{
if(m_NumEvents == MAX_EVENTS)
return 0;
2010-05-29 07:25:38 +00:00
if(m_CurrentOffset+Size >= MAX_DATASIZE)
return 0;
2010-05-29 07:25:38 +00:00
void *p = &m_aData[m_CurrentOffset];
m_aOffsets[m_NumEvents] = m_CurrentOffset;
m_aTypes[m_NumEvents] = Type;
m_aSizes[m_NumEvents] = Size;
m_aClientMasks[m_NumEvents] = Mask;
m_CurrentOffset += Size;
m_NumEvents++;
return p;
}
2010-05-29 07:25:38 +00:00
void CEventHandler::Clear()
{
2010-05-29 07:25:38 +00:00
m_NumEvents = 0;
m_CurrentOffset = 0;
}
2010-05-29 07:25:38 +00:00
void CEventHandler::Snap(int SnappingClient)
{
if (SnappingClient != -1 && GameServer()->m_apPlayers[SnappingClient]->m_Paused)
SnappingClient = GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID;
2010-05-29 07:25:38 +00:00
for(int i = 0; i < m_NumEvents; i++)
{
if(SnappingClient == -1 || CmaskIsSet(m_aClientMasks[i], SnappingClient))
{
2011-06-01 17:43:48 +00:00
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)
{
2010-05-29 07:25:38 +00:00
void *d = GameServer()->Server()->SnapNewItem(m_aTypes[i], i, m_aSizes[i]);
if(d)
mem_copy(d, &m_aData[m_aOffsets[i]], m_aSizes[i]);
}
}
}
}