Skip to content

Commit 5dd7d77

Browse files
authored
Merge branch 'slembcke:master' into master
2 parents 0593976 + 79d9eca commit 5dd7d77

File tree

10 files changed

+38
-23
lines changed

10 files changed

+38
-23
lines changed

VERSION.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ Keep in mind that this is a x.0.0 release and that it's likely there are still s
210210
What's new in 5.3.5
211211
* FIX: Fixed spelling of cpArbiterGetDepth(). Was cpArbiteGetDepth() before. Apparently nobody ever used this function.
212212
* FIX: Added defines for M_PI and M_E. Apparently these values were never part of the C standard math library. Who knew!?
213-
* FIX: Added a guard to cpBodyActivate() so that it's a noop for rouge bodies.
213+
* FIX: Added a guard to cpBodyActivate() so that it's a noop for rogue bodies.
214214
* FIX: Shape queries now work with (and against) sensor shapes.
215215
* FIX: Fixed an issue where removing a collision handler while a separate() callback was waiting to fire the next step would cause crashes.
216216
* FIX: Fixed an issue where the default callback would not be called for sensor shapes.
@@ -297,4 +297,4 @@ What's new in 5.1.0:
297297
What's new in 5.0.0:
298298
* Brand new Joint/Constraint API: New constraints can be added easily and are much more flexible than the old joint system
299299
* Efficient Segment Queries - Like raycasting, but with line segments.
300-
* Brand new collision callback API: Collision begin/separate events, API for removal of objects within callbacks, more programable control over collision handling.
300+
* Brand new collision callback API: Collision begin/separate events, API for removal of objects within callbacks, more programable control over collision handling.

demo/ChipmunkDebugDraw.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,21 @@
2323
#include <stddef.h>
2424
#include <string.h>
2525

26-
#include "sokol/sokol_gfx.h"
26+
#include "sokol/sokol.h"
2727

2828
#include "chipmunk/chipmunk_private.h"
2929
#include "ChipmunkDebugDraw.h"
3030

3131
cpTransform ChipmunkDebugDrawVPMatrix;
3232
float ChipmunkDebugDrawPointLineScale = 1.0f;
3333

34-
#define GLSL33(x) "#version 330\n" #x
34+
#ifdef SOKOL_GLCORE33
35+
#define GLSL(x) "#version 330\n" #x
36+
#endif
37+
#ifdef SOKOL_GLES3
38+
#define GLSL(x) "#version 300 es\n" #x
39+
#endif
40+
3541

