Skip to content

Commit

Permalink
Enable local ToD in SDL_gpu builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
lipk committed Jul 21, 2014
1 parent 86f626c commit e6a1b2f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/display.cpp
Expand Up @@ -1141,7 +1141,7 @@ std::vector<surface> display::get_terrain_images(const map_location &loc,
} else if(lt.empty()) {
img = image::get_texture(image, image::SCALED_TO_HEX);
} else {
img = image::get_lighted_image(image, lt, image::SCALED_TO_HEX);
img = image::get_lighted_texture(image, lt, image::SCALED_TO_HEX);
}

if (!img.null()) {
Expand Down Expand Up @@ -2803,7 +2803,7 @@ void display::draw_hex(const map_location& loc) {

#ifdef SDL_GPU
const sdl::timage img = use_local_light
? image::get_lighted_image(overlays.first->second.image, lt, image::SCALED_TO_HEX)
? image::get_lighted_texture(overlays.first->second.image, lt, image::SCALED_TO_HEX)
: image::get_texture(overlays.first->second.image, image_type);
drawing_buffer_add(LAYER_TERRAIN_BG, loc, xpos, ypos, img);
#else
Expand Down
42 changes: 36 additions & 6 deletions src/image.cpp
Expand Up @@ -140,6 +140,9 @@ image::bool_cache is_empty_hex_;
// caches storing the different lighted cases for each image
image::lit_cache lit_images_,
lit_scaled_images_;
#ifdef SDL_GPU
image::lit_texture_cache lit_textures_;
#endif
// caches storing each lightmap generated
image::lit_variants lightmaps_;

Expand Down Expand Up @@ -560,7 +563,6 @@ light_string get_light_string(int op, int r, int g, int b){
return ls;
}

#ifndef SDL_GPU
static surface apply_light(surface surf, const light_string& ls){
// atomic lightmap operation are handled directly (important to end recursion)
if(ls.size() == 4){
Expand Down Expand Up @@ -605,7 +607,6 @@ static surface apply_light(surface surf, const light_string& ls){
// apply the final lightmap
return light_surface(surf, lightmap);
}
#endif

bool locator::file_exists() const
{
Expand Down Expand Up @@ -966,11 +967,41 @@ sdl::timage get_texture(const locator& loc, TYPE type)
#endif

#ifdef SDL_GPU
sdl::timage get_lighted_image(const locator &i_locator, const light_string &/*ls*/, TYPE type)
sdl::timage get_lighted_texture(const locator &i_locator, const light_string &ls, TYPE type)
{
return get_texture(i_locator, type);
sdl::timage res;
if(i_locator.is_void())
return res;

// if no light variants yet, need to add an empty map
if(!i_locator.in_cache(lit_textures_)){
i_locator.add_to_cache(lit_textures_, lit_texture_variants());
}

//need access to add it if not found
{ // enclose reference pointing to data stored in a changing vector
const lit_texture_variants& lvar = i_locator.locate_in_cache(lit_textures_);
lit_texture_variants::const_iterator lvi = lvar.find(ls);
if(lvi != lvar.end()) {
return lvi->second;
}
}

// not cached yet, generate it
surface surf = get_image(i_locator, HEXED);
surf = apply_light(surf, ls);

res = sdl::timage(surf);

if (type == SCALED_TO_HEX) {
res.set_scale(zoom / 72.0f, zoom / 72.0f);
}
// record the lighted surface in the corresponding variants cache
i_locator.access_in_cache(lit_textures_)[ls] = res;

return res;
}
#else
#endif
surface get_lighted_image(const image::locator& i_locator, const light_string& ls, TYPE type)
{
surface res;
Expand Down Expand Up @@ -1022,7 +1053,6 @@ surface get_lighted_image(const image::locator& i_locator, const light_string& l

return res;
}
#endif

surface get_hexmask()
{
Expand Down
9 changes: 6 additions & 3 deletions src/image.hpp
Expand Up @@ -156,6 +156,10 @@ namespace image {
typedef std::map<light_string, surface> lit_variants;
// lighted variants for each locator
typedef cache_type<lit_variants> lit_cache;
#ifdef SDL_GPU
typedef std::map<light_string, sdl::timage> lit_texture_variants;
typedef cache_type<lit_texture_variants> lit_texture_cache;
#endif

void flush_cache();

Expand Down Expand Up @@ -217,10 +221,9 @@ namespace image {
///after applying the lightmap encoded in ls
///type should be HEXED or SCALED_TO_HEX
#ifdef SDL_GPU
sdl::timage get_lighted_image(const image::locator& i_locator, const light_string& ls, TYPE type);
#else
surface get_lighted_image(const image::locator& i_locator, const light_string& ls, TYPE type);
sdl::timage get_lighted_texture(const image::locator& i_locator, const light_string& ls, TYPE type);
#endif
surface get_lighted_image(const image::locator& i_locator, const light_string& ls, TYPE type);

///function to get the standard hex mask
surface get_hexmask();
Expand Down

0 comments on commit e6a1b2f

Please sign in to comment.