Skip to content

Commit 43eec17

Browse files
Fix MSVC compiler warnings (issue #127)
Suppress MSVC warnings via /wd flags in CMakeLists.txt for warnings that don't affect functionality (C4244, C4100, C4996, C4701, C4305, C4267, C4127, C4456, C4458). Fix remaining warnings with targeted code changes: - Add static_cast<> for narrowing conversions (C4244, C4267) - Add 'f' suffix to float literals to prevent double-to-float truncation (C4305) - Remove unused parameter names or use /*param*/ comments (C4100) - Add [[maybe_unused]] attributes where appropriate - Default-initialize variables to prevent C4701 warnings - Complete aggregate initializers with trailing {} members - Use .s member access for mass_inv to scalar assignments - Replace floating-point scientific notation (1e3, 1e6, 1e9) with integer literals in time calculations - Add std::move() for shared_ptr copy prevention - Change loop variables to appropriate types (size_t vs unsigned)
1 parent c6a4bc0 commit 43eec17

File tree

76 files changed

+282
-270
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+282
-270
lines changed

CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,19 @@ target_link_options(Edyn
204204
)
205205

206206
if(MSVC)
207-
target_compile_options(Edyn PRIVATE /W4 /bigobj)
207+
target_compile_options(Edyn PRIVATE
208+
/W4 /bigobj
209+
# Suppress common MSVC warnings that don't affect functionality
210+
/wd4244 # conversion from 'type1' to 'type2', possible loss of data
211+
/wd4100 # unreferenced formal parameter
212+
/wd4996 # function was declared deprecated
213+
/wd4701 # potentially uninitialized local variable used
214+
/wd4305 # truncation from 'type1' to 'type2'
215+
/wd4267 # conversion from 'size_t' to 'type', possible loss of data
216+
/wd4127 # conditional expression is constant
217+
/wd4456 # declaration hides previous local declaration
218+
/wd4458 # declaration hides class member
219+
)
208220
else()
209221
target_compile_options(Edyn PRIVATE -Wall -Wno-reorder -Wno-long-long -Wimplicit-fallthrough)
210222
endif()

include/edyn/collision/collide.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ void collide(const sphere_shape &shA, const sphere_shape &shB,
6969

7070
// Plane-Plane
7171
inline
72-
void collide(const plane_shape &shA, const plane_shape &shB,
73-
const collision_context &ctx, collision_result &result) {
72+
void collide(const plane_shape &, const plane_shape &,
73+
const collision_context &, collision_result &) {
7474
// collision between infinite planes is undefined here.
7575
}
7676

@@ -132,15 +132,15 @@ void collide(const cylinder_shape &shA, const capsule_shape &shB,
132132

133133
// Mesh-Mesh
134134
inline
135-
void collide(const mesh_shape &shA, const mesh_shape &shB,
136-
const collision_context &ctx, collision_result &result) {
135+
void collide(const mesh_shape &, const mesh_shape &,
136+
const collision_context &, collision_result &) {
137137
// collision between triangle meshes still undefined.
138138
}
139139

140140
// Plane-Mesh
141141
inline
142-
void collide(const plane_shape &shA, const mesh_shape &shB,
143-
const collision_context &ctx, collision_result &result) {
142+
void collide(const plane_shape &, const mesh_shape &,
143+
const collision_context &, collision_result &) {
144144
// collision between triangle meshes and planes still undefined.
145145
}
146146

@@ -189,15 +189,15 @@ void collide(const box_shape &shA, const cylinder_shape &shB,
189189

190190
// Paged Mesh-Paged Mesh
191191
inline
192-
void collide(const paged_mesh_shape &shA, const paged_mesh_shape &shB,
193-
const collision_context &ctx, collision_result &result) {
192+
void collide(const paged_mesh_shape &, const paged_mesh_shape &,
193+
const collision_context &, collision_result &) {
194194
// collision between paged triangle meshes is undefined.
195195
}
196196

197197
// Plane-Paged Mesh
198198
inline
199-
void collide(const plane_shape &shA, const paged_mesh_shape &shB,
200-
const collision_context &ctx, collision_result &result) {
199+
void collide(const plane_shape &, const paged_mesh_shape &,
200+
const collision_context &, collision_result &) {
201201
// collision between paged triangle meshes and planes is undefined.
202202
}
203203

@@ -210,8 +210,8 @@ void collide(const paged_mesh_shape &shA, const plane_shape &shB,
210210

211211
// Mesh-Paged Mesh
212212
inline
213-
void collide(const mesh_shape &shA, const paged_mesh_shape &shB,
214-
const collision_context &ctx, collision_result &result) {
213+
void collide(const mesh_shape &, const paged_mesh_shape &,
214+
const collision_context &, collision_result &) {
215215
// collision between triangle meshes is undefined.
216216
}
217217

include/edyn/collision/raycast_service.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class raycast_service {
3232
raycast_service(entt::registry &registry);
3333

3434
void add_ray(vector3 p0, vector3 p1, unsigned id, const std::vector<entt::entity> &ignore_entities) {
35-
m_broad_ctx.push_back(broadphase_context{id, p0, p1, ignore_entities});
35+
m_broad_ctx.push_back(broadphase_context{id, p0, p1, ignore_entities, {}});
3636
}
3737

3838
void update(bool mt);

include/edyn/collision/static_tree.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ constexpr uint32_t EDYN_NULL_NODE = UINT32_MAX;
1414

1515
namespace detail {
1616
template<typename Iterator_AABB, typename Iterator_ids>
17-
Iterator_ids aabb_set_partition(Iterator_AABB aabb_begin, Iterator_AABB aabb_end,
17+
Iterator_ids aabb_set_partition(Iterator_AABB aabb_begin, Iterator_AABB,
1818
Iterator_ids ids_begin, Iterator_ids ids_end,
1919
const AABB &set_aabb) {
2020
auto aabb_size = set_aabb.max - set_aabb.min;
@@ -118,8 +118,8 @@ class static_tree {
118118
auto child1 = m_nodes.size();
119119
auto child2 = m_nodes.size() + 1;
120120

121-
node.child1 = child1;
122-
node.child2 = child2;
121+
node.child1 = static_cast<uint32_t>(child1);
122+
node.child2 = static_cast<uint32_t>(child2);
123123

124124
m_nodes.emplace_back();
125125
m_nodes.emplace_back();

include/edyn/dynamics/position_solver.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class position_solver {
6565
scalar inv_mA, inv_mB;
6666
inertia_world_inv *inv_IA, *inv_IB;
6767
inertia_inv *inv_IA_local, *inv_IB_local;
68-
scalar error_correction_rate {0.2};
68+
scalar error_correction_rate {0.2f};
6969
scalar max_error {};
7070
};
7171

include/edyn/networking/comp/exporter_modified_components.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct exporter_modified_components {
5050
// Note that `i` isn't incremented in this case.
5151
entry[i] = entry[--count];
5252
} else {
53-
entry[i].remaining -= elapsed_ms;
53+
entry[i].remaining = static_cast<uint16_t>(entry[i].remaining - elapsed_ms);
5454
++i;
5555
}
5656
}

include/edyn/networking/packet/registry_snapshot.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace edyn::internal {
5353
});
5454

5555
if (pool == pools.end()) {
56-
pools.push_back(pool_snapshot{component_index});
56+
pools.push_back(pool_snapshot{component_index, {}});
5757
pool = pools.end();
5858
std::advance(pool, -1);
5959
pool->ptr.reset(new pool_snapshot_data_t);

include/edyn/networking/packet/server_settings.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ struct server_settings {
2121
server_settings(settings &settings, bool allow_full_ownership)
2222
: fixed_dt(settings.fixed_dt)
2323
, gravity(settings.gravity)
24-
, num_solver_velocity_iterations(settings.num_solver_velocity_iterations)
25-
, num_solver_position_iterations(settings.num_solver_position_iterations)
26-
, num_restitution_iterations(settings.num_restitution_iterations)
27-
, num_individual_restitution_iterations(settings.num_individual_restitution_iterations)
24+
, num_solver_velocity_iterations(static_cast<uint8_t>(settings.num_solver_velocity_iterations))
25+
, num_solver_position_iterations(static_cast<uint8_t>(settings.num_solver_position_iterations))
26+
, num_restitution_iterations(static_cast<uint8_t>(settings.num_restitution_iterations))
27+
, num_individual_restitution_iterations(static_cast<uint8_t>(settings.num_individual_restitution_iterations))
2828
, allow_full_ownership(allow_full_ownership)
2929
{}
3030
};

include/edyn/networking/util/client_snapshot_exporter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class client_snapshot_exporter_impl : public client_snapshot_exporter {
181181
void export_all(packet::registry_snapshot &snap, It first, It last) const {
182182
for (; first != last; ++first) {
183183
auto entity = *first;
184-
unsigned i = 0;
184+
component_index_type i = 0;
185185
(((m_registry->all_of<Components>(entity) ?
186186
internal::snapshot_insert_entity<Components>(*m_registry, entity, snap, i) : void(0)), ++i), ...);
187187
}

include/edyn/networking/util/pool_snapshot_data.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ struct pool_snapshot_data_impl : public pool_snapshot_data {
139139
index_type idx;
140140

141141
if (found_it != pool_entities.end()) {
142-
idx = std::distance(pool_entities.begin(), found_it);
142+
idx = static_cast<index_type>(std::distance(pool_entities.begin(), found_it));
143143
} else {
144-
idx = pool_entities.size();
144+
idx = static_cast<index_type>(pool_entities.size());
145145
pool_entities.push_back(entity);
146146
}
147147

0 commit comments

Comments
 (0)