Skip to content

Commit ebe28dc

Browse files
authored
refactor(gamelod): Simplify texture reduction code (#1631)
1 parent 5155aea commit ebe28dc

File tree

20 files changed

+65
-110
lines changed

20 files changed

+65
-110
lines changed

Generals/Code/GameEngine/Include/Common/GameLOD.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,6 @@ class GameLODManager
176176
Bool setDynamicLODLevel(DynamicGameLODLevel level); ///< set the current dynamic LOD level.
177177
DynamicGameLODLevel getDynamicLODLevel(void) { return m_currentDynamicLOD;}
178178
void init(void); ///<initialize tables of preset LOD's.
179-
void setCurrentTextureReduction(Int val) {m_currentTextureReduction = val;}
180-
Int getCurrentTextureReduction(void) {return m_currentTextureReduction;}
181179
Int getStaticGameLODIndex(AsciiString name);
182180
Int getDynamicGameLODIndex(AsciiString name);
183181
inline Bool isParticleSkipped(void);
@@ -229,7 +227,6 @@ class GameLODManager
229227
Real m_floatBenchIndex;
230228
Real m_memBenchIndex;
231229
Real m_compositeBenchIndex;
232-
Real m_currentTextureReduction;
233230
Int m_reallyLowMHz;
234231
};
235232

Generals/Code/GameEngine/Include/GameClient/GameClient.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ class GameClient : public SubsystemInterface,
138138

139139
//---------------------------------------------------------------------------
140140
virtual void setTeamColor( Int red, Int green, Int blue ) = 0; ///< @todo superhack for demo, remove!!!
141-
virtual void adjustLOD( Int adj ) = 0; ///< @todo hack for evaluation, remove.
141+
142+
virtual void setTextureLOD( Int level ) = 0;
142143

143144
virtual void releaseShadows(void); ///< frees all shadow resources used by this module - used by Options screen.
144145
virtual void allocateShadows(void); ///< create shadow resources if not already present. Used by Options screen.

Generals/Code/GameEngine/Source/Common/GameLOD.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ GameLODManager::GameLODManager(void)
227227
m_memBenchIndex=0;
228228
m_compositeBenchIndex=0;
229229
m_numBenchProfiles=0;
230-
m_currentTextureReduction=0;
231230
m_reallyLowMHz = 400;
232231

233232
for (Int i=0; i<STATIC_GAME_LOD_CUSTOM; i++)
@@ -580,13 +579,7 @@ void GameLODManager::applyStaticLODLevel(StaticGameLODLevel level)
580579
TheWritableGlobalData->m_useShadowVolumes=lodInfo->m_useShadowVolumes;
581580
TheWritableGlobalData->m_useShadowDecals=lodInfo->m_useShadowDecals;
582581

583-
//Check if texture resolution changed. No need to apply when current is unknown because display will do it
584-
if (requestedTextureReduction != m_currentTextureReduction)
585-
{
586-
TheWritableGlobalData->m_textureReductionFactor = requestedTextureReduction;
587-
if (TheGameClient)
588-
TheGameClient->adjustLOD(0); //apply the new setting stored in globaldata
589-
}
582+
TheWritableGlobalData->m_textureReductionFactor = requestedTextureReduction;
590583

591584
//Check if shadow state changed
592585
if (m_currentStaticLOD == STATIC_GAME_LOD_UNKNOWN ||
@@ -623,9 +616,12 @@ void GameLODManager::applyStaticLODLevel(StaticGameLODLevel level)
623616
TheWritableGlobalData->m_shellMapOn = false;
624617
}
625618
}
619+
626620
if (TheTerrainVisual)
627621
TheTerrainVisual->setTerrainTracksDetail();
628622

623+
if (TheGameClient)
624+
TheGameClient->setTextureLOD(requestedTextureReduction);
629625
}
630626

631627
/**Parse a description of all the LOD settings for a given detail level*/

Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
//used to access a messagebox that does "ok" and "cancel"
7676
#include "GameClient/MessageBox.h"
7777

78+
#include "ww3d.h"
79+
7880
// This is for non-RC builds only!!!
7981
#define VERBOSE_VERSION L"Release"
8082

