1 /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2 /* If you are missing that file, acquire a complete release at teeworlds.com. */
3 #ifndef GAME_SERVER_ENTITY_H
4 #define GAME_SERVER_ENTITY_H
7 #include <base/vmath.h>
8 #include <game/server/gameworld.h>
10 #define MACRO_ALLOC_HEAP() \
12 void *operator new(size_t Size) \
14 void *p = mem_alloc(Size, 1); \
15 /*dbg_msg("", "++ %p %d", p, size);*/ \
19 void operator delete(void *pPtr) \
21 /*dbg_msg("", "-- %p", p);*/ \
26 #define MACRO_ALLOC_POOL_ID() \
28 void *operator new(size_t Size, int id); \
29 void operator delete(void *p); \
32 #define MACRO_ALLOC_POOL_ID_IMPL(POOLTYPE, PoolSize) \
33 static char ms_PoolData##POOLTYPE[PoolSize][sizeof(POOLTYPE)] = {{0}}; \
34 static int ms_PoolUsed##POOLTYPE[PoolSize] = {0}; \
35 void *POOLTYPE::operator new(size_t Size, int id) \
37 dbg_assert(sizeof(POOLTYPE) == Size, "size error"); \
38 dbg_assert(!ms_PoolUsed##POOLTYPE[id], "already used"); \
39 /*dbg_msg("pool", "++ %s %d", #POOLTYPE, id);*/ \
40 ms_PoolUsed##POOLTYPE[id] = 1; \
41 mem_zero(ms_PoolData##POOLTYPE[id], Size); \
42 return ms_PoolData##POOLTYPE[id]; \
44 void POOLTYPE::operator delete(void *p) \
46 int id = (POOLTYPE*)p - (POOLTYPE*)ms_PoolData##POOLTYPE; \
47 dbg_assert(ms_PoolUsed##POOLTYPE[id], "not used"); \
48 /*dbg_msg("pool", "-- %s %d", #POOLTYPE, id);*/ \
49 ms_PoolUsed##POOLTYPE[id] = 0; \
50 mem_zero(ms_PoolData##POOLTYPE[id], sizeof(POOLTYPE)); \
61 friend class CGameWorld
; // entity list handling
62 CEntity
*m_pPrevTypeEntity
;
63 CEntity
*m_pNextTypeEntity
;
65 class CGameWorld
*m_pGameWorld
;
67 bool m_MarkedForDestroy
;
71 CEntity(CGameWorld
*pGameWorld
, int Objtype
);
74 class CGameWorld
*GameWorld() { return m_pGameWorld
; }
75 class CGameContext
*GameServer() { return GameWorld()->GameServer(); }
76 class IServer
*Server() { return GameWorld()->Server(); }
79 CEntity
*TypeNext() { return m_pNextTypeEntity
; }
80 CEntity
*TypePrev() { return m_pPrevTypeEntity
; }
86 virtual void Destroy() { delete this; }
90 Called when the game resets the map. Puts the entity
91 back to it's starting state or perhaps destroys it.
93 virtual void Reset() {}
97 Called progress the entity to the next tick. Updates
98 and moves the entity to it's new state and position.
100 virtual void Tick() {}
103 Function: tick_defered
104 Called after all entities tick() function has been called.
106 virtual void TickDefered() {}
110 Called when a new snapshot is being generated for a specific
114 snapping_client - ID of the client which snapshot is
115 being generated. Could be -1 to create a complete
116 snapshot of everything in the game for demo
119 virtual void Snap(int SnappingClient
) {}
122 Function: networkclipped(int snapping_client)
123 Performs a series of test to see if a client can see the
127 snapping_client - ID of the client which snapshot is
128 being generated. Could be -1 to create a complete
129 snapshot of everything in the game for demo
133 Non-zero if the entity doesn't have to be in the snapshot.
135 int NetworkClipped(int SnappingClient
);
136 int NetworkClipped(int SnappingClient
, vec2 CheckPos
);
138 bool GameLayerClipped(vec2 CheckPos
);
141 Variable: proximity_radius
142 Contains the physical size of the entity.
144 float m_ProximityRadius
;
148 Contains the current posititon of the entity.