From 32be20aeb3e4211f728dc597b4b809f8072c82b8 Mon Sep 17 00:00:00 2001 From: Vsevolod Kremianskii Date: Sun, 13 Jun 2021 11:24:20 +0700 Subject: [PATCH] Fix all MSVC compilation warnings --- src/engine/game/combat/combat.h | 2 +- src/engine/game/combat/combat_damage.cpp | 2 +- src/engine/game/gui/barkbubble.cpp | 2 +- src/engine/game/gui/selectoverlay.cpp | 8 +++--- src/engine/graphics/lip/lipwriter.cpp | 2 +- src/engine/graphics/mesh/mesh.cpp | 34 +++++++++++------------ src/engine/graphics/texture/tgawriter.cpp | 18 ++++++------ src/engine/gui/control/control.cpp | 4 +-- src/engine/gui/control/imagebutton.cpp | 4 +-- src/engine/scene/node/lightnode.cpp | 4 +-- src/tools/pthtool.cpp | 4 +-- 11 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/engine/game/combat/combat.h b/src/engine/game/combat/combat.h index 29323750..8cd6d3cc 100644 --- a/src/engine/game/combat/combat.h +++ b/src/engine/game/combat/combat.h @@ -114,7 +114,7 @@ private: // Damage - std::vector> getDamageEffects(std::shared_ptr damager, bool offHand = false, float multiplier = 1.0f) const; + std::vector> getDamageEffects(std::shared_ptr damager, bool offHand = false, int multiplier = 1) const; // END Damage diff --git a/src/engine/game/combat/combat_damage.cpp b/src/engine/game/combat/combat_damage.cpp index 1fc97b56..7d41e664 100644 --- a/src/engine/game/combat/combat_damage.cpp +++ b/src/engine/game/combat/combat_damage.cpp @@ -29,7 +29,7 @@ namespace reone { namespace game { -vector> Combat::getDamageEffects(shared_ptr damager, bool offHand, float multiplier) const { +vector> Combat::getDamageEffects(shared_ptr damager, bool offHand, int multiplier) const { shared_ptr weapon(damager->getEquippedItem(offHand ? InventorySlot::leftWeapon : InventorySlot::rightWeapon)); int amount = 0; auto type = DamageType::Bludgeoning; diff --git a/src/engine/game/gui/barkbubble.cpp b/src/engine/game/gui/barkbubble.cpp index 8d409e5f..11386fb6 100644 --- a/src/engine/game/gui/barkbubble.cpp +++ b/src/engine/game/gui/barkbubble.cpp @@ -58,7 +58,7 @@ void BarkBubble::setBarkText(const string &text, float duration) { _binding.lblBarkText->setVisible(false); } else { float textWidth = _binding.lblBarkText->text().font->measure(text); - int lineCount = textWidth / static_cast(_binding.lblBarkText->extent().width) + 1; + int lineCount = static_cast(textWidth / static_cast(_binding.lblBarkText->extent().width)) + 1; int padding = _binding.lblBarkText->extent().left; float rootHeight = lineCount * _binding.lblBarkText->text().font->height() + 2 * padding; float labelHeight = lineCount * _binding.lblBarkText->text().font->height(); diff --git a/src/engine/game/gui/selectoverlay.cpp b/src/engine/game/gui/selectoverlay.cpp index 3819bd05..1287d019 100644 --- a/src/engine/game/gui/selectoverlay.cpp +++ b/src/engine/game/gui/selectoverlay.cpp @@ -146,7 +146,7 @@ bool SelectionOverlay::handleMouseWheel(const SDL_MouseWheelEvent &event) { if (event.y > 0) { if (slot.indexSelected-- == 0) { - slot.indexSelected = numSlotActions - 1; + slot.indexSelected = static_cast(numSlotActions - 1); } } else { if (++slot.indexSelected == numSlotActions) { @@ -267,7 +267,7 @@ void SelectionOverlay::drawTitleBar() { float barHeight = _font->height() + kTitleBarPadding; { float x = opts.width * _selectedScreenCoords.x - kTitleBarWidth / 2; - float y = opts.height * (1.0f - _selectedScreenCoords.y) - _reticleHeight / 2 - barHeight - kOffsetToReticle - kHealthBarHeight - 1.0f; + float y = opts.height * (1.0f - _selectedScreenCoords.y) - _reticleHeight / 2.0f - barHeight - kOffsetToReticle - kHealthBarHeight - 1.0f; if (_hasActions) { y -= kActionHeight + 2 * kActionBarMargin; @@ -299,7 +299,7 @@ void SelectionOverlay::drawTitleBar() { void SelectionOverlay::drawHealthBar() { const GraphicsOptions &opts = _game->options().graphics; float x = opts.width * _selectedScreenCoords.x - kTitleBarWidth / 2; - float y = opts.height * (1.0f - _selectedScreenCoords.y) - _reticleHeight / 2 - kHealthBarHeight - kOffsetToReticle; + float y = opts.height * (1.0f - _selectedScreenCoords.y) - _reticleHeight / 2.0f - kHealthBarHeight - kOffsetToReticle; float w = glm::clamp(_selectedObject->currentHitPoints() / static_cast(_selectedObject->hitPoints()), 0.0f, 1.0f) * kTitleBarWidth; if (_hasActions) { @@ -359,7 +359,7 @@ bool SelectionOverlay::getActionScreenCoords(int index, float &x, float &y) cons const GraphicsOptions &opts = _game->options().graphics; x = opts.width * _selectedScreenCoords.x + (static_cast(index - 1) - 0.5f) * kActionWidth + (index - 1) * kActionBarMargin; - y = opts.height * (1.0f - _selectedScreenCoords.y) - _reticleHeight / 2 - kActionHeight - kOffsetToReticle - kActionBarMargin; + y = opts.height * (1.0f - _selectedScreenCoords.y) - _reticleHeight / 2.0f - kActionHeight - kOffsetToReticle - kActionBarMargin; return true; } diff --git a/src/engine/graphics/lip/lipwriter.cpp b/src/engine/graphics/lip/lipwriter.cpp index df348aab..d5dbcd10 100644 --- a/src/engine/graphics/lip/lipwriter.cpp +++ b/src/engine/graphics/lip/lipwriter.cpp @@ -36,7 +36,7 @@ void LipWriter::save(const fs::path &path) { StreamWriter writer(lip); writer.putString("LIP V1.0"); writer.putFloat(_animation.length()); - writer.putUint32(_animation.keyframes().size()); + writer.putUint32(static_cast(_animation.keyframes().size())); for (auto &keyframe : _animation.keyframes()) { writer.putFloat(keyframe.time); writer.putByte(keyframe.shape); diff --git a/src/engine/graphics/mesh/mesh.cpp b/src/engine/graphics/mesh/mesh.cpp index c909a528..64bb0e37 100644 --- a/src/engine/graphics/mesh/mesh.cpp +++ b/src/engine/graphics/mesh/mesh.cpp @@ -34,7 +34,7 @@ Mesh::Mesh(vector vertices, vector indices, VertexAttributes at if (attributes.stride == 0) { throw invalid_argument("stride in attributes must not be zero"); } - _vertexCount = _vertices.size() / (attributes.stride / sizeof(float)); + _vertexCount = static_cast(_vertices.size()) / (attributes.stride / sizeof(float)); computeAABB(); } @@ -65,39 +65,39 @@ void Mesh::init() { if (_attributes.offCoords != -1) { glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(_attributes.offCoords)); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(static_cast(_attributes.offCoords))); } if (_attributes.offNormals != -1) { glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(_attributes.offNormals)); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(static_cast(_attributes.offNormals))); } if (_attributes.offTexCoords1 != -1) { glEnableVertexAttribArray(2); - glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(_attributes.offTexCoords1)); + glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(static_cast(_attributes.offTexCoords1))); } if (_attributes.offTexCoords2 != -1) { glEnableVertexAttribArray(3); - glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(_attributes.offTexCoords2)); + glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(static_cast(_attributes.offTexCoords2))); } if (_attributes.offTangents != -1) { glEnableVertexAttribArray(4); - glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(_attributes.offTangents)); + glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(static_cast(_attributes.offTangents))); } if (_attributes.offBitangents != -1) { glEnableVertexAttribArray(5); - glVertexAttribPointer(5, 3, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(_attributes.offBitangents)); + glVertexAttribPointer(5, 3, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(static_cast(_attributes.offBitangents))); } if (_attributes.offTanSpaceNormals != -1) { glEnableVertexAttribArray(6); - glVertexAttribPointer(6, 3, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(_attributes.offTanSpaceNormals)); + glVertexAttribPointer(6, 3, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(static_cast(_attributes.offTanSpaceNormals))); } if (_attributes.offBoneIndices != -1) { glEnableVertexAttribArray(7); - glVertexAttribPointer(7, 4, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(_attributes.offBoneIndices)); + glVertexAttribPointer(7, 4, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(static_cast(_attributes.offBoneIndices))); } if (_attributes.offBoneWeights != -1) { glEnableVertexAttribArray(8); - glVertexAttribPointer(8, 4, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(_attributes.offBoneWeights)); + glVertexAttribPointer(8, 4, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast(static_cast(_attributes.offBoneWeights))); } glBindVertexArray(0); @@ -151,13 +151,13 @@ void Mesh::ensureTriangles() const { void Mesh::drawTriangles(int startFace, int numFaces) { ensureTriangles(); glBindVertexArray(_vaoId); - glDrawElements(GL_TRIANGLES, 3 * numFaces, GL_UNSIGNED_SHORT, reinterpret_cast(3 * startFace * sizeof(uint16_t))); + glDrawElements(GL_TRIANGLES, 3 * numFaces, GL_UNSIGNED_SHORT, reinterpret_cast(3ll * startFace * sizeof(uint16_t))); } void Mesh::drawTrianglesInstanced(int startFace, int numFaces, int count) { ensureTriangles(); glBindVertexArray(_vaoId); - glDrawElementsInstanced(GL_TRIANGLES, 3 * numFaces, GL_UNSIGNED_SHORT, reinterpret_cast(3 * startFace * sizeof(uint16_t)), count); + glDrawElementsInstanced(GL_TRIANGLES, 3 * numFaces, GL_UNSIGNED_SHORT, reinterpret_cast(3ll * startFace * sizeof(uint16_t)), count); } vector Mesh::getTriangleCoords(int faceIdx) const { @@ -188,21 +188,21 @@ vector Mesh::getTriangleAttributes(int faceIdx, int offset) const { } if (offset == -1) return vector(); - auto a = getVertexAttribute(_indices[3 * faceIdx + 0], offset); - auto b = getVertexAttribute(_indices[3 * faceIdx + 1], offset); - auto c = getVertexAttribute(_indices[3 * faceIdx + 2], offset); + auto a = getVertexAttribute(_indices[3ll * faceIdx + 0], offset); + auto b = getVertexAttribute(_indices[3ll * faceIdx + 1], offset); + auto c = getVertexAttribute(_indices[3ll * faceIdx + 2], offset); return vector { a, b, c }; } template <> glm::vec2 Mesh::getVertexAttribute(uint16_t vertexIdx, int offset) const { - return glm::make_vec2(&_vertices[(vertexIdx * _attributes.stride + offset) / sizeof(float)]); + return glm::make_vec2(&_vertices[(static_cast(vertexIdx) * _attributes.stride + offset) / sizeof(float)]); } template <> glm::vec3 Mesh::getVertexAttribute(uint16_t vertexIdx, int offset) const { - return glm::make_vec3(&_vertices[(vertexIdx * _attributes.stride + offset) / sizeof(float)]); + return glm::make_vec3(&_vertices[(static_cast(vertexIdx) * _attributes.stride + offset) / sizeof(float)]); } } // namespace graphics diff --git a/src/engine/graphics/texture/tgawriter.cpp b/src/engine/graphics/texture/tgawriter.cpp index dad8d20c..c3606bea 100644 --- a/src/engine/graphics/texture/tgawriter.cpp +++ b/src/engine/graphics/texture/tgawriter.cpp @@ -51,7 +51,7 @@ void TgaWriter::save(ostream &out, bool compress) { // Write Header - uint8_t header[kHeaderSize]; + uint8_t header[kHeaderSize] { 0 }; header[0] = 0; // ID length header[1] = 0; // color map type header[2] = static_cast(dataType); @@ -77,7 +77,7 @@ void TgaWriter::save(ostream &out, bool compress) { writeRLE(&pixels[offset], depth, out); } } else { - out.write(reinterpret_cast(&pixels[0]), totalHeight * scanlineSize); + out.write(reinterpret_cast(&pixels[0]), static_cast(totalHeight) * scanlineSize); } } @@ -108,7 +108,7 @@ vector TgaWriter::getTexturePixels(bool compress, TGADataType &dataType int numLayers = static_cast(_texture->layers().size()); int numPixels = _texture->width() * _texture->height(); int numPixelsTotal = numLayers * numPixels; - result.resize(numPixelsTotal * depth / 8); + result.resize(static_cast(numPixelsTotal) * depth / 8); uint8_t *pixels = &result[0]; for (int i = 0; i < numLayers; ++i) { @@ -137,10 +137,10 @@ vector TgaWriter::getTexturePixels(bool compress, TGADataType &dataType } break; case PixelFormat::BGR: - memcpy(pixels, mipMapPtr, 3 * numPixels); + memcpy(pixels, mipMapPtr, 3ll * numPixels); break; case PixelFormat::BGRA: - memcpy(pixels, mipMapPtr, 4 * numPixels); + memcpy(pixels, mipMapPtr, 4ll * numPixels); break; case PixelFormat::DXT1: { vector decompPixels(numPixels); @@ -194,7 +194,7 @@ void TgaWriter::writeRLE(uint8_t *pixels, int depth, ostream &out) { } else { if (direct) { out.put(direct - 1); - out.write(reinterpret_cast(from), bytes * direct); + out.write(reinterpret_cast(from), bytes * static_cast(direct)); from = pixels; direct = 0; repeat = 1; @@ -203,14 +203,14 @@ void TgaWriter::writeRLE(uint8_t *pixels, int depth, ostream &out) { } } if (repeat == 128) { - out.put(255); + out.put(static_cast(255)); out.write(reinterpret_cast(from), bytes); from = pixels + bytes; direct = 0; repeat = 0; } else if (direct == 128) { out.put(127); - out.write(reinterpret_cast(from), bytes * direct); + out.write(reinterpret_cast(from), bytes * static_cast(direct)); from = pixels + bytes; direct = 0; repeat = 0; @@ -223,7 +223,7 @@ void TgaWriter::writeRLE(uint8_t *pixels, int depth, ostream &out) { out.write(reinterpret_cast(from), bytes); } else { out.put(direct); - out.write(reinterpret_cast(from), bytes * (direct + 1)); + out.write(reinterpret_cast(from), bytes * static_cast(direct + 1)); } } diff --git a/src/engine/gui/control/control.cpp b/src/engine/gui/control/control.cpp index a27e5e8d..dbbdd02c 100644 --- a/src/engine/gui/control/control.cpp +++ b/src/engine/gui/control/control.cpp @@ -435,8 +435,8 @@ void Control::drawText(const vector &lines, const glm::ivec2 &offset, co glm::vec3 color((_focus && _hilight) ? _hilight->color : _text.color); for (auto &line : lines) { - linePosition.x = position.x + offset.x; - linePosition.y = position.y + offset.y; + linePosition.x = static_cast(position.x + offset.x); + linePosition.y = static_cast(position.y + offset.y); _text.font->draw(line, linePosition, color, gravity); position.y += static_cast(_text.font->height()); } diff --git a/src/engine/gui/control/imagebutton.cpp b/src/engine/gui/control/imagebutton.cpp index 7c47949e..d25a3822 100644 --- a/src/engine/gui/control/imagebutton.cpp +++ b/src/engine/gui/control/imagebutton.cpp @@ -120,8 +120,8 @@ void ImageButton::drawIcon( if (!iconText.empty()) { glm::vec3 position(0.0f); - position.x = offset.x + _extent.left + _extent.height; - position.y = offset.y + _extent.top + _extent.height - 0.5f * _iconFont->height(); + position.x = static_cast(offset.x + _extent.left + _extent.height); + position.y = static_cast(offset.y + _extent.top + _extent.height - 0.5f * _iconFont->height()); _iconFont->draw(iconText, position, color, TextGravity::LeftCenter); } } diff --git a/src/engine/scene/node/lightnode.cpp b/src/engine/scene/node/lightnode.cpp index 1f232c43..406b39c8 100644 --- a/src/engine/scene/node/lightnode.cpp +++ b/src/engine/scene/node/lightnode.cpp @@ -70,8 +70,8 @@ void LightSceneNode::drawLensFlares(const ModelNode::LensFlare &flare) { glm::vec4 lightPos(_absTransform[3]); glm::vec4 lightPosNdc(camera->projection() * camera->view() * lightPos); - float w = _sceneGraph->options().width; - float h = _sceneGraph->options().height; + float w = static_cast(_sceneGraph->options().width); + float h = static_cast(_sceneGraph->options().height); glm::vec3 lightPosScreen(glm::vec3(lightPosNdc) / lightPosNdc.w); lightPosScreen *= 0.5f; diff --git a/src/tools/pthtool.cpp b/src/tools/pthtool.cpp index eeb39c32..b1c9cbdf 100644 --- a/src/tools/pthtool.cpp +++ b/src/tools/pthtool.cpp @@ -98,7 +98,7 @@ void PthTool::toPTH(const fs::path &path, const fs::path &destPath) { // Write binary PTH string filename(path.filename().string()); - int lastDotIdx = filename.find_last_of('.'); + size_t lastDotIdx = filename.find_last_of('.'); if (lastDotIdx != -1) { filename = filename.substr(0, lastDotIdx); } @@ -165,7 +165,7 @@ void PthTool::toASCII(const fs::path &path, const fs::path &destPath) { // Write ASCII PTH string filename(path.filename().string()); - int lastDotIdx = filename.find_last_of('.'); + size_t lastDotIdx = filename.find_last_of('.'); if (lastDotIdx != -1) { filename = filename.substr(0, lastDotIdx); }