Skip to content

Commit

Permalink
Added an "Animate water" toggle to display preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
ln-zookeeper committed Mar 2, 2016
1 parent 703d783 commit d9326e1
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog
Expand Up @@ -30,6 +30,7 @@ Version 1.13.2+dev:
* Graphics:
* Improved or new terrain graphics: Stones with Sand Drifts, Igloo Village,
Adobe Village.
* Added option for toggling off water animations to Preferences -> Display.
* Language and i18n:
* New translation: Asturian
* Updated translations: British English, Galician, Russian, Swedish
Expand Down
2 changes: 2 additions & 0 deletions data/core/terrain-graphics/internal-generic.cfg
Expand Up @@ -343,6 +343,7 @@
[image]
name={IMAGESTEM}-A[01~15].png{IPF}:{TIME}
layer=-1000
is_water=yes
[/image]
[/tile]
[/terrain_graphics]
Expand All @@ -367,6 +368,7 @@
[image]
name={IMAGESTEM}-A[01~15]-@R0.png{IPF}:{TIME}
layer={LAYER}
is_water=yes
[/image]
# wmlscope: stop ignoring
[/tile]
Expand Down
5 changes: 5 additions & 0 deletions data/core/terrain-graphics/new-macros.cfg
Expand Up @@ -776,6 +776,7 @@
layer={LAYER}
center=90,144
base=90,144
is_water=yes
[/image]
[/terrain_graphics]
[terrain_graphics]
Expand Down Expand Up @@ -807,6 +808,7 @@
layer={LAYER}
center=90,144
base=90,144
is_water=yes
[/image]
[/terrain_graphics]

Expand Down Expand Up @@ -839,6 +841,7 @@
layer={LAYER}
center=90,144
base=90,144
is_water=yes
[/image]
[/terrain_graphics]
[terrain_graphics]
Expand Down Expand Up @@ -870,6 +873,7 @@
layer={LAYER}
center=90,144
base=90,144
is_water=yes
[/image]
[/terrain_graphics]
#enddef
Expand Down Expand Up @@ -1229,6 +1233,7 @@
layer={LAYER}
name={IMAGESTEM}[01~{FRAMES}].png~CROP(0,0,72,72){MASKIPF}{IPF}:100
random_start=no
is_water=yes

[variant]
has_flag=342x180_water02
Expand Down
14 changes: 14 additions & 0 deletions data/gui/default/window/preferences/03_display.cfg
Expand Up @@ -131,6 +131,20 @@
[/column]
[/row]

