Skip to content

Commit 6ac403d

Browse files
author
xwidghet
committed
Make delayed texture delete...actually delay texture deletion rather than keep them in memory indefinitely.
1 parent 321092d commit 6ac403d

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎src/Font.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,16 @@ void FontPage::SetExtraPixels( int iDrawExtraPixelsLeft, int iDrawExtraPixelsRig
220220

221221
FontPage::~FontPage()
222222
{
223+
// Font texture ref time is reset when unloaded so that on screen changes farther than 30 seconds apart they can be reused -xwidghet
223224
if( m_FontPageTextures.m_pTextureMain != NULL )
224225
{
226+
m_FontPageTextures.m_pTextureMain->m_lastRefTime.Touch();
225227
TEXTUREMAN->UnloadTexture( m_FontPageTextures.m_pTextureMain );
226228
m_FontPageTextures.m_pTextureMain = NULL;
227229
}
228230
if( m_FontPageTextures.m_pTextureStroke != NULL )
229231
{
232+
m_FontPageTextures.m_pTextureStroke->m_lastRefTime.Touch();
230233
TEXTUREMAN->UnloadTexture( m_FontPageTextures.m_pTextureStroke );
231234
m_FontPageTextures.m_pTextureStroke = NULL;
232235
}

‎src/RageTexture.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "RageTypes.h"
77
#include "RageTextureID.h"
8+
#include "RageTimer.h"
89

910
struct lua_State;
1011
class RageTexture
@@ -57,6 +58,7 @@ class RageTexture
5758
RageTextureID::TexPolicy &GetPolicy() { return m_ID.Policy; }
5859
int m_iRefCount;
5960
bool m_bWasUsed;
61+
RageTimer m_lastRefTime;
6062

6163
// The ID that we were asked to load:
6264
const RageTextureID &GetID() const { return m_ID; }

‎src/RageTextureManager.cpp‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ RageTextureManager::~RageTextureManager()
5858

5959
void RageTextureManager::Update( float fDeltaTime )
6060
{
61+
static RageTimer garbageCollector;
62+
if (garbageCollector.PeekDeltaTime() >= 30.0f)
63+
{
64+
DoDelayedDelete();
65+
garbageCollector.Touch();
66+
}
67+
68+
6169
FOREACHM(RageTextureID, RageTexture*, m_textures_to_update, i)
6270
{
6371
RageTexture* pTexture = i->second;
@@ -183,8 +191,12 @@ RageTexture* RageTextureManager::LoadTextureInternal( RageTextureID ID )
183191
RageTexture* RageTextureManager::LoadTexture( const RageTextureID &ID )
184192
{
185193
RageTexture* pTexture = LoadTextureInternal( ID );
186-
if( pTexture )
194+
if ( pTexture )
195+
{
196+
pTexture->m_lastRefTime.Touch();
187197
pTexture->m_bWasUsed = true;
198+
}
199+
188200
return pTexture;
189201
}
190202

@@ -219,7 +231,7 @@ void RageTextureManager::UnloadTexture( RageTexture *t )
219231
bDeleteThis = true;
220232

221233
/* Delete normal textures immediately unless m_bDelayedDelete is is on. */
222-
if( t->GetPolicy() == RageTextureID::TEX_DEFAULT && !m_Prefs.m_bDelayedDelete )
234+
if( t->GetPolicy() == RageTextureID::TEX_DEFAULT && (!m_Prefs.m_bDelayedDelete || t->m_lastRefTime.PeekDeltaTime() >= 30.0f) )
223235
bDeleteThis = true;
224236

225237
/* Delete volatile textures after they've been used at least once. */

0 commit comments

Comments
 (0)