Skip to content

Commit

Permalink
Allow specifying the random shift range for terrain animation times
Browse files Browse the repository at this point in the history
Previously, terrain graphics [image] random_start= only accepted a boolean value, but this commit makes it optionally also accept an integer value, which will be used as the range of random shift (in milliseconds) that the animation is allowed. This can be used for example to allow animations such as water to play only slightly out of sync.
  • Loading branch information
ln-zookeeper committed Aug 29, 2017
1 parent 7534038 commit 863f31c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
14 changes: 10 additions & 4 deletions src/terrain/builder.cpp
Expand Up @@ -166,8 +166,10 @@ void terrain_builder::tile::rebuild_cache(const std::string& tod, logs* log)

assert(anim.get_animation_duration() != 0);

if(variant.random_start)
if(variant.random_start < 0)
img_list.back().set_animation_time(ri.rand % img_list.back().get_animation_duration());
else if(variant.random_start > 0)
img_list.back().set_animation_time(ri.rand % variant.random_start);

if(!animate) {
img_list.back().pause_animation();
Expand Down Expand Up @@ -662,7 +664,7 @@ terrain_builder::rule_image_variant::rule_image_variant(const std::string& image
const std::string& variations,
const std::string& tod,
const std::string& has_flag,
bool random_start)
int random_start)
: image_string(image_string)
, variations(variations)
, images()
Expand Down Expand Up @@ -721,7 +723,9 @@ void terrain_builder::add_images_from_config(rule_imagelist& images, const confi
const std::string& variations = img["variations"];
const std::string& tod = variant["tod"];
const std::string& has_flag = variant["has_flag"];
bool random_start = variant["random_start"].to_bool(true);

// If an integer is given then assign that, but if a bool is given, then assign -1 if true and 0 if false
int random_start = variant["random_start"].to_bool(true) ? variant["random_start"].to_int(-1) : 0;

images.back().variants.push_back(rule_image_variant(name, variations, tod, has_flag, random_start));
}
Expand All @@ -730,7 +734,9 @@ void terrain_builder::add_images_from_config(rule_imagelist& images, const confi
// (will be used only if previous variants don't match)
const std::string& name = img["name"];
const std::string& variations = img["variations"];
bool random_start = img["random_start"].to_bool(true);

int random_start = img["random_start"].to_bool(true) ? img["random_start"].to_int(-1) : 0;

images.back().variants.push_back(rule_image_variant(name, variations, random_start));
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/terrain/builder.hpp
Expand Up @@ -156,7 +156,7 @@ class terrain_builder
struct rule_image_variant
{
/** Constructor for the normal defaut case */
rule_image_variant(const std::string& image_string, const std::string& variations, bool random_start = true)
rule_image_variant(const std::string& image_string, const std::string& variations, int random_start = -1)
: image_string(image_string)
, variations(variations)
, images()
Expand All @@ -171,7 +171,7 @@ class terrain_builder
const std::string& variations,
const std::string& tod,
const std::string& has_flag,
bool random_start = true);
int random_start = -1);

/** A string representing either the filename for an image, or
* a list of images, with an optional timing for each image.
Expand Down Expand Up @@ -208,8 +208,9 @@ class terrain_builder

std::vector<std::string> has_flag;

/** Indicate if the animation uses a random shift */
bool random_start;
/** Specify the allowed amount of random shift (in milliseconds) applied
* to the animation start time, -1 for shifting without limitation.*/
int random_start;
};

/**
Expand Down

0 comments on commit 863f31c

Please sign in to comment.