This commit is contained in:
natural-law 2011-07-11 15:17:24 +08:00
commit 58733417e0
35 changed files with 222 additions and 163 deletions

View File

@ -200,11 +200,21 @@ public class Cocos2dxBitmap{
LinkedList<String> strList = new LinkedList<String>();
/*
* Break a String into String[] by the width
* Break a String into String[] by the width & should wrap the word
*/
for (int i = 1; i <= charLength; ++i){
tempWidth = (int)Math.ceil(paint.measureText(content, start, i));
if (tempWidth >= width){
int lastIndexOfSpace = content.substring(0, i).lastIndexOf(" ");
if (lastIndexOfSpace != -1){
/**
* Should wrap the word
*/
strList.add(content.substring(start, lastIndexOfSpace));
i = lastIndexOfSpace;
}
else {
/*
* Should not exceed the width
*/
@ -218,6 +228,7 @@ public class Cocos2dxBitmap{
else {
strList.add(content.substring(start, i));
}
}
start = i;
}

View File

@ -200,11 +200,21 @@ public class Cocos2dxBitmap{
LinkedList<String> strList = new LinkedList<String>();
/*
* Break a String into String[] by the width
* Break a String into String[] by the width & should wrap the word
*/
for (int i = 1; i <= charLength; ++i){
tempWidth = (int)Math.ceil(paint.measureText(content, start, i));
if (tempWidth >= width){
int lastIndexOfSpace = content.substring(0, i).lastIndexOf(" ");
if (lastIndexOfSpace != -1){
/**
* Should wrap the word
*/
strList.add(content.substring(start, lastIndexOfSpace));
i = lastIndexOfSpace;
}
else {
/*
* Should not exceed the width
*/
@ -218,6 +228,7 @@ public class Cocos2dxBitmap{
else {
strList.add(content.substring(start, i));
}
}
start = i;
}

View File

@ -51,26 +51,6 @@ void cpMessage(const char *message, const char *condition, const char *file, int
#include "chipmunk_types.h"
#ifndef INFINITY
#ifdef _MSC_VER
union MSVC_EVIL_FLOAT_HACK
{
unsigned __int8 Bytes[4];
float Value;
};
static union MSVC_EVIL_FLOAT_HACK INFINITY_HACK = {{0x00, 0x00, 0x80, 0x7F}};
#define INFINITY (INFINITY_HACK.Value)
#endif
#ifdef __GNUC__
#define INFINITY (__builtin_inf())
#endif
#ifndef INFINITY
#define INFINITY (1e1000)
#endif
#endif
// Maximum allocated size for various Chipmunk buffers
#define CP_BUFFER_BYTES (32*1024)

View File

@ -58,6 +58,35 @@
#define cpfceil ceilf
#endif
#ifndef INFINITY
#ifdef _MSC_VER
union MSVC_EVIL_FLOAT_HACK
{
unsigned __int8 Bytes[4];
float Value;
};
static union MSVC_EVIL_FLOAT_HACK INFINITY_HACK = {{0x00, 0x00, 0x80, 0x7F}};
#define INFINITY (INFINITY_HACK.Value)
#endif
#ifdef __GNUC__
#define INFINITY (__builtin_inf())
#endif
#ifndef INFINITY
#define INFINITY (1e1000)
#endif
#endif
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327950288
#endif
#ifndef M_E
#define M_E 2.71828182845904523536028747135266250
#endif
static inline cpFloat
cpfmax(cpFloat a, cpFloat b)
{
@ -138,7 +167,7 @@ typedef unsigned int cpHashValue;
#endif
#ifdef CP_LAYERS_TYPE
typedef CP_GROUP_TYPE cpLayers;
typedef CP_LAYERS_TYPE cpLayers;
#else
typedef unsigned int cpLayers;
#endif

View File

@ -51,11 +51,17 @@ normal_relative_velocity(cpBody *a, cpBody *b, cpVect r1, cpVect r2, cpVect n){
return cpvdot(relative_velocity(a, b, r1, r2), n);
}
static inline void
apply_impulse(cpBody *body, cpVect j, cpVect r){
body->v = cpvadd(body->v, cpvmult(j, body->m_inv));
body->w += body->i_inv*cpvcross(r, j);
}
static inline void
apply_impulses(cpBody *a , cpBody *b, cpVect r1, cpVect r2, cpVect j)
{
cpBodyApplyImpulse(a, cpvneg(j), r1);
cpBodyApplyImpulse(b, j, r2);
apply_impulse(a, cpvneg(j), r1);
apply_impulse(b, j, r2);
}
static inline void

View File

@ -157,7 +157,7 @@ cpArbiterGetPoint(const cpArbiter *arb, int i)
}
static inline cpFloat
cpArbiteGetDepth(const cpArbiter *arb, int i)
cpArbiterGetDepth(const cpArbiter *arb, int i)
{
return arb->CP_PRIVATE(contacts)[i].CP_PRIVATE(dist);
}

View File

@ -192,18 +192,12 @@ cpBodyWorld2Local(const cpBody *body, const cpVect v)
return cpvunrotate(cpvsub(v, body->p), body->rot);
}
// Apply an impulse (in world coordinates) to the body at a point relative to the center of gravity (also in world coordinates).
static inline void
cpBodyApplyImpulse(cpBody *body, const cpVect j, const cpVect r)
{
body->v = cpvadd(body->v, cpvmult(j, body->m_inv));
body->w += body->i_inv*cpvcross(r, j);
}
// Zero the forces on a body.
void cpBodyResetForces(cpBody *body);
// Apply a force (in world coordinates) to a body at a point relative to the center of gravity (also in world coordinates).
void cpBodyApplyForce(cpBody *body, const cpVect f, const cpVect r);
// Apply an impulse (in world coordinates) to the body at a point relative to the center of gravity (also in world coordinates).
void cpBodyApplyImpulse(cpBody *body, const cpVect j, const cpVect r);
static inline cpFloat
cpBodyKineticEnergy(const cpBody *body)

View File

@ -29,7 +29,7 @@ typedef struct cpPolyShapeAxis{
// Convex polygon shape structure.
typedef struct cpPolyShape{
CP_PRIVATE(cpShape shape);
cpShape shape;
// Vertex and axis lists.
CP_PRIVATE(int numVerts);

View File

@ -114,7 +114,7 @@ cpBool cpShapePointQuery(cpShape *shape, cpVect p);
// Circle shape structure.
typedef struct cpCircleShape{
CP_PRIVATE(cpShape shape);
cpShape shape;
// Center in body space coordinates
CP_PRIVATE(cpVect c);
@ -135,7 +135,7 @@ CP_DeclareShapeGetter(cpCircleShape, cpFloat, Radius);
// Segment shape structure.
typedef struct cpSegmentShape{
CP_PRIVATE(cpShape shape);
cpShape shape;
// Endpoints and normal of the segment. (body space coordinates)
cpVect CP_PRIVATE(a), CP_PRIVATE(b), CP_PRIVATE(n);

View File

@ -42,6 +42,8 @@ typedef struct cpCollisionHandler {
void *data;
} cpCollisionHandler;
extern cpCollisionHandler cpSpaceDefaultHandler;
typedef struct cpContactBufferHeader {
cpTimestamp stamp;
struct cpContactBufferHeader *next;

View File

@ -9,7 +9,7 @@ if(BUILD_SHARED)
${chipmunk_source_files}
)
# set the lib's version number
set_target_properties(chipmunk PROPERTIES VERSION 5.3.4)
set_target_properties(chipmunk PROPERTIES VERSION 5.3.5)
install(TARGETS chipmunk RUNTIME DESTINATION lib LIBRARY DESTINATION lib)
endif(BUILD_SHARED)

View File

@ -45,7 +45,7 @@ cpMessage(const char *message, const char *condition, const char *file, int line
}
const char *cpVersionString = "5.3.4";
const char *cpVersionString = "5.3.5";
void
cpInitChipmunk(void)

View File

@ -83,7 +83,7 @@ CP_DefineClassGetter(cpDampedRotarySpring)
cpDampedRotarySpring *
cpDampedRotarySpringAlloc(void)
{
return (cpDampedRotarySpring *)cpmalloc(sizeof(cpDampedRotarySpring));
return (cpDampedRotarySpring *)cpcalloc(1, sizeof(cpDampedRotarySpring));
}
cpDampedRotarySpring *

View File

@ -89,7 +89,7 @@ CP_DefineClassGetter(cpDampedSpring)
cpDampedSpring *
cpDampedSpringAlloc(void)
{
return (cpDampedSpring *)cpmalloc(sizeof(cpDampedSpring));
return (cpDampedSpring *)cpcalloc(1, sizeof(cpDampedSpring));
}
cpDampedSpring *

View File

@ -80,7 +80,7 @@ CP_DefineClassGetter(cpGearJoint)
cpGearJoint *
cpGearJointAlloc(void)
{
return (cpGearJoint *)cpmalloc(sizeof(cpGearJoint));
return (cpGearJoint *)cpcalloc(1, sizeof(cpGearJoint));
}
cpGearJoint *

View File

@ -111,7 +111,7 @@ CP_DefineClassGetter(cpGrooveJoint)
cpGrooveJoint *
cpGrooveJointAlloc(void)
{
return (cpGrooveJoint *)cpmalloc(sizeof(cpGrooveJoint));
return (cpGrooveJoint *)cpcalloc(1, sizeof(cpGrooveJoint));
}
cpGrooveJoint *

View File

@ -88,7 +88,7 @@ CP_DefineClassGetter(cpPinJoint);
cpPinJoint *
cpPinJointAlloc(void)
{
return (cpPinJoint *)cpmalloc(sizeof(cpPinJoint));
return (cpPinJoint *)cpcalloc(1, sizeof(cpPinJoint));
}
cpPinJoint *

View File

@ -83,7 +83,7 @@ CP_DefineClassGetter(cpPivotJoint)
cpPivotJoint *
cpPivotJointAlloc(void)
{
return (cpPivotJoint *)cpmalloc(sizeof(cpPivotJoint));
return (cpPivotJoint *)cpcalloc(1, sizeof(cpPivotJoint));
}
cpPivotJoint *

View File

@ -101,7 +101,7 @@ CP_DefineClassGetter(cpRatchetJoint)
cpRatchetJoint *
cpRatchetJointAlloc(void)
{
return (cpRatchetJoint *)cpmalloc(sizeof(cpRatchetJoint));
return (cpRatchetJoint *)cpcalloc(1, sizeof(cpRatchetJoint));
}
cpRatchetJoint *

View File

@ -97,7 +97,7 @@ CP_DefineClassGetter(cpRotaryLimitJoint)
cpRotaryLimitJoint *
cpRotaryLimitJointAlloc(void)
{
return (cpRotaryLimitJoint *)cpmalloc(sizeof(cpRotaryLimitJoint));
return (cpRotaryLimitJoint *)cpcalloc(1, sizeof(cpRotaryLimitJoint));
}
cpRotaryLimitJoint *

View File

@ -75,7 +75,7 @@ CP_DefineClassGetter(cpSimpleMotor)
cpSimpleMotor *
cpSimpleMotorAlloc(void)
{
return (cpSimpleMotor *)cpmalloc(sizeof(cpSimpleMotor));
return (cpSimpleMotor *)cpcalloc(1, sizeof(cpSimpleMotor));
}
cpSimpleMotor *

View File

@ -104,7 +104,7 @@ CP_DefineClassGetter(cpSlideJoint)
cpSlideJoint *
cpSlideJointAlloc(void)
{
return (cpSlideJoint *)cpmalloc(sizeof(cpSlideJoint));
return (cpSlideJoint *)cpcalloc(1, sizeof(cpSlideJoint));
}
cpSlideJoint *

View File

@ -42,7 +42,7 @@ cpArrayInit(cpArray *arr, int size)
size = (size ? size : 4);
arr->max = size;
arr->arr = (void **)cpmalloc(size*sizeof(void**));
arr->arr = (void **)cpcalloc(size, sizeof(void**));
return arr;
}

View File

@ -24,6 +24,7 @@
#include <stdarg.h>
#include "chipmunk_private.h"
#include "constraints/util.h"
// function declaration
cpBody *cpBodyNewStatic(void);
@ -34,13 +35,13 @@ cpBody cpStaticBodySingleton;
cpBody*
cpBodyAlloc(void)
{
return (cpBody *)cpmalloc(sizeof(cpBody));
return (cpBody *)cpcalloc(1, sizeof(cpBody));
}
cpBodyVelocityFunc cpBodyUpdateVelocityDefault = cpBodyUpdateVelocity;
cpBodyPositionFunc cpBodyUpdatePositionDefault = cpBodyUpdatePosition;
cpBody*
cpBody *
cpBodyInit(cpBody *body, cpFloat m, cpFloat i)
{
body->velocity_func = cpBodyUpdateVelocityDefault;
@ -155,17 +156,28 @@ cpBodyUpdatePosition(cpBody *body, cpFloat dt)
void
cpBodyResetForces(cpBody *body)
{
cpBodyActivate(body);
body->f = cpvzero;
body->t = 0.0f;
}
void
cpBodyApplyForce(cpBody *body, cpVect force, cpVect r)
cpBodyApplyForce(cpBody *body, const cpVect force, const cpVect r)
{
cpBodyActivate(body);
body->f = cpvadd(body->f, force);
body->t += cpvcross(r, force);
}
void
cpBodyApplyImpulse(cpBody *body, const cpVect j, const cpVect r)
{
cpBodyActivate(body);
apply_impulse(body, j, r);
}
void
cpApplyDampedSpring(cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2, cpFloat rlen, cpFloat k, cpFloat dmp, cpFloat dt)
{

View File

@ -33,7 +33,7 @@ cpHashSetDestroy(cpHashSet *set)
// Free the table.
cpfree(set->table);
cpArrayEach(set->allocatedBuffers, freeWrap, NULL);
if(set->allocatedBuffers) cpArrayEach(set->allocatedBuffers, freeWrap, NULL);
cpArrayFree(set->allocatedBuffers);
}
@ -133,7 +133,7 @@ getUnusedBin(cpHashSet *set)
int count = CP_BUFFER_BYTES/sizeof(cpHashSetBin);
cpAssert(count, "Buffer size is too small.");
cpHashSetBin *buffer = (cpHashSetBin *)cpmalloc(CP_BUFFER_BYTES);
cpHashSetBin *buffer = (cpHashSetBin *)cpcalloc(1, CP_BUFFER_BYTES);
cpArrayPush(set->allocatedBuffers, buffer);
// push all but the first one, return the first instead

View File

@ -70,7 +70,7 @@ cpShapeInit(cpShape *shape, const cpShapeClass *klass, cpBody *body)
void
cpShapeDestroy(cpShape *shape)
{
if(shape->klass->destroy) shape->klass->destroy(shape);
if(shape->klass && shape->klass->destroy) shape->klass->destroy(shape);
}
void

View File

@ -49,7 +49,7 @@ contactSetTrans(cpShape **shapes, cpSpace *space)
int count = CP_BUFFER_BYTES/sizeof(cpArbiter);
cpAssert(count, "Buffer size too small.");
cpArbiter *buffer = (cpArbiter *)cpmalloc(CP_BUFFER_BYTES);
cpArbiter *buffer = (cpArbiter *)cpcalloc(1, CP_BUFFER_BYTES);
cpArrayPush(space->allocatedBuffers, buffer);
for(int i=0; i<count; i++) cpArrayPush(space->pooledArbiters, buffer + i);
@ -71,7 +71,7 @@ collFuncSetEql(cpCollisionHandler *check, cpCollisionHandler *pair)
static void *
collFuncSetTrans(cpCollisionHandler *handler, void *unused)
{
cpCollisionHandler *copy = (cpCollisionHandler *)cpmalloc(sizeof(cpCollisionHandler));
cpCollisionHandler *copy = (cpCollisionHandler *)cpcalloc(1, sizeof(cpCollisionHandler));
(*copy) = (*handler);
return copy;
@ -105,7 +105,7 @@ cpSpaceAlloc(void)
#define DEFAULT_ITERATIONS 10
#define DEFAULT_ELASTIC_ITERATIONS 0
cpCollisionHandler defaultHandler = {0, 0, alwaysCollide, alwaysCollide, nothing, nothing, NULL};
cpCollisionHandler cpSpaceDefaultHandler = {0, 0, alwaysCollide, alwaysCollide, nothing, nothing, NULL};
cpSpace*
cpSpaceInit(cpSpace *space)
@ -140,9 +140,9 @@ cpSpaceInit(cpSpace *space)
space->constraints = cpArrayNew(0);
space->defaultHandler = defaultHandler;
space->defaultHandler = cpSpaceDefaultHandler;
space->collFuncSet = cpHashSetNew(0, (cpHashSetEqlFunc)collFuncSetEql, (cpHashSetTransFunc)collFuncSetTrans);
space->collFuncSet->default_value = &space->defaultHandler;
space->collFuncSet->default_value = &cpSpaceDefaultHandler;
space->postStepCallbacks = NULL;
@ -174,20 +174,14 @@ cpSpaceDestroy(cpSpace *space)
cpArrayFree(space->arbiters);
cpArrayFree(space->pooledArbiters);
if(space->allocatedBuffers){
cpArrayEach(space->allocatedBuffers, freeWrap, NULL);
if(space->allocatedBuffers) cpArrayEach(space->allocatedBuffers, freeWrap, NULL);
cpArrayFree(space->allocatedBuffers);
}
if(space->postStepCallbacks){
cpHashSetEach(space->postStepCallbacks, freeWrap, NULL);
if(space->postStepCallbacks) cpHashSetEach(space->postStepCallbacks, freeWrap, NULL);
cpHashSetFree(space->postStepCallbacks);
}
if(space->collFuncSet){
cpHashSetEach(space->collFuncSet, freeWrap, NULL);
if(space->collFuncSet) cpHashSetEach(space->collFuncSet, freeWrap, NULL);
cpHashSetFree(space->collFuncSet);
}
}
void
@ -211,6 +205,12 @@ cpSpaceFreeChildren(cpSpace *space)
cpArrayEach(space->constraints, (cpArrayIter)&constraintFreeWrap, NULL);
}
#define cpAssertSpaceUnlocked(space) \
cpAssert(!space->locked, \
"This addition/removal cannot be done safely during a call to cpSpaceStep() or during a query. " \
"Put these calls into a post-step callback." \
);
#pragma mark Collision Handler Function Management
void
@ -223,6 +223,8 @@ cpSpaceAddCollisionHandler(
cpCollisionSeparateFunc separate,
void *data
){
cpAssertSpaceUnlocked(space);
// Remove any old function so the new one will get added.
cpSpaceRemoveCollisionHandler(space, a, b);
@ -241,6 +243,8 @@ cpSpaceAddCollisionHandler(
void
cpSpaceRemoveCollisionHandler(cpSpace *space, cpCollisionType a, cpCollisionType b)
{
cpAssertSpaceUnlocked(space);
struct{cpCollisionType a, b;} ids = {a, b};
cpCollisionHandler *old_handler = (cpCollisionHandler *) cpHashSetRemove(space->collFuncSet, CP_HASH_PAIR(a, b), &ids);
cpfree(old_handler);
@ -255,6 +259,8 @@ cpSpaceSetDefaultCollisionHandler(
cpCollisionSeparateFunc separate,
void *data
){
cpAssertSpaceUnlocked(space);
cpCollisionHandler handler = {
0, 0,
begin ? begin : alwaysCollide,
@ -265,16 +271,10 @@ cpSpaceSetDefaultCollisionHandler(
};
space->defaultHandler = handler;
space->collFuncSet->default_value = &space->defaultHandler;
}
#pragma mark Body, Shape, and Joint Management
#define cpAssertSpaceUnlocked(space) \
cpAssert(!space->locked, \
"This addition/removal cannot be done safely during a call to cpSpaceStep() or during a query. " \
"Put these calls into a post-step callback." \
);
static void
cpBodyAddShape(cpBody *body, cpShape *shape)
{
@ -479,6 +479,7 @@ cpSpaceRehashShape(cpSpace *space, cpShape *shape)
void
cpSpaceEachBody(cpSpace *space, cpSpaceBodyIterator func, void *data)
{
cpSpaceLock(space); {
cpArray *bodies = space->bodies;
for(int i=0; i<bodies->num; i++){
@ -494,6 +495,7 @@ cpSpaceEachBody(cpSpace *space, cpSpaceBodyIterator func, void *data)
func(body, data);
} while((body = next) != root);
}
} cpSpaceUnlock(space);
}

View File

@ -97,7 +97,10 @@ componentActivate(cpBody *root)
void
cpBodyActivate(cpBody *body)
{
if(!cpBodyIsRogue(body)){
body->node.idleTime = 0.0f;
componentActivate(componentNodeRoot(body));
}
}
static inline void

View File

@ -72,7 +72,7 @@ handleSetTrans(void *obj, cpSpaceHash *hash)
int count = CP_BUFFER_BYTES/sizeof(cpHandle);
cpAssert(count, "Buffer size is too small.");
cpHandle *buffer = (cpHandle *)cpmalloc(CP_BUFFER_BYTES);
cpHandle *buffer = (cpHandle *)cpcalloc(1, CP_BUFFER_BYTES);
cpArrayPush(hash->allocatedBuffers, buffer);
for(int i=0; i<count; i++) cpArrayPush(hash->pooledHandles, buffer + i);
@ -144,15 +144,15 @@ static void freeWrap(void *ptr, void *unused){cpfree(ptr);}
void
cpSpaceHashDestroy(cpSpaceHash *hash)
{
clearHash(hash);
if(hash->table) clearHash(hash);
cpfree(hash->table);
cpHashSetFree(hash->handleSet);
cpArrayEach(hash->allocatedBuffers, freeWrap, NULL);
if(hash->allocatedBuffers) cpArrayEach(hash->allocatedBuffers, freeWrap, NULL);
cpArrayFree(hash->allocatedBuffers);
cpArrayFree(hash->pooledHandles);
cpfree(hash->table);
cpArrayFree(hash->pooledHandles);
}
void
@ -200,7 +200,7 @@ getEmptyBin(cpSpaceHash *hash)
int count = CP_BUFFER_BYTES/sizeof(cpSpaceHashBin);
cpAssert(count, "Buffer size is too small.");
cpSpaceHashBin *buffer = (cpSpaceHashBin *)cpmalloc(CP_BUFFER_BYTES);
cpSpaceHashBin *buffer = (cpSpaceHashBin *)cpcalloc(1, CP_BUFFER_BYTES);
cpArrayPush(hash->allocatedBuffers, buffer);
// push all but the first one, return the first instead

View File

@ -201,7 +201,7 @@ shapeQueryHelper(cpShape *a, cpShape *b, shapeQueryContext *context)
if(
(a->group && a->group == b->group) ||
!(a->layers & b->layers) ||
a->sensor || b->sensor
a == b
) return;
cpContact contacts[CP_MAX_CONTACTS_PER_ARBITER];
@ -216,7 +216,7 @@ shapeQueryHelper(cpShape *a, cpShape *b, shapeQueryContext *context)
}
if(numContacts){
context->anyCollision = cpTrue;
context->anyCollision = !(a->sensor || b->sensor);
if(context->func){
cpContactPointSet set = {numContacts, {}};

View File

@ -41,7 +41,7 @@ postStepFuncSetEql(PostStepCallback *a, PostStepCallback *b){
static void *
postStepFuncSetTrans(PostStepCallback *callback, void *ignored)
{
PostStepCallback *value = (PostStepCallback *)cpmalloc(sizeof(PostStepCallback));
PostStepCallback *value = (PostStepCallback *)cpcalloc(1, sizeof(PostStepCallback));
(*value) = (*callback);
return value;
@ -81,7 +81,7 @@ typedef struct cpContactBuffer {
static cpContactBufferHeader *
cpSpaceAllocContactBuffer(cpSpace *space)
{
cpContactBuffer *buffer = (cpContactBuffer *)cpmalloc(sizeof(cpContactBuffer));
cpContactBuffer *buffer = (cpContactBuffer *)cpcalloc(1, sizeof(cpContactBuffer));
cpArrayPush(space->allocatedBuffers, buffer);
return (cpContactBufferHeader *)buffer;
}
@ -143,6 +143,13 @@ cpSpacePopContacts(cpSpace *space, int count){
#pragma mark Collision Detection Functions
static inline cpCollisionHandler *
lookupCollisionHandler(cpSpace *space, cpCollisionType a, cpCollisionType b)
{
cpCollisionType types[] = {a, b};
return (cpCollisionHandler *)cpHashSetFind(space->collFuncSet, CP_HASH_PAIR(a, b), types);
}
static inline cpBool
queryReject(cpShape *a, cpShape *b)
{
@ -164,13 +171,10 @@ queryFunc(cpShape *a, cpShape *b, cpSpace *space)
// Reject any of the simple cases
if(queryReject(a,b)) return;
// Find the collision pair function for the shapes.
struct{cpCollisionType a, b;} ids = {a->collision_type, b->collision_type};
cpHashValue collHashID = CP_HASH_PAIR(a->collision_type, b->collision_type);
cpCollisionHandler *handler = (cpCollisionHandler *)cpHashSetFind(space->collFuncSet, collHashID, &ids);
cpCollisionHandler *handler = lookupCollisionHandler(space, a->collision_type, b->collision_type);
cpBool sensor = a->sensor || b->sensor;
if(sensor && handler == &space->defaultHandler) return;
if(sensor && handler == &cpSpaceDefaultHandler) return;
// Shape 'a' should have the lower shape type. (required by cpCollideShapes() )
if(a->klass->type > b->klass->type){
@ -255,7 +259,9 @@ contactSetFilter(cpArbiter *arb, cpSpace *space)
// was used last frame, but not this one
if(ticks >= 1 && arb->state != cpArbiterStateCached){
arb->handler->separate(arb, space, arb->handler->data);
// The handler needs to be looked up again as the handler cached on the arbiter may have been deleted since the last step.
cpCollisionHandler *handler = lookupCollisionHandler(space, arb->a->collision_type, arb->b->collision_type);
handler->separate(arb, space, handler->data);
arb->state = cpArbiterStateCached;
}

View File

@ -200,11 +200,21 @@ public class Cocos2dxBitmap{
LinkedList<String> strList = new LinkedList<String>();
/*
* Break a String into String[] by the width
* Break a String into String[] by the width & should wrap the word
*/
for (int i = 1; i <= charLength; ++i){
tempWidth = (int)Math.ceil(paint.measureText(content, start, i));
if (tempWidth >= width){
int lastIndexOfSpace = content.substring(0, i).lastIndexOf(" ");
if (lastIndexOfSpace != -1){
/**
* Should wrap the word
*/
strList.add(content.substring(start, lastIndexOfSpace));
i = lastIndexOfSpace;
}
else {
/*
* Should not exceed the width
*/
@ -218,6 +228,7 @@ public class Cocos2dxBitmap{
else {
strList.add(content.substring(start, i));
}
}
start = i;
}

View File

@ -1 +1 @@
ca6671a2edbcbfdddbb140f60d4a868feab7747f
33ad1fd0694c56b7b34f9ebd3e563782e572c270

View File

@ -66,10 +66,13 @@ blockerSeparate(cpArbiter *arb, cpSpace *space, void *unused)
static void
postStepRemove(cpSpace *space, cpShape *shape, void *unused)
{
// cocos2d-x: bring cpSpaceRemoveShape here to avoid
// the crash on win32 platform
cpSpaceRemoveShape(space, shape);
cpSpaceRemoveBody(space, shape->body);
cpBodyFree(shape->body);
cpShapeFree(shape);
}

View File

@ -500,17 +500,12 @@ drawSpace(cpSpace *space, drawSpaceOptions *options)
glPointSize(options->bodyPointSize);
cpArray *bodies = space->bodies;
// cocos2d-x: use ccDrawPoints to optimize the speed
CCPoint *aPoints = new CCPoint[bodies->num];
glColor4f(LINE_COLOR);
for(int i=0, count = bodies->num; i<count; i++){
cpBody *body = (cpBody *)bodies->arr[i];
aPoints[i] = CCPoint(body->p.x, body->p.y);
// ccDrawPoint( ccp(body->p.x, body->p.y) );
ccDrawPoint( ccp(body->p.x, body->p.y) );
}
ccDrawPoints( aPoints, bodies->num );
delete []aPoints;
// glColor3f(0.5f, 0.5f, 0.5f);
// cpArray *components = space->components;
@ -529,18 +524,12 @@ drawSpace(cpSpace *space, drawSpaceOptions *options)
cpArray *arbiters = space->arbiters;
for(int i=0; i<arbiters->num; i++){
cpArbiter *arb = (cpArbiter*)arbiters->arr[i];
// cocos2d-x: use ccDrawPoints to optimze the speed
CCPoint *aPoints = new CCPoint[arb->numContacts];
glColor4f(COLLISION_COLOR);
for(int i=0; i<arb->numContacts; i++){
cpVect v = arb->contacts[i].p;
// ccDrawPoint( ccp(v.x, v.y) );
aPoints[i] = CCPoint(v.x, v.y);
ccDrawPoint( ccp(v.x, v.y) );
}
ccDrawPoints( aPoints, arb->numContacts );
delete []aPoints;
}
}
}