/* ================= idRenderWorldLocal::FreeDefs dump all the interactions ================= */ void idRenderWorldLocal::FreeDefs() { int i; generateAllInteractionsCalled = false; if ( interactionTable ) { R_StaticFree( interactionTable ); interactionTable = NULL; } // free all lightDefs for ( i = 0 ; i < lightDefs.Num() ; i++ ) { idRenderLightLocal *light; light = lightDefs[i]; if ( light && light->world == this ) { FreeLightDef( i ); lightDefs[i] = NULL; } } // free all entityDefs for ( i = 0 ; i < entityDefs.Num() ; i++ ) { idRenderEntityLocal *mod; mod = entityDefs[i]; if ( mod && mod->world == this ) { FreeEntityDef( i ); entityDefs[i] = NULL; } } }
/* ================ sdClientProjectile::Explode ================ */ void sdClientProjectile::Explode( const trace_t *collision, const char *sndExplode ) { const char *fxname; idVec3 normal, endpos; int removeTime; if ( spawnArgs.GetVector( "detonation_axis", "", normal ) ) { SetAxis( normal.ToMat3() ); } else { normal = collision ? collision->c.normal : idVec3( 0, 0, 1 ); } endpos = ( collision ) ? collision->endpos : GetOrigin(); removeTime = PROJECTILE_REMOVE_TIME; // play sound // StopSound( SND_CHANNEL_ANY ); StartSound( sndExplode, SND_CHANNEL_BODY ); StartSound( "snd_explode_med", SND_CHANNEL_BODY2 ); StartSound( "snd_explode_far", SND_CHANNEL_BODY3 ); Hide(); FreeLightDef(); SetOrigin( GetOrigin() + 8.0f * normal ); // change the model fxname = NULL; if ( g_testParticle.GetInteger() == TEST_PARTICLE_IMPACT ) { fxname = g_testParticleName.GetString(); } else { fxname = spawnArgs.GetString( "model_detonate" ); } ClientEntEvent_Remove( removeTime ); }
/* ================ idItem::~idItem ================ */ idItem::~idItem() { // remove the highlight shell if ( itemShellHandle != -1 ) { gameRenderWorld->FreeEntityDef( itemShellHandle ); } FreeLightDef(); // sikk - Crumb Light }
END_CLASS int hhProjectileStickyCrawlerGrenade::ProcessCollision( const trace_t* collision, const idVec3& velocity ) { idEntity* entHit = gameLocal.entities[ collision->c.entityNum ]; //SAFE_REMOVE( fxFly ); FreeLightDef(); CancelEvents( &EV_Fizzle ); //physicsObj.SetContents( 0 ); physicsObj.PutToRest(); surfTypes_t matterType = gameLocal.GetMatterType( entHit, collision->c.material, "hhProjectile::ProcessCollision" ); return PlayImpactSound( gameLocal.FindEntityDefDict(spawnArgs.GetString("def_damage")), collision->endpos, matterType ); }
/* ================ idItem::Pickup ================ */ bool idItem::Pickup( idPlayer *player ) { if ( !GiveToPlayer( player ) ) { return false; } // play pickup sound StartSound( "snd_acquire", SND_CHANNEL_ITEM, 0, false, NULL ); // sikk - play the sounds through the player //player->StartSoundShader( declManager->FindSound( spawnArgs.GetString( "snd_acquire" ) ), SND_CHANNEL_ITEM, SSF_PRIVATE_SOUND, false, NULL ); // trigger our targets ActivateTargets( player ); // clear our contents so the object isn't picked up twice GetPhysics()->SetContents( 0 ); // hide the model Hide(); FreeLightDef(); // sikk - Crumb Light // add the highlight shell if ( itemShellHandle != -1 ) { gameRenderWorld->FreeEntityDef( itemShellHandle ); itemShellHandle = -1; } float respawn = spawnArgs.GetFloat( "respawn" ); bool dropped = spawnArgs.GetBool( "dropped" ); bool no_respawn = spawnArgs.GetBool( "no_respawn" ); if ( respawn && !dropped && !no_respawn ) { const char *sfx = spawnArgs.GetString( "fxRespawn" ); if ( sfx && *sfx ) { PostEventSec( &EV_RespawnFx, respawn - 0.5f ); } PostEventSec( &EV_RespawnItem, respawn ); } else if ( !spawnArgs.GetBool( "inv_objective" ) && !no_respawn ) { // give some time for the pickup sound to play // FIXME: Play on the owner if ( !spawnArgs.GetBool( "inv_carry" ) ) { PostEventMS( &EV_Remove, 5000 ); } } BecomeInactive( TH_THINK ); return true; }
/* ================= idRenderWorldLocal::FreeDefs dump all the interactions ================= */ void idRenderWorldLocal::FreeDefs() { generateAllInteractionsCalled = false; if( interactionTable ) { R_StaticFree( interactionTable ); interactionTable = NULL; } // free all lightDefs for( int i = 0; i < lightDefs.Num(); i++ ) { idRenderLightLocal* light = lightDefs[i]; if( light != NULL && light->world == this ) { FreeLightDef( i ); lightDefs[i] = NULL; } } // free all entityDefs for( int i = 0; i < entityDefs.Num(); i++ ) { idRenderEntityLocal* mod = entityDefs[i]; if( mod != NULL && mod->world == this ) { FreeEntityDef( i ); entityDefs[i] = NULL; } } // Reset decals and overlays for( int i = 0; i < decals.Num(); i++ ) { decals[i].entityHandle = -1; decals[i].lastStartTime = 0; } for( int i = 0; i < overlays.Num(); i++ ) { overlays[i].entityHandle = -1; overlays[i].lastStartTime = 0; } }
/* ============== ProcessDemoCommand ============== */ bool idRenderWorldLocal::ProcessDemoCommand( idDemoFile *readDemo, renderView_t *renderView, int *demoTimeOffset ) { bool newMap = false; if ( !readDemo ) { return false; } demoCommand_t dc; qhandle_t h; if ( !readDemo->ReadInt( (int&)dc ) ) { // a demoShot may not have an endFrame, but it is still valid return false; } switch( dc ) { case DC_LOADMAP: // read the initial data demoHeader_t header; readDemo->ReadInt( header.version ); readDemo->ReadInt( header.sizeofRenderEntity ); readDemo->ReadInt( header.sizeofRenderLight ); for ( int i = 0; i < 256; i++ ) readDemo->ReadChar( header.mapname[i] ); // the internal version value got replaced by DS_VERSION at toplevel if ( header.version != 4 ) { common->Error( "Demo version mismatch.\n" ); } if ( r_showDemo.GetBool() ) { common->Printf( "DC_LOADMAP: %s\n", header.mapname ); } InitFromMap( header.mapname ); newMap = true; // we will need to set demoTimeOffset break; case DC_RENDERVIEW: readDemo->ReadInt( renderView->viewID ); readDemo->ReadInt( renderView->x ); readDemo->ReadInt( renderView->y ); readDemo->ReadInt( renderView->width ); readDemo->ReadInt( renderView->height ); readDemo->ReadFloat( renderView->fov_x ); readDemo->ReadFloat( renderView->fov_y ); readDemo->ReadVec3( renderView->vieworg ); readDemo->ReadMat3( renderView->viewaxis ); readDemo->ReadBool( renderView->cramZNear ); readDemo->ReadBool( renderView->forceUpdate ); // binary compatibility with win32 padded structures char tmp; readDemo->ReadChar( tmp ); readDemo->ReadChar( tmp ); readDemo->ReadInt( renderView->time ); for ( int i = 0; i < MAX_GLOBAL_SHADER_PARMS; i++ ) readDemo->ReadFloat( renderView->shaderParms[i] ); if ( !readDemo->ReadInt( (int&)renderView->globalMaterial ) ) { return false; } if ( r_showDemo.GetBool() ) { common->Printf( "DC_RENDERVIEW: %i\n", renderView->time ); } // possibly change the time offset if this is from a new map if ( newMap && demoTimeOffset ) { *demoTimeOffset = renderView->time - eventLoop->Milliseconds(); } return false; case DC_UPDATE_ENTITYDEF: ReadRenderEntity(); break; case DC_DELETE_ENTITYDEF: if ( !readDemo->ReadInt( h ) ) { return false; } if ( r_showDemo.GetBool() ) { common->Printf( "DC_DELETE_ENTITYDEF: %i\n", h ); } FreeEntityDef( h ); break; case DC_UPDATE_LIGHTDEF: ReadRenderLight(); break; case DC_DELETE_LIGHTDEF: if ( !readDemo->ReadInt( h ) ) { return false; } if ( r_showDemo.GetBool() ) { common->Printf( "DC_DELETE_LIGHTDEF: %i\n", h ); } FreeLightDef( h ); break; case DC_CAPTURE_RENDER: if ( r_showDemo.GetBool() ) { common->Printf( "DC_CAPTURE_RENDER\n" ); } renderSystem->CaptureRenderToImage( readDemo->ReadHashString() ); break; case DC_CROP_RENDER: if ( r_showDemo.GetBool() ) { common->Printf( "DC_CROP_RENDER\n" ); } int size[3]; readDemo->ReadInt( size[0] ); readDemo->ReadInt( size[1] ); readDemo->ReadInt( size[2] ); renderSystem->CropRenderSize( size[0], size[1], size[2] != 0 ); break; case DC_UNCROP_RENDER: if ( r_showDemo.GetBool() ) { common->Printf( "DC_UNCROP\n" ); } renderSystem->UnCrop(); break; case DC_GUI_MODEL: if ( r_showDemo.GetBool() ) { common->Printf( "DC_GUI_MODEL\n" ); } tr.demoGuiModel->ReadFromDemo( readDemo ); break; case DC_DEFINE_MODEL: { idRenderModel *model = renderModelManager->AllocModel(); model->ReadFromDemoFile( session->readDemo ); // add to model manager, so we can find it renderModelManager->AddModel( model ); // save it in the list to free when clearing this map localModels.Append( model ); if ( r_showDemo.GetBool() ) { common->Printf( "DC_DEFINE_MODEL\n" ); } break; } case DC_SET_PORTAL_STATE: { int data[2]; readDemo->ReadInt( data[0] ); readDemo->ReadInt( data[1] ); SetPortalState( data[0], data[1] ); if ( r_showDemo.GetBool() ) { common->Printf( "DC_SET_PORTAL_STATE: %i %i\n", data[0], data[1] ); } } break; case DC_END_FRAME: return true; default: common->Error( "Bad token in demo stream" ); } return false; }
/* ============== ProcessDemoCommand ============== */ bool idRenderWorldLocal::ProcessDemoCommand( idDemoFile* readDemo, renderView_t* renderView, int* demoTimeOffset ) { bool newMap = false; if( !readDemo ) { return false; } demoCommand_t dc; qhandle_t h; if( !readDemo->ReadInt( ( int& )dc ) ) { // a demoShot may not have an endFrame, but it is still valid return false; } switch( dc ) { case DC_LOADMAP: { // read the initial data demoHeader_t header; readDemo->ReadInt( header.version ); readDemo->ReadInt( header.sizeofRenderEntity ); readDemo->ReadInt( header.sizeofRenderLight ); for( int i = 0; i < 256; i++ ) readDemo->ReadChar( header.mapname[i] ); // the internal version value got replaced by DS_VERSION at toplevel if( header.version != 4 ) { common->Error( "Demo version mismatch.\n" ); } if( r_showDemo.GetBool() ) { common->Printf( "DC_LOADMAP: %s\n", header.mapname ); } // Clean up existing Renderer before loading the new map. FreeWorld(); // Load up the new map. InitFromMap( header.mapname ); newMap = true; // we will need to set demoTimeOffset break; } case DC_CACHE_SKINS: { int numSkins = 0; readDemo->ReadInt( numSkins ); for( int i = 0; i < numSkins; ++i ) { const char* declName = readDemo->ReadHashString(); declManager->FindSkin( declName, true ); } if( r_showDemo.GetBool() ) { common->Printf( "DC_CACHESKINS: %d\n", numSkins ); } break; } case DC_CACHE_PARTICLES: { int numDecls = 0; readDemo->ReadInt( numDecls ); for( int i = 0; i < numDecls; ++i ) { const char* declName = readDemo->ReadHashString(); declManager->FindType( DECL_PARTICLE, declName, true ); } if( r_showDemo.GetBool() ) { common->Printf( "DC_CACHE_PARTICLES: %d\n", numDecls ); } break; } case DC_CACHE_MATERIALS: { int numDecls = 0; readDemo->ReadInt( numDecls ); for( int i = 0; i < numDecls; ++i ) { const char* declName = readDemo->ReadHashString(); declManager->FindMaterial( declName, true ); } if( r_showDemo.GetBool() ) { common->Printf( "DC_CACHE_MATERIALS: %d\n", numDecls ); } break; } case DC_RENDERVIEW: { readDemo->ReadInt( renderView->viewID ); readDemo->ReadFloat( renderView->fov_x ); readDemo->ReadFloat( renderView->fov_y ); readDemo->ReadVec3( renderView->vieworg ); readDemo->ReadMat3( renderView->viewaxis ); readDemo->ReadBool( renderView->cramZNear ); readDemo->ReadBool( renderView->forceUpdate ); // binary compatibility with win32 padded structures char tmp; readDemo->ReadChar( tmp ); readDemo->ReadChar( tmp ); readDemo->ReadInt( renderView->time[0] ); readDemo->ReadInt( renderView->time[1] ); for( int i = 0; i < MAX_GLOBAL_SHADER_PARMS; i++ ) readDemo->ReadFloat( renderView->shaderParms[i] ); if( !readDemo->ReadInt( ( int& )renderView->globalMaterial ) ) { return false; } if( r_showDemo.GetBool() ) { // foresthale 2014-05-19: /analyze fix - was time, changed to time[0] common->Printf( "DC_RENDERVIEW: %i\n", renderView->time[ 0 ] ); } // possibly change the time offset if this is from a new map if( newMap && demoTimeOffset ) { *demoTimeOffset = renderView->time[1] - eventLoop->Milliseconds(); } return false; } case DC_UPDATE_ENTITYDEF: { ReadRenderEntity(); break; } case DC_DELETE_ENTITYDEF: { if( !readDemo->ReadInt( h ) ) { return false; } if( r_showDemo.GetBool() ) { common->Printf( "DC_DELETE_ENTITYDEF: %i\n", h ); } FreeEntityDef( h ); break; } case DC_UPDATE_LIGHTDEF: { ReadRenderLight(); break; } case DC_DELETE_LIGHTDEF: { if( !readDemo->ReadInt( h ) ) { return false; } if( r_showDemo.GetBool() ) { common->Printf( "DC_DELETE_LIGHTDEF: %i\n", h ); } FreeLightDef( h ); break; } case DC_CAPTURE_RENDER: { if( r_showDemo.GetBool() ) { common->Printf( "DC_CAPTURE_RENDER\n" ); } renderSystem->CaptureRenderToImage( readDemo->ReadHashString() ); break; } case DC_CROP_RENDER: { if( r_showDemo.GetBool() ) { common->Printf( "DC_CROP_RENDER\n" ); } int width, height; readDemo->ReadInt( width ); readDemo->ReadInt( height ); renderSystem->CropRenderSize( width, height ); break; } case DC_UNCROP_RENDER: { if( r_showDemo.GetBool() ) { common->Printf( "DC_UNCROP\n" ); } renderSystem->UnCrop(); break; } case DC_GUI_MODEL: { if( r_showDemo.GetBool() ) { common->Printf( "DC_GUI_MODEL\n" ); } break; } case DC_DEFINE_MODEL: { idRenderModel* model = renderModelManager->AllocModel(); model->ReadFromDemoFile( common->ReadDemo() ); // add to model manager, so we can find it renderModelManager->AddModel( model ); // save it in the list to free when clearing this map localModels.Append( model ); if( r_showDemo.GetBool() ) { common->Printf( "DC_DEFINE_MODEL\n" ); } break; } case DC_UPDATE_DECAL: { if( !readDemo->ReadInt( h ) ) { return false; } int data[ 2 ]; readDemo->ReadInt( data[ 0 ] ); readDemo->ReadInt( data[ 1 ] ); decals[ h ].entityHandle = data[ 0 ]; decals[ h ].lastStartTime = data[ 1 ]; decals[ h ].decals->ReadFromDemoFile( readDemo ); break; } case DC_DELETE_DECAL: { if( !readDemo->ReadInt( h ) ) { return false; } int data[ 2 ]; readDemo->ReadInt( data[ 0 ] ); readDemo->ReadInt( data[ 1 ] ); decals[ h ].entityHandle = data[ 0 ]; decals[ h ].lastStartTime = data[ 1 ]; decals[ h ].decals->ReUse(); break; } case DC_UPDATE_OVERLAY: { if( !readDemo->ReadInt( h ) ) { return false; } int data[ 2 ]; readDemo->ReadInt( data[ 0 ] ); readDemo->ReadInt( data[ 1 ] ); overlays[ h ].entityHandle = data[ 0 ]; overlays[ h ].lastStartTime = data[ 1 ]; overlays[ h ].overlays->ReadFromDemoFile( readDemo ); break; } case DC_DELETE_OVERLAY: { if( !readDemo->ReadInt( h ) ) { return false; } int data[ 2 ]; readDemo->ReadInt( data[ 0 ] ); readDemo->ReadInt( data[ 1 ] ); overlays[ h ].entityHandle = data[ 0 ]; overlays[ h ].lastStartTime = data[ 1 ]; overlays[ h ].overlays->ReUse(); break; } case DC_SET_PORTAL_STATE: { int data[2]; readDemo->ReadInt( data[0] ); readDemo->ReadInt( data[1] ); SetPortalState( data[0], data[1] ); if( r_showDemo.GetBool() ) { common->Printf( "DC_SET_PORTAL_STATE: %i %i\n", data[0], data[1] ); } break; } case DC_END_FRAME: { if( r_showDemo.GetBool() ) { common->Printf( "DC_END_FRAME\n" ); } return true; } default: common->Error( "Bad demo render command '%d' in demo stream", dc ); break; } return false; }