Limit text cache size.
This commit is contained in:
parent
041b7659ca
commit
01286b042b
|
@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
#include "text.h"
|
||||
|
||||
void expireTexts(void);
|
||||
static void loadFont(int size);
|
||||
static SDL_Texture *getCachedText(unsigned long hash);
|
||||
static void cacheText(unsigned long hash, SDL_Texture *t);
|
||||
|
@ -32,6 +33,7 @@ static char drawTextBuffer[MAX_DESCRIPTION_LENGTH];
|
|||
static TTF_Font *font[MAX_FONTS];
|
||||
static Texture textures[NUM_TEXT_BUCKETS];
|
||||
static int maxWidth = 0;
|
||||
static int cacheSize = 0;
|
||||
|
||||
void initFonts(void)
|
||||
{
|
||||
|
@ -87,6 +89,11 @@ static void drawTextNormal(int x, int y, int size, int align, SDL_Color c, char
|
|||
t = SDL_CreateTextureFromSurface(app.renderer, surface);
|
||||
SDL_FreeSurface(surface);
|
||||
|
||||
if (cacheSize >= TEXT_CACHE_SIZE)
|
||||
{
|
||||
expireTexts();
|
||||
}
|
||||
|
||||
cacheText(hash, t);
|
||||
}
|
||||
|
||||
|
@ -231,6 +238,8 @@ static void cacheText(unsigned long hash, SDL_Texture *texture)
|
|||
new->texture = texture;
|
||||
|
||||
t->next = new;
|
||||
|
||||
cacheSize++;
|
||||
}
|
||||
|
||||
void expireTexts(void)
|
||||
|
@ -255,6 +264,8 @@ void expireTexts(void)
|
|||
textures[i].next = NULL;
|
||||
}
|
||||
|
||||
cacheSize = 0;
|
||||
|
||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Expired %d texts", n);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
#include "SDL2/SDL_ttf.h"
|
||||
|
||||
#define TEXT_CACHE_SIZE 256
|
||||
|
||||
extern void blit(SDL_Texture *texture, int x, int y, int centered);
|
||||
extern char *getFileLocation(char *filename);
|
||||
|
||||
|
|
Loading…
Reference in New Issue