Skip to content

Commit

Permalink
A cleanup/comment pass
Browse files Browse the repository at this point in the history
  • Loading branch information
slembcke committed Aug 22, 2013
1 parent cf90b1f commit 9d302d9
Show file tree
Hide file tree
Showing 27 changed files with 81 additions and 175 deletions.
2 changes: 1 addition & 1 deletion Demo/ChipmunkDebugDraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ ChipmunkDebugDrawInit(void)
varying vec4 v_outline_color;

void main(void){
// TODO get rid of the GL 2.x matrix bit eventually?
// TODO: get rid of the GL 2.x matrix bit eventually?
gl_Position = gl_ModelViewProjectionMatrix*vec4(vertex, 0.0, 1.0);

v_fill_color = fill_color;
Expand Down
6 changes: 1 addition & 5 deletions Demo/ChipmunkDemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ ChipmunkDemoPrintString(char *fmt, ...)

va_list args;
va_start(args, fmt);
// TODO should use vsnprintf herep
// TODO: should use vsnprintf herep
PrintStringCursor += vsprintf(PrintStringCursor, fmt, args);
va_end(args);
}
Expand Down Expand Up @@ -560,10 +560,6 @@ extern int bench_count;
int
main(int argc, const char **argv)
{
// Segment/segment collisions need to be explicitly enabled currently.
// This will becoume enabled by default in future versions of Chipmunk.
cpEnableSegmentToSegmentCollisions();

ChipmunkDemo demo_list[] = {
LogoSmash,
PyramidStack,
Expand Down
4 changes: 2 additions & 2 deletions Demo/ChipmunkDemoShaderSupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ CompileShader(GLenum type, const char *source)
glShaderSource(shader, 1, &source, NULL);
glCompileShader(shader);

// TODO return placeholder shader instead?
// TODO: return placeholder shader instead?
cpAssertHard(CheckError(shader, GL_COMPILE_STATUS, glGetShaderiv, glGetShaderInfoLog), "Error compiling shader");

return shader;
Expand All @@ -105,7 +105,7 @@ LinkProgram(GLint vshader, GLint fshader)
cpBool
ValidateProgram(GLint program)
{
// TODO
// TODO: Implement?
return cpTrue;
}

Expand Down
2 changes: 1 addition & 1 deletion Demo/ChipmunkDemoTextSupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ ChipmunkDemoTextInit(void)
varying vec4 v_color;

void main(void){
// TODO get rid of the GL 2.x matrix bit eventually?
// TODO: get rid of the GL 2.x matrix bit eventually?
gl_Position = gl_ModelViewProjectionMatrix*vec4(vertex, 0.0, 1.0);

v_color = color;
Expand Down
2 changes: 1 addition & 1 deletion Demo/Crane.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ init(void)
// Max speed of the dolly servo
cpConstraintSetMaxBias(winchServo, 60);

// TODO cleanup
// TODO: cleanup
// Finally a box to play with
cpBody *boxBody = cpSpaceAddBody(space, cpBodyNew(30, cpMomentForBox(30, 50, 50)));
cpBodySetPos(boxBody, cpv(200, -200));
Expand Down
2 changes: 1 addition & 1 deletion Demo/Unicycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static cpBody *wheel_body;
static cpConstraint *motor;

/*
TODO
TODO:
- Clamp max angle dynamically based on output torque.
*/

Expand Down
14 changes: 4 additions & 10 deletions include/chipmunk/chipmunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
extern "C" {
#endif

// NUKE
#ifndef CP_ALLOW_PRIVATE_ACCESS
#define CP_ALLOW_PRIVATE_ACCESS 0
#endif
Expand Down Expand Up @@ -110,21 +111,14 @@ typedef struct cpSpace cpSpace;

#include "cpSpace.h"

// Chipmunk 6.1.5
#define CP_VERSION_MAJOR 6
#define CP_VERSION_MINOR 2
// Chipmunk 7.0.0
#define CP_VERSION_MAJOR 7
#define CP_VERSION_MINOR 0
#define CP_VERSION_RELEASE 0

/// Version string.
extern const char *cpVersionString;

/// @deprecated
void cpInitChipmunk(void);

/// Enables segment to segment shape collisions.
void cpEnableSegmentToSegmentCollisions(void);


/// Calculate the moment of inertia for a circle.
/// @c r1 and @c r2 are the inner and outer diameters. A solid circle has an inner diameter of 0.
cpFloat cpMomentForCircle(cpFloat m, cpFloat r1, cpFloat r2, cpVect offset);
Expand Down
3 changes: 3 additions & 0 deletions include/chipmunk/chipmunk_ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// Create non static inlined copies of Chipmunk functions, useful for working with dynamic FFIs
// This file should only be included in chipmunk.c

// TODO: get rid of the reliance on static inlines.
// They make a mess for FFIs.

#ifdef _MSC_VER
#if _MSC_VER >= 1600
#define MAKE_REF(name) decltype(name) *_##name = name
Expand Down
4 changes: 2 additions & 2 deletions include/chipmunk/chipmunk_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void cpBodyRemoveConstraint(cpBody *body, cpConstraint *constraint);

//MARK: Shape/Collision Functions

// TODO should move this to the cpVect API. It's pretty useful.
// TODO: should move this to the cpVect API. It's pretty useful.
static inline cpVect
cpClosetPointOnSegment(const cpVect p, const cpVect a, const cpVect b)
{
Expand Down Expand Up @@ -146,7 +146,7 @@ CircleSegmentQuery(cpShape *shape, cpVect center, cpFloat r, cpVect a, cpVect b,
}
}

// TODO doesn't really need to be inline, but need a better place to put this function
// NUKE
static inline cpSplittingPlane
cpSplittingPlaneNew(cpVect a, cpVect b)
{
Expand Down
1 change: 1 addition & 0 deletions include/chipmunk/chipmunk_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ typedef uint32_t cpCollisionID;
typedef struct cpVect{cpFloat x,y;} cpVect;
#endif

// NUKE
typedef struct cpMat2x2 {
// Row major [[a, b][c d]]
cpFloat a, b, c, d;
Expand Down
2 changes: 1 addition & 1 deletion include/chipmunk/cpBB.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ cpBBClampVect(const cpBB bb, const cpVect v)
return cpv(cpfclamp(v.x, bb.l, bb.r), cpfclamp(v.y, bb.b, bb.t));
}

// TODO edge case issue
// TODO: edge case issue
/// Wrap a vector to a bounding box.
cpVect cpBBWrapVect(const cpBB bb, const cpVect v); // wrap a vector to a bbox

Expand Down
2 changes: 1 addition & 1 deletion include/chipmunk/cpBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ static inline void cpBodySet##name(cpBody *body, const type value){ \
CP_DefineBodyStructGetter(type, member, name) \
CP_DefineBodyStructSetter(type, member, name)

// TODO add to docs
// TODO: add to docs
CP_DefineBodyStructGetter(cpSpace*, CP_PRIVATE(space), Space)

CP_DefineBodyStructGetter(cpFloat, m, Mass)
Expand Down
5 changes: 5 additions & 0 deletions include/chipmunk/cpPolyShape.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ typedef struct cpPolyShape {

int numVerts;
cpVect *verts, *tVerts;

// NUKE
cpSplittingPlane *planes, *tPlanes;

cpFloat r;
} cpPolyShape;

// TODO: Clean up naming here.
// Use transforms.

/// Allocate a polygon shape.
cpPolyShape* cpPolyShapeAlloc(void);
/// Initialize a polygon shape.
Expand Down
15 changes: 8 additions & 7 deletions include/chipmunk/cpSpace.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ struct cpSpace {
CP_PRIVATE(cpBody _staticBody);
};

// TODO: Make timestep a parameter?

/// Allocate a cpSpace.
cpSpace* cpSpaceAlloc(void);
/// Initialize a cpSpace.
Expand Down Expand Up @@ -147,6 +149,9 @@ cpSpaceIsLocked(cpSpace *space)
return space->CP_PRIVATE(locked);
}

// TODO: Handlers should return a struct that can be filled in.
// TODO: Implement wildcard handlers.

/// Set a default collision handler for this space.
/// The default collision handler is invoked for each colliding pair of shapes
/// that isn't explicitly handled by a specific collision handler.
Expand All @@ -172,23 +177,16 @@ void cpSpaceAddCollisionHandler(
void *data
);

/// Unset a collision handler.
void cpSpaceRemoveCollisionHandler(cpSpace *space, cpCollisionType a, cpCollisionType b);

/// Add a collision shape to the simulation.
/// If the shape is attached to a static body, it will be added as a static shape.
cpShape* cpSpaceAddShape(cpSpace *space, cpShape *shape);
/// Explicity add a shape as a static shape to the simulation.
cpShape* cpSpaceAddStaticShape(cpSpace *space, cpShape *shape);
/// Add a rigid body to the simulation.
cpBody* cpSpaceAddBody(cpSpace *space, cpBody *body);
/// Add a constraint to the simulation.
cpConstraint* cpSpaceAddConstraint(cpSpace *space, cpConstraint *constraint);

/// Remove a collision shape from the simulation.
void cpSpaceRemoveShape(cpSpace *space, cpShape *shape);
/// Remove a collision shape added using cpSpaceAddStaticShape() from the simulation.
void cpSpaceRemoveStaticShape(cpSpace *space, cpShape *shape);
/// Remove a rigid body from the simulation.
void cpSpaceRemoveBody(cpSpace *space, cpBody *body);
/// Remove a constraint from the simulation.
Expand Down Expand Up @@ -216,6 +214,9 @@ typedef void (*cpPostStepFunc)(cpSpace *space, void *key, void *data);
/// It's possible to pass @c NULL for @c func if you only want to mark @c key as being used.
cpBool cpSpaceAddPostStepCallback(cpSpace *space, cpPostStepFunc func, void *key, void *data);

// TODO: Queries and iterators should take a cpSpace parametery.
// TODO: They should also be abortable.

/// Point query callback function type.
typedef void (*cpSpacePointQueryFunc)(cpShape *shape, void *data);
/// Query the space at a point and call @c func for each shape found.
Expand Down
1 change: 1 addition & 0 deletions include/chipmunk/cpVect.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ static inline cpBool cpvnear(const cpVect v1, const cpVect v2, const cpFloat dis
/// 2x2 matrix type used for tensors and such.
/// @{

// NUKE
static inline cpMat2x2
cpMat2x2New(cpFloat a, cpFloat b, cpFloat c, cpFloat d)
{
Expand Down
8 changes: 1 addition & 7 deletions src/chipmunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ cpMessage(const char *condition, const char *file, int line, cpBool isError, cpB

const char *cpVersionString = XSTR(CP_VERSION_MAJOR)"."XSTR(CP_VERSION_MINOR)"."XSTR(CP_VERSION_RELEASE);

void
cpInitChipmunk(void)
{
cpAssertWarn(cpFalse, "cpInitChipmunk is deprecated and no longer required. It will be removed in the future.");
}

//MARK: Misc Functions

cpFloat
Expand Down Expand Up @@ -152,7 +146,7 @@ cpMomentForBox2(cpFloat m, cpBB box)
cpFloat height = box.t - box.b;
cpVect offset = cpvmult(cpv(box.l + box.r, box.b + box.t), 0.5f);

// TODO NaN when offset is 0 and m is INFINITY
// TODO: NaN when offset is 0 and m is INFINITY
return cpMomentForBox(m, width, height) + m*cpvlengthsq(offset);
}

Expand Down
3 changes: 2 additions & 1 deletion src/constraints/cpConstraint.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ cpConstraintFree(cpConstraint *constraint)
}
}

// *** declared in util.h TODO move declaration to chipmunk_private.h
// *** declared in util.h
// TODO: move declaration to chipmunk_private.h

void
cpConstraintInit(cpConstraint *constraint, const cpConstraintClass *klass, cpBody *a, cpBody *b)
Expand Down
4 changes: 2 additions & 2 deletions src/cpArbiter.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ cpCollisionInfoPushContact(cpCollisionInfo *info, cpVect r1, cpVect r2, cpVect n
info->count++;
}

// TODO make this generic so I can reuse it for constraints also.
// TODO: make this generic so I can reuse it for constraints also.
static inline void
unthreadHelper(cpArbiter *arb, cpBody *body)
{
Expand Down Expand Up @@ -320,7 +320,7 @@ cpArbiterApplyCachedImpulse(cpArbiter *arb, cpFloat dt_coef)
}
}

// TODO is it worth splitting velocity/position correction?
// TODO: is it worth splitting velocity/position correction?

void
cpArbiterApplyImpulse(cpArbiter *arb)
Expand Down
23 changes: 0 additions & 23 deletions src/cpArray.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,6 @@ cpArrayPop(cpArray *arr)
return value;
}

//static void
//cpArrayDeleteIndex(cpArray *arr, int idx)
//{
// arr->num--;
//
// arr->arr[idx] = arr->arr[arr->num];
// arr->arr[arr->num] = NULL;
//}

void
cpArrayDeleteObj(cpArray *arr, void *obj)
{
Expand All @@ -94,20 +85,6 @@ cpArrayDeleteObj(cpArray *arr, void *obj)
}
}

//void
//cpArrayAppend(cpArray *arr, cpArray *other)
//{
// void *tail = &arr->arr[arr->num];
//
// arr->num += other->num;
// if(arr->num >= arr->max){
// arr->max = arr->num;
// arr->arr = (void **)cprealloc(arr->arr, arr->max*sizeof(void**));
// }
//
// memcpy(tail, other->arr, other->num*sizeof(void**));
//}

void
cpArrayFreeEach(cpArray *arr, void (freeFunc)(void*))
{
Expand Down
6 changes: 3 additions & 3 deletions src/cpBBTree.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static void
PairRecycle(cpBBTree *tree, Pair *pair)
{
// Share the pool of the master tree.
// TODO would be lovely to move the pairs stuff into an external data structure.
// TODO: would be lovely to move the pairs stuff into an external data structure.
tree = GetMasterTree(tree);

pair->a.next = tree->pooledPairs;
Expand All @@ -143,7 +143,7 @@ static Pair *
PairFromPool(cpBBTree *tree)
{
// Share the pool of the master tree.
// TODO would be lovely to move the pairs stuff into an external data structure.
// TODO: would be lovely to move the pairs stuff into an external data structure.
tree = GetMasterTree(tree);

Pair *pair = tree->pooledPairs;
Expand Down Expand Up @@ -475,7 +475,7 @@ MarkSubtree(Node *subtree, MarkContext *context)
MarkLeaf(subtree, context);
} else {
MarkSubtree(subtree->A, context);
MarkSubtree(subtree->B, context); // TODO Force TCO here?
MarkSubtree(subtree->B, context); // TODO: Force TCO here?
}
}

Expand Down
Loading

0 comments on commit 9d302d9

Please sign in to comment.