PageRenderTime 168ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/v1.6-final/main/netmisc-new.c

https://github.com/simX/d2x-xl
C | 703 lines | 471 code | 71 blank | 161 comment | 47 complexity | 3bfb0b8aaa711529a063f393d3e991e6 MD5 | raw file
Possible License(s): GPL-2.0
  1. /* $Id: netmisc.c,v 1.9 2003/10/04 19:13:32 btb Exp $ */
  2. /*
  3. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  4. SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
  5. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  6. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  7. IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  8. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  9. FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  10. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
  11. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  12. COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  13. */
  14. /*
  15. *
  16. * Misc routines for network.
  17. *
  18. * Old Log:
  19. * Revision 1.1 1995/05/16 15:28:41 allender
  20. * Initial revision
  21. *
  22. * Revision 2.0 1995/02/27 11:27:24 john
  23. * New version 2.0, which has no anonymous unions, builds with
  24. * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  25. *
  26. * Revision 1.3 1994/11/19 15:19:34 mike
  27. * rip out unused code and data.
  28. *
  29. * Revision 1.2 1994/08/09 19:31:53 john
  30. * Networking changes.
  31. *
  32. * Revision 1.1 1994/08/08 11:06:07 john
  33. * Initial revision
  34. *
  35. *
  36. */
  37. #ifdef HAVE_CONFIG_H
  38. #include <conf.h>
  39. #endif
  40. #ifdef RCS
  41. static char rcsid[] = "$Id: netmisc.c,v 1.9 2003/10/04 19:13:32 btb Exp $";
  42. #endif
  43. #include <stdio.h>
  44. #include <string.h>
  45. #include "inferno.h"
  46. #include "pstypes.h"
  47. #include "mono.h"
  48. #if defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__)
  49. #include "byteswap.h"
  50. #include "segment.h"
  51. #include "gameseg.h"
  52. #include "network.h"
  53. #include "wall.h"
  54. #include "ipx.h"
  55. #include "multi.h"
  56. #ifdef NETWORK
  57. #include "network.h"
  58. #endif
  59. #include "object.h"
  60. #include "powerup.h"
  61. #include "netmisc.h"
  62. #include "error.h"
  63. static ubyte nmDataBuf [IPX_MAX_DATA_SIZE]; // used for tmp netgame packets as well as sending object data
  64. static ubyte *nmBufP = NULL;
  65. extern struct ipx_recv_data ipx_udpSrc;
  66. // if using the following macros in loops, the loop's body *must* be enclosed in curly braces,
  67. // or the macros won't work as intended, as the buffer pointer nmBufI will only be incremented
  68. // after the loop has been fully executed!
  69. #define BE_SET_INT(_src) *((int *) (nmBufP + nmBufI)) = INTEL_INT ((int) (_src)); nmBufI += 4
  70. #define BE_SET_SHORT(_src) *((short *) (nmBufP + nmBufI)) = INTEL_SHORT ((short) (_src)); nmBufI += 2
  71. #define BE_SET_BYTE(_src) nmBufP [nmBufI++] = (ubyte) (_src)
  72. #define BE_SET_BYTES(_src,_srcSize) memcpy (nmBufP + nmBufI, _src, _srcSize); nmBufI += (_srcSize)
  73. #define BE_GET_INT(_dest) (_dest) = INTEL_INT (*((int *) (nmBufP + nmBufI))); nmBufI += 4
  74. #define BE_GET_SHORT(_dest) (_dest) = INTEL_SHORT (*((short *) (nmBufP + nmBufI))); nmBufI += 2
  75. #define BE_GET_BYTE(_dest) (_dest) = nmBufP [nmBufI++]
  76. #define BE_GET_BYTES(_dest,_destSize) memcpy (_dest, nmBufP + nmBufI, _destSize); nmBufI += (_destSize)
  77. //------------------------------------------------------------------------------
  78. // routine to calculate the checksum of the segments. We add these specialized routines
  79. // since the current way is byte order dependent.
  80. void BEDoCheckSumCalc (ubyte *b, int len, unsigned int *ps1, unsigned int *ps2)
  81. {
  82. int s1 = *ps1;
  83. int s2 = *ps2;
  84. while(len--) {
  85. s1 += *b++;
  86. if (s1 >= 255)
  87. s1 -= 255;
  88. s2 += s1;
  89. }
  90. *ps1 = s1;
  91. *ps2 = s2;
  92. }
  93. //------------------------------------------------------------------------------
  94. ushort BECalcSegmentCheckSum (void)
  95. {
  96. int i, j, k;
  97. unsigned int sum1, sum2;
  98. short s;
  99. int t;
  100. sum1 = sum2 = 0;
  101. for (i = 0; i < gameData.segs.nLastSegment + 1; i++) {
  102. for (j = 0; j < MAX_SIDES_PER_SEGMENT; j++) {
  103. BEDoCheckSumCalc (&(gameData.segs.segments [i].sides [j].type), 1, &sum1, &sum2);
  104. BEDoCheckSumCalc (&(gameData.segs.segments [i].sides [j].frame_num), 1, &sum1, &sum2);
  105. s = INTEL_SHORT (WallNumI (i, j));
  106. BEDoCheckSumCalc ((ubyte *)&s, 2, &sum1, &sum2);
  107. s = INTEL_SHORT (gameData.segs.segments [i].sides [j].tmap_num);
  108. BEDoCheckSumCalc ((ubyte *)&s, 2, &sum1, &sum2);
  109. s = INTEL_SHORT (gameData.segs.segments [i].sides [j].tmap_num2);
  110. BEDoCheckSumCalc ((ubyte *)&s, 2, &sum1, &sum2);
  111. for (k = 0; k < 4; k++) {
  112. t = INTEL_INT (((int) gameData.segs.segments [i].sides [j].uvls [k].u));
  113. BEDoCheckSumCalc ((ubyte *)&t, 4, &sum1, &sum2);
  114. t = INTEL_INT (((int) gameData.segs.segments [i].sides [j].uvls [k].v));
  115. BEDoCheckSumCalc ((ubyte *)&t, 4, &sum1, &sum2);
  116. t = INTEL_INT (((int) gameData.segs.segments [i].sides [j].uvls [k].l));
  117. BEDoCheckSumCalc ((ubyte *)&t, 4, &sum1, &sum2);
  118. }
  119. for (k = 0; k < 2; k++) {
  120. t = INTEL_INT (((int) gameData.segs.segments [i].sides [j].normals [k].x));
  121. BEDoCheckSumCalc ((ubyte *)&t, 4, &sum1, &sum2);
  122. t = INTEL_INT (((int) gameData.segs.segments [i].sides [j].normals [k].y));
  123. BEDoCheckSumCalc ((ubyte *)&t, 4, &sum1, &sum2);
  124. t = INTEL_INT (((int) gameData.segs.segments [i].sides [j].normals [k].z));
  125. BEDoCheckSumCalc ((ubyte *)&t, 4, &sum1, &sum2);
  126. }
  127. }
  128. for (j = 0; j < MAX_SIDES_PER_SEGMENT; j++) {
  129. s = INTEL_SHORT (gameData.segs.segments [i].children[j]);
  130. BEDoCheckSumCalc ((ubyte *)&s, 2, &sum1, &sum2);
  131. }
  132. for (j = 0; j < MAX_VERTICES_PER_SEGMENT; j++) {
  133. s = INTEL_SHORT (gameData.segs.segments [i].verts [j]);
  134. BEDoCheckSumCalc ((ubyte *)&s, 2, &sum1, &sum2);
  135. }
  136. t = INTEL_INT (gameData.segs.segments [i].objects);
  137. BEDoCheckSumCalc ((ubyte *)&t, 4, &sum1, &sum2);
  138. }
  139. sum2 %= 255;
  140. return ((sum1 << 8) + sum2);
  141. }
  142. //------------------------------------------------------------------------------
  143. // following are routine for big endian hardware that will swap the elements of
  144. // structures send through the networking code. The structures and
  145. // this code must be kept in total sync
  146. void BEReceiveNetPlayerInfo (ubyte *data, netplayer_info *info)
  147. {
  148. int nmBufI = 0;
  149. nmBufP = data;
  150. BE_GET_BYTES (info->callsign, CALLSIGN_LEN + 1);
  151. BE_GET_BYTES (info->network.ipx.server, 4);
  152. BE_GET_BYTES (info->network.ipx.node, 6);
  153. BE_GET_BYTE (info->version_major);
  154. BE_GET_BYTE (info->version_minor);
  155. BE_GET_BYTE (info->computer_type);
  156. BE_GET_BYTE (info->connected);
  157. //BE_GET_SHORT (info->socket);
  158. info->socket = *((short *) (data + nmBufI)); //don't swap!
  159. BE_GET_BYTE (info->rank);
  160. }
  161. //------------------------------------------------------------------------------
  162. void BESendNetPlayersPacket (ubyte *server, ubyte *node)
  163. {
  164. int i;
  165. int nmBufI = 0;
  166. nmBufP = nmDataBuf;
  167. #ifdef _DEBUG
  168. memset (nmBufP, 0, IPX_MAX_DATA_SIZE); //this takes time and shouldn't be necessary
  169. #endif
  170. BE_SET_BYTE (netPlayers.type);
  171. BE_SET_INT (netPlayers.Security);
  172. for (i = 0; i < MAX_PLAYERS + 4; i++) {
  173. BE_SET_BYTES (netPlayers.players [i].callsign, CALLSIGN_LEN + 1);
  174. BE_SET_BYTES (netPlayers.players [i].network.ipx.server, 4);
  175. BE_SET_BYTES (netPlayers.players [i].network.ipx.node, 6);
  176. BE_SET_BYTE (netPlayers.players [i].version_major);
  177. BE_SET_BYTE (netPlayers.players [i].version_minor);
  178. BE_SET_BYTE (netPlayers.players [i].computer_type);
  179. BE_SET_BYTE (netPlayers.players [i].connected);
  180. BE_SET_SHORT (netPlayers.players [i].socket);
  181. BE_SET_BYTE (netPlayers.players [i].rank);
  182. }
  183. if (!server && !node)
  184. IPXSendBroadcastData (nmBufP, nmBufI);
  185. else
  186. IPXSendInternetPacketData (nmBufP, nmBufI, server, node);
  187. }
  188. //------------------------------------------------------------------------------
  189. void BEReceiveNetPlayersPacket (ubyte *data, allNetPlayers_info *pinfo)
  190. {
  191. int i, nmBufI = 0;
  192. nmBufP = data;
  193. BE_GET_BYTE (pinfo->type);
  194. BE_GET_INT (pinfo->Security);
  195. for (i = 0; i < MAX_PLAYERS + 4; i++) {
  196. BEReceiveNetPlayerInfo (data + nmBufI, pinfo->players + i);
  197. nmBufI += 26; // sizeof(netplayer_info) on the PC
  198. }
  199. }
  200. //------------------------------------------------------------------------------
  201. void BESendSequencePacket (sequence_packet seq, ubyte *server, ubyte *node, ubyte *net_address)
  202. {
  203. int nmBufI = 0;
  204. nmBufP = nmDataBuf;
  205. #ifdef _DEBUG
  206. memset (nmBufP, 0, IPX_MAX_DATA_SIZE); //this takes time and shouldn't be necessary
  207. #endif
  208. BE_SET_BYTE (seq.type);
  209. BE_SET_INT (seq.Security);
  210. nmBufI += 3;
  211. BE_SET_BYTES (seq.player.callsign, CALLSIGN_LEN + 1);
  212. BE_SET_BYTES (seq.player.network.ipx.server, 4);
  213. BE_SET_BYTES (seq.player.network.ipx.node, 6);
  214. BE_SET_BYTE (seq.player.version_major);
  215. BE_SET_BYTE (seq.player.version_minor);
  216. BE_SET_BYTE (seq.player.computer_type);
  217. BE_SET_BYTE (seq.player.connected);
  218. BE_SET_SHORT (seq.player.socket);
  219. BE_SET_BYTE (seq.player.rank);
  220. if (net_address)
  221. IPXSendPacketData (nmBufP, nmBufI, server, node, net_address);
  222. else if (!server && !node)
  223. IPXSendBroadcastData (nmBufP, nmBufI);
  224. else
  225. IPXSendInternetPacketData (nmBufP, nmBufI, server, node);
  226. }
  227. //------------------------------------------------------------------------------
  228. void BEReceiveSequencePacket (ubyte *data, sequence_packet *seq)
  229. {
  230. int nmBufI = 0;
  231. nmBufP = data;
  232. BE_GET_BYTE (seq->type);
  233. BE_GET_INT (seq->Security);
  234. nmBufI += 3; // +3 for pad bytes
  235. BEReceiveNetPlayerInfo (data + nmBufI, &(seq->player));
  236. }
  237. //------------------------------------------------------------------------------
  238. void BESendNetGamePacket (ubyte *server, ubyte *node, ubyte *net_address, int bLiteData)
  239. {
  240. int i;
  241. short *ps;
  242. int nmBufI = 0;
  243. nmBufP = nmDataBuf;
  244. #ifdef _DEBUG
  245. memset (nmBufP, 0, IPX_MAX_DATA_SIZE); //this takes time and shouldn't be necessary
  246. #endif
  247. BE_SET_BYTE (netGame.type);
  248. BE_SET_INT (netGame.Security);
  249. BE_SET_BYTES (netGame.game_name, NETGAME_NAME_LEN + 1);
  250. BE_SET_BYTES (netGame.mission_title, MISSION_NAME_LEN + 1);
  251. BE_SET_BYTES (netGame.mission_name, 9);
  252. BE_SET_INT (netGame.levelnum);
  253. BE_SET_BYTE (netGame.gamemode);
  254. BE_SET_BYTE (netGame.RefusePlayers);
  255. BE_SET_BYTE (netGame.difficulty);
  256. BE_SET_BYTE (netGame.game_status);
  257. BE_SET_BYTE (netGame.numplayers);
  258. BE_SET_BYTE (netGame.max_numplayers);
  259. BE_SET_BYTE (netGame.numconnected);
  260. BE_SET_BYTE (netGame.game_flags);
  261. BE_SET_BYTE (netGame.protocol_version);
  262. BE_SET_BYTE (netGame.version_major);
  263. BE_SET_BYTE (netGame.version_minor);
  264. BE_SET_BYTE (netGame.team_vector);
  265. if (bLiteData)
  266. goto do_send;
  267. BE_SET_SHORT (((ubyte *) &netGame.team_vector) + 1); // get the values for the first short bitfield
  268. BE_SET_SHORT (((ubyte *) &netGame.team_vector) + 3); // get the values for the first short bitfield
  269. BE_SET_BYTES (netGame.team_name, 2 * (CALLSIGN_LEN + 1));
  270. for (i = 0; i < MAX_PLAYERS; i++) {
  271. BE_SET_INT (netGame.locations [i]);
  272. }
  273. #if 1
  274. for (i = MAX_PLAYERS * MAX_PLAYERS, ps = &netGame.kills [0][0]; i; i--, ps++) {
  275. BE_SET_SHORT (*ps);
  276. }
  277. #else
  278. {
  279. int j;
  280. for (i = 0; i < MAX_PLAYERS; i++) {
  281. for (j = 0; j < MAX_PLAYERS; j++) {
  282. BE_SET_SHORT (netGame.kills [i][j]);
  283. }
  284. }
  285. }
  286. #endif
  287. BE_SET_SHORT (netGame.segments_checksum);
  288. BE_SET_SHORT (netGame.team_kills [0]);
  289. BE_SET_SHORT (netGame.team_kills [1]);
  290. for (i = 0; i < MAX_PLAYERS; i++) {
  291. BE_SET_SHORT (netGame.killed [i]);
  292. }
  293. for (i = 0; i < MAX_PLAYERS; i++) {
  294. BE_SET_SHORT (netGame.player_kills [i]);
  295. }
  296. BE_SET_INT (netGame.KillGoal);
  297. BE_SET_INT (netGame.PlayTimeAllowed);
  298. BE_SET_INT (netGame.level_time);
  299. BE_SET_INT (netGame.control_invul_time);
  300. BE_SET_INT (netGame.monitor_vector);
  301. for (i = 0; i < MAX_PLAYERS; i++) {
  302. BE_SET_INT (netGame.player_score[i]);
  303. }
  304. BE_SET_BYTES (netGame.player_flags, MAX_PLAYERS);
  305. BE_SET_SHORT (netGame.nPacketsPerSec);
  306. BE_SET_BYTE (netGame.bShortPackets);
  307. do_send:
  308. if (net_address)
  309. IPXSendPacketData(nmBufP, nmBufI, server, node, net_address);
  310. else if (!server && !node)
  311. IPXSendBroadcastData(nmBufP, nmBufI);
  312. else
  313. IPXSendInternetPacketData(nmBufP, nmBufI, server, node);
  314. }
  315. //------------------------------------------------------------------------------
  316. void BEReceiveNetGamePacket (ubyte *data, netgame_info *netgame, int bLiteData)
  317. {
  318. int i;
  319. short *ps;
  320. int nmBufI = 0;
  321. nmBufP = data;
  322. BE_GET_BYTE (netgame->type);
  323. BE_GET_INT (netgame->Security);
  324. BE_GET_BYTES (netgame->game_name, NETGAME_NAME_LEN + 1);
  325. BE_GET_BYTES (netgame->mission_title, MISSION_NAME_LEN + 1);
  326. BE_GET_BYTES (netgame->mission_name, 9);
  327. BE_GET_INT (netgame->levelnum);
  328. BE_GET_BYTE (netgame->gamemode);
  329. BE_GET_BYTE (netgame->RefusePlayers);
  330. BE_GET_BYTE (netgame->difficulty);
  331. BE_GET_BYTE (netgame->game_status);
  332. BE_GET_BYTE (netgame->numplayers);
  333. BE_GET_BYTE (netgame->max_numplayers);
  334. BE_GET_BYTE (netgame->numconnected);
  335. BE_GET_BYTE (netgame->game_flags);
  336. BE_GET_BYTE (netgame->protocol_version);
  337. BE_GET_BYTE (netgame->version_major);
  338. BE_GET_BYTE (netgame->version_minor);
  339. BE_GET_BYTE (netgame->team_vector);
  340. if (bLiteData)
  341. return;
  342. BE_GET_SHORT (*((short *) (((ubyte *) &netgame->team_vector) + 1)));
  343. BE_GET_SHORT (*((short *) (((ubyte *) &netgame->team_vector) + 3)));
  344. BE_GET_BYTES (netgame->team_name, CALLSIGN_LEN + 1);
  345. for (i = 0; i < MAX_PLAYERS; i++) {
  346. BE_GET_INT (netgame->locations [i]);
  347. }
  348. #if 1
  349. for (i = MAX_PLAYERS * MAX_PLAYERS, ps = &netgame->kills [0][0]; i; i--, ps++) {
  350. BE_GET_SHORT (*ps);
  351. }
  352. #else
  353. {
  354. int j;
  355. for (i = 0; i < MAX_PLAYERS; i++)
  356. for (j = 0; j < MAX_PLAYERS; j++) {
  357. BE_GET_SHORT (netgame->kills [i][j]);
  358. }
  359. }
  360. #endif
  361. BE_GET_SHORT (netgame->segments_checksum);
  362. BE_GET_SHORT (netgame->team_kills [0]);
  363. BE_GET_SHORT (netgame->team_kills [1]);
  364. for (i = 0; i < MAX_PLAYERS; i++) {
  365. BE_GET_SHORT (netgame->killed [i]);
  366. }
  367. for (i = 0; i < MAX_PLAYERS; i++) {
  368. BE_GET_SHORT (netgame->player_kills [i]);
  369. }
  370. BE_GET_INT (netgame->KillGoal);
  371. BE_GET_INT (netgame->PlayTimeAllowed);
  372. BE_GET_INT (netgame->level_time);
  373. BE_GET_INT (netgame->control_invul_time);
  374. BE_GET_INT (netgame->monitor_vector);
  375. for (i = 0; i < MAX_PLAYERS; i++) {
  376. BE_GET_INT (netgame->player_score [i]);
  377. }
  378. BE_GET_BYTES (netgame->player_flags, MAX_PLAYERS);
  379. BE_GET_SHORT (netgame->nPacketsPerSec);
  380. BE_GET_BYTE (netgame->bShortPackets);
  381. }
  382. //------------------------------------------------------------------------------
  383. #define EGI_INTEL_SHORT_2BUF(_m) \
  384. *((short *) (nmBufP + ((char *) &extraGameInfo [1]._m - (char *) &extraGameInfo [1]))) = INTEL_SHORT (extraGameInfo [1]._m);
  385. #define EGI_INTEL_INT_2BUF(_m) \
  386. *((int *) (nmBufP + ((char *) &extraGameInfo [1]._m - (char *) &extraGameInfo [1]))) = INTEL_INT (extraGameInfo [1]._m);
  387. #define BUF2_EGI_INTEL_SHORT(_m) \
  388. extraGameInfo [1]._m = INTEL_SHORT (*((short *) (nmBufP + ((char *) &extraGameInfo [1]._m - (char *) &extraGameInfo [1]))));
  389. #define BUF2_EGI_INTEL_INT(_m) \
  390. extraGameInfo [1]._m = INTEL_INT (*((int *) (nmBufP + ((char *) &extraGameInfo [1]._m - (char *) &extraGameInfo [1]))));
  391. void BESendExtraGameInfo (ubyte *server, ubyte *node, ubyte *net_address)
  392. {
  393. int i = 0;
  394. nmBufP = nmDataBuf;
  395. memcpy (nmBufP, &extraGameInfo [1], sizeof (extraGameInfo [0]));
  396. EGI_INTEL_SHORT_2BUF (entropy.nMaxVirusCapacity);
  397. EGI_INTEL_SHORT_2BUF (entropy.nEnergyFillRate);
  398. EGI_INTEL_SHORT_2BUF (entropy.nShieldFillRate);
  399. EGI_INTEL_SHORT_2BUF (entropy.nShieldDamageRate);
  400. EGI_INTEL_INT_2BUF (nSpawnDelay);
  401. if (net_address)
  402. IPXSendPacketData (nmBufP, sizeof (extraGameInfo [0]), server, node, net_address);
  403. else if (!server && !node)
  404. IPXSendBroadcastData (nmBufP, sizeof (extraGameInfo [0]));
  405. else
  406. IPXSendInternetPacketData (nmBufP, sizeof (extraGameInfo [0]), server, node);
  407. }
  408. //------------------------------------------------------------------------------
  409. void BEReceiveExtraGameInfo (ubyte *data, extra_gameinfo *extraGameInfo)
  410. {
  411. int i;
  412. nmBufP = data;
  413. memcpy (&extraGameInfo [1], nmBufP, sizeof (extraGameInfo [0]));
  414. BUF2_EGI_INTEL_SHORT (entropy.nMaxVirusCapacity);
  415. BUF2_EGI_INTEL_SHORT (entropy.nEnergyFillRate);
  416. BUF2_EGI_INTEL_SHORT (entropy.nShieldFillRate);
  417. BUF2_EGI_INTEL_SHORT (entropy.nShieldDamageRate);
  418. BUF2_EGI_INTEL_INT (nSpawnDelay);
  419. }
  420. //------------------------------------------------------------------------------
  421. void BESwapObject ( object *objP)
  422. {
  423. // swap the short and int entries for this object
  424. objP->signature = INTEL_INT (objP->signature);
  425. objP->next = INTEL_SHORT (objP->next);
  426. objP->prev = INTEL_SHORT (objP->prev);
  427. objP->segnum = INTEL_SHORT (objP->segnum);
  428. INTEL_VECTOR (&objP->pos);
  429. INTEL_MATRIX (&objP->orient);
  430. objP->size = INTEL_INT (objP->size);
  431. objP->shields = INTEL_INT (objP->shields);
  432. INTEL_VECTOR (&objP->last_pos);
  433. objP->lifeleft = INTEL_INT (objP->lifeleft);
  434. switch (objP->movement_type) {
  435. case MT_PHYSICS:
  436. INTEL_VECTOR (&objP->mtype.phys_info.velocity);
  437. INTEL_VECTOR (&objP->mtype.phys_info.thrust);
  438. objP->mtype.phys_info.mass = INTEL_INT (objP->mtype.phys_info.mass);
  439. objP->mtype.phys_info.drag = INTEL_INT (objP->mtype.phys_info.drag);
  440. objP->mtype.phys_info.brakes = INTEL_INT (objP->mtype.phys_info.brakes);
  441. INTEL_VECTOR (&objP->mtype.phys_info.rotvel);
  442. INTEL_VECTOR (&objP->mtype.phys_info.rotthrust);
  443. objP->mtype.phys_info.turnroll = INTEL_INT (objP->mtype.phys_info.turnroll);
  444. objP->mtype.phys_info.flags = INTEL_SHORT (objP->mtype.phys_info.flags);
  445. break;
  446. case MT_SPINNING:
  447. INTEL_VECTOR (&objP->mtype.spin_rate);
  448. break;
  449. }
  450. switch (objP->control_type) {
  451. case CT_WEAPON:
  452. objP->ctype.laser_info.parent_type = INTEL_SHORT (objP->ctype.laser_info.parent_type);
  453. objP->ctype.laser_info.parent_num = INTEL_SHORT (objP->ctype.laser_info.parent_num);
  454. objP->ctype.laser_info.parent_signature = INTEL_INT (objP->ctype.laser_info.parent_signature);
  455. objP->ctype.laser_info.creation_time = INTEL_INT (objP->ctype.laser_info.creation_time);
  456. objP->ctype.laser_info.last_hitobj = INTEL_SHORT (objP->ctype.laser_info.last_hitobj);
  457. objP->ctype.laser_info.track_goal = INTEL_SHORT (objP->ctype.laser_info.track_goal);
  458. objP->ctype.laser_info.multiplier = INTEL_INT (objP->ctype.laser_info.multiplier);
  459. break;
  460. case CT_EXPLOSION:
  461. objP->ctype.expl_info.spawn_time = INTEL_INT (objP->ctype.expl_info.spawn_time);
  462. objP->ctype.expl_info.delete_time = INTEL_INT (objP->ctype.expl_info.delete_time);
  463. objP->ctype.expl_info.delete_objnum = INTEL_SHORT (objP->ctype.expl_info.delete_objnum);
  464. objP->ctype.expl_info.attach_parent = INTEL_SHORT (objP->ctype.expl_info.attach_parent);
  465. objP->ctype.expl_info.prev_attach = INTEL_SHORT (objP->ctype.expl_info.prev_attach);
  466. objP->ctype.expl_info.next_attach = INTEL_SHORT (objP->ctype.expl_info.next_attach);
  467. break;
  468. case CT_AI:
  469. objP->ctype.ai_info.hide_segment = INTEL_SHORT (objP->ctype.ai_info.hide_segment);
  470. objP->ctype.ai_info.hide_index = INTEL_SHORT (objP->ctype.ai_info.hide_index);
  471. objP->ctype.ai_info.path_length = INTEL_SHORT (objP->ctype.ai_info.path_length);
  472. objP->ctype.ai_info.danger_laser_num = INTEL_SHORT (objP->ctype.ai_info.danger_laser_num);
  473. objP->ctype.ai_info.danger_laser_signature = INTEL_INT (objP->ctype.ai_info.danger_laser_signature);
  474. objP->ctype.ai_info.dying_start_time = INTEL_INT (objP->ctype.ai_info.dying_start_time);
  475. break;
  476. case CT_LIGHT:
  477. objP->ctype.light_info.intensity = INTEL_INT (objP->ctype.light_info.intensity);
  478. break;
  479. case CT_POWERUP:
  480. objP->ctype.powerup_info.count = INTEL_INT (objP->ctype.powerup_info.count);
  481. objP->ctype.powerup_info.creation_time = INTEL_INT (objP->ctype.powerup_info.creation_time);
  482. break;
  483. }
  484. switch (objP->render_type) {
  485. case RT_MORPH:
  486. case RT_POLYOBJ: {
  487. int i;
  488. objP->rtype.pobj_info.model_num = INTEL_INT (objP->rtype.pobj_info.model_num);
  489. for (i = 0; i < MAX_SUBMODELS; i++)
  490. INTEL_ANGVEC (objP->rtype.pobj_info.anim_angles + i);
  491. objP->rtype.pobj_info.subobj_flags = INTEL_INT (objP->rtype.pobj_info.subobj_flags);
  492. objP->rtype.pobj_info.tmap_override = INTEL_INT (objP->rtype.pobj_info.tmap_override);
  493. objP->rtype.pobj_info.alt_textures = INTEL_INT (objP->rtype.pobj_info.alt_textures);
  494. break;
  495. }
  496. case RT_WEAPON_VCLIP:
  497. case RT_HOSTAGE:
  498. case RT_POWERUP:
  499. case RT_FIREBALL:
  500. case RT_THRUSTER:
  501. objP->rtype.vclip_info.nClipIndex = INTEL_INT (objP->rtype.vclip_info.nClipIndex);
  502. objP->rtype.vclip_info.xFrameTime = INTEL_INT (objP->rtype.vclip_info.xFrameTime);
  503. break;
  504. case RT_LASER:
  505. break;
  506. }
  507. }
  508. #endif /* WORDS_BIGENDIAN */
  509. //------------------------------------------------------------------------------
  510. // Calculates the checksum of a block of memory.
  511. ushort NetMiscCalcCheckSum (void * vptr, int len)
  512. {
  513. #if defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__)
  514. return BECalcSegmentCheckSum ();
  515. #else
  516. ubyte *ptr = (ubyte *) vptr;
  517. unsigned int sum1, sum2;
  518. sum1 = sum2 = 0;
  519. for (; len; len--) {
  520. sum1 += *ptr++;
  521. #if 1
  522. sum1 %= 255;
  523. #else
  524. if (sum1 >= 255)
  525. sum1 -= 255;
  526. #endif
  527. sum2 += sum1;
  528. }
  529. return (sum1 * 256 + sum2 % 255);
  530. #endif
  531. }
  532. //------------------------------------------------------------------------------
  533. // needs to be recoded to actually work with big endian!
  534. //--unused-- //Finds the difference between block1 and block2. Fills in diff_buffer and
  535. //--unused-- //returns the size of diff_buffer.
  536. //--unused-- int netmisc_find_diff(void *block1, void *block2, int block_size, void *diff_buffer)
  537. //--unused-- {
  538. //--unused-- int mode;
  539. //--unused-- ushort *c1, *c2, *diff_start, *c3;
  540. //--unused-- int i, j, size, diff, n , same;
  541. //--unused--
  542. //--unused-- size=(block_size+1)/sizeof(ushort);
  543. //--unused-- c1 = (ushort *)block1;
  544. //--unused-- c2 = (ushort *)block2;
  545. //--unused-- c3 = (ushort *)diff_buffer;
  546. //--unused--
  547. //--unused-- mode = same = diff = n = 0;
  548. //--unused--
  549. //--unused-- for (i=0; i<size; i++, c1++, c2++) {
  550. //--unused-- if (*c1 != *c2) {
  551. //--unused-- if (mode==0) {
  552. //--unused-- mode = 1;
  553. //--unused-- c3[n++] = same;
  554. //--unused-- same=0; diff=0;
  555. //--unused-- diff_start = c2;
  556. //--unused-- }
  557. //--unused-- *c1 = *c2;
  558. //--unused-- diff++;
  559. //--unused-- if (diff==65535) {
  560. //--unused-- mode = 0;
  561. //--unused-- // send how many diff ones.
  562. //--unused-- c3[n++]=diff;
  563. //--unused-- // send all the diff ones.
  564. //--unused-- for (j=0; j<diff; j++)
  565. //--unused-- c3[n++] = diff_start[j];
  566. //--unused-- same=0; diff=0;
  567. //--unused-- diff_start = c2;
  568. //--unused-- }
  569. //--unused-- } else {
  570. //--unused-- if (mode==1) {
  571. //--unused-- mode=0;
  572. //--unused-- // send how many diff ones.
  573. //--unused-- c3[n++]=diff;
  574. //--unused-- // send all the diff ones.
  575. //--unused-- for (j=0; j<diff; j++)
  576. //--unused-- c3[n++] = diff_start[j];
  577. //--unused-- same=0; diff=0;
  578. //--unused-- diff_start = c2;
  579. //--unused-- }
  580. //--unused-- same++;
  581. //--unused-- if (same==65535) {
  582. //--unused-- mode=1;
  583. //--unused-- // send how many the same
  584. //--unused-- c3[n++] = same;
  585. //--unused-- same=0; diff=0;
  586. //--unused-- diff_start = c2;
  587. //--unused-- }
  588. //--unused-- }
  589. //--unused--
  590. //--unused-- }
  591. //--unused-- if (mode==0) {
  592. //--unused-- // send how many the same
  593. //--unused-- c3[n++] = same;
  594. //--unused-- } else {
  595. //--unused-- // send how many diff ones.
  596. //--unused-- c3[n++]=diff;
  597. //--unused-- // send all the diff ones.
  598. //--unused-- for (j=0; j<diff; j++)
  599. //--unused-- c3[n++] = diff_start[j];
  600. //--unused-- }
  601. //--unused--
  602. //--unused-- return n*2;
  603. //--unused-- }
  604. //--unused-- //Applies diff_buffer to block1 to create a new block1. Returns the final
  605. //--unused-- //size of block1.
  606. //--unused-- int netmisc_apply_diff(void *block1, void *diff_buffer, int diff_size)
  607. //--unused-- {
  608. //--unused-- unsigned int i, j, n, size;
  609. //--unused-- ushort *c1, *c2;
  610. //--unused--
  611. //--unused-- c1 = (ushort *)diff_buffer;
  612. //--unused-- c2 = (ushort *)block1;
  613. //--unused--
  614. //--unused-- size = diff_size/2;
  615. //--unused--
  616. //--unused-- i=j=0;
  617. //--unused-- while (1) {
  618. //--unused-- j += c1[i]; // Same
  619. //--unused-- i++;
  620. //--unused-- if (i>=size) break;
  621. //--unused-- n = c1[i]; // ndiff
  622. //--unused-- i++;
  623. //--unused-- if (n>0) {
  624. //--unused-- //AsserT (n* < 256);
  625. //--unused-- memcpy(&c2[j], &c1[i], n*2);
  626. //--unused-- i += n;
  627. //--unused-- j += n;
  628. //--unused-- }
  629. //--unused-- if (i>=size) break;
  630. //--unused-- }
  631. //--unused-- return j*2;
  632. //--unused-- }