Optimized further the building of rotated rules.
This brings the speed up of the previous commit up to 70%.
This commit is contained in:
parent
e3ec2ed503
commit
b069193054
2 changed files with 7 additions and 10 deletions
|
@ -373,7 +373,7 @@ bool terrain_builder::load_images(building_rule &rule)
|
|||
return true;
|
||||
}
|
||||
|
||||
terrain_builder::terrain_constraint terrain_builder::rotate(const terrain_builder::terrain_constraint &constraint, int angle)
|
||||
void terrain_builder::rotate(terrain_constraint &ret, int angle)
|
||||
{
|
||||
static const struct { int ii; int ij; int ji; int jj; } rotations[6] =
|
||||
{ { 1, 0, 0, 1 }, { 1, 1, -1, 0 }, { 0, 1, -1, -1 },
|
||||
|
@ -423,7 +423,6 @@ terrain_builder::terrain_constraint terrain_builder::rotate(const terrain_builde
|
|||
assert(angle >= 0);
|
||||
|
||||
angle %= 6;
|
||||
terrain_constraint ret = constraint;
|
||||
|
||||
// Vector i is going from n to s, vector j is going from ne to sw.
|
||||
int vi = ret.loc.y - ret.loc.x/2;
|
||||
|
@ -452,8 +451,6 @@ terrain_builder::terrain_constraint terrain_builder::rotate(const terrain_builde
|
|||
//std::cerr << "Rotation: from " << vx << ", " << vy << " to " << itor->basex <<
|
||||
// ", " << itor->basey << "\n";
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void terrain_builder::replace_token(std::string &s, const std::string &token, const std::string &replacement)
|
||||
|
@ -517,9 +514,9 @@ terrain_builder::building_rule terrain_builder::rotate_rule(const terrain_builde
|
|||
ret.probability = rule.probability;
|
||||
ret.local = rule.local;
|
||||
|
||||
ret.constraints.reserve(rule.constraints.size());
|
||||
foreach (const terrain_constraint &cons, rule.constraints) {
|
||||
ret.constraints.push_back(rotate(cons, angle));
|
||||
ret.constraints = rule.constraints;
|
||||
foreach (terrain_constraint &cons, ret.constraints) {
|
||||
rotate(cons, angle);
|
||||
}
|
||||
|
||||
// Normalize the rotation, so that it starts on a positive location
|
||||
|
|
|
@ -464,8 +464,8 @@ private:
|
|||
|
||||
/**
|
||||
* "Rotates" a constraint from a rule.
|
||||
* Takes a template constraint from a template rule, and creates
|
||||
* a constraint from this template, rotated to the given angle.
|
||||
* Takes a template constraint from a template rule, and rotates
|
||||
* to the given angle.
|
||||
*
|
||||
* On a constraint, the relative position of each rule, and the "base"
|
||||
* of each vertical images, are rotated according to the given angle.
|
||||
|
@ -482,7 +482,7 @@ private:
|
|||
* @param constraint A template constraint to rotate
|
||||
* @param angle An int, from 0 to 5, representing the rotation angle.
|
||||
*/
|
||||
terrain_constraint rotate(const terrain_constraint &constraint, int angle);
|
||||
void rotate(terrain_constraint &constraint, int angle);
|
||||
|
||||
/**
|
||||
* Replaces, in a given string, a token with its value.
|
||||
|
|
Loading…
Add table
Reference in a new issue