Exemplo n.º 1
0
Arquivo: Tank.c Projeto: 0w/moai-dev
static void
destroy(void)
{
	cpBodyFree(staticBody);
	cpBodyFree(tankControlBody);
	cpSpaceFreeChildren(space);
	cpSpaceFree(space);
}
Exemplo n.º 2
0
static void
destroy(cpSpace *space)
{
	ChipmunkDemoFreeSpaceChildren(space);
	cpBodyFree(planetBody);
	cpSpaceFree(space);
}
Exemplo n.º 3
0
void freeDll(void)
{
	
	int i;
	Variable *var;


	//Poistettaan kaikki muuttujat
	for (i = 1; i != mVariableHandler.mSize;i++)
	{
		var = mVariableHandler.mPtrArray[i];
		if (var != NULL)
		{
			switch(var->mType)
			{
			case VarTypeBody:
				cpBodyFree((cpBody*)var->mPtr);break;
			case VarTypeShape:
				cpShapeFree((cpShape*)var->mPtr);break;
			case VarTypeConstraint:
				cpConstraintFree((cpConstraint*)var->mPtr);break;
			case VarTypeDataArray:
				daFree((DataArray*)var->mPtr);break;
			}
		}
	}

	//Tuhotaan ne kaikki...
	vhDestroy(&mVariableHandler);
	cpSpaceDestroy(&mSpace);
	mState = Unloaded;
}
Exemplo n.º 4
0
ETERM *space_remove_body(ETERM *fromp, ETERM *argp) {

    // get the args
    ETERM *space_refp = erl_element(1, argp);
    ETERM *idp = erl_element(2, argp);

    erlmunk_space *s;
    int space_id = ERL_REF_NUMBER(space_refp);
    HASH_FIND_INT(erlmunk_spaces, &space_id, s);

    int body_id = ERL_INT_VALUE(idp);
    erlmunk_body *b = NULL;
    HASH_FIND_INT(s->bodies, &body_id, b);
    if (b == NULL)
        return NULL;

    // DEBUGF(("removing body #%d\n", body_id));

    // remove the user data associated with the body
    erlmunk_body_data *data = cpBodyGetUserData(b->body);
    if (data->term != NULL)
        erl_free_compound(data->term);
    free(data);

    cpBodyEachShape(b->body, shapeRemove, NULL);
    cpSpaceRemoveBody(s->space, b->body);

    space_remove_body_hash(s, b);

    cpBodyDestroy(b->body);
    cpBodyFree(b->body);

    return NULL;
}
Exemplo n.º 5
0
static void
destroy(void)
{
	cpBodyFree(rogueBoxBody);
	ChipmunkDemoFreeSpaceChildren(space);
	cpSpaceFree(space);
}
Exemplo n.º 6
0
ETERM *space_delete(ETERM *fromp, ETERM *argp) {

    // get the args
    ETERM *space_refp = erl_element(1, argp);

    erlmunk_space *s;
    int space_id = ERL_REF_NUMBER(space_refp);
    HASH_FIND_INT(erlmunk_spaces, &space_id, s);

    // remove all subscribers
    for(erlmunk_subscriber *subscriber = s->subscribers; subscriber != NULL;
        subscriber = subscriber->hh.next) {
        space_remove_subscriber(s, subscriber);
    }
    // remove all bodies
    for(erlmunk_body *b = s->bodies; b != NULL;
        b = b->hh.next) {
        erlmunk_body_data *data = cpBodyGetUserData(b->body);
        if (data->term != NULL)
            erl_free_compound(data->term);
        free(data);

        cpSpaceRemoveBody(s->space, b->body);
        cpBodyDestroy(b->body);
        cpBodyFree(b->body);
        space_remove_body_hash(s, b);
    }

    return NULL;
}
Exemplo n.º 7
0
GameObject::~GameObject()
{
	m_resMgr.DeleteSprite(m_Sprite.ID);
	if(m_pBody)
		cpBodyFree(m_pBody);
	if(m_pShape)
		cpShapeFree(m_pShape);
}
Exemplo n.º 8
0
void
classdef_circularBody_finalize(JSContext* cx, JSObject* sp) {
  cpBody* body = (cpBody*)JS_GetPrivate(cx, sp);
  printf("About to try and delete a cpBody and, its cpConstraints and its cpShapes...\n");
  cpBodyEachShape(body, &removeShapeFromBodyIterator, 0);
  cpBodyEachConstraint(body, &removeConstraintFromBodyIterator, 0);
  cpBodyFree(body);
}
Exemplo n.º 9
0
static void
destroy(void)
{
	cpBodyFree(staticBody);
	cpSpaceFreeChildren(space);
	cpSpaceFree(space);
	
	cpArrayFree(playerInstance.groundShapes);
}
Exemplo n.º 10
0
/* A matching cleanup_tiles function to make sure
 * we free the chipmunk resources we allocated during
 * init_tiles(). Remember - Chipmunk2D is not doing any
 * garbage collection and any time we call one of the New
 * functions we need to match it with a corresponding Free
 * call when we're done.
 */
