Skip to content

Commit 3e604d5

Browse files
committed
Fog fixes
1 parent 2c73eb7 commit 3e604d5

File tree

9 files changed

+124
-22
lines changed

9 files changed

+124
-22
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ This repository contains the source code necessary to compile the game client ex
1616

1717
## 📋 Changelog
1818
### 🐛 Bug fixes
19-
- **TempTrace**: Added `n` support for Python
20-
- **Togglable slots**: Fixed slots not deactivating on death
21-
- **Affects**: Added affect shower support for Mall Attack Speed
22-
- **Specular**: Fixed a bug where specular would not isolate to the targeted item. Swapping for example to a weapon with different specular would cause all surrounding weapon meshes to change specular as well. The issue has been fixed.
19+
- **Fog update**: Adjusted fog settings to work with the updated official version using the 3 classic options.
2320

2421
<br>
2522
<br>

src/EterLib/StateManager.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,9 @@ void CStateManager::SetDefaultState()
241241
SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
242242
SetRenderState(D3DRS_FOGENABLE, FALSE);
243243
SetRenderState(D3DRS_FOGCOLOR, 0xFF000000);
244-
SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);
244+
// MR-14: Fog update by Alaric
245+
SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_NONE);
246+
// MR-14: -- END OF -- Fog update by Alaric
245247
SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR);
246248
SetRenderState(D3DRS_RANGEFOGENABLE, FALSE);
247249
SetRenderState(D3DRS_ZENABLE, TRUE);

src/GameLib/MapManager.cpp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@
77

88
#include "PropertyLoader.h"
99

10+
// MR-14: Fog update by Alaric
11+
// Not the proper way to handle this but I'm lazy
12+
#ifdef _DEBUG
13+
#undef _DEBUG
14+
#include <python/python.h>
15+
#define _DEBUG
16+
#else
17+
#include <python/python.h>
18+
#endif
19+
20+
#include "UserInterface/PythonSystem.h"
21+
// MR-14: -- END OF -- Fog update by Alaric
22+
1023
//////////////////////////////////////////////////////////////////////////
1124
// 기본 함수
1225
//////////////////////////////////////////////////////////////////////////
@@ -251,12 +264,30 @@ void CMapManager::BeginEnvironment()
251264
DWORD dwFogColor = mc_pcurEnvironmentData->FogColor;
252265
STATEMANAGER.SetRenderState(D3DRS_FOGCOLOR, dwFogColor);
253266

254-
if (mc_pcurEnvironmentData->bDensityFog)
267+
// MR-14: Fog update by Alaric
268+
269+
// DIFFERENCE WITH THE OFFICIAL VERSION:
270+
/*
271+
Currently the official does not use the buttons "Dense", "Middle", "Light" for fog density. Instead,
272+
they use an On/Off boolean variable. To maintain the classic feel in the settings, we customized the
273+
modern official functionality into the 3-way button controls.
274+
275+
To migrate to boolean (official-like), replace mc_pcurEnvironmentData->bDensityFog with m_isFogModeEnabled
276+
and remove the const float fFogDensityLevel[3] and instead, multiple mc_pcurEnvironmentData->bFogLevel with
277+
the official 0.000010f value for the fDensity.
278+
279+
To migrate with the official, other variables in this update must be adjusted as well.
280+
*/
281+
282+
if (mc_pcurEnvironmentData->bDensityFog && mc_pcurEnvironmentData->bFogLevel != 0)
255283
{
256-
float fDensity = 0.00015f;
284+
const float fFogDensityLevel[3] = { 0.000020f, 0.000010f, 0.000005f };
285+
float fDensity = mc_pcurEnvironmentData->bFogLevel * fFogDensityLevel[CPythonSystem::Instance().GetFogLevel()];
286+
257287
STATEMANAGER.SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_EXP); // pixel fog
258288
STATEMANAGER.SetRenderState(D3DRS_FOGDENSITY, *((DWORD *) &fDensity)); // vertex fog
259289
}
290+
// MR-14: -- END OF -- Fog update by Alaric
260291
else
261292
{
262293
CSpeedTreeForestDirectX8& rkForest=CSpeedTreeForestDirectX8::Instance();
@@ -267,6 +298,7 @@ void CMapManager::BeginEnvironment()
267298

268299
float fFogNear=mc_pcurEnvironmentData->GetFogNearDistance();
269300
float fFogFar=mc_pcurEnvironmentData->GetFogFarDistance();
301+
270302
STATEMANAGER.SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR); // vertex fox
271303
STATEMANAGER.SetRenderState(D3DRS_RANGEFOGENABLE, TRUE); // vertex fox
272304
STATEMANAGER.SetRenderState(D3DRS_FOGSTART, *((DWORD *) &fFogNear)); // USED BY D3DFOG_LINEAR

