void View::deleteEntity(const std::string& eid) { Entity* ent = getEntity(eid); if (ent) { // copy the child array, since setLocation will modify it EntityArray contents; for (unsigned int c=0; c < ent->numContained(); ++c) { contents.push_back(ent->getContained(c)); } while (!contents.empty()) { Entity* child = contents.back(); child->setLocation(ent->getLocation()); WFMath::Point<3> newPos = ent->toLocationCoords(child->getPosition()); WFMath::Quaternion newOrient = ent->getOrientation() * child->getOrientation(); child->m_position = newPos; child->m_orientation = newOrient; contents.pop_back(); } // force a disappear if one hasn't already happened ent->setVisible(false); // redundant? EntityDeleted.emit(ent); ent->shutdown(); //Check if the deleted entity is the avatar one. bool avatarDeleted = ent == m_owner->getEntity(); delete ent; // actually kill it off if (avatarDeleted) { AvatarEntityDeleted.emit(); } } else { if (isPending(eid)) { //debug() << "got delete for pending entity, argh"; m_pending[eid] = SACTION_DISCARD; } else warning() << "got delete for unknown entity " << eid; } }
void CPartitionGrid::AddSectorsToQuery( int groupX,int groupY,int lx1,int ly1,int lx2,int ly2,const SPartitionGridQuery &query,EntityArray &entities ) { int nGroupIndex = GetGroupIndex(groupX,groupY); assert( nGroupIndex >= 0 && nGroupIndex < m_nWidth * m_nHeight ); SectorGroup* pGroup = m_pSectorGroups[nGroupIndex]; if (pGroup && pGroup->nLocationCount > 0) { for (int y = ly1; y <= ly2; y++) { for (int x = lx1; x <= lx2; x++) { for (SGridLocation* pLoc = pGroup->sectors[x][y].first; pLoc != NULL; pLoc = pLoc->next) { if (((query.nEntityFlags & pLoc->nEntityFlags) == query.nEntityFlags) && (query.pEntityClass == 0 || (query.pEntityClass == pLoc->pEntityClass))) { entities.push_back( pLoc->pEntity ); } } } } } }