UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sv_game.cpp File Reference

Interface to the game library. More...

#include "server.h"
#include "sv_log.h"
#include "../common/grid.h"
#include "../common/routing.h"
#include "../ports/system.h"
#include "../shared/thread.h"
#include "../shared/scopedmutex.h"

Go to the source code of this file.

Data Structures

struct  eventNames_t
 

Macros

#define M(x)   { #x }
 

Functions

static void SV_dprintf (const char *fmt,...)
 Debug print to server console. More...
 
static void SV_PlayerPrintf (const SrvPlayer *player, int level, const char *fmt, va_list ap)
 Print to a single client. More...
 
static float SV_GetVisibility (const pos3_t position)
 Glue function to get the visibility from a given position. More...
 
static void SV_error (const char *fmt,...)
 Abort the server with a game error. More...
 
static unsigned int SV_FindIndex (const char *name, int start, int max, bool create)
 Search the index in the config strings relative to a given start. More...
 
static unsigned int SV_ModelIndex (const char *name)
 
static void SV_SetModel (edict_t *ent, const char *name)
 
static void SV_Configstring (int index, const char *fmt,...)
 
static void SV_WriteChar (char c)
 
static void SV_WriteByte (byte c)
 
static void SV_WriteShort (int c)
 
static void SV_WriteLong (int c)
 
static void SV_WriteString (const char *s)
 
static void SV_WritePos (const vec3_t pos)
 
static void SV_WriteGPos (const pos3_t pos)
 
static void SV_WriteDir (const vec3_t dir)
 
static void SV_WriteAngle (float f)
 
static void SV_WriteFormat (const char *format,...)
 
static int SV_ReadChar (void)
 
static int SV_ReadByte (void)
 
static int SV_ReadShort (void)
 
static int SV_ReadLong (void)
 
static int SV_ReadString (char *str, size_t length)
 
static void SV_ReadPos (vec3_t pos)
 
static void SV_ReadGPos (pos3_t pos)
 
static void SV_ReadDir (vec3_t vector)
 
static float SV_ReadAngle (void)
 
static void SV_ReadData (void *buffer, int size)
 
static void SV_ReadFormat (const char *format,...)
 
static void SV_AbortEvents (void)
 
static void SV_SendQueuedEvents (void)
 
static void SV_EndEvents (void)
 
 CASSERT (lengthof(eventNames)==EV_NUM_EVENTS)
 
static void SV_AddEvent (unsigned int mask, int eType, int entnum)
 
static void SV_QueueEvent (unsigned int mask, int eType, int entnum)
 
static void SV_QueueWriteByte (byte c)
 
static void SV_QueueWriteString (const char *s)
 
static void SV_QueueWritePos (const vec3_t pos)
 
static void SV_QueueWriteShort (int c)
 
static int SV_GetEvent (void)
 
static edict_tSV_GetEventEdict (void)
 
static voidSV_TagAlloc (int size, int tagNum, const char *file, int line)
 Makes sure the game DLL does not use client, or signed tags. More...
 
static void SV_MemFree (void *ptr, const char *file, int line)
 
static void SV_FreeTags (int tagNum, const char *file, int line)
 Makes sure the game DLL does not use client, or signed tags. More...
 
static bool SV_TestLine (const vec3_t start, const vec3_t stop, const int levelmask)
 
static bool SV_TestLineWithEnt (const vec3_t start, const vec3_t stop, const int levelmask, const char **entlist)
 
static pos_t SV_GridFall (const int actorSize, const pos3_t pos)
 
static void SV_RecalcRouting (const char *name, const GridBox &box, const char **list)
 
static void SV_GridPosToVec (const int actorSize, const pos3_t pos, vec3_t vec)
 
static bool SV_GridIsOnMap (const vec3_t vec)
 
static void SV_GridCalcPathing (actorSizeEnum_t actorSize, pathing_t *path, const pos3_t from, int distance, forbiddenList_t *forbiddenList)
 
static bool SV_GridFindPath (actorSizeEnum_t actorSize, pathing_t *path, const pos3_t from, const pos3_t targetPos, byte crouchingState, int maxTUs, forbiddenList_t *forbiddenList)
 
