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. */
|
2008-08-14 18:25:44 +00:00
|
|
|
#ifndef GAME_SERVER_ENTITY_H
|
|
|
|
#define GAME_SERVER_ENTITY_H
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <base/vmath.h>
|
|
|
|
#include <game/server/gameworld.h>
|
2020-09-26 19:41:58 +00:00
|
|
|
#include <new>
|
2008-08-14 18:25:44 +00:00
|
|
|
|
2008-09-24 09:03:49 +00:00
|
|
|
#define MACRO_ALLOC_HEAP() \
|
2020-09-26 19:41:58 +00:00
|
|
|
public: \
|
2010-05-29 07:25:38 +00:00
|
|
|
void *operator new(size_t Size) \
|
2008-09-24 09:03:49 +00:00
|
|
|
{ \
|
2018-04-09 09:56:39 +00:00
|
|
|
void *p = malloc(Size); \
|
2010-05-29 07:25:38 +00:00
|
|
|
mem_zero(p, Size); \
|
2008-09-24 09:03:49 +00:00
|
|
|
return p; \
|
|
|
|
} \
|
2010-05-29 07:25:38 +00:00
|
|
|
void operator delete(void *pPtr) \
|
2008-09-24 09:03:49 +00:00
|
|
|
{ \
|
2018-04-09 09:56:39 +00:00
|
|
|
free(pPtr); \
|
2008-09-24 09:03:49 +00:00
|
|
|
} \
|
2020-09-26 19:41:58 +00:00
|
|
|
\
|
|
|
|
private:
|
2008-09-24 09:03:49 +00:00
|
|
|
|
|
|
|
#define MACRO_ALLOC_POOL_ID() \
|
2020-09-26 19:41:58 +00:00
|
|
|
public: \
|
2010-05-29 07:25:38 +00:00
|
|
|
void *operator new(size_t Size, int id); \
|
2017-09-06 08:54:29 +00:00
|
|
|
void operator delete(void *p, int id); \
|
2020-11-05 10:47:07 +00:00
|
|
|
void operator delete(void *p); /* NOLINT(misc-new-delete-overloads) */ \
|
2020-09-26 19:41:58 +00:00
|
|
|
\
|
|
|
|
private:
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#define MACRO_ALLOC_POOL_ID_IMPL(POOLTYPE, PoolSize) \
|
|
|
|
static char ms_PoolData##POOLTYPE[PoolSize][sizeof(POOLTYPE)] = {{0}}; \
|
|
|
|
static int ms_PoolUsed##POOLTYPE[PoolSize] = {0}; \
|
|
|
|
void *POOLTYPE::operator new(size_t Size, int id) \
|
2008-09-24 09:03:49 +00:00
|
|
|
{ \
|
2010-05-29 07:25:38 +00:00
|
|
|
dbg_assert(sizeof(POOLTYPE) == Size, "size error"); \
|
|
|
|
dbg_assert(!ms_PoolUsed##POOLTYPE[id], "already used"); \
|
2008-09-24 09:03:49 +00:00
|
|
|
/*dbg_msg("pool", "++ %s %d", #POOLTYPE, id);*/ \
|
2010-05-29 07:25:38 +00:00
|
|
|
ms_PoolUsed##POOLTYPE[id] = 1; \
|
|
|
|
mem_zero(ms_PoolData##POOLTYPE[id], Size); \
|
|
|
|
return ms_PoolData##POOLTYPE[id]; \
|
2008-09-24 09:03:49 +00:00
|
|
|
} \
|
2017-09-06 08:54:29 +00:00
|
|
|
void POOLTYPE::operator delete(void *p, int id) \
|
|
|
|
{ \
|
|
|
|
dbg_assert(ms_PoolUsed##POOLTYPE[id], "not used"); \
|
2020-09-26 19:41:58 +00:00
|
|
|
dbg_assert(id == (POOLTYPE *)p - (POOLTYPE *)ms_PoolData##POOLTYPE, "invalid id"); \
|
2017-09-06 08:54:29 +00:00
|
|
|
/*dbg_msg("pool", "-- %s %d", #POOLTYPE, id);*/ \
|
|
|
|
ms_PoolUsed##POOLTYPE[id] = 0; \
|
|
|
|
mem_zero(ms_PoolData##POOLTYPE[id], sizeof(POOLTYPE)); \
|
|
|
|
} \
|
2020-11-05 10:47:07 +00:00
|
|
|
void POOLTYPE::operator delete(void *p) /* NOLINT(misc-new-delete-overloads) */ \
|
2008-09-24 09:03:49 +00:00
|
|
|
{ \
|
2020-09-26 19:41:58 +00:00
|
|
|
int id = (POOLTYPE *)p - (POOLTYPE *)ms_PoolData##POOLTYPE; \
|
2010-05-29 07:25:38 +00:00
|
|
|
dbg_assert(ms_PoolUsed##POOLTYPE[id], "not used"); \
|
2008-09-24 09:03:49 +00:00
|
|
|
/*dbg_msg("pool", "-- %s %d", #POOLTYPE, id);*/ \
|
2010-05-29 07:25:38 +00:00
|
|
|
ms_PoolUsed##POOLTYPE[id] = 0; \
|
|
|
|
mem_zero(ms_PoolData##POOLTYPE[id], sizeof(POOLTYPE)); \
|
2008-09-24 09:03:49 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-14 18:25:44 +00:00
|
|
|
/*
|
|
|
|
Class: Entity
|
|
|
|
Basic entity class.
|
|
|
|
*/
|
2010-05-29 07:25:38 +00:00
|
|
|
class CEntity
|
2008-08-14 18:25:44 +00:00
|
|
|
{
|
2008-09-24 09:03:49 +00:00
|
|
|
MACRO_ALLOC_HEAP()
|
2008-08-14 18:25:44 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
friend class CGameWorld; // entity list handling
|
2010-05-29 07:25:38 +00:00
|
|
|
CEntity *m_pPrevTypeEntity;
|
|
|
|
CEntity *m_pNextTypeEntity;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-14 18:25:44 +00:00
|
|
|
protected:
|
2013-11-13 12:25:26 +00:00
|
|
|
class CGameWorld *m_pGameWorld;
|
2010-05-29 07:25:38 +00:00
|
|
|
bool m_MarkedForDestroy;
|
2011-02-12 10:40:36 +00:00
|
|
|
int m_ID;
|
2011-01-19 17:27:50 +00:00
|
|
|
int m_ObjType;
|
2020-09-26 19:41:58 +00:00
|
|
|
|
2008-08-14 18:25:44 +00:00
|
|
|
public:
|
2010-05-29 07:25:38 +00:00
|
|
|
CEntity(CGameWorld *pGameWorld, int Objtype);
|
|
|
|
virtual ~CEntity();
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
class CGameWorld *GameWorld() { return m_pGameWorld; }
|
|
|
|
class CGameContext *GameServer() { return GameWorld()->GameServer(); }
|
|
|
|
class IServer *Server() { return GameWorld()->Server(); }
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CEntity *TypeNext() { return m_pNextTypeEntity; }
|
|
|
|
CEntity *TypePrev() { return m_pPrevTypeEntity; }
|
2008-08-14 18:25:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: destroy
|
2018-07-10 09:29:02 +00:00
|
|
|
Destroys the entity.
|
2008-08-14 18:25:44 +00:00
|
|
|
*/
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void Destroy() { delete this; }
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-14 18:25:44 +00:00
|
|
|
/*
|
|
|
|
Function: reset
|
2008-10-06 18:05:01 +00:00
|
|
|
Called when the game resets the map. Puts the entity
|
|
|
|
back to it's starting state or perhaps destroys it.
|
2008-08-14 18:25:44 +00:00
|
|
|
*/
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void Reset() {}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-14 18:25:44 +00:00
|
|
|
/*
|
|
|
|
Function: tick
|
2008-10-06 18:05:01 +00:00
|
|
|
Called progress the entity to the next tick. Updates
|
|
|
|
and moves the entity to it's new state and position.
|
2008-08-14 18:25:44 +00:00
|
|
|
*/
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void Tick() {}
|
2008-08-14 18:25:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: tick_defered
|
2008-10-06 18:05:01 +00:00
|
|
|
Called after all entities tick() function has been called.
|
2008-08-14 18:25:44 +00:00
|
|
|
*/
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void TickDefered() {}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2012-01-09 23:49:31 +00:00
|
|
|
/*
|
|
|
|
Function: TickPaused
|
|
|
|
Called when the game is paused, to freeze the state and position of the entity.
|
|
|
|
*/
|
|
|
|
virtual void TickPaused() {}
|
|
|
|
|
2008-08-14 18:25:44 +00:00
|
|
|
/*
|
|
|
|
Function: snap
|
2008-10-06 18:05:01 +00:00
|
|
|
Called when a new snapshot is being generated for a specific
|
|
|
|
client.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-14 18:25:44 +00:00
|
|
|
Arguments:
|
|
|
|
snapping_client - ID of the client which snapshot is
|
|
|
|
being generated. Could be -1 to create a complete
|
|
|
|
snapshot of everything in the game for demo
|
|
|
|
recording.
|
|
|
|
*/
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void Snap(int SnappingClient) {}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-10-06 18:05:01 +00:00
|
|
|
/*
|
|
|
|
Function: networkclipped(int snapping_client)
|
|
|
|
Performs a series of test to see if a client can see the
|
|
|
|
entity.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
snapping_client - ID of the client which snapshot is
|
|
|
|
being generated. Could be -1 to create a complete
|
|
|
|
snapshot of everything in the game for demo
|
|
|
|
recording.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-10-06 18:05:01 +00:00
|
|
|
Returns:
|
|
|
|
Non-zero if the entity doesn't have to be in the snapshot.
|
|
|
|
*/
|
2014-01-10 21:54:07 +00:00
|
|
|
virtual int NetworkClipped(int SnappingClient);
|
|
|
|
virtual int NetworkClipped(int SnappingClient, vec2 CheckPos);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-01-08 10:34:19 +00:00
|
|
|
bool GameLayerClipped(vec2 CheckPos);
|
2008-08-14 18:25:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Variable: proximity_radius
|
2008-10-06 18:05:01 +00:00
|
|
|
Contains the physical size of the entity.
|
2008-08-14 18:25:44 +00:00
|
|
|
*/
|
2010-05-29 07:25:38 +00:00
|
|
|
float m_ProximityRadius;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-14 18:25:44 +00:00
|
|
|
/*
|
|
|
|
Variable: pos
|
2008-10-06 18:05:01 +00:00
|
|
|
Contains the current posititon of the entity.
|
2008-08-14 18:25:44 +00:00
|
|
|
*/
|
2010-05-29 07:25:38 +00:00
|
|
|
vec2 m_Pos;
|
2011-01-29 00:59:50 +00:00
|
|
|
|
2011-04-09 06:41:31 +00:00
|
|
|
// DDRace
|
2020-09-26 19:41:58 +00:00
|
|
|
|
|
|
|
bool GetNearestAirPos(vec2 Pos, vec2 ColPos, vec2 *pOutPos);
|
|
|
|
bool GetNearestAirPosPlayer(vec2 PlayerPos, vec2 *OutPos);
|
2011-04-09 06:41:31 +00:00
|
|
|
|
|
|
|
int m_Number;
|
|
|
|
int m_Layer;
|
2008-08-14 18:25:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|