diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 695fff850..0bc507726 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -135,6 +135,9 @@ if (MSVC) # Atomics are still considered experimental in Visual Studio 17.8 target_compile_options(box2d PRIVATE /experimental:c11atomics) + # All warnings + target_compile_options(box2d PRIVATE /W4) + if (BOX2D_AVX2) message(STATUS "Box2D using AVX2") target_compile_definitions(box2d PRIVATE BOX2D_AVX2) diff --git a/src/body.c b/src/body.c index 273b04c34..7dc6f469b 100644 --- a/src/body.c +++ b/src/body.c @@ -309,6 +309,7 @@ b2BodyId b2CreateBody( b2WorldId worldId, const b2BodyDef* def ) bool b2IsBodyAwake( b2World* world, b2Body* body ) { + B2_MAYBE_UNUSED( world ); return body->setIndex == b2_awakeSet; } diff --git a/src/dynamic_tree.c b/src/dynamic_tree.c index 322b5221c..92885d1fc 100644 --- a/src/dynamic_tree.c +++ b/src/dynamic_tree.c @@ -871,7 +871,7 @@ static int b2ComputeHeight( const b2DynamicTree* tree, int32_t nodeId ) int32_t height1 = b2ComputeHeight( tree, node->child1 ); int32_t height2 = b2ComputeHeight( tree, node->child2 ); - return 1 + b2MaxInt16( height1, height2 ); + return 1 + b2MaxInt( height1, height2 ); } int b2DynamicTree_ComputeHeight( const b2DynamicTree* tree ) @@ -930,8 +930,8 @@ static void b2ValidateMetrics( const b2DynamicTree* tree, int32_t index ) const b2TreeNode* node = tree->nodes + index; - int32_t child1 = node->child1; - int32_t child2 = node->child2; + int child1 = node->child1; + int child2 = node->child2; if ( b2IsLeaf( node ) ) { @@ -944,10 +944,9 @@ static void b2ValidateMetrics( const b2DynamicTree* tree, int32_t index ) B2_ASSERT( 0 <= child1 && child1 < tree->nodeCapacity ); B2_ASSERT( 0 <= child2 && child2 < tree->nodeCapacity ); - int32_t height1 = tree->nodes[child1].height; - int32_t height2 = tree->nodes[child2].height; - int32_t height; - height = 1 + b2MaxInt16( height1, height2 ); + int height1 = tree->nodes[child1].height; + int height2 = tree->nodes[child2].height; + int height = 1 + b2MaxInt( height1, height2 ); B2_ASSERT( node->height == height ); // b2AABB aabb = b2AABB_Union(tree->nodes[child1].aabb, tree->nodes[child2].aabb); @@ -1000,8 +999,8 @@ void b2DynamicTree_Validate( const b2DynamicTree* tree ) int32_t b2DynamicTree_GetMaxBalance( const b2DynamicTree* tree ) { - int32_t maxBalance = 0; - for ( int32_t i = 0; i < tree->nodeCapacity; ++i ) + int maxBalance = 0; + for ( int i = 0; i < tree->nodeCapacity; ++i ) { const b2TreeNode* node = tree->nodes + i; if ( node->height <= 1 ) @@ -1011,9 +1010,9 @@ int32_t b2DynamicTree_GetMaxBalance( const b2DynamicTree* tree ) B2_ASSERT( b2IsLeaf( node ) == false ); - int32_t child1 = node->child1; - int32_t child2 = node->child2; - int32_t balance = b2AbsFloat( tree->nodes[child2].height - tree->nodes[child1].height ); + int child1 = node->child1; + int child2 = node->child2; + int balance = b2AbsInt( tree->nodes[child2].height - tree->nodes[child1].height ); maxBalance = b2MaxInt( maxBalance, balance ); } @@ -1022,11 +1021,11 @@ int32_t b2DynamicTree_GetMaxBalance( const b2DynamicTree* tree ) void b2DynamicTree_RebuildBottomUp( b2DynamicTree* tree ) { - int32_t* nodes = b2Alloc( tree->nodeCount * sizeof( int32_t ) ); - int32_t count = 0; + int* nodes = b2Alloc( tree->nodeCount * sizeof( int ) ); + int count = 0; // Build array of leaves. Free the rest. - for ( int32_t i = 0; i < tree->nodeCapacity; ++i ) + for ( int i = 0; i < tree->nodeCapacity; ++i ) { if ( tree->nodes[i].height < 0 ) { diff --git a/src/hull.c b/src/hull.c index 41fd76de1..eb0f4c5c7 100644 --- a/src/hull.c +++ b/src/hull.c @@ -94,7 +94,7 @@ b2Hull b2ComputeHull( const b2Vec2* points, int count ) return hull; } - count = b2MinFloat( count, b2_maxPolygonVertices ); + count = b2MinInt( count, b2_maxPolygonVertices ); b2AABB aabb = { { FLT_MAX, FLT_MAX }, { -FLT_MAX, -FLT_MAX } }; diff --git a/src/joint.h b/src/joint.h index 80ac04bfb..441e4394c 100644 --- a/src/joint.h +++ b/src/joint.h @@ -47,13 +47,14 @@ typedef struct b2Joint int islandPrev; int islandNext; - // This is monotonically advanced when a body is allocated in this slot - // Used to check for invalid b2JointId - int revision; - float drawSize; b2JointType type; + + // This is monotonically advanced when a body is allocated in this slot + // Used to check for invalid b2JointId + uint16_t revision; + bool isMarked; bool collideConnected; diff --git a/src/manifold.c b/src/manifold.c index b66785d28..38f7c94d2 100644 --- a/src/manifold.c +++ b/src/manifold.c @@ -328,7 +328,7 @@ b2Manifold b2CollideCapsules( const b2Capsule* capsuleA, b2Transform xfA, const return manifold; } - float distance = sqrt( distanceSquared ); + float distance = sqrtf( distanceSquared ); float length1, length2; b2Vec2 u1 = b2GetLengthAndNormalize( &length1, d1 ); diff --git a/src/motor_joint.c b/src/motor_joint.c index b41f685a8..721e98974 100644 --- a/src/motor_joint.c +++ b/src/motor_joint.c @@ -186,6 +186,7 @@ void b2WarmStartMotorJoint( b2JointSim* base, b2StepContext* context ) void b2SolveMotorJoint( b2JointSim* base, b2StepContext* context, bool useBias ) { + B2_MAYBE_UNUSED( useBias ); B2_ASSERT( base->type == b2_motorJoint ); float mA = base->invMassA; diff --git a/src/weld_joint.c b/src/weld_joint.c index e772fde22..965a5210f 100644 --- a/src/weld_joint.c +++ b/src/weld_joint.c @@ -150,8 +150,6 @@ void b2PrepareWeldJoint( b2JointSim* base, b2StepContext* context ) float ka = iA + iB; joint->axialMass = ka > 0.0f ? 1.0f / ka : 0.0f; - const float h = context->dt; - if ( joint->linearHertz == 0.0f ) { joint->linearSoftness = context->jointSoftness; diff --git a/src/wheel_joint.c b/src/wheel_joint.c index e4d96b401..b2a971dfc 100644 --- a/src/wheel_joint.c +++ b/src/wheel_joint.c @@ -315,9 +315,6 @@ void b2SolveWheelJoint( b2JointSim* base, b2StepContext* context, bool useBias ) b2WheelJoint* joint = &base->wheelJoint; - // This is a dummy body to represent a static body since static bodies don't have a solver body. - b2BodyState dummyBody = { 0 }; - b2BodyState* stateA = joint->indexA == B2_NULL_INDEX ? &dummyState : context->states + joint->indexA; b2BodyState* stateB = joint->indexB == B2_NULL_INDEX ? &dummyState : context->states + joint->indexB; @@ -378,8 +375,6 @@ void b2SolveWheelJoint( b2JointSim* base, b2StepContext* context, bool useBias ) if ( joint->enableLimit ) { - float translation = b2Dot( axisA, d ); - // Lower limit { float C = translation - joint->lowerTranslation; diff --git a/src/world.c b/src/world.c index 68be3286e..e9b7d718a 100644 --- a/src/world.c +++ b/src/world.c @@ -294,7 +294,7 @@ void b2DestroyWorld( b2WorldId worldId ) // Wipe world but preserve revision uint16_t revision = world->revision; *world = ( b2World ){ 0 }; - world->worldId = B2_NULL_INDEX; + world->worldId = 0; world->revision = revision + 1; } @@ -304,7 +304,7 @@ static void b2CollideTask( int startIndex, int endIndex, uint32_t threadIndex, v b2StepContext* stepContext = context; b2World* world = stepContext->world; - B2_ASSERT( threadIndex < world->workerCount ); + B2_ASSERT( (int)threadIndex < world->workerCount ); b2TaskContext* taskContext = world->taskContexts.data + threadIndex; b2ContactSim** contactSims = stepContext->contacts; b2Shape* shapes = world->shapes.data; @@ -2891,7 +2891,7 @@ void b2ValidateSolverSets( b2World* world ) int contactIdCount = b2GetIdCount( &world->contactIdPool ); B2_ASSERT( totalContactCount == contactIdCount ); - B2_ASSERT( totalContactCount == world->broadPhase.pairSet.count ); + B2_ASSERT( totalContactCount == (int)world->broadPhase.pairSet.count ); int jointIdCount = b2GetIdCount( &world->jointIdPool ); B2_ASSERT( totalJointCount == jointIdCount );