Small optimization of ToD local light and code simplification.
Add a ToD color struct and operators to easily kill some wasteful ~CS(0,0,0) (which were common for some ToD cases)
This commit is contained in:
parent
03f0abb017
commit
0306759c54
6 changed files with 73 additions and 64 deletions
|
@ -125,9 +125,7 @@ display::display(CVideo& video, const gamemap* map, const config& theme_cfg, con
|
|||
draw_coordinates_(false),
|
||||
draw_terrain_codes_(false),
|
||||
arrows_map_(),
|
||||
color_adjust_red_(0),
|
||||
color_adjust_green_(0),
|
||||
color_adjust_blue_(0)
|
||||
color_adjust_()
|
||||
#if defined(__GLIBC__)
|
||||
, do_reverse_memcpy_workaround_(false)
|
||||
#endif
|
||||
|
@ -175,15 +173,13 @@ const time_of_day & display::get_time_of_day(const map_location& loc) const
|
|||
|
||||
void display::update_tod() {
|
||||
const time_of_day& tod = get_time_of_day();
|
||||
image::set_color_adjustment(color_adjust_red_ + tod.red, color_adjust_green_ + tod.green, color_adjust_blue_ + tod.blue);
|
||||
tod_color col = color_adjust_ + tod.color;
|
||||
image::set_color_adjustment(col.r, col.g, col.b);
|
||||
}
|
||||
|
||||
void display::adjust_color_overlay(int r, int g, int b) {
|
||||
const time_of_day& tod = get_time_of_day();
|
||||
image::set_color_adjustment(r + tod.red, g + tod.green, b + tod.blue);
|
||||
color_adjust_red_ = r ;
|
||||
color_adjust_green_ = g ;
|
||||
color_adjust_blue_ = b ;
|
||||
color_adjust_ = tod_color(r, g, b);
|
||||
update_tod();
|
||||
}
|
||||
|
||||
|
||||
|
@ -668,53 +664,47 @@ std::vector<surface> display::get_terrain_images(const map_location &loc,
|
|||
static const std::string dir[6] = {"n","ne","se","s","sw","nw"};
|
||||
|
||||
//get all the light transitions
|
||||
//note that lightmap needs halved values
|
||||
std::ostringstream light_trans;
|
||||
for(int d=0; d<6; ++d){
|
||||
const time_of_day& atod = get_time_of_day(adjs[d]);
|
||||
if(atod.red == tod.red && atod.green == tod.green && atod.blue == tod.blue) { continue; }
|
||||
if(atod.color == tod.color)
|
||||
continue;
|
||||
|
||||
light_trans
|
||||
<< "~BLIT("
|
||||
<< "terrain/light-" << dir[d] << ".png"
|
||||
<< "~CS("
|
||||
<< (atod.red + color_adjust_red_)/2 << ","
|
||||
<< (atod.green + color_adjust_green_)/2 << ","
|
||||
<< (atod.blue + color_adjust_blue_)/2
|
||||
<< ")" // CS
|
||||
<< ")"; //BLIT
|
||||
tod_color col = (atod.color + color_adjust_);
|
||||
col *= 0.5; // lightmap needs halved values
|
||||
|
||||
light_trans << "~BLIT(terrain/light-" << dir[d] << ".png";
|
||||
if(!col.is_zero()) {
|
||||
light_trans << "~CS(" << col << ")";
|
||||
}
|
||||
light_trans << ")"; //BLIT
|
||||
use_lightmap = true;
|
||||
}
|
||||
|
||||
std::ostringstream mod;
|
||||
if(use_lightmap) {
|
||||
tod_color col = tod.color + color_adjust_;
|
||||
col *= 0.5; // lightmap needs halved values
|
||||
|
||||
//generate the base of the lightmap
|
||||
//and add light transitions on it
|
||||
mod << "~L("
|
||||
<< "terrain/light.png"
|
||||
<< "~CS("
|
||||
<< (tod.red + color_adjust_red_)/2 << ","
|
||||
<< (tod.green + color_adjust_green_)/2<< ","
|
||||
<< (tod.blue + color_adjust_blue_)/2
|
||||
<< ")" // CS
|
||||
<< light_trans.str()
|
||||
<< ")"; // L
|
||||
mod << "~L(terrain/light.png";
|
||||
if(!col.is_zero()) {
|
||||
mod << "~CS(" << col << ")";
|
||||
}
|
||||
mod << light_trans.str() << ")"; // L
|
||||
} else {
|
||||
// no light map needed, but still need to color the hex
|
||||
const time_of_day& global_tod = get_time_of_day(map_location::null_location);
|
||||
bool is_same_as_global(tod.red == global_tod.red && tod.green == global_tod.green && tod.blue == global_tod.blue);
|
||||
if(is_same_as_global ) {
|
||||
if(tod.color == global_tod.color) {
|
||||
// It's the same as global ToD, don't use local light
|
||||
use_local_light = false;
|
||||
} else if ((tod.red + color_adjust_red_) != 0
|
||||
|| (tod.green + color_adjust_green_) != 0
|
||||
|| (tod.blue + color_adjust_blue_) != 0) {
|
||||
} else {
|
||||
// simply color it if needed
|
||||
mod << "~CS("
|
||||
<< (tod.red + color_adjust_red_) << ","
|
||||
<< (tod.green + color_adjust_green_)<< ","
|
||||
<< (tod.blue + color_adjust_blue_)
|
||||
<< ")"; // CS
|
||||
tod_color col = tod.color + color_adjust_;
|
||||
if(!col.is_zero()) {
|
||||
mod << "~CS(" << col << ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
color_mod = mod.str();
|
||||
|
@ -732,7 +722,6 @@ std::vector<surface> display::get_terrain_images(const map_location &loc,
|
|||
it->get_current_frame() : it->get_first_frame();
|
||||
|
||||
// We prevent ToD coloring and brightening of off-map tiles,
|
||||
// except if we are not in_game and so in the editor.
|
||||
// We need to test for the tile to be rendered and
|
||||
// not the location, since the transitions are rendered
|
||||
// over the offmap-terrain and these need a ToD coloring.
|
||||
|
@ -2541,14 +2530,14 @@ void display::update_arrow(arrow & arrow)
|
|||
|
||||
void display::write(config& cfg) const
|
||||
{
|
||||
cfg["color_adjust_red"] = color_adjust_red_;
|
||||
cfg["color_adjust_green"] = color_adjust_green_;
|
||||
cfg["color_adjust_blue_"] = color_adjust_blue_;
|
||||
cfg["color_adjust_red"] = color_adjust_.r;
|
||||
cfg["color_adjust_green"] = color_adjust_.g;
|
||||
cfg["color_adjust_blue_"] = color_adjust_.b;
|
||||
}
|
||||
|
||||
void display::read(const config& cfg)
|
||||
{
|
||||
color_adjust_red_ = cfg["color_adjust_red"].to_int(0);
|
||||
color_adjust_green_ = cfg["color_adjust_green"].to_int(0);
|
||||
color_adjust_blue_ = cfg["color_adjust_blue_"].to_int(0);
|
||||
color_adjust_.r = cfg["color_adjust_red"].to_int(0);
|
||||
color_adjust_.g = cfg["color_adjust_green"].to_int(0);
|
||||
color_adjust_.b = cfg["color_adjust_blue_"].to_int(0);
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ class arrow;
|
|||
#include "font.hpp"
|
||||
#include "key.hpp"
|
||||
#include "team.hpp"
|
||||
#include "time_of_day.hpp"
|
||||
#include "theme.hpp"
|
||||
#include "video.hpp"
|
||||
#include "widgets/button.hpp"
|
||||
|
@ -865,9 +866,7 @@ private:
|
|||
/** Maps the list of arrows for each location */
|
||||
arrows_map_t arrows_map_;
|
||||
|
||||
int color_adjust_red_;
|
||||
int color_adjust_green_;
|
||||
int color_adjust_blue_;
|
||||
tod_color color_adjust_;
|
||||
|
||||
#if defined(__GLIBC__)
|
||||
/** Flag for bug #17573 - this is set in the constructor **/
|
||||
|
|
|
@ -161,13 +161,13 @@ void teditor_settings::update_selected_tod_info(twindow& window)
|
|||
//current_tod_image_->set_icon_name(get_selected_tod().image);
|
||||
custom_tod_red_field_->set_widget_value(
|
||||
window
|
||||
, get_selected_tod().red);
|
||||
, get_selected_tod().color.r);
|
||||
custom_tod_green_field_->set_widget_value(
|
||||
window
|
||||
, get_selected_tod().green);
|
||||
, get_selected_tod().color.g);
|
||||
custom_tod_blue_field_->set_widget_value(
|
||||
window
|
||||
, get_selected_tod().blue);
|
||||
, get_selected_tod().color.b);
|
||||
}
|
||||
custom_tod_red_field_->widget()->set_active(custom);
|
||||
custom_tod_green_field_->widget()->set_active(custom);
|
||||
|
@ -235,7 +235,7 @@ void teditor_settings::pre_show(CVideo& /*video*/, twindow& window)
|
|||
const int r = custom_tod_red_field_->get_widget_value(window);
|
||||
const int g = custom_tod_green_field_->get_widget_value(window);
|
||||
const int b = custom_tod_blue_field_->get_widget_value(window);
|
||||
if (tod.red == r && tod.green == g && tod.blue == b) {
|
||||
if (tod.color.r == r && tod.color.g == g && tod.color.b == b) {
|
||||
current_tod_ = i;
|
||||
custom_tod_toggle_->set_value(false);
|
||||
update_selected_tod_info(window);
|
||||
|
|
|
@ -1736,11 +1736,11 @@ static int intf_get_time_of_day(lua_State *L)
|
|||
luaW_pushtstring(L, tod.name);
|
||||
lua_setfield(L, -2, "name");
|
||||
|
||||
lua_pushinteger(L, tod.red);
|
||||
lua_pushinteger(L, tod.color.r);
|
||||
lua_setfield(L, -2, "red");
|
||||
lua_pushinteger(L, tod.green);
|
||||
lua_pushinteger(L, tod.color.g);
|
||||
lua_setfield(L, -2, "green");
|
||||
lua_pushinteger(L, tod.blue);
|
||||
lua_pushinteger(L, tod.color.b);
|
||||
lua_setfield(L, -2, "blue");
|
||||
|
||||
return 1;
|
||||
|
|
|
@ -21,12 +21,19 @@
|
|||
#include "foreach.hpp"
|
||||
#include "time_of_day.hpp"
|
||||
|
||||
|
||||
std::ostream &operator<<(std::ostream &s, const tod_color& c){
|
||||
s << c.r << "," << c.g << "," << c.b;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
time_of_day::time_of_day(const config& cfg):
|
||||
lawful_bonus(cfg["lawful_bonus"]),
|
||||
bonus_modified(0),
|
||||
image(cfg["image"]), name(cfg["name"].t_str()), id(cfg["id"]),
|
||||
image_mask(cfg["mask"]),
|
||||
red(cfg["red"]), green(cfg["green"]), blue(cfg["blue"]),
|
||||
color(cfg["red"], cfg["green"], cfg["blue"]),
|
||||
sounds(cfg["sound"])
|
||||
{
|
||||
}
|
||||
|
@ -38,9 +45,7 @@ time_of_day::time_of_day()
|
|||
, name("NULL_TOD")
|
||||
, id("nulltod")
|
||||
, image_mask()
|
||||
, red(0)
|
||||
, green(0)
|
||||
, blue(0)
|
||||
, color(0,0,0)
|
||||
, sounds()
|
||||
{
|
||||
}
|
||||
|
@ -48,9 +53,9 @@ time_of_day::time_of_day()
|
|||
void time_of_day::write(config& cfg) const
|
||||
{
|
||||
cfg["lawful_bonus"] = lawful_bonus;
|
||||
cfg["red"] = red;
|
||||
cfg["green"] = green;
|
||||
cfg["blue"] = blue;
|
||||
cfg["red"] = color.r;
|
||||
cfg["green"] = color.g;
|
||||
cfg["blue"] = color.b;
|
||||
cfg["image"] = image;
|
||||
cfg["name"] = name;
|
||||
cfg["id"] = id;
|
||||
|
|
|
@ -24,6 +24,22 @@
|
|||
|
||||
class config;
|
||||
|
||||
/** Small struct to store and manipulate ToD colors */
|
||||
|
||||
struct tod_color{
|
||||
tod_color(int red = 0, int green = 0, int blue = 0) : r(red), g(green), b(blue) {}
|
||||
bool operator==(const tod_color& o) const { return r == o.r && g == o.g && b == o.b; }
|
||||
bool is_zero() const { return r == 0 && g == 0 && b == 0; }
|
||||
bool operator!=(const tod_color& o) const { return !operator==(o); }
|
||||
tod_color operator+(const tod_color& o) const { return tod_color(r+o.r, g+o.g, b+o.b);}
|
||||
void operator*=(float x) { r *= x; g *= x; b *= x;}
|
||||
|
||||
int r,g,b;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &s, const tod_color& tod);
|
||||
|
||||
|
||||
/**
|
||||
* Object which defines a time of day
|
||||
* with associated bonuses, image, sounds etc.
|
||||
|
@ -62,7 +78,7 @@ struct time_of_day
|
|||
* The color modifications that should be made
|
||||
* to the game board to reflect the time of day.
|
||||
*/
|
||||
int red, green, blue;
|
||||
tod_color color;
|
||||
|
||||
/**
|
||||
* List of "ambient" sounds associated with this time_of_day,
|
||||
|
|
Loading…
Add table
Reference in a new issue