icculus quake2 doxygen  1.0 dev
game.h
Go to the documentation of this file.
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 // game.h -- game dll information visible to server
22 
23 #define GAME_API_VERSION 3
24 
25 // edict->svflags
26 
27 #define SVF_NOCLIENT 0x00000001 // don't send entity to clients, even if it has effects
28 #define SVF_DEADMONSTER 0x00000002 // treat as CONTENTS_DEADMONSTER for collision
29 #define SVF_MONSTER 0x00000004 // treat as CONTENTS_MONSTER for collision
30 
31 // edict->solid values
32 
33 typedef enum
34 {
35 SOLID_NOT, // no interaction with other objects
36 SOLID_TRIGGER, // only touch when inside, after moving
37 SOLID_BBOX, // touch on edge
38 SOLID_BSP // bsp clip, touch on edge
39 } solid_t;
40 
41 //===============================================================
42 
43 // link_t is only used for entity area links now
44 typedef struct link_s
45 {
46  struct link_s *prev, *next;
47 } link_t;
48 
49 #define MAX_ENT_CLUSTERS 16
50 
51 
52 typedef struct edict_s edict_t;
53 typedef struct gclient_s gclient_t;
54 
55 
56 #ifndef GAME_INCLUDE
57 
58 struct gclient_s
59 {
60  player_state_t ps; // communicated by server to clients
61  int ping;
62  // the game dll can add anything it wants after
63  // this point in the structure
64 };
65 
66 
67 struct edict_s
68 {
70  struct gclient_s *client;
72  int linkcount;
73 
74  // FIXME: move these fields to a server private sv_entity_t
75  link_t area; // linked to a division node or leaf
76 
77  int num_clusters; // if -1, use headnode instead
79  int headnode; // unused if num_clusters != -1
80  int areanum, areanum2;
81 
82  //================================
83 
84  int svflags; // SVF_NOCLIENT, SVF_DEADMONSTER, SVF_MONSTER, etc
85  vec3_t mins, maxs;
87  solid_t solid;
88  int clipmask;
89  edict_t *owner;
90 
91  // the game dll can add anything it wants after
92  // this point in the structure
93 };
94 
95 #endif // GAME_INCLUDE
96 
97 //===============================================================
98 
99 //
100 // functions provided by the main engine
101 //
102 typedef struct
103 {
104  // special messages
105  void (*bprintf) (int printlevel, char *fmt, ...);
106  void (*dprintf) (char *fmt, ...);
107  void (*cprintf) (edict_t *ent, int printlevel, char *fmt, ...);
108  void (*centerprintf) (edict_t *ent, char *fmt, ...);
109  void (*sound) (edict_t *ent, int channel, int soundindex, float volume, float attenuation, float timeofs);
110  void (*positioned_sound) (vec3_t origin, edict_t *ent, int channel, int soundinedex, float volume, float attenuation, float timeofs);
111 
112  // config strings hold all the index strings, the lightstyles,
113  // and misc data like the sky definition and cdtrack.
114  // All of the current configstrings are sent to clients when
115  // they connect, and changes are sent to all connected clients.
116  void (*configstring) (int num, char *string);
117 
118  void (*error) (char *fmt, ...);
119 
120  // the *index functions create configstrings and some internal server state
121  int (*modelindex) (char *name);
122  int (*soundindex) (char *name);
123  int (*imageindex) (char *name);
124 
125  void (*setmodel) (edict_t *ent, char *name);
126 
127  // collision detection
128  trace_t (*trace) (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, edict_t *passent, int contentmask);
129  int (*pointcontents) (vec3_t point);
130  qboolean (*inPVS) (vec3_t p1, vec3_t p2);
131  qboolean (*inPHS) (vec3_t p1, vec3_t p2);
132  void (*SetAreaPortalState) (int portalnum, qboolean open);
133  qboolean (*AreasConnected) (int area1, int area2);
134 
135  // an entity will never be sent to a client or used for collision
136  // if it is not passed to linkentity. If the size, position, or
137  // solidity changes, it must be relinked.
138  void (*linkentity) (edict_t *ent);
139  void (*unlinkentity) (edict_t *ent); // call before removing an interactive edict
140  int (*BoxEdicts) (vec3_t mins, vec3_t maxs, edict_t **list, int maxcount, int areatype);
141  void (*Pmove) (pmove_t *pmove); // player movement code common with client prediction
142 
143  // network messaging
144  void (*multicast) (vec3_t origin, multicast_t to);
145  void (*unicast) (edict_t *ent, qboolean reliable);
146  void (*WriteChar) (int c);
147  void (*WriteByte) (int c);
148  void (*WriteShort) (int c);
149  void (*WriteLong) (int c);
150  void (*WriteFloat) (float f);
151  void (*WriteString) (char *s);
152  void (*WritePosition) (vec3_t pos); // some fractional bits
153  void (*WriteDir) (vec3_t pos); // single byte encoded, very coarse
154  void (*WriteAngle) (float f);
155 
156  // managed memory allocation
157  void *(*TagMalloc) (int size, int tag);
158  void (*TagFree) (void *block);
159  void (*FreeTags) (int tag);
160 
161  // console variable interaction
162  cvar_t *(*cvar) (char *var_name, char *value, int flags);
163  cvar_t *(*cvar_set) (char *var_name, char *value);
164  cvar_t *(*cvar_forceset) (char *var_name, char *value);
165 
166  // ClientCommand and ServerCommand parameter access
167  int (*argc) (void);
168  char *(*argv) (int n);
169  char *(*args) (void); // concatenation of all argv >= 1
170 
171  // add commands to the server console as if they were typed in
172  // for map changing, etc
173  void (*AddCommandString) (char *text);
174 
175  void (*DebugGraph) (float value, int color);
176 } game_import_t;
177 
178 //
179 // functions exported by the game subsystem
180 //
181 typedef struct
182 {
184 
185  // the init function will only be called when a game starts,
186  // not each time a level is loaded. Persistant data for clients
187  // and the server can be allocated in init
188  void (*Init) (void);
189  void (*Shutdown) (void);
190 
191  // each new level entered will cause a call to SpawnEntities
192  void (*SpawnEntities) (char *mapname, char *entstring, char *spawnpoint);
193 
194  // Read/Write Game is for storing persistant cross level information
195  // about the world state and the clients.
196  // WriteGame is called every time a level is exited.
197  // ReadGame is called on a loadgame.
198  void (*WriteGame) (char *filename, qboolean autosave);
199  void (*ReadGame) (char *filename);
200 
201  // ReadLevel is called after the default map information has been
202  // loaded with SpawnEntities
203  void (*WriteLevel) (char *filename);
204  void (*ReadLevel) (char *filename);
205 
206  qboolean (*ClientConnect) (edict_t *ent, char *userinfo);
208  void (*ClientUserinfoChanged) (edict_t *ent, char *userinfo);
212 
213  void (*RunFrame) (void);
214 
215  // ServerCommand will be called when an "sv <command>" command is issued on the
216  // server console.
217  // The game can issue gi.argc() / gi.argv() commands to get the rest
218  // of the parameters
220 
221  //
222  // global variables shared between game and server
223  //
224 
225  // The edict array is allocated in the game dll so it
226  // can vary in size from one game to another.
227  //
228  // The size will be fixed when ge->Init() is called
229  struct edict_s *edicts;
231  int num_edicts; // current number, <= max_edicts
233 } game_export_t;
234 
236 
237 
238 /*
239  * PATCH: eliasm
240  *
241  * Some functions can't be static when using the new save game technique
242  */
243 /*#define FUNCSTATIC*/
game_import_t
Definition: game.h:102
WriteLevel
void WriteLevel(char *filename)
Definition: g_save.c:635
edict_s::s
entity_state_t s
Definition: g_local.h:964
link_t
struct link_s link_t
game_export_t::edict_size
int edict_size
Definition: game.h:230
value
GLfloat value
Definition: qgl_win.c:63
GetGameApi
game_export_t * GetGameApi(game_import_t *import)
int
CONST PIXELFORMATDESCRIPTOR int
Definition: qgl_win.c:35
gclient_s::ping
int ping
Definition: g_local.h:881
edict_s::absmax
vec3_t absmax
Definition: g_local.h:985
SOLID_BBOX
@ SOLID_BBOX
Definition: game.h:37
ClientThink
void ClientThink(edict_t *ent, usercmd_t *cmd)
Definition: p_client.c:1580
ClientUserinfoChanged
void ClientUserinfoChanged(edict_t *ent, char *userinfo)
Definition: p_client.c:1371
entity_state_s
Definition: q_shared.h:1169
game_export_t::edicts
struct edict_s * edicts
Definition: game.h:229
ClientConnect
qboolean ClientConnect(edict_t *ent, char *userinfo)
Definition: p_client.c:1440
game_export_t::apiversion
int apiversion
Definition: game.h:183
edict_s::linkcount
int linkcount
Definition: g_local.h:971
game_export_t::max_edicts
int max_edicts
Definition: game.h:232
qboolean
qboolean
Definition: q_shared.h:56
edict_s::inuse
qboolean inuse
Definition: g_local.h:970
edict_s::areanum2
int areanum2
Definition: g_local.h:979
trace_t
Definition: q_shared.h:449
ClientBegin
void ClientBegin(edict_t *ent)
Definition: p_client.c:1305
SOLID_TRIGGER
@ SOLID_TRIGGER
Definition: game.h:36
edict_s::client
struct gclient_s * client
Definition: g_local.h:965
argc
int argc
Definition: sys_win.c:54
edict_s::mins
vec3_t mins
Definition: g_local.h:984
edict_s::clusternums
int clusternums[MAX_ENT_CLUSTERS]
Definition: g_local.h:977
cvar_s
Definition: q_shared.h:317
edict_s::areanum
int areanum
Definition: g_local.h:979
ClientDisconnect
void ClientDisconnect(edict_t *ent)
Definition: p_client.c:1514
edict_s::svflags
int svflags
Definition: g_local.h:983
edict_s
Definition: g_local.h:962
ReadLevel
void ReadLevel(char *filename)
Definition: g_save.c:689
edict_s::clipmask
int clipmask
Definition: g_local.h:987
ServerCommand
void ServerCommand(void)
Definition: g_svcmds.c:282
edict_s::owner
edict_t * owner
Definition: g_local.h:988
multicast_t
multicast_t
Definition: q_shared.h:107
SpawnEntities
void SpawnEntities(char *mapname, char *entities, char *spawnpoint)
Definition: g_spawn.c:522
gclient_s::ps
player_state_t ps
Definition: g_local.h:880
edict_s::solid
solid_t solid
Definition: g_local.h:986
solid_t
solid_t
Definition: game.h:33
SOLID_NOT
@ SOLID_NOT
Definition: game.h:35
name
cvar_t * name
Definition: cl_main.c:94
game_export_t
Definition: game.h:181
usercmd_s
Definition: q_shared.h:513
ClientCommand
void ClientCommand(edict_t *ent)
Definition: g_cmds.c:909
SOLID_BSP
@ SOLID_BSP
Definition: game.h:38
edict_s::maxs
vec3_t maxs
Definition: g_local.h:984
edict_s::num_clusters
int num_clusters
Definition: g_local.h:976
ReadGame
void ReadGame(char *filename)
Definition: g_save.c:494
Pmove
void Pmove(pmove_t *pmove)
Definition: pmove.c:1240
edict_s::headnode
int headnode
Definition: g_local.h:978
player_state_t
Definition: q_shared.h:1198
edict_s::area
link_t area
Definition: g_local.h:974
gclient_s
Definition: g_local.h:877
edict_s::size
vec3_t size
Definition: g_local.h:985
MAX_ENT_CLUSTERS
#define MAX_ENT_CLUSTERS
Definition: game.h:49
vec3_t
vec_t vec3_t[3]
Definition: q_shared.h:127
edict_s::absmin
vec3_t absmin
Definition: g_local.h:985
pmove_t
Definition: q_shared.h:525
WriteGame
void WriteGame(char *filename, qboolean autosave)
Definition: g_save.c:467
game_export_t::num_edicts
int num_edicts
Definition: game.h:231
void
void(APIENTRY *qglAccum)(GLenum op