Skip to content

Commit

Permalink
increased warning level to W4 on MSVC for #816
Browse files Browse the repository at this point in the history
  • Loading branch information
erincatto committed Oct 5, 2024
1 parent 6336023 commit 8f22f3f
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 31 deletions.
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/body.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
29 changes: 14 additions & 15 deletions src/dynamic_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 ) )
{
Expand All @@ -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);
Expand Down Expand Up @@ -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 )
Expand All @@ -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 );
}

Expand All @@ -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 )
{
Expand Down
2 changes: 1 addition & 1 deletion src/hull.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 } };

Expand Down
9 changes: 5 additions & 4 deletions src/joint.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/manifold.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/motor_joint.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/weld_joint.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions src/wheel_joint.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/world.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 8f22f3f

Please sign in to comment.