Quake-2

Quake 2 GPL Source Release
Log | Files | Refs

game.h (8262B)


      1 /*
      2 Copyright (C) 1997-2001 Id Software, Inc.
      3 
      4 This program is free software; you can redistribute it and/or
      5 modify it under the terms of the GNU General Public License
      6 as published by the Free Software Foundation; either version 2
      7 of the License, or (at your option) any later version.
      8 
      9 This program is distributed in the hope that it will be useful,
     10 but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     12 
     13 See the GNU General Public License for more details.
     14 
     15 You should have received a copy of the GNU General Public License
     16 along with this program; if not, write to the Free Software
     17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     18 
     19 */
     20 /*
     21 Copyright (C) 1997-2001 Id Software, Inc.
     22 
     23 This program is free software; you can redistribute it and/or
     24 modify it under the terms of the GNU General Public License
     25 as published by the Free Software Foundation; either version 2
     26 of the License, or (at your option) any later version.
     27 
     28 This program is distributed in the hope that it will be useful,
     29 but WITHOUT ANY WARRANTY; without even the implied warranty of
     30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     31 
     32 See the GNU General Public License for more details.
     33 
     34 You should have received a copy of the GNU General Public License
     35 along with this program; if not, write to the Free Software
     36 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     37 
     38 */
     39 
     40 // game.h -- game dll information visible to server
     41 
     42 #define	GAME_API_VERSION	3
     43 
     44 // edict->svflags
     45 
     46 #define	SVF_NOCLIENT			0x00000001	// don't send entity to clients, even if it has effects
     47 #define	SVF_DEADMONSTER			0x00000002	// treat as CONTENTS_DEADMONSTER for collision
     48 #define	SVF_MONSTER				0x00000004	// treat as CONTENTS_MONSTER for collision
     49 
     50 // edict->solid values
     51 
     52 typedef enum
     53 {
     54 SOLID_NOT,			// no interaction with other objects
     55 SOLID_TRIGGER,		// only touch when inside, after moving
     56 SOLID_BBOX,			// touch on edge
     57 SOLID_BSP			// bsp clip, touch on edge
     58 } solid_t;
     59 
     60 //===============================================================
     61 
     62 // link_t is only used for entity area links now
     63 typedef struct link_s
     64 {
     65 	struct link_s	*prev, *next;
     66 } link_t;
     67 
     68 #define	MAX_ENT_CLUSTERS	16
     69 
     70 
     71 typedef struct edict_s edict_t;
     72 typedef struct gclient_s gclient_t;
     73 
     74 
     75 #ifndef GAME_INCLUDE
     76 
     77 struct gclient_s
     78 {
     79 	player_state_t	ps;		// communicated by server to clients
     80 	int				ping;
     81 	// the game dll can add anything it wants after
     82 	// this point in the structure
     83 };
     84 
     85 
     86 struct edict_s
     87 {
     88 	entity_state_t	s;
     89 	struct gclient_s	*client;
     90 	qboolean	inuse;
     91 	int			linkcount;
     92 
     93 	// FIXME: move these fields to a server private sv_entity_t
     94 	link_t		area;				// linked to a division node or leaf
     95 	
     96 	int			num_clusters;		// if -1, use headnode instead
     97 	int			clusternums[MAX_ENT_CLUSTERS];
     98 	int			headnode;			// unused if num_clusters != -1
     99 	int			areanum, areanum2;
    100 
    101 	//================================
    102 
    103 	int			svflags;			// SVF_NOCLIENT, SVF_DEADMONSTER, SVF_MONSTER, etc
    104 	vec3_t		mins, maxs;
    105 	vec3_t		absmin, absmax, size;
    106 	solid_t		solid;
    107 	int			clipmask;
    108 	edict_t		*owner;
    109 
    110 	// the game dll can add anything it wants after
    111 	// this point in the structure
    112 };
    113 
    114 #endif		// GAME_INCLUDE
    115 
    116 //===============================================================
    117 
    118 //
    119 // functions provided by the main engine
    120 //
    121 typedef struct
    122 {
    123 	// special messages
    124 	void	(*bprintf) (int printlevel, char *fmt, ...);
    125 	void	(*dprintf) (char *fmt, ...);
    126 	void	(*cprintf) (edict_t *ent, int printlevel, char *fmt, ...);
    127 	void	(*centerprintf) (edict_t *ent, char *fmt, ...);
    128 	void	(*sound) (edict_t *ent, int channel, int soundindex, float volume, float attenuation, float timeofs);
    129 	void	(*positioned_sound) (vec3_t origin, edict_t *ent, int channel, int soundinedex, float volume, float attenuation, float timeofs);
    130 
    131 	// config strings hold all the index strings, the lightstyles,
    132 	// and misc data like the sky definition and cdtrack.
    133 	// All of the current configstrings are sent to clients when
    134 	// they connect, and changes are sent to all connected clients.
    135 	void	(*configstring) (int num, char *string);
    136 
    137 	void	(*error) (char *fmt, ...);
    138 
    139 	// the *index functions create configstrings and some internal server state
    140 	int		(*modelindex) (char *name);
    141 	int		(*soundindex) (char *name);
    142 	int		(*imageindex) (char *name);
    143 
    144 	void	(*setmodel) (edict_t *ent, char *name);
    145 
    146 	// collision detection
    147 	trace_t	(*trace) (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, edict_t *passent, int contentmask);
    148 	int		(*pointcontents) (vec3_t point);
    149 	qboolean	(*inPVS) (vec3_t p1, vec3_t p2);
    150 	qboolean	(*inPHS) (vec3_t p1, vec3_t p2);
    151 	void		(*SetAreaPortalState) (int portalnum, qboolean open);
    152 	qboolean	(*AreasConnected) (int area1, int area2);
    153 
    154 	// an entity will never be sent to a client or used for collision
    155 	// if it is not passed to linkentity.  If the size, position, or
    156 	// solidity changes, it must be relinked.
    157 	void	(*linkentity) (edict_t *ent);
    158 	void	(*unlinkentity) (edict_t *ent);		// call before removing an interactive edict
    159 	int		(*BoxEdicts) (vec3_t mins, vec3_t maxs, edict_t **list,	int maxcount, int areatype);
    160 	void	(*Pmove) (pmove_t *pmove);		// player movement code common with client prediction
    161 
    162 	// network messaging
    163 	void	(*multicast) (vec3_t origin, multicast_t to);
    164 	void	(*unicast) (edict_t *ent, qboolean reliable);
    165 	void	(*WriteChar) (int c);
    166 	void	(*WriteByte) (int c);
    167 	void	(*WriteShort) (int c);
    168 	void	(*WriteLong) (int c);
    169 	void	(*WriteFloat) (float f);
    170 	void	(*WriteString) (char *s);
    171 	void	(*WritePosition) (vec3_t pos);	// some fractional bits
    172 	void	(*WriteDir) (vec3_t pos);		// single byte encoded, very coarse
    173 	void	(*WriteAngle) (float f);
    174 
    175 	// managed memory allocation
    176 	void	*(*TagMalloc) (int size, int tag);
    177 	void	(*TagFree) (void *block);
    178 	void	(*FreeTags) (int tag);
    179 
    180 	// console variable interaction
    181 	cvar_t	*(*cvar) (char *var_name, char *value, int flags);
    182 	cvar_t	*(*cvar_set) (char *var_name, char *value);
    183 	cvar_t	*(*cvar_forceset) (char *var_name, char *value);
    184 
    185 	// ClientCommand and ServerCommand parameter access
    186 	int		(*argc) (void);
    187 	char	*(*argv) (int n);
    188 	char	*(*args) (void);	// concatenation of all argv >= 1
    189 
    190 	// add commands to the server console as if they were typed in
    191 	// for map changing, etc
    192 	void	(*AddCommandString) (char *text);
    193 
    194 	void	(*DebugGraph) (float value, int color);
    195 } game_import_t;
    196 
    197 //
    198 // functions exported by the game subsystem
    199 //
    200 typedef struct
    201 {
    202 	int			apiversion;
    203 
    204 	// the init function will only be called when a game starts,
    205 	// not each time a level is loaded.  Persistant data for clients
    206 	// and the server can be allocated in init
    207 	void		(*Init) (void);
    208 	void		(*Shutdown) (void);
    209 
    210 	// each new level entered will cause a call to SpawnEntities
    211 	void		(*SpawnEntities) (char *mapname, char *entstring, char *spawnpoint);
    212 
    213 	// Read/Write Game is for storing persistant cross level information
    214 	// about the world state and the clients.
    215 	// WriteGame is called every time a level is exited.
    216 	// ReadGame is called on a loadgame.
    217 	void		(*WriteGame) (char *filename, qboolean autosave);
    218 	void		(*ReadGame) (char *filename);
    219 
    220 	// ReadLevel is called after the default map information has been
    221 	// loaded with SpawnEntities
    222 	void		(*WriteLevel) (char *filename);
    223 	void		(*ReadLevel) (char *filename);
    224 
    225 	qboolean	(*ClientConnect) (edict_t *ent, char *userinfo);
    226 	void		(*ClientBegin) (edict_t *ent);
    227 	void		(*ClientUserinfoChanged) (edict_t *ent, char *userinfo);
    228 	void		(*ClientDisconnect) (edict_t *ent);
    229 	void		(*ClientCommand) (edict_t *ent);
    230 	void		(*ClientThink) (edict_t *ent, usercmd_t *cmd);
    231 
    232 	void		(*RunFrame) (void);
    233 
    234 	// ServerCommand will be called when an "sv <command>" command is issued on the
    235 	// server console.
    236 	// The game can issue gi.argc() / gi.argv() commands to get the rest
    237 	// of the parameters
    238 	void		(*ServerCommand) (void);
    239 
    240 	//
    241 	// global variables shared between game and server
    242 	//
    243 
    244 	// The edict array is allocated in the game dll so it
    245 	// can vary in size from one game to another.
    246 	// 
    247 	// The size will be fixed when ge->Init() is called
    248 	struct edict_s	*edicts;
    249 	int			edict_size;
    250 	int			num_edicts;		// current number, <= max_edicts
    251 	int			max_edicts;
    252 } game_export_t;
    253 
    254 game_export_t *GetGameApi (game_import_t *import);