Amazon world map
This commit is contained in:
@@ -494,6 +494,7 @@ set(viewer_SOURCE_FILES
|
||||
llwlparamset.cpp
|
||||
llworld.cpp
|
||||
llworldmap.cpp
|
||||
llworldmipmap.cpp
|
||||
llmapresponders.cpp
|
||||
llworldmapview.cpp
|
||||
llxmlrpctransaction.cpp
|
||||
@@ -968,6 +969,7 @@ set(viewer_HEADER_FILES
|
||||
llwlparamset.h
|
||||
llworld.h
|
||||
llworldmap.h
|
||||
llworldmipmap.h
|
||||
llmapresponders.h
|
||||
llworldmapview.h
|
||||
llxmlrpctransaction.h
|
||||
|
||||
@@ -299,7 +299,7 @@ void LLFloaterWorldMap::show(void*, BOOL center_on_target)
|
||||
LLWorldMap::getInstance()->clearSimFlags();
|
||||
|
||||
const bool request_from_sim = true;
|
||||
LLWorldMap::getInstance()->setCurrentLayer(1, request_from_sim);
|
||||
LLWorldMap::getInstance()->setCurrentLayer(0, request_from_sim);
|
||||
|
||||
// We may already have a bounding box for the regions of the world,
|
||||
// so use that to adjust the view.
|
||||
|
||||
@@ -203,6 +203,8 @@ void LLWorldMap::eraseItems()
|
||||
|
||||
void LLWorldMap::clearImageRefs()
|
||||
{
|
||||
mWorldMipmap.reset();
|
||||
|
||||
for (sim_info_map_t::iterator it = mSimInfoMap.begin(); it != mSimInfoMap.end(); ++it)
|
||||
{
|
||||
LLSimInfo* info = (*it).second;
|
||||
@@ -231,6 +233,12 @@ void LLWorldMap::clearSimFlags()
|
||||
}
|
||||
}
|
||||
|
||||
void LLWorldMap::equalizeBoostLevels()
|
||||
{
|
||||
mWorldMipmap.equalizeBoostLevels();
|
||||
return;
|
||||
}
|
||||
|
||||
LLSimInfo* LLWorldMap::simInfoFromPosGlobal(const LLVector3d& pos_global)
|
||||
{
|
||||
U64 handle = to_region_handle(pos_global);
|
||||
@@ -1071,3 +1079,19 @@ void LLWorldMap::updateTelehubCoverage()
|
||||
mTelehubCoverageMap[index] *= mNeighborMap[index];
|
||||
}*/
|
||||
}
|
||||
|
||||
// Drop priority of all images being fetched by the map
|
||||
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)
|
||||
{
|
||||
LLSimInfo* info = it->second;
|
||||
if (!info->mOverlayImage.isNull())
|
||||
{
|
||||
info->mOverlayImage->setBoostLevel(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "v3dmath.h"
|
||||
#include "llframetimer.h"
|
||||
#include "llmapimagetype.h"
|
||||
#include "llworldmipmap.h"
|
||||
#include "lluuid.h"
|
||||
#include "llmemory.h"
|
||||
#include "llviewerimage.h"
|
||||
@@ -133,6 +134,9 @@ public:
|
||||
// Clears the flags indicating that we've received sim infos
|
||||
// Causes a re-request of the sim info without erasing extisting info
|
||||
void clearSimFlags();
|
||||
|
||||
// Drops the priority of the images being fetched
|
||||
void dropImagePriorities();
|
||||
|
||||
// Returns simulator information, or NULL if out of range
|
||||
LLSimInfo* simInfoFromHandle(const U64 handle);
|
||||
@@ -183,6 +187,13 @@ public:
|
||||
// Bounds of the world, in meters
|
||||
U32 getWorldWidth() const;
|
||||
U32 getWorldHeight() const;
|
||||
|
||||
// World Mipmap delegation: currently used when drawing the mipmap
|
||||
void equalizeBoostLevels();
|
||||
LLPointer<LLViewerImage> getObjectsTile(U32 grid_x, U32 grid_y, S32 level, bool load = true) {
|
||||
return mWorldMipmap.getObjectsTile(grid_x, grid_y, level, load);
|
||||
}
|
||||
|
||||
public:
|
||||
// Map from region-handle to simulator info
|
||||
typedef std::map<U64, LLSimInfo*> sim_info_map_t;
|
||||
@@ -224,6 +235,9 @@ public:
|
||||
S32 mNeighborMapHeight;
|
||||
|
||||
private:
|
||||
|
||||
LLWorldMipmap mWorldMipmap;
|
||||
|
||||
LLTimer mRequestTimer;
|
||||
|
||||
// search for named region for url processing
|
||||
|
||||
@@ -61,12 +61,15 @@
|
||||
#include "llviewerregion.h"
|
||||
#include "llviewerwindow.h"
|
||||
#include "llworldmap.h"
|
||||
#include "llworldmipmap.h"
|
||||
#include "lltexturefetch.h"
|
||||
#include "llappviewer.h" // Only for constants!
|
||||
#include "lltrans.h"
|
||||
|
||||
#include "llglheaders.h"
|
||||
|
||||
#include "hippogridmanager.h"
|
||||
|
||||
// [RLVa:KB]
|
||||
#include "rlvhandler.h"
|
||||
// [/RLVa:KB]
|
||||
@@ -106,6 +109,7 @@ F32 LLWorldMapView::sTargetPanY = 0.f;
|
||||
S32 LLWorldMapView::sTrackingArrowX = 0;
|
||||
S32 LLWorldMapView::sTrackingArrowY = 0;
|
||||
F32 LLWorldMapView::sPixelsPerMeter = 1.f;
|
||||
bool LLWorldMapView::sVisibleTilesLoaded = false;
|
||||
F32 LLWorldMapView::sMapScale = 128.f;
|
||||
F32 CONE_SIZE = 0.6f;
|
||||
|
||||
@@ -261,6 +265,7 @@ void LLWorldMapView::setScale( F32 scale )
|
||||
sTargetPanY = sPanY;
|
||||
|
||||
sPixelsPerMeter = sMapScale / REGION_WIDTH_METERS;
|
||||
sVisibleTilesLoaded = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,6 +277,7 @@ void LLWorldMapView::translatePan( S32 delta_x, S32 delta_y )
|
||||
sPanY += delta_y;
|
||||
sTargetPanX = sPanX;
|
||||
sTargetPanY = sPanY;
|
||||
sVisibleTilesLoaded = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -285,6 +291,7 @@ void LLWorldMapView::setPan( S32 x, S32 y, BOOL snap )
|
||||
sPanX = sTargetPanX;
|
||||
sPanY = sTargetPanY;
|
||||
}
|
||||
sVisibleTilesLoaded = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -335,7 +342,10 @@ void LLWorldMapView::draw()
|
||||
gGL.setColorMask(true, true);
|
||||
gGL.setSceneBlendType(LLRender::BT_ALPHA);
|
||||
|
||||
drawTiles(width, height);
|
||||
if(gHippoGridManager->getConnectedGrid()->isSecondLife())
|
||||
drawMipmap(width, height);
|
||||
else
|
||||
drawTiles(width, height);
|
||||
|
||||
LLFontGL* font = LLFontGL::getFontSansSerifSmall();
|
||||
const F32 half_width = F32(width) / 2.0f;
|
||||
@@ -922,8 +932,6 @@ void LLWorldMapView::drawTiles(S32 width, S32 height) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LLWorldMapView::drawGenericItems(const LLWorldMap::item_info_list_t& items, LLUIImagePtr image)
|
||||
{
|
||||
LLWorldMap::item_info_list_t::const_iterator e;
|
||||
@@ -1122,6 +1130,138 @@ void LLWorldMapView::drawFrustum()
|
||||
gGL.popMatrix();
|
||||
}
|
||||
|
||||
void LLWorldMapView::drawMipmap(S32 width, S32 height)
|
||||
{
|
||||
// Compute the level of the mipmap to use for the current scale level
|
||||
S32 level = LLWorldMipmap::scaleToLevel(sMapScale);
|
||||
// Set the tile boost level so that unused tiles get to 0
|
||||
LLWorldMap::getInstance()->equalizeBoostLevels();
|
||||
|
||||
// Render whatever we already have loaded if we haven't the current level
|
||||
// complete and use it as a background (scaled up or scaled down)
|
||||
if (!sVisibleTilesLoaded)
|
||||
{
|
||||
// Note: the (load = false) parameter avoids missing tiles to be fetched (i.e. we render what we have, no more)
|
||||
// Check all the lower res levels and render them in reverse order (worse to best)
|
||||
// We need to traverse all the levels as the user can zoom in very fast
|
||||
for (S32 l = LLWorldMipmap::MAP_LEVELS; l > level; l--)
|
||||
{
|
||||
drawMipmapLevel(width, height, l, false);
|
||||
}
|
||||
// Skip the current level, as we'll do it anyway here under...
|
||||
|
||||
// Just go one level down in res as it can really get too much stuff
|
||||
// when zooming out and too small to see anyway...
|
||||
if (level > 1)
|
||||
{
|
||||
drawMipmapLevel(width, height, level - 1, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//LL_INFOS("World Map") << "Render complete, don't draw background..." << LL_ENDL;
|
||||
}
|
||||
|
||||
// Render the current level
|
||||
sVisibleTilesLoaded = drawMipmapLevel(width, height, level);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Return true if all the tiles required to render that level have been fetched or are truly missing
|
||||
bool LLWorldMapView::drawMipmapLevel(S32 width, S32 height, S32 level, bool load)
|
||||
{
|
||||
// Check input level
|
||||
llassert (level > 0);
|
||||
if (level <= 0)
|
||||
return false;
|
||||
|
||||
// Count tiles hit and completed
|
||||
S32 completed_tiles = 0;
|
||||
S32 total_tiles = 0;
|
||||
|
||||
// Size in meters (global) of each tile of that level
|
||||
S32 tile_width = LLWorldMipmap::MAP_TILE_SIZE * (1 << (level - 1));
|
||||
// Dimension of the screen in meter at that scale
|
||||
LLVector3d pos_SW = viewPosToGlobal(0, 0);
|
||||
LLVector3d pos_NE = viewPosToGlobal(width, height);
|
||||
// Add external band of tiles on the outskirt so to hit the partially displayed tiles right and top
|
||||
pos_NE[VX] += tile_width;
|
||||
pos_NE[VY] += tile_width;
|
||||
|
||||
// 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)
|
||||
{
|
||||
for (F64 index_x = pos_SW[VX]; index_x < pos_NE[VX]; index_x += tile_width)
|
||||
{
|
||||
// Compute the world coordinates of the current point
|
||||
LLVector3d pos_global(index_x, index_y, pos_SW[VZ]);
|
||||
// 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<LLViewerImage> simimage = LLWorldMap::getInstance()->getObjectsTile(grid_x, grid_y, level, load);
|
||||
if (simimage)
|
||||
{
|
||||
// Check the texture state
|
||||
if (simimage->getHasGLTexture())
|
||||
{
|
||||
// Increment the number of completly fetched tiles
|
||||
completed_tiles++;
|
||||
|
||||
// Convert those coordinates (SW corner of the mipmap tile) into world (meters) coordinates
|
||||
pos_global[VX] = grid_x * REGION_WIDTH_METERS;
|
||||
pos_global[VY] = grid_y * REGION_WIDTH_METERS;
|
||||
// Now to screen coordinates for SW corner of that tile
|
||||
LLVector3 pos_screen = globalPosToView (pos_global);
|
||||
F32 left = pos_screen[VX];
|
||||
F32 bottom = pos_screen[VY];
|
||||
// Compute the NE corner coordinates of the tile now
|
||||
pos_global[VX] += tile_width;
|
||||
pos_global[VY] += tile_width;
|
||||
pos_screen = globalPosToView (pos_global);
|
||||
F32 right = pos_screen[VX];
|
||||
F32 top = pos_screen[VY];
|
||||
|
||||
// Draw the tile
|
||||
LLGLSUIDefault gls_ui;
|
||||
gGL.getTexUnit(0)->bind(simimage.get());
|
||||
simimage->setAddressMode(LLTexUnit::TAM_CLAMP);
|
||||
|
||||
gGL.setSceneBlendType(LLRender::BT_ALPHA);
|
||||
gGL.color4f(1.f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
gGL.begin(LLRender::QUADS);
|
||||
gGL.texCoord2f(0.f, 1.f);
|
||||
gGL.vertex3f(left, top, 0.f);
|
||||
gGL.texCoord2f(0.f, 0.f);
|
||||
gGL.vertex3f(left, bottom, 0.f);
|
||||
gGL.texCoord2f(1.f, 0.f);
|
||||
gGL.vertex3f(right, bottom, 0.f);
|
||||
gGL.texCoord2f(1.f, 1.f);
|
||||
gGL.vertex3f(right, top, 0.f);
|
||||
gGL.end();
|
||||
#if DEBUG_DRAW_TILE
|
||||
drawTileOutline(level, top, left, bottom, right);
|
||||
#endif // DEBUG_DRAW_TILE
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// Waiting for a tile -> the level is not complete
|
||||
// LL_INFOS("World Map") << "Unfetched tile. level = " << level << LL_ENDL;
|
||||
//}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unexistent tiles are counted as "completed"
|
||||
completed_tiles++;
|
||||
}
|
||||
// Increment the number of tiles in that level / screen
|
||||
total_tiles++;
|
||||
}
|
||||
}
|
||||
return (completed_tiles == total_tiles);
|
||||
}
|
||||
|
||||
LLVector3 LLWorldMapView::globalPosToView( const LLVector3d& global_pos )
|
||||
{
|
||||
|
||||
@@ -95,6 +95,8 @@ public:
|
||||
void drawAgents();
|
||||
void drawEvents();
|
||||
void drawFrustum();
|
||||
void drawMipmap(S32 width, S32 height);
|
||||
bool drawMipmapLevel(S32 width, S32 height, S32 level, bool load = true);
|
||||
|
||||
static void cleanupTextures();
|
||||
|
||||
@@ -174,6 +176,7 @@ public:
|
||||
static F32 sTargetPanY; // in pixels
|
||||
static S32 sTrackingArrowX;
|
||||
static S32 sTrackingArrowY;
|
||||
static bool sVisibleTilesLoaded;
|
||||
|
||||
// Are we mid-pan from a user drag?
|
||||
BOOL mPanning;
|
||||
|
||||
274
indra/newview/llworldmipmap.cpp
Normal file
274
indra/newview/llworldmipmap.cpp
Normal file
@@ -0,0 +1,274 @@
|
||||
/**
|
||||
* @file llworldmipmap.cpp
|
||||
* @brief Data storage for the S3 mipmap of the entire world.
|
||||
*
|
||||
* $LicenseInfo:firstyear=2003&license=viewergpl$
|
||||
*
|
||||
* Copyright (c) 2003-2009, Linden Research, Inc.
|
||||
*
|
||||
* Second Life Viewer Source Code
|
||||
* The source code in this file ("Source Code") is provided by Linden Lab
|
||||
* to you under the terms of the GNU General Public License, version 2.0
|
||||
* ("GPL"), unless you have obtained a separate licensing agreement
|
||||
* ("Other License"), formally executed by you and Linden Lab. Terms of
|
||||
* the GPL can be found in doc/GPL-license.txt in this distribution, or
|
||||
* online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
|
||||
*
|
||||
* There are special exceptions to the terms and conditions of the GPL as
|
||||
* it is applied to this Source Code. View the full text of the exception
|
||||
* in the file doc/FLOSS-exception.txt in this software distribution, or
|
||||
* online at
|
||||
* http://secondlifegrid.net/programs/open_source/licensing/flossexception
|
||||
*
|
||||
* By copying, modifying or distributing this software, you acknowledge
|
||||
* that you have read and understood your obligations described above,
|
||||
* and agree to abide by those obligations.
|
||||
*
|
||||
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
|
||||
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
|
||||
* COMPLETENESS OR PERFORMANCE.
|
||||
* $/LicenseInfo$
|
||||
*/
|
||||
|
||||
#include "llviewerprecompiledheaders.h"
|
||||
|
||||
#include "llworldmipmap.h"
|
||||
|
||||
#include "llviewercontrol.h"
|
||||
#include "llviewerimagelist.h"
|
||||
#include "math.h" // log()
|
||||
|
||||
// Turn this on to output tile stats in the standard output
|
||||
#define DEBUG_TILES_STAT 0
|
||||
|
||||
LLWorldMipmap::LLWorldMipmap() :
|
||||
mCurrentLevel(0)
|
||||
{
|
||||
}
|
||||
|
||||
LLWorldMipmap::~LLWorldMipmap()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
// Delete all sublevel maps and clean them
|
||||
void LLWorldMipmap::reset()
|
||||
{
|
||||
for (int level = 0; level < MAP_LEVELS; level++)
|
||||
{
|
||||
mWorldObjectsMipMap[level].clear();
|
||||
}
|
||||
}
|
||||
|
||||
// This method should be called before each use of the mipmap (typically, before each draw), so that to let
|
||||
// the boost level of unused tiles to drop to 0 (BOOST_NONE).
|
||||
// Tiles that are accessed have had their boost level pushed to BOOST_MAP_VISIBLE so we can identify them.
|
||||
// The result of this strategy is that if a tile is not used during 2 consecutive loops, its boost level drops to 0.
|
||||
void LLWorldMipmap::equalizeBoostLevels()
|
||||
{
|
||||
#if DEBUG_TILES_STAT
|
||||
S32 nb_missing = 0;
|
||||
S32 nb_tiles = 0;
|
||||
S32 nb_visible = 0;
|
||||
#endif // DEBUG_TILES_STAT
|
||||
// For each level
|
||||
for (S32 level = 0; level < MAP_LEVELS; level++)
|
||||
{
|
||||
sublevel_tiles_t& level_mipmap = mWorldObjectsMipMap[level];
|
||||
// For each tile
|
||||
for (sublevel_tiles_t::iterator iter = level_mipmap.begin(); iter != level_mipmap.end(); iter++)
|
||||
{
|
||||
LLPointer<LLViewerImage> img = iter->second;
|
||||
S32 current_boost_level = img->getBoostLevel();
|
||||
if (current_boost_level == LLViewerImageBoostLevel::BOOST_MAP_VISIBLE)
|
||||
{
|
||||
// If level was BOOST_MAP_VISIBLE, the tile has been used in the last draw so keep it high
|
||||
img->setBoostLevel(LLViewerImageBoostLevel::BOOST_MAP);
|
||||
}
|
||||
else
|
||||
{
|
||||
// If level was BOOST_MAP only (or anything else...), the tile wasn't used in the last draw
|
||||
// so we drop its boost level to BOOST_NONE.
|
||||
img->setBoostLevel(LLViewerImageBoostLevel::BOOST_NONE);
|
||||
}
|
||||
#if DEBUG_TILES_STAT
|
||||
// Increment some stats if compile option on
|
||||
nb_tiles++;
|
||||
if (current_boost_level == LLViewerImageBoostLevel::BOOST_MAP_VISIBLE)
|
||||
{
|
||||
nb_visible++;
|
||||
}
|
||||
if (img->isMissingAsset())
|
||||
{
|
||||
nb_missing++;
|
||||
}
|
||||
#endif // DEBUG_TILES_STAT
|
||||
}
|
||||
}
|
||||
#if DEBUG_TILES_STAT
|
||||
LL_INFOS("World Map") << "LLWorldMipmap tile stats : total requested = " << nb_tiles << ", visible = " << nb_visible << ", missing = " << nb_missing << LL_ENDL;
|
||||
#endif // DEBUG_TILES_STAT
|
||||
}
|
||||
|
||||
// This method should be used when the mipmap is not actively used for a while, e.g., the map UI is hidden
|
||||
void LLWorldMipmap::dropBoostLevels()
|
||||
{
|
||||
// For each level
|
||||
for (S32 level = 0; level < MAP_LEVELS; level++)
|
||||
{
|
||||
sublevel_tiles_t& level_mipmap = mWorldObjectsMipMap[level];
|
||||
// For each tile
|
||||
for (sublevel_tiles_t::iterator iter = level_mipmap.begin(); iter != level_mipmap.end(); iter++)
|
||||
{
|
||||
LLPointer<LLViewerImage> img = iter->second;
|
||||
img->setBoostLevel(LLViewerImageBoostLevel::BOOST_NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LLPointer<LLViewerImage> LLWorldMipmap::getObjectsTile(U32 grid_x, U32 grid_y, S32 level, bool load)
|
||||
{
|
||||
// Check the input data
|
||||
llassert(level <= MAP_LEVELS);
|
||||
llassert(level >= 1);
|
||||
|
||||
// If the *loading* level changed, cleared the new level from "missed" tiles
|
||||
// so that we get a chance to reload them
|
||||
if (load && (level != mCurrentLevel))
|
||||
{
|
||||
cleanMissedTilesFromLevel(level);
|
||||
mCurrentLevel = level;
|
||||
}
|
||||
|
||||
// Build the region handle
|
||||
U64 handle = convertGridToHandle(grid_x, grid_y);
|
||||
|
||||
// Check if the image is around already
|
||||
sublevel_tiles_t& level_mipmap = mWorldObjectsMipMap[level-1];
|
||||
sublevel_tiles_t::iterator found = level_mipmap.find(handle);
|
||||
|
||||
// If not there and load on, go load it
|
||||
if (found == level_mipmap.end())
|
||||
{
|
||||
if (load)
|
||||
{
|
||||
// Load it
|
||||
LLPointer<LLViewerImage> 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);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Return with NULL if not found and we're not trying to load
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the image pointer and check if this asset is missing
|
||||
LLPointer<LLViewerImage> img = found->second;
|
||||
if (img->isMissingAsset())
|
||||
{
|
||||
// Return NULL if asset missing
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Boost the tile level so to mark it's in use *if* load on
|
||||
if (load)
|
||||
{
|
||||
img->setBoostLevel(LLViewerImageBoostLevel::BOOST_MAP_VISIBLE);
|
||||
}
|
||||
return img;
|
||||
}
|
||||
}
|
||||
|
||||
LLPointer<LLViewerImage> LLWorldMipmap::loadObjectsTile(U32 grid_x, U32 grid_y, S32 level)
|
||||
{
|
||||
// Get the grid coordinates
|
||||
std::string imageurl = gSavedSettings.getString("MapServerURL") + llformat("map-%d-%d-%d-objects.jpg", level, grid_x, grid_y);
|
||||
|
||||
// DO NOT COMMIT!! DEBUG ONLY!!!
|
||||
// Use a local jpeg for every tile to test map speed without S3 access
|
||||
//imageurl = "file://C:\\Develop\\mapserver-distribute-3\\indra\\build-vc80\\mapserver\\relwithdebinfo\\regions\\00995\\01001\\region-995-1001-prims.jpg";
|
||||
// END DEBUG
|
||||
//LL_INFOS("World Map") << "LLWorldMipmap::loadObjectsTile(), URL = " << imageurl << LL_ENDL;
|
||||
|
||||
LLPointer<LLViewerImage> img = gImageList.getImageFromUrl(imageurl);
|
||||
img->setBoostLevel(LLViewerImageBoostLevel::BOOST_MAP);
|
||||
|
||||
// Return the smart pointer
|
||||
return img;
|
||||
}
|
||||
|
||||
// This method is used to clean up a level from tiles marked as "missing".
|
||||
// The idea is to allow tiles that have been improperly marked missing to be reloaded when retraversing the level again.
|
||||
// When zooming in and out rapidly, some tiles are never properly loaded and, eventually marked missing.
|
||||
// This creates "blue" areas in a subresolution that never got a chance to reload if we don't clean up the level.
|
||||
void LLWorldMipmap::cleanMissedTilesFromLevel(S32 level)
|
||||
{
|
||||
// Check the input data
|
||||
llassert(level <= MAP_LEVELS);
|
||||
llassert(level >= 0);
|
||||
|
||||
// This happens when the object is first initialized
|
||||
if (level == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 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())
|
||||
{
|
||||
LLPointer<LLViewerImage> img = it->second;
|
||||
if (img->isMissingAsset())
|
||||
{
|
||||
level_mipmap.erase(it++);
|
||||
}
|
||||
else
|
||||
{
|
||||
++it;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// static methods
|
||||
// Compute the level in the world mipmap (between 1 and MAP_LEVELS, as in the URL) given the scale (size of a sim in screen pixels)
|
||||
S32 LLWorldMipmap::scaleToLevel(F32 scale)
|
||||
{
|
||||
// If scale really small, picks up the higest level there is (lowest resolution)
|
||||
if (scale <= F32_MIN)
|
||||
return MAP_LEVELS;
|
||||
// Compute the power of two resolution level knowing the base level
|
||||
S32 level = llfloor((log(REGION_WIDTH_METERS/scale)/log(2.0f)) + 1.0f);
|
||||
// Check bounds and return the value
|
||||
if (level > MAP_LEVELS)
|
||||
return MAP_LEVELS;
|
||||
else if (level < 1)
|
||||
return 1;
|
||||
else
|
||||
return level;
|
||||
}
|
||||
|
||||
// Convert world coordinates to mipmap grid coordinates at a given level (between 1 and MAP_LEVELS)
|
||||
void LLWorldMipmap::globalToMipmap(F64 global_x, F64 global_y, S32 level, U32* grid_x, U32* grid_y)
|
||||
{
|
||||
// Check the input data
|
||||
llassert(level <= MAP_LEVELS);
|
||||
llassert(level >= 1);
|
||||
|
||||
// Convert world coordinates into grid coordinates
|
||||
*grid_x = lltrunc(global_x/REGION_WIDTH_METERS);
|
||||
*grid_y = lltrunc(global_y/REGION_WIDTH_METERS);
|
||||
// Compute the valid grid coordinates at that level of the mipmap
|
||||
S32 regions_in_tile = 1 << (level - 1);
|
||||
*grid_x = *grid_x - (*grid_x % regions_in_tile);
|
||||
*grid_y = *grid_y - (*grid_y % regions_in_tile);
|
||||
}
|
||||
|
||||
|
||||
100
indra/newview/llworldmipmap.h
Normal file
100
indra/newview/llworldmipmap.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* @file llworldmipmap.h
|
||||
* @brief Data storage for the S3 mipmap of the entire world.
|
||||
*
|
||||
* $LicenseInfo:firstyear=2003&license=viewergpl$
|
||||
*
|
||||
* Copyright (c) 2003-2009, Linden Research, Inc.
|
||||
*
|
||||
* Second Life Viewer Source Code
|
||||
* The source code in this file ("Source Code") is provided by Linden Lab
|
||||
* to you under the terms of the GNU General Public License, version 2.0
|
||||
* ("GPL"), unless you have obtained a separate licensing agreement
|
||||
* ("Other License"), formally executed by you and Linden Lab. Terms of
|
||||
* the GPL can be found in doc/GPL-license.txt in this distribution, or
|
||||
* online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
|
||||
*
|
||||
* There are special exceptions to the terms and conditions of the GPL as
|
||||
* it is applied to this Source Code. View the full text of the exception
|
||||
* in the file doc/FLOSS-exception.txt in this software distribution, or
|
||||
* online at
|
||||
* http://secondlifegrid.net/programs/open_source/licensing/flossexception
|
||||
*
|
||||
* By copying, modifying or distributing this software, you acknowledge
|
||||
* that you have read and understood your obligations described above,
|
||||
* and agree to abide by those obligations.
|
||||
*
|
||||
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
|
||||
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
|
||||
* COMPLETENESS OR PERFORMANCE.
|
||||
* $/LicenseInfo$
|
||||
*/
|
||||
|
||||
#ifndef LL_LLWORLDMIPMAP_H
|
||||
#define LL_LLWORLDMIPMAP_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "llmemory.h" // LLPointer
|
||||
#include "indra_constants.h" // REGION_WIDTH_UNITS
|
||||
#include "llregionhandle.h" // to_region_handle()
|
||||
|
||||
class LLViewerImage;
|
||||
|
||||
// LLWorldMipmap : Mipmap handling of all the tiles used to render the world at any resolution.
|
||||
// This class provides a clean structured access to the hierarchy of tiles stored in the
|
||||
// Amazon S3 repository and abstracts its directory/file structure.
|
||||
// The interface of this class though still assumes that the caller knows the general level/tiles
|
||||
// structure (at least, that it exists...) but doesn't requite the caller to know the details of it.
|
||||
// IOW, you need to know that rendering levels exists as well as grid coordinates for regions,
|
||||
// but you can ignore where those tiles are located, how to get them, etc...
|
||||
// The class API gives you back LLPointer<LLViewerImage> per tile.
|
||||
|
||||
// See llworldmipmapview.cpp for the implementation of a class who knows how to render an LLWorldMipmap.
|
||||
|
||||
// Implementation notes:
|
||||
// - On the S3 servers, the tiles are rendered in 2 flavors: Objects and Terrain.
|
||||
// - For the moment, LLWorldMipmap implements access only to the Objects tiles.
|
||||
class LLWorldMipmap
|
||||
{
|
||||
public:
|
||||
// Parameters of the mipmap
|
||||
static const S32 MAP_LEVELS = 8; // Number of subresolution levels computed by the mapserver
|
||||
static const S32 MAP_TILE_SIZE = 256; // Width in pixels of the tiles computed by the mapserver
|
||||
|
||||
LLWorldMipmap();
|
||||
~LLWorldMipmap();
|
||||
|
||||
// Clear up the maps and release all image handles
|
||||
void reset();
|
||||
// Manage the boost levels between loops (typically draw() loops)
|
||||
void equalizeBoostLevels();
|
||||
// Drop the boost levels to none (used when hiding the map)
|
||||
void dropBoostLevels();
|
||||
// Get the tile smart pointer, does the loading if necessary
|
||||
LLPointer<LLViewerImage> getObjectsTile(U32 grid_x, U32 grid_y, S32 level, bool load = true);
|
||||
|
||||
// Helper functions: those are here as they depend solely on the topology of the mipmap though they don't access it
|
||||
// Convert sim scale (given in sim width in display pixels) into a mipmap level
|
||||
static S32 scaleToLevel(F32 scale);
|
||||
// Convert world coordinates to mipmap grid coordinates at a given level
|
||||
static void globalToMipmap(F64 global_x, F64 global_y, S32 level, U32* grid_x, U32* grid_y);
|
||||
|
||||
private:
|
||||
// Get a handle (key) from grid coordinates
|
||||
U64 convertGridToHandle(U32 grid_x, U32 grid_y) { return to_region_handle(grid_x * REGION_WIDTH_UNITS, grid_y * REGION_WIDTH_UNITS); }
|
||||
// Load the relevant tile from S3
|
||||
LLPointer<LLViewerImage> loadObjectsTile(U32 grid_x, U32 grid_y, S32 level);
|
||||
// Clear a level from its "missing" tiles
|
||||
void cleanMissedTilesFromLevel(S32 level);
|
||||
|
||||
// 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<LLViewerImage> > sublevel_tiles_t;
|
||||
sublevel_tiles_t mWorldObjectsMipMap[MAP_LEVELS];
|
||||
// sublevel_tiles_t mWorldTerrainMipMap[MAP_LEVELS];
|
||||
|
||||
S32 mCurrentLevel; // The level last accessed by a getObjectsTile()
|
||||
};
|
||||
|
||||
#endif // LL_LLWORLDMIPMAP_H
|
||||
Reference in New Issue
Block a user