src/GameLib/MapOutdoorRenderHTP.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,17 @@ void CMapOutdoor::__RenderTerrain_RenderHardwareTransformPatch()
8989

9090
SelectIndexBuffer(0, &wPrimitiveCount, &ePrimitiveType);
9191

92-
DWORD dwFogEnable = STATEMANAGER.GetRenderState(D3DRS_FOGENABLE);
92+
// MR-14: Fog update by Alaric
93+
// DWORD dwFogEnable = STATEMANAGER.GetRenderState(D3DRS_FOGENABLE);
94+
// MR-14: -- END OF -- Fog update by Alaric
9395
std::vector<std::pair<float, long> >::iterator it = m_PatchVector.begin();
9496

9597
// NOTE: 맵툴에서는 view ~ fog near 사이의 지형을 fog disabled 상태로 그리는 작업을 하지 않음.
96-
STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, FALSE);
98+
// MR-14: Fog update by Alaric
99+
// STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, FALSE);
100+
// MR-14: -- END OF -- Fog update by Alaric
97101

98-
for( ; it != near_it; ++it)
102+
for(; it != near_it; ++it)
99103
{
100104
if (byCUrrentLODLevel == 0 && fLODLevel1Distance <= it->first)
101105
{
@@ -109,14 +113,17 @@ void CMapOutdoor::__RenderTerrain_RenderHardwareTransformPatch()
109113
}
110114

111115
__HardwareTransformPatch_RenderPatchSplat(it->second, wPrimitiveCount, ePrimitiveType);
116+
112117
if (m_iRenderedSplatNum >= m_iSplatLimit)
113118
break;
114119

115120
if (m_bDrawWireFrame)
116121
DrawWireFrame(it->second, wPrimitiveCount, ePrimitiveType);
117122
}
118123

119-
STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, dwFogEnable);
124+
// MR-14: Fog update by Alaric
125+
// STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, dwFogEnable);
126+
// MR-14: -- END OF -- Fog update by Alaric
120127

121128
if (m_iRenderedSplatNum < m_iSplatLimit)
122129
{
@@ -143,7 +150,9 @@ void CMapOutdoor::__RenderTerrain_RenderHardwareTransformPatch()
143150
}
144151
}
145152

146-
STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, FALSE);
153+
// MR-14: Fog update by Alaric
154+
// STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, FALSE);
155+
// MR-14: -- END OF -- Fog update by Alaric
147156
STATEMANAGER.SetRenderState(D3DRS_LIGHTING, FALSE);
148157

149158
STATEMANAGER.SetTexture(0, NULL);
@@ -195,7 +204,9 @@ void CMapOutdoor::__RenderTerrain_RenderHardwareTransformPatch()
195204
STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
196205
STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
197206

198-
STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, dwFogEnable);
207+
// MR-14: Fog update by Alaric
208+
// STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, dwFogEnable);
209+
// MR-14: -- END OF -- Fog update by Alaric
199210
STATEMANAGER.SetRenderState(D3DRS_LIGHTING, TRUE);
200211

201212
std::sort(m_RenderedTextureNumVector.begin(),m_RenderedTextureNumVector.end());

src/GameLib/MapType.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ typedef struct SEnvironmentData
143143
float GetFogFarDistance() const;
144144

145145
D3DXCOLOR FogColor;
146+
// MR-14: Fog update by Alaric
147+
BYTE bFogLevel;
148+
// MR-14: -- END OF -- Fog update by Alaric
146149

147150
// Filtering
148151
BOOL bFilteringEnable;

