Stop uselessly storing precedence into each rule

(already stored in the main containing structure)
This commit is contained in:
Ali El Gariani 2009-12-04 06:01:02 +00:00
parent e3b61579f0
commit fde533b6b1
2 changed files with 16 additions and 22 deletions

View file

@ -524,7 +524,6 @@ terrain_builder::building_rule terrain_builder::rotate_rule(const terrain_builde
}
ret.location_constraints = rule.location_constraints;
ret.probability = rule.probability;
ret.precedence = rule.precedence;
ret.local = rule.local;
constraint_set tmp_cons;
@ -702,26 +701,26 @@ void terrain_builder::parse_mapstring(const std::string &mapstring,
}
}
void terrain_builder::add_rule(building_ruleset& rules, building_rule &rule)
void terrain_builder::add_rule(building_ruleset& rules, building_rule &rule, int precedence)
{
if(rule_valid(rule)) {
start_animation(rule);
rules.insert(std::pair<int, building_rule>(rule.precedence, rule));
rules.insert(std::pair<int, building_rule>(precedence, rule));
}
}
void terrain_builder::add_rotated_rules(building_ruleset& rules, building_rule& tpl, const std::string &rotations)
void terrain_builder::add_rotated_rules(building_ruleset& rules, building_rule& tpl, int precedence, const std::string &rotations )
{
if(rotations.empty()) {
// Adds the parsed built terrain to the list
add_rule(rules, tpl);
add_rule(rules, tpl, precedence);
} else {
const std::vector<std::string>& rot = utils::split(rotations, ',');
for(size_t angle = 0; angle < rot.size(); angle++) {
building_rule rule = rotate_rule(tpl, angle, rot);
add_rule(rules, rule);
add_rule(rules, rule, precedence);
}
}
}
@ -743,7 +742,6 @@ void terrain_builder::parse_config(const config &cfg, bool local)
map_location(atoi(br["x"].c_str()) - 1, atoi(br["y"].c_str()) - 1);
pbr.probability = br["probability"].empty() ? -1 : atoi(br["probability"].c_str());
pbr.precedence = br["precedence"].empty() ? 0 : atoi(br["precedence"].c_str());
// Mapping anchor indices to anchor locations.
anchormap anchors;
@ -811,7 +809,10 @@ void terrain_builder::parse_config(const config &cfg, bool local)
// Handles rotations
const std::string &rotations = br["rotations"];
add_rotated_rules(building_rules_, pbr, rotations);
const std::string preced = br["precedence"];
int precedence = preced.empty() ? 0 : atoi(preced.c_str());
add_rotated_rules(building_rules_, pbr, precedence, rotations);
}
@ -824,7 +825,6 @@ void terrain_builder::parse_config(const config &cfg, bool local)
std::cerr << ">> New rule: image_background = "
<< "\n>> Location " << rule->second.location_constraints
<< "\n>> Probability " << rule->second.probability
<< "\n>> Precedence " << rule->second.precedence << '\n';
for(constraint_set::const_iterator constraint = rule->second.constraints.begin();
constraint != rule->second.constraints.end(); ++constraint) {

View file

@ -330,7 +330,6 @@ private:
constraints(),
location_constraints(),
probability(0),
precedence(0),
local(false)
{}
@ -353,14 +352,6 @@ private:
*/
int probability;
/**
* The precedence of this rule. Used to order rules differently
* that the order in which they appear.
* Defined if the "precedence" parameter of the
* [terrain_graphics] element is set.
*/
int precedence;
/**
* Indicate if the rule is only for this scenario
*/
@ -639,10 +630,11 @@ private:
/**
* Adds a rule to a ruleset. Checks for validity before adding the rule.
*
* @param rules The ruleset into which to add the rules.
* @param rule The rule to add.
* @param rules The ruleset into which to add the rules.
* @param rule The rule to add.
* @param precedence The precedence specified in [terrain_graphics].
*/
void add_rule(building_ruleset& rules, building_rule &rule);
void add_rule(building_ruleset& rules, building_rule &rule, int precedence);
/**
* Adds a set of rules to a ruleset, from a template rule which spans
@ -650,11 +642,13 @@ private:
*
* @param rules The ruleset into which to add the rules.
* @param tpl The template rule
* @param precedence The precedence specified in [terrain_graphics].
* @param rotations A comma-separated string containing the
* 6 values for replacing rotation
* template strings @verbatim (@Rn) @endverbatim
*/
void add_rotated_rules(building_ruleset& rules, building_rule& tpl, const std::string &rotations);
void add_rotated_rules(building_ruleset& rules, building_rule& tpl,
int precedence, const std::string &rotations);
/**
* Parses a configuration object containing [terrain_graphics] rules,