game.h 6.7 KB

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