diff options
author | Ansariel <ansariel.hiller@phoenixviewer.com> | 2024-05-22 19:04:52 +0200 |
---|---|---|
committer | Ansariel <ansariel.hiller@phoenixviewer.com> | 2024-05-22 19:04:52 +0200 |
commit | 1b67dd855c41f5a0cda7ec2a68d98071986ca703 (patch) | |
tree | ab243607f74f78200787bba5b9b88f07ef1b966f /indra/newview/llworldmipmap.cpp | |
parent | 6d6eabca44d08d5b97bfe3e941d2b9687c2246ea (diff) | |
parent | e1623bb276f83a43ce7a197e388720c05bdefe61 (diff) |
Merge remote-tracking branch 'origin/main' into DRTVWR-600-maint-A
# Conflicts:
# autobuild.xml
# indra/cmake/CMakeLists.txt
# indra/cmake/GoogleMock.cmake
# indra/llaudio/llaudioengine_fmodstudio.cpp
# indra/llaudio/llaudioengine_fmodstudio.h
# indra/llaudio/lllistener_fmodstudio.cpp
# indra/llaudio/lllistener_fmodstudio.h
# indra/llaudio/llstreamingaudio_fmodstudio.cpp
# indra/llaudio/llstreamingaudio_fmodstudio.h
# indra/llcharacter/llmultigesture.cpp
# indra/llcharacter/llmultigesture.h
# indra/llimage/llimage.cpp
# indra/llimage/llimagepng.cpp
# indra/llimage/llimageworker.cpp
# indra/llimage/tests/llimageworker_test.cpp
# indra/llmessage/tests/llmockhttpclient.h
# indra/llprimitive/llgltfmaterial.h
# indra/llrender/llfontfreetype.cpp
# indra/llui/llcombobox.cpp
# indra/llui/llfolderview.cpp
# indra/llui/llfolderviewmodel.h
# indra/llui/lllineeditor.cpp
# indra/llui/lllineeditor.h
# indra/llui/lltextbase.cpp
# indra/llui/lltextbase.h
# indra/llui/lltexteditor.cpp
# indra/llui/lltextvalidate.cpp
# indra/llui/lltextvalidate.h
# indra/llui/lluictrl.h
# indra/llui/llview.cpp
# indra/llwindow/llwindowmacosx.cpp
# indra/newview/app_settings/settings.xml
# indra/newview/llappearancemgr.cpp
# indra/newview/llappearancemgr.h
# indra/newview/llavatarpropertiesprocessor.cpp
# indra/newview/llavatarpropertiesprocessor.h
# indra/newview/llbreadcrumbview.cpp
# indra/newview/llbreadcrumbview.h
# indra/newview/llbreastmotion.cpp
# indra/newview/llbreastmotion.h
# indra/newview/llconversationmodel.h
# indra/newview/lldensityctrl.cpp
# indra/newview/lldensityctrl.h
# indra/newview/llface.inl
# indra/newview/llfloatereditsky.cpp
# indra/newview/llfloatereditwater.cpp
# indra/newview/llfloateremojipicker.h
# indra/newview/llfloaterimsessiontab.cpp
# indra/newview/llfloaterprofiletexture.cpp
# indra/newview/llfloaterprofiletexture.h
# indra/newview/llgesturemgr.cpp
# indra/newview/llgesturemgr.h
# indra/newview/llimpanel.cpp
# indra/newview/llimpanel.h
# indra/newview/llinventorybridge.cpp
# indra/newview/llinventorybridge.h
# indra/newview/llinventoryclipboard.cpp
# indra/newview/llinventoryclipboard.h
# indra/newview/llinventoryfunctions.cpp
# indra/newview/llinventoryfunctions.h
# indra/newview/llinventorygallery.cpp
# indra/newview/lllistbrowser.cpp
# indra/newview/lllistbrowser.h
# indra/newview/llpanelobjectinventory.cpp
# indra/newview/llpanelprofile.cpp
# indra/newview/llpanelprofile.h
# indra/newview/llpreviewgesture.cpp
# indra/newview/llsavedsettingsglue.cpp
# indra/newview/llsavedsettingsglue.h
# indra/newview/lltooldraganddrop.cpp
# indra/newview/llurllineeditorctrl.cpp
# indra/newview/llvectorperfoptions.cpp
# indra/newview/llvectorperfoptions.h
# indra/newview/llviewerparceloverlay.cpp
# indra/newview/llviewertexlayer.cpp
# indra/newview/llviewertexturelist.cpp
# indra/newview/macmain.h
# indra/test/test.cpp
Diffstat (limited to 'indra/newview/llworldmipmap.cpp')
-rw-r--r-- | indra/newview/llworldmipmap.cpp | 540 |
1 files changed, 270 insertions, 270 deletions
diff --git a/indra/newview/llworldmipmap.cpp b/indra/newview/llworldmipmap.cpp index 2c0beb0141..7deeb07403 100644 --- a/indra/newview/llworldmipmap.cpp +++ b/indra/newview/llworldmipmap.cpp @@ -1,270 +1,270 @@ -/** - * @file llworldmipmap.cpp - * @brief Data storage for the S3 mipmap of the entire world. - * - * $LicenseInfo:firstyear=2003&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#include "llviewerprecompiledheaders.h" - -#include "llworldmipmap.h" -#include "llviewercontrol.h" // LLControlGroup - -#include "llviewertexturelist.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<LLViewerFetchedTexture> img = iter->second; - S32 current_boost_level = img->getBoostLevel(); - if (current_boost_level == LLGLTexture::BOOST_MAP_VISIBLE) - { - // If level was BOOST_MAP_VISIBLE, the tile has been used in the last draw so keep it high - img->setBoostLevel(LLGLTexture::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(LLGLTexture::BOOST_NONE); - } -#if DEBUG_TILES_STAT - // Increment some stats if compile option on - nb_tiles++; - if (current_boost_level == LLGLTexture::BOOST_MAP_VISIBLE) - { - nb_visible++; - } - if (img->isMissingAsset()) - { - nb_missing++; - } -#endif // DEBUG_TILES_STAT - } - } -#if DEBUG_TILES_STAT - LL_INFOS("WorldMap") << "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<LLViewerFetchedTexture> img = iter->second; - img->setBoostLevel(LLGLTexture::BOOST_NONE); - } - } -} - -LLPointer<LLViewerFetchedTexture> 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<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); - } - 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<LLViewerFetchedTexture> 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(LLGLTexture::BOOST_MAP_VISIBLE); - } - return img; - } -} - -LLPointer<LLViewerFetchedTexture> LLWorldMipmap::loadObjectsTile(U32 grid_x, U32 grid_y, S32 level) -{ - // Get the grid coordinates - std::string imageurl = gSavedSettings.getString("CurrentMapServerURL") + 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("WorldMap") << "LLWorldMipmap::loadObjectsTile(), URL = " << imageurl << LL_ENDL; - - LLPointer<LLViewerFetchedTexture> img = LLViewerTextureManager::getFetchedTextureFromUrl(imageurl, FTT_MAP_TILE, true, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE); - LL_INFOS("MAPURL") << "fetching map tile from " << imageurl << LL_ENDL; - - img->setBoostLevel(LLGLTexture::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<LLViewerFetchedTexture> 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); -} - - +/**
+ * @file llworldmipmap.cpp
+ * @brief Data storage for the S3 mipmap of the entire world.
+ *
+ * $LicenseInfo:firstyear=2003&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2010, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#include "llviewerprecompiledheaders.h"
+
+#include "llworldmipmap.h"
+#include "llviewercontrol.h" // LLControlGroup
+
+#include "llviewertexturelist.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<LLViewerFetchedTexture> img = iter->second;
+ S32 current_boost_level = img->getBoostLevel();
+ if (current_boost_level == LLGLTexture::BOOST_MAP_VISIBLE)
+ {
+ // If level was BOOST_MAP_VISIBLE, the tile has been used in the last draw so keep it high
+ img->setBoostLevel(LLGLTexture::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(LLGLTexture::BOOST_NONE);
+ }
+#if DEBUG_TILES_STAT
+ // Increment some stats if compile option on
+ nb_tiles++;
+ if (current_boost_level == LLGLTexture::BOOST_MAP_VISIBLE)
+ {
+ nb_visible++;
+ }
+ if (img->isMissingAsset())
+ {
+ nb_missing++;
+ }
+#endif // DEBUG_TILES_STAT
+ }
+ }
+#if DEBUG_TILES_STAT
+ LL_INFOS("WorldMap") << "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<LLViewerFetchedTexture> img = iter->second;
+ img->setBoostLevel(LLGLTexture::BOOST_NONE);
+ }
+ }
+}
+
+LLPointer<LLViewerFetchedTexture> 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<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);
+ }
+ 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<LLViewerFetchedTexture> 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(LLGLTexture::BOOST_MAP_VISIBLE);
+ }
+ return img;
+ }
+}
+
+LLPointer<LLViewerFetchedTexture> LLWorldMipmap::loadObjectsTile(U32 grid_x, U32 grid_y, S32 level)
+{
+ // Get the grid coordinates
+ std::string imageurl = gSavedSettings.getString("CurrentMapServerURL") + 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("WorldMap") << "LLWorldMipmap::loadObjectsTile(), URL = " << imageurl << LL_ENDL;
+
+ LLPointer<LLViewerFetchedTexture> img = LLViewerTextureManager::getFetchedTextureFromUrl(imageurl, FTT_MAP_TILE, true, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
+ LL_INFOS("MAPURL") << "fetching map tile from " << imageurl << LL_ENDL;
+
+ img->setBoostLevel(LLGLTexture::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<LLViewerFetchedTexture> 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);
+}
+
+
|