diff --git a/src/GameLib/MapManager.cpp b/src/GameLib/MapManager.cpp index 57b8f9e..2bc620b 100644 --- a/src/GameLib/MapManager.cpp +++ b/src/GameLib/MapManager.cpp @@ -261,50 +261,38 @@ void CMapManager::BeginEnvironment() if (mc_pcurEnvironmentData->bFogEnable) { - DWORD dwFogColor = mc_pcurEnvironmentData->FogColor; + const DWORD dwFogColor = mc_pcurEnvironmentData->FogColor; STATEMANAGER.SetRenderState(D3DRS_FOGCOLOR, dwFogColor); - // MR-14: Fog update by Alaric + const int iFogLevel = CPythonSystem::Instance().GetFogLevel(); // 2=Dense,1=Middle,0=Light - // DIFFERENCE WITH THE OFFICIAL VERSION: - /* - Currently the official does not use the buttons "Dense", "Middle", "Light" for fog density. Instead, - they use an On/Off boolean variable. To maintain the classic feel in the settings, we customized the - modern official functionality into the 3-way button controls. - - To migrate to boolean (official-like), replace mc_pcurEnvironmentData->bDensityFog with m_isFogModeEnabled - and remove the const float fFogDensityLevel[3] and instead, multiple mc_pcurEnvironmentData->bFogLevel with - the official 0.000010f value for the fDensity. - - To migrate with the official, other variables in this update must be adjusted as well. - */ - - if (mc_pcurEnvironmentData->bDensityFog && mc_pcurEnvironmentData->bFogLevel != 0) + if (mc_pcurEnvironmentData->bDensityFog && (mc_pcurEnvironmentData->bFogLevel != 0)) { const float fFogDensityLevel[3] = { 0.000006f, 0.000004f, 0.000002f }; - float fDensity = mc_pcurEnvironmentData->bFogLevel * fFogDensityLevel[CPythonSystem::Instance().GetFogLevel()]; + float fDensity = mc_pcurEnvironmentData->bFogLevel * fFogDensityLevel[iFogLevel]; - STATEMANAGER.SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_EXP); // pixel fog - STATEMANAGER.SetRenderState(D3DRS_FOGDENSITY, *((DWORD *) &fDensity)); // vertex fog + STATEMANAGER.SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_EXP); // pixel fog + STATEMANAGER.SetRenderState(D3DRS_FOGDENSITY, *((DWORD *) &fDensity)); // vertex fog float fApproxFogFar = 2.3f / fDensity; CSpeedTreeForestDirectX& rkForest = CSpeedTreeForestDirectX::Instance(); rkForest.SetFog(0.0f, fApproxFogFar); } - // MR-14: -- END OF -- Fog update by Alaric else { + const float fFogScaleLevel[3] = { 0.75f, 1.0f, 1.25f }; + + float fFogNear = mc_pcurEnvironmentData->GetFogNearDistance(); + float fFogFar = mc_pcurEnvironmentData->GetFogFarDistance(); + + fFogNear *= fFogScaleLevel[iFogLevel]; + fFogFar *= fFogScaleLevel[iFogLevel]; + CSpeedTreeForestDirectX& rkForest=CSpeedTreeForestDirectX::Instance(); - rkForest.SetFog( - mc_pcurEnvironmentData->GetFogNearDistance(), - mc_pcurEnvironmentData->GetFogFarDistance() - ); + rkForest.SetFog(fFogNear, fFogFar); - float fFogNear=mc_pcurEnvironmentData->GetFogNearDistance(); - float fFogFar=mc_pcurEnvironmentData->GetFogFarDistance(); - - STATEMANAGER.SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR); // vertex fox - STATEMANAGER.SetRenderState(D3DRS_RANGEFOGENABLE, TRUE); // vertex fox + STATEMANAGER.SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR); // vertex fox + STATEMANAGER.SetRenderState(D3DRS_RANGEFOGENABLE, TRUE); // vertex fox STATEMANAGER.SetRenderState(D3DRS_FOGSTART, *((DWORD *) &fFogNear)); // USED BY D3DFOG_LINEAR STATEMANAGER.SetRenderState(D3DRS_FOGEND, *((DWORD *) &fFogFar)); // USED BY D3DFOG_LINEAR } diff --git a/src/GameLib/MapUtil.cpp b/src/GameLib/MapUtil.cpp index 80cccc7..f64bdce 100644 --- a/src/GameLib/MapUtil.cpp +++ b/src/GameLib/MapUtil.cpp @@ -30,6 +30,7 @@ void Environment_Init(SEnvironmentData& envData) // MR-14: Fog update by Alaric envData.bFogEnable = TRUE; envData.bDensityFog = TRUE; + envData.bFogLevel = 0; // MR-14: -- END OF -- Fog update by Alaric envData.m_fFogNearDistance = 25600.0f * 0.5f; envData.m_fFogFarDistance = 25600.0f * 0.7f; @@ -116,17 +117,23 @@ bool Environment_Load(SEnvironmentData& envData, const char* envFileName) if (textLoader.SetChildNode("fog")) { - // MR-14: Fog update by Alaric - // textLoader.GetTokenBoolean("enable", &envData.bFogEnable); - // textLoader.GetTokenBoolean("isdensity", &envData.bDensityFog); - // textLoader.GetTokenFloat("neardistance", &envData.m_fFogNearDistance); - // textLoader.GetTokenFloat("fardistance", &envData.m_fFogFarDistance); - textLoader.GetTokenByte("foglevel", &envData.bFogLevel); - // MR-14: -- END OF -- Fog update by Alaric + if (textLoader.GetTokenByte("foglevel", &envData.bFogLevel)) + { + envData.bDensityFog = true; + } + else + { + envData.bDensityFog = false; + textLoader.GetTokenBoolean("enable", &envData.bFogEnable); + textLoader.GetTokenFloat("neardistance", &envData.m_fFogNearDistance); + textLoader.GetTokenFloat("fardistance", &envData.m_fFogFarDistance); + } + textLoader.GetTokenColor("color", &envData.FogColor); + textLoader.SetParentNode(); } - + if (textLoader.SetChildNode("filter")) { textLoader.GetTokenBoolean("enable", (BOOL *) &envData.bFilteringEnable); @@ -308,4 +315,4 @@ float CEaseOutInterpolation::GetValue() float CEaseOutInterpolation::GetChangingValue() { return m_fValue - m_fLastValue; -} \ No newline at end of file +}