Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuous Integration: build samples #130

Merged
merged 6 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
build-ubuntu-gcc:
name: ubuntu-gcc
runs-on: ubuntu-latest

timeout-minutes: 4
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBOX2D_SAMPLES=OFF -DBUILD_SHARED_LIBS=OFF

Expand All @@ -32,7 +32,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_COMPILER=clang++-14 -DCMAKE_C_COMPILER=clang -DBOX2D_SAMPLES=OFF -DBUILD_SHARED_LIBS=OFF
Expand All @@ -49,10 +49,10 @@ jobs:
runs-on: macos-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBOX2D_SAMPLES=OFF -DBUILD_SHARED_LIBS=OFF
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBOX2D_SAMPLES=ON -DBUILD_SHARED_LIBS=OFF

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
Expand All @@ -66,10 +66,10 @@ jobs:
runs-on: windows-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBOX2D_SAMPLES=OFF -DBUILD_SHARED_LIBS=OFF
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBOX2D_SAMPLES=ON -DBUILD_SHARED_LIBS=OFF

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
Expand Down
31 changes: 25 additions & 6 deletions include/box2d/box2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,25 @@ B2_API b2Filter b2Shape_GetFilter(b2ShapeId shapeId);
/// Set the current filter. This is almost as expensive as recreating the shape.
B2_API void b2Shape_SetFilter(b2ShapeId shapeId, b2Filter filter);

/// Enable sensor events for this shape. Only applies to kinematic and dynamic bodies. Ignored for sensors.
B2_API void b2Shape_EnableSensorEvents(b2ShapeId shapeId, bool flag);

/// @return are sensor events enabled?
B2_API bool b2Shape_AreSensorEventsEnabled(b2ShapeId shapeId);

/// Enable contact events for this shape. Only applies to kinematic and dynamic bodies. Ignored for sensors.
B2_API void b2Shape_EnableContactEvents(b2ShapeId shapeId, bool flag);

/// @return are contact events enabled?
B2_API bool b2Shape_AreContactEventsEnabled(b2ShapeId shapeId);

/// Enable pre-solve contact events for this shape. Only applies to dynamic bodies. These are expensive
/// and must be carefully handled due to multi-threading. Ignored for sensors.
B2_API void b2Shape_EnablePreSolveEvents(b2ShapeId shapeId, bool flag);

/// @return are pre-solve events enabled?
B2_API bool b2Shape_ArePreSolveEventsEnabled(b2ShapeId shapeId);

/// Test a point for overlap with a shape
B2_API bool b2Shape_TestPoint(b2ShapeId shapeId, b2Vec2 point);

Expand Down Expand Up @@ -449,12 +468,6 @@ B2_API void b2Shape_SetPolygon(b2ShapeId shapeId, const b2Polygon* polygon);
/// If the shape is not a smooth segment then this will return b2_nullChainId.
B2_API b2ChainId b2Shape_GetParentChain(b2ShapeId shapeId);

/// Set the friction of a chain. Normally this is set in b2ChainDef.
B2_API void b2Chain_SetFriction(b2ChainId chainId, float friction);

/// Set the restitution (bounciness) on a chain. Normally this is specified in b2ChainDef.
B2_API void b2Chain_SetRestitution(b2ChainId chainId, float restitution);

/// Get the maximum capacity required for retrieving all the touching contacts on a shape
B2_API int32_t b2Shape_GetContactCapacity(b2ShapeId shapeId);

Expand All @@ -473,6 +486,12 @@ B2_API b2ChainId b2CreateChain(b2BodyId bodyId, const b2ChainDef* def);
/// Destroy a chain shape
B2_API void b2DestroyChain(b2ChainId chainId);

/// Set the friction of a chain. Normally this is set in b2ChainDef.
B2_API void b2Chain_SetFriction(b2ChainId chainId, float friction);

/// Set the restitution (bounciness) on a chain. Normally this is specified in b2ChainDef.
B2_API void b2Chain_SetRestitution(b2ChainId chainId, float restitution);

/// Chain identifier validation. Provides validation for up to 64K allocations.
B2_API bool b2Chain_IsValid(b2ChainId id);

