Speed up the first display of stamp buttons by not loading the sounds at that time.

As a side effect it reduces the memory usage as it just loads the sounds for the stamps that the user selects.
This commit is contained in:
Pere Pujal i Carabantes 2019-06-07 08:09:08 +02:00
parent 4d3ef642da
commit 8736793889

View file

@ -1776,6 +1776,7 @@ typedef struct stamp_type
#ifndef NOSOUND
Mix_Chunk *ssnd;
Mix_Chunk *sdesc;
unsigned sound_processed:1;
#endif
SDL_Surface *thumbnail;
@ -1808,6 +1809,8 @@ typedef struct stamp_type
unsigned is_svg:1;
} stamp_type;
static void get_stamp_thumb(stamp_type * sd, int process_sound);
#define MAX_STAMP_GROUPS 256
static unsigned int stamp_group_dir_depth = 1; /* How deep (how many slashes in a subdirectory path) we think a new stamp group should be */
@ -4229,6 +4232,13 @@ static void mainloop(void)
/* Only play when picking a different stamp */
if (toolopt_changed && !mute)
{
/* If the sound hasn't been loaded yet, do it now */
if (!stamp_data[stamp_group][cur_thing]->sound_processed)
{
get_stamp_thumb(stamp_data[stamp_group][cur_thing], 1);
}
/* If there's an SFX, play it! */
if (stamp_data[stamp_group][cur_thing]->ssnd != NULL)
@ -7386,7 +7396,7 @@ static void set_active_stamp(void)
/**
* FIXME
*/
static void get_stamp_thumb(stamp_type * sd)
static void get_stamp_thumb(stamp_type * sd, int process_sound)
{
SDL_Surface *bigimg = NULL;
unsigned len = strlen(sd->stampname);
@ -7436,22 +7446,27 @@ static void get_stamp_thumb(stamp_type * sd)
}
#ifndef NOSOUND
/* good time to load the sound */
if (!sd->no_sound && !sd->ssnd && use_sound)
if (!sd->sound_processed && process_sound)
{
/* damn thing wants a .png extension; give it one */
memcpy(buf + len, ".png", 5);
sd->ssnd = loadsound(buf);
sd->no_sound = !sd->ssnd;
}
/* good time to load the sound */
if (!sd->no_sound && !sd->ssnd && use_sound)
{
/* damn thing wants a .png extension; give it one */
memcpy(buf + len, ".png", 5);
sd->ssnd = loadsound(buf);
sd->no_sound = !sd->ssnd;
}
/* ...and the description */
if (!sd->no_descsound && !sd->sdesc && use_sound)
{
/* damn thing wants a .png extension; give it one */
memcpy(buf + len, ".png", 5);
sd->sdesc = loaddescsound(buf);
sd->no_descsound = !sd->sdesc;
/* ...and the description */
if (!sd->no_descsound && !sd->sdesc && use_sound)
{
/* damn thing wants a .png extension; give it one */
memcpy(buf + len, ".png", 5);
sd->sdesc = loaddescsound(buf);
sd->no_descsound = !sd->sdesc;
}
sd->sound_processed = 1;
}
#endif
@ -9121,7 +9136,8 @@ static void draw_stamps(void)
if (stamp < num_stamps[stamp_group])
{
get_stamp_thumb(stamp_data[stamp_group][stamp]);
/* Loads the thumbnail and sounds, the sounds just if this is the current stamp, increasing responsivity for low powered devices */
get_stamp_thumb(stamp_data[stamp_group][stamp], stamp == cur_stamp[stamp_group] ? 1 : 0);
img = stamp_data[stamp_group][stamp]->thumbnail;
base_x = ((i % 2) * 48) + (WINDOW_WIDTH - 96) + ((48 - (img->w)) / 2);