[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"

[toggle_button]
id = "animate_water"
label = _ "Animate water"
tooltip = "Display animated water graphics (can be slow)"
[/toggle_button]
[/column]
[/row]

[row]
[column]
border = "all"
Expand Down
1 change: 1 addition & 0 deletions players_changelog
Expand Up @@ -13,6 +13,7 @@ Version 1.13.2+dev:
* Graphics:
* Improved or new terrain graphics: Stones with Sand Drifts, Igloo Village,
Adobe Village.
* Added option for toggling off water animations to Preferences -> Display.

* Language and i18n:
* New translation: Asturian
Expand Down
7 changes: 7 additions & 0 deletions src/display.cpp
Expand Up @@ -203,6 +203,7 @@ display::display(const display_context * dc, CVideo& video, boost::weak_ptr<wb::
mouseoverHex_(),
keys_(),
animate_map_(true),
animate_water_(true),
flags_(),
activeTeam_(0),
drawing_buffer_(),
Expand Down Expand Up @@ -2770,6 +2771,12 @@ void display::draw(bool update,bool force) {
return;
}

// Trigger cache rebuild when preference gets changed
if (animate_water_ != preferences::animate_water()) {
animate_water_ = preferences::animate_water();
builder_->rebuild_cache_all();
}

set_scontext_unsynced leave_synced_context;

draw_init();
Expand Down
3 changes: 3 additions & 0 deletions src/display.hpp
Expand Up @@ -839,6 +839,9 @@ class display : public filter_context, public video2::draw_layering
/** Local cache for preferences::animate_map, since it is constantly queried. */
bool animate_map_;

/** Local version of preferences::animate_water, used to detect when it's changed. */
bool animate_water_;

private:

#ifdef SDL_GPU
Expand Down
4 changes: 4 additions & 0 deletions src/gui/dialogs/preferences_dialog.cpp
Expand Up @@ -573,6 +573,10 @@ void tpreferences::initialize_members(twindow& window)
setup_single_toggle("animate_terrains",
animate_map(), set_animate_map, window);

/* ANIMATE WATER */
setup_single_toggle("animate_water",
animate_water(), set_animate_water, window);

/* SHOW UNIT STANDING ANIMS */
setup_single_toggle("animate_units_standing",
show_standing_animations(), set_show_standing_animations, window);
Expand Down
10 changes: 10 additions & 0 deletions src/preferences.cpp
Expand Up @@ -864,6 +864,11 @@ bool animate_map()
return preferences::get("animate_map", true);
}

bool animate_water()
{
return preferences::get("animate_water", true);
}

bool minimap_movement_coding()
{
return preferences::get("minimap_movement_coding", true);
Expand Down Expand Up @@ -919,6 +924,11 @@ void set_animate_map(bool value)
set("animate_map", value);
}

void set_animate_water(bool value)
{
set("animate_water", value);
}

bool show_standing_animations()
{
return preferences::get("unit_standing_animations", true);
Expand Down
3 changes: 3 additions & 0 deletions src/preferences.hpp
Expand Up @@ -222,6 +222,9 @@ namespace preferences {
bool animate_map();
void set_animate_map(bool value);

bool animate_water();
void set_animate_water(bool value);

bool minimap_movement_coding();
void toggle_minimap_movement_coding();

Expand Down
24 changes: 21 additions & 3 deletions src/terrain_builder.cpp
Expand Up @@ -19,6 +19,7 @@

#include "terrain_builder.hpp"

#include "game_preferences.hpp"
#include "image.hpp"
#include "loadscreen.hpp"
#include "log.hpp"
Expand Down Expand Up @@ -88,14 +89,15 @@ static map_location legacy_difference(const map_location & me, const map_locatio
terrain_builder::building_ruleset terrain_builder::building_rules_;
const config* terrain_builder::rules_cfg_ = NULL;

terrain_builder::rule_image::rule_image(int layer, int x, int y, bool global_image, int cx, int cy) :
terrain_builder::rule_image::rule_image(int layer, int x, int y, bool global_image, int cx, int cy, bool is_water) :
layer(layer),
basex(x),
basey(y),
variants(),
global_image(global_image),
center_x(cx),
center_y(cy)
center_y(cy),
is_water(is_water)
{}

terrain_builder::tile::tile() :
Expand All @@ -121,6 +123,7 @@ void terrain_builder::tile::rebuild_cache(const std::string& tod, logs* log)

BOOST_FOREACH(const rule_image_rand& ri, images){
bool is_background = ri->is_background();
bool animate = (!ri.ri->is_water || preferences::animate_water());

imagelist& img_list = is_background ? images_background : images_foreground;

Expand Down Expand Up @@ -164,6 +167,10 @@ void terrain_builder::tile::rebuild_cache(const std::string& tod, logs* log)
if(variant.random_start)
img_list.back().set_animation_time(ri.rand % img_list.back().get_animation_duration());

if (!animate) {
img_list.back().pause_animation();
}

if(log) {
log->push_back(std::make_pair(&ri, &variant));
}
Expand Down Expand Up @@ -256,6 +263,15 @@ terrain_builder::terrain_builder(const config& level,
build_terrains();
}

void terrain_builder::rebuild_cache_all()
{
for(int x = -2; x <= map().w(); ++x) {
for(int y = -2; y <= map().h(); ++y) {
tile_map_[map_location(x,y)].rebuild_cache("");
}
}
}

void terrain_builder::flush_local_rules()
{
building_ruleset::iterator i = building_rules_.begin();
Expand Down Expand Up @@ -684,7 +700,9 @@ void terrain_builder::add_images_from_config(rule_imagelist& images, const confi
}
}

images.push_back(rule_image(layer, basex - dx, basey - dy, global, center_x, center_y));
bool is_water = img["is_water"].to_bool();

images.push_back(rule_image(layer, basex - dx, basey - dy, global, center_x, center_y, is_water));

// Adds the other variants of the image
BOOST_FOREACH(const config &variant, img.child_range("variant"))
Expand Down
6 changes: 5 additions & 1 deletion src/terrain_builder.hpp
Expand Up @@ -143,6 +143,8 @@ class terrain_builder
*/
void rebuild_all();

void rebuild_cache_all();

/**
* An image variant. The in-memory representation of the [variant]
* WML tag of the [image] WML tag. When an image only has one variant,
Expand Down Expand Up @@ -209,7 +211,7 @@ class terrain_builder
* The rule_image structure represents one such image.
*/
struct rule_image {
rule_image(int layer, int x, int y, bool global_image=false, int center_x=-1, int center_y=-1);
rule_image(int layer, int x, int y, bool global_image=false, int center_x=-1, int center_y=-1, bool is_water=false);

bool is_background() const {
return layer < 0 || (layer == 0 && basey < UNITPOS);
Expand All @@ -233,6 +235,8 @@ class terrain_builder
/** The position where the center of the image base should be
*/
int center_x, center_y;

bool is_water;
};

/**
Expand Down

0 comments on commit d9326e1

Please sign in to comment.