static bool SV_CanActorStandHere (const int actorSize, const pos3_t pos)
 
static void SV_SetInlineModelOrientation (const char *name, const vec3_t origin, const vec3_t angles)
 
static void SV_GetInlineModelAABB (const char *name, AABB &aabb)
 
static void SV_UnloadGame (void)
 
static bool SV_LoadGame (const char *path)
 
static game_export_tSV_GetGameAPI (game_import_t *parms)
 Loads the game shared library and calls the api init function. More...
 
void SV_ShutdownGameProgs (void)
 Called when either the entire server is being killed, or it is changing to a different game directory. More...
 
int SV_RunGameFrameThread (void *data)
 Thread for the game frame function. More...
 
void SV_RunGameFrame (void)
 Calls the G_RunFrame function from game api let everything in the world think and move. More...
 
void SV_InitGameProgs (void)
 Init the game subsystem for a new map. More...
 

Variables

static const eventNames_t eventNames []
 
static char const *const gameSysPoolName = "Server: Game system"
 

Detailed Description

Interface to the game library.

Definition in file sv_game.cpp.

Macro Definition Documentation

#define M (   x)    { #x }

Definition at line 356 of file sv_game.cpp.

Function Documentation

CASSERT ( lengthof(eventNames = =EV_NUM_EVENTS)
static void SV_AbortEvents ( void  )
static
See also
gi.AbortEvents

Definition at line 308 of file sv_game.cpp.

References pending_event_s::buf, pending_event_s::pending, serverInstanceGame_s::pendingEvent, and sv.

Referenced by SV_InitGameProgs().

static void SV_AddEvent ( unsigned int  mask,
int  eType,
int  entnum 
)
static
See also
gi.AddEvent
Parameters
[in]maskThe player bitmask to send the events to. Use PM_ALL to send to every connected player.
[in]eTypeThe event type
[in]entnumThe entity number

Definition at line 427 of file sv_game.cpp.

References pending_event_s::buf, Com_DPrintf(), Com_Error(), Com_UnsignedIntToBinary(), DEBUG_EVENTSYS, pending_event_s::entnum, ERR_DROP, EV_NUM_EVENTS, EVENT_INSTANTLY, eventNames_t::name, NET_WriteByte(), NET_WriteShort(), pending_event_s::pending, serverInstanceGame_s::pendingEvent, pending_event_s::playerMask, sv, SV_EndEvents(), SV_SendQueuedEvents(), svc_event, and pending_event_s::type.

Referenced by SV_InitGameProgs().

static bool SV_CanActorStandHere ( const int  actorSize,
const pos3_t  pos 
)
static

Definition at line 608 of file sv_game.cpp.

References serverInstanceGame_s::mapData, mapData_s::routing, RT_CanActorStandHere(), and sv.

Referenced by SV_InitGameProgs().

static void SV_dprintf ( const char *  fmt,
  ... 
)
static

Debug print to server console.

Definition at line 39 of file sv_game.cpp.

References SV_LogAdd().

Referenced by SV_InitGameProgs().

static void SV_error ( const char *  fmt,
  ... 
)
static

Abort the server with a game error.

Note
The error message should not have a newline - it's added inside of this function

Definition at line 79 of file sv_game.cpp.

References Com_Error(), ERR_DROP, and Q_vsnprintf().

Referenced by SV_Configstring(), SV_FindIndex(), SV_InitGameProgs(), and SV_SetModel().

static unsigned int SV_FindIndex ( const char *  name,
int  start,
int  max,
bool  create 
)
static

Search the index in the config strings relative to a given start.

Parameters
nameThe value of the config string to search the index for
startThe relative start point for the search
maxThe max. searched entries in the config string before giving up
createif true the value will get written into the config strings (appended)
Returns
0 if not found

Definition at line 99 of file sv_game.cpp.

References Com_ServerState(), i, NET_WriteByte(), NET_WriteShort(), NET_WriteString(), Q_streq, ss_loading, SV_error(), SV_GetConfigString(), SV_Multicast(), SV_SetConfigString, and svc_configstring.

Referenced by SV_ModelIndex().

static void SV_FreeTags ( int  tagNum,
const char *  file,
int  line 
)
static

Makes sure the game DLL does not use client, or signed tags.

Definition at line 558 of file sv_game.cpp.

References _Mem_FreeTag(), serverInstanceGame_s::gameSysPool, and sv.

Referenced by SV_InitGameProgs().

static int SV_GetEvent ( void  )
static
Returns
The current active event or -1 if no event is active at the moment

Definition at line 517 of file sv_game.cpp.

References pending_event_s::pending, serverInstanceGame_s::pendingEvent, sv, and pending_event_s::type.

Referenced by SV_InitGameProgs().

static edict_t* SV_GetEventEdict ( void  )
static
static game_export_t* SV_GetGameAPI ( game_import_t parms)
static

Loads the game shared library and calls the api init function.

Definition at line 659 of file sv_game.cpp.

References Com_Error(), Com_Printf(), ERR_FATAL, FS_NextPath(), serverInstanceStatic_s::gameLibrary, GetGameAPI(), PKGLIBDIR, SV_LoadGame(), SV_UnloadGame(), and svs.

Referenced by SV_InitGameProgs().

static void SV_GetInlineModelAABB ( const char *  name,
AABB aabb 
)
static

Definition at line 618 of file sv_game.cpp.

References CM_GetInlineModelAABB(), serverInstanceGame_s::mapTiles, and sv.

Referenced by SV_InitGameProgs().

static float SV_GetVisibility ( const pos3_t  position)
static

Glue function to get the visibility from a given position.

Definition at line 69 of file sv_game.cpp.

References CM_GetVisibility(), serverInstanceGame_s::mapTiles, and sv.

Referenced by SV_InitGameProgs().

static void SV_GridCalcPathing ( actorSizeEnum_t  actorSize,
pathing_t path,
const pos3_t  from,
int  distance,
forbiddenList_t forbiddenList 
)
static

Definition at line 598 of file sv_game.cpp.

References Grid_CalcPathing(), serverInstanceGame_s::mapData, mapData_s::routing, and sv.

Referenced by SV_InitGameProgs().

static pos_t SV_GridFall ( const int  actorSize,
const pos3_t  pos 
)
static

Definition at line 578 of file sv_game.cpp.

References Grid_Fall(), serverInstanceGame_s::mapData, mapData_s::routing, and sv.

Referenced by SV_InitGameProgs().

static bool SV_GridFindPath ( actorSizeEnum_t  actorSize,
pathing_t path,
const pos3_t  from,
const pos3_t  targetPos,
byte  crouchingState,
int  maxTUs,
forbiddenList_t forbiddenList 
)
static

Definition at line 603 of file sv_game.cpp.

References Grid_FindPath(), serverInstanceGame_s::mapData, mapData_s::routing, and sv.

Referenced by SV_InitGameProgs().

static bool SV_GridIsOnMap ( const vec3_t  vec)
static

Definition at line 593 of file sv_game.cpp.

References AABB::contains(), mapData_s::mapBox, serverInstanceGame_s::mapData, and sv.

Referenced by SV_InitGameProgs().

static void SV_GridPosToVec ( const int  actorSize,
const pos3_t  pos,
vec3_t  vec 
)
static

Definition at line 588 of file sv_game.cpp.

References Grid_PosToVec(), serverInstanceGame_s::mapData, mapData_s::routing, and sv.

Referenced by SV_InitGameProgs().

void SV_InitGameProgs ( void  )

Init the game subsystem for a new map.

See also
SV_ShutdownGameProgs

Definition at line 769 of file sv_game.cpp.

References game_export_s::apiversion, Cbuf_AddText(), Cmd_Argc(), Cmd_Args(), Cmd_Argv(), Com_CreateThread(), Com_Error(), Com_GetCharacterValues(), Com_GetConstInt(), Com_GetConstIntFromNamespace(), Com_GetConstVariable(), Com_GrenadeTarget(), Com_Printf(), Com_RegisterConstInt(), Com_UnregisterConstVariable(), csi, Cvar_Get(), Cvar_GetString(), Cvar_Set(), ERR_DROP, FS_FreeFile(), FS_Gamedir(), FS_LoadFile(), GAME_API_VERSION, serverInstanceStatic_s::gameFrameCond, serverInstanceGame_s::gameSysPool, serverInstanceStatic_s::gameThread, serverInstanceStatic_s::ge, Grid_GetTUsForDirection(), Grid_MoveLength(), Grid_MoveNext(), Grid_MoveStore(), Grid_ShouldUseAutostand(), cvar_s::integer, Mem_CreatePool, sv, SV_AbortEvents(), SV_AddEvent(), SV_BroadcastPrintf(), SV_CanActorStandHere(), SV_Configstring(), SV_dprintf(), SV_EndEvents(), SV_error(), SV_FreeTags(), SV_GetBounceFraction(), SV_GetEvent(), SV_GetEventEdict(), SV_GetFootstepSound(), SV_GetGameAPI(), SV_GetInlineModelAABB(), SV_GetVisibility(), SV_GridCalcPathing(), SV_GridFall(), SV_GridFindPath(), SV_GridIsOnMap(), SV_GridPosToVec(), SV_LinkEdict(), SV_LoadModelAABB(), SV_MemFree(), SV_ModelIndex(), SV_PlayerPrintf(), SV_PointContents(), SV_QueueEvent(), SV_QueueWriteByte(), SV_QueueWritePos(), SV_QueueWriteShort(), SV_QueueWriteString(), SV_ReadAngle(), SV_ReadByte(), SV_ReadChar(), SV_ReadData(), SV_ReadDir(), SV_ReadFormat(), SV_ReadGPos(), SV_ReadLong(), SV_ReadPos(), SV_ReadShort(), SV_ReadString(), SV_RecalcRouting(), SV_RunGameFrameThread(), SV_SetInlineModelOrientation(), SV_SetModel(), SV_TagAlloc(), SV_TestLine(), SV_TestLineWithEnt(), sv_threads, SV_Trace(), SV_UnlinkEdict(), SV_WriteAngle(), SV_WriteByte(), SV_WriteChar(), SV_WriteDir(), SV_WriteFormat(), SV_WriteGPos(), SV_WriteLong(), SV_WritePos(), SV_WriteShort(), SV_WriteString(), svs, Sys_Fopen(), and Sys_Milliseconds().

Referenced by SV_InitGame(), and TEST_F().

static bool SV_LoadGame ( const char *  path)
static
static void SV_MemFree ( void ptr,
const char *  file,
int  line 
)
static

Definition at line 550 of file sv_game.cpp.

References _Mem_Free().

Referenced by SV_InitGameProgs().

static unsigned int SV_ModelIndex ( const char *  name)
static

Definition at line 131 of file sv_game.cpp.

References CS_MODELS, MAX_MODELS, and SV_FindIndex().

Referenced by SV_InitGameProgs(), and SV_SetModel().

static void SV_PlayerPrintf ( const SrvPlayer player,
int  level,
const char *  fmt,
va_list  ap 
)
static

Print to a single client.

See also
SV_BroadcastPrintf

Definition at line 52 of file sv_game.cpp.

References cl, SrvPlayer::getNum(), PRINT_NONE, Q_vsnprintf(), SV_ClientPrintf(), SV_GetClient(), and SV_LogAdd().

Referenced by SV_InitGameProgs().

static void SV_QueueEvent ( unsigned int  mask,
int  eType,
int  entnum 
)
static
See also
gi.QueueEvent
Parameters
[in]maskThe player bitmask to send the events to. Use PM_ALL to send to every connected player.
[in]eTypeThe event type
[in]entnumThe entity number

Definition at line 465 of file sv_game.cpp.

References pending_event_s::buf, Com_DPrintf(), Com_Error(), Com_UnsignedIntToBinary(), DEBUG_EVENTSYS, pending_event_s::entnum, ERR_DROP, EV_NUM_EVENTS, EVENT_INSTANTLY, serverInstanceGame_s::eventQueue, serverInstanceGame_s::eventQueuePos, lengthof, eventNames_t::name, NET_WriteByte(), NET_WriteShort(), pending_event_s::pending, pending_event_s::playerMask, sv, svc_event, and pending_event_s::type.

Referenced by SV_InitGameProgs().

static void SV_QueueWriteByte ( byte  c)
static
static void SV_QueueWritePos ( const vec3_t  pos)
static
static void SV_QueueWriteShort ( int  c)
static
static void SV_QueueWriteString ( const char *  s)
static
static float SV_ReadAngle ( void  )
static

Definition at line 279 of file sv_game.cpp.

References serverInstanceGame_s::messageBuffer, NET_ReadAngle(), and sv.

Referenced by SV_InitGameProgs().

static int SV_ReadByte ( void  )
static

Definition at line 244 of file sv_game.cpp.

References serverInstanceGame_s::messageBuffer, NET_ReadByte(), and sv.

Referenced by SV_InitGameProgs().

static int SV_ReadChar ( void  )
static

Definition at line 239 of file sv_game.cpp.

References serverInstanceGame_s::messageBuffer, NET_ReadChar(), and sv.

Referenced by SV_InitGameProgs().

static void SV_ReadData ( void buffer,
int  size 
)
static

Definition at line 284 of file sv_game.cpp.

References serverInstanceGame_s::messageBuffer, NET_ReadData(), and sv.

Referenced by SV_InitGameProgs().

static void SV_ReadDir ( vec3_t  vector)
static

Definition at line 274 of file sv_game.cpp.

References serverInstanceGame_s::messageBuffer, NET_ReadDir(), and sv.

Referenced by SV_InitGameProgs().

static void SV_ReadFormat ( const char *  format,
  ... 
)
static
See also
NET_vReadFormat

Definition at line 292 of file sv_game.cpp.

References serverInstanceGame_s::messageBuffer, NET_vReadFormat(), and sv.

Referenced by SV_InitGameProgs().

static void SV_ReadGPos ( pos3_t  pos)
static

Definition at line 269 of file sv_game.cpp.

References serverInstanceGame_s::messageBuffer, NET_ReadGPos(), and sv.

Referenced by SV_InitGameProgs().

static int SV_ReadLong ( void  )
static

Definition at line 254 of file sv_game.cpp.

References serverInstanceGame_s::messageBuffer, NET_ReadLong(), and sv.

Referenced by SV_InitGameProgs().

static void SV_ReadPos ( vec3_t  pos)
static

Definition at line 264 of file sv_game.cpp.

References serverInstanceGame_s::messageBuffer, NET_ReadPos(), and sv.

Referenced by SV_InitGameProgs().

static int SV_ReadShort ( void  )
static

Definition at line 249 of file sv_game.cpp.

References serverInstanceGame_s::messageBuffer, NET_ReadShort(), and sv.

Referenced by SV_InitGameProgs().

static int SV_ReadString ( char *  str,
size_t  length 
)
static

Definition at line 259 of file sv_game.cpp.

References serverInstanceGame_s::messageBuffer, NET_ReadString(), and sv.

Referenced by SV_InitGameProgs().

static void SV_RecalcRouting ( const char *  name,
const GridBox box,
const char **  list 
)
static
void SV_RunGameFrame ( void  )

Calls the G_RunFrame function from game api let everything in the world think and move.

See also
G_RunFrame
SV_Frame

Definition at line 758 of file sv_game.cpp.

References serverInstanceGame_s::endgame, serverInstanceStatic_s::ge, ss_game_shutdown, serverInstanceGame_s::state, sv, and svs.

Referenced by SV_Frame(), and SV_RunGameFrameThread().

int SV_RunGameFrameThread ( void data)

Thread for the game frame function.

See also
SV_RunGameFrame
SV_Frame

Definition at line 741 of file sv_game.cpp.

References serverInstanceGame_s::endgame, serverInstanceStatic_s::gameFrameCond, serverInstanceStatic_s::serverMutex, sv, SV_RunGameFrame(), and svs.

Referenced by SV_InitGameProgs().

static void SV_SetInlineModelOrientation ( const char *  name,
const vec3_t  origin,
const vec3_t  angles 
)
static

Definition at line 613 of file sv_game.cpp.

References CM_SetInlineModelOrientation(), serverInstanceGame_s::mapTiles, and sv.

Referenced by SV_InitGameProgs().

static void SV_SetModel ( edict_t ent,
const char *  name 
)
static
static void* SV_TagAlloc ( int  size,
int  tagNum,
const char *  file,
int  line 
)
static

Makes sure the game DLL does not use client, or signed tags.

Definition at line 542 of file sv_game.cpp.

References _Mem_Alloc(), serverInstanceGame_s::gameSysPool, and sv.

Referenced by SV_InitGameProgs().

static bool SV_TestLine ( const vec3_t  start,
const vec3_t  stop,
const int  levelmask 
)
static

Definition at line 566 of file sv_game.cpp.

References serverInstanceGame_s::mapTiles, sv, and TR_TestLine().

Referenced by SV_InitGameProgs().

static bool SV_TestLineWithEnt ( const vec3_t  start,
const vec3_t  stop,
const int  levelmask,
const char **  entlist 
)
static

Definition at line 571 of file sv_game.cpp.

References CM_EntTestLine(), serverInstanceGame_s::mapTiles, and sv.

Referenced by SV_InitGameProgs().

static void SV_UnloadGame ( void  )
static

Definition at line 623 of file sv_game.cpp.

References Com_Printf(), serverInstanceStatic_s::gameLibrary, and svs.

Referenced by SV_GetGameAPI(), and SV_ShutdownGameProgs().

static void SV_WriteAngle ( float  f)
static

Definition at line 226 of file sv_game.cpp.

References pending_event_s::buf, NET_WriteAngle(), serverInstanceGame_s::pendingEvent, and sv.

Referenced by SV_InitGameProgs().

static void SV_WriteByte ( byte  c)
static

Definition at line 191 of file sv_game.cpp.

References pending_event_s::buf, NET_WriteByte(), serverInstanceGame_s::pendingEvent, and sv.

Referenced by SV_InitGameProgs().

static void SV_WriteChar ( char  c)
static

Definition at line 186 of file sv_game.cpp.

References pending_event_s::buf, NET_WriteChar(), serverInstanceGame_s::pendingEvent, and sv.

Referenced by SV_InitGameProgs().

static void SV_WriteDir ( const vec3_t  dir)
static

Definition at line 221 of file sv_game.cpp.

References pending_event_s::buf, NET_WriteDir(), serverInstanceGame_s::pendingEvent, and sv.

Referenced by SV_InitGameProgs().

static void SV_WriteFormat ( const char *  format,
  ... 
)
static
static void SV_WriteGPos ( const pos3_t  pos)
static

Definition at line 216 of file sv_game.cpp.

References pending_event_s::buf, NET_WriteGPos(), serverInstanceGame_s::pendingEvent, and sv.

Referenced by SV_InitGameProgs().

static void SV_WriteLong ( int  c)
static

Definition at line 201 of file sv_game.cpp.

References pending_event_s::buf, NET_WriteLong(), serverInstanceGame_s::pendingEvent, and sv.

Referenced by SV_InitGameProgs().

static void SV_WritePos ( const vec3_t  pos)
static

Definition at line 211 of file sv_game.cpp.

References pending_event_s::buf, NET_WritePos(), serverInstanceGame_s::pendingEvent, and sv.

Referenced by SV_InitGameProgs().

static void SV_WriteShort ( int  c)
static

Definition at line 196 of file sv_game.cpp.

References pending_event_s::buf, NET_WriteShort(), serverInstanceGame_s::pendingEvent, and sv.

Referenced by SV_InitGameProgs().

static void SV_WriteString ( const char *  s)
static

Definition at line 206 of file sv_game.cpp.

References pending_event_s::buf, NET_WriteString(), serverInstanceGame_s::pendingEvent, and sv.

Referenced by SV_InitGameProgs().

Variable Documentation

const eventNames_t eventNames[]
static

Definition at line 357 of file sv_game.cpp.

char const* const gameSysPoolName = "Server: Game system"
static

Definition at line 696 of file sv_game.cpp.