/* ================ idBrittleFracture::Save ================ */ void idBrittleFracture::Save( idSaveGame *savefile ) const { int i, j; savefile->WriteInt( health ); entityFlags_s flags = fl; LittleBitField( &flags, sizeof( flags ) ); savefile->Write( &flags, sizeof( flags ) ); // setttings savefile->WriteMaterial( material ); savefile->WriteMaterial( decalMaterial ); savefile->WriteFloat( decalSize ); savefile->WriteFloat( maxShardArea ); savefile->WriteFloat( maxShatterRadius ); savefile->WriteFloat( minShatterRadius ); savefile->WriteFloat( linearVelocityScale ); savefile->WriteFloat( angularVelocityScale ); savefile->WriteFloat( shardMass ); savefile->WriteFloat( density ); savefile->WriteFloat( friction ); savefile->WriteFloat( bouncyness ); savefile->WriteString( fxFracture ); // state savefile->WriteBounds( bounds ); savefile->WriteBool( disableFracture ); savefile->WriteInt( lastRenderEntityUpdate ); savefile->WriteBool( changed ); savefile->WriteStaticObject( physicsObj ); savefile->WriteInt( shards.Num() ); for ( i = 0; i < shards.Num(); i++ ) { savefile->WriteWinding( shards[i]->winding ); savefile->WriteInt( shards[i]->decals.Num() ); for ( j = 0; j < shards[i]->decals.Num(); j++ ) { savefile->WriteWinding( *shards[i]->decals[j] ); } savefile->WriteInt( shards[i]->neighbours.Num() ); for ( j = 0; j < shards[i]->neighbours.Num(); j++ ) { int index = shards.FindIndex(shards[i]->neighbours[j]); assert(index != -1); savefile->WriteInt( index ); } savefile->WriteInt( shards[i]->edgeHasNeighbour.Num() ); for ( j = 0; j < shards[i]->edgeHasNeighbour.Num(); j++ ) { savefile->WriteBool( shards[i]->edgeHasNeighbour[j] ); } savefile->WriteInt( shards[i]->droppedTime ); savefile->WriteInt( shards[i]->islandNum ); savefile->WriteBool( shards[i]->atEdge ); savefile->WriteStaticObject( shards[i]->physicsObj ); } }
/* ================ idBrittleFracture::Save ================ */ void idBrittleFracture::Save( idSaveGame* savefile ) const { savefile->WriteInt( health ); entityFlags_s flags = fl; LittleBitField( &flags, sizeof( flags ) ); savefile->Write( &flags, sizeof( flags ) ); // setttings savefile->WriteMaterial( material ); savefile->WriteMaterial( decalMaterial ); savefile->WriteFloat( decalSize ); savefile->WriteFloat( maxShardArea ); savefile->WriteFloat( maxShatterRadius ); savefile->WriteFloat( minShatterRadius ); savefile->WriteFloat( linearVelocityScale ); savefile->WriteFloat( angularVelocityScale ); savefile->WriteFloat( shardMass ); savefile->WriteFloat( density ); savefile->WriteFloat( friction ); savefile->WriteFloat( bouncyness ); savefile->WriteString( fxFracture ); // state savefile->WriteBounds( bounds ); savefile->WriteBool( disableFracture ); savefile->WriteInt( lastRenderEntityUpdate ); savefile->WriteBool( changed ); savefile->WriteModel( defaultRenderModel ); // So we can re-break the object on load if needed savefile->WriteInt( storedEvents.Num() ); for( int i = 0; i < storedEvents.Num(); ++i ) { savefile->WriteInt( storedEvents[i].eventType ); savefile->WriteVec3( storedEvents[i].point ); savefile->WriteVec3( storedEvents[i].vector ); } savefile->WriteBool( isXraySurface ); }
/* ================ idBrittleFracture::Restore ================ */ void idBrittleFracture::Restore( idRestoreGame *savefile ) { int i, j , num; renderEntity.hModel = renderModelManager->AllocModel(); renderEntity.hModel->InitEmpty( brittleFracture_SnapshotName ); renderEntity.callback = idBrittleFracture::ModelCallback; renderEntity.noShadow = true; renderEntity.noSelfShadow = true; renderEntity.noDynamicInteractions = false; savefile->ReadInt( health ); savefile->Read( &fl, sizeof( fl ) ); LittleBitField( &fl, sizeof( fl ) ); // setttings savefile->ReadMaterial( material ); savefile->ReadMaterial( decalMaterial ); savefile->ReadFloat( decalSize ); savefile->ReadFloat( maxShardArea ); savefile->ReadFloat( maxShatterRadius ); savefile->ReadFloat( minShatterRadius ); savefile->ReadFloat( linearVelocityScale ); savefile->ReadFloat( angularVelocityScale ); savefile->ReadFloat( shardMass ); savefile->ReadFloat( density ); savefile->ReadFloat( friction ); savefile->ReadFloat( bouncyness ); savefile->ReadString( fxFracture ); // state savefile->ReadBounds(bounds); savefile->ReadBool( disableFracture ); savefile->ReadInt( lastRenderEntityUpdate ); savefile->ReadBool( changed ); savefile->ReadStaticObject( physicsObj ); RestorePhysics( &physicsObj ); savefile->ReadInt( num ); shards.SetNum( num ); for ( i = 0; i < num; i++ ) { shards[i] = new shard_t; } for ( i = 0; i < num; i++ ) { savefile->ReadWinding( shards[i]->winding ); savefile->ReadInt( j ); shards[i]->decals.SetNum( j ); for ( j = 0; j < shards[i]->decals.Num(); j++ ) { shards[i]->decals[j] = new idFixedWinding; savefile->ReadWinding( *shards[i]->decals[j] ); } savefile->ReadInt( j ); shards[i]->neighbours.SetNum( j ); for ( j = 0; j < shards[i]->neighbours.Num(); j++ ) { int index; savefile->ReadInt( index ); assert(index != -1); shards[i]->neighbours[j] = shards[index]; } savefile->ReadInt( j ); shards[i]->edgeHasNeighbour.SetNum( j ); for ( j = 0; j < shards[i]->edgeHasNeighbour.Num(); j++ ) { savefile->ReadBool( shards[i]->edgeHasNeighbour[j] ); } savefile->ReadInt( shards[i]->droppedTime ); savefile->ReadInt( shards[i]->islandNum ); savefile->ReadBool( shards[i]->atEdge ); savefile->ReadStaticObject( shards[i]->physicsObj ); if ( shards[i]->droppedTime < 0 ) { shards[i]->clipModel = physicsObj.GetClipModel( i ); } else { shards[i]->clipModel = shards[i]->physicsObj.GetClipModel(); } } }
/* ================ idBrittleFracture::Restore ================ */ void idBrittleFracture::Restore( idRestoreGame* savefile ) { savefile->ReadInt( health ); savefile->Read( &fl, sizeof( fl ) ); LittleBitField( &fl, sizeof( fl ) ); // setttings savefile->ReadMaterial( material ); savefile->ReadMaterial( decalMaterial ); savefile->ReadFloat( decalSize ); savefile->ReadFloat( maxShardArea ); savefile->ReadFloat( maxShatterRadius ); savefile->ReadFloat( minShatterRadius ); savefile->ReadFloat( linearVelocityScale ); savefile->ReadFloat( angularVelocityScale ); savefile->ReadFloat( shardMass ); savefile->ReadFloat( density ); savefile->ReadFloat( friction ); savefile->ReadFloat( bouncyness ); savefile->ReadString( fxFracture ); // state savefile->ReadBounds( bounds ); savefile->ReadBool( disableFracture ); savefile->ReadInt( lastRenderEntityUpdate ); savefile->ReadBool( changed ); savefile->ReadModel( defaultRenderModel ); // Reset all brittle Fractures so we can re-break them if necessary fl.takedamage = true; CreateFractures( defaultRenderModel ); FindNeighbours(); int numEvents = 0; bool resolveBreaks = false; savefile->ReadInt( numEvents ); for( int i = 0; i < numEvents; i++ ) { fractureEvent_s restoredEvent; savefile->ReadInt( restoredEvent.eventType ); savefile->ReadVec3( restoredEvent.point ); savefile->ReadVec3( restoredEvent.vector ); if( restoredEvent.eventType == EVENT_PROJECT_DECAL ) { ProjectDecal( restoredEvent.point, restoredEvent.vector, gameLocal.time, NULL ); } else { Shatter( restoredEvent.point, restoredEvent.vector, gameLocal.time ); } resolveBreaks = true; } // remove any dropped shards for( int i = 0; resolveBreaks && i < shards.Num(); i++ ) { if( shards[i]->droppedTime != -1 ) { RemoveShard( i ); i--; } } renderEntity.hModel = renderModelManager->AllocModel(); renderEntity.hModel->InitEmpty( brittleFracture_SnapshotName ); renderEntity.callback = idBrittleFracture::ModelCallback; renderEntity.noShadow = true; renderEntity.noSelfShadow = true; renderEntity.noDynamicInteractions = false; savefile->ReadBool( isXraySurface ); }