diff options
author | Jozef Behran <jozuejozef@gmail.com> | 2019-08-13 19:58:27 +0200 |
---|---|---|
committer | SmallJoker <SmallJoker@users.noreply.github.com> | 2019-08-13 19:58:27 +0200 |
commit | 72b7a957af331c7481a60705d1a35a78b5afb494 (patch) | |
tree | ab862023f10383403daa2962f087d0890e187e76 | |
parent | 539f016c1b1a706da2c113435ec60bb39c868f4b (diff) | |
download | minetest-72b7a957af331c7481a60705d1a35a78b5afb494.tar.gz minetest-72b7a957af331c7481a60705d1a35a78b5afb494.tar.bz2 minetest-72b7a957af331c7481a60705d1a35a78b5afb494.zip |
Fix unnecessary exception use in Map::getSectorXXX (#8792)
The Map::getSectorNoGenerate throws an exception but no other
code is really dependent on that. Fix the odd instance of
misuse in ClientMap::emergeSector and remove the exception
throwing version of the method along with the "NoEx" suffixes
in the names of these methods.
-rw-r--r-- | src/client/clientmap.cpp | 13 | ||||
-rw-r--r-- | src/map.cpp | 21 | ||||
-rw-r--r-- | src/map.h | 4 |
3 files changed, 13 insertions, 25 deletions
diff --git a/src/client/clientmap.cpp b/src/client/clientmap.cpp index 8a182b14a..15fa45940 100644 --- a/src/client/clientmap.cpp +++ b/src/client/clientmap.cpp @@ -63,14 +63,13 @@ ClientMap::ClientMap( MapSector * ClientMap::emergeSector(v2s16 p2d) { // Check that it doesn't exist already - try { - return getSectorNoGenerate(p2d); - } catch(InvalidPositionException &e) { - } + MapSector *sector = getSectorNoGenerate(p2d); - // Create a sector - MapSector *sector = new MapSector(this, p2d, m_gamedef); - m_sectors[p2d] = sector; + // Create it if it does not exist yet + if (!sector) { + sector = new MapSector(this, p2d, m_gamedef); + m_sectors[p2d] = sector; + } return sector; } diff --git a/src/map.cpp b/src/map.cpp index a1389fd10..2ccd6fd1c 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -96,7 +96,7 @@ void Map::dispatchEvent(MapEditEvent *event) } } -MapSector * Map::getSectorNoGenerateNoExNoLock(v2s16 p) +MapSector * Map::getSectorNoGenerateNoLock(v2s16 p) { if(m_sector_cache != NULL && p == m_sector_cache_p){ MapSector * sector = m_sector_cache; @@ -117,24 +117,15 @@ MapSector * Map::getSectorNoGenerateNoExNoLock(v2s16 p) return sector; } -MapSector * Map::getSectorNoGenerateNoEx(v2s16 p) -{ - return getSectorNoGenerateNoExNoLock(p); -} - MapSector * Map::getSectorNoGenerate(v2s16 p) { - MapSector *sector = getSectorNoGenerateNoEx(p); - if(sector == NULL) - throw InvalidPositionException(); - - return sector; + return getSectorNoGenerateNoLock(p); } MapBlock * Map::getBlockNoCreateNoEx(v3s16 p3d) { v2s16 p2d(p3d.X, p3d.Z); - MapSector * sector = getSectorNoGenerateNoEx(p2d); + MapSector * sector = getSectorNoGenerate(p2d); if(sector == NULL) return NULL; MapBlock *block = sector->getBlockNoCreateNoEx(p3d.Y); @@ -1404,7 +1395,7 @@ MapSector *ServerMap::createSector(v2s16 p2d) /* Check if it exists already in memory */ - MapSector *sector = getSectorNoGenerateNoEx(p2d); + MapSector *sector = getSectorNoGenerate(p2d); if (sector) return sector; @@ -2114,7 +2105,7 @@ MapBlock* ServerMap::loadBlock(v3s16 blockpos) Make sure sector is loaded */ - MapSector *sector = getSectorNoGenerateNoEx(p2d); + MapSector *sector = getSectorNoGenerate(p2d); /* Make sure file exists @@ -2157,7 +2148,7 @@ bool ServerMap::deleteBlock(v3s16 blockpos) MapBlock *block = getBlockNoCreateNoEx(blockpos); if (block) { v2s16 p2d(blockpos.X, blockpos.Z); - MapSector *sector = getSectorNoGenerateNoEx(p2d); + MapSector *sector = getSectorNoGenerate(p2d); if (!sector) return false; sector->deleteBlock(block); @@ -155,10 +155,8 @@ public: void dispatchEvent(MapEditEvent *event); // On failure returns NULL - MapSector * getSectorNoGenerateNoExNoLock(v2s16 p2d); + MapSector * getSectorNoGenerateNoLock(v2s16 p2d); // Same as the above (there exists no lock anymore) - MapSector * getSectorNoGenerateNoEx(v2s16 p2d); - // On failure throws InvalidPositionException MapSector * getSectorNoGenerate(v2s16 p2d); // Gets an existing sector or creates an empty one //MapSector * getSectorCreate(v2s16 p2d); |