diff --git a/indra/newview/llfloaterworldmap.cpp b/indra/newview/llfloaterworldmap.cpp index b8e0e50412778c12f283098e3b855de7d2e84bcc..146f68ee53f640ea41e7a9d561ae1700162e0a6c 100644 --- a/indra/newview/llfloaterworldmap.cpp +++ b/indra/newview/llfloaterworldmap.cpp @@ -1607,7 +1607,14 @@ void LLFloaterWorldMap::updateSims(bool found_null_sim) S32 num_results = 0; - std::vector<std::pair <U64, LLSimInfo*> > sim_info_vec(LLWorldMap::getInstanceFast()->getRegionMap().begin(), LLWorldMap::getInstanceFast()->getRegionMap().end()); + const auto& region_map = LLWorldMap::getInstanceFast()->getRegionMap(); + + std::vector<std::pair <U64, LLSimInfo*> > sim_info_vec; + sim_info_vec.reserve(region_map.size()); + for (const auto& region_pair : region_map) + { + sim_info_vec.emplace_back(region_pair.first, region_pair.second.get()); + } 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) @@ -1676,7 +1683,7 @@ void LLFloaterWorldMap::onCommitSearchResult() for (const auto& sim_info_pair : LLWorldMap::getInstanceFast()->getRegionMap()) { - LLSimInfo* info = sim_info_pair.second; + LLSimInfo* info = sim_info_pair.second.get(); if (info->isName(sim_name)) { diff --git a/indra/newview/llworldmap.cpp b/indra/newview/llworldmap.cpp index 0afc4386918262b7041c61a487b86862ab7caf2c..760a85df4bb421ef1dba484339ee66e746f7cf12 100644 --- a/indra/newview/llworldmap.cpp +++ b/indra/newview/llworldmap.cpp @@ -262,7 +262,6 @@ void LLWorldMap::reset() clearSimFlags(); // Clear the block info flags array // Finally, clear the region map itself - for_each(mSimInfoMap.begin(), mSimInfoMap.end(), DeletePairedPointer()); mSimInfoMap.clear(); } @@ -277,7 +276,7 @@ bool LLWorldMap::clearItems(bool force) LLSimInfo* sim_info = NULL; for (sim_info_map_t::iterator it = mSimInfoMap.begin(); it != mSimInfoMap.end(); ++it) { - sim_info = it->second; + sim_info = it->second.get(); if (sim_info) { sim_info->clearItems(); @@ -299,7 +298,7 @@ void LLWorldMap::clearImageRefs() LLSimInfo* sim_info = NULL; for (sim_info_map_t::iterator it = mSimInfoMap.begin(); it != mSimInfoMap.end(); ++it) { - sim_info = it->second; + sim_info = it->second.get(); if (sim_info) { sim_info->clearImage(); @@ -316,9 +315,8 @@ void LLWorldMap::clearSimFlags() LLSimInfo* LLWorldMap::createSimInfoFromHandle(const U64 handle) { - LLSimInfo* sim_info = new LLSimInfo(handle); - mSimInfoMap[handle] = sim_info; - return sim_info; + auto ret = mSimInfoMap.insert_or_assign(handle, std::make_unique<LLSimInfo>(handle)); + return ret.first->second.get(); } void LLWorldMap::equalizeBoostLevels() @@ -338,7 +336,7 @@ LLSimInfo* LLWorldMap::simInfoFromHandle(const U64 handle) sim_info_map_t::iterator it = mSimInfoMap.find(handle); if (it != mSimInfoMap.end()) { - return it->second; + return it->second.get(); } U32 x = 0, y = 0; from_region_handle(handle, &x, &y); @@ -348,7 +346,7 @@ LLSimInfo* LLWorldMap::simInfoFromHandle(const U64 handle) U32 checkRegionX, checkRegionY; from_region_handle(sim_info_pair.first, &checkRegionX, &checkRegionY); - LLSimInfo* info = sim_info_pair.second; + LLSimInfo* info = sim_info_pair.second.get(); if (x >= checkRegionX && x < (checkRegionX + info->getSizeX()) && y >= checkRegionY && y < (checkRegionY + info->getSizeY())) { @@ -367,7 +365,7 @@ LLSimInfo* LLWorldMap::simInfoFromName(const std::string& sim_name) // Iterate through the entire sim info map and compare the name for (const auto& sim_info_pair : mSimInfoMap) { - auto temp_sim_info = sim_info_pair.second; + auto temp_sim_info = sim_info_pair.second.get(); if (temp_sim_info && temp_sim_info->isName(sim_name) ) { sim_info = temp_sim_info; @@ -606,7 +604,7 @@ void LLWorldMap::dropImagePriorities() // Same for the "land for sale" tiles per region for (sim_info_map_t::iterator it = mSimInfoMap.begin(); it != mSimInfoMap.end(); ++it) { - LLSimInfo* info = it->second; + LLSimInfo* info = it->second.get(); info->dropImagePriority(); } } @@ -657,7 +655,7 @@ void LLWorldMap::dump() LL_INFOS("WorldMap") << "LLWorldMap::dump()" << LL_ENDL; for (sim_info_map_t::iterator it = mSimInfoMap.begin(); it != mSimInfoMap.end(); ++it) { - LLSimInfo* info = it->second; + LLSimInfo* info = it->second.get(); if (info) { info->dump(); diff --git a/indra/newview/llworldmap.h b/indra/newview/llworldmap.h index 1190871c3c50db729d6e49335d13317b1730b4f9..d8775b8f9e3b10d49a1217c3e0ee5c8959385374 100644 --- a/indra/newview/llworldmap.h +++ b/indra/newview/llworldmap.h @@ -216,7 +216,7 @@ class LLWorldMap final : public LLSingleton<LLWorldMap> void reloadItems(bool force = false); // Reload the items (people, hub, etc...) // Region Map access - typedef std::map<U64, LLSimInfo*> sim_info_map_t; + typedef absl::flat_hash_map<U64, std::unique_ptr<LLSimInfo>> sim_info_map_t; const LLWorldMap::sim_info_map_t& getRegionMap() const { return mSimInfoMap; } void updateRegions(S32 x0, S32 y0, S32 x1, S32 y1); // Requests region info for a rectangle of regions (in grid coordinates) diff --git a/indra/newview/llworldmapview.cpp b/indra/newview/llworldmapview.cpp index 679b28eb0e7a9b084909e7c860612c44b3341347..90d434c1876a896bf1f0c1d0e57553a877fcb180 100644 --- a/indra/newview/llworldmapview.cpp +++ b/indra/newview/llworldmapview.cpp @@ -351,7 +351,7 @@ void LLWorldMapView::draw() for (const auto& sim_info_pair : LLWorldMap::getInstanceFast()->getRegionMap()) { U64 handle = sim_info_pair.first; - LLSimInfo* info = sim_info_pair.second; + LLSimInfo* info = sim_info_pair.second.get(); LLVector3d origin_global = from_region_handle(handle); diff --git a/indra/newview/llworldmipmap.cpp b/indra/newview/llworldmipmap.cpp index f31449ab668718a09a6d21fa8c4a8ecc79023817..d0af06be24e63d844e4dd538fd9117ac7dcb2d96 100644 --- a/indra/newview/llworldmipmap.cpp +++ b/indra/newview/llworldmipmap.cpp @@ -72,7 +72,7 @@ void LLWorldMipmap::equalizeBoostLevels() { sublevel_tiles_t& level_mipmap = mWorldObjectsMipMap[level]; // For each tile - for (sublevel_tiles_t::iterator iter = level_mipmap.begin(); iter != level_mipmap.end(); iter++) + for (sublevel_tiles_t::iterator iter = level_mipmap.begin(), end_it = level_mipmap.end(); iter != end_it; ++iter) { LLPointer<LLViewerFetchedTexture> img = iter->second; S32 current_boost_level = img->getBoostLevel(); @@ -114,7 +114,7 @@ void LLWorldMipmap::dropBoostLevels() { sublevel_tiles_t& level_mipmap = mWorldObjectsMipMap[level]; // For each tile - for (sublevel_tiles_t::iterator iter = level_mipmap.begin(); iter != level_mipmap.end(); iter++) + for (sublevel_tiles_t::iterator iter = level_mipmap.begin(), end_it = level_mipmap.end(); iter != end_it; iter++) { LLPointer<LLViewerFetchedTexture> img = iter->second; img->setBoostLevel(LLGLTexture::BOOST_NONE); @@ -151,9 +151,16 @@ LLPointer<LLViewerFetchedTexture> LLWorldMipmap::getObjectsTile(U32 grid_x, U32 // Load it LLPointer<LLViewerFetchedTexture> img = loadObjectsTile(grid_x, grid_y, level); // Insert the image in the map - level_mipmap.insert(sublevel_tiles_t::value_type( handle, img )); - // Find the element again in the map (it's there now...) - found = level_mipmap.find(handle); + const auto& ret = level_mipmap.emplace(handle, img); + if (ret.second) + { + // Find the element again in the map (it's there now...) + found = ret.first; + } + else + { + return nullptr; + } } else { @@ -193,10 +200,10 @@ LLPointer<LLViewerFetchedTexture> LLWorldMipmap::loadObjectsTile(U32 grid_x, U32 // END DEBUG //LL_INFOS("WorldMap") << "LLWorldMipmap::loadObjectsTile(), URL = " << imageurl << LL_ENDL; - LLPointer<LLViewerFetchedTexture> img = LLViewerTextureManager::getFetchedTextureFromUrl(imageurl, FTT_MAP_TILE, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE); + LLPointer<LLViewerFetchedTexture> img = LLViewerTextureManager::getFetchedTextureFromUrl(imageurl, FTT_MAP_TILE, TRUE, LLGLTexture::BOOST_MAP, LLViewerTexture::LOD_TEXTURE); +#if SHOW_DEBUG LL_DEBUGS("MAPURL") << "fetching map tile from " << imageurl << LL_ENDL; - - img->setBoostLevel(LLGLTexture::BOOST_MAP); +#endif // Return the smart pointer return img; @@ -221,19 +228,16 @@ void LLWorldMipmap::cleanMissedTilesFromLevel(S32 level) // Iterate through the subresolution level and suppress the tiles that are marked as missing // Note: erasing in a map while iterating through it is bug prone. Using a postfix increment is mandatory here. sublevel_tiles_t& level_mipmap = mWorldObjectsMipMap[level-1]; - sublevel_tiles_t::iterator it = level_mipmap.begin(); - while (it != level_mipmap.end()) + for (auto it = level_mipmap.begin(), end = level_mipmap.end(); it != end;) { - LLPointer<LLViewerFetchedTexture> img = it->second; - if (img->isMissingAsset()) + auto copy_it = it++; + LLPointer<LLViewerFetchedTexture> img = copy_it->second; + if (img->isMissingAsset()) { - level_mipmap.erase(it++); - } - else - { - ++it; + level_mipmap.erase(copy_it); } } + return; } diff --git a/indra/newview/llworldmipmap.h b/indra/newview/llworldmipmap.h index 963aac1403d4d497e129d3f74d2fb67c65cb7195..44a8455334da36bcc4b23daa7723735f21d41b4e 100644 --- a/indra/newview/llworldmipmap.h +++ b/indra/newview/llworldmipmap.h @@ -84,7 +84,7 @@ class LLWorldMipmap // The mipmap is organized by resolution level (MAP_LEVELS of them). Each resolution level is an std::map // using a region_handle as a key and storing a smart pointer to the image as a value. - typedef std::map<U64, LLPointer<LLViewerFetchedTexture> > sublevel_tiles_t; + typedef absl::flat_hash_map<U64, LLPointer<LLViewerFetchedTexture> > sublevel_tiles_t; sublevel_tiles_t mWorldObjectsMipMap[MAP_LEVELS]; // sublevel_tiles_t mWorldTerrainMipMap[MAP_LEVELS]; diff --git a/indra/newview/tests/llworldmap_test.cpp b/indra/newview/tests/llworldmap_test.cpp index d058ca76d043291f73c3dfe156ce85c7d41b7cde..9bf29f235777cc47dc8ffd04968dd71b1f37a633 100644 --- a/indra/newview/tests/llworldmap_test.cpp +++ b/indra/newview/tests/llworldmap_test.cpp @@ -403,9 +403,7 @@ namespace tut } // Test 9 : Verify that all the region list is empty - LLWorldMap::sim_info_map_t list; - list = mWorld->getRegionMap(); - ensure("LLWorldMap::getRegionMap() empty at init test failed", list.empty()); + ensure("LLWorldMap::getRegionMap() empty at init test failed", mWorld->getRegionMap().empty()); // Test 10 : Insert a region bool success; @@ -417,8 +415,7 @@ namespace tut id, SIM_ACCESS_PG, REGION_FLAGS_SANDBOX); - list = mWorld->getRegionMap(); - ensure("LLWorldMap::insertRegion() failed", success && (list.size() == 1)); + ensure("LLWorldMap::insertRegion() failed", success && (mWorld->getRegionMap().size() == 1)); // Test 11 : Insert an item in the same region -> number of regions doesn't increase std::string name_item = ITEM_NAME_TEST; @@ -428,8 +425,7 @@ namespace tut id, MAP_ITEM_LAND_FOR_SALE, 0, 0); - list = mWorld->getRegionMap(); - ensure("LLWorldMap::insertItem() in existing region failed", success && (list.size() == 1)); + ensure("LLWorldMap::insertItem() in existing region failed", success && (mWorld->getRegionMap().size() == 1)); // Test 12 : Insert an item in another region -> number of regions increases success = mWorld->insertItem( U32(X_WORLD_TEST + REGION_WIDTH_METERS*2), @@ -438,8 +434,7 @@ namespace tut id, MAP_ITEM_LAND_FOR_SALE, 0, 0); - list = mWorld->getRegionMap(); - ensure("LLWorldMap::insertItem() in unexisting region failed", success && (list.size() == 2)); + ensure("LLWorldMap::insertItem() in unexisting region failed", success && (mWorld->getRegionMap().size() == 2)); // Test 13 : simInfoFromPosGlobal() in region LLVector3d pos1( X_WORLD_TEST + REGION_WIDTH_METERS*2 + REGION_WIDTH_METERS/2, @@ -480,8 +475,7 @@ namespace tut } // Test 19 : Verify that all the region list is empty - list = mWorld->getRegionMap(); - ensure("LLWorldMap::getRegionMap() empty at end test failed", list.empty()); + ensure("LLWorldMap::getRegionMap() empty at end test failed", mWorld->getRegionMap().empty()); } // Test tracking template<> template<>