Fix various compiler warnings on MSVC

I tried to avoid casts whereever it was possible, but for some cases it wasn't.
master
addi 2016-06-16 08:03:29 +02:00 committed by Rogier
parent fade10aa1b
commit 445071cad5
6 changed files with 15 additions and 14 deletions

View File

@ -142,8 +142,8 @@ public:
NodeCoordHashed(const BlockPos &pos) : NodeCoord(pos) { rehash(); }
NodeCoordHashed(const NodeCoord &coord) : NodeCoord(coord) { rehash(); }
void rehash(void) { m_hash = NodeCoord::hash(); }
unsigned hash(void) { rehash(); return m_hash; }
unsigned hash(void) const { return m_hash; }
size_t hash(void) { rehash(); return m_hash; }
size_t hash(void) const { return m_hash; }
bool operator==(const NodeCoordHashed &coord) const { if (m_hash != coord.m_hash) return false; return NodeCoord::operator==(coord); }
void operator=(const NodeCoord &coord) { NodeCoord::operator=(coord); rehash(); }
bool operator<(const NodeCoordHashed &coord) { return m_hash < coord.m_hash; }

View File

@ -2214,8 +2214,8 @@ void TileGenerator::renderHeightScale()
Color color = computeMapHeightColor(int(height + 0.5));
gdImageLine(m_image, xBorderOffset + x, yBorderOffset + 8, xBorderOffset + x, yBorderOffset + borderBottom() - 20, color.to_libgd());
int iheight = int(height + (height > 0 ? 0.5 : -0.5));
int iheightMaj = int(iheight / major + (height > 0 ? 0.5 : -0.5)) * major;
int iheight = static_cast<int>(height + (height > 0 ? 0.5 : -0.5));
int iheightMaj = static_cast<int>(trunc(iheight / major + (height > 0 ? 0.5 : -0.5)) * major);
if (fabs(height - iheightMaj) <= height_step / 2 && (height - iheightMaj) > -height_step / 2) {
if (iheightMaj / int(major) % 2 == 1 && fabs(height) > 9999 && major / height_step < 56) {
// Maybe not enough room for the number. Draw a tick mark instead
@ -2252,8 +2252,8 @@ void TileGenerator::renderPlayers(const std::string &inputPath)
PlayerAttributes players(inputPath);
for (PlayerAttributes::Players::iterator player = players.begin(); player != players.end(); ++player) {
int imageX = worldX2ImageX(player->x / 10);
int imageY = worldZ2ImageY(player->z / 10);
int imageX = worldX2ImageX(static_cast<int>(player->x / 10));
int imageY = worldZ2ImageY(static_cast<int>(player->z / 10));
std::string displayName = m_gdStringConv->convert(player->name);
gdImageArc(m_image, imageX, imageY, 5, 5, 0, 360, color);

View File

@ -46,7 +46,7 @@ ustring ZlibDecompressor::decompress()
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.next_in = Z_NULL;
strm.avail_in = size;
strm.avail_in = static_cast<uInt>(size);
if (inflateInit(&strm) != Z_OK) {
throw DecompressError(strm.msg);

View File

@ -49,6 +49,7 @@ using namespace std;
#define DRAW_ARROW_LENGTH 10
#define DRAW_ARROW_ANGLE 30
// Will be replaced with the actual name and location of the executable (if found)
string executableName = "minetestmapper";
string executablePath; // ONLY for use on windows
@ -497,7 +498,7 @@ static void orderCoordinateDimensions(NodeCoord &coord1, NodeCoord &coord2, int
// <x>,<y>@<angle>+<length>
static bool parseGeometry(istream &is, NodeCoord &coord1, NodeCoord &coord2, NodeCoord &dimensions, bool &legacy, bool &centered, int n, FuzzyBool expectDimensions, int wildcard = 0)
{
int pos;
std::streamoff pos;
pos = is.tellg();
legacy = false;
@ -871,7 +872,7 @@ int main(int argc, char *argv[])
break;
case OPT_HEIGHTMAPYSCALE:
if (isdigit(optarg[0]) || ((optarg[0]=='-' || optarg[0]=='+') && isdigit(optarg[1]))) {
float scale = atof(optarg);
float scale = static_cast<float>(atof(optarg));
generator.setHeightMapYScale(scale);
}
else {

View File

@ -34,15 +34,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
static inline int unsigned_to_signed(unsigned i, unsigned max_positive)
{
if (i < max_positive) {
return i;
return static_cast<int>(i);
} else {
return i - (max_positive * 2);
return static_cast<int>(i - (max_positive * 2));
}
}
// Modulo of a negative number does not work consistently in C
static inline int64_t pythonmodulo(int64_t i, int16_t mod)
static inline unsigned pythonmodulo(int64_t i, unsigned mod)
{
if (i >= 0) {
return i % mod;

4
util.h
View File

@ -6,9 +6,9 @@
inline std::string strlower(const std::string &s)
{
int l = s.length();
size_t l = s.length();
std::string sl = s;
for (int i = 0; i < l; i++)
for (size_t i = 0; i < l; i++)
sl[i] = tolower(sl[i]);
return sl;
}