Skip to content

Commit

Permalink
Fix unnecessary exception use in Map::getSectorXXX (#8792)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
osjc authored and SmallJoker committed Aug 13, 2019
1 parent 539f016 commit 72b7a95
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
13 changes: 6 additions & 7 deletions src/client/clientmap.cpp
Expand Up @@ -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;
}
Expand Down
21 changes: 6 additions & 15 deletions src/map.cpp
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions src/map.h
Expand Up @@ -155,10 +155,8 @@ class Map /*: public NodeContainer*/
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);
Expand Down

0 comments on commit 72b7a95

Please sign in to comment.