d_net.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. //
  37. // Network play related stuff.
  38. // There is a data struct that stores network
  39. // communication related stuff, and another
  40. // one that defines the actual packets to
  41. // be transmitted.
  42. //
  43. #define DOOMCOM_ID 0x12345678l
  44. // Max computers/players in a game.
  45. #define MAXNETNODES 8
  46. typedef enum
  47. {
  48. CMD_SEND = 1,
  49. CMD_GET = 2
  50. } command_t;
  51. //
  52. // Network packet data.
  53. //
  54. typedef struct
  55. {
  56. // High bit is retransmit request.
  57. unsigned checksum;
  58. // Only valid if NCMD_RETRANSMIT.
  59. byte retransmitfrom;
  60. byte starttic;
  61. byte player;
  62. byte numtics;
  63. ticcmd_t cmds[BACKUPTICS];
  64. } doomdata_t;
  65. //
  66. // Startup packet difference
  67. // SG: 4/12/98
  68. // Added so we can send more startup data to synch things like
  69. // bobbing, recoil, etc.
  70. // this is just mapped over the ticcmd_t array when setup packet is sent
  71. //
  72. // Note: the original code takes care of startskill, deathmatch, nomonsters
  73. // respawn, startepisode, startmap
  74. // Note: for phase 1 we need to add monsters_remember, variable_friction,
  75. // weapon_recoil, allow_pushers, over_under, player_bobbing,
  76. // fastparm, demo_insurance, and the rngseed
  77. //Stick all options into bytes so we don't need to mess with bitfields
  78. //WARNING: make sure this doesn't exceed the size of the ticcmds area!
  79. //sizeof(ticcmd_t)*BACKUPTICS
  80. //This is the current length of our extra stuff
  81. //
  82. //killough 5/2/98: this should all be replaced by calls to G_WriteOptions()
  83. //and G_ReadOptions(), which were specifically designed to set up packets.
  84. //By creating a separate struct and functions to read/write the options,
  85. //you now have two functions and data to maintain instead of just one.
  86. //If the array in g_game.c which G_WriteOptions()/G_ReadOptions() operates
  87. //on, is too large (more than sizeof(ticcmd_t)*BACKUPTICS), it can
  88. //either be shortened, or the net code needs to divide it up
  89. //automatically into packets. The STARTUPLEN below is non-portable.
  90. //There's a portable way to do it without having to know the sizes.
  91. #define STARTUPLEN 12
  92. typedef struct
  93. {
  94. byte monsters_remember;
  95. byte variable_friction;
  96. byte weapon_recoil;
  97. byte allow_pushers;
  98. byte over_under;
  99. byte player_bobbing;
  100. byte fastparm;
  101. byte demo_insurance;
  102. unsigned long rngseed;
  103. char filler[sizeof(ticcmd_t)*BACKUPTICS-STARTUPLEN];
  104. } startup_t;
  105. typedef enum {
  106. // Leave space, so low values corresponding to normal netgame setup packets can be ignored
  107. nm_plcolour = 3,
  108. nm_savegamename = 4,
  109. } netmisctype_t;
  110. typedef struct
  111. {
  112. netmisctype_t type;
  113. size_t len;
  114. byte value[sizeof(ticcmd_t)*BACKUPTICS - sizeof(netmisctype_t) - sizeof(size_t)];
  115. } netmisc_t;
  116. typedef struct
  117. {
  118. // Supposed to be DOOMCOM_ID?
  119. long id;
  120. // DOOM executes an int to execute commands.
  121. short intnum;
  122. // Communication between DOOM and the driver.
  123. // Is CMD_SEND or CMD_GET.
  124. short command;
  125. // Is dest for send, set by get (-1 = no packet).
  126. short remotenode;
  127. // Number of bytes in doomdata to be sent
  128. short datalength;
  129. // Info common to all nodes.
  130. // Console is allways node 0.
  131. short numnodes;
  132. // Flag: 1 = no duplication, 2-5 = dup for slow nets.
  133. short ticdup;
  134. // Flag: 1 = send a backup tic in every packet.
  135. short extratics;
  136. // Flag: 1 = deathmatch.
  137. short deathmatch;
  138. // Flag: -1 = new game, 0-5 = load savegame
  139. short savegame;
  140. short episode; // 1-3
  141. short map; // 1-9
  142. short skill; // 1-5
  143. // Info specific to this node.
  144. short consoleplayer;
  145. short numplayers;
  146. // These are related to the 3-display mode,
  147. // in which two drones looking left and right
  148. // were used to render two additional views
  149. // on two additional computers.
  150. // Probably not operational anymore.
  151. // 1 = left, 0 = center, -1 = right
  152. short angleoffset;
  153. // 1 = drone
  154. short drone;
  155. // The packet data to be sent.
  156. doomdata_t data;
  157. } doomcom_t;
  158. // Create any new ticcmds and broadcast to other players.
  159. #ifdef HAVE_NET
  160. void NetUpdate (void);
  161. #else
  162. void D_BuildNewTiccmds(void);
  163. #endif
  164. //? how many ticks to run?
  165. void TryRunTics (void);
  166. // CPhipps - move to header file
  167. void D_InitNetGame (void); // This does the setup
  168. void D_CheckNetGame(void); // This waits for game start
  169. // CPhipps - misc info broadcast
  170. void D_NetSendMisc(netmisctype_t type, size_t len, void* data);
  171. // CPhipps - ask server for a wad file we need
  172. boolean D_NetGetWad(const char* name);
  173. // Netgame stuff (buffers and pointers, i.e. indices).
  174. extern doomcom_t *doomcom;
  175. extern doomdata_t *netbuffer; // This points inside doomcom.
  176. #endif