void AGameplayPawn::UpdatePos(int x, int y) { FVector2D coord(x,y); if (grid[x][y] != E_TERRAIN) { int sumAdjacent = 0; for (int i = 0; i < 8; i++) { if (grid[x + dX[i]][y + dY[i]] != E_TERRAIN) sumAdjacent++; } if (sumAdjacent == 8) { DestroyBody(x,y); } else { CreateBody(x,y); } } else { DestroyBody(x,y); } }
dgWorld::~dgWorld() { Sync(); dgAsyncThread::Terminate(); dgMutexThread::Terminate(); #ifdef _NEWTON_AMP if (m_amp) { delete m_amp; } #endif dgSkeletonList::Iterator iter (*this); for (iter.Begin(); iter; iter ++) { delete iter.GetNode()->GetInfo(); } m_preListener.RemoveAll(); m_postListener.RemoveAll(); DestroyAllBodies(); RemoveAllGroupID(); m_pointCollision->Release(); DestroyBody (m_sentinelBody); delete m_broadPhase; }
void Keyboard(int key) { switch (key) { case GLFW_KEY_1: case GLFW_KEY_2: case GLFW_KEY_3: case GLFW_KEY_4: case GLFW_KEY_5: case GLFW_KEY_6: Create(key - GLFW_KEY_1); break; case GLFW_KEY_D: DestroyBody(); break; case GLFW_KEY_M: if (m_mode == e_closest) { m_mode = e_any; } else if (m_mode == e_any) { m_mode = e_multiple; } else if (m_mode == e_multiple) { m_mode = e_closest; } } }
void Triangle::CreatePhysicsBody () { DestroyBody(); b2BodyDef def; def.type = b2_staticBody; m_body = CreateBody(def); b2PolygonShape shape; bool flip = m_transform.scale.x * m_transform.scale.y < 0; b2Vec2 vertices[NUM_VERTS]; vertices[0] = b2Vec2(0, 0); if (flip) { vertices[2] = b2Vec2(m_transform.scale.x, 0); vertices[1] = b2Vec2(0, m_transform.scale.y); } else { vertices[1] = b2Vec2(m_transform.scale.x, 0); vertices[2] = b2Vec2(0, m_transform.scale.y); } shape.Set(vertices, NUM_VERTS); b2FixtureDef fixtureDef; fixtureDef.shape = &shape; fixtureDef.density = 1.0f; fixtureDef.restitution = 0.0f; fixtureDef.friction = 1.0f; m_body->CreateFixture(&fixtureDef); }
BodyWrapper::~BodyWrapper() { GetEntity()->RemoveEventListenType(Event_Simulate); GetEntity()->RemoveEventListenType(Event_BeginContact); GetEntity()->RemoveEventListenType(Event_EndContact); GetEntity()->RemoveEventListenType(Event_PreSolve); GetEntity()->RemoveEventListenType(Event_PostSolve); DestroyBody(); }
void BodyWrapper::CreateBody( const b2BodyDef& bodyDef ) { if( _body ) { DestroyBody(); } _body = PhysicsManager::GetInstance()->GetWorld()->CreateBody( &bodyDef ); _body->SetUserData( static_cast<IPhysics*>(this) ); }
void dgWorld::DestroyAllBodies () { dgBodyMasterList& me = *this; Sync (); dgTree<int, dgBody*>::Iterator iter (m_disableBodies); for (iter.Begin(); iter; iter ++) { dgBody* body = iter.GetKey(); DestroyBody (body); } dgAssert(!m_disableBodies.GetCount()); dgAssert (dgBodyMasterList::GetFirst()->GetInfo().GetBody() == m_sentinelBody); for (dgBodyMasterList::dgListNode* node = me.GetFirst()->GetNext(); node; ) { dgBody* const body = node->GetInfo().GetBody(); node = node->GetNext(); DestroyBody (body); } dgAssert (me.GetFirst()->GetInfo().GetCount() == 0); dgAssert (dgBodyCollisionList::GetCount() == 0); }
void Game::HandleEvent(SDL_Event &event) { if (event.user.code == COLLISION_ASTEROID_PLANET) { RemovePoint(); DestroyBody((b2Body*)event.user.data1); } else if (event.user.code == COLLISION_BOMB_PLANET) { RemovePoint(); DestroyBody((b2Body*)event.user.data1); } else if (event.user.code == COLLISION_ASTEROID_BOMB) { // blow up bomb ((Bomb*)((b2Body*)event.user.data2)->GetUserData())->Detonate((b2Body*)event.user.data1); } else if (event.user.code == DELETE_BODY) { DestroyBody((b2Body*)event.user.data1); } }
dgWorld::~dgWorld() { Sync(); Terminate(); UnloadPlugins(); m_listeners.RemoveAll(); DestroyAllBodies(); RemoveAllGroupID(); m_pointCollision->Release(); DestroyBody (m_sentinelBody); delete m_broadPhase; }
void Game::SelectLevel(Game::Levels level) { level_ = level; // Destroying all bodies should also delete current planet_ b2Body* body = world_.GetBodyList(); while (body != NULL) { DestroyBody(body); body = body->GetNext(); } planet_ = NULL; for (unsigned int i = 0; i < Bomb::BombType::COUNT_; ++i) { bombs_[i] = 0; } points_ = 0; for (unsigned int i = 0; i < Bomb::BombType::COUNT_; ++i) { previousReplenish_[i] = SDL_GetTicks(); } previousAsteroid_ = SDL_GetTicks(); if (level_ != Levels::COUNT_) { points_ = LevelInfo()->lives; asteroids_ = LevelInfo()->asteroids; for (unsigned int i = 0; i < Bomb::BombType::COUNT_; ++i) { bombs_[i] = LevelInfo()->bombs[i]; } if (level_ == Levels::INF) { srand(time(NULL)); } else { srand(LevelInfo()->rand); } planet_ = new Planet(LevelInfo()->planet); } }
dgWorld::~dgWorld() { DestroyAllBodies(); RemoveAllGroupID(); m_destroyCollision = NULL; ReleaseCollision(m_pointCollision); DestroyBody (m_sentionelBody); m_allocator->FreeLow (m_jointsMemory); m_allocator->FreeLow (m_bodiesMemory); m_allocator->FreeLow (m_islandMemory); m_allocator->FreeLow (m_pairMemoryBuffer); for (dgInt32 i = 0; i < DG_MAXIMUN_THREADS; i ++) { m_allocator->FreeLow (m_jacobiansMemory[i]); m_allocator->FreeLow (m_internalForcesMemory[i]); m_allocator->FreeLow (m_contactBuffers[i]); } }
void dgWorld::DestroyAllBodies () { dgBody* body; dgBodyMasterList::dgListNode* node; dgBodyMasterList& me = *this; // dgBodyMasterList::Iterator iter(me); // for (iter.Begin(); iter; ) { _ASSERTE (dgBodyMasterList::GetFirst()->GetInfo().GetBody() == m_sentionelBody); for (node = me.GetFirst()->GetNext(); node; ) { body = node->GetInfo().GetBody(); node = node->GetNext(); DestroyBody (body); } _ASSERTE (me.GetFirst()->GetInfo().GetCount() == 0); _ASSERTE (dgBodyCollisionList::GetCount() == 0); }
dgWorld::~dgWorld() { Sync(); dgAsyncThread::Terminate(); dgMutexThread::Terminate(); #ifdef _NEWTON_AMP if (m_amp) { delete m_amp; } #endif m_preListener.RemoveAll(); m_postListener.RemoveAll(); DestroyAllBodies(); RemoveAllGroupID(); m_pointCollision->Release(); DestroyBody (m_sentinelBody); delete m_broadPhase; }
void dgWorld::DestroyAllBodies() { dgBodyMasterList& me = *this; Sync(); dgInverseDynamicsList& ikList = *this; for (dgInverseDynamicsList::dgListNode* ptr = ikList.GetFirst(); ptr; ptr = ptr->GetNext()) { delete ptr->GetInfo(); } ikList.RemoveAll(); dgSkeletonList& skelList = *this; dgSkeletonList::Iterator iter(skelList); for (iter.Begin(); iter; iter++) { dgSkeletonContainer* const skeleton = iter.GetNode()->GetInfo(); delete skeleton; } skelList.RemoveAll(); while (m_disableBodies.GetRoot()) { dgBody* const body = m_disableBodies.GetRoot()->GetKey(); BodyEnableSimulation(body); } dgAssert(dgBodyMasterList::GetFirst()->GetInfo().GetBody() == m_sentinelBody); for (dgBodyMasterList::dgListNode* node = me.GetFirst()->GetNext(); node;) { dgBody* const body = node->GetInfo().GetBody(); node = node->GetNext(); DestroyBody(body); } dgAssert(me.GetFirst()->GetInfo().GetCount() == 0); dgAssert(dgBodyCollisionList::GetCount() == 0); }
b2World::~b2World() { DestroyBody(m_groundBody); m_broadPhase->~b2BroadPhase(); b2Free(m_broadPhase); }
void b2World::Step(float32 dt, int32 iterations) { b2TimeStep step; step.dt = dt; step.iterations = iterations; if (dt > 0.0f) { step.inv_dt = 1.0f / dt; } else { step.inv_dt = 0.0f; } m_positionIterationCount = 0; // Handle deferred contact destruction. m_contactManager.CleanContactList(); // Handle deferred body destruction. CleanBodyList(); // Update contacts. m_contactManager.Collide(); // Size the island for the worst case. b2Island island(m_bodyCount, m_contactCount, m_jointCount, &m_stackAllocator); // Clear all the island flags. for (b2Body* b = m_bodyList; b; b = b->m_next) { b->m_flags &= ~b2Body::e_islandFlag; } for (b2Contact* c = m_contactList; c; c = c->m_next) { c->m_flags &= ~b2Contact::e_islandFlag; } for (b2Joint* j = m_jointList; j; j = j->m_next) { j->m_islandFlag = false; } // Build and simulate all awake islands. int32 stackSize = m_bodyCount; b2Body** stack = (b2Body**)m_stackAllocator.Allocate(stackSize * sizeof(b2Body*)); for (b2Body* seed = m_bodyList; seed; seed = seed->m_next) { if (seed->m_flags & (b2Body::e_staticFlag | b2Body::e_islandFlag | b2Body::e_sleepFlag | b2Body::e_frozenFlag)) { continue; } // Reset island and stack. island.Clear(); int32 stackCount = 0; stack[stackCount++] = seed; seed->m_flags |= b2Body::e_islandFlag; // Perform a depth first search (DFS) on the constraint graph. while (stackCount > 0) { // Grab the next body off the stack and add it to the island. b2Body* b = stack[--stackCount]; island.Add(b); // Make sure the body is awake. b->m_flags &= ~b2Body::e_sleepFlag; // To keep islands as small as possible, we don't // propagate islands across static bodies. if (b->m_flags & b2Body::e_staticFlag) { continue; } // Search all contacts connected to this body. for (b2ContactNode* cn = b->m_contactList; cn; cn = cn->next) { if (cn->contact->m_flags & b2Contact::e_islandFlag) { continue; } island.Add(cn->contact); cn->contact->m_flags |= b2Contact::e_islandFlag; b2Body* other = cn->other; if (other->m_flags & b2Body::e_islandFlag) { continue; } b2Assert(stackCount < stackSize); stack[stackCount++] = other; other->m_flags |= b2Body::e_islandFlag; } // Search all joints connect to this body. for (b2JointNode* jn = b->m_jointList; jn; jn = jn->next) { if (jn->joint->m_islandFlag == true) { continue; } island.Add(jn->joint); jn->joint->m_islandFlag = true; b2Body* other = jn->other; if (other->m_flags & b2Body::e_islandFlag) { continue; } b2Assert(stackCount < stackSize); stack[stackCount++] = other; other->m_flags |= b2Body::e_islandFlag; } } island.Solve(&step, m_gravity); m_positionIterationCount = b2Max(m_positionIterationCount, island.m_positionIterationCount); if (m_allowSleep) { island.UpdateSleep(dt); } // Post solve cleanup. for (int32 i = 0; i < island.m_bodyCount; ++i) { // Allow static bodies to participate in other islands. b2Body* b = island.m_bodies[i]; if (b->m_flags & b2Body::e_staticFlag) { b->m_flags &= ~b2Body::e_islandFlag; } // Handle newly frozen bodies. if (b->IsFrozen() && m_listener) { b2BoundaryResponse response = m_listener->NotifyBoundaryViolated(b); if (response == b2_destroyBody) { DestroyBody(b); b = NULL; island.m_bodies[i] = NULL; } } } } m_stackAllocator.Free(stack); m_broadPhase->Commit(); #if 0 for (b2Contact* c = m_contactList; c; c = c->GetNext()) { b2Shape* shape1 = c->GetShape1(); b2Shape* shape2 = c->GetShape2(); b2Body* body1 = shape1->GetBody(); b2Body* body2 = shape2->GetBody(); if (body1->IsSleeping() && body2->IsSleeping()) { continue; } b2Conservative(shape1, shape2); } #endif }
PhysicsWorld::~PhysicsWorld(void) { // destroy bodies while (!mRigidBodies.empty()) DestroyBody(*mRigidBodies.begin()); }
void cPhysicsObject::RemoveFromWorld() { DestroyBody(); DestroyGeom(); DestroyHeightfield(); }