Expand Down
50 changes: 27 additions & 23 deletions samples/sample_stacking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "settings.h"

#include <imgui.h>
#include <GLFW/glfw3.h>

class SingleBox : public Sample
{
Expand Down Expand Up @@ -68,8 +69,8 @@ class TiltedStack : public Sample
b2BodyId groundId = b2CreateBody(m_worldId, &bodyDef);

b2Polygon box = b2MakeBox(1000.0f, 1.0f);
b2ShapeDef sd = b2DefaultShapeDef();
b2CreatePolygonShape(groundId, &sd, &box);
b2ShapeDef shapeDef = b2DefaultShapeDef();
b2CreatePolygonShape(groundId, &shapeDef, &box);
}

for (int32_t i = 0; i < e_rows * e_columns; ++i)
Expand All @@ -79,9 +80,9 @@ class TiltedStack : public Sample

b2Polygon box = b2MakeRoundedBox(0.45f, 0.45f, 0.05f);

b2ShapeDef sd = b2DefaultShapeDef();
sd.density = 1.0f;
sd.friction = 0.3f;
b2ShapeDef shapeDef = b2DefaultShapeDef();
shapeDef.density = 1.0f;
shapeDef.friction = 0.3f;

float offset = 0.2f;
float dx = 5.0f;
Expand All @@ -103,7 +104,7 @@ class TiltedStack : public Sample

m_bodies[n] = bodyId;

b2CreatePolygonShape(bodyId, &sd, &box);
b2CreatePolygonShape(bodyId, &shapeDef, &box);
}
}
}
Expand Down Expand Up @@ -139,7 +140,7 @@ class VerticalStack : public Sample
{
if (settings.restart == false)
{
g_camera.m_center = {-5.5f, 6.5f};
g_camera.m_center = {-2.0f, 6.5f};
g_camera.m_zoom = 0.4f;
}

Expand All @@ -148,9 +149,12 @@ class VerticalStack : public Sample
bodyDef.position = {0.0f, -1.0f};
b2BodyId groundId = b2CreateBody(m_worldId, &bodyDef);

b2Polygon box = b2MakeBox(1000.0f, 1.0f);
b2ShapeDef sd = b2DefaultShapeDef();
b2CreatePolygonShape(groundId, &sd, &box);
b2Polygon box = b2MakeBox(100.0f, 1.0f);
b2ShapeDef shapeDef = b2DefaultShapeDef();
b2CreatePolygonShape(groundId, &shapeDef, &box);

b2Segment segment = {{10.0f, 1.0f}, {10.0f, 21.0f}};
b2CreateSegmentShape(groundId, &shapeDef, &segment);
}

for (int32_t i = 0; i < e_maxRows * e_maxColumns; ++i)
Expand All @@ -165,7 +169,7 @@ class VerticalStack : public Sample

m_shapeType = e_boxShape;
m_rowCount = e_maxRows;
m_columnCount = 4;
m_columnCount = 1;
m_bulletCount = 1;
m_bulletType = e_circleShape;

Expand All @@ -189,9 +193,9 @@ class VerticalStack : public Sample
b2Polygon box = b2MakeBox(0.5f, 0.5f);
// b2Polygon box = b2MakeRoundedBox(0.45f, 0.45f, 0.05f);

b2ShapeDef sd = b2DefaultShapeDef();
sd.density = 1.0f;
sd.friction = 0.3f;
b2ShapeDef shapeDef = b2DefaultShapeDef();
shapeDef.density = 1.0f;
shapeDef.friction = 0.3f;

float offset;

Expand All @@ -204,8 +208,8 @@ class VerticalStack : public Sample
offset = 0.01f;
}

float dx = 3.0f;
float xroot = -0.5f * dx * (m_columnCount - 1.0f);
float dx = -3.0f;
float xroot = 8.0f;

