game.h 7.4 KB

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