Allow specifying the random shift range for terrain animation times
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.
This commit is contained in:
parent
7534038e48
commit
863f31c628
2 changed files with 15 additions and 8 deletions
|
@ -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();
|
||||
|
@ -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()
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,7 +156,7 @@ public:
|
|||
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()
|
||||
|
@ -171,7 +171,7 @@ public:
|
|||
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.
|
||||
|
@ -208,8 +208,9 @@ public:
|
|||
|
||||
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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue