PageRenderTime 65ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/v1.14.94/network/netmisc-new.cpp

https://github.com/simX/d2x-xl
C++ | 585 lines | 466 code | 76 blank | 43 comment | 53 complexity | d41c9e4f1c57af510cb0fee3df179db2 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. #ifdef HAVE_CONFIG_H
  15. #include <conf.h>
  16. #endif
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include "descent.h"
  20. #include "pstypes.h"
  21. #include "mono.h"
  22. #include "byteswap.h"
  23. #if defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__)
  24. #include "segment.h"
  25. #include "gameseg.h"
  26. #include "network.h"
  27. #include "network_lib.h"
  28. #include "wall.h"
  29. #include "ipx.h"
  30. #include "multi.h"
  31. #include "object.h"
  32. #include "powerup.h"
  33. #include "netmisc.h"
  34. #include "error.h"
  35. #endif
  36. //------------------------------------------------------------------------------
  37. // routine to calculate the checksum of the segments. We add these specialized routines
  38. // since the current way is byte order dependent.
  39. ubyte* CalcCheckSum (ubyte* bufP, int len, uint& sum1, uint& sum2)
  40. {
  41. while(len--) {
  42. sum1 += *bufP++;
  43. if (sum1 >= 255)
  44. sum1 -= 255;
  45. sum2 += sum1;
  46. }
  47. return bufP;
  48. }
  49. //------------------------------------------------------------------------------
  50. #if defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__)
  51. static ubyte nmDataBuf [MAX_PACKETSIZE]; // used for tmp netgame packets as well as sending CObject data
  52. static ubyte *nmBufP = NULL;
  53. // if using the following macros in loops, the loop's body *must* be enclosed in curly braces,
  54. // or the macros won't work as intended, as the buffer pointer nmBufI will only be incremented
  55. // after the loop has been fully executed!
  56. #define BE_SET_INT(_src) *(reinterpret_cast<int*> (nmBufP + nmBufI)) = INTEL_INT ((int) (_src)); nmBufI += 4
  57. #define BE_SET_SHORT(_src) *(reinterpret_cast<short*> (nmBufP + nmBufI)) = INTEL_SHORT ((short) (_src)); nmBufI += 2
  58. #define BE_SET_BYTE(_src) nmBufP [nmBufI++] = (ubyte) (_src)
  59. #define BE_SET_BYTES(_src,_srcSize) memcpy (nmBufP + nmBufI, _src, _srcSize); nmBufI += (_srcSize)
  60. #define BE_GET_INT(_dest) (_dest) = INTEL_INT (*(reinterpret_cast<int*> (nmBufP + nmBufI))); nmBufI += 4
  61. #define BE_GET_SHORT(_dest) (_dest) = INTEL_SHORT (*(reinterpret_cast<short*> (nmBufP + nmBufI))); nmBufI += 2
  62. #define BE_GET_BYTE(_dest) (_dest) = nmBufP [nmBufI++]
  63. #define BE_GET_BYTES(_dest,_destSize) memcpy (_dest, nmBufP + nmBufI, _destSize); nmBufI += (_destSize)
  64. //------------------------------------------------------------------------------
  65. // following are routine for big endian hardware that will swap the elements of
  66. // structures send through the networking code. The structures and
  67. // this code must be kept in total sync
  68. void BEReceiveNetPlayerInfo (ubyte *data, tNetPlayerInfo *info)
  69. {
  70. int nmBufI = 0;
  71. nmBufP = data;
  72. BE_GET_BYTES (info->callsign, CALLSIGN_LEN + 1);
  73. BE_GET_BYTES (info->network.ipx.server, 4);
  74. BE_GET_BYTES (info->network.ipx.node, 6);
  75. BE_GET_BYTE (info->versionMajor);
  76. BE_GET_BYTE (info->versionMinor);
  77. BE_GET_BYTE (info->computerType);
  78. BE_GET_BYTE (info->connected);
  79. //BE_GET_SHORT (info->socket);
  80. info->socket = *(reinterpret_cast<short*> (data + nmBufI)); //don't swap!
  81. nmBufI += 2;
  82. BE_GET_BYTE (info->rank);
  83. }
  84. //------------------------------------------------------------------------------
  85. void BESendNetPlayersPacket (ubyte *server, ubyte *node)
  86. {
  87. int i;
  88. int nmBufI = 0;
  89. nmBufP = nmDataBuf;
  90. #if DBG
  91. memset (nmBufP, 0, IPX_DATALIMIT); //this takes time and shouldn't be necessary
  92. #endif
  93. BE_SET_BYTE (netPlayers.nType);
  94. BE_SET_INT (netPlayers.nSecurity);
  95. for (i = 0; i < MAX_PLAYERS + 4; i++) {
  96. BE_SET_BYTES (netPlayers.players [i].callsign, CALLSIGN_LEN + 1);
  97. BE_SET_BYTES (netPlayers.players [i].network.ipx.server, 4);
  98. BE_SET_BYTES (netPlayers.players [i].network.ipx.node, 6);
  99. BE_SET_BYTE (netPlayers.players [i].versionMajor);
  100. BE_SET_BYTE (netPlayers.players [i].versionMinor);
  101. BE_SET_BYTE (netPlayers.players [i].computerType);
  102. BE_SET_BYTE (netPlayers.players [i].connected);
  103. BE_SET_SHORT (netPlayers.players [i].socket);
  104. BE_SET_BYTE (netPlayers.players [i].rank);
  105. }
  106. if (!server && !node)
  107. IPXSendBroadcastData (nmBufP, nmBufI);
  108. else
  109. IPXSendInternetPacketData (nmBufP, nmBufI, server, node);
  110. }
  111. //------------------------------------------------------------------------------
  112. void BEReceiveNetPlayersPacket (ubyte *data, tAllNetPlayersInfo *pinfo)
  113. {
  114. int i, nmBufI = 0;
  115. nmBufP = data;
  116. BE_GET_BYTE (pinfo->nType);
  117. BE_GET_INT (pinfo->nSecurity);
  118. for (i = 0; i < MAX_PLAYERS + 4; i++)
  119. BEReceiveNetPlayerInfo (nmBufP, pinfo->players + i);
  120. }
  121. //------------------------------------------------------------------------------
  122. void BESendSequencePacket (tSequencePacket seq, ubyte *server, ubyte *node, ubyte *netAddress)
  123. {
  124. int nmBufI = 0;
  125. nmBufP = nmDataBuf;
  126. #if DBG
  127. memset (nmBufP, 0, IPX_DATALIMIT); //this takes time and shouldn't be necessary
  128. #endif
  129. BE_SET_BYTE (seq.nType);
  130. BE_SET_INT (seq.nSecurity);
  131. BE_SET_BYTES (seq.player.callsign, CALLSIGN_LEN + 1);
  132. BE_SET_BYTES (seq.player.network.ipx.server, 4);
  133. BE_SET_BYTES (seq.player.network.ipx.node, 6);
  134. BE_SET_BYTE (seq.player.versionMajor);
  135. BE_SET_BYTE (seq.player.versionMinor);
  136. BE_SET_BYTE (seq.player.computerType);
  137. BE_SET_BYTE (seq.player.connected);
  138. BE_SET_SHORT (seq.player.socket);
  139. BE_SET_BYTE (seq.player.rank);
  140. if (netAddress)
  141. IPXSendPacketData (nmBufP, nmBufI, server, node, netAddress);
  142. else if (!server && !node)
  143. IPXSendBroadcastData (nmBufP, nmBufI);
  144. else
  145. IPXSendInternetPacketData (nmBufP, nmBufI, server, node);
  146. }
  147. //------------------------------------------------------------------------------
  148. void BEReceiveSequencePacket (ubyte *data, tSequencePacket *seq)
  149. {
  150. int nmBufI = 0;
  151. nmBufP = data;
  152. BE_GET_BYTE (seq->nType);
  153. BE_GET_INT (seq->nSecurity);
  154. BEReceiveNetPlayerInfo (data + nmBufI + 3, &(seq->player)); // +3 for pad bytes
  155. }
  156. //------------------------------------------------------------------------------
  157. void BESendNetGamePacket (ubyte *server, ubyte *node, ubyte *netAddress, int bLiteData)
  158. {
  159. int i;
  160. short h;
  161. int nmBufI = 0;
  162. nmBufP = nmDataBuf;
  163. #if DBG
  164. memset (nmBufP, 0, MAX_PACKETSIZE); //this takes time and shouldn't be necessary
  165. #endif
  166. BE_SET_BYTE (netGame.nType);
  167. BE_SET_INT (netGame.nSecurity);
  168. BE_SET_BYTES (netGame.szGameName, NETGAME_NAME_LEN + 1);
  169. BE_SET_BYTES (netGame.szMissionTitle, MISSION_NAME_LEN + 1);
  170. BE_SET_BYTES (netGame.szMissionName, 9);
  171. BE_SET_INT (netGame.nLevel);
  172. BE_SET_BYTE (netGame.gameMode);
  173. BE_SET_BYTE (netGame.bRefusePlayers);
  174. BE_SET_BYTE (netGame.difficulty);
  175. BE_SET_BYTE (netGame.gameStatus);
  176. BE_SET_BYTE (netGame.nNumPlayers);
  177. BE_SET_BYTE (netGame.nMaxPlayers);
  178. BE_SET_BYTE (netGame.nConnected);
  179. BE_SET_BYTE (netGame.gameFlags);
  180. BE_SET_BYTE (netGame.protocolVersion);
  181. BE_SET_BYTE (netGame.versionMajor);
  182. BE_SET_BYTE (netGame.versionMinor);
  183. BE_SET_BYTE (netGame.teamVector);
  184. if (bLiteData)
  185. goto do_send;
  186. h = *(reinterpret_cast<ushort*> (&netGame.teamVector + 1));
  187. BE_SET_SHORT (h); // get the values for the first short bitfield
  188. h = *(reinterpret_cast<ushort*> (&netGame.teamVector + 3));
  189. BE_SET_SHORT (h); // get the values for the first short bitfield
  190. BE_SET_BYTES (netGame.szTeamName, 2 * (CALLSIGN_LEN + 1));
  191. for (i = 0; i < MAX_PLAYERS; i++) {
  192. BE_SET_INT (netGame.locations [i]);
  193. }
  194. int j;
  195. for (i = 0; i < MAX_PLAYERS; i++) {
  196. for (j = 0; j < MAX_PLAYERS; j++) {
  197. BE_SET_SHORT (netGame.kills [i][j]);
  198. }
  199. }
  200. BE_SET_SHORT (netGame.nSegmentCheckSum);
  201. BE_SET_SHORT (netGame.teamKills [0]);
  202. BE_SET_SHORT (netGame.teamKills [1]);
  203. for (i = 0; i < MAX_PLAYERS; i++) {
  204. BE_SET_SHORT (netGame.killed [i]);
  205. }
  206. for (i = 0; i < MAX_PLAYERS; i++) {
  207. BE_SET_SHORT (netGame.playerKills [i]);
  208. }
  209. BE_SET_INT (netGame.KillGoal);
  210. BE_SET_INT (netGame.xPlayTimeAllowed);
  211. BE_SET_INT (netGame.xLevelTime);
  212. BE_SET_INT (netGame.controlInvulTime);
  213. BE_SET_INT (netGame.monitorVector);
  214. for (i = 0; i < MAX_PLAYERS; i++) {
  215. BE_SET_INT (netGame.playerScore[i]);
  216. }
  217. BE_SET_BYTES (netGame.playerFlags, MAX_PLAYERS);
  218. BE_SET_SHORT (PacketsPerSec ());
  219. BE_SET_BYTE (netGame.bShortPackets);
  220. do_send:
  221. if (netAddress)
  222. IPXSendPacketData(nmBufP, nmBufI, server, node, netAddress);
  223. else if (!server && !node)
  224. IPXSendBroadcastData(nmBufP, nmBufI);
  225. else
  226. IPXSendInternetPacketData(nmBufP, nmBufI, server, node);
  227. }
  228. //------------------------------------------------------------------------------
  229. void BEReceiveNetGamePacket (ubyte *data, tNetgameInfo *netgame, int bLiteData)
  230. {
  231. int i;
  232. short *ps;
  233. int nmBufI = 0;
  234. nmBufP = data;
  235. BE_GET_BYTE (netgame->nType);
  236. BE_GET_INT (netgame->nSecurity);
  237. BE_GET_BYTES (netgame->szGameName, NETGAME_NAME_LEN + 1);
  238. BE_GET_BYTES (netgame->szMissionTitle, MISSION_NAME_LEN + 1);
  239. BE_GET_BYTES (netgame->szMissionName, 9);
  240. BE_GET_INT (netgame->nLevel);
  241. BE_GET_BYTE (netgame->gameMode);
  242. BE_GET_BYTE (netgame->bRefusePlayers);
  243. BE_GET_BYTE (netgame->difficulty);
  244. BE_GET_BYTE (netgame->gameStatus);
  245. BE_GET_BYTE (netgame->nNumPlayers);
  246. BE_GET_BYTE (netgame->nMaxPlayers);
  247. BE_GET_BYTE (netgame->nConnected);
  248. BE_GET_BYTE (netgame->gameFlags);
  249. BE_GET_BYTE (netgame->protocolVersion);
  250. BE_GET_BYTE (netgame->versionMajor);
  251. BE_GET_BYTE (netgame->versionMinor);
  252. BE_GET_BYTE (netgame->teamVector);
  253. if (bLiteData)
  254. return;
  255. BE_GET_SHORT (*reinterpret_cast<short*> ((reinterpret_cast<ubyte*> (&netgame->teamVector) + 1)));
  256. BE_GET_SHORT (*reinterpret_cast<short*> ((reinterpret_cast<ubyte*> (&netgame->teamVector) + 3)));
  257. BE_GET_BYTES (netgame->szTeamName, CALLSIGN_LEN + 1);
  258. for (i = 0; i < MAX_PLAYERS; i++) {
  259. BE_GET_INT (netgame->locations [i]);
  260. }
  261. #if 1
  262. for (i = MAX_PLAYERS * MAX_PLAYERS, ps = &netgame->kills [0][0]; i; i--, ps++) {
  263. BE_GET_SHORT (*ps);
  264. }
  265. #else
  266. {
  267. int j;
  268. for (i = 0; i < MAX_PLAYERS; i++)
  269. for (j = 0; j < MAX_PLAYERS; j++) {
  270. BE_GET_SHORT (netgame->kills [i][j]);
  271. }
  272. }
  273. #endif
  274. BE_GET_SHORT (netgame->nSegmentCheckSum);
  275. BE_GET_SHORT (netgame->teamKills [0]);
  276. BE_GET_SHORT (netgame->teamKills [1]);
  277. for (i = 0; i < MAX_PLAYERS; i++) {
  278. BE_GET_SHORT (netgame->killed [i]);
  279. }
  280. for (i = 0; i < MAX_PLAYERS; i++) {
  281. BE_GET_SHORT (netgame->playerKills [i]);
  282. }
  283. BE_GET_INT (netgame->KillGoal);
  284. BE_GET_INT (netgame->xPlayTimeAllowed);
  285. BE_GET_INT (netgame->xLevelTime);
  286. BE_GET_INT (netgame->controlInvulTime);
  287. BE_GET_INT (netgame->monitorVector);
  288. for (i = 0; i < MAX_PLAYERS; i++) {
  289. BE_GET_INT (netgame->playerScore [i]);
  290. }
  291. BE_GET_BYTES (netgame->playerFlags, MAX_PLAYERS);
  292. BE_GET_SHORT (netgame->nPacketsPerSec);
  293. BE_GET_BYTE (netgame->bShortPackets);
  294. }
  295. //------------------------------------------------------------------------------
  296. #define EGI_INTEL_SHORT_2BUF(_m) \
  297. *(reinterpret_cast<short*> (nmBufP) + (reinterpret_cast<char*> (&extraGameInfo [1]._m) - reinterpret_cast<char*> (&extraGameInfo [1]))) = INTEL_SHORT (extraGameInfo [1]._m);
  298. #define EGI_INTEL_INT_2BUF(_m) \
  299. *(reinterpret_cast<int*> (nmBufP) + (reinterpret_cast<char*> (&extraGameInfo [1]._m) - reinterpret_cast<char*> (&extraGameInfo [1]))) = INTEL_INT (extraGameInfo [1]._m);
  300. #define BUF2_EGI_INTEL_SHORT(_m) \
  301. extraGameInfo [1]._m = INTEL_SHORT (*reinterpret_cast<short*> (nmBufP + (reinterpret_cast<char*> (&extraGameInfo [1]._m) - reinterpret_cast<char*> (&extraGameInfo [1]))));
  302. #define BUF2_EGI_INTEL_INT(_m) \
  303. extraGameInfo [1]._m = INTEL_INT (*reinterpret_cast<int*> (nmBufP + (reinterpret_cast<char*> (&extraGameInfo [1]._m) - reinterpret_cast<char*> (&extraGameInfo [1]))));
  304. //------------------------------------------------------------------------------
  305. void BESendExtraGameInfo (ubyte *server, ubyte *node, ubyte *netAddress)
  306. {
  307. nmBufP = nmDataBuf;
  308. memcpy (nmBufP, &extraGameInfo [1], sizeof (extraGameInfo [0]));
  309. EGI_INTEL_SHORT_2BUF (entropy.nMaxVirusCapacity);
  310. EGI_INTEL_SHORT_2BUF (entropy.nEnergyFillRate);
  311. EGI_INTEL_SHORT_2BUF (entropy.nShieldFillRate);
  312. EGI_INTEL_SHORT_2BUF (entropy.nShieldDamageRate);
  313. EGI_INTEL_INT_2BUF (nSpawnDelay);
  314. if (netAddress)
  315. IPXSendPacketData (nmBufP, sizeof (extraGameInfo [0]), server, node, netAddress);
  316. else if (!server && !node)
  317. IPXSendBroadcastData (nmBufP, sizeof (extraGameInfo [0]));
  318. else
  319. IPXSendInternetPacketData (nmBufP, sizeof (extraGameInfo [0]), server, node);
  320. }
  321. //------------------------------------------------------------------------------
  322. void BEReceiveExtraGameInfo (ubyte *data, tExtraGameInfo *extraGameInfo)
  323. {
  324. nmBufP = data;
  325. memcpy (&extraGameInfo [1], nmBufP, sizeof (extraGameInfo [0]));
  326. BUF2_EGI_INTEL_SHORT (entropy.nMaxVirusCapacity);
  327. BUF2_EGI_INTEL_SHORT (entropy.nEnergyFillRate);
  328. BUF2_EGI_INTEL_SHORT (entropy.nShieldFillRate);
  329. BUF2_EGI_INTEL_SHORT (entropy.nShieldDamageRate);
  330. BUF2_EGI_INTEL_INT (nSpawnDelay);
  331. }
  332. //------------------------------------------------------------------------------
  333. void BESendMissingObjFrames(ubyte *server, ubyte *node, ubyte *netAddress)
  334. {
  335. int i;
  336. memcpy (nmDataBuf, &networkData.sync [0].objs.missingFrames, sizeof (networkData.sync [0].objs.missingFrames));
  337. reinterpret_cast<tMissingObjFrames*> (&nmDataBuf [0])->nFrame = INTEL_SHORT (networkData.sync [0].objs.missingFrames.nFrame);
  338. i = 2 * sizeof (ubyte) + sizeof (ushort);
  339. if (netAddress != NULL)
  340. IPXSendPacketData(nmDataBuf, i, server, node, netAddress);
  341. else if ((server == NULL) && (node == NULL))
  342. IPXSendBroadcastData(nmDataBuf, i);
  343. else
  344. IPXSendInternetPacketData(nmDataBuf, i, server, node);
  345. }
  346. //------------------------------------------------------------------------------
  347. void BEReceiveMissingObjFrames(ubyte *data, tMissingObjFrames *missingObjFrames)
  348. {
  349. memcpy (missingObjFrames, nmDataBuf, sizeof (tMissingObjFrames));
  350. missingObjFrames->nFrame = INTEL_SHORT (missingObjFrames->nFrame);
  351. }
  352. //------------------------------------------------------------------------------
  353. void BESwapObject (CObject *objP)
  354. {
  355. // swap the short and int entries for this CObject
  356. objP->info.nSignature = INTEL_INT (objP->info.nSignature);
  357. objP->info.nNextInSeg = INTEL_SHORT (objP->info.nNextInSeg);
  358. objP->info.nPrevInSeg = INTEL_SHORT (objP->info.nPrevInSeg);
  359. objP->info.nSegment = INTEL_SHORT (objP->info.nSegment);
  360. INTEL_VECTOR (objP->info.position.vPos);
  361. INTEL_MATRIX (objP->info.position.mOrient);
  362. objP->info.xSize = INTEL_INT (objP->info.xSize);
  363. objP->info.xShields = INTEL_INT (objP->info.xShields);
  364. INTEL_VECTOR (objP->info.vLastPos);
  365. objP->info.xLifeLeft = INTEL_INT (objP->info.xLifeLeft);
  366. switch (objP->info.movementType) {
  367. case MT_PHYSICS:
  368. INTEL_VECTOR (objP->mType.physInfo.velocity);
  369. INTEL_VECTOR (objP->mType.physInfo.thrust);
  370. objP->mType.physInfo.mass = INTEL_INT (objP->mType.physInfo.mass);
  371. objP->mType.physInfo.drag = INTEL_INT (objP->mType.physInfo.drag);
  372. objP->mType.physInfo.brakes = INTEL_INT (objP->mType.physInfo.brakes);
  373. INTEL_VECTOR (objP->mType.physInfo.rotVel);
  374. INTEL_VECTOR (objP->mType.physInfo.rotThrust);
  375. objP->mType.physInfo.turnRoll = INTEL_INT (objP->mType.physInfo.turnRoll);
  376. objP->mType.physInfo.flags = INTEL_SHORT (objP->mType.physInfo.flags);
  377. break;
  378. case MT_SPINNING:
  379. INTEL_VECTOR (objP->mType.spinRate);
  380. break;
  381. }
  382. switch (objP->info.controlType) {
  383. case CT_WEAPON:
  384. objP->cType.laserInfo.parent.nType = INTEL_SHORT (objP->cType.laserInfo.parent.nType);
  385. objP->cType.laserInfo.parent.nObject = INTEL_SHORT (objP->cType.laserInfo.parent.nObject);
  386. objP->cType.laserInfo.parent.nSignature = INTEL_INT (objP->cType.laserInfo.parent.nSignature);
  387. objP->cType.laserInfo.xCreationTime = INTEL_INT (objP->cType.laserInfo.xCreationTime);
  388. objP->cType.laserInfo.nLastHitObj = INTEL_SHORT (objP->cType.laserInfo.nLastHitObj);
  389. if (objP->cType.laserInfo.nLastHitObj < 0)
  390. objP->cType.laserInfo.nLastHitObj = 0;
  391. else {
  392. gameData.objs.nHitObjects [OBJ_IDX (objP) * MAX_HIT_OBJECTS] = objP->cType.laserInfo.nLastHitObj;
  393. objP->cType.laserInfo.nLastHitObj = 1;
  394. }
  395. objP->cType.laserInfo.nHomingTarget = INTEL_SHORT (objP->cType.laserInfo.nHomingTarget);
  396. objP->cType.laserInfo.xScale = INTEL_INT (objP->cType.laserInfo.xScale);
  397. break;
  398. case CT_EXPLOSION:
  399. objP->cType.explInfo.nSpawnTime = INTEL_INT (objP->cType.explInfo.nSpawnTime);
  400. objP->cType.explInfo.nDeleteTime = INTEL_INT (objP->cType.explInfo.nDeleteTime);
  401. objP->cType.explInfo.nDeleteObj = INTEL_SHORT (objP->cType.explInfo.nDeleteObj);
  402. objP->cType.explInfo.attached.nParent = INTEL_SHORT (objP->cType.explInfo.attached.nParent);
  403. objP->cType.explInfo.attached.nPrev = INTEL_SHORT (objP->cType.explInfo.attached.nPrev);
  404. objP->cType.explInfo.attached.nNext = INTEL_SHORT (objP->cType.explInfo.attached.nNext);
  405. break;
  406. case CT_AI:
  407. objP->cType.aiInfo.nHideSegment = INTEL_SHORT (objP->cType.aiInfo.nHideSegment);
  408. objP->cType.aiInfo.nHideIndex = INTEL_SHORT (objP->cType.aiInfo.nHideIndex);
  409. objP->cType.aiInfo.nPathLength = INTEL_SHORT (objP->cType.aiInfo.nPathLength);
  410. objP->cType.aiInfo.nDangerLaser = INTEL_SHORT (objP->cType.aiInfo.nDangerLaser);
  411. objP->cType.aiInfo.nDangerLaserSig = INTEL_INT (objP->cType.aiInfo.nDangerLaserSig);
  412. objP->cType.aiInfo.xDyingStartTime = INTEL_INT (objP->cType.aiInfo.xDyingStartTime);
  413. break;
  414. case CT_LIGHT:
  415. objP->cType.lightInfo.intensity = INTEL_INT (objP->cType.lightInfo.intensity);
  416. break;
  417. case CT_POWERUP:
  418. objP->cType.powerupInfo.nCount = INTEL_INT (objP->cType.powerupInfo.nCount);
  419. objP->cType.powerupInfo.xCreationTime = INTEL_INT (objP->cType.powerupInfo.xCreationTime);
  420. break;
  421. }
  422. switch (objP->info.renderType) {
  423. case RT_MORPH:
  424. case RT_POLYOBJ: {
  425. int i;
  426. objP->rType.polyObjInfo.nModel = INTEL_INT (objP->rType.polyObjInfo.nModel);
  427. for (i = 0; i < MAX_SUBMODELS; i++)
  428. INTEL_ANGVEC (objP->rType.polyObjInfo.animAngles [i]);
  429. objP->rType.polyObjInfo.nSubObjFlags = INTEL_INT (objP->rType.polyObjInfo.nSubObjFlags);
  430. objP->rType.polyObjInfo.nTexOverride = INTEL_INT (objP->rType.polyObjInfo.nTexOverride);
  431. objP->rType.polyObjInfo.nAltTextures = INTEL_INT (objP->rType.polyObjInfo.nAltTextures);
  432. break;
  433. }
  434. case RT_WEAPON_VCLIP:
  435. case RT_HOSTAGE:
  436. case RT_POWERUP:
  437. case RT_FIREBALL:
  438. case RT_THRUSTER:
  439. objP->rType.vClipInfo.nClipIndex = INTEL_INT (objP->rType.vClipInfo.nClipIndex);
  440. objP->rType.vClipInfo.xFrameTime = INTEL_INT (objP->rType.vClipInfo.xFrameTime);
  441. break;
  442. case RT_LASER:
  443. break;
  444. }
  445. }
  446. #endif /* WORDS_BIGENDIAN */
  447. //------------------------------------------------------------------------------
  448. void CSide::CheckSum (uint& sum1, uint& sum2)
  449. {
  450. int i, h;
  451. short s;
  452. CalcCheckSum (reinterpret_cast<ubyte*> (&m_nType), 1, sum1, sum2);
  453. CalcCheckSum (reinterpret_cast<ubyte*> (&m_nFrame), 1, sum1, sum2);
  454. s = INTEL_SHORT (m_nWall);
  455. CalcCheckSum (reinterpret_cast<ubyte*> (&s), 2, sum1, sum2);
  456. s = INTEL_SHORT (m_nBaseTex);
  457. CalcCheckSum (reinterpret_cast<ubyte*> (&s), 2, sum1, sum2);
  458. s = INTEL_SHORT ((m_nOvlOrient << 14) + m_nOvlTex);
  459. CalcCheckSum (reinterpret_cast<ubyte*> (&s), 2, sum1, sum2);
  460. for (i = 0; i < 4; i++) {
  461. h = INTEL_INT (int (m_uvls [i].u));
  462. CalcCheckSum (reinterpret_cast<ubyte*> (&h), 4, sum1, sum2);
  463. h = INTEL_INT (int (m_uvls [i].v));
  464. CalcCheckSum (reinterpret_cast<ubyte*> (&h), 4, sum1, sum2);
  465. h = INTEL_INT (int (m_uvls [i].l));
  466. CalcCheckSum (reinterpret_cast<ubyte*> (&h), 4, sum1, sum2);
  467. }
  468. for (i = 0; i < 2; i++) {
  469. h = INTEL_INT (int (m_normals [i][X]));
  470. CalcCheckSum (reinterpret_cast<ubyte*> (&h), 4, sum1, sum2);
  471. h = INTEL_INT (int (m_normals [i][Y]));
  472. CalcCheckSum (reinterpret_cast<ubyte*> (&h), 4, sum1, sum2);
  473. h = INTEL_INT (int (m_normals [i][Z]));
  474. CalcCheckSum (reinterpret_cast<ubyte*> (&h), 4, sum1, sum2);
  475. }
  476. }
  477. //------------------------------------------------------------------------------
  478. void CSegment::CheckSum (uint& sum1, uint& sum2)
  479. {
  480. int i;
  481. short j;
  482. uint s1, s2;
  483. for (i = 0; i < 6; i++) {
  484. m_sides [i].CheckSum (sum1, sum2);
  485. s1 = sum1;
  486. s2 = sum2;
  487. }
  488. for (i = 0; i < MAX_SIDES_PER_SEGMENT; i++) {
  489. j = INTEL_SHORT (m_children [i]);
  490. CalcCheckSum (reinterpret_cast<ubyte*> (&j), 2, sum1, sum2);
  491. }
  492. for (i = 0; i < MAX_VERTICES_PER_SEGMENT; i++) {
  493. j = INTEL_SHORT (m_verts [i]);
  494. CalcCheckSum (reinterpret_cast<ubyte*> (&j), 2, sum1, sum2);
  495. }
  496. i = INTEL_INT (m_objects);
  497. CalcCheckSum (reinterpret_cast<ubyte*> (&i), 4, sum1, sum2);
  498. }
  499. //------------------------------------------------------------------------------
  500. ushort CalcSegmentCheckSum (void)
  501. {
  502. uint sum1, sum2;
  503. sum1 = sum2 = 0;
  504. for (int i = 0; i < gameData.segs.nSegments; i++)
  505. SEGMENTS [i].CheckSum (sum1, sum2);
  506. return sum1 * 256 + sum2 % 255;
  507. }
  508. //------------------------------------------------------------------------------
  509. //eof