3642
static sg_bindings bindings;
3743
static sg_pipeline pipeline;
@@ -84,7 +90,7 @@ ChipmunkDebugDrawInit(void)
8490
.size = sizeof(Uniforms),
8591
.uniforms[0] = {.name = "U_vp_matrix", .type = SG_UNIFORMTYPE_MAT4},
8692
},
87-
.vs.source = GLSL33(
93+
.vs.source = GLSL(
8894
layout(location = 0) in vec2 IN_pos;
8995
layout(location = 1) in vec2 IN_uv;
9096
layout(location = 2) in float IN_radius;
@@ -100,15 +106,16 @@ ChipmunkDebugDrawInit(void)
100106
} FRAG;
101107

102108
void main(){
103-
gl_Position = U_vp_matrix*vec4(IN_pos + IN_radius*IN_uv, 0, 1);
109+
gl_Position = U_vp_matrix*vec4(IN_pos + IN_radius*IN_uv, 0.0, 1.0);
104110
FRAG.uv = IN_uv;
105111
FRAG.fill = IN_fill;
106112
FRAG.fill.rgb *= IN_fill.a;
107113
FRAG.outline = IN_outline;
108114
FRAG.outline.a *= IN_outline.a;
109115
}
110116
),
111-
.fs.source = GLSL33(
117+
.fs.source = GLSL(
118+
precision mediump float;
112119
in struct {
113120
vec2 uv;
114121
vec4 fill;
@@ -119,10 +126,10 @@ ChipmunkDebugDrawInit(void)
119126

120127
void main(){
121128
float len = length(FRAG.uv);
122-
float fw = length(fwidth(FRAG.uv));
123-
float mask = smoothstep(-1, fw - 1, -len);
129+
float fw = length(vec2(dFdx(len), dFdy(len)));
130+
float mask = smoothstep(-1.0, fw - 1.0, -len);
124131

125-
float outline = 1 - fw;
132+
float outline = 1.0 - fw;
126133
float outline_mask = smoothstep(outline - fw, outline, len);
127134
vec4 color = FRAG.fill + (FRAG.outline - FRAG.fill*FRAG.outline.a)*outline_mask;
128135
OUT_color = color*mask;
@@ -273,7 +280,7 @@ void ChipmunkDebugDrawPolygon(int count, const cpVect *verts, cpFloat radius, cp
273280

274281
void ChipmunkDebugDrawBB(cpBB bb, cpSpaceDebugColor color)
275282
{
276-
cpVect verts[] = {
283+
cpVect verts[4] = {
277284
cpv(bb.r, bb.b),
278285
cpv(bb.r, bb.t),
279286
cpv(bb.l, bb.t),

demo/ChipmunkDemoTextSupport.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <stddef.h>
2323
#include <string.h>
2424

25-
#include "sokol/sokol_gfx.h"
25+
#include "sokol/sokol.h"
2626

2727
// #include "chipmunk/chipmunk_private.h"
2828
// #include "ChipmunkDemo.h"
@@ -39,7 +39,12 @@ static int glyph_indexes[256];
3939

4040
cpTransform ChipmunkDemoTextMatrix;
4141

42-
#define GLSL33(x) "#version 330\n" #x
42+
#ifdef SOKOL_GLCORE33
43+
#define GLSL(x) "#version 330\n" #x
44+
#endif
45+
#ifdef SOKOL_GLES3
46+
#define GLSL(x) "#version 300 es\n" #x
47+
#endif
4348

4449
static sg_bindings bindings;
4550
static sg_pipeline pipeline;
@@ -102,7 +107,7 @@ ChipmunkDemoTextInit(void)
102107
.size = sizeof(Uniforms),
103108
.uniforms[0] = {.name = "U_vp_matrix", .type = SG_UNIFORMTYPE_MAT4},
104109
},
105-
.vs.source = GLSL33(
110+
.vs.source = GLSL(
106111
layout(location = 0) in vec2 IN_pos;
107112
layout(location = 1) in vec2 IN_uv;
108113
layout(location = 2) in vec4 IN_color;
@@ -115,13 +120,14 @@ ChipmunkDemoTextInit(void)
115120
} FRAG;
116121

117122
void main(){
118-
gl_Position = U_vp_matrix*vec4(IN_pos, 0, 1);
123+
gl_Position = U_vp_matrix*vec4(IN_pos, 0.0, 1.0);
119124
FRAG.uv = IN_uv;
120125
FRAG.color = IN_color;
121126
}
122127
),
123128
.fs.images[0] = {.name = "U_texture", .type = SG_IMAGETYPE_2D},
124-
.fs.source = GLSL33(
129+
.fs.source = GLSL(
130+
precision mediump float;
125131
in struct {
126132
vec2 uv;
127133
vec4 color;

demo/Planet.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ add_box(cpSpace *space)
6262
const cpFloat size = 10.0f;
6363
const cpFloat mass = 1.0f;
6464

65-
cpVect verts[] = {
65+
cpVect verts[4] = {
6666
cpv(-size,-size),
6767
cpv(-size, size),
6868
cpv( size, size),
@@ -95,10 +95,10 @@ add_box(cpSpace *space)
9595
static cpSpace *
9696
init(void)
9797
{
98-
// Create a rouge body to control the planet manually.
9998
cpSpace *space = cpSpaceNew();
10099
cpSpaceSetIterations(space, 20);
101100

101+
// Create a kinematic body to control the planet manually.
102102
planetBody = cpSpaceAddBody(space, cpBodyNewKinematic());
103103
cpBodySetAngularVelocity(planetBody, 0.2f);
104104

demo/Plink.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ init(void)
7272
cpShape *shape;
7373

7474
// Vertexes for a triangle shape.
75-
cpVect tris[] = {
75+
cpVect tris[4] = {
7676
cpv(-15,-15),
7777
cpv( 0, 10),
7878
cpv( 15,-15),

demo/Pump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ init(void)
109109
cpShapeSetFriction(shape, 0.5f);
110110
cpShapeSetFilter(shape, NOT_GRABBABLE_FILTER);
111111

112-
cpVect verts[] = {
112+
cpVect verts[4] = {
113113
cpv(-30,-80),
114114
cpv(-30, 80),
115115
cpv( 30, 64),

demo/sokol/sokol.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#define SOKOL_WIN32_FORCE_MAIN
2+
#ifndef SOKOL_GLES3
23
#define SOKOL_GLCORE33
4+
#endif
35
#include "sokol_app.h"
46
#include "sokol_time.h"
57
#include "sokol_gfx.h"

doc-src/chipmunk-docs.textile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ Static bodies are bodies that never (or rarely) move. Using static bodies for th
274274
A graphics engine only needs to know the position of an object for each frame that its drawn. For a physics engine, this isn't enough information to calculate a collision response. When you set the position of a body, you are effectively asking it to teleport itself. This means that it will instantly move to its new position instead of moving through space and time like a normal object. If you teleport an object so that it overlaps another one, the best the physics engine can do is to attempt to push the objects apart again since there is no information about their movement. This generally results in very mushy looking collisions. So instead of setting the position of an object, it's better to set its velocity and allow the physics engine to update the position. That way it can resolve any resulting colisions natuarally since it knows how the objects were moving. This is why kinematic bodies work the way they do. You set the velocity, and the physics updates their position so the two are never out of sync.
275275

276276

277-
For dynamic bodies, setting the velocity explicitly every frame can cause problems. For example, a problem occurs when a light dynamic body (like a person) is pressed against a heavy dynamic body (like a car), and you set velocity of the small object so that it's pushing it into the big body. To the physics engine, the change in velocity is the same as applying a large impulse (a very short, very large force). Even if the velocity is low, the large force can allow the small body to push the big body, even when it normally wouldn't be able to. For example, a person walking into a car can overpower the car's friction and cause it to creep along the ground slowly. Additionally, when you set the velocity of an object that is already in contact, it can cause the two objects to overlap by a small amount. The easiest way to avoid both of these problems is to make smaller changes to the body's velocity, accelerating it over a fraction of a second instead of a single frame. An even better solution, which is covered more thoroughly later, is to use constraints to move the object.
277+
For dynamic bodies, setting the velocity explicitly every frame can cause problems. For example, a problem occurs when a light dynamic body (like a person) is pressed against a heavy dynamic body (like a car), and you set velocity of the small object so that it's pushing it into the big body. To the physics engine, the change in velocity is the same as applying a large impulse (a very short, very large force). Even if the velocity is low, the large force can allow the small body to push the big body, even when it normally wouldn't be able to. For example, a person walking into a car can overpower the car's friction and cause it to creep along the ground slowly. Additionally, when you set the velocity of an object that is already in contact, it can cause the two objects to overlap by a small amount. The easiest way to avoid both of these problems is to make smaller changes to the body's velocity, accelerating it over a fraction of a second instead of a single frame. An even better solution is to use constraints to move the object. For an example, look at how the Tank and Crane demos drive their constraints and use the maximum bias and force properties. The mouse control in the demo application works the same way.
278278

279279
<%= h 2, "Memory Management Functions:", "Memory" %>
280280

include/chipmunk/chipmunk_structs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ struct cpSpace {
428428
cpArray *pooledArbiters;
429429

430430
cpArray *allocatedBuffers;
431-
unsigned int locked;
431+
int locked;
432432

433433
cpBool usesWildcards;
434434
cpHashSet *collisionHandlers;

src/cpPolyShape.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ cpBoxShapeInit(cpPolyShape *poly, cpBody *body, cpFloat width, cpFloat height, c
234234
cpPolyShape *
235235
cpBoxShapeInit2(cpPolyShape *poly, cpBody *body, cpBB box, cpFloat radius)
236236
{
237-
cpVect verts[] = {
237+
cpVect verts[4] = {
238238
cpv(box.r, box.b),
239239
cpv(box.r, box.t),
240240
cpv(box.l, box.t),

0 commit comments

Comments
 (0)