RenderWorld_demo.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 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 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 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 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 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. #include "../idlib/precompiled.h"
  21. #pragma hdrstop
  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->ReadInt( renderView->x );
  98. readDemo->ReadInt( renderView->y );
  99. readDemo->ReadInt( renderView->width );
  100. readDemo->ReadInt( renderView->height );
  101. readDemo->ReadFloat( renderView->fov_x );
  102. readDemo->ReadFloat( renderView->fov_y );
  103. readDemo->ReadVec3( renderView->vieworg );
  104. readDemo->ReadMat3( renderView->viewaxis );
  105. readDemo->ReadBool( renderView->cramZNear );
  106. readDemo->ReadBool( renderView->forceUpdate );
  107. // binary compatibility with win32 padded structures
  108. char tmp;
  109. readDemo->ReadChar( tmp );
  110. readDemo->ReadChar( tmp );
  111. readDemo->ReadInt( renderView->time );
  112. for ( int i = 0; i < MAX_GLOBAL_SHADER_PARMS; i++ )
  113. readDemo->ReadFloat( renderView->shaderParms[i] );
  114. if ( !readDemo->ReadInt( (int&)renderView->globalMaterial ) ) {
  115. return false;
  116. }
  117. if ( r_showDemo.GetBool() ) {
  118. common->Printf( "DC_RENDERVIEW: %i\n", renderView->time );
  119. }
  120. // possibly change the time offset if this is from a new map
  121. if ( newMap && demoTimeOffset ) {
  122. *demoTimeOffset = renderView->time - eventLoop->Milliseconds();
  123. }
  124. return false;
  125. case DC_UPDATE_ENTITYDEF:
  126. ReadRenderEntity();
  127. break;
  128. case DC_DELETE_ENTITYDEF:
  129. if ( !readDemo->ReadInt( h ) ) {
  130. return false;
  131. }
  132. if ( r_showDemo.GetBool() ) {
  133. common->Printf( "DC_DELETE_ENTITYDEF: %i\n", h );
  134. }
  135. FreeEntityDef( h );
  136. break;
  137. case DC_UPDATE_LIGHTDEF:
  138. ReadRenderLight();
  139. break;
  140. case DC_DELETE_LIGHTDEF:
  141. if ( !readDemo->ReadInt( h ) ) {
  142. return false;
  143. }
  144. if ( r_showDemo.GetBool() ) {
  145. common->Printf( "DC_DELETE_LIGHTDEF: %i\n", h );
  146. }
  147. FreeLightDef( h );
  148. break;
  149. case DC_CAPTURE_RENDER:
  150. if ( r_showDemo.GetBool() ) {
  151. common->Printf( "DC_CAPTURE_RENDER\n" );
  152. }
  153. renderSystem->CaptureRenderToImage( readDemo->ReadHashString() );
  154. break;
  155. case DC_CROP_RENDER:
  156. if ( r_showDemo.GetBool() ) {
  157. common->Printf( "DC_CROP_RENDER\n" );
  158. }
  159. int size[3];
  160. readDemo->ReadInt( size[0] );
  161. readDemo->ReadInt( size[1] );
  162. readDemo->ReadInt( size[2] );
  163. renderSystem->CropRenderSize( size[0], size[1], size[2] != 0 );
  164. break;
  165. case DC_UNCROP_RENDER:
  166. if ( r_showDemo.GetBool() ) {
  167. common->Printf( "DC_UNCROP\n" );
  168. }
  169. renderSystem->UnCrop();
  170. break;
  171. case DC_GUI_MODEL:
  172. if ( r_showDemo.GetBool() ) {
  173. common->Printf( "DC_GUI_MODEL\n" );
  174. }
  175. tr.demoGuiModel->ReadFromDemo( readDemo );
  176. break;
  177. case DC_DEFINE_MODEL:
  178. {
  179. idRenderModel *model = renderModelManager->AllocModel();
  180. model->ReadFromDemoFile( session->readDemo );
  181. // add to model manager, so we can find it
  182. renderModelManager->AddModel( model );
  183. // save it in the list to free when clearing this map
  184. localModels.Append( model );
  185. if ( r_showDemo.GetBool() ) {
  186. common->Printf( "DC_DEFINE_MODEL\n" );
  187. }
  188. break;
  189. }
  190. case DC_SET_PORTAL_STATE:
  191. {
  192. int data[2];
  193. readDemo->ReadInt( data[0] );
  194. readDemo->ReadInt( data[1] );
  195. SetPortalState( data[0], data[1] );
  196. if ( r_showDemo.GetBool() ) {
  197. common->Printf( "DC_SET_PORTAL_STATE: %i %i\n", data[0], data[1] );
  198. }
  199. }
  200. break;
  201. case DC_END_FRAME:
  202. return true;
  203. default:
  204. common->Error( "Bad token in demo stream" );
  205. }
  206. return false;
  207. }
  208. /*
  209. ================
  210. WriteLoadMap
  211. ================
  212. */
  213. void idRenderWorldLocal::WriteLoadMap() {
  214. // only the main renderWorld writes stuff to demos, not the wipes or
  215. // menu renders
  216. if ( this != session->rw ) {
  217. return;
  218. }
  219. session->writeDemo->WriteInt( DS_RENDER );
  220. session->writeDemo->WriteInt( DC_LOADMAP );
  221. demoHeader_t header;
  222. strncpy( header.mapname, mapName.c_str(), sizeof( header.mapname ) - 1 );
  223. header.version = 4;
  224. header.sizeofRenderEntity = sizeof( renderEntity_t );
  225. header.sizeofRenderLight = sizeof( renderLight_t );
  226. session->writeDemo->WriteInt( header.version );
  227. session->writeDemo->WriteInt( header.sizeofRenderEntity );
  228. session->writeDemo->WriteInt( header.sizeofRenderLight );
  229. for ( int i = 0; i < 256; i++ )
  230. session->writeDemo->WriteChar( header.mapname[i] );
  231. if ( r_showDemo.GetBool() ) {
  232. common->Printf( "write DC_DELETE_LIGHTDEF: %s\n", mapName.c_str() );
  233. }
  234. }
  235. /*
  236. ================
  237. WriteVisibleDefs
  238. ================
  239. */
  240. void idRenderWorldLocal::WriteVisibleDefs( const viewDef_t *viewDef ) {
  241. // only the main renderWorld writes stuff to demos, not the wipes or
  242. // menu renders
  243. if ( this != session->rw ) {
  244. return;
  245. }
  246. // make sure all necessary entities and lights are updated
  247. for ( viewEntity_t *viewEnt = viewDef->viewEntitys ; viewEnt ; viewEnt = viewEnt->next ) {
  248. idRenderEntityLocal *ent = viewEnt->entityDef;
  249. if ( ent->archived ) {
  250. // still up to date
  251. continue;
  252. }
  253. // write it out
  254. WriteRenderEntity( ent->index, &ent->parms );
  255. ent->archived = true;
  256. }
  257. for ( viewLight_t *viewLight = viewDef->viewLights ; viewLight ; viewLight = viewLight->next ) {
  258. idRenderLightLocal *light = viewLight->lightDef;
  259. if ( light->archived ) {
  260. // still up to date
  261. continue;
  262. }
  263. // write it out
  264. WriteRenderLight( light->index, &light->parms );
  265. light->archived = true;
  266. }
  267. }
  268. /*
  269. ================
  270. WriteRenderView
  271. ================
  272. */
  273. void idRenderWorldLocal::WriteRenderView( const renderView_t *renderView ) {
  274. int i;
  275. // only the main renderWorld writes stuff to demos, not the wipes or
  276. // menu renders
  277. if ( this != session->rw ) {
  278. return;
  279. }
  280. // write the actual view command
  281. session->writeDemo->WriteInt( DS_RENDER );
  282. session->writeDemo->WriteInt( DC_RENDERVIEW );
  283. session->writeDemo->WriteInt( renderView->viewID );
  284. session->writeDemo->WriteInt( renderView->x );
  285. session->writeDemo->WriteInt( renderView->y );
  286. session->writeDemo->WriteInt( renderView->width );
  287. session->writeDemo->WriteInt( renderView->height );
  288. session->writeDemo->WriteFloat( renderView->fov_x );
  289. session->writeDemo->WriteFloat( renderView->fov_y );
  290. session->writeDemo->WriteVec3( renderView->vieworg );
  291. session->writeDemo->WriteMat3( renderView->viewaxis );
  292. session->writeDemo->WriteBool( renderView->cramZNear );
  293. session->writeDemo->WriteBool( renderView->forceUpdate );
  294. // binary compatibility with old win32 version writing padded structures directly to disk
  295. session->writeDemo->WriteUnsignedChar( 0 );
  296. session->writeDemo->WriteUnsignedChar( 0 );
  297. session->writeDemo->WriteInt( renderView->time );
  298. for ( i = 0; i < MAX_GLOBAL_SHADER_PARMS; i++ )
  299. session->writeDemo->WriteFloat( renderView->shaderParms[i] );
  300. session->writeDemo->WriteInt( (int&)renderView->globalMaterial );
  301. if ( r_showDemo.GetBool() ) {
  302. common->Printf( "write DC_RENDERVIEW: %i\n", renderView->time );
  303. }
  304. }
  305. /*
  306. ================
  307. WriteFreeEntity
  308. ================
  309. */
  310. void idRenderWorldLocal::WriteFreeEntity( qhandle_t handle ) {
  311. // only the main renderWorld writes stuff to demos, not the wipes or
  312. // menu renders
  313. if ( this != session->rw ) {
  314. return;
  315. }
  316. session->writeDemo->WriteInt( DS_RENDER );
  317. session->writeDemo->WriteInt( DC_DELETE_ENTITYDEF );
  318. session->writeDemo->WriteInt( handle );
  319. if ( r_showDemo.GetBool() ) {
  320. common->Printf( "write DC_DELETE_ENTITYDEF: %i\n", handle );
  321. }
  322. }
  323. /*
  324. ================
  325. WriteFreeLightEntity
  326. ================
  327. */
  328. void idRenderWorldLocal::WriteFreeLight( qhandle_t handle ) {
  329. // only the main renderWorld writes stuff to demos, not the wipes or
  330. // menu renders
  331. if ( this != session->rw ) {
  332. return;
  333. }
  334. session->writeDemo->WriteInt( DS_RENDER );
  335. session->writeDemo->WriteInt( DC_DELETE_LIGHTDEF );
  336. session->writeDemo->WriteInt( handle );
  337. if ( r_showDemo.GetBool() ) {
  338. common->Printf( "write DC_DELETE_LIGHTDEF: %i\n", handle );
  339. }
  340. }
  341. /*
  342. ================
  343. WriteRenderLight
  344. ================
  345. */
  346. void idRenderWorldLocal::WriteRenderLight( qhandle_t handle, const renderLight_t *light ) {
  347. // only the main renderWorld writes stuff to demos, not the wipes or
  348. // menu renders
  349. if ( this != session->rw ) {
  350. return;
  351. }
  352. session->writeDemo->WriteInt( DS_RENDER );
  353. session->writeDemo->WriteInt( DC_UPDATE_LIGHTDEF );
  354. session->writeDemo->WriteInt( handle );
  355. session->writeDemo->WriteMat3( light->axis );
  356. session->writeDemo->WriteVec3( light->origin );
  357. session->writeDemo->WriteInt( light->suppressLightInViewID );
  358. session->writeDemo->WriteInt( light->allowLightInViewID );
  359. session->writeDemo->WriteBool( light->noShadows );
  360. session->writeDemo->WriteBool( light->noSpecular );
  361. session->writeDemo->WriteBool( light->pointLight );
  362. session->writeDemo->WriteBool( light->parallel );
  363. session->writeDemo->WriteVec3( light->lightRadius );
  364. session->writeDemo->WriteVec3( light->lightCenter );
  365. session->writeDemo->WriteVec3( light->target );
  366. session->writeDemo->WriteVec3( light->right );
  367. session->writeDemo->WriteVec3( light->up );
  368. session->writeDemo->WriteVec3( light->start );
  369. session->writeDemo->WriteVec3( light->end );
  370. session->writeDemo->WriteInt( (int&)light->prelightModel );
  371. session->writeDemo->WriteInt( light->lightId );
  372. session->writeDemo->WriteInt( (int&)light->shader );
  373. for ( int i = 0; i < MAX_ENTITY_SHADER_PARMS; i++)
  374. session->writeDemo->WriteFloat( light->shaderParms[i] );
  375. session->writeDemo->WriteInt( (int&)light->referenceSound );
  376. if ( light->prelightModel ) {
  377. session->writeDemo->WriteHashString( light->prelightModel->Name() );
  378. }
  379. if ( light->shader ) {
  380. session->writeDemo->WriteHashString( light->shader->GetName() );
  381. }
  382. if ( light->referenceSound ) {
  383. int index = light->referenceSound->Index();
  384. session->writeDemo->WriteInt( index );
  385. }
  386. if ( r_showDemo.GetBool() ) {
  387. common->Printf( "write DC_UPDATE_LIGHTDEF: %i\n", handle );
  388. }
  389. }
  390. /*
  391. ================
  392. ReadRenderLight
  393. ================
  394. */
  395. void idRenderWorldLocal::ReadRenderLight( ) {
  396. renderLight_t light;
  397. int index;
  398. session->readDemo->ReadInt( index );
  399. if ( index < 0 ) {
  400. common->Error( "ReadRenderLight: index < 0 " );
  401. }
  402. session->readDemo->ReadMat3( light.axis );
  403. session->readDemo->ReadVec3( light.origin );
  404. session->readDemo->ReadInt( light.suppressLightInViewID );
  405. session->readDemo->ReadInt( light.allowLightInViewID );
  406. session->readDemo->ReadBool( light.noShadows );
  407. session->readDemo->ReadBool( light.noSpecular );
  408. session->readDemo->ReadBool( light.pointLight );
  409. session->readDemo->ReadBool( light.parallel );
  410. session->readDemo->ReadVec3( light.lightRadius );
  411. session->readDemo->ReadVec3( light.lightCenter );
  412. session->readDemo->ReadVec3( light.target );
  413. session->readDemo->ReadVec3( light.right );
  414. session->readDemo->ReadVec3( light.up );
  415. session->readDemo->ReadVec3( light.start );
  416. session->readDemo->ReadVec3( light.end );
  417. session->readDemo->ReadInt( (int&)light.prelightModel );
  418. session->readDemo->ReadInt( light.lightId );
  419. session->readDemo->ReadInt( (int&)light.shader );
  420. for ( int i = 0; i < MAX_ENTITY_SHADER_PARMS; i++)
  421. session->readDemo->ReadFloat( light.shaderParms[i] );
  422. session->readDemo->ReadInt( (int&)light.referenceSound );
  423. if ( light.prelightModel ) {
  424. light.prelightModel = renderModelManager->FindModel( session->readDemo->ReadHashString() );
  425. }
  426. if ( light.shader ) {
  427. light.shader = declManager->FindMaterial( session->readDemo->ReadHashString() );
  428. }
  429. if ( light.referenceSound ) {
  430. int index;
  431. session->readDemo->ReadInt( index );
  432. light.referenceSound = session->sw->EmitterForIndex( index );
  433. }
  434. UpdateLightDef( index, &light );
  435. if ( r_showDemo.GetBool() ) {
  436. common->Printf( "DC_UPDATE_LIGHTDEF: %i\n", index );
  437. }
  438. }
  439. /*
  440. ================
  441. WriteRenderEntity
  442. ================
  443. */
  444. void idRenderWorldLocal::WriteRenderEntity( qhandle_t handle, const renderEntity_t *ent ) {
  445. // only the main renderWorld writes stuff to demos, not the wipes or
  446. // menu renders
  447. if ( this != session->rw ) {
  448. return;
  449. }
  450. session->writeDemo->WriteInt( DS_RENDER );
  451. session->writeDemo->WriteInt( DC_UPDATE_ENTITYDEF );
  452. session->writeDemo->WriteInt( handle );
  453. session->writeDemo->WriteInt( (int&)ent->hModel );
  454. session->writeDemo->WriteInt( ent->entityNum );
  455. session->writeDemo->WriteInt( ent->bodyId );
  456. session->writeDemo->WriteVec3( ent->bounds[0] );
  457. session->writeDemo->WriteVec3( ent->bounds[1] );
  458. session->writeDemo->WriteInt( (int&)ent->callback );
  459. session->writeDemo->WriteInt( (int&)ent->callbackData );
  460. session->writeDemo->WriteInt( ent->suppressSurfaceInViewID );
  461. session->writeDemo->WriteInt( ent->suppressShadowInViewID );
  462. session->writeDemo->WriteInt( ent->suppressShadowInLightID );
  463. session->writeDemo->WriteInt( ent->allowSurfaceInViewID );
  464. session->writeDemo->WriteVec3( ent->origin );
  465. session->writeDemo->WriteMat3( ent->axis );
  466. session->writeDemo->WriteInt( (int&)ent->customShader );
  467. session->writeDemo->WriteInt( (int&)ent->referenceShader );
  468. session->writeDemo->WriteInt( (int&)ent->customSkin );
  469. session->writeDemo->WriteInt( (int&)ent->referenceSound );
  470. for ( int i = 0; i < MAX_ENTITY_SHADER_PARMS; i++ )
  471. session->writeDemo->WriteFloat( ent->shaderParms[i] );
  472. for ( int i = 0; i < MAX_RENDERENTITY_GUI; i++ )
  473. session->writeDemo->WriteInt( (int&)ent->gui[i] );
  474. session->writeDemo->WriteInt( (int&)ent->remoteRenderView );
  475. session->writeDemo->WriteInt( ent->numJoints );
  476. session->writeDemo->WriteInt( (int&)ent->joints );
  477. session->writeDemo->WriteFloat( ent->modelDepthHack );
  478. session->writeDemo->WriteBool( ent->noSelfShadow );
  479. session->writeDemo->WriteBool( ent->noShadow );
  480. session->writeDemo->WriteBool( ent->noDynamicInteractions );
  481. session->writeDemo->WriteBool( ent->weaponDepthHack );
  482. session->writeDemo->WriteInt( ent->forceUpdate );
  483. if ( ent->customShader ) {
  484. session->writeDemo->WriteHashString( ent->customShader->GetName() );
  485. }
  486. if ( ent->customSkin ) {
  487. session->writeDemo->WriteHashString( ent->customSkin->GetName() );
  488. }
  489. if ( ent->hModel ) {
  490. session->writeDemo->WriteHashString( ent->hModel->Name() );
  491. }
  492. if ( ent->referenceShader ) {
  493. session->writeDemo->WriteHashString( ent->referenceShader->GetName() );
  494. }
  495. if ( ent->referenceSound ) {
  496. int index = ent->referenceSound->Index();
  497. session->writeDemo->WriteInt( index );
  498. }
  499. if ( ent->numJoints ) {
  500. for ( int i = 0; i < ent->numJoints; i++) {
  501. float *data = ent->joints[i].ToFloatPtr();
  502. for ( int j = 0; j < 12; ++j)
  503. session->writeDemo->WriteFloat( data[j] );
  504. }
  505. }
  506. /*
  507. if ( ent->decals ) {
  508. ent->decals->WriteToDemoFile( session->readDemo );
  509. }
  510. if ( ent->overlay ) {
  511. ent->overlay->WriteToDemoFile( session->writeDemo );
  512. }
  513. */
  514. #ifdef WRITE_GUIS
  515. if ( ent->gui ) {
  516. ent->gui->WriteToDemoFile( session->writeDemo );
  517. }
  518. if ( ent->gui2 ) {
  519. ent->gui2->WriteToDemoFile( session->writeDemo );
  520. }
  521. if ( ent->gui3 ) {
  522. ent->gui3->WriteToDemoFile( session->writeDemo );
  523. }
  524. #endif
  525. // RENDERDEMO_VERSION >= 2 ( Doom3 1.2 )
  526. session->writeDemo->WriteInt( ent->timeGroup );
  527. session->writeDemo->WriteInt( ent->xrayIndex );
  528. if ( r_showDemo.GetBool() ) {
  529. common->Printf( "write DC_UPDATE_ENTITYDEF: %i = %s\n", handle, ent->hModel ? ent->hModel->Name() : "NULL" );
  530. }
  531. }
  532. /*
  533. ================
  534. ReadRenderEntity
  535. ================
  536. */
  537. void idRenderWorldLocal::ReadRenderEntity() {
  538. renderEntity_t ent;
  539. int index, i;
  540. session->readDemo->ReadInt( index );
  541. if ( index < 0 ) {
  542. common->Error( "ReadRenderEntity: index < 0" );
  543. }
  544. session->readDemo->ReadInt( (int&)ent.hModel );
  545. session->readDemo->ReadInt( ent.entityNum );
  546. session->readDemo->ReadInt( ent.bodyId );
  547. session->readDemo->ReadVec3( ent.bounds[0] );
  548. session->readDemo->ReadVec3( ent.bounds[1] );
  549. session->readDemo->ReadInt( (int&)ent.callback );
  550. session->readDemo->ReadInt( (int&)ent.callbackData );
  551. session->readDemo->ReadInt( ent.suppressSurfaceInViewID );
  552. session->readDemo->ReadInt( ent.suppressShadowInViewID );
  553. session->readDemo->ReadInt( ent.suppressShadowInLightID );
  554. session->readDemo->ReadInt( ent.allowSurfaceInViewID );
  555. session->readDemo->ReadVec3( ent.origin );
  556. session->readDemo->ReadMat3( ent.axis );
  557. session->readDemo->ReadInt( (int&)ent.customShader );
  558. session->readDemo->ReadInt( (int&)ent.referenceShader );
  559. session->readDemo->ReadInt( (int&)ent.customSkin );
  560. session->readDemo->ReadInt( (int&)ent.referenceSound );
  561. for ( i = 0; i < MAX_ENTITY_SHADER_PARMS; i++ ) {
  562. session->readDemo->ReadFloat( ent.shaderParms[i] );
  563. }
  564. for ( i = 0; i < MAX_RENDERENTITY_GUI; i++ ) {
  565. session->readDemo->ReadInt( (int&)ent.gui[i] );
  566. }
  567. session->readDemo->ReadInt( (int&)ent.remoteRenderView );
  568. session->readDemo->ReadInt( ent.numJoints );
  569. session->readDemo->ReadInt( (int&)ent.joints );
  570. session->readDemo->ReadFloat( ent.modelDepthHack );
  571. session->readDemo->ReadBool( ent.noSelfShadow );
  572. session->readDemo->ReadBool( ent.noShadow );
  573. session->readDemo->ReadBool( ent.noDynamicInteractions );
  574. session->readDemo->ReadBool( ent.weaponDepthHack );
  575. session->readDemo->ReadInt( ent.forceUpdate );
  576. ent.callback = NULL;
  577. if ( ent.customShader ) {
  578. ent.customShader = declManager->FindMaterial( session->readDemo->ReadHashString() );
  579. }
  580. if ( ent.customSkin ) {
  581. ent.customSkin = declManager->FindSkin( session->readDemo->ReadHashString() );
  582. }
  583. if ( ent.hModel ) {
  584. ent.hModel = renderModelManager->FindModel( session->readDemo->ReadHashString() );
  585. }
  586. if ( ent.referenceShader ) {
  587. ent.referenceShader = declManager->FindMaterial( session->readDemo->ReadHashString() );
  588. }
  589. if ( ent.referenceSound ) {
  590. int index;
  591. session->readDemo->ReadInt( index );
  592. ent.referenceSound = session->sw->EmitterForIndex( index );
  593. }
  594. if ( ent.numJoints ) {
  595. ent.joints = (idJointMat *)Mem_Alloc16( ent.numJoints * sizeof( ent.joints[0] ) );
  596. for ( int i = 0; i < ent.numJoints; i++) {
  597. float *data = ent.joints[i].ToFloatPtr();
  598. for ( int j = 0; j < 12; ++j)
  599. session->readDemo->ReadFloat( data[j] );
  600. }
  601. }
  602. ent.callbackData = NULL;
  603. /*
  604. if ( ent.decals ) {
  605. ent.decals = idRenderModelDecal::Alloc();
  606. ent.decals->ReadFromDemoFile( session->readDemo );
  607. }
  608. if ( ent.overlay ) {
  609. ent.overlay = idRenderModelOverlay::Alloc();
  610. ent.overlay->ReadFromDemoFile( session->readDemo );
  611. }
  612. */
  613. for ( i = 0; i < MAX_RENDERENTITY_GUI; i++ ) {
  614. if ( ent.gui[ i ] ) {
  615. ent.gui[ i ] = uiManager->Alloc();
  616. #ifdef WRITE_GUIS
  617. ent.gui[ i ]->ReadFromDemoFile( session->readDemo );
  618. #endif
  619. }
  620. }
  621. // >= Doom3 v1.2 only
  622. if ( session->renderdemoVersion >= 2 ) {
  623. session->readDemo->ReadInt( ent.timeGroup );
  624. session->readDemo->ReadInt( ent.xrayIndex );
  625. } else {
  626. ent.timeGroup = 0;
  627. ent.xrayIndex = 0;
  628. }
  629. UpdateEntityDef( index, &ent );
  630. if ( r_showDemo.GetBool() ) {
  631. common->Printf( "DC_UPDATE_ENTITYDEF: %i = %s\n", index, ent.hModel ? ent.hModel->Name() : "NULL" );
  632. }
  633. }