BrittleFracture.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  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 "Game_local.h"
  23. CLASS_DECLARATION( idEntity, idBrittleFracture )
  24. EVENT( EV_Activate, idBrittleFracture::Event_Activate )
  25. EVENT( EV_Touch, idBrittleFracture::Event_Touch )
  26. END_CLASS
  27. const int SHARD_ALIVE_TIME = 5000;
  28. const int SHARD_FADE_START = 2000;
  29. static const char *brittleFracture_SnapshotName = "_BrittleFracture_Snapshot_";
  30. /*
  31. ================
  32. idBrittleFracture::idBrittleFracture
  33. ================
  34. */
  35. idBrittleFracture::idBrittleFracture( void ) {
  36. material = NULL;
  37. decalMaterial = NULL;
  38. decalSize = 0.0f;
  39. maxShardArea = 0.0f;
  40. maxShatterRadius = 0.0f;
  41. minShatterRadius = 0.0f;
  42. linearVelocityScale = 0.0f;
  43. angularVelocityScale = 0.0f;
  44. shardMass = 0.0f;
  45. density = 0.0f;
  46. friction = 0.0f;
  47. bouncyness = 0.0f;
  48. fxFracture.Clear();
  49. bounds.Clear();
  50. disableFracture = false;
  51. lastRenderEntityUpdate = -1;
  52. changed = false;
  53. fl.networkSync = true;
  54. }
  55. /*
  56. ================
  57. idBrittleFracture::~idBrittleFracture
  58. ================
  59. */
  60. idBrittleFracture::~idBrittleFracture( void ) {
  61. int i;
  62. for ( i = 0; i < shards.Num(); i++ ) {
  63. shards[i]->decals.DeleteContents( true );
  64. delete shards[i];
  65. }
  66. // make sure the render entity is freed before the model is freed
  67. FreeModelDef();
  68. renderModelManager->FreeModel( renderEntity.hModel );
  69. }
  70. /*
  71. ================
  72. idBrittleFracture::Save
  73. ================
  74. */
  75. void idBrittleFracture::Save( idSaveGame *savefile ) const {
  76. int i, j;
  77. savefile->WriteInt( health );
  78. entityFlags_s flags = fl;
  79. LittleBitField( &flags, sizeof( flags ) );
  80. savefile->Write( &flags, sizeof( flags ) );
  81. // setttings
  82. savefile->WriteMaterial( material );
  83. savefile->WriteMaterial( decalMaterial );
  84. savefile->WriteFloat( decalSize );
  85. savefile->WriteFloat( maxShardArea );
  86. savefile->WriteFloat( maxShatterRadius );
  87. savefile->WriteFloat( minShatterRadius );
  88. savefile->WriteFloat( linearVelocityScale );
  89. savefile->WriteFloat( angularVelocityScale );
  90. savefile->WriteFloat( shardMass );
  91. savefile->WriteFloat( density );
  92. savefile->WriteFloat( friction );
  93. savefile->WriteFloat( bouncyness );
  94. savefile->WriteString( fxFracture );
  95. // state
  96. savefile->WriteBounds( bounds );
  97. savefile->WriteBool( disableFracture );
  98. savefile->WriteInt( lastRenderEntityUpdate );
  99. savefile->WriteBool( changed );
  100. savefile->WriteStaticObject( physicsObj );
  101. savefile->WriteInt( shards.Num() );
  102. for ( i = 0; i < shards.Num(); i++ ) {
  103. savefile->WriteWinding( shards[i]->winding );
  104. savefile->WriteInt( shards[i]->decals.Num() );
  105. for ( j = 0; j < shards[i]->decals.Num(); j++ ) {
  106. savefile->WriteWinding( *shards[i]->decals[j] );
  107. }
  108. savefile->WriteInt( shards[i]->neighbours.Num() );
  109. for ( j = 0; j < shards[i]->neighbours.Num(); j++ ) {
  110. int index = shards.FindIndex(shards[i]->neighbours[j]);
  111. assert(index != -1);
  112. savefile->WriteInt( index );
  113. }
  114. savefile->WriteInt( shards[i]->edgeHasNeighbour.Num() );
  115. for ( j = 0; j < shards[i]->edgeHasNeighbour.Num(); j++ ) {
  116. savefile->WriteBool( shards[i]->edgeHasNeighbour[j] );
  117. }
  118. savefile->WriteInt( shards[i]->droppedTime );
  119. savefile->WriteInt( shards[i]->islandNum );
  120. savefile->WriteBool( shards[i]->atEdge );
  121. savefile->WriteStaticObject( shards[i]->physicsObj );
  122. }
  123. }
  124. /*
  125. ================
  126. idBrittleFracture::Restore
  127. ================
  128. */
  129. void idBrittleFracture::Restore( idRestoreGame *savefile ) {
  130. int i, j , num;
  131. renderEntity.hModel = renderModelManager->AllocModel();
  132. renderEntity.hModel->InitEmpty( brittleFracture_SnapshotName );
  133. renderEntity.callback = idBrittleFracture::ModelCallback;
  134. renderEntity.noShadow = true;
  135. renderEntity.noSelfShadow = true;
  136. renderEntity.noDynamicInteractions = false;
  137. savefile->ReadInt( health );
  138. savefile->Read( &fl, sizeof( fl ) );
  139. LittleBitField( &fl, sizeof( fl ) );
  140. // setttings
  141. savefile->ReadMaterial( material );
  142. savefile->ReadMaterial( decalMaterial );
  143. savefile->ReadFloat( decalSize );
  144. savefile->ReadFloat( maxShardArea );
  145. savefile->ReadFloat( maxShatterRadius );
  146. savefile->ReadFloat( minShatterRadius );
  147. savefile->ReadFloat( linearVelocityScale );
  148. savefile->ReadFloat( angularVelocityScale );
  149. savefile->ReadFloat( shardMass );
  150. savefile->ReadFloat( density );
  151. savefile->ReadFloat( friction );
  152. savefile->ReadFloat( bouncyness );
  153. savefile->ReadString( fxFracture );
  154. // state
  155. savefile->ReadBounds(bounds);
  156. savefile->ReadBool( disableFracture );
  157. savefile->ReadInt( lastRenderEntityUpdate );
  158. savefile->ReadBool( changed );
  159. savefile->ReadStaticObject( physicsObj );
  160. RestorePhysics( &physicsObj );
  161. savefile->ReadInt( num );
  162. shards.SetNum( num );
  163. for ( i = 0; i < num; i++ ) {
  164. shards[i] = new shard_t;
  165. }
  166. for ( i = 0; i < num; i++ ) {
  167. savefile->ReadWinding( shards[i]->winding );
  168. savefile->ReadInt( j );
  169. shards[i]->decals.SetNum( j );
  170. for ( j = 0; j < shards[i]->decals.Num(); j++ ) {
  171. shards[i]->decals[j] = new idFixedWinding;
  172. savefile->ReadWinding( *shards[i]->decals[j] );
  173. }
  174. savefile->ReadInt( j );
  175. shards[i]->neighbours.SetNum( j );
  176. for ( j = 0; j < shards[i]->neighbours.Num(); j++ ) {
  177. int index;
  178. savefile->ReadInt( index );
  179. assert(index != -1);
  180. shards[i]->neighbours[j] = shards[index];
  181. }
  182. savefile->ReadInt( j );
  183. shards[i]->edgeHasNeighbour.SetNum( j );
  184. for ( j = 0; j < shards[i]->edgeHasNeighbour.Num(); j++ ) {
  185. savefile->ReadBool( shards[i]->edgeHasNeighbour[j] );
  186. }
  187. savefile->ReadInt( shards[i]->droppedTime );
  188. savefile->ReadInt( shards[i]->islandNum );
  189. savefile->ReadBool( shards[i]->atEdge );
  190. savefile->ReadStaticObject( shards[i]->physicsObj );
  191. if ( shards[i]->droppedTime < 0 ) {
  192. shards[i]->clipModel = physicsObj.GetClipModel( i );
  193. } else {
  194. shards[i]->clipModel = shards[i]->physicsObj.GetClipModel();
  195. }
  196. }
  197. }
  198. /*
  199. ================
  200. idBrittleFracture::Spawn
  201. ================
  202. */
  203. void idBrittleFracture::Spawn( void ) {
  204. // get shard properties
  205. decalMaterial = declManager->FindMaterial( spawnArgs.GetString( "mtr_decal" ) );
  206. decalSize = spawnArgs.GetFloat( "decalSize", "40" );
  207. maxShardArea = spawnArgs.GetFloat( "maxShardArea", "200" );
  208. maxShardArea = idMath::ClampFloat( 100, 10000, maxShardArea );
  209. maxShatterRadius = spawnArgs.GetFloat( "maxShatterRadius", "40" );
  210. minShatterRadius = spawnArgs.GetFloat( "minShatterRadius", "10" );
  211. linearVelocityScale = spawnArgs.GetFloat( "linearVelocityScale", "0.1" );
  212. angularVelocityScale = spawnArgs.GetFloat( "angularVelocityScale", "40" );
  213. fxFracture = spawnArgs.GetString( "fx" );
  214. // get rigid body properties
  215. shardMass = spawnArgs.GetFloat( "shardMass", "20" );
  216. shardMass = idMath::ClampFloat( 0.001f, 1000.0f, shardMass );
  217. spawnArgs.GetFloat( "density", "0.1", density );
  218. density = idMath::ClampFloat( 0.001f, 1000.0f, density );
  219. spawnArgs.GetFloat( "friction", "0.4", friction );
  220. friction = idMath::ClampFloat( 0.0f, 1.0f, friction );
  221. spawnArgs.GetFloat( "bouncyness", "0.01", bouncyness );
  222. bouncyness = idMath::ClampFloat( 0.0f, 1.0f, bouncyness );
  223. disableFracture = spawnArgs.GetBool( "disableFracture", "0" );
  224. health = spawnArgs.GetInt( "health", "40" );
  225. fl.takedamage = true;
  226. // FIXME: set "bleed" so idProjectile calls AddDamageEffect
  227. spawnArgs.SetBool( "bleed", 1 );
  228. CreateFractures( renderEntity.hModel );
  229. FindNeighbours();
  230. renderEntity.hModel = renderModelManager->AllocModel();
  231. renderEntity.hModel->InitEmpty( brittleFracture_SnapshotName );
  232. renderEntity.callback = idBrittleFracture::ModelCallback;
  233. renderEntity.noShadow = true;
  234. renderEntity.noSelfShadow = true;
  235. renderEntity.noDynamicInteractions = false;
  236. }
  237. /*
  238. ================
  239. idBrittleFracture::AddShard
  240. ================
  241. */
  242. void idBrittleFracture::AddShard( idClipModel *clipModel, idFixedWinding &w ) {
  243. shard_t *shard = new shard_t;
  244. shard->clipModel = clipModel;
  245. shard->droppedTime = -1;
  246. shard->winding = w;
  247. shard->decals.Clear();
  248. shard->edgeHasNeighbour.AssureSize( w.GetNumPoints(), false );
  249. shard->neighbours.Clear();
  250. shard->atEdge = false;
  251. shards.Append( shard );
  252. }
  253. /*
  254. ================
  255. idBrittleFracture::RemoveShard
  256. ================
  257. */
  258. void idBrittleFracture::RemoveShard( int index ) {
  259. int i;
  260. delete shards[index];
  261. shards.RemoveIndex( index );
  262. physicsObj.RemoveIndex( index );
  263. for ( i = index; i < shards.Num(); i++ ) {
  264. shards[i]->clipModel->SetId( i );
  265. }
  266. }
  267. /*
  268. ================
  269. idBrittleFracture::UpdateRenderEntity
  270. ================
  271. */
  272. bool idBrittleFracture::UpdateRenderEntity( renderEntity_s *renderEntity, const renderView_t *renderView ) const {
  273. int i, j, k, n, msec, numTris, numDecalTris;
  274. float fade;
  275. dword packedColor;
  276. srfTriangles_t *tris, *decalTris;
  277. modelSurface_t surface;
  278. idDrawVert *v;
  279. idPlane plane;
  280. idMat3 tangents;
  281. // this may be triggered by a model trace or other non-view related source,
  282. // to which we should look like an empty model
  283. if ( !renderView ) {
  284. return false;
  285. }
  286. // don't regenerate it if it is current
  287. if ( lastRenderEntityUpdate == gameLocal.time || !changed ) {
  288. return false;
  289. }
  290. lastRenderEntityUpdate = gameLocal.time;
  291. changed = false;
  292. numTris = 0;
  293. numDecalTris = 0;
  294. for ( i = 0; i < shards.Num(); i++ ) {
  295. n = shards[i]->winding.GetNumPoints();
  296. if ( n > 2 ) {
  297. numTris += n - 2;
  298. }
  299. for ( k = 0; k < shards[i]->decals.Num(); k++ ) {
  300. n = shards[i]->decals[k]->GetNumPoints();
  301. if ( n > 2 ) {
  302. numDecalTris += n - 2;
  303. }
  304. }
  305. }
  306. // FIXME: re-use model surfaces
  307. renderEntity->hModel->InitEmpty( brittleFracture_SnapshotName );
  308. // allocate triangle surfaces for the fractures and decals
  309. tris = renderEntity->hModel->AllocSurfaceTriangles( numTris * 3, material->ShouldCreateBackSides() ? numTris * 6 : numTris * 3 );
  310. decalTris = renderEntity->hModel->AllocSurfaceTriangles( numDecalTris * 3, decalMaterial->ShouldCreateBackSides() ? numDecalTris * 6 : numDecalTris * 3 );
  311. for ( i = 0; i < shards.Num(); i++ ) {
  312. const idVec3 &origin = shards[i]->clipModel->GetOrigin();
  313. const idMat3 &axis = shards[i]->clipModel->GetAxis();
  314. fade = 1.0f;
  315. if ( shards[i]->droppedTime >= 0 ) {
  316. msec = gameLocal.time - shards[i]->droppedTime - SHARD_FADE_START;
  317. if ( msec > 0 ) {
  318. fade = 1.0f - (float) msec / ( SHARD_ALIVE_TIME - SHARD_FADE_START );
  319. }
  320. }
  321. packedColor = PackColor( idVec4( renderEntity->shaderParms[ SHADERPARM_RED ] * fade,
  322. renderEntity->shaderParms[ SHADERPARM_GREEN ] * fade,
  323. renderEntity->shaderParms[ SHADERPARM_BLUE ] * fade,
  324. fade ) );
  325. const idWinding &winding = shards[i]->winding;
  326. winding.GetPlane( plane );
  327. tangents = ( plane.Normal() * axis ).ToMat3();
  328. for ( j = 2; j < winding.GetNumPoints(); j++ ) {
  329. v = &tris->verts[tris->numVerts++];
  330. v->Clear();
  331. v->xyz = origin + winding[0].ToVec3() * axis;
  332. v->st[0] = winding[0].s;
  333. v->st[1] = winding[0].t;
  334. v->normal = tangents[0];
  335. v->tangents[0] = tangents[1];
  336. v->tangents[1] = tangents[2];
  337. v->SetColor( packedColor );
  338. v = &tris->verts[tris->numVerts++];
  339. v->Clear();
  340. v->xyz = origin + winding[j-1].ToVec3() * axis;
  341. v->st[0] = winding[j-1].s;
  342. v->st[1] = winding[j-1].t;
  343. v->normal = tangents[0];
  344. v->tangents[0] = tangents[1];
  345. v->tangents[1] = tangents[2];
  346. v->SetColor( packedColor );
  347. v = &tris->verts[tris->numVerts++];
  348. v->Clear();
  349. v->xyz = origin + winding[j].ToVec3() * axis;
  350. v->st[0] = winding[j].s;
  351. v->st[1] = winding[j].t;
  352. v->normal = tangents[0];
  353. v->tangents[0] = tangents[1];
  354. v->tangents[1] = tangents[2];
  355. v->SetColor( packedColor );
  356. tris->indexes[tris->numIndexes++] = tris->numVerts - 3;
  357. tris->indexes[tris->numIndexes++] = tris->numVerts - 2;
  358. tris->indexes[tris->numIndexes++] = tris->numVerts - 1;
  359. if ( material->ShouldCreateBackSides() ) {
  360. tris->indexes[tris->numIndexes++] = tris->numVerts - 2;
  361. tris->indexes[tris->numIndexes++] = tris->numVerts - 3;
  362. tris->indexes[tris->numIndexes++] = tris->numVerts - 1;
  363. }
  364. }
  365. for ( k = 0; k < shards[i]->decals.Num(); k++ ) {
  366. const idWinding &decalWinding = *shards[i]->decals[k];
  367. for ( j = 2; j < decalWinding.GetNumPoints(); j++ ) {
  368. v = &decalTris->verts[decalTris->numVerts++];
  369. v->Clear();
  370. v->xyz = origin + decalWinding[0].ToVec3() * axis;
  371. v->st[0] = decalWinding[0].s;
  372. v->st[1] = decalWinding[0].t;
  373. v->normal = tangents[0];
  374. v->tangents[0] = tangents[1];
  375. v->tangents[1] = tangents[2];
  376. v->SetColor( packedColor );
  377. v = &decalTris->verts[decalTris->numVerts++];
  378. v->Clear();
  379. v->xyz = origin + decalWinding[j-1].ToVec3() * axis;
  380. v->st[0] = decalWinding[j-1].s;
  381. v->st[1] = decalWinding[j-1].t;
  382. v->normal = tangents[0];
  383. v->tangents[0] = tangents[1];
  384. v->tangents[1] = tangents[2];
  385. v->SetColor( packedColor );
  386. v = &decalTris->verts[decalTris->numVerts++];
  387. v->Clear();
  388. v->xyz = origin + decalWinding[j].ToVec3() * axis;
  389. v->st[0] = decalWinding[j].s;
  390. v->st[1] = decalWinding[j].t;
  391. v->normal = tangents[0];
  392. v->tangents[0] = tangents[1];
  393. v->tangents[1] = tangents[2];
  394. v->SetColor( packedColor );
  395. decalTris->indexes[decalTris->numIndexes++] = decalTris->numVerts - 3;
  396. decalTris->indexes[decalTris->numIndexes++] = decalTris->numVerts - 2;
  397. decalTris->indexes[decalTris->numIndexes++] = decalTris->numVerts - 1;
  398. if ( decalMaterial->ShouldCreateBackSides() ) {
  399. decalTris->indexes[decalTris->numIndexes++] = decalTris->numVerts - 2;
  400. decalTris->indexes[decalTris->numIndexes++] = decalTris->numVerts - 3;
  401. decalTris->indexes[decalTris->numIndexes++] = decalTris->numVerts - 1;
  402. }
  403. }
  404. }
  405. }
  406. tris->tangentsCalculated = true;
  407. decalTris->tangentsCalculated = true;
  408. SIMDProcessor->MinMax( tris->bounds[0], tris->bounds[1], tris->verts, tris->numVerts );
  409. SIMDProcessor->MinMax( decalTris->bounds[0], decalTris->bounds[1], decalTris->verts, decalTris->numVerts );
  410. memset( &surface, 0, sizeof( surface ) );
  411. surface.shader = material;
  412. surface.id = 0;
  413. surface.geometry = tris;
  414. renderEntity->hModel->AddSurface( surface );
  415. memset( &surface, 0, sizeof( surface ) );
  416. surface.shader = decalMaterial;
  417. surface.id = 1;
  418. surface.geometry = decalTris;
  419. renderEntity->hModel->AddSurface( surface );
  420. return true;
  421. }
  422. /*
  423. ================
  424. idBrittleFracture::ModelCallback
  425. ================
  426. */
  427. bool idBrittleFracture::ModelCallback( renderEntity_s *renderEntity, const renderView_t *renderView ) {
  428. const idBrittleFracture *ent;
  429. ent = static_cast<idBrittleFracture *>(gameLocal.entities[ renderEntity->entityNum ]);
  430. if ( !ent ) {
  431. gameLocal.Error( "idBrittleFracture::ModelCallback: callback with NULL game entity" );
  432. }
  433. return ent->UpdateRenderEntity( renderEntity, renderView );
  434. }
  435. /*
  436. ================
  437. idBrittleFracture::Present
  438. ================
  439. */
  440. void idBrittleFracture::Present() {
  441. // don't present to the renderer if the entity hasn't changed
  442. if ( !( thinkFlags & TH_UPDATEVISUALS ) ) {
  443. return;
  444. }
  445. BecomeInactive( TH_UPDATEVISUALS );
  446. renderEntity.bounds = bounds;
  447. renderEntity.origin.Zero();
  448. renderEntity.axis.Identity();
  449. // force an update because the bounds/origin/axis may stay the same while the model changes
  450. renderEntity.forceUpdate = true;
  451. // add to refresh list
  452. if ( modelDefHandle == -1 ) {
  453. modelDefHandle = gameRenderWorld->AddEntityDef( &renderEntity );
  454. } else {
  455. gameRenderWorld->UpdateEntityDef( modelDefHandle, &renderEntity );
  456. }
  457. changed = true;
  458. }
  459. /*
  460. ================
  461. idBrittleFracture::Think
  462. ================
  463. */
  464. void idBrittleFracture::Think( void ) {
  465. int i, startTime, endTime, droppedTime;
  466. shard_t *shard;
  467. bool atRest = true, fading = false;
  468. // remove overdue shards
  469. for ( i = 0; i < shards.Num(); i++ ) {
  470. droppedTime = shards[i]->droppedTime;
  471. if ( droppedTime != -1 ) {
  472. if ( gameLocal.time - droppedTime > SHARD_ALIVE_TIME ) {
  473. RemoveShard( i );
  474. i--;
  475. }
  476. fading = true;
  477. }
  478. }
  479. // remove the entity when nothing is visible
  480. if ( !shards.Num() ) {
  481. PostEventMS( &EV_Remove, 0 );
  482. return;
  483. }
  484. if ( thinkFlags & TH_PHYSICS ) {
  485. startTime = gameLocal.previousTime;
  486. endTime = gameLocal.time;
  487. // run physics on shards
  488. for ( i = 0; i < shards.Num(); i++ ) {
  489. shard = shards[i];
  490. if ( shard->droppedTime == -1 ) {
  491. continue;
  492. }
  493. shard->physicsObj.Evaluate( endTime - startTime, endTime );
  494. if ( !shard->physicsObj.IsAtRest() ) {
  495. atRest = false;
  496. }
  497. }
  498. if ( atRest ) {
  499. BecomeInactive( TH_PHYSICS );
  500. } else {
  501. BecomeActive( TH_PHYSICS );
  502. }
  503. }
  504. if ( !atRest || bounds.IsCleared() ) {
  505. bounds.Clear();
  506. for ( i = 0; i < shards.Num(); i++ ) {
  507. bounds.AddBounds( shards[i]->clipModel->GetAbsBounds() );
  508. }
  509. }
  510. if ( fading ) {
  511. BecomeActive( TH_UPDATEVISUALS | TH_THINK );
  512. } else {
  513. BecomeInactive( TH_THINK );
  514. }
  515. RunPhysics();
  516. Present();
  517. }
  518. /*
  519. ================
  520. idBrittleFracture::ApplyImpulse
  521. ================
  522. */
  523. void idBrittleFracture::ApplyImpulse( idEntity *ent, int id, const idVec3 &point, const idVec3 &impulse ) {
  524. if ( id < 0 || id >= shards.Num() ) {
  525. return;
  526. }
  527. if ( shards[id]->droppedTime != -1 ) {
  528. shards[id]->physicsObj.ApplyImpulse( 0, point, impulse );
  529. } else if ( health <= 0 && !disableFracture ) {
  530. Shatter( point, impulse, gameLocal.time );
  531. }
  532. }
  533. /*
  534. ================
  535. idBrittleFracture::AddForce
  536. ================
  537. */
  538. void idBrittleFracture::AddForce( idEntity *ent, int id, const idVec3 &point, const idVec3 &force ) {
  539. if ( id < 0 || id >= shards.Num() ) {
  540. return;
  541. }
  542. if ( shards[id]->droppedTime != -1 ) {
  543. shards[id]->physicsObj.AddForce( 0, point, force );
  544. } else if ( health <= 0 && !disableFracture ) {
  545. Shatter( point, force, gameLocal.time );
  546. }
  547. }
  548. /*
  549. ================
  550. idBrittleFracture::ProjectDecal
  551. ================
  552. */
  553. void idBrittleFracture::ProjectDecal( const idVec3 &point, const idVec3 &dir, const int time, const char *damageDefName ) {
  554. int i, j, bits, clipBits;
  555. float a, c, s;
  556. idVec2 st[MAX_POINTS_ON_WINDING];
  557. idVec3 origin;
  558. idMat3 axis, axistemp;
  559. idPlane textureAxis[2];
  560. if ( gameLocal.isServer ) {
  561. idBitMsg msg;
  562. byte msgBuf[MAX_EVENT_PARAM_SIZE];
  563. msg.Init( msgBuf, sizeof( msgBuf ) );
  564. msg.BeginWriting();
  565. msg.WriteFloat( point[0] );
  566. msg.WriteFloat( point[1] );
  567. msg.WriteFloat( point[2] );
  568. msg.WriteFloat( dir[0] );
  569. msg.WriteFloat( dir[1] );
  570. msg.WriteFloat( dir[2] );
  571. ServerSendEvent( EVENT_PROJECT_DECAL, &msg, true, -1 );
  572. }
  573. if ( time >= gameLocal.time ) {
  574. // try to get the sound from the damage def
  575. const idDeclEntityDef *damageDef = NULL;
  576. const idSoundShader *sndShader = NULL;
  577. if ( damageDefName ) {
  578. damageDef = gameLocal.FindEntityDef( damageDefName, false );
  579. if ( damageDef ) {
  580. sndShader = declManager->FindSound( damageDef->dict.GetString( "snd_shatter", "" ) );
  581. }
  582. }
  583. if ( sndShader ) {
  584. StartSoundShader( sndShader, SND_CHANNEL_ANY, 0, false, NULL );
  585. } else {
  586. StartSound( "snd_bullethole", SND_CHANNEL_ANY, 0, false, NULL );
  587. }
  588. }
  589. a = gameLocal.random.RandomFloat() * idMath::TWO_PI;
  590. c = cos( a );
  591. s = -sin( a );
  592. axis[2] = -dir;
  593. axis[2].Normalize();
  594. axis[2].NormalVectors( axistemp[0], axistemp[1] );
  595. axis[0] = axistemp[ 0 ] * c + axistemp[ 1 ] * s;
  596. axis[1] = axistemp[ 0 ] * s + axistemp[ 1 ] * -c;
  597. textureAxis[0] = axis[0] * ( 1.0f / decalSize );
  598. textureAxis[0][3] = -( point * textureAxis[0].Normal() ) + 0.5f;
  599. textureAxis[1] = axis[1] * ( 1.0f / decalSize );
  600. textureAxis[1][3] = -( point * textureAxis[1].Normal() ) + 0.5f;
  601. for ( i = 0; i < shards.Num(); i++ ) {
  602. idFixedWinding &winding = shards[i]->winding;
  603. origin = shards[i]->clipModel->GetOrigin();
  604. axis = shards[i]->clipModel->GetAxis();
  605. float d0, d1;
  606. clipBits = -1;
  607. for ( j = 0; j < winding.GetNumPoints(); j++ ) {
  608. idVec3 p = origin + winding[j].ToVec3() * axis;
  609. st[j].x = d0 = textureAxis[0].Distance( p );
  610. st[j].y = d1 = textureAxis[1].Distance( p );
  611. bits = FLOATSIGNBITSET( d0 );
  612. d0 = 1.0f - d0;
  613. bits |= FLOATSIGNBITSET( d1 ) << 2;
  614. d1 = 1.0f - d1;
  615. bits |= FLOATSIGNBITSET( d0 ) << 1;
  616. bits |= FLOATSIGNBITSET( d1 ) << 3;
  617. clipBits &= bits;
  618. }
  619. if ( clipBits ) {
  620. continue;
  621. }
  622. idFixedWinding *decal = new idFixedWinding;
  623. shards[i]->decals.Append( decal );
  624. decal->SetNumPoints( winding.GetNumPoints() );
  625. for ( j = 0; j < winding.GetNumPoints(); j++ ) {
  626. (*decal)[j].ToVec3() = winding[j].ToVec3();
  627. (*decal)[j].s = st[j].x;
  628. (*decal)[j].t = st[j].y;
  629. }
  630. }
  631. BecomeActive( TH_UPDATEVISUALS );
  632. }
  633. /*
  634. ================
  635. idBrittleFracture::DropShard
  636. ================
  637. */
  638. void idBrittleFracture::DropShard( shard_t *shard, const idVec3 &point, const idVec3 &dir, const float impulse, const int time ) {
  639. int i, j, clipModelId;
  640. float dist, f;
  641. idVec3 dir2, origin;
  642. idMat3 axis;
  643. shard_t *neighbour;
  644. // don't display decals on dropped shards
  645. shard->decals.DeleteContents( true );
  646. // remove neighbour pointers of neighbours pointing to this shard
  647. for ( i = 0; i < shard->neighbours.Num(); i++ ) {
  648. neighbour = shard->neighbours[i];
  649. for ( j = 0; j < neighbour->neighbours.Num(); j++ ) {
  650. if ( neighbour->neighbours[j] == shard ) {
  651. neighbour->neighbours.RemoveIndex( j );
  652. break;
  653. }
  654. }
  655. }
  656. // remove neighbour pointers
  657. shard->neighbours.Clear();
  658. // remove the clip model from the static physics object
  659. clipModelId = shard->clipModel->GetId();
  660. physicsObj.SetClipModel( NULL, 1.0f, clipModelId, false );
  661. origin = shard->clipModel->GetOrigin();
  662. axis = shard->clipModel->GetAxis();
  663. // set the dropped time for fading
  664. shard->droppedTime = time;
  665. dir2 = origin - point;
  666. dist = dir2.Normalize();
  667. f = dist > maxShatterRadius ? 1.0f : idMath::Sqrt( dist - minShatterRadius ) * ( 1.0f / idMath::Sqrt( maxShatterRadius - minShatterRadius ) );
  668. // setup the physics
  669. shard->physicsObj.SetSelf( this );
  670. shard->physicsObj.SetClipModel( shard->clipModel, density );
  671. shard->physicsObj.SetMass( shardMass );
  672. shard->physicsObj.SetOrigin( origin );
  673. shard->physicsObj.SetAxis( axis );
  674. shard->physicsObj.SetBouncyness( bouncyness );
  675. shard->physicsObj.SetFriction( 0.6f, 0.6f, friction );
  676. shard->physicsObj.SetGravity( gameLocal.GetGravity() );
  677. shard->physicsObj.SetContents( CONTENTS_RENDERMODEL );
  678. shard->physicsObj.SetClipMask( MASK_SOLID | CONTENTS_MOVEABLECLIP );
  679. shard->physicsObj.ApplyImpulse( 0, origin, impulse * linearVelocityScale * dir );
  680. shard->physicsObj.SetAngularVelocity( dir.Cross( dir2 ) * ( f * angularVelocityScale ) );
  681. shard->clipModel->SetId( clipModelId );
  682. BecomeActive( TH_PHYSICS );
  683. }
  684. /*
  685. ================
  686. idBrittleFracture::Shatter
  687. ================
  688. */
  689. void idBrittleFracture::Shatter( const idVec3 &point, const idVec3 &impulse, const int time ) {
  690. int i;
  691. idVec3 dir;
  692. shard_t *shard;
  693. float m;
  694. if ( gameLocal.isServer ) {
  695. idBitMsg msg;
  696. byte msgBuf[MAX_EVENT_PARAM_SIZE];
  697. msg.Init( msgBuf, sizeof( msgBuf ) );
  698. msg.BeginWriting();
  699. msg.WriteFloat( point[0] );
  700. msg.WriteFloat( point[1] );
  701. msg.WriteFloat( point[2] );
  702. msg.WriteFloat( impulse[0] );
  703. msg.WriteFloat( impulse[1] );
  704. msg.WriteFloat( impulse[2] );
  705. ServerSendEvent( EVENT_SHATTER, &msg, true, -1 );
  706. }
  707. if ( time > ( gameLocal.time - SHARD_ALIVE_TIME ) ) {
  708. StartSound( "snd_shatter", SND_CHANNEL_ANY, 0, false, NULL );
  709. }
  710. if ( !IsBroken() ) {
  711. Break();
  712. }
  713. if ( fxFracture.Length() ) {
  714. idEntityFx::StartFx( fxFracture, &point, &GetPhysics()->GetAxis(), this, true );
  715. }
  716. dir = impulse;
  717. m = dir.Normalize();
  718. for ( i = 0; i < shards.Num(); i++ ) {
  719. shard = shards[i];
  720. if ( shard->droppedTime != -1 ) {
  721. continue;
  722. }
  723. if ( ( shard->clipModel->GetOrigin() - point ).LengthSqr() > Square( maxShatterRadius ) ) {
  724. continue;
  725. }
  726. DropShard( shard, point, dir, m, time );
  727. }
  728. DropFloatingIslands( point, impulse, time );
  729. }
  730. /*
  731. ================
  732. idBrittleFracture::DropFloatingIslands
  733. ================
  734. */
  735. void idBrittleFracture::DropFloatingIslands( const idVec3 &point, const idVec3 &impulse, const int time ) {
  736. int i, j, numIslands;
  737. int queueStart, queueEnd;
  738. shard_t *curShard, *nextShard, **queue;
  739. bool touchesEdge;
  740. idVec3 dir;
  741. dir = impulse;
  742. dir.Normalize();
  743. numIslands = 0;
  744. queue = (shard_t **) _alloca16( shards.Num() * sizeof(shard_t **) );
  745. for ( i = 0; i < shards.Num(); i++ ) {
  746. shards[i]->islandNum = 0;
  747. }
  748. for ( i = 0; i < shards.Num(); i++ ) {
  749. if ( shards[i]->droppedTime != -1 ) {
  750. continue;
  751. }
  752. if ( shards[i]->islandNum ) {
  753. continue;
  754. }
  755. queueStart = 0;
  756. queueEnd = 1;
  757. queue[0] = shards[i];
  758. shards[i]->islandNum = numIslands+1;
  759. touchesEdge = false;
  760. if ( shards[i]->atEdge ) {
  761. touchesEdge = true;
  762. }
  763. for ( curShard = queue[queueStart]; queueStart < queueEnd; curShard = queue[++queueStart] ) {
  764. for ( j = 0; j < curShard->neighbours.Num(); j++ ) {
  765. nextShard = curShard->neighbours[j];
  766. if ( nextShard->droppedTime != -1 ) {
  767. continue;
  768. }
  769. if ( nextShard->islandNum ) {
  770. continue;
  771. }
  772. queue[queueEnd++] = nextShard;
  773. nextShard->islandNum = numIslands+1;
  774. if ( nextShard->atEdge ) {
  775. touchesEdge = true;
  776. }
  777. }
  778. }
  779. numIslands++;
  780. // if the island is not connected to the world at any edges
  781. if ( !touchesEdge ) {
  782. for ( j = 0; j < queueEnd; j++ ) {
  783. DropShard( queue[j], point, dir, 0.0f, time );
  784. }
  785. }
  786. }
  787. }
  788. /*
  789. ================
  790. idBrittleFracture::Break
  791. ================
  792. */
  793. void idBrittleFracture::Break( void ) {
  794. fl.takedamage = false;
  795. physicsObj.SetContents( CONTENTS_RENDERMODEL | CONTENTS_TRIGGER );
  796. }
  797. /*
  798. ================
  799. idBrittleFracture::IsBroken
  800. ================
  801. */
  802. bool idBrittleFracture::IsBroken( void ) const {
  803. return ( fl.takedamage == false );
  804. }
  805. /*
  806. ================
  807. idBrittleFracture::Killed
  808. ================
  809. */
  810. void idBrittleFracture::Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location ) {
  811. if ( !disableFracture ) {
  812. ActivateTargets( this );
  813. Break();
  814. }
  815. }
  816. /*
  817. ================
  818. idBrittleFracture::AddDamageEffect
  819. ================
  820. */
  821. void idBrittleFracture::AddDamageEffect( const trace_t &collision, const idVec3 &velocity, const char *damageDefName ) {
  822. if ( !disableFracture ) {
  823. ProjectDecal( collision.c.point, collision.c.normal, gameLocal.time, damageDefName );
  824. }
  825. }
  826. /*
  827. ================
  828. idBrittleFracture::Fracture_r
  829. ================
  830. */
  831. void idBrittleFracture::Fracture_r( idFixedWinding &w ) {
  832. int i, j, bestPlane;
  833. float a, c, s, dist, bestDist;
  834. idVec3 origin;
  835. idPlane windingPlane, splitPlanes[2];
  836. idMat3 axis, axistemp;
  837. idFixedWinding back;
  838. idTraceModel trm;
  839. idClipModel *clipModel;
  840. while( 1 ) {
  841. origin = w.GetCenter();
  842. w.GetPlane( windingPlane );
  843. if ( w.GetArea() < maxShardArea ) {
  844. break;
  845. }
  846. // randomly create a split plane
  847. a = gameLocal.random.RandomFloat() * idMath::TWO_PI;
  848. c = cos( a );
  849. s = -sin( a );
  850. axis[2] = windingPlane.Normal();
  851. axis[2].NormalVectors( axistemp[0], axistemp[1] );
  852. axis[0] = axistemp[ 0 ] * c + axistemp[ 1 ] * s;
  853. axis[1] = axistemp[ 0 ] * s + axistemp[ 1 ] * -c;
  854. // get the best split plane
  855. bestDist = 0.0f;
  856. bestPlane = 0;
  857. for ( i = 0; i < 2; i++ ) {
  858. splitPlanes[i].SetNormal( axis[i] );
  859. splitPlanes[i].FitThroughPoint( origin );
  860. for ( j = 0; j < w.GetNumPoints(); j++ ) {
  861. dist = splitPlanes[i].Distance( w[j].ToVec3() );
  862. if ( dist > bestDist ) {
  863. bestDist = dist;
  864. bestPlane = i;
  865. }
  866. }
  867. }
  868. // split the winding
  869. if ( !w.Split( &back, splitPlanes[bestPlane] ) ) {
  870. break;
  871. }
  872. // recursively create shards for the back winding
  873. Fracture_r( back );
  874. }
  875. // translate the winding to it's center
  876. origin = w.GetCenter();
  877. for ( j = 0; j < w.GetNumPoints(); j++ ) {
  878. w[j].ToVec3() -= origin;
  879. }
  880. w.RemoveEqualPoints();
  881. trm.SetupPolygon( w );
  882. trm.Shrink( CM_CLIP_EPSILON );
  883. clipModel = new idClipModel( trm );
  884. physicsObj.SetClipModel( clipModel, 1.0f, shards.Num() );
  885. physicsObj.SetOrigin( GetPhysics()->GetOrigin() + origin, shards.Num() );
  886. physicsObj.SetAxis( GetPhysics()->GetAxis(), shards.Num() );
  887. AddShard( clipModel, w );
  888. }
  889. /*
  890. ================
  891. idBrittleFracture::CreateFractures
  892. ================
  893. */
  894. void idBrittleFracture::CreateFractures( const idRenderModel *renderModel ) {
  895. int i, j, k;
  896. const modelSurface_t *surf;
  897. const idDrawVert *v;
  898. idFixedWinding w;
  899. if ( !renderModel ) {
  900. return;
  901. }
  902. physicsObj.SetSelf( this );
  903. physicsObj.SetOrigin( GetPhysics()->GetOrigin(), 0 );
  904. physicsObj.SetAxis( GetPhysics()->GetAxis(), 0 );
  905. for ( i = 0; i < 1 /*renderModel->NumSurfaces()*/; i++ ) {
  906. surf = renderModel->Surface( i );
  907. material = surf->shader;
  908. for ( j = 0; j < surf->geometry->numIndexes; j += 3 ) {
  909. w.Clear();
  910. for ( k = 0; k < 3; k++ ) {
  911. v = &surf->geometry->verts[ surf->geometry->indexes[ j + 2 - k ] ];
  912. w.AddPoint( v->xyz );
  913. w[k].s = v->st[0];
  914. w[k].t = v->st[1];
  915. }
  916. Fracture_r( w );
  917. }
  918. }
  919. physicsObj.SetContents( material->GetContentFlags() );
  920. SetPhysics( &physicsObj );
  921. }
  922. /*
  923. ================
  924. idBrittleFracture::FindNeighbours
  925. ================
  926. */
  927. void idBrittleFracture::FindNeighbours( void ) {
  928. int i, j, k, l;
  929. idVec3 p1, p2, dir;
  930. idMat3 axis;
  931. idPlane plane[4];
  932. for ( i = 0; i < shards.Num(); i++ ) {
  933. shard_t *shard1 = shards[i];
  934. const idWinding &w1 = shard1->winding;
  935. const idVec3 &origin1 = shard1->clipModel->GetOrigin();
  936. const idMat3 &axis1 = shard1->clipModel->GetAxis();
  937. for ( k = 0; k < w1.GetNumPoints(); k++ ) {
  938. p1 = origin1 + w1[k].ToVec3() * axis1;
  939. p2 = origin1 + w1[(k+1)%w1.GetNumPoints()].ToVec3() * axis1;
  940. dir = p2 - p1;
  941. dir.Normalize();
  942. axis = dir.ToMat3();
  943. plane[0].SetNormal( dir );
  944. plane[0].FitThroughPoint( p1 );
  945. plane[1].SetNormal( -dir );
  946. plane[1].FitThroughPoint( p2 );
  947. plane[2].SetNormal( axis[1] );
  948. plane[2].FitThroughPoint( p1 );
  949. plane[3].SetNormal( axis[2] );
  950. plane[3].FitThroughPoint( p1 );
  951. for ( j = 0; j < shards.Num(); j++ ) {
  952. if ( i == j ) {
  953. continue;
  954. }
  955. shard_t *shard2 = shards[j];
  956. for ( l = 0; l < shard1->neighbours.Num(); l++ ) {
  957. if ( shard1->neighbours[l] == shard2 ) {
  958. break;
  959. }
  960. }
  961. if ( l < shard1->neighbours.Num() ) {
  962. continue;
  963. }
  964. const idWinding &w2 = shard2->winding;
  965. const idVec3 &origin2 = shard2->clipModel->GetOrigin();
  966. const idMat3 &axis2 = shard2->clipModel->GetAxis();
  967. for ( l = w2.GetNumPoints()-1; l >= 0; l-- ) {
  968. p1 = origin2 + w2[l].ToVec3() * axis2;
  969. p2 = origin2 + w2[(l-1+w2.GetNumPoints())%w2.GetNumPoints()].ToVec3() * axis2;
  970. if ( plane[0].Side( p2, 0.1f ) == SIDE_FRONT && plane[1].Side( p1, 0.1f ) == SIDE_FRONT ) {
  971. if ( plane[2].Side( p1, 0.1f ) == SIDE_ON && plane[3].Side( p1, 0.1f ) == SIDE_ON ) {
  972. if ( plane[2].Side( p2, 0.1f ) == SIDE_ON && plane[3].Side( p2, 0.1f ) == SIDE_ON ) {
  973. shard1->neighbours.Append( shard2 );
  974. shard1->edgeHasNeighbour[k] = true;
  975. shard2->neighbours.Append( shard1 );
  976. shard2->edgeHasNeighbour[(l-1+w2.GetNumPoints())%w2.GetNumPoints()] = true;
  977. break;
  978. }
  979. }
  980. }
  981. }
  982. }
  983. }
  984. for ( k = 0; k < w1.GetNumPoints(); k++ ) {
  985. if ( !shard1->edgeHasNeighbour[k] ) {
  986. break;
  987. }
  988. }
  989. if ( k < w1.GetNumPoints() ) {
  990. shard1->atEdge = true;
  991. } else {
  992. shard1->atEdge = false;
  993. }
  994. }
  995. }
  996. /*
  997. ================
  998. idBrittleFracture::Event_Activate
  999. ================
  1000. */
  1001. void idBrittleFracture::Event_Activate( idEntity *activator ) {
  1002. disableFracture = false;
  1003. if ( health <= 0 ) {
  1004. Break();
  1005. }
  1006. }
  1007. /*
  1008. ================
  1009. idBrittleFracture::Event_Touch
  1010. ================
  1011. */
  1012. void idBrittleFracture::Event_Touch( idEntity *other, trace_t *trace ) {
  1013. idVec3 point, impulse;
  1014. if ( !IsBroken() ) {
  1015. return;
  1016. }
  1017. if ( trace->c.id < 0 || trace->c.id >= shards.Num() ) {
  1018. return;
  1019. }
  1020. point = shards[trace->c.id]->clipModel->GetOrigin();
  1021. impulse = other->GetPhysics()->GetLinearVelocity() * other->GetPhysics()->GetMass();
  1022. Shatter( point, impulse, gameLocal.time );
  1023. }
  1024. /*
  1025. ================
  1026. idBrittleFracture::ClientPredictionThink
  1027. ================
  1028. */
  1029. void idBrittleFracture::ClientPredictionThink( void ) {
  1030. // only think forward because the state is not synced through snapshots
  1031. if ( !gameLocal.isNewFrame ) {
  1032. return;
  1033. }
  1034. Think();
  1035. }
  1036. /*
  1037. ================
  1038. idBrittleFracture::ClientReceiveEvent
  1039. ================
  1040. */
  1041. bool idBrittleFracture::ClientReceiveEvent( int event, int time, const idBitMsg &msg ) {
  1042. idVec3 point, dir;
  1043. switch( event ) {
  1044. case EVENT_PROJECT_DECAL: {
  1045. point[0] = msg.ReadFloat();
  1046. point[1] = msg.ReadFloat();
  1047. point[2] = msg.ReadFloat();
  1048. dir[0] = msg.ReadFloat();
  1049. dir[1] = msg.ReadFloat();
  1050. dir[2] = msg.ReadFloat();
  1051. ProjectDecal( point, dir, time, NULL );
  1052. return true;
  1053. }
  1054. case EVENT_SHATTER: {
  1055. point[0] = msg.ReadFloat();
  1056. point[1] = msg.ReadFloat();
  1057. point[2] = msg.ReadFloat();
  1058. dir[0] = msg.ReadFloat();
  1059. dir[1] = msg.ReadFloat();
  1060. dir[2] = msg.ReadFloat();
  1061. Shatter( point, dir, time );
  1062. return true;
  1063. }
  1064. default: {
  1065. return idEntity::ClientReceiveEvent( event, time, msg );
  1066. }
  1067. }
  1068. return false;
  1069. }