Skip to content

Commit 8f22f3f

Browse files
committed
increased warning level to W4 on MSVC for #816
1 parent 6336023 commit 8f22f3f

File tree

10 files changed

+29
-31
lines changed

10 files changed

+29
-31
lines changed

src/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ if (MSVC)
135135
# Atomics are still considered experimental in Visual Studio 17.8
136136
target_compile_options(box2d PRIVATE /experimental:c11atomics)
137137

138+
# All warnings
139+
target_compile_options(box2d PRIVATE /W4)
140+
138141
if (BOX2D_AVX2)
139142
message(STATUS "Box2D using AVX2")
140143
target_compile_definitions(box2d PRIVATE BOX2D_AVX2)

src/body.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ b2BodyId b2CreateBody( b2WorldId worldId, const b2BodyDef* def )
309309

310310
bool b2IsBodyAwake( b2World* world, b2Body* body )
311311
{
312+
B2_MAYBE_UNUSED( world );
312313
return body->setIndex == b2_awakeSet;
313314
}
314315

src/dynamic_tree.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ static int b2ComputeHeight( const b2DynamicTree* tree, int32_t nodeId )
871871

872872
int32_t height1 = b2ComputeHeight( tree, node->child1 );
873873
int32_t height2 = b2ComputeHeight( tree, node->child2 );
874-
return 1 + b2MaxInt16( height1, height2 );
874+
return 1 + b2MaxInt( height1, height2 );
875875
}
876876

877877
int b2DynamicTree_ComputeHeight( const b2DynamicTree* tree )
@@ -930,8 +930,8 @@ static void b2ValidateMetrics( const b2DynamicTree* tree, int32_t index )
930930

931931
const b2TreeNode* node = tree->nodes + index;
932932

933-
int32_t child1 = node->child1;
934-
int32_t child2 = node->child2;
933+
int child1 = node->child1;
934+
int child2 = node->child2;
935935

