RenderWorld_demo.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code 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. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #pragma hdrstop
  21. #include "../idlib/precompiled.h"
  22. #include "tr_local.h"
  23. //#define WRITE_GUIS
  24. typedef struct {
  25. int version;
  26. int sizeofRenderEntity;
  27. int sizeofRenderLight;
  28. char mapname[256];
  29. } demoHeader_t;
  30. /*
  31. ==============
  32. StartWritingDemo
  33. ==============
  34. */
  35. void idRenderWorldLocal::StartWritingDemo( idDemoFile *demo ) {
  36. int i;
  37. // FIXME: we should track the idDemoFile locally, instead of snooping into session for it
  38. WriteLoadMap();
  39. // write the door portal state
  40. for ( i = 0 ; i < numInterAreaPortals ; i++ ) {
  41. if ( doublePortals[i].blockingBits ) {
  42. SetPortalState( i+1, doublePortals[i].blockingBits );
  43. }
  44. }
  45. // clear the archive counter on all defs
  46. for ( i = 0 ; i < lightDefs.Num() ; i++ ) {
  47. if ( lightDefs[i] ) {
  48. lightDefs[i]->archived = false;
  49. }
  50. }
  51. for ( i = 0 ; i < entityDefs.Num() ; i++ ) {
  52. if ( entityDefs[i] ) {
  53. entityDefs[i]->archived = false;
  54. }
  55. }
  56. }
  57. void idRenderWorldLocal::StopWritingDemo() {
  58. // writeDemo = NULL;
  59. }
  60. /*
  61. ==============
  62. ProcessDemoCommand
  63. ==============
  64. */
  65. bool idRenderWorldLocal::ProcessDemoCommand( idDemoFile *readDemo, renderView_t *renderView, int *demoTimeOffset ) {
  66. bool newMap = false;
  67. if ( !readDemo ) {
  68. return false;
  69. }
  70. demoCommand_t dc;
  71. qhandle_t h;
  72. if ( !readDemo->ReadInt( (int&)dc ) ) {
  73. // a demoShot may not have an endFrame, but it is still valid
  74. return false;
  75. }
  76. switch( dc ) {
  77. case DC_LOADMAP:
  78. // read the initial data
  79. demoHeader_t header;
  80. readDemo->ReadInt( header.version );
  81. readDemo->ReadInt( header.sizeofRenderEntity );
  82. readDemo->ReadInt( header.sizeofRenderLight );
  83. for ( int i = 0; i < 256; i++ )
  84. readDemo->ReadChar( header.mapname[i] );
  85. // the internal version value got replaced by DS_VERSION at toplevel
  86. if ( header.version != 4 ) {
  87. common->Error( "Demo version mismatch.\n" );
  88. }
  89. if ( r_showDemo.GetBool() ) {
  90. common->Printf( "DC_LOADMAP: %s\n", header.mapname );
  91. }
  92. InitFromMap( header.mapname );
  93. newMap = true; // we will need to set demoTimeOffset
  94. break;
  95. case DC_RENDERVIEW:
  96. readDemo->ReadInt( renderView->viewID );
  97. readDemo->ReadFloat( renderView->fov_x );
  98. readDemo->ReadFloat( renderView->fov_y );
  99. readDemo->ReadVec3( renderView->vieworg );
  100. readDemo->ReadMat3( renderView->viewaxis );
  101. readDemo->ReadBool( renderView->cramZNear );
  102. readDemo->ReadBool( renderView->forceUpdate );
  103. // binary compatibility with win32 padded structures
  104. char tmp;
  105. readDemo->ReadChar( tmp );
  106. readDemo->ReadChar( tmp );
  107. readDemo->ReadInt( renderView->time[1] );
  108. for ( int i = 0; i < MAX_GLOBAL_SHADER_PARMS; i++ )
  109. readDemo->ReadFloat( renderView->shaderParms[i] );
  110. if ( !readDemo->ReadInt( (int&)renderView->globalMaterial ) ) {
  111. return false;
  112. }
  113. if ( r_showDemo.GetBool() ) {
  114. common->Printf( "DC_RENDERVIEW: %i\n", renderView->time );
  115. }
  116. // possibly change the time offset if this is from a new map
  117. if ( newMap && demoTimeOffset ) {
  118. *demoTimeOffset = renderView->time[1] - eventLoop->Milliseconds();
  119. }
  120. return false;
  121. case DC_UPDATE_ENTITYDEF:
  122. ReadRenderEntity();
  123. break;
  124. case DC_DELETE_ENTITYDEF:
  125. if ( !readDemo->ReadInt( h ) ) {
  126. return false;
  127. }
  128. if ( r_showDemo.GetBool() ) {
  129. common->Printf( "DC_DELETE_ENTITYDEF: %i\n", h );
  130. }
  131. FreeEntityDef( h );
  132. break;
  133. case DC_UPDATE_LIGHTDEF:
  134. ReadRenderLight();
  135. break;
  136. case DC_DELETE_LIGHTDEF:
  137. if ( !readDemo->ReadInt( h ) ) {
  138. return false;
  139. }
  140. if ( r_showDemo.GetBool() ) {
  141. common->Printf( "DC_DELETE_LIGHTDEF: %i\n", h );
  142. }
  143. FreeLightDef( h );
  144. break;
  145. case DC_CAPTURE_RENDER:
  146. if ( r_showDemo.GetBool() ) {
  147. common->Printf( "DC_CAPTURE_RENDER\n" );
  148. }
  149. renderSystem->CaptureRenderToImage( readDemo->ReadHashString() );
  150. break;
  151. case DC_CROP_RENDER:
  152. if ( r_showDemo.GetBool() ) {
  153. common->Printf( "DC_CROP_RENDER\n" );
  154. }
  155. int size[3];
  156. readDemo->ReadInt( size[0] );
  157. readDemo->ReadInt( size[1] );
  158. readDemo->ReadInt( size[2] );
  159. renderSystem->CropRenderSize( size[0], size[1] );
  160. break;
  161. case DC_UNCROP_RENDER:
  162. if ( r_showDemo.GetBool() ) {
  163. common->Printf( "DC_UNCROP\n" );
  164. }
  165. renderSystem->UnCrop();
  166. break;
  167. case DC_GUI_MODEL:
  168. if ( r_showDemo.GetBool() ) {
  169. common->Printf( "DC_GUI_MODEL\n" );
  170. }
  171. break;
  172. case DC_DEFINE_MODEL:
  173. {
  174. idRenderModel *model = renderModelManager->AllocModel();
  175. model->ReadFromDemoFile( common->ReadDemo() );
  176. // add to model manager, so we can find it
  177. renderModelManager->AddModel( model );
  178. // save it in the list to free when clearing this map
  179. localModels.Append( model );
  180. if ( r_showDemo.GetBool() ) {
  181. common->Printf( "DC_DEFINE_MODEL\n" );
  182. }
  183. break;
  184. }
  185. case DC_SET_PORTAL_STATE:
  186. {
  187. int data[2];
  188. readDemo->ReadInt( data[0] );
  189. readDemo->ReadInt( data[1] );
  190. SetPortalState( data[0], data[1] );
  191. if ( r_showDemo.GetBool() ) {
  192. common->Printf( "DC_SET_PORTAL_STATE: %i %i\n", data[0], data[1] );
  193. }
  194. }
  195. break;
  196. case DC_END_FRAME:
  197. return true;
  198. default:
  199. common->Error( "Bad token in demo stream" );
  200. }
  201. return false;
  202. }
  203. /*
  204. ================
  205. WriteLoadMap
  206. ================
  207. */
  208. void idRenderWorldLocal::WriteLoadMap() {
  209. // only the main renderWorld writes stuff to demos, not the wipes or
  210. // menu renders
  211. if ( this != common->RW() ) {
  212. return;
  213. }
  214. common->WriteDemo()->WriteInt( DS_RENDER );
  215. common->WriteDemo()->WriteInt( DC_LOADMAP );
  216. demoHeader_t header;
  217. strncpy( header.mapname, mapName.c_str(), sizeof( header.mapname ) - 1 );
  218. header.version = 4;
  219. header.sizeofRenderEntity = sizeof( renderEntity_t );
  220. header.sizeofRenderLight = sizeof( renderLight_t );
  221. common->WriteDemo()->WriteInt( header.version );
  222. common->WriteDemo()->WriteInt( header.sizeofRenderEntity );
  223. common->WriteDemo()->WriteInt( header.sizeofRenderLight );
  224. for ( int i = 0; i < 256; i++ )
  225. common->WriteDemo()->WriteChar( header.mapname[i] );
  226. if ( r_showDemo.GetBool() ) {
  227. common->Printf( "write DC_DELETE_LIGHTDEF: %s\n", mapName.c_str() );
  228. }
  229. }
  230. /*
  231. ================
  232. WriteVisibleDefs
  233. ================
  234. */
  235. void idRenderWorldLocal::WriteVisibleDefs( const viewDef_t *viewDef ) {
  236. // only the main renderWorld writes stuff to demos, not the wipes or
  237. // menu renders
  238. if ( this != common->RW() ) {
  239. return;
  240. }
  241. // make sure all necessary entities and lights are updated
  242. for ( viewEntity_t *viewEnt = viewDef->viewEntitys ; viewEnt ; viewEnt = viewEnt->next ) {
  243. idRenderEntityLocal *ent = viewEnt->entityDef;
  244. if ( ent->archived ) {
  245. // still up to date
  246. continue;
  247. }
  248. // write it out
  249. WriteRenderEntity( ent->index, &ent->parms );
  250. ent->archived = true;
  251. }
  252. for ( viewLight_t *viewLight = viewDef->viewLights ; viewLight ; viewLight = viewLight->next ) {
  253. idRenderLightLocal *light = viewLight->lightDef;
  254. if ( light->archived ) {
  255. // still up to date
  256. continue;
  257. }
  258. // write it out
  259. WriteRenderLight( light->index, &light->parms );
  260. light->archived = true;
  261. }
  262. }
  263. /*
  264. ================
  265. WriteRenderView
  266. ================
  267. */
  268. void idRenderWorldLocal::WriteRenderView( const renderView_t *renderView ) {
  269. int i;
  270. // only the main renderWorld writes stuff to demos, not the wipes or
  271. // menu renders
  272. if ( this != common->RW() ) {
  273. return;
  274. }
  275. // write the actual view command
  276. common->WriteDemo()->WriteInt( DS_RENDER );
  277. common->WriteDemo()->WriteInt( DC_RENDERVIEW );
  278. common->WriteDemo()->WriteInt( renderView->viewID );
  279. common->WriteDemo()->WriteFloat( renderView->fov_x );
  280. common->WriteDemo()->WriteFloat( renderView->fov_y );
  281. common->WriteDemo()->WriteVec3( renderView->vieworg );
  282. common->WriteDemo()->WriteMat3( renderView->viewaxis );
  283. common->WriteDemo()->WriteBool( renderView->cramZNear );
  284. common->WriteDemo()->WriteBool( renderView->forceUpdate );
  285. // binary compatibility with old win32 version writing padded structures directly to disk
  286. common->WriteDemo()->WriteUnsignedChar( 0 );
  287. common->WriteDemo()->WriteUnsignedChar( 0 );
  288. common->WriteDemo()->WriteInt( renderView->time[1] );
  289. for ( i = 0; i < MAX_GLOBAL_SHADER_PARMS; i++ )
  290. common->WriteDemo()->WriteFloat( renderView->shaderParms[i] );
  291. common->WriteDemo()->WriteInt( (int&)renderView->globalMaterial );
  292. if ( r_showDemo.GetBool() ) {
  293. common->Printf( "write DC_RENDERVIEW: %i\n", renderView->time );
  294. }
  295. }
  296. /*
  297. ================
  298. WriteFreeEntity
  299. ================
  300. */
  301. void idRenderWorldLocal::WriteFreeEntity( qhandle_t handle ) {
  302. // only the main renderWorld writes stuff to demos, not the wipes or
  303. // menu renders
  304. if ( this != common->RW() ) {
  305. return;
  306. }
  307. common->WriteDemo()->WriteInt( DS_RENDER );
  308. common->WriteDemo()->WriteInt( DC_DELETE_ENTITYDEF );
  309. common->WriteDemo()->WriteInt( handle );
  310. if ( r_showDemo.GetBool() ) {
  311. common->Printf( "write DC_DELETE_ENTITYDEF: %i\n", handle );
  312. }
  313. }
  314. /*
  315. ================
  316. WriteFreeLightEntity
  317. ================
  318. */
  319. void idRenderWorldLocal::WriteFreeLight( qhandle_t handle ) {
  320. // only the main renderWorld writes stuff to demos, not the wipes or
  321. // menu renders
  322. if ( this != common->RW() ) {
  323. return;
  324. }
  325. common->WriteDemo()->WriteInt( DS_RENDER );
  326. common->WriteDemo()->WriteInt( DC_DELETE_LIGHTDEF );
  327. common->WriteDemo()->WriteInt( handle );
  328. if ( r_showDemo.GetBool() ) {
  329. common->Printf( "write DC_DELETE_LIGHTDEF: %i\n", handle );
  330. }
  331. }
  332. /*
  333. ================
  334. WriteRenderLight
  335. ================
  336. */
  337. void idRenderWorldLocal::WriteRenderLight( qhandle_t handle, const renderLight_t *light ) {
  338. // only the main renderWorld writes stuff to demos, not the wipes or
  339. // menu renders
  340. if ( this != common->RW() ) {
  341. return;
  342. }
  343. common->WriteDemo()->WriteInt( DS_RENDER );
  344. common->WriteDemo()->WriteInt( DC_UPDATE_LIGHTDEF );
  345. common->WriteDemo()->WriteInt( handle );
  346. common->WriteDemo()->WriteMat3( light->axis );
  347. common->WriteDemo()->WriteVec3( light->origin );
  348. common->WriteDemo()->WriteInt( light->suppressLightInViewID );
  349. common->WriteDemo()->WriteInt( light->allowLightInViewID );
  350. common->WriteDemo()->WriteBool( light->noShadows );
  351. common->WriteDemo()->WriteBool( light->noSpecular );
  352. common->WriteDemo()->WriteBool( light->pointLight );
  353. common->WriteDemo()->WriteBool( light->parallel );
  354. common->WriteDemo()->WriteVec3( light->lightRadius );
  355. common->WriteDemo()->WriteVec3( light->lightCenter );
  356. common->WriteDemo()->WriteVec3( light->target );
  357. common->WriteDemo()->WriteVec3( light->right );
  358. common->WriteDemo()->WriteVec3( light->up );
  359. common->WriteDemo()->WriteVec3( light->start );
  360. common->WriteDemo()->WriteVec3( light->end );
  361. common->WriteDemo()->WriteInt( (int&)light->prelightModel );
  362. common->WriteDemo()->WriteInt( light->lightId );
  363. common->WriteDemo()->WriteInt( (int&)light->shader );
  364. for ( int i = 0; i < MAX_ENTITY_SHADER_PARMS; i++)
  365. common->WriteDemo()->WriteFloat( light->shaderParms[i] );
  366. common->WriteDemo()->WriteInt( (int&)light->referenceSound );
  367. if ( light->prelightModel ) {
  368. common->WriteDemo()->WriteHashString( light->prelightModel->Name() );
  369. }
  370. if ( light->shader ) {
  371. common->WriteDemo()->WriteHashString( light->shader->GetName() );
  372. }
  373. if ( light->referenceSound ) {
  374. int index = light->referenceSound->Index();
  375. common->WriteDemo()->WriteInt( index );
  376. }
  377. if ( r_showDemo.GetBool() ) {
  378. common->Printf( "write DC_UPDATE_LIGHTDEF: %i\n", handle );
  379. }
  380. }
  381. /*
  382. ================
  383. ReadRenderLight
  384. ================
  385. */
  386. void idRenderWorldLocal::ReadRenderLight( ) {
  387. renderLight_t light;
  388. int index;
  389. common->ReadDemo()->ReadInt( index );
  390. if ( index < 0 ) {
  391. common->Error( "ReadRenderLight: index < 0 " );
  392. }
  393. common->ReadDemo()->ReadMat3( light.axis );
  394. common->ReadDemo()->ReadVec3( light.origin );
  395. common->ReadDemo()->ReadInt( light.suppressLightInViewID );
  396. common->ReadDemo()->ReadInt( light.allowLightInViewID );
  397. common->ReadDemo()->ReadBool( light.noShadows );
  398. common->ReadDemo()->ReadBool( light.noSpecular );
  399. common->ReadDemo()->ReadBool( light.pointLight );
  400. common->ReadDemo()->ReadBool( light.parallel );
  401. common->ReadDemo()->ReadVec3( light.lightRadius );
  402. common->ReadDemo()->ReadVec3( light.lightCenter );
  403. common->ReadDemo()->ReadVec3( light.target );
  404. common->ReadDemo()->ReadVec3( light.right );
  405. common->ReadDemo()->ReadVec3( light.up );
  406. common->ReadDemo()->ReadVec3( light.start );
  407. common->ReadDemo()->ReadVec3( light.end );
  408. common->ReadDemo()->ReadInt( (int&)light.prelightModel );
  409. common->ReadDemo()->ReadInt( light.lightId );
  410. common->ReadDemo()->ReadInt( (int&)light.shader );
  411. for ( int i = 0; i < MAX_ENTITY_SHADER_PARMS; i++)
  412. common->ReadDemo()->ReadFloat( light.shaderParms[i] );
  413. common->ReadDemo()->ReadInt( (int&)light.referenceSound );
  414. if ( light.prelightModel ) {
  415. light.prelightModel = renderModelManager->FindModel( common->ReadDemo()->ReadHashString() );
  416. }
  417. if ( light.shader ) {
  418. light.shader = declManager->FindMaterial( common->ReadDemo()->ReadHashString() );
  419. }
  420. if ( light.referenceSound ) {
  421. int index;
  422. common->ReadDemo()->ReadInt( index );
  423. light.referenceSound = common->SW()->EmitterForIndex( index );
  424. }
  425. UpdateLightDef( index, &light );
  426. if ( r_showDemo.GetBool() ) {
  427. common->Printf( "DC_UPDATE_LIGHTDEF: %i\n", index );
  428. }
  429. }
  430. /*
  431. ================
  432. WriteRenderEntity
  433. ================
  434. */
  435. void idRenderWorldLocal::WriteRenderEntity( qhandle_t handle, const renderEntity_t *ent ) {
  436. // only the main renderWorld writes stuff to demos, not the wipes or
  437. // menu renders
  438. if ( this != common->RW() ) {
  439. return;
  440. }
  441. common->WriteDemo()->WriteInt( DS_RENDER );
  442. common->WriteDemo()->WriteInt( DC_UPDATE_ENTITYDEF );
  443. common->WriteDemo()->WriteInt( handle );
  444. common->WriteDemo()->WriteInt( (int&)ent->hModel );
  445. common->WriteDemo()->WriteInt( ent->entityNum );
  446. common->WriteDemo()->WriteInt( ent->bodyId );
  447. common->WriteDemo()->WriteVec3( ent->bounds[0] );
  448. common->WriteDemo()->WriteVec3( ent->bounds[1] );
  449. common->WriteDemo()->WriteInt( (int&)ent->callback );
  450. common->WriteDemo()->WriteInt( (int&)ent->callbackData );
  451. common->WriteDemo()->WriteInt( ent->suppressSurfaceInViewID );
  452. common->WriteDemo()->WriteInt( ent->suppressShadowInViewID );
  453. common->WriteDemo()->WriteInt( ent->suppressShadowInLightID );
  454. common->WriteDemo()->WriteInt( ent->allowSurfaceInViewID );
  455. common->WriteDemo()->WriteVec3( ent->origin );
  456. common->WriteDemo()->WriteMat3( ent->axis );
  457. common->WriteDemo()->WriteInt( (int&)ent->customShader );
  458. common->WriteDemo()->WriteInt( (int&)ent->referenceShader );
  459. common->WriteDemo()->WriteInt( (int&)ent->customSkin );
  460. common->WriteDemo()->WriteInt( (int&)ent->referenceSound );
  461. for ( int i = 0; i < MAX_ENTITY_SHADER_PARMS; i++ )
  462. common->WriteDemo()->WriteFloat( ent->shaderParms[i] );
  463. for ( int i = 0; i < MAX_RENDERENTITY_GUI; i++ )
  464. common->WriteDemo()->WriteInt( (int&)ent->gui[i] );
  465. common->WriteDemo()->WriteInt( (int&)ent->remoteRenderView );
  466. common->WriteDemo()->WriteInt( ent->numJoints );
  467. common->WriteDemo()->WriteInt( (int&)ent->joints );
  468. common->WriteDemo()->WriteFloat( ent->modelDepthHack );
  469. common->WriteDemo()->WriteBool( ent->noSelfShadow );
  470. common->WriteDemo()->WriteBool( ent->noShadow );
  471. common->WriteDemo()->WriteBool( ent->noDynamicInteractions );
  472. common->WriteDemo()->WriteBool( ent->weaponDepthHack );
  473. common->WriteDemo()->WriteInt( ent->forceUpdate );
  474. if ( ent->customShader ) {
  475. common->WriteDemo()->WriteHashString( ent->customShader->GetName() );
  476. }
  477. if ( ent->customSkin ) {
  478. common->WriteDemo()->WriteHashString( ent->customSkin->GetName() );
  479. }
  480. if ( ent->hModel ) {
  481. common->WriteDemo()->WriteHashString( ent->hModel->Name() );
  482. }
  483. if ( ent->referenceShader ) {
  484. common->WriteDemo()->WriteHashString( ent->referenceShader->GetName() );
  485. }
  486. if ( ent->referenceSound ) {
  487. int index = ent->referenceSound->Index();
  488. common->WriteDemo()->WriteInt( index );
  489. }
  490. if ( ent->numJoints ) {
  491. for ( int i = 0; i < ent->numJoints; i++) {
  492. float *data = ent->joints[i].ToFloatPtr();
  493. for ( int j = 0; j < 12; ++j)
  494. common->WriteDemo()->WriteFloat( data[j] );
  495. }
  496. }
  497. /*
  498. if ( ent->decals ) {
  499. ent->decals->WriteToDemoFile( common->ReadDemo() );
  500. }
  501. if ( ent->overlays ) {
  502. ent->overlays->WriteToDemoFile( common->WriteDemo() );
  503. }
  504. */
  505. #ifdef WRITE_GUIS
  506. if ( ent->gui ) {
  507. ent->gui->WriteToDemoFile( common->WriteDemo() );
  508. }
  509. if ( ent->gui2 ) {
  510. ent->gui2->WriteToDemoFile( common->WriteDemo() );
  511. }
  512. if ( ent->gui3 ) {
  513. ent->gui3->WriteToDemoFile( common->WriteDemo() );
  514. }
  515. #endif
  516. // RENDERDEMO_VERSION >= 2 ( Doom3 1.2 )
  517. common->WriteDemo()->WriteInt( ent->timeGroup );
  518. common->WriteDemo()->WriteInt( ent->xrayIndex );
  519. if ( r_showDemo.GetBool() ) {
  520. common->Printf( "write DC_UPDATE_ENTITYDEF: %i = %s\n", handle, ent->hModel ? ent->hModel->Name() : "NULL" );
  521. }
  522. }
  523. /*
  524. ================
  525. ReadRenderEntity
  526. ================
  527. */
  528. void idRenderWorldLocal::ReadRenderEntity() {
  529. renderEntity_t ent;
  530. int index, i;
  531. common->ReadDemo()->ReadInt( index );
  532. if ( index < 0 ) {
  533. common->Error( "ReadRenderEntity: index < 0" );
  534. }
  535. common->ReadDemo()->ReadInt( (int&)ent.hModel );
  536. common->ReadDemo()->ReadInt( ent.entityNum );
  537. common->ReadDemo()->ReadInt( ent.bodyId );
  538. common->ReadDemo()->ReadVec3( ent.bounds[0] );
  539. common->ReadDemo()->ReadVec3( ent.bounds[1] );
  540. common->ReadDemo()->ReadInt( (int&)ent.callback );
  541. common->ReadDemo()->ReadInt( (int&)ent.callbackData );
  542. common->ReadDemo()->ReadInt( ent.suppressSurfaceInViewID );
  543. common->ReadDemo()->ReadInt( ent.suppressShadowInViewID );
  544. common->ReadDemo()->ReadInt( ent.suppressShadowInLightID );
  545. common->ReadDemo()->ReadInt( ent.allowSurfaceInViewID );
  546. common->ReadDemo()->ReadVec3( ent.origin );
  547. common->ReadDemo()->ReadMat3( ent.axis );
  548. common->ReadDemo()->ReadInt( (int&)ent.customShader );
  549. common->ReadDemo()->ReadInt( (int&)ent.referenceShader );
  550. common->ReadDemo()->ReadInt( (int&)ent.customSkin );
  551. common->ReadDemo()->ReadInt( (int&)ent.referenceSound );
  552. for ( i = 0; i < MAX_ENTITY_SHADER_PARMS; i++ ) {
  553. common->ReadDemo()->ReadFloat( ent.shaderParms[i] );
  554. }
  555. for ( i = 0; i < MAX_RENDERENTITY_GUI; i++ ) {
  556. common->ReadDemo()->ReadInt( (int&)ent.gui[i] );
  557. }
  558. common->ReadDemo()->ReadInt( (int&)ent.remoteRenderView );
  559. common->ReadDemo()->ReadInt( ent.numJoints );
  560. common->ReadDemo()->ReadInt( (int&)ent.joints );
  561. common->ReadDemo()->ReadFloat( ent.modelDepthHack );
  562. common->ReadDemo()->ReadBool( ent.noSelfShadow );
  563. common->ReadDemo()->ReadBool( ent.noShadow );
  564. common->ReadDemo()->ReadBool( ent.noDynamicInteractions );
  565. common->ReadDemo()->ReadBool( ent.weaponDepthHack );
  566. common->ReadDemo()->ReadInt( ent.forceUpdate );
  567. ent.callback = NULL;
  568. if ( ent.customShader ) {
  569. ent.customShader = declManager->FindMaterial( common->ReadDemo()->ReadHashString() );
  570. }
  571. if ( ent.customSkin ) {
  572. ent.customSkin = declManager->FindSkin( common->ReadDemo()->ReadHashString() );
  573. }
  574. if ( ent.hModel ) {
  575. ent.hModel = renderModelManager->FindModel( common->ReadDemo()->ReadHashString() );
  576. }
  577. if ( ent.referenceShader ) {
  578. ent.referenceShader = declManager->FindMaterial( common->ReadDemo()->ReadHashString() );
  579. }
  580. if ( ent.referenceSound ) {
  581. int index;
  582. common->ReadDemo()->ReadInt( index );
  583. ent.referenceSound = common->SW()->EmitterForIndex( index );
  584. }
  585. if ( ent.numJoints ) {
  586. ent.joints = (idJointMat *)Mem_Alloc16( SIMD_ROUND_JOINTS( ent.numJoints ) * sizeof( ent.joints[0] ), TAG_JOINTMAT );
  587. for ( int i = 0; i < ent.numJoints; i++) {
  588. float *data = ent.joints[i].ToFloatPtr();
  589. for ( int j = 0; j < 12; ++j ) {
  590. common->ReadDemo()->ReadFloat( data[j] );
  591. }
  592. }
  593. SIMD_INIT_LAST_JOINT( ent.joints, ent.numJoints );
  594. }
  595. ent.callbackData = NULL;
  596. /*
  597. if ( ent.decals ) {
  598. ent.decals = idRenderModelDecal::Alloc();
  599. ent.decals->ReadFromDemoFile( common->ReadDemo() );
  600. }
  601. if ( ent.overlays ) {
  602. ent.overlays = idRenderModelOverlay::Alloc();
  603. ent.overlays->ReadFromDemoFile( common->ReadDemo() );
  604. }
  605. */
  606. for ( i = 0; i < MAX_RENDERENTITY_GUI; i++ ) {
  607. if ( ent.gui[ i ] ) {
  608. ent.gui[ i ] = uiManager->Alloc();
  609. #ifdef WRITE_GUIS
  610. ent.gui[ i ]->ReadFromDemoFile( common->ReadDemo() );
  611. #endif
  612. }
  613. }
  614. common->ReadDemo()->ReadInt( ent.timeGroup );
  615. common->ReadDemo()->ReadInt( ent.xrayIndex );
  616. UpdateEntityDef( index, &ent );
  617. if ( r_showDemo.GetBool() ) {
  618. common->Printf( "DC_UPDATE_ENTITYDEF: %i = %s\n", index, ent.hModel ? ent.hModel->Name() : "NULL" );
  619. }
  620. }