Exemplo n.º 1
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.º 2
0
static void RemoveShape(cpBody *body, cpShape *shape, void *data)
{
	UNUSED(body);
	cpSpace *s = data;
	cpSpaceRemoveShape(s, shape);
	cpShapeFree(shape);
}
void MachineSystem::removePart(cpVect gridPosition)
{
    int machineNum = machinePositionToNumber(gridPosition);
    
    MachinePart *partToRemove = parts[machineNum];
    if (partToRemove) {
        
        cpBody *attachmentBody = partToRemove->getBody();
        __block cpBody *pegBody = NULL;
        cpBodyEachConstraint_b(attachmentBody, ^(cpConstraint *c) {
            if (cpConstraintGetB(c) == attachmentBody) {
                cpBody *otherBody = cpConstraintGetA(c); // the peg is always body A
                if (cpBodyGetMass(otherBody) == INFINITY)
                    pegBody = otherBody;
            }
        });
        
        assert(pegBody);
        
        int nPegs = size.x * size.y;
        // remove the attachments for this machine
        for (int i=0; i<nPegs; i++) {
            cpVect otherMachinePos = machineNumberToPosition(i);
            detachMachines(gridPosition, otherMachinePos);
        }
        
        
        partToRemove->detachFromBody(pegBody);
        
        cpBodyEachShape_b(pegBody, ^(cpShape *shape) {
            cpSpaceRemoveStaticShape(space, shape);
            cpShapeFree(shape);
        });
Exemplo n.º 4
0
GameObject::~GameObject()
{
	m_resMgr.DeleteSprite(m_Sprite.ID);
	if(m_pBody)
		cpBodyFree(m_pBody);
	if(m_pShape)
		cpShapeFree(m_pShape);
}
Exemplo n.º 5
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.º 6
0
PhysicsShape::~PhysicsShape()
{
    for (auto shape : _cpShapes)
    {
        s_physicsShapeMap.erase(shape);

        cpShapeFree(shape);
    }
}
Exemplo n.º 7
0
static void
postStepRemove(cpSpace *space, cpShape *shape, void *unused)
{
	cpSpaceRemoveBody(space, shape->body);
	cpSpaceRemoveShape(space, shape);
	
	cpBodyFree(shape->body);
	cpShapeFree(shape);
}
Exemplo n.º 8
0
ChipmunkTestLayer::~ChipmunkTestLayer()
{
    // manually Free rogue shapes
    for( int i=0;i<4;i++) {
        cpShapeFree( _walls[i] );
    }

    cpSpaceFree( _space );

}
PhysicsShapeInfo::~PhysicsShapeInfo()
{
    for (auto shape : _shapes)
    {
        auto it = _map.find(shape);
        if (it != _map.end()) _map.erase(shape);
        
        cpShapeFree(shape);
    }
}
void PhysicsShapeInfo::removeAll()
{
    for (cpShape* shape : _shapes)
    {
        auto mit = _map.find(shape);
        if (mit != _map.end()) _map.erase(mit);
        cpShapeFree(shape);
    }
    
    _shapes.clear();
}
Exemplo n.º 11
0
	static void remove_unused(void* s)
	{
		cpShape* shape = (cpShape*)s;
		chipmunk_data* p = (chipmunk_data*)shape->data;

		destroy_chipmunk_data(p, shape->body);
	
		/* The player was marked as to be deleted. The player is freed here,
		 * to avoid concurrence problems if we delete somewhere else. */
	    cpSpaceRemoveShape(space, shape);
	    cpShapeFree(shape);
	}
Exemplo n.º 12
0
void GameScene::onExit()
{
	Scene::onExit();
	this->unscheduleUpdate();

	for (auto& shape : shapes)
		cpShapeFree(shape);
	shapes.clear();

	cpSpaceRemoveCollisionHandler(space, collisionTypeBall, collisionTypeWall);
	cpSpaceFree(space);
}
Exemplo n.º 13
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.º 14
0
ChipmunkTestLayer::~ChipmunkTestLayer()
{
#if CC_ENABLE_CHIPMUNK_INTEGRATION
    // manually Free rogue shapes
    for( int i=0;i<4;i++) {
        cpShapeFree( _walls[i] );
    }

    cpSpaceFree( _space );

    Device::setAccelerometerEnabled(false);
#endif
}
 bool CDynamics2DBoxEntity::MoveTo(const CVector3& c_position,
                                       const CQuaternion& c_orientation,
                                       bool b_check_only) {
    SInt32 nCollision;
    /* Check whether the box is movable or not */
    if(m_cBoxEntity.GetEmbodiedEntity().IsMovable()) {
       /* The box is movable */
       /* Save body position and orientation */
       cpVect tOldPos = m_ptBody->p;
       cpFloat fOldA = m_ptBody->a;
       /* Move the body to the desired position */
       m_ptBody->p = cpv(c_position.GetX(), c_position.GetY());
       CRadians cXAngle, cYAngle, cZAngle;
       c_orientation.ToEulerAngles(cZAngle, cYAngle, cXAngle);
       cpBodySetAngle(m_ptBody, cZAngle.GetValue());
       /* Create a shape sensor to test the movement */
       /* First construct the vertices */
       CVector3 cHalfSize = m_cBoxEntity.GetSize() * 0.5f;
       cpVect tVertices[] = {
          cpv(-cHalfSize.GetX(), -cHalfSize.GetY()),
          cpv(-cHalfSize.GetX(),  cHalfSize.GetY()),
          cpv( cHalfSize.GetX(),  cHalfSize.GetY()),
          cpv( cHalfSize.GetX(), -cHalfSize.GetY())
       };
       /* Then create the shape itself */
       cpShape* ptTestShape = cpPolyShapeNew(m_ptBody,
                                             4,
                                             tVertices,
                                             cpvzero);
       /* Check if there is a collision */
       nCollision = cpSpaceShapeQuery(m_cEngine.GetPhysicsSpace(), ptTestShape, NULL, NULL);
       /* Dispose of the sensor shape */
       cpShapeFree(ptTestShape);
       if(b_check_only || nCollision) {
          /* Restore old body state if there was a collision or
             it was only a check for movement */
          m_ptBody->p = tOldPos;
          cpBodySetAngle(m_ptBody, fOldA);
       }
       else {
          /* Update the active space hash if the movement is actual */
          cpSpaceReindexShape(m_cEngine.GetPhysicsSpace(), m_ptShape);
       }
    }
    else {
       /* The box is not movable, so you can't move it :-) */
       nCollision = 1;
    }
    /* The movement is allowed if there is no collision */
    return !nCollision;
 }
Exemplo n.º 16
0
void GameInst::UnloadLevel()
{
	// Clear blocks
	for (auto it = m_blocks.begin(); it != m_blocks.end();)
	{
		m_Renderer.RemoveDrawableSprite((*it)->GetSprite());
		delete *it;
		it = m_blocks.erase(it);
	}

	//clear laser catchers
	/*for (auto it = Catchers.begin(); it != Catchers.end();)
	{
		it = Catchers.erase(it);
		m_Renderer.RemoveDrawableSprite((*it)->GetSprite());
	}*/

	//clear laser emitters
	for (auto it = Emitters.begin(); it != Emitters.end();)
	{
		m_Renderer.RemoveDrawableSprite((*it)->GetSprite());
		delete *it;
		it = Emitters.erase(it);
	}

	//clear physworld
	cpShapeFree(m_WorldBounds.Top);
	cpShapeFree(m_WorldBounds.Bottom);
	cpShapeFree(m_WorldBounds.Left);
	cpShapeFree(m_WorldBounds.Right);
	cpSpaceFree(m_pSpace);

	//clear player
	m_Renderer.RemoveDrawableSprite(m_pPlayer->GetSprite());
	delete m_pPlayer;
	m_pPlayer = NULL;
}
Exemplo n.º 17
0
void GameInst::UnloadLevel()
{
    // Clear blocks
    for (auto it = m_blocks.begin(); it != m_blocks.end();) {
        it = m_blocks.erase(it);
    }

    // Clear laser sprites
    for (auto it = m_laserSprites.begin(); it != m_laserSprites.end();)
    {
        m_Renderer.RemoveDrawableSprite(&(*it));
        m_ResMgr.DeleteSprite((*it).ID);
        it = m_laserSprites.erase(it);
    }

    //clear physworld
    cpShapeFree(m_WorldBounds.Top);
    cpShapeFree(m_WorldBounds.Bottom);
    cpShapeFree(m_WorldBounds.Left);
    cpShapeFree(m_WorldBounds.Right);
    cpSpaceFree(m_pSpace);

    //clear player
}
void PhysicsShapeInfo::remove(cpShape* shape)
{
    if (shape == nullptr) return;
    
    auto it = std::find(_shapes.begin(), _shapes.end(), shape);
    if (it != _shapes.end())
    {
        _shapes.erase(it);
        
        auto mit = _map.find(shape);
        if (mit != _map.end()) _map.erase(mit);
        
        cpShapeFree(shape);
    }
}
 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());
 }
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);
}
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
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);
}
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;
	}
}
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.º 25
0
Arquivo: sys.c Projeto: niksaak/dame
int remove_body(cpBody* body)
{
  if(body == NULL) {
    return -1; // nyurupo~
  }

  cpSpace* space;
  if(the_space != NULL) {
    space = the_space;
  } else {
    return -1;
  }

  cpBodyEachShape_b(body,
      ^(cpShape* s){
        cpSpaceRemoveShape(space, s);
        cpShapeFree(s);
      });
Exemplo n.º 26
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.º 27
0
Arquivo: LevelGrid.cpp Projeto: ofx/dr
LevelGrid::~LevelGrid(void)
{
    delete this->m_BackgroundQuad;
    
    // Remove grid vertices
    for (int y = 0 ; y <= this->m_NumY ; ++y)
    {
        for (int x = 0 ; x <= this->m_NumX ; ++x)
        {
            delete this->m_GridVertices[y][x];
        }
        delete this->m_GridVertices[y];
    }
    delete this->m_GridVertices;

    // Delete the activators
    for (int i = 0 ; i < this->m_NumActivators ; ++i)
    {
        delete this->m_Activators[i];
    }
    if (this->m_NumActivators > 0)
    {
        delete this->m_Activators;
    }

    // Free the physics shapes and body
    std::list<cpShape*>::const_iterator it;
    cpSpace *space = this->m_Engine->GetWorld()->GetSpace();
    for (it = this->m_Shapes.begin() ; it != this->m_Shapes.end() ; ++it)
    {
        cpSpaceRemoveShape(space, *it);
        cpShapeFree(*it);
    }
    this->m_Shapes.clear();
    delete this->m_Body;

    // Free the left and right index memory
    delete this->m_LeftLevelIndices;
    delete this->m_RightLevelIndices;

    // Free the left and right vertex memory
    delete this->m_LeftLevelVertices;
    delete this->m_RightLevelVertices;
}
Exemplo n.º 28
0
int main (int argc, char **argv) {
    cpSpace *space = cpSpaceNew();
    cpSpaceSetGravity(space, cpv(0, GRAVITY));
    cpEnableSegmentToSegmentCollisions();
    
    cpShape *ground = cpSpaceAddShape(space, cpSegmentShapeNew(space->staticBody, cpv(0, 5), cpv(10, -5), 0));
    cpShapeSetFriction(ground, 0.3);
    
    cpBody *drawing = drawing_new(2, 7, 0);
    drawing = drawing_update(space, drawing, 3, 8);
    drawing = drawing_update(space, drawing, 3, 9);
    drawing = drawing_update(space, drawing, 2, 9);
    //cpBody *drawing = drawing_new(0, 0, 0);
    //drawing = drawing_update(space, drawing, 2, 0);
    //drawing = drawing_update(space, drawing, 2, 2);
    //drawing = drawing_update(space, drawing, 0, 2);
    print_positions(drawing);
    
    //drawing_activate(drawing);
    //print_positions(drawing);
    
    cpVect vel, pos;
    int i = 0;
    for(cpFloat time = 0; time < 2; time += TIMESTEP){
        pos = cpBodyGetPos(drawing);
        vel = cpBodyGetVel(drawing);
        
        printf( "Time = %2.2f Position = (%2.2f, %2.2f) Velocity = (%2.2f, %2.2f)\n",
            time, pos.x, pos.y, vel.x, vel.y);
        cpSpaceStep(space, TIMESTEP);
        
        i++;
        if (i == 20) {
            drawing_activate(space, drawing);
            print_positions(drawing);
        }
    }
    print_positions(drawing);
    
    free_body_full(drawing);
    cpShapeFree(ground);
    cpSpaceFree(space);
    return EXIT_SUCCESS;
}
Exemplo n.º 29
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.º 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);
}