static void cleanup_tiles(struct state* state)
{
    for (size_t i = 0; i < MAX_TILES; i++) {
        if (state->tiles[i].is_active) {
            cpShapeFree(state->tiles[i].shape);
            cpBodyFree(state->tiles[i].body);
        }
    }
}
Exemplo n.º 11
0
static void
postStepRemove(cpSpace *space, cpShape *shape, void *unused)
{
	cpSpaceRemoveBody(space, shape->body);
	cpSpaceRemoveShape(space, shape);
	
	cpBodyFree(shape->body);
	cpShapeFree(shape);
}
Exemplo n.º 12
0
void free_body_full(cpBody *body) {
    cpBodyEachShape(body, (cpBodyShapeIteratorFunc) free_shape, NULL);
    
    point_array_free( (Body_data *) cpBodyGetUserData(body) );
	cpSpace *space = cpBodyGetSpace(body);
	cpSpaceRemoveBody(space, body);
	cpBodyDestroy(body);
    cpBodyFree(body);
}
Exemplo n.º 13
0
/* Cleanup
 * -------
 *
 * Clean up is simple enough. Just destroy the tile
 * image and free the state structure memory.
 */
static void destroy_sample(void* data)
{
    struct state* state = data;
    cleanup_walls(state);
    cleanup_tiles(state);
    destroy_image(state->tile_img);
    cpBodyFree(state->mouse_body);
    cpSpaceFree(state->space);
    free(data);
}
Exemplo n.º 14
0
 void CDynamics2DEngine::Destroy() {
    /* Empty the physics model map */
    for(CDynamics2DModel::TMap::iterator it = m_tPhysicsModels.begin();
        it != m_tPhysicsModels.end(); ++it) {
       delete it->second;
    }
    m_tPhysicsModels.clear();
    /* Get rid of the physics space */
    cpSpaceFree(m_ptSpace);
    cpBodyFree(m_ptGroundBody);
 }
Exemplo n.º 15
0
	void RigidBody2D::Destroy()
	{
		UnregisterFromSpace();

		cpSpace* space = m_world->GetHandle();
		for (cpShape* shape : m_shapes)
			cpShapeFree(shape);

		if (m_handle)
			cpBodyFree(m_handle);

		m_shapes.clear();
	}
