Commit a4f32f56 authored by Drake Arconis's avatar Drake Arconis
Browse files

Optimize and cleanup some for loops and various other code

parent 30036884
......@@ -76,9 +76,9 @@ void LLAvatarList::toggleIcons()
// Show/hide icons for all existing items.
std::vector<LLPanel*> items;
getItems(items);
for( std::vector<LLPanel*>::const_iterator it = items.begin(); it != items.end(); it++)
for (auto item : items)
{
static_cast<LLAvatarListItem*>(*it)->setAvatarIconVisible(mShowIcons);
static_cast<LLAvatarListItem*>(item)->setAvatarIconVisible(mShowIcons);
}
}
......@@ -90,9 +90,9 @@ void LLAvatarList::setSpeakingIndicatorsVisible(bool visible)
// Show/hide icons for all existing items.
std::vector<LLPanel*> items;
getItems(items);
for( std::vector<LLPanel*>::const_iterator it = items.begin(); it != items.end(); it++)
for (auto item : items)
{
static_cast<LLAvatarListItem*>(*it)->showSpeakingIndicator(mShowSpeakingIndicator);
static_cast<LLAvatarListItem*>(item)->showSpeakingIndicator(mShowSpeakingIndicator);
}
}
......@@ -104,9 +104,9 @@ void LLAvatarList::showPermissions(bool visible)
// Enable or disable showing permissions icons for all existing items.
std::vector<LLPanel*> items;
getItems(items);
for(std::vector<LLPanel*>::const_iterator it = items.begin(), end_it = items.end(); it != end_it; ++it)
for (auto item : items)
{
static_cast<LLAvatarListItem*>(*it)->setShowPermissions(mShowPermissions);
static_cast<LLAvatarListItem*>(item)->setShowPermissions(mShowPermissions);
}
}
......@@ -294,9 +294,8 @@ void LLAvatarList::refresh()
unsigned nadded = 0;
const std::string waiting_str = LLTrans::getString("AvatarNameWaiting");
for (uuid_vec_t::const_iterator it=added.cbegin(); it != added.cend(); ++it)
for (const auto& buddy_id : added)
{
const LLUUID& buddy_id = *it;
LLAvatarName av_name;
have_names &= LLAvatarNameCache::get(buddy_id, &av_name);
......@@ -331,9 +330,9 @@ void LLAvatarList::refresh()
}
// Handle removed items.
for (uuid_vec_t::const_iterator it = removed.cbegin(); it != removed.cend(); ++it)
for (const auto& item : removed)
{
removeItemByUUID(*it);
removeItemByUUID(item);
modified = true;
}
......@@ -343,9 +342,9 @@ void LLAvatarList::refresh()
std::vector<LLSD> cur_values;
getValues(cur_values);
for (std::vector<LLSD>::const_iterator it = cur_values.cbegin(); it != cur_values.cend(); ++it)
for (const auto& value : cur_values)
{
const LLUUID& buddy_id = it->asUUID();
const LLUUID& buddy_id = value.asUUID();
LLAvatarName av_name;
have_names &= LLAvatarNameCache::get(buddy_id, &av_name);
if (!findInsensitive(getAvatarName(av_name), mNameFilter))
......@@ -380,9 +379,9 @@ void LLAvatarList::refresh()
// Highlight items matching the filter.
std::vector<LLPanel*> items;
getItems(items);
for (std::vector<LLPanel*>::const_iterator it = items.begin(); it != items.end(); ++it)
for (const auto& itemp : items)
{
static_cast<LLAvatarListItem*>(*it)->setHighlight(mNameFilter);
static_cast<LLAvatarListItem*>(itemp)->setHighlight(mNameFilter);
}
// Send refresh_complete signal.
......@@ -399,9 +398,9 @@ void LLAvatarList::updateAvatarNames()
std::vector<LLPanel*> items;
getItems(items);
for (std::vector<LLPanel*>::const_iterator it = items.begin(); it != items.end(); ++it)
for (const auto& itemp : items)
{
LLAvatarListItem* item = static_cast<LLAvatarListItem*>(*it);
LLAvatarListItem* item = static_cast<LLAvatarListItem*>(itemp);
item->setShowCompleteName(mShowCompleteName);
item->updateAvatarName();
}
......@@ -413,9 +412,8 @@ bool LLAvatarList::filterHasMatches()
{
uuid_vec_t values = getIDs();
for (uuid_vec_t::const_iterator it = values.cbegin(); it != values.cend(); ++it)
for (const auto& buddy_id : values)
{
const LLUUID& buddy_id = *it;
LLAvatarName av_name;
bool have_name = LLAvatarNameCache::get(buddy_id, &av_name);
......@@ -543,11 +541,10 @@ bool LLAvatarList::isAvalineItemSelected() const
{
std::vector<LLPanel*> selected_items;
getSelectedItems(selected_items);
std::vector<LLPanel*>::iterator it = selected_items.begin();
for(; it != selected_items.end(); ++it)
for (const auto& selected_item : selected_items)
{
if (dynamic_cast<LLAvalineListItem*>(*it))
if (dynamic_cast<LLAvalineListItem*>(selected_item))
return true;
}
......@@ -589,10 +586,10 @@ void LLAvatarList::updateLastInteractionTimes()
std::vector<LLPanel*> items;
getItems(items);
for( std::vector<LLPanel*>::const_iterator it = items.begin(); it != items.end(); it++)
for(auto itemp : items)
{
// *TODO: error handling
LLAvatarListItem* item = static_cast<LLAvatarListItem*>(*it);
LLAvatarListItem* item = static_cast<LLAvatarListItem*>(itemp);
S32 secs_since = now - (S32) LLRecentPeople::instance().getDate(item->getAvatarId()).secondsSinceEpoch();
if (secs_since >= 0)
item->setLastInteractionTime(secs_since);
......@@ -604,13 +601,15 @@ void LLAvatarList::updateDistances()
std::vector<LLPanel*> items;
getItems(items);
for(std::vector<LLPanel*>::const_iterator it = items.begin(); it != items.end(); ++it)
static LLCachedControl<F32> near_me_range(gSavedSettings, "NearMeRange");
LLWorld::pos_map_t positions;
LLWorld::getInstance()->getAvatars(&positions, gAgent.getPositionGlobal(), near_me_range);
for (auto itemp : items)
{
LLAvatarListItem* item = static_cast<LLAvatarListItem*>(*it);
LLAvatarListItem* item = static_cast<LLAvatarListItem*>(itemp);
if (item->getAvatarId() == gAgentID) continue;
LLWorld::pos_map_t positions;
LLWorld::getInstance()->getAvatars(&positions, gAgent.getPositionGlobal(), gSavedSettings.getF32("NearMeRange"));
LLWorld::pos_map_t::iterator iter = positions.find(item->getAvatarId());
if (iter != positions.end())
item->setDistance((iter->second - gAgent.getPositionGlobal()).magVec());
......
......@@ -1591,9 +1591,9 @@ void LLFloaterWorldMap::updateSims(bool found_null_sim)
std::vector<std::pair <U64, LLSimInfo*> > sim_info_vec(LLWorldMap::getInstance()->getRegionMap().begin(), LLWorldMap::getInstance()->getRegionMap().end());
std::sort(sim_info_vec.begin(), sim_info_vec.end(), SortRegionNames());
for (std::vector<std::pair <U64, LLSimInfo*> >::const_iterator it = sim_info_vec.begin(); it != sim_info_vec.end(); ++it)
for (const auto& sim_info_pair : sim_info_vec)
{
LLSimInfo* info = it->second;
LLSimInfo* info = sim_info_pair.second;
std::string sim_name_lower = info->getName();
LLStringUtil::toLower(sim_name_lower);
......@@ -1655,10 +1655,9 @@ void LLFloaterWorldMap::onCommitSearchResult()
}
LLStringUtil::toLower(sim_name);
std::map<U64, LLSimInfo*>::const_iterator it;
for (it = LLWorldMap::getInstance()->getRegionMap().begin(); it != LLWorldMap::getInstance()->getRegionMap().end(); ++it)
for (auto map_pair : LLWorldMap::getInstance()->getRegionMap())
{
LLSimInfo* info = it->second;
LLSimInfo* info = map_pair.second;
if (info->isName(sim_name))
{
......
......@@ -838,8 +838,8 @@ void LLPanelPeople::updateNearbyList()
return;
std::vector<LLVector3d> positions;
LLWorld::getInstance()->getAvatars(&mNearbyList->getIDs(), &positions, gAgent.getPositionGlobal(), gSavedSettings.getF32("NearMeRange"));
static LLCachedControl<F32> near_me_range(gSavedSettings, "NearMeRange");
LLWorld::getInstance()->getAvatars(&mNearbyList->getIDs(), &positions, gAgent.getPositionGlobal(), near_me_range);
mNearbyList->setDirty();
DISTANCE_COMPARATOR.updateAvatarsPositions(positions, mNearbyList->getIDs());
......
......@@ -265,9 +265,9 @@ bool LLWorldMap::clearItems(bool force)
mRequestTimer.reset();
LLSimInfo* sim_info = nullptr;
for (sim_info_map_t::iterator it = mSimInfoMap.begin(); it != mSimInfoMap.end(); ++it)
for (const auto& sim_info_pair : mSimInfoMap)
{
sim_info = it->second;
sim_info = sim_info_pair.second;
if (sim_info)
{
sim_info->clearItems();
......@@ -287,9 +287,9 @@ void LLWorldMap::clearImageRefs()
// Images hold by the region map
LLSimInfo* sim_info = nullptr;
for (sim_info_map_t::iterator it = mSimInfoMap.begin(); it != mSimInfoMap.end(); ++it)
for (const auto& sim_info_pair : mSimInfoMap)
{
sim_info = it->second;
sim_info = sim_info_pair.second;
if (sim_info)
{
sim_info->clearImage();
......@@ -331,12 +331,13 @@ LLSimInfo* LLWorldMap::simInfoFromHandle(const U64 handle)
}
U32 x = 0, y = 0;
from_region_handle(handle, &x, &y);
for (it = mSimInfoMap.begin(); it != mSimInfoMap.end(); ++it)
for (const auto& sim_info_pair : mSimInfoMap)
{
U32 checkRegionX, checkRegionY;
from_region_handle((*it).first, &checkRegionX, &checkRegionY);
from_region_handle(sim_info_pair.first, &checkRegionX, &checkRegionY);
LLSimInfo* info = (*it).second;
LLSimInfo* info = sim_info_pair.second;
if (x >= checkRegionX && x < (checkRegionX + info->getSizeX()) &&
y >= checkRegionY && y < (checkRegionY + info->getSizeY()))
{
......@@ -353,19 +354,16 @@ LLSimInfo* LLWorldMap::simInfoFromName(const std::string& sim_name)
if (!sim_name.empty())
{
// Iterate through the entire sim info map and compare the name
sim_info_map_t::iterator it;
for (it = mSimInfoMap.begin(); it != mSimInfoMap.end(); ++it)
for (const auto& sim_info_pair : mSimInfoMap)
{
sim_info = it->second;
if (sim_info && sim_info->isName(sim_name) )
auto temp_sim_info = sim_info_pair.second;
if (temp_sim_info && temp_sim_info->isName(sim_name) )
{
sim_info = temp_sim_info;
// break out of loop if success
break;
}
}
// If we got to the end, we haven't found the sim. Reset the ouput value to NULL.
if (it == mSimInfoMap.end())
sim_info = nullptr;
}
return sim_info;
}
......@@ -594,9 +592,9 @@ void LLWorldMap::dropImagePriorities()
// Drop the download of tiles priority to nil
mWorldMipmap.dropBoostLevels();
// Same for the "land for sale" tiles per region
for (sim_info_map_t::iterator it = mSimInfoMap.begin(); it != mSimInfoMap.end(); ++it)
for(const auto& sim_info_pair : mSimInfoMap)
{
LLSimInfo* info = it->second;
LLSimInfo* info = sim_info_pair.second;
info->dropImagePriority();
}
}
......@@ -610,6 +608,8 @@ void LLWorldMap::updateRegions(S32 x0, S32 y0, S32 x1, S32 y1)
y0 = y0 / MAP_BLOCK_SIZE;
y1 = y1 / MAP_BLOCK_SIZE;
auto& world_map_inst = LLWorldMapMessage::instance();
// Load the region info those blocks
for (S32 block_x = llmax(x0, 0); block_x <= llmin(x1, MAP_BLOCK_RES-1); ++block_x)
{
......@@ -619,7 +619,7 @@ void LLWorldMap::updateRegions(S32 x0, S32 y0, S32 x1, S32 y1)
if (!mMapBlockLoaded[offset])
{
//LL_INFOS("World Map") << "Loading Block (" << block_x << "," << block_y << ")" << LL_ENDL;
LLWorldMapMessage::getInstance()->sendMapBlockRequest(block_x * MAP_BLOCK_SIZE, block_y * MAP_BLOCK_SIZE, (block_x * MAP_BLOCK_SIZE) + MAP_BLOCK_SIZE - 1, (block_y * MAP_BLOCK_SIZE) + MAP_BLOCK_SIZE - 1);
world_map_inst.sendMapBlockRequest(block_x * MAP_BLOCK_SIZE, block_y * MAP_BLOCK_SIZE, (block_x * MAP_BLOCK_SIZE) + MAP_BLOCK_SIZE - 1, (block_y * MAP_BLOCK_SIZE) + MAP_BLOCK_SIZE - 1);
mMapBlockLoaded[offset] = true;
}
}
......@@ -629,9 +629,9 @@ void LLWorldMap::updateRegions(S32 x0, S32 y0, S32 x1, S32 y1)
void LLWorldMap::dump()
{
LL_INFOS("World Map") << "LLWorldMap::dump()" << LL_ENDL;
for (sim_info_map_t::iterator it = mSimInfoMap.begin(); it != mSimInfoMap.end(); ++it)
for (const auto& sim_info_pair : mSimInfoMap)
{
LLSimInfo* info = it->second;
LLSimInfo* info = sim_info_pair.second;
if (info)
{
info->dump();
......
......@@ -350,11 +350,10 @@ void LLWorldMapView::draw()
gGL.setColorMask(true, true);
// Draw per sim overlayed information (names, mature, offline...)
for (LLWorldMap::sim_info_map_t::const_iterator it = LLWorldMap::getInstance()->getRegionMap().begin();
it != LLWorldMap::getInstance()->getRegionMap().end(); ++it)
for (auto region_pair : LLWorldMap::getInstance()->getRegionMap())
{
U64 handle = it->first;
LLSimInfo* info = it->second;
U64 handle = region_pair.first;
LLSimInfo* info = region_pair.second;
LLVector3d origin_global = from_region_handle(handle);
......@@ -676,6 +675,8 @@ bool LLWorldMapView::drawMipmapLevel(S32 width, S32 height, S32 level, bool load
pos_NE[VX] += tile_width;
pos_NE[VY] += tile_width;
auto& world_map_inst = LLWorldMap::instance();
// Iterate through the tiles on screen: we just need to ask for one tile every tile_width meters
U32 grid_x, grid_y;
for (F64 index_y = pos_SW[VY]; index_y < pos_NE[VY]; index_y += tile_width)
......@@ -687,7 +688,7 @@ bool LLWorldMapView::drawMipmapLevel(S32 width, S32 height, S32 level, bool load
// Convert to the mipmap level coordinates for that point (i.e. which tile to we hit)
LLWorldMipmap::globalToMipmap(pos_global[VX], pos_global[VY], level, &grid_x, &grid_y);
// Get the tile. Note: NULL means that the image does not exist (so it's considered "complete" as far as fetching is concerned)
LLPointer<LLViewerFetchedTexture> simimage = LLWorldMap::getInstance()->getObjectsTile(grid_x, grid_y, level, load);
LLPointer<LLViewerFetchedTexture> simimage = world_map_inst.getObjectsTile(grid_x, grid_y, level, load);
if (simimage)
{
// Checks that the image has a valid texture
......@@ -787,10 +788,9 @@ void LLWorldMapView::drawTileOutline(S32 level, F32 top, F32 left, F32 bottom, F
void LLWorldMapView::drawGenericItems(const LLSimInfo::item_info_list_t& items, LLUIImagePtr image)
{
LLSimInfo::item_info_list_t::const_iterator e;
for (e = items.begin(); e != items.end(); ++e)
for (auto item_info : items)
{
drawGenericItem(*e, image);
drawGenericItem(item_info, image);
}
}
......@@ -811,7 +811,7 @@ void LLWorldMapView::drawImage(const LLVector3d& global_pos, LLUIImagePtr image,
void LLWorldMapView::drawImageStack(const LLVector3d& global_pos, LLUIImagePtr image, U32 count, F32 offset, const LLColor4& color)
{
LLVector3 pos_map = globalPosToView( global_pos );
for(U32 i=0; i<count; i++)
for (U32 i=0; i<count; i++)
{
image->draw(ll_round(pos_map.mV[VX] - image->getWidth() /2.f),
ll_round(pos_map.mV[VY] - image->getHeight()/2.f + i*offset),
......@@ -827,10 +827,11 @@ void LLWorldMapView::drawItems()
BOOL show_mature = mature_enabled && gSavedSettings.getBOOL("ShowMatureEvents");
BOOL show_adult = adult_enabled && gSavedSettings.getBOOL("ShowAdultEvents");
for (handle_list_t::iterator iter = mVisibleRegions.begin(); iter != mVisibleRegions.end(); ++iter)
auto& world_map_inst = LLWorldMap::instance();
for (auto vis_region_handle : mVisibleRegions)
{
U64 handle = *iter;
LLSimInfo* info = LLWorldMap::getInstance()->simInfoFromHandle(handle);
U64 handle = vis_region_handle;
LLSimInfo* info = world_map_inst.simInfoFromHandle(handle);
if ((info == NULL) || (info->isDown()))
{
continue;
......@@ -879,16 +880,17 @@ void LLWorldMapView::drawAgents()
{
static LLUIColor map_avatar_color = LLUIColorTable::instance().getColor("MapAvatarColor", LLColor4::white);
for (handle_list_t::iterator iter = mVisibleRegions.begin(); iter != mVisibleRegions.end(); ++iter)
auto& world_map_inst = LLWorldMap::instance();
for (auto vis_region_handle : mVisibleRegions)
{
U64 handle = *iter;
LLSimInfo* siminfo = LLWorldMap::getInstance()->simInfoFromHandle(handle);
U64 handle = vis_region_handle;
LLSimInfo* siminfo = world_map_inst.simInfoFromHandle(handle);
if ((siminfo == NULL) || (siminfo->isDown()))
{
continue;
}
LLSimInfo::item_info_list_t::const_iterator it = siminfo->getAgentLocation().begin();
while (it != siminfo->getAgentLocation().end())
LLSimInfo::item_info_list_t::const_iterator it = siminfo->getAgentLocation().cbegin();
while (it != siminfo->getAgentLocation().cend())
{
// Show Individual agents (or little stacks where real agents are)
......@@ -1507,7 +1509,8 @@ void LLWorldMapView::handleClick(S32 x, S32 y, MASK mask,
*hit_type = 0; // hit nothing
LLWorldMap::getInstance()->cancelTracking();
auto& world_map_inst = LLWorldMap::instance();
world_map_inst.cancelTracking();
LLFloaterWorldMap* floater_map = LLFloaterWorldMap::getInstance();
......@@ -1522,10 +1525,10 @@ void LLWorldMapView::handleClick(S32 x, S32 y, MASK mask,
if (gSavedSettings.getBOOL("MapShowEvents") || show_mature || show_adult || gSavedSettings.getBOOL("MapShowLandForSale"))
{
// Iterate through the visible regions
for (handle_list_t::iterator iter = mVisibleRegions.begin(); iter != mVisibleRegions.end(); ++iter)
for (auto vis_region_handle : mVisibleRegions)
{
U64 handle = *iter;
LLSimInfo* siminfo = LLWorldMap::getInstance()->simInfoFromHandle(handle);
U64 handle = vis_region_handle;
LLSimInfo* siminfo = world_map_inst.simInfoFromHandle(handle);
if ((siminfo == NULL) || (siminfo->isDown()))
{
continue;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment