Skip to content

Commit

Permalink
Update Box2D to version 2.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
marmichalski committed Nov 21, 2021
1 parent ee80476 commit a9e9896
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 155 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ compiler: clang
before_install:
- sudo apt-get update
- sudo apt-get install -y libxml2-dev
- sudo apt install libglew-dev libglfw3-dev libglm-dev libgl1-mesa-dev xorg-dev clang
- sudo apt install libglew-dev libglfw3-dev libglm-dev libgl1-mesa-dev xorg-dev clang cmake
- sudo apt-get install libopenal-dev
script:
- make
21 changes: 10 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ get_demoversion:

clean:
.build/premake5 gmake --cc=clang
make -C third_party/Box2D/Build clean
rm -rf third_party/Box2D/build
make -C .build clean

run:
Expand All @@ -43,13 +43,12 @@ builddir:

premake: builddir
test -e .build/premake5 || (cd .build && \
wget https://github.com/premake/premake-core/releases/download/v5.0.0-alpha14/premake-5.0.0-alpha14-linux.tar.gz && \
tar xzf premake-5.0.0-alpha14-linux.tar.gz && \
rm premake-5.0.0-alpha14-linux.tar.gz)

box2d: premake
.build/premake5 --file=third_party/Box2D/premake5.lua gmake
make -C third_party/Box2D/Build config=debug_x86_64 -j$(CPUS)
make -C third_party/Box2D/Build config=release_x86_64 -j$(CPUS)


wget https://github.com/premake/premake-core/releases/download/v5.0.0-beta1/premake-5.0.0-beta1-linux.tar.gz && \
tar xzf premake-5.0.0-beta1-linux.tar.gz && \
rm premake-5.0.0-beta1-linux.tar.gz)

box2d:
cd third_party/Box2D && \
mkdir -p build && cd build && \
cmake -DCMAKE_BUILD_TYPE=Release -DBOX2D_BUILD_DOCS=Off -DBOX2D_BUILD_UNIT_TESTS=Off -DBOX2D_BUILD_TESTBED=Off .. && \
cmake --build .
8 changes: 4 additions & 4 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ project "carnage3d"
"src/*.h",
"src/*.cpp"
}
includedirs { "third_party/Box2D" }
includedirs { "third_party/Box2D/include" }
includedirs { "GLFW" }
links { "GL", "GLEW", "stdc++fs", "openal", "Box2D", "X11", "Xrandr", "Xinerama", "Xcursor", "pthread", "dl", "GLFW" }
links { "GL", "GLEW", "stdc++fs", "openal", "box2d", "X11", "Xrandr", "Xinerama", "Xcursor", "pthread", "dl", "GLFW" }

filter { "configurations:Debug" }
defines { "DEBUG", "_DEBUG" }
symbols "On"
libdirs { "third_party/Box2D/Build/bin/x86_64/Debug" }
libdirs { "third_party/Box2D/build/bin" }

filter { "configurations:Release" }
defines { "NDEBUG" }
optimize "On"
libdirs { "third_party/Box2D/Build/bin/x86_64/Release" }
libdirs { "third_party/Box2D/build/bin" }
8 changes: 4 additions & 4 deletions src/Box2D_Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ inline b2Vec2 convert_vec2(const glm::vec2& vector_value)
inline Collider* b2Fixture_get_collider(b2Fixture* fixture)
{
debug_assert(fixture);
Collider* collisionShape = (Collider*) fixture->GetUserData();
Collider* collisionShape = (Collider*) fixture->GetUserData().pointer;

return collisionShape;
}
Expand All @@ -32,15 +32,15 @@ inline PhysicsBody* b2Fixture_get_physics_body(b2Fixture* fixture)
{
debug_assert(fixture);

PhysicsBody* physicsBoxy = (PhysicsBody*) fixture->GetBody()->GetUserData();
PhysicsBody* physicsBoxy = (PhysicsBody*) fixture->GetBody()->GetUserData().pointer;
return physicsBoxy;
}

inline GameObject* b2Fixture_get_game_object(b2Fixture* fixture)
{
debug_assert(fixture);

PhysicsBody* physicsBoxy = (PhysicsBody*) fixture->GetBody()->GetUserData();
PhysicsBody* physicsBoxy = (PhysicsBody*) fixture->GetBody()->GetUserData().pointer;
GameObject* gameObject = nullptr;
if (physicsBoxy)
{
Expand All @@ -49,4 +49,4 @@ inline GameObject* b2Fixture_get_game_object(b2Fixture* fixture)
return gameObject;
}

//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
6 changes: 3 additions & 3 deletions src/Collider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Collider::Collider(PhysicsBody* physicsBody, const CollisionShape& shapeData, co

// allocate new shape
b2FixtureDef fixtureDef;
fixtureDef.userData = this;
fixtureDef.userData.pointer = reinterpret_cast<uintptr_t>(this);
fixtureDef.friction = shapeMaterial.mFriction;
fixtureDef.restitution = shapeMaterial.mRestitution;
fixtureDef.density = shapeMaterial.mDensity;
Expand All @@ -31,7 +31,7 @@ Collider::Collider(PhysicsBody* physicsBody, const CollisionShape& shapeData, co
};

FixtureShapeDefs fixtureShapeDefs;

switch (shapeData.mType)
{
case eCollisionShape_Circle:
Expand All @@ -40,7 +40,7 @@ Collider::Collider(PhysicsBody* physicsBody, const CollisionShape& shapeData, co
break;

case eCollisionShape_Edge:
fixtureShapeDefs.mEdgeShape.Set(
fixtureShapeDefs.mEdgeShape.SetTwoSided(
convert_vec2(shapeData.mEdge.mEdgePoint0),
convert_vec2(shapeData.mEdge.mEdgePoint1));
fixtureDef.shape = &fixtureShapeDefs.mEdgeShape;
Expand Down
16 changes: 8 additions & 8 deletions src/PhysicsBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ PhysicsBody::PhysicsBody(GameObject* owner, PhysicsBodyFlags flags)

bodyDef.fixedRotation = CheckFlags(PhysicsBodyFlags_FixRotation);
bodyDef.bullet = CheckFlags(PhysicsBodyFlags_Bullet);
bodyDef.active = CheckFlags(PhysicsBodyFlags_Disabled) == false;
bodyDef.userData = this;
bodyDef.enabled = CheckFlags(PhysicsBodyFlags_Disabled) == false;
bodyDef.userData.pointer = reinterpret_cast<uintptr_t>(this);
// setup initial transform
if (mGameObject)
{
Expand Down Expand Up @@ -98,7 +98,7 @@ void PhysicsBody::SetupFlags(PhysicsBodyFlags flags)
}

bool isDisabled = CheckFlags(PhysicsBodyFlags_Disabled);
mBox2Body->SetActive(!isDisabled);
mBox2Body->SetEnabled(!isDisabled);

bool isHovering = CheckFlags(PhysicsBodyFlags_NoGravity);

Expand Down Expand Up @@ -126,7 +126,7 @@ bool PhysicsBody::CheckFlags(PhysicsBodyFlags flags) const
}

Collider* PhysicsBody::AddCollider(int colliderIndex, const CollisionShape& shapeData, const PhysicsMaterial& shapeMaterial,
CollisionGroup collisionGroup,
CollisionGroup collisionGroup,
CollisionGroup collidesWith, ColliderFlags colliderFlags)
{
debug_assert(!gPhysics.IsSimulationStepInProgress());
Expand Down Expand Up @@ -326,7 +326,7 @@ void PhysicsBody::ApplyAngularImpulse(float impulse)
{
if (cxx::equals_zero(impulse))
return;

mBox2Body->ApplyAngularImpulse(impulse, true);
}

Expand All @@ -350,8 +350,8 @@ void PhysicsBody::ClearForces()
glm::vec2 PhysicsBody::GetSignVector() const
{
float angleRadians = mBox2Body->GetAngle();
return {
cos(angleRadians),
return {
cos(angleRadians),
sin(angleRadians)
};
}
Expand Down Expand Up @@ -407,4 +407,4 @@ void PhysicsBody::SetAwake(bool isAwake)
float PhysicsBody::GetMass() const
{
return mBox2Body->GetMass();
}
}
Loading

0 comments on commit a9e9896

Please sign in to comment.