// moves an entity from a bucket to another bool ETHBucketManager::MoveEntity(const int id, const Vector2 ¤tBucket, const Vector2 &destBucket) { // if the destiny bucket is the current bucket, don't need to do anything if (currentBucket == destBucket) return true; // remove the entity from its current bucket ETHBucketMap::iterator bucketIter = Find(currentBucket); if (bucketIter == GetLastBucket()) { ETH_STREAM_DECL(ss) << GS_L("The current bucket doesn't exist: (") << currentBucket.x << GS_L(",") << currentBucket.y << GS_L(")"); m_provider->Log(ss.str(), Platform::Logger::ERROR); return false; } ETHRenderEntity* entity = 0; ETHEntityList& entityList = bucketIter->second; for (ETHEntityList::iterator iter = entityList.begin(); iter != entityList.end(); ++iter) { if ((*iter)->GetID() == id) { entity = *iter; entityList.erase(iter); break; } } // if the entity hasn't been found if (!entity) { ETH_STREAM_DECL(ss) << GS_L("Couldn't find entity ID ") << id << GS_L(" to move"); m_provider->Log(ss.str(), Platform::Logger::ERROR); return false; } // adds the entity to the destiny bucket if (entity->GetType() == ETHEntityProperties::ET_HORIZONTAL) { m_entities[destBucket].push_front(entity); } else { m_entities[destBucket].push_back(entity); } #if defined(_DEBUG) || defined(DEBUG) ETH_STREAM_DECL(ss) << entity->GetEntityName() << GS_L("(") << entity->GetID() << GS_L(")") << GS_L(" moved from bucket (") << currentBucket.x << GS_L(",") << currentBucket.y << GS_L(") to bucket (") << destBucket.x << GS_L(",") << destBucket.y << GS_L(")"); m_provider->Log(ss.str(), Platform::Logger::INFO); #endif return true; }