1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Fix unused function warning in release mode

This commit is contained in:
Vadim Markovtsev 2016-02-02 11:12:28 +03:00
parent 35c243c30a
commit 8d7629bdab

View File

@ -12,7 +12,7 @@
#include "CDrawRoadsOperation.h" #include "CDrawRoadsOperation.h"
#include "CMap.h" #include "CMap.h"
const std::vector<CDrawRoadsOperation::RoadPattern> CDrawRoadsOperation::patterns = const std::vector<CDrawRoadsOperation::RoadPattern> CDrawRoadsOperation::patterns =
{ {
//single tile. fall-back pattern //single tile. fall-back pattern
{ {
@ -31,7 +31,7 @@ const std::vector<CDrawRoadsOperation::RoadPattern> CDrawRoadsOperation::pattern
{ {
"?","-","+", "?","-","+",
"-","+","+", "-","+","+",
"+","+","?" "+","+","?"
}, },
{2,5}, {2,5},
{-1,-1}, {-1,-1},
@ -43,7 +43,7 @@ const std::vector<CDrawRoadsOperation::RoadPattern> CDrawRoadsOperation::pattern
{ {
"?","-","?", "?","-","?",
"-","+","+", "-","+","+",
"?","+","?" "?","+","?"
}, },
{0,1}, {0,1},
{0,3}, {0,3},
@ -55,7 +55,7 @@ const std::vector<CDrawRoadsOperation::RoadPattern> CDrawRoadsOperation::pattern
{ {
"?","-","?", "?","-","?",
"-","+","+", "-","+","+",
"?","-","?" "?","-","?"
}, },
{15,15},{11,12}, {15,15},{11,12},
true, true,
@ -66,7 +66,7 @@ const std::vector<CDrawRoadsOperation::RoadPattern> CDrawRoadsOperation::pattern
{ {
"?","-","?", "?","-","?",
"-","+","-", "-","+","-",
"?","+","?" "?","+","?"
}, },
{14,14},{9,10}, {14,14},{9,10},
false, false,
@ -77,7 +77,7 @@ const std::vector<CDrawRoadsOperation::RoadPattern> CDrawRoadsOperation::pattern
{ {
"?","+","?", "?","+","?",
"-","+","+", "-","+","+",
"?","+","?" "?","+","?"
}, },
{6,7},{7,8}, {6,7},{7,8},
true, true,
@ -88,46 +88,46 @@ const std::vector<CDrawRoadsOperation::RoadPattern> CDrawRoadsOperation::pattern
{ {
"?","-","?", "?","-","?",
"+","+","+", "+","+","+",
"?","+","?" "?","+","?"
}, },
{8,9},{5,6}, {8,9},{5,6},
false, false,
true true
}, },
//Straight Horizontal //Straight Horizontal
{ {
{ {
"?","-","?", "?","-","?",
"+","+","+", "+","+","+",
"?","-","?" "?","-","?"
}, },
{12,13},{11,12}, {12,13},{11,12},
false, false,
false false
}, },
//Straight Vertical //Straight Vertical
{ {
{ {
"?","+","?", "?","+","?",
"-","+","-", "-","+","-",
"?","+","?" "?","+","?"
}, },
{10,11},{9,10}, {10,11},{9,10},
false, false,
false false
}, },
//X-cross //X-cross
{ {
{ {
"?","+","?", "?","+","?",
"+","+","+", "+","+","+",
"?","+","?" "?","+","?"
}, },
{16,16},{4,4}, {16,16},{4,4},
false, false,
false false
} }
}; };
static bool ruleIsNone(const std::string & rule) static bool ruleIsNone(const std::string & rule)
@ -140,45 +140,47 @@ static bool ruleIsSomething(const std::string & rule)
return rule == "+"; return rule == "+";
} }
#ifndef NDEBUG
static bool ruleIsAny(const std::string & rule) static bool ruleIsAny(const std::string & rule)
{ {
return rule == "?"; return rule == "?";
} }
#endif
///CDrawRoadsOperation ///CDrawRoadsOperation
CDrawRoadsOperation::CDrawRoadsOperation(CMap * map, const CTerrainSelection & terrainSel, ERoadType::ERoadType roadType, CRandomGenerator * gen): CDrawRoadsOperation::CDrawRoadsOperation(CMap * map, const CTerrainSelection & terrainSel, ERoadType::ERoadType roadType, CRandomGenerator * gen):
CMapOperation(map),terrainSel(terrainSel), roadType(roadType), gen(gen) CMapOperation(map),terrainSel(terrainSel), roadType(roadType), gen(gen)
{ {
} }
void CDrawRoadsOperation::execute() void CDrawRoadsOperation::execute()
{ {
std::set<int3> invalidated; std::set<int3> invalidated;
for(const auto & pos : terrainSel.getSelectedItems()) for(const auto & pos : terrainSel.getSelectedItems())
{ {
auto & tile = map->getTile(pos); auto & tile = map->getTile(pos);
tile.roadType = roadType; tile.roadType = roadType;
auto rect = extendTileAroundSafely(pos); auto rect = extendTileAroundSafely(pos);
rect.forEach([&invalidated](const int3 & pos) rect.forEach([&invalidated](const int3 & pos)
{ {
invalidated.insert(pos); invalidated.insert(pos);
}); });
} }
updateTiles(invalidated); updateTiles(invalidated);
} }
void CDrawRoadsOperation::undo() void CDrawRoadsOperation::undo()
{ {
//TODO //TODO
} }
void CDrawRoadsOperation::redo() void CDrawRoadsOperation::redo()
{ {
//TODO //TODO
} }
std::string CDrawRoadsOperation::getLabel() const std::string CDrawRoadsOperation::getLabel() const
@ -188,14 +190,14 @@ std::string CDrawRoadsOperation::getLabel() const
bool CDrawRoadsOperation::canApplyPattern(const RoadPattern & pattern) const bool CDrawRoadsOperation::canApplyPattern(const RoadPattern & pattern) const
{ {
//TODO: this method should be virtual for river support //TODO: this method should be virtual for river support
return pattern.roadMapping.first >= 0; return pattern.roadMapping.first >= 0;
} }
void CDrawRoadsOperation::flipPattern(RoadPattern& pattern, int flip) const void CDrawRoadsOperation::flipPattern(RoadPattern& pattern, int flip) const
{ {
//todo: use cashing here and also in terrain patterns //todo: use cashing here and also in terrain patterns
if(flip == 0) if(flip == 0)
{ {
return; return;
@ -217,7 +219,7 @@ void CDrawRoadsOperation::flipPattern(RoadPattern& pattern, int flip) const
{ {
std::swap(pattern.data[i], pattern.data[6 + i]); std::swap(pattern.data[i], pattern.data[6 + i]);
} }
} }
} }
@ -226,98 +228,98 @@ bool CDrawRoadsOperation::needUpdateTile(const TerrainTile & tile) const
return tile.roadType != ERoadType::NO_ROAD; //TODO: this method should be virtual for river support return tile.roadType != ERoadType::NO_ROAD; //TODO: this method should be virtual for river support
} }
void CDrawRoadsOperation::updateTiles(std::set<int3> & invalidated) void CDrawRoadsOperation::updateTiles(std::set<int3> & invalidated)
{ {
for(int3 coord : invalidated) for(int3 coord : invalidated)
{ {
TerrainTile & tile = map->getTile(coord); TerrainTile & tile = map->getTile(coord);
ValidationResult result(false); ValidationResult result(false);
if(!needUpdateTile(tile)) if(!needUpdateTile(tile))
continue; continue;
int bestPattern = -1; int bestPattern = -1;
for(int k = 0; k < patterns.size(); ++k) for(int k = 0; k < patterns.size(); ++k)
{ {
result = validateTile(patterns[k], coord); result = validateTile(patterns[k], coord);
if(result.result) if(result.result)
{ {
bestPattern = k; bestPattern = k;
break; break;
} }
} }
if(bestPattern != -1) if(bestPattern != -1)
{ {
updateTile(tile, patterns[bestPattern], result.flip); updateTile(tile, patterns[bestPattern], result.flip);
} }
} }
}; };
bool CDrawRoadsOperation::tileHasSomething(const int3& pos) const bool CDrawRoadsOperation::tileHasSomething(const int3& pos) const
{ {
//TODO: this method should be virtual for river support //TODO: this method should be virtual for river support
return map->getTile(pos).roadType != ERoadType::NO_ROAD; return map->getTile(pos).roadType != ERoadType::NO_ROAD;
} }
void CDrawRoadsOperation::updateTile(TerrainTile & tile, const RoadPattern & pattern, const int flip) void CDrawRoadsOperation::updateTile(TerrainTile & tile, const RoadPattern & pattern, const int flip)
{ {
//TODO: this method should be virtual for river support //TODO: this method should be virtual for river support
const std::pair<int, int> & mapping = pattern.roadMapping; const std::pair<int, int> & mapping = pattern.roadMapping;
tile.roadDir = gen->nextInt(mapping.first, mapping.second); tile.roadDir = gen->nextInt(mapping.first, mapping.second);
tile.extTileFlags = (tile.extTileFlags & 0xCF) | (flip << 4); tile.extTileFlags = (tile.extTileFlags & 0xCF) | (flip << 4);
} }
CDrawRoadsOperation::ValidationResult CDrawRoadsOperation::validateTile(const RoadPattern & pattern, const int3 & pos) CDrawRoadsOperation::ValidationResult CDrawRoadsOperation::validateTile(const RoadPattern & pattern, const int3 & pos)
{ {
ValidationResult result(false); ValidationResult result(false);
if(!canApplyPattern(pattern)) if(!canApplyPattern(pattern))
return result; return result;
for(int flip = 0; flip < 4; ++flip) for(int flip = 0; flip < 4; ++flip)
{ {
if((flip == FLIP_PATTERN_BOTH) && !(pattern.hasHFlip && pattern.hasVFlip)) if((flip == FLIP_PATTERN_BOTH) && !(pattern.hasHFlip && pattern.hasVFlip))
continue; continue;
if((flip == FLIP_PATTERN_HORIZONTAL) && !pattern.hasHFlip) if((flip == FLIP_PATTERN_HORIZONTAL) && !pattern.hasHFlip)
continue; continue;
if((flip == FLIP_PATTERN_VERTICAL) && !(pattern.hasVFlip)) if((flip == FLIP_PATTERN_VERTICAL) && !(pattern.hasVFlip))
continue; continue;
RoadPattern flipped = pattern; RoadPattern flipped = pattern;
flipPattern(flipped, flip); flipPattern(flipped, flip);
bool validated = true; bool validated = true;
for(int i = 0; i < 9; ++i) for(int i = 0; i < 9; ++i)
{ {
if(4 == i) if(4 == i)
continue; continue;
int cx = pos.x + (i % 3) - 1; int cx = pos.x + (i % 3) - 1;
int cy = pos.y + (i / 3) - 1; int cy = pos.y + (i / 3) - 1;
int3 currentPos(cx, cy, pos.z); int3 currentPos(cx, cy, pos.z);
bool hasSomething; bool hasSomething;
if(!map->isInTheMap(currentPos)) if(!map->isInTheMap(currentPos))
{ {
hasSomething = true; //road/river can go out of map hasSomething = true; //road/river can go out of map
} }
else else
{ {
hasSomething = tileHasSomething(currentPos); hasSomething = tileHasSomething(currentPos);
} }
if(ruleIsSomething(flipped.data[i])) if(ruleIsSomething(flipped.data[i]))
{ {
if(!hasSomething) if(!hasSomething)
@ -332,23 +334,22 @@ CDrawRoadsOperation::ValidationResult CDrawRoadsOperation::validateTile(const Ro
{ {
validated = false; validated = false;
break; break;
} }
} }
else else
{ {
assert(ruleIsAny(flipped.data[i])); assert(ruleIsAny(flipped.data[i]));
} }
} }
if(validated) if(validated)
{ {
result.result = true; result.result = true;
result.flip = flip; result.flip = flip;
return result; return result;
} }
} }
return result; return result;
} }