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.
This commit is contained in:
Jozef Behran 2019-08-13 19:58:27 +02:00 committed by SmallJoker
parent 539f016c1b
commit 72b7a957af
3 changed files with 13 additions and 25 deletions

@ -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;
}

@ -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);