game.h 8.1 KB

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