936936
if ( b2IsLeaf( node ) )
937937
{
@@ -944,10 +944,9 @@ static void b2ValidateMetrics( const b2DynamicTree* tree, int32_t index )
944944
B2_ASSERT( 0 <= child1 && child1 < tree->nodeCapacity );
945945
B2_ASSERT( 0 <= child2 && child2 < tree->nodeCapacity );
946946

947-
int32_t height1 = tree->nodes[child1].height;
948-
int32_t height2 = tree->nodes[child2].height;
949-
int32_t height;
950-
height = 1 + b2MaxInt16( height1, height2 );
947+
int height1 = tree->nodes[child1].height;
948+
int height2 = tree->nodes[child2].height;
949+
int height = 1 + b2MaxInt( height1, height2 );
951950
B2_ASSERT( node->height == height );
952951

953952
// b2AABB aabb = b2AABB_Union(tree->nodes[child1].aabb, tree->nodes[child2].aabb);
@@ -1000,8 +999,8 @@ void b2DynamicTree_Validate( const b2DynamicTree* tree )
1000999

10011000
int32_t b2DynamicTree_GetMaxBalance( const b2DynamicTree* tree )
10021001
{
1003-
int32_t maxBalance = 0;
1004-
for ( int32_t i = 0; i < tree->nodeCapacity; ++i )
1002+
int maxBalance = 0;
1003+
for ( int i = 0; i < tree->nodeCapacity; ++i )
10051004
{
10061005
const b2TreeNode* node = tree->nodes + i;
10071006
if ( node->height <= 1 )
@@ -1011,9 +1010,9 @@ int32_t b2DynamicTree_GetMaxBalance( const b2DynamicTree* tree )
10111010

10121011
B2_ASSERT( b2IsLeaf( node ) == false );
10131012

1014-
int32_t child1 = node->child1;
1015-
int32_t child2 = node->child2;
1016-
int32_t balance = b2AbsFloat( tree->nodes[child2].height - tree->nodes[child1].height );
1013+
int child1 = node->child1;
1014+
int child2 = node->child2;
1015+
int balance = b2AbsInt( tree->nodes[child2].height - tree->nodes[child1].height );
10171016
maxBalance = b2MaxInt( maxBalance, balance );
10181017
}
10191018

@@ -1022,11 +1021,11 @@ int32_t b2DynamicTree_GetMaxBalance( const b2DynamicTree* tree )
10221021

10231022
void b2DynamicTree_RebuildBottomUp( b2DynamicTree* tree )
10241023
{
1025-
int32_t* nodes = b2Alloc( tree->nodeCount * sizeof( int32_t ) );
1026-
int32_t count = 0;
1024+
int* nodes = b2Alloc( tree->nodeCount * sizeof( int ) );
1025+
int count = 0;
10271026

10281027
// Build array of leaves. Free the rest.
1029-
for ( int32_t i = 0; i < tree->nodeCapacity; ++i )
1028+
for ( int i = 0; i < tree->nodeCapacity; ++i )
10301029
{
10311030
if ( tree->nodes[i].height < 0 )
10321031
{

src/hull.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ b2Hull b2ComputeHull( const b2Vec2* points, int count )
9494
return hull;
9595
}
9696

97-
count = b2MinFloat( count, b2_maxPolygonVertices );
97+
count = b2MinInt( count, b2_maxPolygonVertices );
9898

9999
b2AABB aabb = { { FLT_MAX, FLT_MAX }, { -FLT_MAX, -FLT_MAX } };
100100

src/joint.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ typedef struct b2Joint
4747
int islandPrev;
4848
int islandNext;
4949

50-
// This is monotonically advanced when a body is allocated in this slot
51-
// Used to check for invalid b2JointId
52-
int revision;
53-
5450
float drawSize;
5551

5652
b2JointType type;
53+
54+
// This is monotonically advanced when a body is allocated in this slot
55+
// Used to check for invalid b2JointId
56+
uint16_t revision;
57+
5758
bool isMarked;
5859
bool collideConnected;
5960

src/manifold.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ b2Manifold b2CollideCapsules( const b2Capsule* capsuleA, b2Transform xfA, const
328328
return manifold;
329329
}
330330

331-
float distance = sqrt( distanceSquared );
331+
float distance = sqrtf( distanceSquared );
332332

333333
float length1, length2;
334334
b2Vec2 u1 = b2GetLengthAndNormalize( &length1, d1 );

src/motor_joint.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ void b2WarmStartMotorJoint( b2JointSim* base, b2StepContext* context )
186186

187187
void b2SolveMotorJoint( b2JointSim* base, b2StepContext* context, bool useBias )
188188
{
189+
B2_MAYBE_UNUSED( useBias );
189190
B2_ASSERT( base->type == b2_motorJoint );
190191

191192
float mA = base->invMassA;

src/weld_joint.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ void b2PrepareWeldJoint( b2JointSim* base, b2StepContext* context )
150150
float ka = iA + iB;
151151
joint->axialMass = ka > 0.0f ? 1.0f / ka : 0.0f;
152152

153-
const float h = context->dt;
154-
155153
if ( joint->linearHertz == 0.0f )
156154
{
157155
joint->linearSoftness = context->jointSoftness;

src/wheel_joint.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,6 @@ void b2SolveWheelJoint( b2JointSim* base, b2StepContext* context, bool useBias )
315315

316316
b2WheelJoint* joint = &base->wheelJoint;
317317

318-
// This is a dummy body to represent a static body since static bodies don't have a solver body.
319-
b2BodyState dummyBody = { 0 };
320-
321318
b2BodyState* stateA = joint->indexA == B2_NULL_INDEX ? &dummyState : context->states + joint->indexA;
322319
b2BodyState* stateB = joint->indexB == B2_NULL_INDEX ? &dummyState : context->states + joint->indexB;
323320

@@ -378,8 +375,6 @@ void b2SolveWheelJoint( b2JointSim* base, b2StepContext* context, bool useBias )
378375

379376
if ( joint->enableLimit )
380377
{
381-
float translation = b2Dot( axisA, d );
382-
383378
// Lower limit
384379
{
385380
float C = translation - joint->lowerTranslation;

src/world.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ void b2DestroyWorld( b2WorldId worldId )
294294
// Wipe world but preserve revision
295295
uint16_t revision = world->revision;
296296
*world = ( b2World ){ 0 };
297-
world->worldId = B2_NULL_INDEX;
297+
world->worldId = 0;
298298
world->revision = revision + 1;
299299
}
300300

@@ -304,7 +304,7 @@ static void b2CollideTask( int startIndex, int endIndex, uint32_t threadIndex, v
304304

305305
b2StepContext* stepContext = context;
306306
b2World* world = stepContext->world;
307-
B2_ASSERT( threadIndex < world->workerCount );
307+
B2_ASSERT( (int)threadIndex < world->workerCount );
308308
b2TaskContext* taskContext = world->taskContexts.data + threadIndex;
309309
b2ContactSim** contactSims = stepContext->contacts;
310310
b2Shape* shapes = world->shapes.data;
@@ -2891,7 +2891,7 @@ void b2ValidateSolverSets( b2World* world )
28912891

28922892
int contactIdCount = b2GetIdCount( &world->contactIdPool );
28932893
B2_ASSERT( totalContactCount == contactIdCount );
2894-
B2_ASSERT( totalContactCount == world->broadPhase.pairSet.count );
2894+
B2_ASSERT( totalContactCount == (int)world->broadPhase.pairSet.count );
28952895

28962896
int jointIdCount = b2GetIdCount( &world->jointIdPool );
28972897
B2_ASSERT( totalJointCount == jointIdCount );

0 commit comments

Comments
 (0)