Xfer.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: Xfer.cpp /////////////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, February 2002
  25. // Desc: The Xfer system is capable of setting up operations to work with blocks of data
  26. // from other subsystems. It can work things such as file reading, file writing,
  27. // CRC computations etc
  28. ///////////////////////////////////////////////////////////////////////////////////////////////////
  29. // USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
  30. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  31. #include "Common/Upgrade.h"
  32. #include "Common/GameState.h"
  33. #include "Common/Xfer.h"
  34. #include "Common/BitFlagsIO.h"
  35. //-------------------------------------------------------------------------------------------------
  36. //-------------------------------------------------------------------------------------------------
  37. Xfer::Xfer( void )
  38. {
  39. m_options = XO_NONE;
  40. m_xferMode = XFER_INVALID;
  41. } // end Xfer
  42. //-------------------------------------------------------------------------------------------------
  43. //-------------------------------------------------------------------------------------------------
  44. Xfer::~Xfer( void )
  45. {
  46. } // end ~Xfer
  47. // ------------------------------------------------------------------------------------------------
  48. /** Open */
  49. // ------------------------------------------------------------------------------------------------
  50. void Xfer::open( AsciiString identifier )
  51. {
  52. // save identifier
  53. m_identifier = identifier;
  54. } // end open
  55. // ------------------------------------------------------------------------------------------------
  56. // ------------------------------------------------------------------------------------------------
  57. void Xfer::xferByte( Byte *byteData )
  58. {
  59. xferImplementation( byteData, sizeof( Byte ) );
  60. } // end xferByte
  61. // ------------------------------------------------------------------------------------------------
  62. // ------------------------------------------------------------------------------------------------
  63. void Xfer::xferVersion( XferVersion *versionData, XferVersion currentVersion )
  64. {
  65. xferImplementation( versionData, sizeof( XferVersion ) );
  66. // sanity, after the xfer, version data is never allowed to be higher than the current version
  67. if( *versionData > currentVersion )
  68. {
  69. DEBUG_CRASH(( "XferVersion - Unknown version '%d' should be no higher than '%d'\n",
  70. *versionData, currentVersion ));
  71. throw XFER_INVALID_VERSION;
  72. } // end if
  73. } // end xferVersion
  74. // ------------------------------------------------------------------------------------------------
  75. // ------------------------------------------------------------------------------------------------
  76. void Xfer::xferUnsignedByte( UnsignedByte *unsignedByteData )
  77. {
  78. xferImplementation( unsignedByteData, sizeof( UnsignedByte ) );
  79. } // end xferUnsignedByte
  80. // ------------------------------------------------------------------------------------------------
  81. // ------------------------------------------------------------------------------------------------
  82. void Xfer::xferBool( Bool *boolData )
  83. {
  84. xferImplementation( boolData, sizeof( Bool ) );
  85. } // end xferBool
  86. // ------------------------------------------------------------------------------------------------
  87. // ------------------------------------------------------------------------------------------------
  88. void Xfer::xferInt( Int *intData )
  89. {
  90. xferImplementation( intData, sizeof( Int ) );
  91. } // end xferInt
  92. // ------------------------------------------------------------------------------------------------
  93. // ------------------------------------------------------------------------------------------------
  94. void Xfer::xferInt64( Int64 *int64Data )
  95. {
  96. xferImplementation( int64Data, sizeof( Int64 ) );
  97. } // end xferInt64
  98. // ------------------------------------------------------------------------------------------------
  99. // ------------------------------------------------------------------------------------------------
  100. void Xfer::xferUnsignedInt( UnsignedInt *unsignedIntData )
  101. {
  102. xferImplementation( unsignedIntData, sizeof( UnsignedInt ) );
  103. } // end xferUnsignedInt
  104. // ------------------------------------------------------------------------------------------------
  105. // ------------------------------------------------------------------------------------------------
  106. void Xfer::xferShort( Short *shortData )
  107. {
  108. xferImplementation( shortData, sizeof( Short ) );
  109. } // end xferShort
  110. // ------------------------------------------------------------------------------------------------
  111. // ------------------------------------------------------------------------------------------------
  112. void Xfer::xferUnsignedShort( UnsignedShort *unsignedShortData )
  113. {
  114. xferImplementation( unsignedShortData, sizeof( UnsignedShort ) );
  115. } // end xferUnsignedShort
  116. // ------------------------------------------------------------------------------------------------
  117. // ------------------------------------------------------------------------------------------------
  118. void Xfer::xferReal( Real *realData )
  119. {
  120. xferImplementation( realData, sizeof( Real ) );
  121. } // end xferReal
  122. // ------------------------------------------------------------------------------------------------
  123. // ------------------------------------------------------------------------------------------------
  124. void Xfer::xferMapName( AsciiString *mapNameData )
  125. {
  126. if (getXferMode() == XFER_SAVE)
  127. {
  128. AsciiString tmp = TheGameState->realMapPathToPortableMapPath(*mapNameData);
  129. xferAsciiString(&tmp);
  130. }
  131. else if (getXferMode() == XFER_LOAD)
  132. {
  133. xferAsciiString(mapNameData);
  134. *mapNameData = TheGameState->portableMapPathToRealMapPath(*mapNameData);
  135. }
  136. } // end xferAsciiString
  137. // ------------------------------------------------------------------------------------------------
  138. // ------------------------------------------------------------------------------------------------
  139. void Xfer::xferAsciiString( AsciiString *asciiStringData )
  140. {
  141. xferImplementation( (void *)asciiStringData->str(), sizeof( Byte ) * asciiStringData->getLength() );
  142. } // end xferAsciiString
  143. // ------------------------------------------------------------------------------------------------
  144. // ------------------------------------------------------------------------------------------------
  145. void Xfer::xferMarkerLabel( AsciiString asciiStringData )
  146. {
  147. } // end xferMarkerLabel
  148. // ------------------------------------------------------------------------------------------------
  149. // ------------------------------------------------------------------------------------------------
  150. void Xfer::xferUnicodeString( UnicodeString *unicodeStringData )
  151. {
  152. xferImplementation( (void *)unicodeStringData->str(), sizeof( WideChar ) * unicodeStringData->getLength() );
  153. } // end xferUnicodeString
  154. // ------------------------------------------------------------------------------------------------
  155. // ------------------------------------------------------------------------------------------------
  156. void Xfer::xferCoord3D( Coord3D *coord3D )
  157. {
  158. xferReal( &coord3D->x );
  159. xferReal( &coord3D->y );
  160. xferReal( &coord3D->z );
  161. } // end xferCoord3D
  162. // ------------------------------------------------------------------------------------------------
  163. // ------------------------------------------------------------------------------------------------
  164. void Xfer::xferICoord3D( ICoord3D *iCoord3D )
  165. {
  166. xferInt( &iCoord3D->x );
  167. xferInt( &iCoord3D->y );
  168. xferInt( &iCoord3D->z );
  169. } // end xferICoor3D
  170. // ------------------------------------------------------------------------------------------------
  171. // ------------------------------------------------------------------------------------------------
  172. void Xfer::xferRegion3D( Region3D *region3D )
  173. {
  174. xferCoord3D( &region3D->lo );
  175. xferCoord3D( &region3D->hi );
  176. } // end xferRegion3D
  177. // ------------------------------------------------------------------------------------------------
  178. // ------------------------------------------------------------------------------------------------
  179. void Xfer::xferIRegion3D( IRegion3D *iRegion3D )
  180. {
  181. xferICoord3D( &iRegion3D->lo );
  182. xferICoord3D( &iRegion3D->hi );
  183. } // end xferIRegion3D
  184. // ------------------------------------------------------------------------------------------------
  185. // ------------------------------------------------------------------------------------------------
  186. void Xfer::xferCoord2D( Coord2D *coord2D )
  187. {
  188. xferReal( &coord2D->x );
  189. xferReal( &coord2D->y );
  190. } // end xferCoord2D
  191. // ------------------------------------------------------------------------------------------------
  192. // ------------------------------------------------------------------------------------------------
  193. void Xfer::xferICoord2D( ICoord2D *iCoord2D )
  194. {
  195. xferInt( &iCoord2D->x );
  196. xferInt( &iCoord2D->y );
  197. } // end xferICoord2D
  198. // ------------------------------------------------------------------------------------------------
  199. // ------------------------------------------------------------------------------------------------
  200. void Xfer::xferRegion2D( Region2D *region2D )
  201. {
  202. xferCoord2D( &region2D->lo );
  203. xferCoord2D( &region2D->hi );
  204. } // end xferRegion2D
  205. // ------------------------------------------------------------------------------------------------
  206. // ------------------------------------------------------------------------------------------------
  207. void Xfer::xferIRegion2D( IRegion2D *iRegion2D )
  208. {
  209. xferICoord2D( &iRegion2D->lo );
  210. xferICoord2D( &iRegion2D->hi );
  211. } // end xferIRegion2D
  212. // ------------------------------------------------------------------------------------------------
  213. // ------------------------------------------------------------------------------------------------
  214. void Xfer::xferRealRange( RealRange *realRange )
  215. {
  216. xferReal( &realRange->lo );
  217. xferReal( &realRange->hi );
  218. } // end xferRealRange
  219. // ------------------------------------------------------------------------------------------------
  220. // ------------------------------------------------------------------------------------------------
  221. void Xfer::xferColor( Color *color )
  222. {
  223. xferImplementation( color, sizeof( Color ) );
  224. } // end xferColor
  225. // ------------------------------------------------------------------------------------------------
  226. // ------------------------------------------------------------------------------------------------
  227. void Xfer::xferRGBColor( RGBColor *rgbColor )
  228. {
  229. xferReal( &rgbColor->red );
  230. xferReal( &rgbColor->green );
  231. xferReal( &rgbColor->blue );
  232. } // end xferRGBColor
  233. // ------------------------------------------------------------------------------------------------
  234. // ------------------------------------------------------------------------------------------------
  235. void Xfer::xferRGBAColorReal( RGBAColorReal *rgbaColorReal )
  236. {
  237. xferReal( &rgbaColorReal->red );
  238. xferReal( &rgbaColorReal->green );
  239. xferReal( &rgbaColorReal->blue );
  240. xferReal( &rgbaColorReal->alpha );
  241. } // end xferRGBAColorReal
  242. // ------------------------------------------------------------------------------------------------
  243. // ------------------------------------------------------------------------------------------------
  244. void Xfer::xferRGBAColorInt( RGBAColorInt *rgbaColorInt )
  245. {
  246. xferUnsignedInt( &rgbaColorInt->red );
  247. xferUnsignedInt( &rgbaColorInt->green );
  248. xferUnsignedInt( &rgbaColorInt->blue );
  249. xferUnsignedInt( &rgbaColorInt->alpha );
  250. } // end xferRGBAColorInt
  251. // ------------------------------------------------------------------------------------------------
  252. // ------------------------------------------------------------------------------------------------
  253. void Xfer::xferObjectID( ObjectID *objectID )
  254. {
  255. xferImplementation( objectID, sizeof( ObjectID ) );
  256. } // end xferObjeftID
  257. // ------------------------------------------------------------------------------------------------
  258. // ------------------------------------------------------------------------------------------------
  259. void Xfer::xferDrawableID( DrawableID *drawableID )
  260. {
  261. xferImplementation( drawableID, sizeof( DrawableID ) );
  262. } // end xferDrawableID
  263. // ------------------------------------------------------------------------------------------------
  264. /** STL Object ID list (cause it's a common data structure we use a lot)
  265. * Version Info;
  266. * 1: Initial version */
  267. // ------------------------------------------------------------------------------------------------
  268. void Xfer::xferSTLObjectIDList( std::list< ObjectID > *objectIDListData )
  269. {
  270. //
  271. // the fact that this is a list and a little higher level than a simple data type
  272. // is reason enough to have every one of these versioned
  273. //
  274. XferVersion currentVersion = 1;
  275. XferVersion version = currentVersion;
  276. xferVersion( &version, currentVersion );
  277. // xfer the count of the list
  278. UnsignedShort listCount = objectIDListData->size();
  279. xferUnsignedShort( &listCount );
  280. // xfer list data
  281. ObjectID objectID;
  282. if( getXferMode() == XFER_SAVE || getXferMode() == XFER_CRC )
  283. {
  284. // save all ids
  285. std::list< ObjectID >::const_iterator it;
  286. for( it = objectIDListData->begin(); it != objectIDListData->end(); ++it )
  287. {
  288. objectID = *it;
  289. xferObjectID( &objectID );
  290. } // end for
  291. } // end if, save
  292. else if( getXferMode() == XFER_LOAD )
  293. {
  294. // sanity, the list should be empty before we transfer more data into it
  295. if( objectIDListData->size() != 0 )
  296. {
  297. DEBUG_CRASH(( "Xfer::xferSTLObjectIDList - object list should be empty before loading\n" ));
  298. throw XFER_LIST_NOT_EMPTY;
  299. } // end if
  300. // read all ids
  301. for( UnsignedShort i = 0; i < listCount; ++i )
  302. {
  303. xferObjectID( &objectID );
  304. objectIDListData->push_back( objectID );
  305. } // end for, i
  306. } // end else if
  307. else
  308. {
  309. DEBUG_CRASH(( "xferSTLObjectIDList - Unknown xfer mode '%d'\n", getXferMode() ));
  310. throw XFER_MODE_UNKNOWN;
  311. } // end else
  312. } // end xferSTLObjectIDList
  313. // ------------------------------------------------------------------------------------------------
  314. // ------------------------------------------------------------------------------------------------
  315. void Xfer::xferSTLIntList( std::list< Int > *intListData )
  316. {
  317. // sanity
  318. if( intListData == NULL )
  319. return;
  320. // version
  321. XferVersion currentVersion = 1;
  322. XferVersion version = currentVersion;
  323. xferVersion( &version, currentVersion );
  324. // xfer the count of the list
  325. UnsignedShort listCount = intListData->size();
  326. xferUnsignedShort( &listCount );
  327. // xfer list data
  328. Int intData;
  329. if( getXferMode() == XFER_SAVE || getXferMode() == XFER_CRC )
  330. {
  331. // save all ids
  332. std::list< Int >::const_iterator it;
  333. for( it = intListData->begin(); it != intListData->end(); ++it )
  334. {
  335. intData = *it;
  336. xferInt( &intData );
  337. } // end for
  338. } // end if, save
  339. else if( getXferMode() == XFER_LOAD )
  340. {
  341. // sanity, the list should be empty before we transfer more data into it
  342. if( intListData->size() != 0 )
  343. {
  344. DEBUG_CRASH(( "Xfer::xferSTLIntList - int list should be empty before loading\n" ));
  345. throw XFER_LIST_NOT_EMPTY;
  346. } // end if
  347. // read all ids
  348. for( UnsignedShort i = 0; i < listCount; ++i )
  349. {
  350. xferInt( &intData );
  351. intListData->push_back( intData );
  352. } // end for, i
  353. } // end else if
  354. else
  355. {
  356. DEBUG_CRASH(( "xferSTLIntList - Unknown xfer mode '%d'\n", getXferMode() ));
  357. throw XFER_MODE_UNKNOWN;
  358. } // end else
  359. } // end xferSTLIntList
  360. // ------------------------------------------------------------------------------------------------
  361. // ------------------------------------------------------------------------------------------------
  362. void Xfer::xferScienceType( ScienceType *science )
  363. {
  364. // sanity
  365. DEBUG_ASSERTCRASH( science != NULL, ("xferScienceType - Invalid parameters\n") );
  366. AsciiString scienceName;
  367. if( getXferMode() == XFER_SAVE )
  368. {
  369. // translate to string
  370. scienceName = TheScienceStore->getInternalNameForScience( *science );
  371. // write the string
  372. xferAsciiString( &scienceName );
  373. } // end if, save
  374. else if( getXferMode() == XFER_LOAD )
  375. {
  376. xferAsciiString( &scienceName );
  377. // translate to science
  378. *science = TheScienceStore->getScienceFromInternalName( scienceName );
  379. if( *science == SCIENCE_INVALID )
  380. {
  381. DEBUG_CRASH(( "xferScienceType - Unknown science '%s'\n", scienceName.str() ));
  382. throw XFER_UNKNOWN_STRING;
  383. } // end if
  384. } // end else if, load
  385. else if( getXferMode() == XFER_CRC )
  386. {
  387. xferImplementation( science, sizeof( *science ) );
  388. } // end else if, crc
  389. else
  390. {
  391. DEBUG_CRASH(( "xferScienceVec - Unknown xfer mode '%d'\n", getXferMode() ));
  392. throw XFER_MODE_UNKNOWN;
  393. } // end else
  394. } // end xferScienceType
  395. // ------------------------------------------------------------------------------------------------
  396. // ------------------------------------------------------------------------------------------------
  397. void Xfer::xferScienceVec( ScienceVec *scienceVec )
  398. {
  399. // sanity
  400. DEBUG_ASSERTCRASH( scienceVec != NULL, ("xferScienceVec - Invalid parameters\n") );
  401. // this deserves a version number
  402. const XferVersion currentVersion = 1;
  403. XferVersion version = currentVersion;
  404. xferVersion( &version, currentVersion );
  405. // count of vector
  406. UnsignedShort count = scienceVec->size();
  407. xferUnsignedShort( &count );
  408. if( getXferMode() == XFER_SAVE )
  409. {
  410. for( ScienceVec::const_iterator it = scienceVec->begin(); it != scienceVec->end(); ++it )
  411. {
  412. ScienceType science = *it;
  413. xferScienceType(&science);
  414. }
  415. }
  416. else if( getXferMode() == XFER_LOAD )
  417. {
  418. // vector should be empty at this point
  419. if( scienceVec->empty() == FALSE )
  420. {
  421. DEBUG_CRASH(( "xferScienceVec - vector is not empty, but should be\n" ));
  422. throw XFER_LIST_NOT_EMPTY;
  423. }
  424. for( UnsignedShort i = 0; i < count; ++i )
  425. {
  426. ScienceType science;
  427. xferScienceType(&science);
  428. scienceVec->push_back( science );
  429. }
  430. }
  431. else if( getXferMode() == XFER_CRC )
  432. {
  433. for( ScienceVec::const_iterator it = scienceVec->begin(); it != scienceVec->end(); ++it )
  434. {
  435. ScienceType science = *it;
  436. xferImplementation( &science, sizeof( ScienceType ) );
  437. } // end for, it
  438. } // end else if, crc
  439. else
  440. {
  441. DEBUG_CRASH(( "xferScienceVec - Unknown xfer mode '%d'\n", getXferMode() ));
  442. throw XFER_MODE_UNKNOWN;
  443. } // end else
  444. } // end xferScienceVec
  445. // ------------------------------------------------------------------------------------------------
  446. /** kind of type, for load/save it is xfered as a string so we can reorder the
  447. * kindofs if we like
  448. * Version Info:
  449. * 1: Initial version */
  450. // ------------------------------------------------------------------------------------------------
  451. void Xfer::xferKindOf( KindOfType *kindOfData )
  452. {
  453. // this deserves a version number
  454. XferVersion currentVersion = 1;
  455. XferVersion version = currentVersion;
  456. xferVersion( &version, currentVersion );
  457. // check which type of xfer we're doing
  458. if( getXferMode() == XFER_SAVE )
  459. {
  460. // save as an ascii string
  461. AsciiString kindOfName = KindOfMaskType::getNameFromSingleBit(*kindOfData);
  462. xferAsciiString( &kindOfName );
  463. } // end if, save
  464. else if( getXferMode() == XFER_LOAD )
  465. {
  466. // read ascii string from file
  467. AsciiString kindOfName;
  468. xferAsciiString( &kindOfName );
  469. // turn kind of name into an enum value
  470. Int bit = KindOfMaskType::getSingleBitFromName(kindOfName.str());
  471. if (bit != -1)
  472. *kindOfData = (KindOfType)bit;
  473. } // end else if, load
  474. else if( getXferMode() == XFER_CRC )
  475. {
  476. // just call the xfer implementation on the data values
  477. xferImplementation( kindOfData, sizeof( KindOfType ) );
  478. } // end else if, crc
  479. else
  480. {
  481. DEBUG_CRASH(( "xferKindOf - Unknown xfer mode '%d'\n", getXferMode() ));
  482. throw XFER_MODE_UNKNOWN;
  483. } // end else
  484. } // end xferKindOf
  485. // ------------------------------------------------------------------------------------------------
  486. // ------------------------------------------------------------------------------------------------
  487. void Xfer::xferUpgradeMask( Int64 *upgradeMaskData )
  488. {
  489. // this deserves a version number
  490. XferVersion currentVersion = 1;
  491. XferVersion version = currentVersion;
  492. xferVersion( &version, currentVersion );
  493. // check which type of xfer we're doing
  494. if( getXferMode() == XFER_SAVE )
  495. {
  496. AsciiString upgradeName;
  497. // count how many bits are set in the mask
  498. UnsignedShort count = 0;
  499. UpgradeTemplate *upgradeTemplate;
  500. for( upgradeTemplate = TheUpgradeCenter->firstUpgradeTemplate();
  501. upgradeTemplate;
  502. upgradeTemplate = upgradeTemplate->friend_getNext() )
  503. {
  504. // if the mask of this upgrade is set, it counts
  505. if( BitTest( *upgradeMaskData, upgradeTemplate->getUpgradeMask() ) )
  506. count++;
  507. } // end for, upgradeTemplate
  508. // write the count
  509. xferUnsignedShort( &count );
  510. // write out the upgrades as strings
  511. for( upgradeTemplate = TheUpgradeCenter->firstUpgradeTemplate();
  512. upgradeTemplate;
  513. upgradeTemplate = upgradeTemplate->friend_getNext() )
  514. {
  515. // if the mask of this upgrade is set, it counts
  516. if( BitTest( *upgradeMaskData, upgradeTemplate->getUpgradeMask() ) )
  517. {
  518. upgradeName = upgradeTemplate->getUpgradeName();
  519. xferAsciiString( &upgradeName );
  520. } // end if
  521. } // end for, upgradeTemplate
  522. } // end if, save
  523. else if( getXferMode() == XFER_LOAD )
  524. {
  525. AsciiString upgradeName;
  526. const UpgradeTemplate *upgradeTemplate;
  527. // how many strings are we going to read from the file
  528. UnsignedShort count;
  529. xferUnsignedShort( &count );
  530. // zero the mask data
  531. *upgradeMaskData = 0;
  532. // read all the strings and set the mask vaules
  533. for( UnsignedShort i = 0; i < count; ++i )
  534. {
  535. // read the string
  536. xferAsciiString( &upgradeName );
  537. // find this upgrade template
  538. upgradeTemplate = TheUpgradeCenter->findUpgrade( upgradeName );
  539. if( upgradeTemplate == NULL )
  540. {
  541. DEBUG_CRASH(( "Xfer::xferUpgradeMask - Unknown upgrade '%s'\n", upgradeName.str() ));
  542. throw XFER_UNKNOWN_STRING;
  543. } // end if
  544. // set the mask data
  545. BitSet( *upgradeMaskData, upgradeTemplate->getUpgradeMask() );
  546. } // end for i
  547. } // end else if, load
  548. else if( getXferMode() == XFER_CRC )
  549. {
  550. // just xfer implementation the data itself
  551. xferImplementation( upgradeMaskData, sizeof( Int64 ) );
  552. } // end else if, crc
  553. else
  554. {
  555. DEBUG_CRASH(( "xferUpgradeMask - Unknown xfer mode '%d'\n", getXferMode() ));
  556. throw XFER_MODE_UNKNOWN;
  557. } // end else
  558. } // end xferUpgradeMask
  559. // ------------------------------------------------------------------------------------------------
  560. // ------------------------------------------------------------------------------------------------
  561. void Xfer::xferUser( void *data, Int dataSize )
  562. {
  563. xferImplementation( data, dataSize );
  564. } // end xferUser
  565. // ------------------------------------------------------------------------------------------------
  566. // ------------------------------------------------------------------------------------------------
  567. void Xfer::xferMatrix3D( Matrix3D* mtx )
  568. {
  569. // this deserves a version number
  570. const XferVersion currentVersion = 1;
  571. XferVersion version = currentVersion;
  572. xferVersion( &version, currentVersion );
  573. Vector4& tmp0 = (*mtx)[0];
  574. Vector4& tmp1 = (*mtx)[1];
  575. Vector4& tmp2 = (*mtx)[2];
  576. xferReal(&tmp0.X);
  577. xferReal(&tmp0.Y);
  578. xferReal(&tmp0.Z);
  579. xferReal(&tmp0.W);
  580. xferReal(&tmp1.X);
  581. xferReal(&tmp1.Y);
  582. xferReal(&tmp1.Z);
  583. xferReal(&tmp1.W);
  584. xferReal(&tmp2.X);
  585. xferReal(&tmp2.Y);
  586. xferReal(&tmp2.Z);
  587. xferReal(&tmp2.W);
  588. }