diff --git a/lib/mapObjects/ObjectTemplate.cpp b/lib/mapObjects/ObjectTemplate.cpp index 7dcd1d799..153d2d3e4 100644 --- a/lib/mapObjects/ObjectTemplate.cpp +++ b/lib/mapObjects/ObjectTemplate.cpp @@ -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(ret, row.size()); } diff --git a/lib/mapping/CMapEditManager.cpp b/lib/mapping/CMapEditManager.cpp index 95b7b8fbb..87439613d 100644 --- a/lib/mapping/CMapEditManager.cpp +++ b/lib/mapping/CMapEditManager.cpp @@ -321,16 +321,16 @@ TerrainViewPattern::TerrainViewPattern() : diffImages(false), rotationTypesCount maxPoints = std::numeric_limits::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 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) { diff --git a/lib/mapping/CMapEditManager.h b/lib/mapping/CMapEditManager.h index b24cb9262..a2b91c1b6 100644 --- a/lib/mapping/CMapEditManager.h +++ b/lib/mapping/CMapEditManager.h @@ -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; diff --git a/lib/rmg/CRmgTemplateZone.cpp b/lib/rmg/CRmgTemplateZone.cpp index 9a655226e..6825beade 100644 --- a/lib/rmg/CRmgTemplateZone.cpp +++ b/lib/rmg/CRmgTemplateZone.cpp @@ -1497,11 +1497,7 @@ void CRmgTemplateZone::initTerrainType (CMapGenerator* gen) void CRmgTemplateZone::paintZoneTerrain (CMapGenerator* gen, ETerrainType terrainType) { - std::vector tiles; - for (auto tile : tileinfo) - { - tiles.push_back (tile); - } + std::vector 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 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;