@@ -1112,18 +1114,14 @@ static void saveOptions( void )
11121114
//-------------------------------------------------------------------------------------------------
11131115
// Texture resolution slider
11141116
{
1115-
AsciiString prefString;
1116-
1117-
val = GadgetSliderGetPosition(sliderTextureResolution);
1118-
val = 2-val;
1117+
val = 2 - GadgetSliderGetPosition(sliderTextureResolution);
11191118

1119+
AsciiString prefString;
11201120
prefString.format("%d",val);
11211121
(*pref)["TextureReduction"] = prefString;
11221122

1123-
if (TheGlobalData->m_textureReductionFactor != val)
1124-
{
1125-
TheGameClient->adjustLOD(val-TheGlobalData->m_textureReductionFactor); //apply the new setting
1126-
}
1123+
TheWritableGlobalData->m_textureReductionFactor = val;
1124+
TheGameClient->setTextureLOD(val);
11271125
}
11281126

11291127
TheWritableGlobalData->m_useShadowVolumes = GadgetCheckBoxIsChecked( check3DShadows );
@@ -1855,10 +1853,9 @@ void OptionsMenuInit( WindowLayout *layout, void *userData )
18551853
TheGameLODManager->setStaticLODLevel(TheGameLODManager->getRecommendedStaticLODLevel());
18561854
}
18571855

1858-
Int txtFact=TheGameLODManager->getCurrentTextureReduction();
18591856
GadgetComboBoxSetSelectedPos(comboBoxDetail, (Int)TheGameLODManager->getStaticLODLevel());
18601857

1861-
GadgetSliderSetPosition( sliderTextureResolution, 2-txtFact);
1858+
GadgetSliderSetPosition( sliderTextureResolution, 2-WW3D::Get_Texture_Reduction());
18621859

18631860
GadgetCheckBoxSetChecked( check3DShadows, TheGlobalData->m_useShadowVolumes);
18641861

Generals/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
#include "GameNetwork/GameSpyOverlay.h"
8989
#include "GameNetwork/GameSpy/BuddyThread.h"
9090

91+
#include "ww3d.h"
9192

9293

