Beispiel #1
0
bool CEngineSprite::Init( const char *pName )
{
	m_hAVIMaterial = AVIMATERIAL_INVALID;
	m_width = m_height = m_numFrames = 1;

	const char *pExt = Q_GetFileExtension( pName );
	bool bIsAVI = pExt && !Q_stricmp( pExt, "avi" );
	if ( bIsAVI )
	{
		m_hAVIMaterial = avi->CreateAVIMaterial( pName, pName, "GAME" );
		if ( m_hAVIMaterial == AVIMATERIAL_INVALID )
			return false;

		m_material = avi->GetMaterial( m_hAVIMaterial );
		avi->GetFrameSize( m_hAVIMaterial, &m_width, &m_height );
		m_numFrames = avi->GetFrameCount( m_hAVIMaterial );
	}
	else
	{
		m_material = materials->FindMaterial( pName, TEXTURE_GROUP_CLIENT_EFFECTS );
		m_width = m_material->GetMappingWidth();
		m_height = m_material->GetMappingHeight();
		m_numFrames = (!bIsAVI) ? m_material->GetNumAnimationFrames() : avi->GetFrameCount( m_hAVIMaterial );
	}

	if ( !m_material )
		return false;

	m_material->IncrementReferenceCount();

	IMaterialVar *orientationVar = m_material->FindVarFast( "$spriteorientation", &spriteOrientationCache );
	m_orientation = orientationVar ? orientationVar->GetIntValue() : C_SpriteRenderer::SPR_VP_PARALLEL_UPRIGHT;

	IMaterialVar *originVar = m_material->FindVarFast( "$spriteorigin", &spriteOriginCache );
	Vector origin, originVarValue;
	if( !originVar || ( originVar->GetType() != MATERIAL_VAR_TYPE_VECTOR ) )
	{
		origin[0] = -m_width * 0.5f;
		origin[1] = m_height * 0.5f;
	}
	else
	{
		originVar->GetVecValue( &originVarValue[0], 3 );
		origin[0] = -m_width * originVarValue[0];
		origin[1] = m_height * originVarValue[1];
	}

	up = origin[1];
	down = origin[1] - m_height;
	left = origin[0];
	right = m_width + origin[0];

	return true;
}
Beispiel #2
0
void CLevelTheme::LoadRoomTemplatesInFolder( const char *szPath )
{
	char mapwild[MAX_PATH];
	Q_snprintf( mapwild, sizeof( mapwild ), "%s/*", szPath );
	char const *filename;
	FileFindHandle_t	hRoomfind = FILESYSTEM_INVALID_FIND_HANDLE;
	filename = Sys_FindFirst( hRoomfind, mapwild, NULL, 0 );
	while ( filename )
	{
		if ( g_pFullFileSystem->FindIsDirectory( hRoomfind ) )
		{
			if ( Q_strcmp( filename, "." ) && Q_strcmp( filename, ".." ) )
			{
				char subfolder[MAX_PATH];
				Q_snprintf( subfolder, sizeof( subfolder ), "%s/%s", szPath, filename );
				LoadRoomTemplatesInFolder( subfolder );
			}
		}
		else
		{	
			const char *pExt = Q_GetFileExtension( filename );
			if ( pExt && !Q_stricmp( pExt, "roomtemplate" ) )
			{
				// load the room template
				char szFullFileName[256];
				Q_snprintf(szFullFileName, sizeof(szFullFileName), "%s/%s", szPath, filename);
				KeyValues *pRoomTemplateKeyValues = new KeyValues( filename );
				if (pRoomTemplateKeyValues->LoadFromFile(g_pFullFileSystem, szFullFileName, "GAME"))
				{
					CRoomTemplate* pRoomTemplate = new CRoomTemplate(this);
					pRoomTemplate->LoadFromKeyValues( szFullFileName + Q_strlen( ROOMTEMPLATES_FOLDER ) + 1 + Q_strlen( m_szName ), pRoomTemplateKeyValues );		// sets the room templates properties based on these keyvalues
					m_RoomTemplates.Insert(pRoomTemplate);
				}
				else
				{
					Msg("Error: failed to load room template %s\n", szFullFileName);
				}
				pRoomTemplateKeyValues->deleteThis();
			}
		}
		filename = Sys_FindNext(hRoomfind, NULL, 0);
	}
		
	Sys_FindClose(hRoomfind);
}
void CASW_KeyValuesDatabase::LoadFilesInFolder( const char *pPath )
{
	FileFindHandle_t tagsfind = FILESYSTEM_INVALID_FIND_HANDLE;

	// Search the directory structure.
	char mapwild[MAX_PATH];
	Q_snprintf( mapwild, sizeof( mapwild ), "%s*", pPath );
	char const *filename;
	filename = Sys_FindFirst( tagsfind, mapwild, NULL, 0 );

	while (filename)
	{
		if ( g_pFullFileSystem->FindIsDirectory( tagsfind ) )
		{
			if ( Q_strcmp( filename, "." ) && Q_strcmp( filename, ".." ) )
			{
				char subfolder[MAX_PATH];
				Q_snprintf( subfolder, sizeof( subfolder ), "%s%s/", pPath, filename );
				LoadFilesInFolder( subfolder );
			}
		}
		else
		{
			const char *pExt = Q_GetFileExtension( filename );
			if ( pExt && !Q_stricmp( pExt, "txt" ) )
			{
				// load the mission spec
				char fullFileName[256];
				Q_snprintf(fullFileName, sizeof(fullFileName), "%s%s", pPath, filename);
				KeyValues *pKeyValues = new KeyValues( filename );
				if (pKeyValues->LoadFromFile(g_pFullFileSystem, fullFileName, "GAME"))
				{
					AddFile( pKeyValues, fullFileName );
				}
				else
				{
					Msg( "Error: failed to load file: %s\n", fullFileName );
				}
			}
		}
		filename = Sys_FindNext(tagsfind, NULL, 0);
	}

	Sys_FindClose( tagsfind );
}
Beispiel #4
0
bool CEngineSprite::Init( const char *pName )
{
	m_hAVIMaterial = AVIMATERIAL_INVALID;
	m_hBIKMaterial = BIKMATERIAL_INVALID;
	m_width = m_height = m_numFrames = 1;

	const char *pExt = Q_GetFileExtension( pName );
	bool bIsAVI = pExt && !Q_stricmp( pExt, "avi" );
#if !defined( _X360 ) || defined( BINK_ENABLED_FOR_X360 )
	bool bIsBIK = pExt && !Q_stricmp( pExt, "bik" );
#endif
	if ( bIsAVI && IsPC() )
	{
		m_hAVIMaterial = avi->CreateAVIMaterial( pName, pName, "GAME" );
		if ( m_hAVIMaterial == AVIMATERIAL_INVALID )
			return false;

		IMaterial *pMaterial = avi->GetMaterial( m_hAVIMaterial );
		avi->GetFrameSize( m_hAVIMaterial, &m_width, &m_height );
		m_numFrames = avi->GetFrameCount( m_hAVIMaterial );
		for ( int i = 0; i < kRenderModeCount; ++i )
		{
			m_material[i] = pMaterial;
			pMaterial->IncrementReferenceCount();
		}
	}
#if !defined( _X360 ) || defined( BINK_ENABLED_FOR_X360 )
	else if ( bIsBIK )
	{
		m_hBIKMaterial = bik->CreateMaterial( pName, pName, "GAME" );
		if ( m_hBIKMaterial == BIKMATERIAL_INVALID )
			return false;

		IMaterial *pMaterial = bik->GetMaterial( m_hBIKMaterial );
		bik->GetFrameSize( m_hBIKMaterial, &m_width, &m_height );
		m_numFrames = bik->GetFrameCount( m_hBIKMaterial );
		for ( int i = 0; i < kRenderModeCount; ++i )
		{
			m_material[i] = pMaterial;
			pMaterial->IncrementReferenceCount();
		}
	}
#endif
	else
	{
		char pTemp[MAX_PATH];
		char pMaterialName[MAX_PATH];
		char pMaterialPath[MAX_PATH];
		Q_StripExtension( pName, pTemp, sizeof(pTemp) );
		Q_strlower( pTemp );
		Q_FixSlashes( pTemp, '/' );

		// Check to see if this is a UNC-specified material name
		bool bIsUNC = pTemp[0] == '/' && pTemp[1] == '/' && pTemp[2] != '/';
		if ( !bIsUNC )
		{
			Q_strncpy( pMaterialName, "materials/", sizeof(pMaterialName) );
			Q_strncat( pMaterialName, pTemp, sizeof(pMaterialName), COPY_ALL_CHARACTERS );
		}
		else
		{
			Q_strncpy( pMaterialName, pTemp, sizeof(pMaterialName) );
		}
		Q_strncpy( pMaterialPath, pMaterialName, sizeof(pMaterialPath) );
		Q_SetExtension( pMaterialPath, ".vmt", sizeof(pMaterialPath) );

		for ( int i = 0; i < kRenderModeCount; ++i )
		{	
			m_material[i] = NULL;
		}

		KeyValues *kv = new KeyValues( "vmt" );
		if ( !kv->LoadFromFile( g_pFullFileSystem, pMaterialPath, "GAME" ) )
		{
			Warning( "Unable to load sprite material %s!\n", pMaterialPath );
			return false;
		}

		for ( int i = 0; i < kRenderModeCount; ++i )
		{	
			if ( i == kRenderNone || i == kRenderEnvironmental )
			{
				continue;
			}

			// strip possible materials/
			Q_snprintf( pMaterialPath, sizeof(pMaterialPath), "%s_rendermode_%d", pMaterialName + ( bIsUNC ? 0 : 10 ), i );
			KeyValues *pMaterialKV = kv->MakeCopy();
			pMaterialKV->SetInt( "$spriteRenderMode", i );
			m_material[i] = g_pMaterialSystem->FindProceduralMaterial( pMaterialPath, TEXTURE_GROUP_CLIENT_EFFECTS, pMaterialKV );
			m_material[i]->IncrementReferenceCount();	
		}

		kv->deleteThis();

		m_width = m_material[0]->GetMappingWidth();
		m_height = m_material[0]->GetMappingHeight();
		m_numFrames = m_material[0]->GetNumAnimationFrames();
	}

	for ( int i = 0; i < kRenderModeCount; ++i )
	{
		if ( i == kRenderNone || i == kRenderEnvironmental )
			continue;

		if ( !m_material[i] )
			return false;
	}

	IMaterialVar *orientationVar = m_material[0]->FindVarFast( "$spriteorientation", &spriteOrientationCache );
	m_orientation = orientationVar ? orientationVar->GetIntValue() : C_SpriteRenderer::SPR_VP_PARALLEL_UPRIGHT;

	IMaterialVar *originVar = m_material[0]->FindVarFast( "$spriteorigin", &spriteOriginCache );
	Vector origin, originVarValue;
	if( !originVar || ( originVar->GetType() != MATERIAL_VAR_TYPE_VECTOR ) )
	{
		origin[0] = -m_width * 0.5f;
		origin[1] = m_height * 0.5f;
	}
	else
	{
		originVar->GetVecValue( &originVarValue[0], 3 );
		origin[0] = -m_width * originVarValue[0];
		origin[1] = m_height * originVarValue[1];
	}

	up = origin[1];
	down = origin[1] - m_height;
	left = origin[0];
	right = m_width + origin[0];

	return true;
}
//-----------------------------------------------------------------------------
// Saves/loads from file
//-----------------------------------------------------------------------------
bool CVcdBlockDoc::LoadFromFile( const char *pFileName )
{
	Assert( !m_hVMFRoot.Get() );
	Assert( !m_hEditRoot.Get() );

	CAppDisableUndoScopeGuard guard( "CVcdBlockDoc::LoadFromFile", NOTIFY_CHANGE_OTHER );
	SetDirty( false );

	if ( !pFileName[0] )
		return false;

	// Construct VMF file name from the BSP
	const char *pGame = Q_stristr( pFileName, "\\game\\" );
	if ( !pGame )
	{
		pGame = Q_stristr( pFileName, "\\content\\" );
		if ( !pGame )
			return false;
	}

	// Compute the map name
	const char *pMaps = Q_stristr( pFileName, "\\maps\\" );
	if ( !pMaps )
		return false;

	// Build map name
	char mapname[ 256 ];
	Q_StripExtension( pFileName, mapname, sizeof(mapname) );
	char *pszFileName = (char*)Q_UnqualifiedFileName(mapname);

	int nLen = (int)( (size_t)pGame - (size_t)pFileName ) + 1;
	Q_strncpy( m_pVMFFileName, pFileName, nLen );
	Q_strncat( m_pVMFFileName, "\\content\\", sizeof(m_pVMFFileName) );
	Q_strncat( m_pVMFFileName, pGame + 6, sizeof(m_pVMFFileName) );
	Q_SetExtension( m_pVMFFileName, ".vmf", sizeof(m_pVMFFileName) );

	// Make sure new entities start with ids at 0
	CDmeVMFEntity::SetNextEntityId( 0 );

	// Build the Edit file name
	Q_StripExtension( m_pVMFFileName, m_pEditFileName, sizeof(m_pEditFileName) );
	Q_strncat( m_pEditFileName, ".vle", sizeof( m_pEditFileName ) );

	// Store the BSP file name
	Q_strncpy( m_pBSPFileName, pFileName, sizeof( m_pBSPFileName ) );

	// Set the txt file name. 
	// If we loaded a .bsp, clear out what we're doing
	// load the Edits file into memory, assign it as our "root"
	CDmElement *pEdit = NULL;
	if ( !V_stricmp( Q_GetFileExtension( pFileName ), "vle" ) )
	{
		if ( g_pDataModel->RestoreFromFile( m_pEditFileName, NULL, "vmf", &pEdit ) != DMFILEID_INVALID )
		{
			// If we successfully read the file in, ask it for the max hammer id
			//int nMaxHammerId = pVMF->GetAttributeValue<int>( "maxHammerId" );
			//CDmeVMFEntity::SetNextEntityId( nMaxHammerId + 1 );
			m_hEditRoot = pEdit;
			SetDirty( false );
		}
	}

	if (pEdit == NULL)
	{
		if ( g_pFileSystem->FileExists( m_pEditFileName ) )
		{
			char pBuf[1024];
			Q_snprintf( pBuf, sizeof(pBuf), "File %s already exists!\n", m_pEditFileName ); 
			m_pEditFileName[0] = 0;
			vgui::MessageBox *pMessageBox = new vgui::MessageBox( "Unable to overwrite file!\n", pBuf, g_pVcdBlockTool );
			pMessageBox->DoModal( );
			return false;
		}

		DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( m_pEditFileName );
		m_hEditRoot = CreateElement<CDmElement>( "root", fileid );
		m_hEditRoot->AddAttribute( "entities", AT_ELEMENT_ARRAY );
		g_pDataModel->SetFileRoot( fileid, m_hEditRoot );
		SetDirty( true );
	}

	guard.Release();

	// tell the engine to actually load the map
	char cmd[ 256 ];
	Q_snprintf( cmd, sizeof( cmd ), "disconnect; map %s\n", pszFileName );
	enginetools->Command( cmd );
	enginetools->Execute( );

	return true;
}