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"
|
2008-08-14 18:42:47 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
|
|
// Event handler
|
|
|
|
//////////////////////////////////////////////////
|
2010-05-29 07:25:38 +00:00
|
|
|
CEventHandler::CEventHandler()
|
2008-08-14 18:42:47 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_pGameServer = 0;
|
|
|
|
Clear();
|
2008-08-14 18:42:47 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CEventHandler::SetGameServer(CGameContext *pGameServer)
|
2008-08-14 18:42:47 +00:00
|
|
|
{
|
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)
|
2008-08-14 18:42:47 +00:00
|
|
|
return 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_CurrentOffset+Size >= MAX_DATASIZE)
|
2008-08-14 18:42:47 +00:00
|
|
|
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++;
|
2008-08-14 18:42:47 +00:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CEventHandler::Clear()
|
2008-08-14 18:42:47 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_NumEvents = 0;
|
|
|
|
m_CurrentOffset = 0;
|
2008-08-14 18:42:47 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CEventHandler::Snap(int SnappingClient)
|
2008-08-14 18:42:47 +00:00
|
|
|
{
|
2011-12-31 10:06:34 +00:00
|
|
|
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++)
|
2008-08-14 18:42:47 +00:00
|
|
|
{
|
2011-12-31 10:06:34 +00:00
|
|
|
if(SnappingClient == -1 || CmaskIsSet(m_aClientMasks[i], SnappingClient))
|
2008-08-14 18:42:47 +00:00
|
|
|
{
|
2011-06-01 17:43:48 +00:00
|
|
|
CNetEvent_Common *ev = (CNetEvent_Common *)&m_aData[m_aOffsets[i]];
|
2011-12-31 10:06:34 +00:00
|
|
|
if(SnappingClient == -1 || distance(GameServer()->m_apPlayers[SnappingClient]->m_ViewPos, vec2(ev->m_X, ev->m_Y)) < 1500.0f)
|
2008-08-14 18:42:47 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
void *d = GameServer()->Server()->SnapNewItem(m_aTypes[i], i, m_aSizes[i]);
|
2010-12-16 02:29:08 +00:00
|
|
|
if(d)
|
|
|
|
mem_copy(d, &m_aData[m_aOffsets[i]], m_aSizes[i]);
|
2008-08-14 18:42:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|