Example #1
0
/*
=================
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;
		}
	}
}
Example #2
0
/*
================
rvClientMoveable::~rvClientMoveable
================
*/
rvClientMoveable::~rvClientMoveable ( void ) {
	FreeEntityDef ( );

	// Remove any trail effect if there is one
	if ( trailEffect ) {
		trailEffect->Stop ( );
	}
}
Example #3
0
/*
================
rvClientMoveable::~rvClientMoveable
================
*/
rvClientMoveable::~rvClientMoveable ( void ) {
	FreeEntityDef ( );
	gameEdit->DestroyRenderEntity( renderEntity );

	// Remove any trail effect if there is one
	if ( trailEffect ) {
		trailEffect->Stop ( );
	}
}
/*
=================
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;
}
Example #6
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 );
			}
			// 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;
}