Skip to content

Commit 215d31b

Browse files
committed
Tweaked automatic TXD resizing
1 parent cb69ae5 commit 215d31b

File tree

7 files changed

+61
-11
lines changed

7 files changed

+61
-11
lines changed

MTA10/core/CCore.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,6 +2391,11 @@ void CCore::NotifyRenderingGrass( bool bIsRenderingGrass )
23912391

23922392
bool CCore::GetRightSizeTxdEnabled( void )
23932393
{
2394+
if ( g_pCore->GetDiagnosticDebug () == EDiagnosticDebug::RESIZE_NEVER_0000 )
2395+
return false;
2396+
if ( g_pCore->GetDiagnosticDebug () == EDiagnosticDebug::RESIZE_ALWAYS_0000 )
2397+
return true;
2398+
23942399
// 32 bit users get rightsized txds
23952400
if ( !Is64BitOS() )
23962401
return true;
@@ -2400,9 +2405,5 @@ bool CCore::GetRightSizeTxdEnabled( void )
24002405
if ( iSystemRamMB <= 2048 )
24012406
return true;
24022407

2403-
// Debug users get rightsized txds
2404-
if ( g_strJingleBells == "rightsize" )
2405-
return true;
2406-
24072408
return false;
24082409
}

MTA10/core/CGraphics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,9 +1973,9 @@ bool CGraphics::ResizeTextureData( const void* pData, uint uiDataPitch, uint uiW
19731973
do
19741974
{
19751975
// Create surfaces
1976-
if ( FAILED( g_pGraphics->GetDevice()->CreateOffscreenPlainSurface( uiWidth, uiHeight, (D3DFORMAT)d3dFormat, D3DPOOL_SYSTEMMEM, &pCurrentSurface, NULL ) ) )
1976+
if ( FAILED( g_pGraphics->GetDevice()->CreateOffscreenPlainSurface( uiWidth, uiHeight, (D3DFORMAT)d3dFormat, D3DPOOL_SCRATCH, &pCurrentSurface, NULL ) ) )
19771977
break;
1978-
if ( FAILED( g_pGraphics->GetDevice()->CreateOffscreenPlainSurface( uiNewWidth, uiNewHeight, (D3DFORMAT)d3dFormat, D3DPOOL_SYSTEMMEM, &pNewSurface, NULL ) ) )
1978+
if ( FAILED( g_pGraphics->GetDevice()->CreateOffscreenPlainSurface( uiNewWidth, uiNewHeight, (D3DFORMAT)d3dFormat, D3DPOOL_SCRATCH, &pNewSurface, NULL ) ) )
19791979
break;
19801980

19811981
// Data in

MTA10/core/CSettings.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,8 @@ void CSettings::CreateGUI ( void )
12601260
m_pDebugSettingCombo->AddItem ( "#0000 Log timing" )->SetData ( (void*)EDiagnosticDebug::LOG_TIMING_0000 );
12611261
m_pDebugSettingCombo->AddItem ( "#0000 Joystick" )->SetData ( (void*)EDiagnosticDebug::JOYSTICK_0000 );
12621262
m_pDebugSettingCombo->AddItem ( "#0000 Lua trace" )->SetData ( (void*)EDiagnosticDebug::LUA_TRACE_0000 );
1263+
m_pDebugSettingCombo->AddItem ( "#0000 Resize always" )->SetData ( (void*)EDiagnosticDebug::RESIZE_ALWAYS_0000 );
1264+
m_pDebugSettingCombo->AddItem ( "#0000 Resize never" )->SetData ( (void*)EDiagnosticDebug::RESIZE_NEVER_0000 );
12631265
m_pDebugSettingCombo->SetReadOnly ( true );
12641266
vecTemp.fY += fLineHeight;
12651267

MTA10/game_sa/CRenderWareSA.TxdRightSizing.cpp

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,16 @@ bool CRenderWareSA::RightSizeTxd( const SString& strInTxdFilename, const SString
5454
std::vector < RwTexture* > textureList;
5555
pGame->GetRenderWareSA()->GetTxdTextures( textureList, pTxd );
5656

57+
// Double size limit if only one texture in txd
58+
if ( textureList.size() == 1 )
59+
uiSizeLimit *= 2;
60+
61+
SString strError;
5762
bool bChanged = false;
5863
for ( std::vector < RwTexture* > ::iterator iter = textureList.begin() ; iter != textureList.end() ; iter++ )
5964
{
6065
RwTexture* pTexture = *iter;
61-
RwTexture* pNewRwTexture = RightSizeTexture( pTexture, uiSizeLimit );
66+
RwTexture* pNewRwTexture = RightSizeTexture( pTexture, uiSizeLimit, strError );
6267
if ( pNewRwTexture && pNewRwTexture != pTexture )
6368
{
6469
// Replace texture in txd if changed
@@ -74,6 +79,11 @@ bool CRenderWareSA::RightSizeTxd( const SString& strInTxdFilename, const SString
7479
}
7580
}
7681

82+
// Log last error
83+
if ( !strError.empty() )
84+
{
85+
AddReportLog( 8430, SString( "RightSizeTxd problem %s with '%s'", *strError, *strInTxdFilename ), 10 );
86+
}
7787

7888
//
7989
// Save shrunked txd if changed
@@ -103,16 +113,32 @@ bool CRenderWareSA::RightSizeTxd( const SString& strInTxdFilename, const SString
103113
// Returns new texture if did shrink
104114
//
105115
/////////////////////////////////////////////////////////////////////////////
106-
RwTexture* CRenderWareSA::RightSizeTexture( RwTexture* pTexture, uint uiSizeLimit )
116+
RwTexture* CRenderWareSA::RightSizeTexture( RwTexture* pTexture, uint uiSizeLimit, SString& strError )
107117
{
108118
// Validate
109119
RwRaster* pRaster = pTexture->raster;
110120
if ( !pRaster )
121+
{
122+
strError = "pRaster == NULL";
111123
return NULL;
124+
}
112125

113126
RwD3D9Raster* pD3DRaster = (RwD3D9Raster*)( &pRaster->renderResource );
114-
if ( !pD3DRaster->texture || !pD3DRaster->lockedSurface || !pD3DRaster->lockedRect.pBits )
127+
if ( !pD3DRaster->texture )
128+
{
129+
strError = "pD3DRaster->texture == NULL";
130+
return NULL;
131+
}
132+
if ( !pD3DRaster->lockedSurface )
133+
{
134+
strError = "pD3DRaster->lockedSurface == NULL";
135+
return NULL;
136+
}
137+
if ( !pD3DRaster->lockedRect.pBits )
138+
{
139+
strError = "pD3DRaster->lockedRect.pBits == NULL";
115140
return NULL;
141+
}
116142

117143
// Get texture info
118144
uint uiWidth = pRaster->width;
@@ -131,6 +157,10 @@ RwTexture* CRenderWareSA::RightSizeTexture( RwTexture* pTexture, uint uiSizeLimi
131157
if ( d3dFormat != D3DFMT_DXT1 && d3dFormat != D3DFMT_DXT3 && d3dFormat != D3DFMT_DXT5 )
132158
return NULL;
133159

160+
// Double size limit if DXT1
161+
if ( d3dFormat == D3DFMT_DXT1 )
162+
uiSizeLimit *= 2;
163+
134164
// Change size
135165
uint uiReqWidth = Min( uiSizeLimit, uiWidth );
136166
uint uiReqHeight = Min( uiSizeLimit, uiHeight );
@@ -142,7 +172,10 @@ RwTexture* CRenderWareSA::RightSizeTexture( RwTexture* pTexture, uint uiSizeLimi
142172
bool bNeedOwnLock = ( pD3DRaster->lockedLevel != 0 ) || !pD3DRaster->lockedSurface;
143173
if ( bNeedOwnLock )
144174
if ( FAILED( pD3DRaster->texture->LockRect( 0, &lockedRect, NULL, D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_NOSYSLOCK | D3DLOCK_READONLY ) ) )
175+
{
176+
strError = "pD3DRaster->texture->LockRect failed";
145177
return NULL;
178+
}
146179

147180
// Try resize
148181
CBuffer newPixelBuffer;
@@ -152,7 +185,10 @@ RwTexture* CRenderWareSA::RightSizeTexture( RwTexture* pTexture, uint uiSizeLimi
152185
pD3DRaster->texture->UnlockRect( 0 );
153186

154187
if ( !bDidResize )
188+
{
189+
strError = "ResizeTextureData failed";
155190
return NULL;
191+
}
156192

157193
// Make new RwTexture from pixels
158194
NativeTexturePC_Header header;
@@ -190,12 +226,21 @@ RwTexture* CRenderWareSA::RightSizeTexture( RwTexture* pTexture, uint uiSizeLimi
190226
buffer.size = nativeData.GetSize();
191227
RwStream * rwStream = RwStreamOpen( STREAM_TYPE_BUFFER, STREAM_MODE_READ, &buffer );
192228
if ( !rwStream )
229+
{
230+
strError = "RwStreamOpen failed";
193231
return NULL;
232+
}
194233

195234
// Read new texture
196235
RwTexture* pNewRwTexture = NULL;
197236
rwD3D9NativeTextureRead( rwStream, &pNewRwTexture );
198237
RwStreamClose( rwStream, NULL );
199238

239+
if ( !pNewRwTexture )
240+
{
241+
strError = "rwD3D9NativeTextureRead failed";
242+
return NULL;
243+
}
244+
200245
return pNewRwTexture;
201246
}

MTA10/game_sa/CRenderWareSA.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class CRenderWareSA : public CRenderWare
109109
void TxdForceUnload ( ushort usTxdId, bool bDestroyTextures );
110110

111111
// CRenderWareSA methods
112-
RwTexture* RightSizeTexture ( RwTexture* pTexture, uint uiSizeLimit );
112+
RwTexture* RightSizeTexture ( RwTexture* pTexture, uint uiSizeLimit, SString& strError );
113113
void ResetStats ( void );
114114
void GetShaderReplacementStats ( SShaderReplacementStats& outStats );
115115
CModelTexturesInfo* GetModelTexturesInfo ( ushort usModelId );

MTA10/mods/shared_logic/CClientTXD.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ bool CClientTXD::GetFilenameToUse( SString& strOutFilename )
172172
{
173173
// See if previously shrunk result exists
174174
SString strLargeSha256 = GenerateSha256HexStringFromFile( m_strFilename );
175-
SString strShrunkFilename = PathJoin( ExtractPath( m_strFilename ), SString( "_2_%s", *strLargeSha256.Left( 32 ) ) );
175+
SString strShrunkFilename = PathJoin( ExtractPath( m_strFilename ), SString( "_3_%s", *strLargeSha256.Left( 32 ) ) );
176176
uint uiShrunkSize = (uint)FileSize( strShrunkFilename );
177177
if ( uiShrunkSize >= 128 )
178178
{

Shared/sdk/SharedUtil.Game.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ namespace SharedUtil
100100
LOG_TIMING_0000,
101101
JOYSTICK_0000,
102102
LUA_TRACE_0000,
103+
RESIZE_ALWAYS_0000,
104+
RESIZE_NEVER_0000,
103105
MAX,
104106
};
105107
};

0 commit comments

Comments
 (0)