Skip to content

Commit

Permalink
Add basic github actions build
Browse files Browse the repository at this point in the history
  • Loading branch information
viblo committed Jan 4, 2025
1 parent 5dd7d77 commit 8531104
Show file tree
Hide file tree
Showing 29 changed files with 280 additions and 35 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml
name: CMake on multiple platforms

on:
push:
branches: master
pull_request:
branches: master

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false

# Set up a matrix to run the following 3 configurations:
# 1. <Windows, Release, latest MSVC compiler toolchain on the default runner image, default generator>
# 2. <Linux, Release, latest GCC compiler toolchain on the default runner image, default generator>
# 3. <Linux, Release, latest Clang compiler toolchain on the default runner image, default generator>
#
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
matrix:
os: [ubuntu-latest, windows-latest]
build_type: [Release]
c_compiler: [gcc, clang, cl]
include:
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
exclude:
- os: windows-latest
c_compiler: gcc
- os: windows-latest
c_compiler: clang
- os: ubuntu-latest
c_compiler: cl

steps:
- uses: actions/checkout@v4

- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Update packages
run: sudo apt-get update

- name: Install packages
run: sudo apt-get install --fix-missing libgl1-mesa-dev

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} -DCMAKE_C_COMPILER=${{
matrix.c_compiler }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -S
${{ github.workspace }}
- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run:
cmake --build ${{ steps.strings.outputs.build-output-dir }} --config
${{ matrix.build_type }}

#- name: Test
# working-directory: ${{ steps.strings.outputs.build-output-dir }}
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
# run: ctest --build-config ${{ matrix.build_type }}
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.7)
cmake_minimum_required(VERSION 3.10)

project(chipmunk)

Expand Down
19 changes: 19 additions & 0 deletions README.textile
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
!http://files.slembcke.net/chipmunk/logo/logo1_med.png!

h2. FORK INFO - START HERE

This is a fork of the original "Chipmunk2D":https://github.com/slembcke/Chipmunk2D

The main purpose of this fork is to be a compainion for the Python 2D physics library "Pymunk":https://www.pymunk.org which is built on Chipmunk2D. Given the slow pace of development of Chipmunk2D, and some unique requirements and oppurtunitites of Pymunk this is something that have grown over a long time. What really made me consider to make it more formal was the discussion "here":https://github.com/slembcke/Chipmunk2D/issues/237 with Slembcke, the creator of Chipmunk2D.

I do not forsee that I have the time, motivation or skills to really revive Chipmunk2D. However, I hope to incorporate minor new features, and a bunch of fixes. Any changes are driven by what make sense from the Pymunk use case. However, I do think many of these changes are useful also to users outside of Pymunk, and you are of course free to use the fork for other projects / languages as well.

At the moment I dont have any formal release of this fork, but I plan to make some kind of rename and a release if/when enough changes are accumulated.

h3. Differeces:

* This fork will have ABI breaking changes. For Pymunk it does not matter, a Pymunk verison is always compiled against a specific Chipmunk2D version.
* This fork might have API breaking changes. Since Pymunk wraps Chipmunk2D in a Python friendly API, end users of Pymunk wont be affected.
* Some additional minor features, useful from Pymunk
* Fixes to various issues, mainly those affecting Pymunk

---

h2. NEW IN CHIPMUNK 7

Chipmunk 7 is complete and now includes the ARM NEON optimizations, the autogeometry code, and the mulithreaded solver.
Expand Down
21 changes: 21 additions & 0 deletions VERSION.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
What's new in NEXT:
* API: Now possible to to override cpMessage by defining CP_OVERRIDE_MESSAGE
* API: The maxForce property now have effect on DampedSpring and DampedRotarySpring
* API: Reset velocity and constraint jAcc when body type changes to DYNAMIC
* API: Add transform property to cpSpaceDebugDrawOptions
* API: Use CGFloat as the float type if CP_USE_CGTYPES is set.
* BUG: Fixed total impulse calculation of DampedRotarySpring
* BUG: Fix for compiling cpPolyline with MSVC
* BUG: Fix FFI symbols not exported on windows under mingw
* BUG: Fix a potential divide by zero in ClosestT
* BUG: Fix division by zero in cpPolyShapeSegmentQuery() function.
* BUG: Fix planetmath url (by ccgargantua)
* BUG: Optimized memory allocation of cpPolylineSet (by richardgroves)
* BUG: Fix cast between incompatible function type to reduce warnings (by aganm)
* BUG: Rename body local variable to fix shadow warning (by aganm)
* BUG: Fixes bug in cpSpaceShapeQuery to not miss collisions (by alanmillard)
* BUG: Fix for cpSpaceShapeQuery using cpSegmentShape with null body (by maniek2332)
* MISC: Fix spelling of positive (by skitt)



What's new in 7.0.3:
* MISC: Replacing GLFW with Sokol in the demo application. No need to push GLFW binaries and has a nice x-platform renderer to build on.
* MISC: Fixed some 'const' warnings for MSCV.
Expand Down
1 change: 1 addition & 0 deletions demo/ChipmunkDemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ ChipmunkDemoDefaultDrawImpl(cpSpace *space)
ColorForShape,
{0.0f, 0.75f, 0.0f, 1.0f}, // Constraint color
{1.0f, 0.0f, 0.0f, 1.0f}, // Collision point color
cpTransformIdentity,
NULL,
};

