Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Visual Studio and XCode Warnings #618

Merged
merged 24 commits into from
Sep 17, 2018

Conversation

madebr
Copy link
Contributor

@madebr madebr commented Aug 30, 2018

This pr fixes all Visual Studio and XCode warnings created by our code.
Most warnings were caused by:

  • narrowing data types;
  • implicitly converting floats to integers and vice versa; and
  • missing PDB files (=debug symbols)

Warnings remaining on Visual Studio:

  • There is still a warning caused by Bullet, which is fixed upstream and will be gone in the next bullet release.
    I've explicitly disabled these warnings using #pragma's. This commit can be reverted once a fixed version of bullet is released.
  • Some linking warnings which will be dealt with in a next pr or by the upstream conan repositories.
  • Warnings by microprofile. A pull request has been submitted.

Also:

  • I've removed all #pragma once's
  • I've modified the ci to additionally build openrw on llvm.
  • Added configuration option to build in parallel using Visual Studio. This reduced the time for a rebuild of openrw from 5'25" to 2'40".
  • fix warning: missing braces around initializer [-Wmissing-braces] warnings of xcode

Check out the green at https://my.cdash.org/index.php?project=OpenRW

rwcore/gl/DrawBuffer.cpp Outdated Show resolved Hide resolved
@madebr
Copy link
Contributor Author

madebr commented Aug 30, 2018

clang emits another warning about an unused private field: m_errorTexture in rwengine/src/render/ObjectRenderer.hpp. Suggestions?

EDIT:
added a setErrorTexture method in debug mode.
EDIT2:
and removed.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

;)

@@ -19,7 +19,7 @@ AIGraph::~AIGraph() {

void AIGraph::createPathNodes(const glm::vec3& position,
const glm::quat& rotation, PathData& path) {
size_t startIndex = nodes.size();
std::uint32_t startIndex = static_cast<std::uint32_t>(nodes.size());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto

@@ -248,7 +248,7 @@ struct InputData {
/// to buffer.
static int read_packet(void* opaque, uint8_t* buf, int buf_size) {
auto* input = reinterpret_cast<InputData*>(opaque);
buf_size = FFMIN(buf_size, input->size);
buf_size = FFMIN(buf_size, static_cast<int>(input->size));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here can be used std::fmin instead of this ugly macro. IIRC it's clang warn.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::fmin is for floating points. That would create new warnings.
std::min has only templates for arguments of the same type.

@@ -58,15 +58,15 @@ WaterRenderer::WaterRenderer(GameRenderer* renderer) {
void WaterRenderer::setWaterTable(const float* waterHeights, const unsigned int nHeights,
const uint8_t* tiles, const unsigned int nTiles) {
// Determine the dimensions of the input tiles
int edgeNum = sqrt(nTiles);
unsigned int edgeNum = static_cast<unsigned int>(sqrt(nTiles));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto

float tileSize = WATER_WORLD_SIZE / edgeNum;
glm::vec2 wO{-WATER_WORLD_SIZE / 2.f, -WATER_WORLD_SIZE / 2.f};

std::vector<glm::vec3> vertexData;

for (int x = 0; x < edgeNum; x++) {
for (unsigned int x = 0; x < edgeNum; x++) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (auto x = 0u; x < edgeNum; x++) {

int xi = x * WATER_HQ_DATA_SIZE;
for (int y = 0; y < edgeNum; y++) {
for (unsigned int y = 0; y < edgeNum; y++) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (auto y = 0u; y < edgeNum; y++) {

@@ -14,15 +13,15 @@ class IMGArchiveModel : public QAbstractListModel {
: QAbstractListModel(parent), archive(archive) {
}

virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use override there's no need for virtual.

@madebr madebr force-pushed the fix_msvc_warnings branch 5 times, most recently from efc4872 to cc48a70 Compare August 31, 2018 15:03
@@ -32,9 +32,9 @@ class ViewFrustum {
}

void update(const glm::mat4& proj) {
for (size_t i = 0; i < 6; ++i) {
for (unsigned int i = 0; i < 6; ++i) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (auto i = 0u; i < 6; ++i) {

@@ -284,7 +284,7 @@ void TextRenderer::renderText(const TextRenderer::TextInfo& ti,
// will need to be wrapped
if (ti.wrapX > 0 && coord.x > 0.f && !std::isspace(c)) {
auto wend = std::find_if(std::begin(text) + i, std::end(text),
[](char x) { return std::isspace(x); });
[](GameStringChar c) { return std::isspace(c); });
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be here used auto?

@madebr madebr force-pushed the fix_msvc_warnings branch 3 times, most recently from a7bee5e to 26a5d50 Compare September 1, 2018 01:17
@madebr madebr changed the title Fix Visual Studio Warnings Fix Visual Studio and XCode Warnings Sep 1, 2018
@madebr madebr force-pushed the fix_msvc_warnings branch 7 times, most recently from 6fe0bdd to 413cb50 Compare September 1, 2018 16:59
.appveyor.yml Outdated
@@ -22,7 +22,8 @@ platform:

configuration:
# - Debug
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused configurations

if(CC)
list(APPEND _CONGIGURE_OPTIONS "-DCMAKE_C_COMPILER=${CC}")
endif()
if(CXX)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't CMake respect the environment variables already?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, and ctest does too. I overcomplicated things because at the start of a travis build, there is an explicit export CC=gcc and export CXX=g++

if(MSVC_PARALLEL_BUILD)
target_compile_options(rw_interface
INTERFACE
"/MP"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be configurable? Can we put it in the default flags above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a convenience for me to see what source emitted the bullet warnings. These warnings messages did not contain any reference to what source included them. But I guess its use is gone.

glVertexAttribPointer(vaoindex, at.size, at.type, GL_TRUE, at.stride,
reinterpret_cast<GLvoid*>(at.offset));
glVertexAttribPointer(vaoindex, static_cast<GLint>(at.size), at.type, GL_TRUE, at.stride,
reinterpret_cast<void*>(static_cast<size_t>(at.offset)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make offset size_t?

@@ -259,7 +259,7 @@ GeometryPtr LoaderDFF::readGeometry(const RWBStream &stream) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, geom->EBO);

size_t icount = std::accumulate(
geom->subgeom.begin(), geom->subgeom.end(), 0u,
geom->subgeom.begin(), geom->subgeom.end(), static_cast<size_t>(0u),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size_t{0u} is shorter

private:
GameWorld* m_world;
const ViewCamera& m_camera;
float m_renderAlpha;
GLuint m_errorTexture;
#ifdef RW_DEBUG
GLuint m_errorTexture = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks completely unused

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it was. Removed.

@madebr madebr force-pushed the fix_msvc_warnings branch 4 times, most recently from e56bdab to 5df0d05 Compare September 2, 2018 00:26
rwgame/GameConfig.cpp Outdated Show resolved Hide resolved
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@madebr
Copy link
Contributor Author

madebr commented Sep 15, 2018

I've disabled SIMD for glm by setting the compile definition GLM_FORCE_PURE.
An alternative is to not define it and use GLM_RELAXED_CONSTEXPR in our codebase instead of constexpr/const (when using glm data types).

@danhedron
Copy link
Member

LGTM

@danhedron danhedron merged commit 5951b97 into rwengine:master Sep 17, 2018
@madebr madebr deleted the fix_msvc_warnings branch September 17, 2018 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants