Skip to content
Permalink
Browse files

A cleanup/comment pass

  • Loading branch information...
slembcke committed Aug 22, 2013
1 parent cf90b1f commit 9d302d9538c9245bf1c050702fab9bac12d1b472
@@ -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;
@@ -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);
}
@@ -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,
@@ -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;
@@ -105,7 +105,7 @@ LinkProgram(GLint vshader, GLint fshader)
cpBool
ValidateProgram(GLint program)
{
// TODO
// TODO: Implement?
return cpTrue;
}

@@ -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;
@@ -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));
@@ -32,7 +32,7 @@ static cpBody *wheel_body;
static cpConstraint *motor;

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

@@ -33,6 +33,7 @@
extern "C" {
#endif

// NUKE
#ifndef CP_ALLOW_PRIVATE_ACCESS
#define CP_ALLOW_PRIVATE_ACCESS 0
#endif
@@ -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);
@@ -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
@@ -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)
{
@@ -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)
{
@@ -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;
@@ -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

@@ -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)
@@ -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.
@@ -105,6 +105,8 @@ struct cpSpace {
CP_PRIVATE(cpBody _staticBody);
};

// TODO: Make timestep a parameter?

/// Allocate a cpSpace.
cpSpace* cpSpaceAlloc(void);
/// Initialize a cpSpace.
@@ -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.
@@ -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.
@@ -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.
@@ -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)
{
@@ -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
@@ -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);
}

@@ -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)
@@ -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)
{
@@ -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)
@@ -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)
{
@@ -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*))
{
@@ -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;
@@ -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;
@@ -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?
}
}

0 comments on commit 9d302d9

Please sign in to comment.
You can’t perform that action at this time.