for (int32_t j = 0; j < m_columnCount; ++j)
{
Expand All @@ -227,11 +231,11 @@ class VerticalStack : public Sample

if (m_shapeType == e_circleShape)
{
b2CreateCircleShape(bodyId, &sd, &circle);
b2CreateCircleShape(bodyId, &shapeDef, &circle);
}
else
{
b2CreatePolygonShape(bodyId, &sd, &box);
b2CreatePolygonShape(bodyId, &shapeDef, &box);
}
}
}
Expand Down Expand Up @@ -274,8 +278,8 @@ class VerticalStack : public Sample
b2Circle circle = {{0.0f, 0.0f}, 0.25f};
b2Polygon box = b2MakeBox(0.25f, 0.25f);

b2ShapeDef sd = b2DefaultShapeDef();
sd.density = 4.0f;
b2ShapeDef shapeDef = b2DefaultShapeDef();
shapeDef.density = 4.0f;

for (int32_t i = 0; i < m_bulletCount; ++i)
{
Expand All @@ -290,11 +294,11 @@ class VerticalStack : public Sample

if (m_bulletType == e_boxShape)
{
b2CreatePolygonShape(bullet, &sd, &box);
b2CreatePolygonShape(bullet, &shapeDef, &box);
}
else
{
b2CreateCircleShape(bullet, &sd, &circle);
b2CreateCircleShape(bullet, &shapeDef, &circle);
}
assert(B2_IS_NULL(m_bullets[i]));
m_bullets[i] = bullet;
Expand Down Expand Up @@ -327,7 +331,7 @@ class VerticalStack : public Sample

ImGui::PopItemWidth();

if (ImGui::Button("Fire Bullets"))
if (ImGui::Button("Fire Bullets") || glfwGetKey(g_mainWindow, GLFW_KEY_B) == GLFW_PRESS)
{
DestroyBullets();
FireBullets();
Expand Down
57 changes: 57 additions & 0 deletions src/shape.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,63 @@ void b2Shape_SetFilter(b2ShapeId shapeId, b2Filter filter)
}
}

void b2Shape_EnableSensorEvents(b2ShapeId shapeId, bool flag)
{
b2World* world = b2GetWorldFromIndexLocked(shapeId.world);
if (world == NULL)
{
return;
}

b2Shape* shape = b2GetShape(world, shapeId);
shape->enableSensorEvents = flag;
}

bool b2Shape_AreSensorEventsEnabled(b2ShapeId shapeId)
{
b2World* world = b2GetWorldFromIndex(shapeId.world);
b2Shape* shape = b2GetShape(world, shapeId);
return shape->enableSensorEvents;
}

void b2Shape_EnableContactEvents(b2ShapeId shapeId, bool flag)
{
b2World* world = b2GetWorldFromIndexLocked(shapeId.world);
if (world == NULL)
{
return;
}

b2Shape* shape = b2GetShape(world, shapeId);
shape->enableContactEvents = flag;
}

bool b2Shape_AreContactEventsEnabled(b2ShapeId shapeId)
{
b2World* world = b2GetWorldFromIndex(shapeId.world);
b2Shape* shape = b2GetShape(world, shapeId);
return shape->enableContactEvents;
}

void b2Shape_EnablePreSolveEvents(b2ShapeId shapeId, bool flag)
{
b2World* world = b2GetWorldFromIndexLocked(shapeId.world);
if (world == NULL)
{
return;
}

b2Shape* shape = b2GetShape(world, shapeId);
shape->enablePreSolveEvents = flag;
}

bool b2Shape_ArePreSolveEventsEnabled(b2ShapeId shapeId)
{
b2World* world = b2GetWorldFromIndex(shapeId.world);
b2Shape* shape = b2GetShape(world, shapeId);
return shape->enablePreSolveEvents;
}

b2ShapeType b2Shape_GetType(b2ShapeId shapeId)
{
b2World* world = b2GetWorldFromIndex(shapeId.world);
Expand Down
2 changes: 1 addition & 1 deletion test/test_distance.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static int TimeOfImpactTest(void)

b2TOIOutput output = b2TimeOfImpact(&input);

ENSURE(output.state = b2_toiStateHit);
ENSURE(output.state == b2_toiStateHit);
ENSURE_SMALL(output.t - 0.5f, b2_linearSlop);

return 0;
Expand Down