d_net.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /* Emacs style mode select -*- C++ -*-
  2. *-----------------------------------------------------------------------------
  3. *
  4. *
  5. * PrBoom: a Doom port merged with LxDoom and LSDLDoom
  6. * based on BOOM, a modified and improved DOOM engine
  7. * Copyright (C) 1999 by
  8. * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
  9. * Copyright (C) 1999-2000 by
  10. * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
  11. * Copyright 2005, 2006 by
  12. * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version 2
  17. * of the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  27. * 02111-1307, USA.
  28. *
  29. * DESCRIPTION:
  30. * Networking stuff.
  31. *
  32. *-----------------------------------------------------------------------------*/
  33. #ifndef __D_NET__
  34. #define __D_NET__
  35. #include "d_player.h"
  36. #ifdef __GNUG__
  37. #pragma interface
  38. #endif
  39. //
  40. // Network play related stuff.
  41. // There is a data struct that stores network
  42. // communication related stuff, and another
  43. // one that defines the actual packets to
  44. // be transmitted.
  45. //
  46. #define DOOMCOM_ID 0x12345678l
  47. // Max computers/players in a game.
  48. #define MAXNETNODES 8
  49. typedef enum
  50. {
  51. CMD_SEND = 1,
  52. CMD_GET = 2
  53. } command_t;
  54. //
  55. // Network packet data.
  56. //
  57. typedef struct
  58. {
  59. // High bit is retransmit request.
  60. unsigned checksum;
  61. // Only valid if NCMD_RETRANSMIT.
  62. byte retransmitfrom;
  63. byte starttic;
  64. byte player;
  65. byte numtics;
  66. ticcmd_t cmds[BACKUPTICS];
  67. } doomdata_t;
  68. //
  69. // Startup packet difference
  70. // SG: 4/12/98
  71. // Added so we can send more startup data to synch things like
  72. // bobbing, recoil, etc.
  73. // this is just mapped over the ticcmd_t array when setup packet is sent
  74. //
  75. // Note: the original code takes care of startskill, deathmatch, nomonsters
  76. // respawn, startepisode, startmap
  77. // Note: for phase 1 we need to add monsters_remember, variable_friction,
  78. // weapon_recoil, allow_pushers, over_under, player_bobbing,
  79. // fastparm, demo_insurance, and the rngseed
  80. //Stick all options into bytes so we don't need to mess with bitfields
  81. //WARNING: make sure this doesn't exceed the size of the ticcmds area!
  82. //sizeof(ticcmd_t)*BACKUPTICS
  83. //This is the current length of our extra stuff
  84. //
  85. //killough 5/2/98: this should all be replaced by calls to G_WriteOptions()
  86. //and G_ReadOptions(), which were specifically designed to set up packets.
  87. //By creating a separate struct and functions to read/write the options,
  88. //you now have two functions and data to maintain instead of just one.
  89. //If the array in g_game.c which G_WriteOptions()/G_ReadOptions() operates
  90. //on, is too large (more than sizeof(ticcmd_t)*BACKUPTICS), it can
  91. //either be shortened, or the net code needs to divide it up
  92. //automatically into packets. The STARTUPLEN below is non-portable.
  93. //There's a portable way to do it without having to know the sizes.
  94. #define STARTUPLEN 12
  95. typedef struct
  96. {
  97. byte monsters_remember;
  98. byte variable_friction;
  99. byte weapon_recoil;
  100. byte allow_pushers;
  101. byte over_under;
  102. byte player_bobbing;
  103. byte fastparm;
  104. byte demo_insurance;
  105. unsigned long rngseed;
  106. char filler[sizeof(ticcmd_t)*BACKUPTICS-STARTUPLEN];
  107. } startup_t;
  108. typedef enum {
  109. // Leave space, so low values corresponding to normal netgame setup packets can be ignored
  110. nm_plcolour = 3,
  111. nm_savegamename = 4,
  112. } netmisctype_t;
  113. typedef struct
  114. {
  115. netmisctype_t type;
  116. size_t len;
  117. byte value[sizeof(ticcmd_t)*BACKUPTICS - sizeof(netmisctype_t) - sizeof(size_t)];
  118. } netmisc_t;
  119. typedef struct
  120. {
  121. // Supposed to be DOOMCOM_ID?
  122. long id;
  123. // DOOM executes an int to execute commands.
  124. short intnum;
  125. // Communication between DOOM and the driver.
  126. // Is CMD_SEND or CMD_GET.
  127. short command;
  128. // Is dest for send, set by get (-1 = no packet).
  129. short remotenode;
  130. // Number of bytes in doomdata to be sent
  131. short datalength;
  132. // Info common to all nodes.
  133. // Console is allways node 0.
  134. short numnodes;
  135. // Flag: 1 = no duplication, 2-5 = dup for slow nets.
  136. short ticdup;
  137. // Flag: 1 = send a backup tic in every packet.
  138. short extratics;
  139. // Flag: 1 = deathmatch.
  140. short deathmatch;
  141. // Flag: -1 = new game, 0-5 = load savegame
  142. short savegame;
  143. short episode; // 1-3
  144. short map; // 1-9
  145. short skill; // 1-5
  146. // Info specific to this node.
  147. short consoleplayer;
  148. short numplayers;
  149. // These are related to the 3-display mode,
  150. // in which two drones looking left and right
  151. // were used to render two additional views
  152. // on two additional computers.
  153. // Probably not operational anymore.
  154. // 1 = left, 0 = center, -1 = right
  155. short angleoffset;
  156. // 1 = drone
  157. short drone;
  158. // The packet data to be sent.
  159. doomdata_t data;
  160. } doomcom_t;
  161. // Create any new ticcmds and broadcast to other players.
  162. #ifdef HAVE_NET
  163. void NetUpdate (void);
  164. #else
  165. void D_BuildNewTiccmds(void);
  166. #endif
  167. //? how many ticks to run?
  168. void TryRunTics (void);
  169. // CPhipps - move to header file
  170. void D_InitNetGame (void); // This does the setup
  171. void D_CheckNetGame(void); // This waits for game start
  172. // CPhipps - misc info broadcast
  173. void D_NetSendMisc(netmisctype_t type, size_t len, void* data);
  174. // CPhipps - ask server for a wad file we need
  175. boolean D_NetGetWad(const char* name);
  176. // Netgame stuff (buffers and pointers, i.e. indices).
  177. extern doomcom_t *doomcom;
  178. extern doomdata_t *netbuffer; // This points inside doomcom.
  179. #endif