src/GameLib/MapUtil.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ void Environment_Init(SEnvironmentData& envData)
2727
envData.Material.Specular = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);
2828
envData.Material.Power = 0.0f;
2929

30-
envData.bFogEnable = FALSE;
31-
envData.bDensityFog = FALSE;
30+
// MR-14: Fog update by Alaric
31+
envData.bFogEnable = TRUE;
32+
envData.bDensityFog = TRUE;
33+
// MR-14: -- END OF -- Fog update by Alaric
3234
envData.m_fFogNearDistance = 25600.0f * 0.5f;
3335
envData.m_fFogFarDistance = 25600.0f * 0.7f;
3436
envData.FogColor = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
@@ -114,10 +116,13 @@ bool Environment_Load(SEnvironmentData& envData, const char* envFileName)
114116

115117
if (textLoader.SetChildNode("fog"))
116118
{
117-
textLoader.GetTokenBoolean("enable", &envData.bFogEnable);
118-
textLoader.GetTokenBoolean("isdensity", &envData.bDensityFog);
119-
textLoader.GetTokenFloat("neardistance", &envData.m_fFogNearDistance);
120-
textLoader.GetTokenFloat("fardistance", &envData.m_fFogFarDistance);
119+
// MR-14: Fog update by Alaric
120+
// textLoader.GetTokenBoolean("enable", &envData.bFogEnable);
121+
// textLoader.GetTokenBoolean("isdensity", &envData.bDensityFog);
122+
// textLoader.GetTokenFloat("neardistance", &envData.m_fFogNearDistance);
123+
// textLoader.GetTokenFloat("fardistance", &envData.m_fFogFarDistance);
124+
textLoader.GetTokenByte("foglevel", &envData.bFogLevel);
125+
// MR-14: -- END OF -- Fog update by Alaric
121126
textLoader.GetTokenColor("color", &envData.FogColor);
122127
textLoader.SetParentNode();
123128
}

src/UserInterface/PythonSystem.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,18 @@ void CPythonSystem::SetShadowLevel(unsigned int level)
244244
CPythonBackground::instance().RefreshShadowLevel();
245245
}
246246

247+
// MR-14: Fog update by Alaric
248+
int CPythonSystem::GetFogLevel()
249+
{
250+
return m_Config.iFogLevel;
251+
}
252+
253+
void CPythonSystem::SetFogLevel(unsigned int level)
254+
{
255+
m_Config.iFogLevel = MIN(level, 2);
256+
}
257+
// MR-14: -- END OF -- Fog update by Alaric
258+
247259
int CPythonSystem::IsSaveID()
248260
{
249261
return m_Config.isSaveID;
@@ -299,6 +311,9 @@ void CPythonSystem::SetDefaultConfig()
299311
m_Config.bDecompressDDS = 0;
300312
m_Config.bSoftwareTiling = 0;
301313
m_Config.iShadowLevel = 3;
314+
// MR-14: Fog update by Alaric
315+
m_Config.iFogLevel = 0;
316+
// MR-14: -- END OF -- Fog update by Alaric
302317
m_Config.bViewChat = true;
303318
m_Config.bAlwaysShowName = DEFAULT_VALUE_ALWAYS_SHOW_NAME;
304319
m_Config.bShowDamage = true;
@@ -431,6 +446,10 @@ bool CPythonSystem::LoadConfig()
431446
m_Config.bSoftwareTiling = atoi(value);
432447
else if (!stricmp(command, "SHADOW_LEVEL"))
433448
m_Config.iShadowLevel = atoi(value);
449+
// MR-14: Fog update by Alaric
450+
else if (!stricmp(command, "FOG_LEVEL"))
451+
m_Config.iFogLevel = atoi(value);
452+
// MR-14: -- END OF -- Fog update by Alaric
434453
else if (!stricmp(command, "DECOMPRESSED_TEXTURE"))
435454
m_Config.bDecompressDDS = atoi(value) == 1 ? true : false;
436455
else if (!stricmp(command, "NO_SOUND_CARD"))
@@ -520,11 +539,11 @@ bool CPythonSystem::SaveConfig()
520539
m_Config.bDecompressDDS);
521540

