Skip to content

Commit fb42749

Browse files
committed
refactor(gamelod): Simplify texture reduction code
1 parent aadbe9d commit fb42749

File tree

11 files changed

+33
-55
lines changed

11 files changed

+33
-55
lines changed

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

GeneralsMD/Code/GameEngine/Include/GameClient/GameClient.h

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

144144
//---------------------------------------------------------------------------
145145
virtual void setTeamColor( Int red, Int green, Int blue ) = 0; ///< @todo superhack for demo, remove!!!
146-
virtual void adjustLOD( Int adj ) = 0; ///< @todo hack for evaluation, remove.
146+
147+
virtual void setTextureLOD( Int level ) = 0;
147148

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

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ GameLODManager::GameLODManager(void)
229229
m_memBenchIndex=0;
230230
m_compositeBenchIndex=0;
231231
m_numBenchProfiles=0;
232-
m_currentTextureReduction=0;
233232
m_reallyLowMHz = 400;
234233

235234
for (Int i=0; i<STATIC_GAME_LOD_CUSTOM; i++)
@@ -585,13 +584,7 @@ void GameLODManager::applyStaticLODLevel(StaticGameLODLevel level)
585584
TheWritableGlobalData->m_useShadowVolumes=lodInfo->m_useShadowVolumes;
586585
TheWritableGlobalData->m_useShadowDecals=lodInfo->m_useShadowDecals;
587586

588-
//Check if texture resolution changed. No need to apply when current is unknown because display will do it
589-
if (requestedTextureReduction != m_currentTextureReduction)
590-
{
591-
TheWritableGlobalData->m_textureReductionFactor = requestedTextureReduction;
592-
if (TheGameClient)
593-
TheGameClient->adjustLOD(0); //apply the new setting stored in globaldata
594-
}
587+
TheWritableGlobalData->m_textureReductionFactor = requestedTextureReduction;
595588

596589
//Check if shadow state changed
597590
if (m_currentStaticLOD == STATIC_GAME_LOD_UNKNOWN ||
@@ -629,9 +622,12 @@ void GameLODManager::applyStaticLODLevel(StaticGameLODLevel level)
629622
TheWritableGlobalData->m_shellMapOn = false;
630623
}
631624
}
625+
632626
if (TheTerrainVisual)
633627
TheTerrainVisual->setTerrainTracksDetail();
634628

629+
if (TheGameClient)
630+
TheGameClient->setTextureLOD(requestedTextureReduction);
635631
}
636632

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

GeneralsMD/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

@@ -1095,18 +1097,14 @@ static void saveOptions( void )
10951097
//-------------------------------------------------------------------------------------------------
10961098
// Texture resolution slider
10971099
{
1098-
AsciiString prefString;
1099-
1100-
val = GadgetSliderGetPosition(sliderTextureResolution);
1101-
val = 2-val;
1100+
val = 2 - GadgetSliderGetPosition(sliderTextureResolution);
11021101

1102+
AsciiString prefString;
11031103
prefString.format("%d",val);
11041104
(*pref)["TextureReduction"] = prefString;
11051105

1106-
if (TheGlobalData->m_textureReductionFactor != val)
1107-
{
1108-
TheGameClient->adjustLOD(val-TheGlobalData->m_textureReductionFactor); //apply the new setting
1109-
}
1106+
TheWritableGlobalData->m_textureReductionFactor = val;
1107+
TheGameClient->setTextureLOD(val);
11101108
}
11111109

11121110
TheWritableGlobalData->m_useShadowVolumes = GadgetCheckBoxIsChecked( check3DShadows );
@@ -1829,10 +1827,9 @@ void OptionsMenuInit( WindowLayout *layout, void *userData )
18291827
TheGameLODManager->setStaticLODLevel(TheGameLODManager->getRecommendedStaticLODLevel());
18301828
}
18311829

1832-
Int txtFact=TheGameLODManager->getCurrentTextureReduction();
18331830
GadgetComboBoxSetSelectedPos(comboBoxDetail, (Int)TheGameLODManager->getStaticLODLevel());
18341831

1835-
GadgetSliderSetPosition( sliderTextureResolution, 2-txtFact);
1832+
GadgetSliderSetPosition( sliderTextureResolution, 2-WW3D::Get_Texture_Reduction());
18361833

18371834
GadgetCheckBoxSetChecked( check3DShadows, TheGlobalData->m_useShadowVolumes);
18381835

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

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

91-
91+
#include "ww3d.h"
9292

9393