Exemplo n.º 16
0
PhysicsBody::~PhysicsBody()
{
    for (auto& joint : _joints)
    {
        PhysicsBody* other = joint->getBodyA() == this ? joint->getBodyB() : joint->getBodyA();
        other->removeJoint(joint);
        delete joint;
    }
    
    if (_cpBody)
    {
        cpBodyFree(_cpBody);
    }
}
Exemplo n.º 17
0
cpBody *cpSpaceSerializer::createBody(TiXmlElement *elm)
{	
	TiXmlElement *bodyElm;;
	cpBody *body;
	
	CPSS_ID b_id = createValue<CPSS_ID>("body_id", elm);
	BodyMap::iterator itr = _bodyMap.find(b_id);
	
	//If it doesn't exist, try to create it
	if (itr == _bodyMap.end())
	{
		bodyElm = elm->FirstChildElement("body");
		
		if (bodyElm)
		{
			cpFloat mass = createValue<cpFloat>("mass", bodyElm);
			cpFloat inertia = createValue<cpFloat>("inertia", bodyElm);
			
            if (mass == INFINITY)
                body = cpBodyNewStatic();
            else
                body = cpBodyNew(mass, inertia);
			
			body->p = createPoint("p", bodyElm);
			body->v = createPoint("v", bodyElm);
			body->f = createPoint("f", bodyElm);
			body->w = createValue<cpFloat>("w", bodyElm);
			body->t = createValue<cpFloat>("t", bodyElm);
            cpBodySetAngle(body, createValue<cpFloat>("a", bodyElm));
			
			_bodyMap[b_id] = body;

            if (delegate && b_id != 0)
            {
                if (!delegate->reading(body, b_id))
                {
                    cpBodyFree(body);
                    body = NULL;
                }
            }
		}
		else
			body = cpBodyNewStatic(); //Fail case, should throw or something
	}
	else 
		body = itr->second; //Else grab it
	
	return body;
}
Exemplo n.º 18
0
void RCPBody::destroy()
{
    // remove all shapes before removing the body
    mShapes.clear();

    if (mType != Static && RCPWorld::instance()) {
        cpSpace * space = RCPWorld::instance()->space();
        if (mBody && space) {
            cpSpaceRemoveBody(space, mBody);
            cpBodyFree(mBody);
        }
    }

    mBody = 0;
}
Exemplo n.º 19
0
CDynamics2DCylinderEntity::~CDynamics2DCylinderEntity() {
    if(m_ptBody != NULL) {
        cpSpaceRemoveConstraint(m_cEngine.GetPhysicsSpace(), m_ptLinearFriction);
        cpSpaceRemoveConstraint(m_cEngine.GetPhysicsSpace(), m_ptAngularFriction);
        cpConstraintFree(m_ptLinearFriction);
        cpConstraintFree(m_ptAngularFriction);
        cpSpaceRemoveBody(m_cEngine.GetPhysicsSpace(), m_ptBody);
        cpBodyFree(m_ptBody);
        cpSpaceRemoveShape(m_cEngine.GetPhysicsSpace(), m_ptShape);
    }
    else {
        cpSpaceRemoveStaticShape(m_cEngine.GetPhysicsSpace(), m_ptShape);
        cpSpaceRehashStatic(m_cEngine.GetPhysicsSpace());
    }
    cpShapeFree(m_ptShape);
}
 CDynamics2DSingleBodyObjectModel::~CDynamics2DSingleBodyObjectModel() {
    bool bIsStatic = cpBodyIsStatic(m_ptBody);
    /* Dispose of shapes */
    for(cpShape* pt_shape = m_ptBody->shapeList;
        pt_shape != NULL;
        pt_shape = pt_shape->next) {
       cpSpaceRemoveShape(GetDynamics2DEngine().GetPhysicsSpace(), pt_shape);
       cpShapeFree(pt_shape);
    }
    /* Dispose of body */
    if(! bIsStatic)
       cpSpaceRemoveBody(GetDynamics2DEngine().GetPhysicsSpace(), m_ptBody);
    cpBodyFree(m_ptBody);
    /* Reindex space */
    if(bIsStatic) cpSpaceReindexStatic(GetDynamics2DEngine().GetPhysicsSpace());
 }
Exemplo n.º 21
0
	void RigidBody2D::Destroy()
	{
		cpSpace* space = m_world->GetHandle();
		for (cpShape* shape : m_shapes)
		{
			cpSpaceRemoveShape(space, shape);
			cpShapeFree(shape);
		}

		if (m_handle)
		{
			cpSpaceRemoveBody(space, m_handle);
			cpBodyFree(m_handle);
		}
		m_shapes.clear();
	}
