game.h 7.8 KB

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