cpFloat Spring::springForceFunc(cpConstraint *constraint, cpFloat dist){ Spring* spring = (Spring*)cpConstraintGetUserData(constraint); if(spring->forceFunction){ return spring->forceFunction(spring, dist); } return 0; }
mrb_value mrb_cp_constraint_get_mrb_obj(mrb_state *mrb, const cpConstraint *constraint) { struct mrb_cp_constraint_user_data *user_data; user_data = cpConstraintGetUserData(constraint); if (user_data) { return user_data->constraint; } else { return mrb_nil_value(); } }
void mrb_cp_constraint_free(mrb_state *mrb, void *ptr) { cpConstraint *constraint = ptr; mrb_cp_constraint_user_data *user_data; if (constraint) { user_data = cpConstraintGetUserData(constraint); if (user_data) { mrb_cp_constraint_user_data_free(mrb, user_data); } cpConstraintFree(constraint); } }
Body::~Body(){ if(body){ //clean up all constraints constraintsToRemove.clear(); cpBodyEachConstraint(body, &constraintRemoveQuery, (void*)this); for(auto c: constraintsToRemove){ ((Constraint*)cpConstraintGetUserData(c))->constraint = nullptr; cpSpaceRemoveConstraint(cpConstraintGetSpace(c), c); cpConstraintDestroy(c); } //remove body cpSpaceRemoveBody(cpBodyGetSpace(body), body); cpBodyFree(body); body = nullptr; } }