9494
#define dont_ALLOW_ALT_F4
@@ -4179,7 +4179,8 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
41794179
//-----------------------------------------------------------------------------------------
41804180
case GameMessage::MSG_META_DEMO_LOD_DECREASE:
41814181
{
4182-
TheGameClient->adjustLOD(-1);
4182+
const Int level = clamp(0, WW3D::Get_Texture_Reduction() - 1, 4);
4183+
TheGameClient->setTextureLOD(level);
41834184
TheInGameUI->messageNoFormat( TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:DebugDecreaseLOD", L"Decrease LOD") );
41844185
disp = DESTROY_MESSAGE;
41854186
break;
@@ -4189,7 +4190,8 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
41894190
//-----------------------------------------------------------------------------------------
41904191
case GameMessage::MSG_META_DEMO_LOD_INCREASE:
41914192
{
4192-
TheGameClient->adjustLOD(1);
4193+
const Int level = clamp(0, WW3D::Get_Texture_Reduction() + 1, 4);
4194+
TheGameClient->setTextureLOD(level);
41934195
TheInGameUI->messageNoFormat( TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:DebugIncreaseLOD", L"Increase LOD") );
41944196
disp = DESTROY_MESSAGE;
41954197
break;

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

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

9393
//---------------------------------------------------------------------------
9494
virtual void setTeamColor( Int red, Int green, Int blue ); ///< @todo superhack for demo, remove!!!
95-
virtual void adjustLOD( Int adj ); ///< @todo hack for evaluation, remove.
95+
virtual void setTextureLOD( Int level );
9696
virtual void notifyTerrainObjectMoved(Object *obj);
9797

9898
protected:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ int TerrainTextureClass::update(WorldHeightMap *htMap)
195195
surface_level->UnlockRect();
196196
surface_level->Release();
197197
DX8_ErrorCode(D3DXFilterTexture(Peek_D3D_Texture(), NULL, 0, D3DX_FILTER_BOX));
198-
if (TheWritableGlobalData->m_textureReductionFactor) {
199-
Peek_D3D_Texture()->SetLOD(TheWritableGlobalData->m_textureReductionFactor);
198+
if (WW3D::Get_Texture_Reduction()) {
199+
Peek_D3D_Texture()->SetLOD(WW3D::Get_Texture_Reduction());
200200
}
201201
return(surface_desc.Height);
202202
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -794,14 +794,10 @@ void W3DDisplay::init( void )
794794
TheGameLODManager->setStaticLODLevel(TheGameLODManager->getRecommendedStaticLODLevel());
795795
}
796796
else
797-
{ //Static LOD level was applied during GameLOD manager init except for texture reduction
797+
{
798+
//Static LOD level was applied during GameLOD manager init except for texture reduction
798799
//which needs to be applied here.
799-
Int txtReduction=TheWritableGlobalData->m_textureReductionFactor;
800-
if (txtReduction > 0)
801-
{ WW3D::Set_Texture_Reduction(txtReduction,32);
802-
//Tell LOD manager that texture reduction was applied.
803-
TheGameLODManager->setCurrentTextureReduction(txtReduction);
804-
}
800+
TheGameClient->setTextureLOD(TheWritableGlobalData->m_textureReductionFactor);
805801
}
806802

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

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

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -196,27 +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, 32);
212205

213-
if (WW3D::Get_Texture_Reduction() != TheWritableGlobalData->m_textureReductionFactor)
214-
{ WW3D::Set_Texture_Reduction(TheWritableGlobalData->m_textureReductionFactor,32);
215-
TheGameLODManager->setCurrentTextureReduction(TheWritableGlobalData->m_textureReductionFactor);
216206
if( TheTerrainRenderObject )
217-
TheTerrainRenderObject->setTextureLOD( TheWritableGlobalData->m_textureReductionFactor );
207+
TheTerrainRenderObject->setTextureLOD(level);
218208
}
219-
220209
}
221210

222211
//-------------------------------------------------------------------------------------------------

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ int W3DTreeBuffer::W3DTreeTextureClass::update(W3DTreeBuffer *buffer)
189189
DX8_ErrorCode(surface_level->UnlockRect());
190190
surface_level->Release();
191191
DX8_ErrorCode(D3DXFilterTexture(Peek_D3D_Texture(), NULL, (UINT)0, D3DX_FILTER_BOX));
192-
if (TheWritableGlobalData->m_textureReductionFactor) {
193-
DX8_ErrorCode(Peek_D3D_Texture()->SetLOD((DWORD)TheWritableGlobalData->m_textureReductionFactor));
192+
if (WW3D::Get_Texture_Reduction()) {
193+
DX8_ErrorCode(Peek_D3D_Texture()->SetLOD((DWORD)WW3D::Get_Texture_Reduction()));
194194
}
195195
return(surface_desc.Height);
196196
}

0 commit comments

Comments
 (0)