Fix all MSVC compilation warnings

This commit is contained in:
Vsevolod Kremianskii 2021-06-13 11:24:20 +07:00
parent 452baa3a16
commit 32be20aeb3
11 changed files with 42 additions and 42 deletions

View file

@ -114,7 +114,7 @@ private:
// Damage
std::vector<std::shared_ptr<DamageEffect>> getDamageEffects(std::shared_ptr<Creature> damager, bool offHand = false, float multiplier = 1.0f) const;
std::vector<std::shared_ptr<DamageEffect>> getDamageEffects(std::shared_ptr<Creature> damager, bool offHand = false, int multiplier = 1) const;
// END Damage

View file

@ -29,7 +29,7 @@ namespace reone {
namespace game {
vector<shared_ptr<DamageEffect>> Combat::getDamageEffects(shared_ptr<Creature> damager, bool offHand, float multiplier) const {
vector<shared_ptr<DamageEffect>> Combat::getDamageEffects(shared_ptr<Creature> damager, bool offHand, int multiplier) const {
shared_ptr<Item> weapon(damager->getEquippedItem(offHand ? InventorySlot::leftWeapon : InventorySlot::rightWeapon));
int amount = 0;
auto type = DamageType::Bludgeoning;

View file

@ -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<float>(_binding.lblBarkText->extent().width) + 1;
int lineCount = static_cast<int>(textWidth / static_cast<float>(_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();

View file

@ -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<uint32_t>(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<float>(_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<float>(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;
}

View file

@ -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<uint32_t>(_animation.keyframes().size()));
for (auto &keyframe : _animation.keyframes()) {
writer.putFloat(keyframe.time);
writer.putByte(keyframe.shape);

View file

@ -34,7 +34,7 @@ Mesh::Mesh(vector<float> vertices, vector<uint16_t> 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<int>(_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<void *>(_attributes.offCoords));
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(static_cast<size_t>(_attributes.offCoords)));
}
if (_attributes.offNormals != -1) {
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(_attributes.offNormals));
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(static_cast<size_t>(_attributes.offNormals)));
}
if (_attributes.offTexCoords1 != -1) {
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(_attributes.offTexCoords1));
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(static_cast<size_t>(_attributes.offTexCoords1)));
}
if (_attributes.offTexCoords2 != -1) {
glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(_attributes.offTexCoords2));
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(static_cast<size_t>(_attributes.offTexCoords2)));
}
if (_attributes.offTangents != -1) {
glEnableVertexAttribArray(4);
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(_attributes.offTangents));
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(static_cast<size_t>(_attributes.offTangents)));
}
if (_attributes.offBitangents != -1) {
glEnableVertexAttribArray(5);
glVertexAttribPointer(5, 3, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(_attributes.offBitangents));
glVertexAttribPointer(5, 3, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(static_cast<size_t>(_attributes.offBitangents)));
}
if (_attributes.offTanSpaceNormals != -1) {
glEnableVertexAttribArray(6);
glVertexAttribPointer(6, 3, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(_attributes.offTanSpaceNormals));
glVertexAttribPointer(6, 3, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(static_cast<size_t>(_attributes.offTanSpaceNormals)));
}
if (_attributes.offBoneIndices != -1) {
glEnableVertexAttribArray(7);
glVertexAttribPointer(7, 4, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(_attributes.offBoneIndices));
glVertexAttribPointer(7, 4, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(static_cast<size_t>(_attributes.offBoneIndices)));
}
if (_attributes.offBoneWeights != -1) {
glEnableVertexAttribArray(8);
glVertexAttribPointer(8, 4, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(_attributes.offBoneWeights));
glVertexAttribPointer(8, 4, GL_FLOAT, GL_FALSE, _attributes.stride, reinterpret_cast<void *>(static_cast<size_t>(_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<void *>(3 * startFace * sizeof(uint16_t)));
glDrawElements(GL_TRIANGLES, 3 * numFaces, GL_UNSIGNED_SHORT, reinterpret_cast<void *>(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<void *>(3 * startFace * sizeof(uint16_t)), count);
glDrawElementsInstanced(GL_TRIANGLES, 3 * numFaces, GL_UNSIGNED_SHORT, reinterpret_cast<void *>(3ll * startFace * sizeof(uint16_t)), count);
}
vector<glm::vec3> Mesh::getTriangleCoords(int faceIdx) const {
@ -188,21 +188,21 @@ vector<T> Mesh::getTriangleAttributes(int faceIdx, int offset) const {
}
if (offset == -1) return vector<T>();
auto a = getVertexAttribute<T>(_indices[3 * faceIdx + 0], offset);
auto b = getVertexAttribute<T>(_indices[3 * faceIdx + 1], offset);
auto c = getVertexAttribute<T>(_indices[3 * faceIdx + 2], offset);
auto a = getVertexAttribute<T>(_indices[3ll * faceIdx + 0], offset);
auto b = getVertexAttribute<T>(_indices[3ll * faceIdx + 1], offset);
auto c = getVertexAttribute<T>(_indices[3ll * faceIdx + 2], offset);
return vector<T> { 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<size_t>(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<size_t>(vertexIdx) * _attributes.stride + offset) / sizeof(float)]);
}
} // namespace graphics

View file

@ -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<uint8_t>(dataType);
@ -77,7 +77,7 @@ void TgaWriter::save(ostream &out, bool compress) {
writeRLE(&pixels[offset], depth, out);
}
} else {
out.write(reinterpret_cast<char *>(&pixels[0]), totalHeight * scanlineSize);
out.write(reinterpret_cast<char *>(&pixels[0]), static_cast<size_t>(totalHeight) * scanlineSize);
}
}
@ -108,7 +108,7 @@ vector<uint8_t> TgaWriter::getTexturePixels(bool compress, TGADataType &dataType
int numLayers = static_cast<int>(_texture->layers().size());
int numPixels = _texture->width() * _texture->height();
int numPixelsTotal = numLayers * numPixels;
result.resize(numPixelsTotal * depth / 8);
result.resize(static_cast<size_t>(numPixelsTotal) * depth / 8);
uint8_t *pixels = &result[0];
for (int i = 0; i < numLayers; ++i) {
@ -137,10 +137,10 @@ vector<uint8_t> 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<unsigned long> 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<char *>(from), bytes * direct);
out.write(reinterpret_cast<char *>(from), bytes * static_cast<size_t>(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<char>(255));
out.write(reinterpret_cast<char *>(from), bytes);
from = pixels + bytes;
direct = 0;
repeat = 0;
} else if (direct == 128) {
out.put(127);
out.write(reinterpret_cast<char *>(from), bytes * direct);
out.write(reinterpret_cast<char *>(from), bytes * static_cast<size_t>(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<char *>(from), bytes);
} else {
out.put(direct);
out.write(reinterpret_cast<char *>(from), bytes * (direct + 1));
out.write(reinterpret_cast<char *>(from), bytes * static_cast<size_t>(direct + 1));
}
}

View file

@ -435,8 +435,8 @@ void Control::drawText(const vector<string> &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<float>(position.x + offset.x);
linePosition.y = static_cast<float>(position.y + offset.y);
_text.font->draw(line, linePosition, color, gravity);
position.y += static_cast<int>(_text.font->height());
}

View file

@ -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<float>(offset.x + _extent.left + _extent.height);
position.y = static_cast<float>(offset.y + _extent.top + _extent.height - 0.5f * _iconFont->height());
_iconFont->draw(iconText, position, color, TextGravity::LeftCenter);
}
}

View file

@ -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<float>(_sceneGraph->options().width);
float h = static_cast<float>(_sceneGraph->options().height);
glm::vec3 lightPosScreen(glm::vec3(lightPosNdc) / lightPosNdc.w);
lightPosScreen *= 0.5f;

View file

@ -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);
}