Skip to content

Commit 82f7be1

Browse files
Merge pull request #202 from ricardoquesada/chipmunk_70_squashed
Squashed commit of the following:
2 parents 91ac435 + 84a8f5a commit 82f7be1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2238
-1717
lines changed

chipmunk/include/chipmunk/chipmunk.h

100755100644
+68-49
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2007 Scott Lembcke
1+
/* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
22
*
33
* Permission is hereby granted, free of charge, to any person obtaining a copy
44
* of this software and associated documentation files (the "Software"), to deal
@@ -19,20 +19,26 @@
1919
* SOFTWARE.
2020
*/
2121

22-
#ifndef CHIPMUNK_HEADER
23-
#define CHIPMUNK_HEADER
24-
25-
#ifdef _MSC_VER
26-
#define _USE_MATH_DEFINES
27-
#endif
22+
#ifndef CHIPMUNK_H
23+
#define CHIPMUNK_H
2824

2925
#include <stdlib.h>
3026
#include <math.h>
3127

28+
#ifdef WIN32
29+
// For alloca().
30+
#include <malloc.h>
31+
#define CP_EXPORT __declspec(dllexport)
32+
#else
33+
#include <alloca.h>
34+
#define CP_EXPORT
35+
#endif
36+
3237
#ifdef __cplusplus
3338
extern "C" {
3439
#endif
3540

41+
// NUKE
3642
#ifndef CP_ALLOW_PRIVATE_ACCESS
3743
#define CP_ALLOW_PRIVATE_ACCESS 0
3844
#endif
@@ -43,22 +49,17 @@ extern "C" {
4349
#define CP_PRIVATE(__symbol__) __symbol__##_private
4450
#endif
4551

46-
void cpMessage(const char *condition, const char *file, int line, int isError, int isHardError, const char *message, ...);
52+
CP_EXPORT void cpMessage(const char *condition, const char *file, int line, int isError, int isHardError, const char *message, ...);
4753
#ifdef NDEBUG
4854
#define cpAssertWarn(__condition__, ...)
49-
#else
50-
#define cpAssertWarn(__condition__, ...) if(!(__condition__)) cpMessage(#__condition__, __FILE__, __LINE__, 0, 0, __VA_ARGS__)
51-
#endif
52-
53-
#ifdef NDEBUG
5455
#define cpAssertSoft(__condition__, ...)
5556
#else
56-
#define cpAssertSoft(__condition__, ...) if(!(__condition__)) cpMessage(#__condition__, __FILE__, __LINE__, 1, 0, __VA_ARGS__)
57+
#define cpAssertSoft(__condition__, ...) if(!(__condition__)){cpMessage(#__condition__, __FILE__, __LINE__, 1, 0, __VA_ARGS__); abort();}
58+
#define cpAssertWarn(__condition__, ...) if(!(__condition__)) cpMessage(#__condition__, __FILE__, __LINE__, 0, 0, __VA_ARGS__)
5759
#endif
5860

59-
// Hard assertions are important and cheap to execute. They are not disabled by compiling as debug.
60-
#define cpAssertHard(__condition__, ...) if(!(__condition__)) cpMessage(#__condition__, __FILE__, __LINE__, 1, 1, __VA_ARGS__)
61-
61+
// Hard assertions are used in situations where the program definitely will crash anyway, and the reason is inexpensive to detect.
62+
#define cpAssertHard(__condition__, ...) if(!(__condition__)){cpMessage(#__condition__, __FILE__, __LINE__, 1, 1, __VA_ARGS__); abort();}
6263

6364
#include "chipmunk_types.h"
6465

@@ -89,81 +90,90 @@ typedef struct cpArray cpArray;
8990
typedef struct cpHashSet cpHashSet;
9091

9192
typedef struct cpBody cpBody;
93+
9294
typedef struct cpShape cpShape;
95+
typedef struct cpCircleShape cpCircleShape;
96+
typedef struct cpSegmentShape cpSegmentShape;
97+
typedef struct cpPolyShape cpPolyShape;
98+
9399
typedef struct cpConstraint cpConstraint;
100+
typedef struct cpPinJoint cpPinJoint;
101+
typedef struct cpSlideJoint cpSlideJoint;
102+
typedef struct cpPivotJoint cpPivotJoint;
103+
typedef struct cpGrooveJoint cpGrooveJoint;
104+
typedef struct cpDampedSpring cpDampedSpring;
105+
typedef struct cpDampedRotarySpring cpDampedRotarySpring;
106+
typedef struct cpRotaryLimitJoint cpRotaryLimitJoint;
107+
typedef struct cpRatchetJoint cpRatchetJoint;
108+
typedef struct cpGearJoint cpGearJoint;
109+
typedef struct cpSimpleMotorJoint cpSimpleMotorJoint;
94110

95111
typedef struct cpCollisionHandler cpCollisionHandler;
112+
typedef struct cpContactPointSet cpContactPointSet;
96113
typedef struct cpArbiter cpArbiter;
97114

98115
typedef struct cpSpace cpSpace;
99116

100117
#include "cpVect.h"
101118
#include "cpBB.h"
119+
#include "cpTransform.h"
102120
#include "cpSpatialIndex.h"
103121

122+
#include "cpArbiter.h"
123+
104124
#include "cpBody.h"
105125
#include "cpShape.h"
106126
#include "cpPolyShape.h"
107127

108-
#include "cpArbiter.h"
109-
#include "constraints/cpConstraint.h"
128+
#include "cpConstraint.h"
110129

111130
#include "cpSpace.h"
131+
#include "cpHastySpace.h"
112132

113-
// Chipmunk 6.2.1
114-
#define CP_VERSION_MAJOR 6
115-
#define CP_VERSION_MINOR 2
133+
// Chipmunk 7.0.1
134+
#define CP_VERSION_MAJOR 7
135+
#define CP_VERSION_MINOR 0
116136
#define CP_VERSION_RELEASE 1
117137

118138
/// Version string.
119-
extern const char *cpVersionString;
120-
121-
/// @deprecated
122-
void cpInitChipmunk(void);
123-
124-
/// Enables segment to segment shape collisions.
125-
void cpEnableSegmentToSegmentCollisions(void);
126-
139+
CP_EXPORT extern const char *cpVersionString;
127140

128141
/// Calculate the moment of inertia for a circle.
129142
/// @c r1 and @c r2 are the inner and outer diameters. A solid circle has an inner diameter of 0.
130-
cpFloat cpMomentForCircle(cpFloat m, cpFloat r1, cpFloat r2, cpVect offset);
143+
CP_EXPORT cpFloat cpMomentForCircle(cpFloat m, cpFloat r1, cpFloat r2, cpVect offset);
131144

132145
/// Calculate area of a hollow circle.
133146
/// @c r1 and @c r2 are the inner and outer diameters. A solid circle has an inner diameter of 0.
134-
cpFloat cpAreaForCircle(cpFloat r1, cpFloat r2);
147+
CP_EXPORT cpFloat cpAreaForCircle(cpFloat r1, cpFloat r2);
135148

136149
/// Calculate the moment of inertia for a line segment.
137150
/// Beveling radius is not supported.
138-
cpFloat cpMomentForSegment(cpFloat m, cpVect a, cpVect b);
151+
CP_EXPORT cpFloat cpMomentForSegment(cpFloat m, cpVect a, cpVect b, cpFloat radius);
139152

140153
/// Calculate the area of a fattened (capsule shaped) line segment.
141-
cpFloat cpAreaForSegment(cpVect a, cpVect b, cpFloat r);
154+
CP_EXPORT cpFloat cpAreaForSegment(cpVect a, cpVect b, cpFloat radius);
142155

143156
/// Calculate the moment of inertia for a solid polygon shape assuming it's center of gravity is at it's centroid. The offset is added to each vertex.
144-
cpFloat cpMomentForPoly(cpFloat m, int numVerts, const cpVect *verts, cpVect offset);
157+
CP_EXPORT cpFloat cpMomentForPoly(cpFloat m, int count, const cpVect *verts, cpVect offset, cpFloat radius);
145158

146159
/// Calculate the signed area of a polygon. A Clockwise winding gives positive area.
147160
/// This is probably backwards from what you expect, but matches Chipmunk's the winding for poly shapes.
148-
cpFloat cpAreaForPoly(const int numVerts, const cpVect *verts);
161+
CP_EXPORT cpFloat cpAreaForPoly(const int count, const cpVect *verts, cpFloat radius);
149162

150163
/// Calculate the natural centroid of a polygon.
151-
cpVect cpCentroidForPoly(const int numVerts, const cpVect *verts);
152-
153-
/// Center the polygon on the origin. (Subtracts the centroid of the polygon from each vertex)
154-
void cpRecenterPoly(const int numVerts, cpVect *verts);
164+
CP_EXPORT cpVect cpCentroidForPoly(const int count, const cpVect *verts);
155165

156166
/// Calculate the moment of inertia for a solid box.
157-
cpFloat cpMomentForBox(cpFloat m, cpFloat width, cpFloat height);
167+
CP_EXPORT cpFloat cpMomentForBox(cpFloat m, cpFloat width, cpFloat height);
158168

159169
/// Calculate the moment of inertia for a solid box.
160-
cpFloat cpMomentForBox2(cpFloat m, cpBB box);
170+
CP_EXPORT cpFloat cpMomentForBox2(cpFloat m, cpBB box);
161171

162172
/// Calculate the convex hull of a given set of points. Returns the count of points in the hull.
163-
/// @c result must be a pointer to a @c cpVect array with at least @c count elements. If @c result is @c NULL, then @c verts will be reduced instead.
173+
/// @c result must be a pointer to a @c cpVect array with at least @c count elements. If @c verts == @c result, then @c verts will be reduced inplace.
164174
/// @c first is an optional pointer to an integer to store where the first vertex in the hull came from (i.e. verts[first] == result[0])
165175
/// @c tol is the allowed amount to shrink the hull when simplifying it. A tolerance of 0.0 creates an exact hull.
166-
int cpConvexHull(int count, cpVect *verts, cpVect *result, int *first, cpFloat tol);
176+
CP_EXPORT int cpConvexHull(int count, const cpVect *verts, cpVect *result, int *first, cpFloat tol);
167177

168178
#ifdef _MSC_VER
169179
#include "malloc.h"
@@ -177,6 +187,15 @@ int cpConvexHull(int count, cpVect *verts, cpVect *result, int *first, cpFloat t
177187
cpVect *__verts_var__ = (cpVect *)alloca(__count__*sizeof(cpVect)); \
178188
int __count_var__ = cpConvexHull(__count__, __verts__, __verts_var__, NULL, 0.0); \
179189

190+
/// Returns the closest point on the line segment ab, to the point p.
191+
static inline cpVect
192+
cpClosetPointOnSegment(const cpVect p, const cpVect a, const cpVect b)
193+
{
194+
cpVect delta = cpvsub(a, b);
195+
cpFloat t = cpfclamp01(cpvdot(delta, cpvsub(p, b))/cpvlengthsq(delta));
196+
return cpvadd(b, cpvmult(delta, t));
197+
}
198+
180199
#if defined(__has_extension)
181200
#if __has_extension(blocks)
182201
// Define alternate block based alternatives for a few of the callback heavy functions.
@@ -191,14 +210,14 @@ void cpBodyEachShape_b(cpBody *body, void (^block)(cpShape *shape));
191210
void cpBodyEachConstraint_b(cpBody *body, void (^block)(cpConstraint *constraint));
192211
void cpBodyEachArbiter_b(cpBody *body, void (^block)(cpArbiter *arbiter));
193212

194-
typedef void (^cpSpaceNearestPointQueryBlock)(cpShape *shape, cpFloat distance, cpVect point);
195-
void cpSpaceNearestPointQuery_b(cpSpace *space, cpVect point, cpFloat maxDistance, cpLayers layers, cpGroup group, cpSpaceNearestPointQueryBlock block);
213+
typedef void (^cpSpacePointQueryBlock)(cpShape *shape, cpVect point, cpFloat distance, cpVect gradient);
214+
void cpSpacePointQuery_b(cpSpace *space, cpVect point, cpFloat maxDistance, cpShapeFilter filter, cpSpacePointQueryBlock block);
196215

197-
typedef void (^cpSpaceSegmentQueryBlock)(cpShape *shape, cpFloat t, cpVect n);
198-
void cpSpaceSegmentQuery_b(cpSpace *space, cpVect start, cpVect end, cpLayers layers, cpGroup group, cpSpaceSegmentQueryBlock block);
216+
typedef void (^cpSpaceSegmentQueryBlock)(cpShape *shape, cpVect point, cpVect normal, cpFloat alpha);
217+
void cpSpaceSegmentQuery_b(cpSpace *space, cpVect start, cpVect end, cpFloat radius, cpShapeFilter filter, cpSpaceSegmentQueryBlock block);
199218

200219
typedef void (^cpSpaceBBQueryBlock)(cpShape *shape);
201-
void cpSpaceBBQuery_b(cpSpace *space, cpBB bb, cpLayers layers, cpGroup group, cpSpaceBBQueryBlock block);
220+
void cpSpaceBBQuery_b(cpSpace *space, cpBB bb, cpShapeFilter filter, cpSpaceBBQueryBlock block);
202221

203222
typedef void (^cpSpaceShapeQueryBlock)(cpShape *shape, cpContactPointSet *points);
204223
cpBool cpSpaceShapeQuery_b(cpSpace *space, cpShape *shape, cpSpaceShapeQueryBlock block);

0 commit comments

Comments
 (0)