9394
#if defined(RTS_DEBUG)
@@ -3785,7 +3786,8 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
37853786
//-----------------------------------------------------------------------------------------
37863787
case GameMessage::MSG_META_DEMO_LOD_DECREASE:
37873788
{
3788-
TheGameClient->adjustLOD(-1);
3789+
const Int level = clamp(0, WW3D::Get_Texture_Reduction() - 1, 4);
3790+
TheGameClient->setTextureLOD(level);
37893791
TheInGameUI->messageNoFormat( TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:DebugDecreaseLOD", L"Decrease LOD") );
37903792
disp = DESTROY_MESSAGE;
37913793
break;
@@ -3795,7 +3797,8 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
37953797
//-----------------------------------------------------------------------------------------
37963798
case GameMessage::MSG_META_DEMO_LOD_INCREASE:
37973799
{
3798-
TheGameClient->adjustLOD(1);
3800+
const Int level = clamp(0, WW3D::Get_Texture_Reduction() + 1, 4);
3801+
TheGameClient->setTextureLOD(level);
37993802
TheInGameUI->messageNoFormat( TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:DebugIncreaseLOD", L"Increase LOD") );
38003803
disp = DESTROY_MESSAGE;
38013804
break;

Generals/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DGameClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class W3DGameClient : public GameClient
8888

8989
//---------------------------------------------------------------------------
9090
virtual void setTeamColor( Int red, Int green, Int blue ); ///< @todo superhack for demo, remove!!!
91-
virtual void adjustLOD( Int adj ); ///< @todo hack for evaluation, remove.
91+
virtual void setTextureLOD( Int level );
9292

9393
protected:
9494

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/TerrainTex.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ int TerrainTextureClass::update(WorldHeightMap *htMap)
187187
surface_level->UnlockRect();
188188
surface_level->Release();
189189
DX8_ErrorCode(D3DXFilterTexture(Peek_D3D_Texture(), NULL, 0, D3DX_FILTER_BOX));
190-
if (TheWritableGlobalData->m_textureReductionFactor) {
191-
Peek_D3D_Texture()->SetLOD(TheWritableGlobalData->m_textureReductionFactor);
190+
if (WW3D::Get_Texture_Reduction()) {
191+
Peek_D3D_Texture()->SetLOD(WW3D::Get_Texture_Reduction());
192192
}
193193
return(surface_desc.Height);
194194
}

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -745,14 +745,10 @@ void W3DDisplay::init( void )
745745
TheGameLODManager->setStaticLODLevel(TheGameLODManager->getRecommendedStaticLODLevel());
746746
}
747747
else
748-
{ //Static LOD level was applied during GameLOD manager init except for texture reduction
748+
{
749+
//Static LOD level was applied during GameLOD manager init except for texture reduction
749750
//which needs to be applied here.
750-
Int txtReduction=TheWritableGlobalData->m_textureReductionFactor;
751-
if (txtReduction > 0)
752-
{ WW3D::Set_Texture_Reduction(txtReduction,6);
753-
//Tell LOD manager that texture reduction was applied.
754-
TheGameLODManager->setCurrentTextureReduction(txtReduction);
755-
}
751+
TheGameClient->setTextureLOD(TheWritableGlobalData->m_textureReductionFactor);
756752
}
757753

758754
if (TheGlobalData->m_displayGamma != 1.0f)

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DGameClient.cpp

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -196,29 +196,16 @@ void W3DGameClient::setTeamColor(Int red, Int green, Int blue)
196196
}
197197

198198
//-------------------------------------------------------------------------------------------------
199-
/** temporary entry point for adjusting LOD for development testing. */
200199
//-------------------------------------------------------------------------------------------------
201-
void W3DGameClient::adjustLOD( Int adj )
200+
void W3DGameClient::setTextureLOD( Int level )
202201
{
203-
if (TheGlobalData == NULL)
204-
return;
205-
206-
TheWritableGlobalData->m_textureReductionFactor += adj;
207-
208-
if (TheWritableGlobalData->m_textureReductionFactor > 4)
209-
TheWritableGlobalData->m_textureReductionFactor = 4; //16x less resolution is probably enough.
210-
if (TheWritableGlobalData->m_textureReductionFactor < 0)
211-
TheWritableGlobalData->m_textureReductionFactor = 0;
202+
if (WW3D::Get_Texture_Reduction() != level)
203+
{
204+
WW3D::Set_Texture_Reduction(level, 6);
212205

213-
if (WW3D::Get_Texture_Reduction() != TheWritableGlobalData->m_textureReductionFactor)
214-
{ WW3D::Set_Texture_Reduction(TheWritableGlobalData->m_textureReductionFactor,6);
215-
TheGameLODManager->setCurrentTextureReduction(TheWritableGlobalData->m_textureReductionFactor);
206+
//I commented this out because we're no longer using terrain LOD. So I
207+
//stole this function and keys to adjust the texture resolution instead. -MW
208+
//if( TheTerrainRenderObject )
209+
// TheTerrainRenderObject->setTextureLOD(level);
216210
}
217-
218-
//I commented this out because we're no longer using terrain LOD. So I
219-
//stole this function and keys to adjust the texture resolution instead. -MW
220-
221-
// if( TheTerrainRenderObject )
222-
// TheTerrainRenderObject->adjustTerrainLOD( adj );
223-
224211
}

GeneralsMD/Code/GameEngine/Include/Common/GameLOD.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ class GameLODManager
177177
Bool setDynamicLODLevel(DynamicGameLODLevel level); ///< set the current dynamic LOD level.
178178
DynamicGameLODLevel getDynamicLODLevel(void) { return m_currentDynamicLOD;}
179179
void init(void); ///<initialize tables of preset LOD's.
180-
void setCurrentTextureReduction(Int val) {m_currentTextureReduction = val;}
181-
Int getCurrentTextureReduction(void) {return m_currentTextureReduction;}
182180
Int getStaticGameLODIndex(AsciiString name);
183181
Int getDynamicGameLODIndex(AsciiString name);
184182
inline Bool isParticleSkipped(void);
@@ -230,7 +228,6 @@ class GameLODManager
230228
Real m_floatBenchIndex;
231229
Real m_memBenchIndex;
232230
Real m_compositeBenchIndex;
233-
Int m_currentTextureReduction;
234231
Int m_reallyLowMHz;
235232
};
236233

0 commit comments

Comments
 (0)