Expand Down
2 changes: 2 additions & 0 deletions include/chipmunk/chipmunk_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,14 @@ typedef void (*cpConstraintPreStepImpl)(cpConstraint *constraint, cpFloat dt);
typedef void (*cpConstraintApplyCachedImpulseImpl)(cpConstraint *constraint, cpFloat dt_coef);
typedef void (*cpConstraintApplyImpulseImpl)(cpConstraint *constraint, cpFloat dt);
typedef cpFloat (*cpConstraintGetImpulseImpl)(cpConstraint *constraint);
typedef void (*cpConstraintResetAccImpl)(cpConstraint *constraint);

typedef struct cpConstraintClass {
cpConstraintPreStepImpl preStep;
cpConstraintApplyCachedImpulseImpl applyCachedImpulse;
cpConstraintApplyImpulseImpl applyImpulse;
cpConstraintGetImpulseImpl getImpulse;
cpConstraintResetAccImpl resetAcc;
} cpConstraintClass;

struct cpConstraint {
Expand Down
8 changes: 8 additions & 0 deletions include/chipmunk/cpMarch.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright 2013 Howling Moon Software. All rights reserved.
// See http://chipmunk2d.net/legal.php for more information.

#ifdef __cplusplus
extern "C" {
#endif

/// Function type used as a callback from the marching squares algorithm to sample an image function.
/// It passes you the point to sample and your context pointer, and you return the density.
typedef cpFloat (*cpMarchSampleFunc)(cpVect point, void *data);
Expand All @@ -26,3 +30,7 @@ CP_EXPORT void cpMarchHard(
cpMarchSegmentFunc segment, void *segment_data,
cpMarchSampleFunc sample, void *sample_data
);

#ifdef __cplusplus
}
#endif
8 changes: 8 additions & 0 deletions include/chipmunk/cpPolyline.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright 2013 Howling Moon Software. All rights reserved.
// See http://chipmunk2d.net/legal.php for more information.

#ifdef __cplusplus
extern "C" {
#endif

// Polylines are just arrays of vertexes.
// They are looped if the first vertex is equal to the last.
// cpPolyline structs are intended to be passed by value and destroyed when you are done with them.
Expand Down Expand Up @@ -68,3 +72,7 @@ CP_EXPORT void cpPolylineSetCollectSegment(cpVect v0, cpVect v1, cpPolylineSet *
CP_EXPORT cpPolylineSet *cpPolylineConvexDecomposition(cpPolyline *line, cpFloat tol);

#define cpPolylineConvexDecomposition_BETA cpPolylineConvexDecomposition

#ifdef __cplusplus
}
#endif
5 changes: 4 additions & 1 deletion src/chipmunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
*/

#include <stdio.h>
#include <string.h>
Expand All @@ -28,6 +28,7 @@

#include "chipmunk/chipmunk_private.h"

#ifndef CP_OVERRIDE_MESSAGE
void
cpMessage(const char *condition, const char *file, int line, int isError, int isHardError, const char *message, ...)
{
Expand All @@ -52,6 +53,8 @@ cpMessage(const char *condition, const char *file, int line, int isError, int is
fprintf(stderr, "\tSource:%s:%d\n", file, line);
#endif
}
#endif


#define STR(s) #s
#define XSTR(s) STR(s)
Expand Down
2 changes: 1 addition & 1 deletion src/cpBBTree.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ cpBBTreeAlloc(void)
return (cpBBTree *)cpcalloc(1, sizeof(cpBBTree));
}

static int
static cpBool
leafSetEql(void *obj, Node *node)
{
return (obj == node->obj);
Expand Down
23 changes: 20 additions & 3 deletions src/cpBody.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ cpBodyFree(cpBody *body)
#ifdef NDEBUG
#define cpAssertSaneBody(body)
#else
static void cpv_assert_nan(cpVect v, char *message){cpAssertHard(v.x == v.x && v.y == v.y, message);}
static void cpv_assert_infinite(cpVect v, char *message){cpAssertHard(cpfabs(v.x) != INFINITY && cpfabs(v.y) != INFINITY, message);}
static void cpv_assert_sane(cpVect v, char *message){cpv_assert_nan(v, message); cpv_assert_infinite(v, message);}
static void cpv_assert_nan(cpVect v, const char *message){cpAssertHard(v.x == v.x && v.y == v.y, message);}
static void cpv_assert_infinite(cpVect v, const char *message){cpAssertHard(cpfabs(v.x) != INFINITY && cpfabs(v.y) != INFINITY, message);}
static void cpv_assert_sane(cpVect v, const char *message){cpv_assert_nan(v, message); cpv_assert_infinite(v, message);}

static void
cpBodySanityCheck(const cpBody *body)
Expand Down Expand Up @@ -160,6 +160,23 @@ cpBodySetType(cpBody *body, cpBodyType type)
body->m_inv = body->i_inv = INFINITY;

cpBodyAccumulateMassFromShapes(body);

// Check any constraints, and if there are
// constraints with another non-DYNAMIC body:
// Reset any accumulated force in constraints attached to the body.
// Reset velocity of the body. These will be NaN or Inf otherwise.
cpConstraint* constraint = body->constraintList;
while (constraint) {
constraint->klass->resetAcc(constraint);
cpBody* a = cpConstraintGetBodyA(constraint);
a->v = cpvzero;
a->w = 0.0f;
cpBody* b = cpConstraintGetBodyB(constraint);
b->v = cpvzero;
b->w = 0.0f;

constraint = cpConstraintNext(constraint, body);
}
} else {
body->m = body->i = INFINITY;
body->m_inv = body->i_inv = 0.0f;
Expand Down
8 changes: 4 additions & 4 deletions src/cpCollision.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ CircleToSegment(const cpCircleShape *circle, const cpSegmentShape *segment, stru
cpVect n = info->n = (dist ? cpvmult(delta, 1.0f/dist) : segment->tn);

// Reject endcap collisions if tangents are provided.
cpVect rot = cpBodyGetRotation(segment->shape.body);
cpVect rot = segment->shape.body ? cpBodyGetRotation(segment->shape.body) : cpv(1.0f, 0.0f);
if(
(closest_t != 0.0f || cpvdot(n, cpvrotate(segment->a_tangent, rot)) >= 0.0) &&
(closest_t != 1.0f || cpvdot(n, cpvrotate(segment->b_tangent, rot)) >= 0.0)
Expand Down Expand Up @@ -587,8 +587,8 @@ SegmentToSegment(const cpSegmentShape *seg1, const cpSegmentShape *seg2, struct
#endif

cpVect n = points.n;
cpVect rot1 = cpBodyGetRotation(seg1->shape.body);
cpVect rot2 = cpBodyGetRotation(seg2->shape.body);
cpVect rot1 = seg1->shape.body ? cpBodyGetRotation(seg1->shape.body) : cpv(1.0f, 0.0f);
cpVect rot2 = seg2->shape.body ? cpBodyGetRotation(seg2->shape.body) : cpv(1.0f, 0.0f);

// If the closest points are nearer than the sum of the radii...
if(
Expand Down Expand Up @@ -645,7 +645,7 @@ SegmentToPoly(const cpSegmentShape *seg, const cpPolyShape *poly, struct cpColli
#endif

cpVect n = points.n;
cpVect rot = cpBodyGetRotation(seg->shape.body);
cpVect rot = seg->shape.body ? cpBodyGetRotation(seg->shape.body) : cpv(1.0f, 0.0f);

if(
// If the closest points are nearer than the sum of the radii...
Expand Down
20 changes: 17 additions & 3 deletions src/cpDampedRotarySpring.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/

#include "chipmunk/chipmunk_private.h"

#include <stdio.h>
static cpFloat
defaultSpringTorque(cpDampedRotarySpring *spring, cpFloat relativeAngle){
return (relativeAngle - spring->restAngle)*spring->stiffness;
Expand All @@ -40,7 +40,10 @@ preStep(cpDampedRotarySpring *spring, cpFloat dt)
spring->target_wrn = 0.0f;

// apply spring torque
cpFloat j_spring = spring->springTorqueFunc((cpConstraint *)spring, a->a - b->a)*dt;
cpFloat t_spring = spring->springTorqueFunc((cpConstraint *)spring, a->a - b->a);
t_spring = cpfclamp(t_spring, -spring->constraint.maxForce, spring->constraint.maxForce);

cpFloat j_spring = t_spring*dt;
spring->jAcc = j_spring;

a->w -= j_spring*a->i_inv;
Expand All @@ -65,8 +68,12 @@ applyImpulse(cpDampedRotarySpring *spring, cpFloat dt)

//apply_impulses(a, b, spring->r1, spring->r2, cpvmult(spring->n, v_damp*spring->nMass));
cpFloat j_damp = w_damp*spring->iSum;
spring->jAcc += j_damp;
cpFloat maxImpulse = spring->constraint.maxForce*dt;

cpFloat jAccClamped = cpfclamp(spring->jAcc-j_damp, -maxImpulse, maxImpulse);
j_damp = spring->jAcc - jAccClamped;

spring->jAcc -= j_damp;
a->w += j_damp*a->i_inv;
b->w -= j_damp*b->i_inv;
}
Expand All @@ -77,11 +84,18 @@ getImpulse(cpDampedRotarySpring *spring)
return spring->jAcc;
}

static void
resetAcc(cpDampedRotarySpring *spring)
{
spring->jAcc = 0.0f;
}

static const cpConstraintClass klass = {
(cpConstraintPreStepImpl)preStep,
(cpConstraintApplyCachedImpulseImpl)applyCachedImpulse,
(cpConstraintApplyImpulseImpl)applyImpulse,
(cpConstraintGetImpulseImpl)getImpulse,
(cpConstraintResetAccImpl)resetAcc,
};

cpDampedRotarySpring *
Expand Down
Loading

0 comments on commit 8531104

Please sign in to comment.