profile.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:28k
- //-----------------------------------------------------------------------------
- // File: Profile.cpp
- //
- // Copyright (c) Microsoft Corporation. All rights reserved
- //-----------------------------------------------------------------------------
- #include "stdafx.h"
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- CProfile::CProfile()
- {
- nNumThemes = 0;
- aThemes = NULL;
- aEnemyStyles = NULL;
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- CProfile::~CProfile()
- {
- SAFE_DELETE_ARRAY( aThemes );
- SAFE_DELETE_ARRAY( aEnemyStyles );
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc: this function reads our profile into member variables of the profile object.
- //-----------------------------------------------------------------------------
- VOID CProfile::GetProfile( LPCTSTR szIniName )
- {
- HRESULT hr;
- lstrcpy( m_szIniName, szIniName );
- GetBulletParameters( "BULLET1", &Blaster );
- Get3DSoundParameters( "ExplosionDonut", &ExplosionDonut );
- GetShipParameters( "Ship", &Ship );
- bLoadAudio = GetLong( "GLOBAL", TEXT("LoadAudio"), TEXT("1") );
- bRenderSplash = GetLong( "GLOBAL", TEXT("RenderSplash"), TEXT("1") );
- bRenderUI = GetLong( "GLOBAL", TEXT("RenderUI"), TEXT("1") );
- bRenderRadar = GetLong( "GLOBAL", TEXT("RenderRadar"), TEXT("1") );
- bRenderGround = GetLong( "GLOBAL", TEXT("RenderGround"), TEXT("1") );
- bRenderSky = GetLong( "GLOBAL", TEXT("RenderSky"), TEXT("1") );
- bRenderEnemies = GetLong( "GLOBAL", TEXT("RenderEnemies"), TEXT("1") );
- bRenderParticles = GetLong( "GLOBAL", TEXT("RenderParticles"), TEXT("1") );
- bFullScreen = GetLong( "GLOBAL", TEXT("FullScreen"), TEXT("0") );
- bLoadFast = GetLong( "GLOBAL", TEXT("LoadFast"), TEXT("0") );
- bForceREF = GetLong( "GLOBAL", TEXT("ForceREF"), TEXT("0") );
- bForceSoftwareVP = GetLong( "GLOBAL", TEXT("ForceSoftwareVP"), TEXT("0") );
- bForceHardwareVP = GetLong( "GLOBAL", TEXT("ForceHardwareVP"), TEXT("0") );
- fChangeGunRecharge = GetFloat( "GLOBAL", TEXT("ChangeGunRecharge"), TEXT("0.5") );
- flDistanceFactor = GetFloat( "GLOBAL", TEXT("DistanceFactor"), TEXT("1.0") );
- flRolloffFactor = GetFloat( "GLOBAL", TEXT("RolloffFactor"), TEXT("1.0") );
- flDopplerFactor = GetFloat( "GLOBAL", TEXT("DopplerFactor"), TEXT("1.0") );
- nNumEnemiesPerLevelScale = GetLong( "GLOBAL", TEXT("NumEnemiesPerLevelScale"), TEXT("2") );
- nNumEnemiesBase = GetLong( "GLOBAL", TEXT("NumEnemiesBase"), TEXT("3") );
- nRenderTerrianStyle = GetLong( "GLOBAL", TEXT("RenderTerrainStyle"), TEXT("1") );
- nWorldHeight = GetLong( "GLOBAL", TEXT("WorldHeight"), TEXT("3") );
- nWorldWidth = GetLong( "GLOBAL", TEXT("WorldWidth"), TEXT("3") );
- dwRenderText = GetLong( "GLOBAL", TEXT("RenderText"), TEXT("1") );
- fFOV = GetFloat( "GLOBAL", TEXT("FOV"), TEXT("0.7853") );
- bGenerateMipMaps = GetLong( "GLOBAL", TEXT("GenerateMipMaps"), TEXT("1") );
- bOptimizeMesh = GetLong( "GLOBAL", TEXT("OptimizeMesh"), TEXT("1") );
- bCompactMesh = GetLong( "GLOBAL", TEXT("CompactMesh"), TEXT("1") );
- bSimplifyMesh = GetLong( "GLOBAL", TEXT("SimplifyMesh"), TEXT("1") );
- fSimplifyMeshFactor = GetFloat( "GLOBAL", TEXT("SimplifyMeshFactor"), TEXT("0.25") );
- fRenderDist = GetFloat( "GLOBAL", TEXT("RenderDist"), TEXT("250.0f") );
- fZFarDist = GetFloat( "GLOBAL", TEXT("ZFarDist"), TEXT("250.0f") );
- fFogStart = GetFloat( "GLOBAL", TEXT("FogStart"), TEXT("80.0f") );
- fFogEnd = GetFloat( "GLOBAL", TEXT("FogEnd"), TEXT("300.0f") );
- nNumThemes = GetLong( "THEMES", TEXT("NumThemes"), TEXT("1") );
- if( NULL == aThemes )
- {
- aThemes = new CThemeStyle[nNumThemes];
- if( NULL == aThemes )
- return;
- ZeroMemory( aThemes, sizeof(CThemeStyle)*nNumThemes );
- }
- for( int iTheme=0; iTheme<nNumThemes; iTheme++ )
- {
- TCHAR strName[MAX_PATH];
- TCHAR strFileName[MAX_PATH];
- TCHAR strFilePath[MAX_PATH];
- wsprintf( strName, "Theme%d", iTheme+1 );
- GetString( strFileName, TEXT("THEMES"), strName, TEXT("theme1.ini") );
- if( FAILED( hr = CMyApplication::FindMediaFileCch( strFilePath, sizeof(strFilePath)/sizeof(TCHAR), strFileName ) ) )
- {
- g_pApp->CleanupAndDisplayError( DONUTSERR_ARTLOADFAILED, strFileName, strFilePath );
- DXTRACE_ERR( TEXT("FindMediaFileCch"), hr );
- return;
- }
- GetTheme( &aThemes[iTheme], strFilePath );
- }
- bForceThemeSelect = GetLong( "THEMES", TEXT("ForceThemeSelect"), TEXT("0") );
- nSelectTheme = GetLong( "THEMES", TEXT("SelectTheme"), TEXT("1") ) - 1;
- GetString( szUITextureMap, TEXT("GLOBAL"), TEXT("UITextureMap"), TEXT("ui.bmp") );
- GetString( szSplashTextureMap, TEXT("GLOBAL"), TEXT("SplashTextureMap"), TEXT("splash.bmp") );
- GetString( szAudioScript, TEXT("GLOBAL"), TEXT("AudioScript"), TEXT("donuts4.spt") );
-
- nNumEnemies = GetLong( "GLOBAL", TEXT("NumEnemies"), TEXT("1") );
- bForceEnemySelect = GetLong( "GLOBAL", TEXT("ForceEnemySelect"), TEXT("0") );
- nSelectEnemy = GetLong( "GLOBAL", TEXT("SelectEnemy"), TEXT("1") ) - 1;
- if( NULL == aEnemyStyles )
- {
- aEnemyStyles = new CEnemyStyle[nNumEnemies];
- if( NULL == aEnemyStyles )
- return;
- ZeroMemory( aEnemyStyles, sizeof(CEnemyStyle)*nNumEnemies );
- }
- for( int iEnemy=0; iEnemy<nNumEnemies; iEnemy++ )
- {
- TCHAR strName[MAX_PATH];
- wsprintf( strName, "ENEMY%d", iEnemy+1 );
- GetEnemyStyle( &aEnemyStyles[iEnemy], strName );
- }
- for( int i=0; i<10; i++ )
- {
- TCHAR strName[MAX_PATH];
- wsprintf( strName, "NTemp%d", i );
- nTemp[i] = GetLong( "GLOBAL", strName, TEXT("1") );
- wsprintf( strName, "FTemp%d", i );
- fTemp[i] = GetFloat( "GLOBAL", strName, TEXT("1.0f") );
- }
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- VOID CProfile::GetEnemyStyle( CEnemyStyle* pEnemyStyle, TCHAR* strSection )
- {
- TCHAR strName[MAX_PATH];
- GetString( strName, strSection, TEXT("EnemyCreationType"), TEXT("FromFile") );
- if( lstrcmp( strName, TEXT("FromFile" ) ) == 0 )
- pEnemyStyle->EnemyCreationType = ECT_FromFile;
- else if( lstrcmp( strName, TEXT("CreateTest" ) ) == 0 )
- pEnemyStyle->EnemyCreationType = ECT_CreateTest;
- GetString( pEnemyStyle->strEnemyModel, strSection, TEXT("EnemyModel"), TEXT("enemy.x") );
- pEnemyStyle->fEnemySpeedFactor = GetFloat( strSection, TEXT("EnemySpeedFactor"), TEXT("30.0f") );
- pEnemyStyle->dwEnemyAmbientLight = GetHex( strSection, TEXT("EnemyAmbientLight"), TEXT("0x00000000") );
- GetString( strName, strSection, TEXT("EnemyMovementType"), TEXT("MoveRandom") );
- if( lstrcmp( strName, TEXT("None" ) ) == 0 )
- pEnemyStyle->EnemyMovementType = EMT_None;
- else if( lstrcmp( strName, TEXT("MoveRandom" ) ) == 0 )
- pEnemyStyle->EnemyMovementType = EMT_MoveRandom;
- else if( lstrcmp( strName, TEXT("MoveTowards" ) ) == 0 )
- pEnemyStyle->EnemyMovementType = EMT_MoveTowards;
- else
- MessageBox( NULL, "Unknown EnemyMovementType", strName, MB_OK );
- GetString( strName, strSection, TEXT("EnemyAttackType"), TEXT("None") );
- if( lstrcmp( strName, TEXT("None" ) ) == 0 )
- pEnemyStyle->EnemyAttackType = EAT_None;
- else
- MessageBox( NULL, "Unknown EnemyAttackType", strName, MB_OK );
- pEnemyStyle->fMoveRandomCountdown = GetFloat( strSection, TEXT("MoveRandomCountdown"), TEXT("1.0f") );
- pEnemyStyle->fThrustCountdown = GetFloat( strSection, TEXT("ThrustCountdown"), TEXT("1.0f") );
- pEnemyStyle->fTurnCountdown = GetFloat( strSection, TEXT("TurnCountdown"), TEXT("0.1f") );
- pEnemyStyle->fMoveTowardsAccuracy = GetFloat( strSection, TEXT("MoveTowardsAccuracy"), TEXT("0.1f") );
- pEnemyStyle->fMaxHealth = GetFloat( strSection, TEXT("MaxHealth"), TEXT("100.0") );
- pEnemyStyle->fMass = GetFloat( strSection, TEXT("Mass"), TEXT("5.0") );
- pEnemyStyle->fInvulnerableCountdown = GetFloat( strSection, TEXT("InvulnerableCountdown"), TEXT("0.0") );
- pEnemyStyle->fHitAnimationCountdown = GetFloat( strSection, TEXT("HitAnimationCountdown"), TEXT("1.0") );
- pEnemyStyle->fDeathAnimationCountdown= GetFloat( strSection, TEXT("DeathAnimationCountdown"), TEXT("1.0") );
- pEnemyStyle->fDamage = GetFloat( strSection, TEXT("Damage"), TEXT("10.0") );
- DWORD dwColor;
- dwColor = GetHex( strSection, TEXT("AliveColor"), TEXT("0x00000000") );
- pEnemyStyle->clrAlive = dwColor;
- dwColor = GetHex( strSection, TEXT("DeadColor"), TEXT("0x00000000") );
- pEnemyStyle->clrDead = dwColor;
- pEnemyStyle->fMass = GetFloat( strSection, TEXT("Mass"), TEXT("5.0") );
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc: This function gets the sound parameters from
- // the specified section of the private profile.
- //-----------------------------------------------------------------------------
- VOID CProfile::GetLandType( CZoneStyleParameter* pLandType, TCHAR* strSection )
- {
- TCHAR strName[MAX_PATH];
- GetString( strName, strSection, TEXT("HeightCreationType"), TEXT("FromFile") );
- if( lstrcmp( strName, TEXT("FromFile" ) ) == 0 )
- pLandType->HeightCreationType = HCT_FromFile;
- else if( lstrcmp( strName, TEXT("CreateTest" ) ) == 0 )
- pLandType->HeightCreationType = HCT_CreateTest;
- GetString( pLandType->szHeightMap, strSection, TEXT("HeightMap"), TEXT("land.bmp") );
- GetString( strName, strSection, TEXT("TextureCreationType"), TEXT("FromLayers") );
- if( lstrcmp( strName, TEXT("FromFile" ) ) == 0 )
- pLandType->TextureCreationType = TCT_FromFile;
- else if( lstrcmp( strName, TEXT("CreateTest" ) ) == 0 )
- pLandType->TextureCreationType = TCT_CreateTest;
- else if( lstrcmp( strName, TEXT("CreateFromHeight" ) ) == 0 )
- pLandType->TextureCreationType = TCT_CreateFromHeight;
- else if( lstrcmp( strName, TEXT("FromLayers" ) ) == 0 )
- pLandType->TextureCreationType = TCT_FromLayers;
- pLandType->dwTextureSize = GetLong( strSection, TEXT("TextureSize"), TEXT("256") );
- if( pLandType->TextureCreationType == TCT_FromLayers ||
- pLandType->TextureCreationType == TCT_CreateFromHeight )
- {
- pLandType->dwNumLayers = GetLong( strSection, TEXT("NumLayers"), TEXT("1") );
- assert( pLandType->dwNumLayers <= MAX_SOURCE_TEXTURES );
- for( DWORD iLayer=0; iLayer<pLandType->dwNumLayers; iLayer++ )
- {
- wsprintf( strName, "LayerTexture%d", iLayer+1 );
- GetString( pLandType->aLayerTexture[iLayer], strSection, strName, TEXT("gfx\land_sand64.bmp") );
- wsprintf( strName, "LayerHeight%d", iLayer+1 );
- pLandType->aLayerHeight[iLayer] = GetFloat( strSection, strName, TEXT("0.0f") ) / MAX_HEIGHT_OF_MAP;
- wsprintf( strName, "LayerTile%d", iLayer+1 );
- pLandType->aLayerTile[iLayer] = GetFloat( strSection, strName, TEXT("4.0f") );
- wsprintf( strName, "LayerRandomness%d", iLayer+1 );
- pLandType->aLayerRandomness[iLayer] = GetFloat( strSection, strName, TEXT("0.05f") );
- wsprintf( strName, "LayerColor%d", iLayer+1 );
- pLandType->aLayerColor[iLayer] = GetHex( strSection, strName, TEXT("0xFF0000FF") );
- wsprintf( strName, "LayerBlendFactor%d", iLayer+1 );
- pLandType->fLayerBlendFactor[iLayer] = GetFloat( strSection, strName, TEXT("1.4f") );
- }
- }
- GetString( pLandType->szTextureMap, strSection, TEXT("TextureMap"), TEXT("land.bmp") );
- pLandType->bSaveMedia = GetLong( strSection, TEXT("SaveMedia"), TEXT("0") );
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- VOID CProfile::GetSkyParameters( CSkyParameter* pSky, LPCTSTR strSection )
- {
- GetString( pSky->szModel, TEXT("SKY"), TEXT("Model"), TEXT("sky-model.x") );
- GetString( pSky->szTextureMap, TEXT("SKY"), TEXT("TextureMap"), TEXT("sky-texture.bmp") );
- pSky->dwFogColor = GetHex( TEXT("SKY"), TEXT("FogColor"), TEXT("0xFF0000FF") );
- pSky->dwClearColor = GetHex( TEXT("SKY"), TEXT("ClearColor"), TEXT("0xFF000000") );
- pSky->fOffsetY = GetFloat( TEXT("SKY"), TEXT("OffsetY"), TEXT("-400.0f") );
- pSky->fScaleX = GetFloat( TEXT("SKY"), TEXT("ScaleX"), TEXT("1.0f") );
- pSky->fScaleY = GetFloat( TEXT("SKY"), TEXT("ScaleY"), TEXT("1.0f") );
- pSky->fScaleZ = GetFloat( TEXT("SKY"), TEXT("ScaleZ"), TEXT("1.0f") );
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc: This function gets the sound parameters from
- // the specified section of the private profile.
- //-----------------------------------------------------------------------------
- VOID CProfile::GetSoundParameters(TCHAR* strSection, CSoundParameter* pSoundParam)
- {
- TCHAR szBuffer[MAX_PATH];
- GetPrivateProfileString( strSection, TEXT("WavFile"), TEXT("