mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-26 03:52:01 +02:00
- WeightedRule optimization - part 1
- comments, style
This commit is contained in:
parent
25fd4d85e2
commit
2410f0af61
@ -350,7 +350,7 @@ ui32 ObjectTemplate::getWidth() const
|
||||
//TODO: Use 2D array
|
||||
//TODO: better precalculate and store constant value
|
||||
ui32 ret = 0;
|
||||
for (auto const &row : usedTiles) //copy is expensive
|
||||
for (const auto &row : usedTiles) //copy is expensive
|
||||
{
|
||||
ret = std::max<ui32>(ret, row.size());
|
||||
}
|
||||
|
@ -321,16 +321,16 @@ TerrainViewPattern::TerrainViewPattern() : diffImages(false), rotationTypesCount
|
||||
maxPoints = std::numeric_limits<int>::max();
|
||||
}
|
||||
|
||||
TerrainViewPattern::WeightedRule::WeightedRule() : points(0)
|
||||
TerrainViewPattern::WeightedRule::WeightedRule(std::string &Name) : points(0), name(Name)
|
||||
{
|
||||
|
||||
standardRule = (TerrainViewPattern::RULE_ANY == name || TerrainViewPattern::RULE_DIRT == name
|
||||
|| TerrainViewPattern::RULE_NATIVE == name || TerrainViewPattern::RULE_SAND == name
|
||||
|| TerrainViewPattern::RULE_TRANSITION == name || TerrainViewPattern::RULE_NATIVE_STRONG == name);
|
||||
}
|
||||
|
||||
bool TerrainViewPattern::WeightedRule::isStandardRule() const
|
||||
{
|
||||
return TerrainViewPattern::RULE_ANY == name || TerrainViewPattern::RULE_DIRT == name
|
||||
|| TerrainViewPattern::RULE_NATIVE == name || TerrainViewPattern::RULE_SAND == name
|
||||
|| TerrainViewPattern::RULE_TRANSITION == name || TerrainViewPattern::RULE_NATIVE_STRONG == name;
|
||||
return standardRule;
|
||||
}
|
||||
|
||||
CTerrainViewPatternConfig::CTerrainViewPatternConfig()
|
||||
@ -357,8 +357,7 @@ CTerrainViewPatternConfig::CTerrainViewPatternConfig()
|
||||
{
|
||||
std::vector<std::string> ruleParts;
|
||||
boost::split(ruleParts, ruleStr, boost::is_any_of("-"));
|
||||
TerrainViewPattern::WeightedRule rule;
|
||||
rule.name = ruleParts[0];
|
||||
TerrainViewPattern::WeightedRule rule(ruleParts[0]);
|
||||
assert(!rule.name.empty());
|
||||
if(ruleParts.size() > 1)
|
||||
{
|
||||
|
@ -229,7 +229,7 @@ struct DLL_LINKAGE TerrainViewPattern
|
||||
{
|
||||
struct WeightedRule
|
||||
{
|
||||
WeightedRule();
|
||||
WeightedRule(std::string &Name);
|
||||
/// Gets true if this rule is a standard rule which means that it has a value of one of the RULE_* constants.
|
||||
bool isStandardRule() const;
|
||||
|
||||
@ -237,6 +237,11 @@ struct DLL_LINKAGE TerrainViewPattern
|
||||
std::string name;
|
||||
/// Optional. A rule can have points. Patterns may have a minimum count of points to reach to be successful.
|
||||
int points;
|
||||
|
||||
private:
|
||||
bool standardRule;
|
||||
|
||||
WeightedRule(); //only allow string constructor
|
||||
};
|
||||
|
||||
static const int PATTERN_DATA_SIZE = 9;
|
||||
|
@ -1497,11 +1497,7 @@ void CRmgTemplateZone::initTerrainType (CMapGenerator* gen)
|
||||
|
||||
void CRmgTemplateZone::paintZoneTerrain (CMapGenerator* gen, ETerrainType terrainType)
|
||||
{
|
||||
std::vector<int3> tiles;
|
||||
for (auto tile : tileinfo)
|
||||
{
|
||||
tiles.push_back (tile);
|
||||
}
|
||||
std::vector<int3> tiles(tileinfo.begin(), tileinfo.end());
|
||||
gen->editManager->getTerrainSelection().setSelection(tiles);
|
||||
gen->editManager->drawTerrain(terrainType, &gen->rand);
|
||||
}
|
||||
@ -2305,7 +2301,6 @@ ObjectInfo CRmgTemplateZone::getRandomObject(CMapGenerator* gen, CTreasurePileIn
|
||||
|
||||
bool fitsBlockmap = true;
|
||||
|
||||
|
||||
std::set<int3> blockedOffsets = oi.templ.getBlockedOffsets();
|
||||
blockedOffsets.insert (newVisitableOffset);
|
||||
for (auto blockingTile : blockedOffsets)
|
||||
@ -2327,13 +2322,11 @@ ObjectInfo CRmgTemplateZone::getRandomObject(CMapGenerator* gen, CTreasurePileIn
|
||||
|
||||
total += oi.probability;
|
||||
|
||||
//FIXME: apparently this is quite expensive operation
|
||||
//FIXME: apparently this is quite expensive operation, but "reserve" doesn't improve speed
|
||||
thresholds.push_back (std::make_pair (total, oi));
|
||||
}
|
||||
}
|
||||
|
||||
//logGlobal->infoStream() << boost::format ("Number of objects visitable from bottom: %d") % objectsVisitableFromBottom;
|
||||
|
||||
if (thresholds.empty())
|
||||
{
|
||||
ObjectInfo oi;
|
||||
|
Loading…
x
Reference in New Issue
Block a user