Skip to content

Commit 94c1d8b

Browse files
committed
Memory management optimization for streamer/texture loading
1 parent 22b6a75 commit 94c1d8b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Client/game_sa/CRenderWareSA.TextureReplacing.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,29 @@ bool CRenderWareSA::ModelInfoTXDAddTextures(SReplacementTextures* pReplacementTe
260260
perTxdInfo.usingTextures.push_back(pNewTexture);
261261
}
262262

263+
// Request space from the SA streaming system for the new textures.
264+
// This reduces mem pressure/OOM by encouraging the engine to free unused resources.
265+
// Note: We do not modify CStreamingInfo::sizeInBlocks as that affects disk I/O during model reload.
266+
// Only perform this check for new rasters (not copies) to avoid double-counting shared resources.
267+
if (!perTxdInfo.bTexturesAreCopies && pGame->GetStreaming())
268+
{
269+
uint32_t uiTotalSize = 0;
270+
for (RwTexture* pNewTexture : perTxdInfo.usingTextures)
271+
{
272+
if (pNewTexture && SharedUtil::IsReadablePointer(pNewTexture, sizeof(RwTexture)) && pNewTexture->raster)
273+
{
274+
// Estimate texture size (Width * Height * 4 bytes for 32-bit).
275+
// This helps the SA streaming system manage memory pressure.
276+
uiTotalSize += pNewTexture->raster->width * pNewTexture->raster->height * 4;
277+
}
278+
}
279+
280+
if (uiTotalSize > 0)
281+
{
282+
pGame->GetStreaming()->MakeSpaceFor(uiTotalSize);
283+
}
284+
}
285+
263286
//
264287
// Add each texture to the target txd
265288
//

0 commit comments

Comments
 (0)