Exemplo n.º 22
0
PhysicsBody::~PhysicsBody()
{
    for (auto it = _joints.begin(); it != _joints.end(); ++it)
    {
        PhysicsJoint* joint = *it;

        PhysicsBody* other = joint->getBodyA() == this ? joint->getBodyB() : joint->getBodyA();
        other->removeJoint(joint);
        delete joint;
    }

    if (_cpBody)
    {
        cpBodyFree(_cpBody);
    }
}
Exemplo n.º 23
0
GameObject::~GameObject()
{
	if (m_body) {
		cpBodyFree(m_body);
		m_body = nullptr;
	}
	if (m_shape) {
		cpSpaceRemoveStaticShape(m_space, m_shape);
		cpShapeFree(m_shape);
		m_shape = nullptr;
	}
	if (m_sprite) {
		m_sprite->removeFromParent();
		m_sprite = nullptr;
	}
}
void TestColliderDetector::destroyCPBody(cpBody *body)
{
	cpShape *shape = body->shapeList_private;
	while(shape)
	{
		cpShape *temp = shape->next_private;
        
		cpSpaceRemoveShape(space, shape);
		cpShapeFree(shape);
        
		shape = temp;
	}
    
	cpSpaceRemoveBody(space, body);
	cpBodyFree(body);
}
GeometrySpringDynamic::~GeometrySpringDynamic()
{
	clearJoints();

	if( 0 != m_Shape && true == cpSpaceContainsShape( m_Space, m_Shape ) )
	{
		cpSpaceRemoveShape( m_Space, m_Shape );
		cpShapeFree( m_Shape );
		m_Shape = 0;
	}
	if( 0 != m_Body && true == cpSpaceContainsBody( m_Space, m_Body ) )
	{
		cpSpaceRemoveBody( m_Space, m_Body );
		cpBodyFree( m_Body );
		m_Body = 0;
	}
}
Exemplo n.º 26
0
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;
	}
}
Exemplo n.º 27
0
void Slice::SliceShapePostStep(cpSpace *space, cpShape *shape, struct SliceContext *context)
{
	cpVect a = context->a;
	cpVect b = context->b;
	
	// Clipping plane normal and distance.
	cpVect n = cpvnormalize(cpvperp(cpvsub(b, a)));
	cpFloat dist = cpvdot(a, n);
	
	ClipPoly(space, shape, n, dist);
	ClipPoly(space, shape, cpvneg(n), -dist);
	
	cpBody *body = cpShapeGetBody(shape);
	cpSpaceRemoveShape(space, shape);
	cpSpaceRemoveBody(space, body);
	cpShapeFree(shape);
	cpBodyFree(body);
}
Exemplo n.º 28
0
Unit::~Unit()
{
	ActionTimer* timer = NULL;
	while( actionTimers != NULL ){
		timer = actionTimers;
		Timer::DeleteTimerEventById( timer->timerId );
		actionTimers = timer->next;
		delete timer, timer = NULL;
	}
	if( physShape ){
		cpSpaceRemoveShape( Phys::space, physShape );
		cpShapeFree( physShape );
	}
	if( physBody ){
		if( !cpBodyIsStatic(physBody) )
			cpSpaceRemoveBody( Phys::space, physBody );
		cpBodyFree( physBody );
	}
}
Exemplo n.º 29
0
void Bomb::destroy(cpSpace *space) {
  if (!destroyed) {
    destroyed = true;
    if (simulation_type == "DYNAMIC")
      cpSpaceRemoveShape(space, bombShape);
    else
      cpSpaceRemoveStaticShape(space, bombShape);
    
    if (simulation_type == "DYNAMIC") cpSpaceRemoveBody(space, body);
    cpShapeFree(bombShape);
    cpBodyFree(body);
  
    for (int j=0; j < PARTICLE_TOTAL; j++) {
      delete particles[j];
      particles[j] = NULL;
    }
  
    delete [] particles;
  }
}
Exemplo n.º 30
0
Arquivo: Player.cpp Projeto: ofx/dr
Player::~Player(void)
{
    delete this->m_ParticleSystem;
	delete this->m_Sprite;
	delete this->m_ParticleSprite;

    // Delete weapon in weapon slots
    for (int i = 0 ; i < NUM_WEAPON_SLOTS ; ++i)
    {
        delete this->m_Weaponslots[i];
    }
    delete this->m_Weaponslots;

    // Delete physics stuff
    cpSpace *space = this->m_Engine->GetWorld()->GetSpace();
    cpSpaceRemoveShape(space, this->m_Shape);
    cpSpaceRemoveBody(space, this->m_Body);
    cpShapeFree(this->m_Shape);
    cpBodyFree(this->m_Body);
}