ddnet/src/game/server/entity.h

154 lines
3.6 KiB
C
Raw Normal View History

#ifndef GAME_SERVER_ENTITY_H
#define GAME_SERVER_ENTITY_H
#include <new>
2010-05-29 07:25:38 +00:00
#include <base/vmath.h>
#include <game/server/gameworld.h>
#define MACRO_ALLOC_HEAP() \
public: \
2010-05-29 07:25:38 +00:00
void *operator new(size_t Size) \
{ \
2010-05-29 07:25:38 +00:00
void *p = mem_alloc(Size, 1); \
/*dbg_msg("", "++ %p %d", p, size);*/ \
2010-05-29 07:25:38 +00:00
mem_zero(p, Size); \
return p; \
} \
2010-05-29 07:25:38 +00:00
void operator delete(void *pPtr) \
{ \
/*dbg_msg("", "-- %p", p);*/ \
2010-05-29 07:25:38 +00:00
mem_free(pPtr); \
} \
private:
#define MACRO_ALLOC_POOL_ID() \
public: \
2010-05-29 07:25:38 +00:00
void *operator new(size_t Size, int id); \
void operator delete(void *p); \
private:
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) \
{ \
2010-05-29 07:25:38 +00:00
dbg_assert(sizeof(POOLTYPE) == Size, "size error"); \
dbg_assert(!ms_PoolUsed##POOLTYPE[id], "already used"); \
/*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]; \
} \
void POOLTYPE::operator delete(void *p) \
{ \
2010-05-29 07:25:38 +00:00
int id = (POOLTYPE*)p - (POOLTYPE*)ms_PoolData##POOLTYPE; \
dbg_assert(ms_PoolUsed##POOLTYPE[id], "not used"); \
/*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)); \
}
/*
Class: Entity
Basic entity class.
*/
2010-05-29 07:25:38 +00:00
class CEntity
{
MACRO_ALLOC_HEAP()
private:
2010-05-29 07:25:38 +00:00
friend class CGameWorld; // thy these?
CEntity *m_pPrevEntity;
CEntity *m_pNextEntity;
2010-05-29 07:25:38 +00:00
CEntity *m_pPrevTypeEntity;
CEntity *m_pNextTypeEntity;
class CGameWorld *m_pGameWorld;
protected:
2010-05-29 07:25:38 +00:00
bool m_MarkedForDestroy;
int m_Id;
int m_Objtype;
public:
2010-05-29 07:25:38 +00:00
CEntity(CGameWorld *pGameWorld, int Objtype);
virtual ~CEntity();
class CGameWorld *GameWorld() { return m_pGameWorld; }
class CGameContext *GameServer() { return GameWorld()->GameServer(); }
class IServer *Server() { return GameWorld()->Server(); }
2010-05-29 07:25:38 +00:00
CEntity *TypeNext() { return m_pNextTypeEntity; }
CEntity *TypePrev() { return m_pPrevTypeEntity; }
/*
Function: destroy
Destorys the entity.
*/
2010-05-29 07:25:38 +00:00
virtual void Destroy() { delete this; }
/*
Function: reset
Called when the game resets the map. Puts the entity
back to it's starting state or perhaps destroys it.
*/
2010-05-29 07:25:38 +00:00
virtual void Reset() {}
/*
Function: tick
Called progress the entity to the next tick. Updates
and moves the entity to it's new state and position.
*/
2010-05-29 07:25:38 +00:00
virtual void Tick() {}
/*
Function: tick_defered
Called after all entities tick() function has been called.
*/
2010-05-29 07:25:38 +00:00
virtual void TickDefered() {}
/*
Function: snap
Called when a new snapshot is being generated for a specific
client.
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) {}
/*
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.
Returns:
Non-zero if the entity doesn't have to be in the snapshot.
*/
2010-05-29 07:25:38 +00:00
int NetworkClipped(int SnappingClient);
int NetworkClipped(int SnappingClient, vec2 CheckPos);
/*
Variable: proximity_radius
Contains the physical size of the entity.
*/
2010-05-29 07:25:38 +00:00
float m_ProximityRadius;
/*
Variable: pos
Contains the current posititon of the entity.
*/
2010-05-29 07:25:38 +00:00
vec2 m_Pos;
};
#endif