unit images arn't cached, except when standing

This commit is contained in:
Jérémy Rosen 2006-10-07 12:07:39 +00:00
parent 4f4d915721
commit e7633095ff
3 changed files with 15 additions and 11 deletions

View file

@ -575,7 +575,7 @@ surface get_semi_brightened(const locator i_locator, COLOUR_ADJUSTMENT adj)
return surface(brighten_image(image, ftofxp(1.25)));
}
surface get_image(const image::locator& i_locator, TYPE type, COLOUR_ADJUSTMENT adj)
surface get_image(const image::locator& i_locator, TYPE type, COLOUR_ADJUSTMENT adj,bool add_to_cache )
{
surface res(NULL);
image_cache *imap;
@ -618,7 +618,7 @@ surface get_image(const image::locator& i_locator, TYPE type, COLOUR_ADJUSTMENT
res = i_locator.load_from_disk();
if(res == NULL) {
i_locator.add_to_cache(*imap, surface(NULL));
if(add_to_cache) i_locator.add_to_cache(*imap, surface(NULL));
return surface(NULL);
}
} else {
@ -651,18 +651,18 @@ surface get_image(const image::locator& i_locator, TYPE type, COLOUR_ADJUSTMENT
// optimizes surface before storing it
res = create_optimized_surface(res);
i_locator.add_to_cache(*imap, res);
if(add_to_cache) i_locator.add_to_cache(*imap, res);
return res;
}
surface get_image_dim(const image::locator& i_locator, size_t x, size_t y)
surface get_image_dim(const image::locator& i_locator, size_t x, size_t y,bool add_to_cache)
{
const surface surf(get_image(i_locator,UNSCALED));
if(surf != NULL && (size_t(surf->w) != x || size_t(surf->h) != y)) {
const surface new_image(scale_surface(surf,x,y));
i_locator.add_to_cache(images_, new_image);
if(add_to_cache) i_locator.add_to_cache(images_, new_image);
return new_image;
}
@ -691,7 +691,7 @@ surface reverse_image(const surface& surf)
return rev;
}
locator get_alternative(const image::locator &i_locator, const std::string &alt)
locator get_alternative(const image::locator &i_locator, const std::string &alt,bool add_to_cache)
{
if(i_locator.is_void())
return locator();
@ -716,7 +716,7 @@ locator get_alternative(const image::locator &i_locator, const std::string &alt)
wassert(false);
}
i_locator.add_to_cache(alternative_images_, res);
if(add_to_cache) i_locator.add_to_cache(alternative_images_, res);
return res;
}

View file

@ -175,6 +175,8 @@ namespace image {
///scaled images.
void set_zoom(int zoom);
// unscaled : image will be drawn "as is" without changing size, even in case of redraw
// scaled : image will be scaled to fit into a hex, taking zoom into account
enum TYPE { UNSCALED, SCALED, UNMASKED, GREYED, DARKENED, BRIGHTENED, SEMI_BRIGHTENED };
enum COLOUR_ADJUSTMENT { ADJUST_COLOUR, NO_ADJUST_COLOUR };
@ -182,13 +184,13 @@ namespace image {
///function to get the surface corresponding to an image.
///note that this surface must be freed by the user by calling
///SDL_FreeSurface()
surface get_image(const locator& i_locator,TYPE type=SCALED, COLOUR_ADJUSTMENT adj=ADJUST_COLOUR);
surface get_image(const locator& i_locator,TYPE type=SCALED, COLOUR_ADJUSTMENT adj=ADJUST_COLOUR,bool add_to_cache = true);
///function to get a scaled image, but scale it to specific dimensions.
///if you later try to get the same image using get_image() the image will
///have the dimensions specified here.
///Note that this surface must be freed by the user by calling SDL_FreeSurface
surface get_image_dim(const locator& i_locator, size_t x, size_t y);
surface get_image_dim(const locator& i_locator, size_t x, size_t y,bool add_to_cache = true);
///function to reverse an image. The image MUST have originally been returned from
///an image:: function. Returned images have the same semantics as for get_image()
@ -196,7 +198,7 @@ namespace image {
surface reverse_image(const surface &surf);
locator get_alternative(const locator &i_locator, const std::string &alt);
locator get_alternative(const locator &i_locator, const std::string &alt,bool add_to_cache = true);
///function to register an image with the given id. Calls to get_image(id,UNSCALED) will
///return this image. register_image() will take ownership of this image and free

View file

@ -1917,7 +1917,9 @@ void unit::redraw_unit(display& disp,gamemap::location hex)
}
#endif
surface image(image::get_image(loc,utils::string_bool(get_state("stoned"))?image::GREYED : image::UNSCALED));
surface image(image::get_image(loc,
utils::string_bool(get_state("stoned"))?image::GREYED : image::UNSCALED,image::ADJUST_COLOUR,
state_ == STATE_STANDING?true:false));
if(image ==NULL) {
image = still_image();
}