522541
if (m_Config.bWindowed == 1)
523-
fprintf(fp, "WINDOWED %d\n", m_Config.bWindowed);
542+
fprintf(fp, "WINDOWED %d\n", m_Config.bWindowed);
524543
if (m_Config.bViewChat == 0)
525-
fprintf(fp, "VIEW_CHAT %d\n", m_Config.bViewChat);
544+
fprintf(fp, "VIEW_CHAT %d\n", m_Config.bViewChat);
526545
if (m_Config.bAlwaysShowName != DEFAULT_VALUE_ALWAYS_SHOW_NAME)
527-
fprintf(fp, "ALWAYS_VIEW_NAME %d\n", m_Config.bAlwaysShowName);
546+
fprintf(fp, "ALWAYS_VIEW_NAME %d\n", m_Config.bAlwaysShowName);
528547
if (m_Config.bShowDamage == 0)
529548
fprintf(fp, "SHOW_DAMAGE %d\n", m_Config.bShowDamage);
530549
if (m_Config.bShowSalesText == 0)
@@ -533,6 +552,9 @@ bool CPythonSystem::SaveConfig()
533552
fprintf(fp, "USE_DEFAULT_IME %d\n", m_Config.bUseDefaultIME);
534553
fprintf(fp, "SOFTWARE_TILING %d\n", m_Config.bSoftwareTiling);
535554
fprintf(fp, "SHADOW_LEVEL %d\n", m_Config.iShadowLevel);
555+
// MR-14: Fog update by Alaric
556+
fprintf(fp, "FOG_LEVEL %d\n", m_Config.iFogLevel);
557+
// MR-14: -- END OF -- Fog update by Alaric
536558
fprintf(fp, "\n");
537559

538560
fclose(fp);

src/UserInterface/PythonSystem.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class CPythonSystem : public CSingleton<CPythonSystem>
5757
bool is_object_culling;
5858
int iDistance;
5959
int iShadowLevel;
60+
// MR-14: Fog update by Alaric
61+
int iFogLevel;
62+
// MR-14: -- END OF -- Fog update by Alaric
6063

6164
FLOAT music_volume;
6265
FLOAT voice_volume;
@@ -149,6 +152,11 @@ class CPythonSystem : public CSingleton<CPythonSystem>
149152
int GetShadowLevel();
150153
void SetShadowLevel(unsigned int level);
151154

155+
// MR-14: Fog update by Alaric
156+
int GetFogLevel();
157+
void SetFogLevel(unsigned int level);
158+
// MR-14: -- END OF -- Fog update by Alaric
159+
152160
protected:
153161
TResolution m_ResolutionList[RESOLUTION_MAX_NUM];
154162
int m_ResolutionCount;

src/UserInterface/PythonSystemModule.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,32 @@ PyObject * systemSetShadowLevel(PyObject * poSelf, PyObject * poArgs)
372372
return Py_BuildNone();
373373
}
374374

375+
// MR-14: Fog update by Alaric
376+
PyObject * systemGetFogLevel(PyObject * poSelf, PyObject * poArgs)
377+
{
378+
return Py_BuildValue("i", CPythonSystem::Instance().GetFogLevel());
379+
}
380+
381+
PyObject * systemSetFogLevel(PyObject * poSelf, PyObject * poArgs)
382+
{
383+
int iLevel;
384+
if (!PyTuple_GetInteger(poArgs, 0, &iLevel))
385+
return Py_BuildException();
386+
387+
CPythonSystem::Instance().SetFogLevel(iLevel);
388+
return Py_BuildNone();
389+
}
390+
// MR-14: -- END OF -- Fog update by Alaric
391+
375392
void initsystem()
376393
{
377394
static PyMethodDef s_methods[] =
378395
{
396+
// MR-14: Fog update by Alaric
397+
{ "GetFogLevel", systemGetFogLevel, METH_VARARGS },
398+
{ "SetFogLevel", systemSetFogLevel, METH_VARARGS },
399+
// MR-14: -- END OF -- Fog update by Alaric
400+
379401
{ "GetWidth", systemGetWidth, METH_VARARGS },
380402
{ "GetHeight", systemGetHeight, METH_VARARGS },
381403

0 commit comments

Comments
 (0)