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:
parent
539f016c1b
commit
72b7a957af
@ -63,14 +63,13 @@ ClientMap::ClientMap(
|
|||||||
MapSector * ClientMap::emergeSector(v2s16 p2d)
|
MapSector * ClientMap::emergeSector(v2s16 p2d)
|
||||||
{
|
{
|
||||||
// Check that it doesn't exist already
|
// Check that it doesn't exist already
|
||||||
try {
|
MapSector *sector = getSectorNoGenerate(p2d);
|
||||||
return getSectorNoGenerate(p2d);
|
|
||||||
} catch(InvalidPositionException &e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a sector
|
// Create it if it does not exist yet
|
||||||
MapSector *sector = new MapSector(this, p2d, m_gamedef);
|
if (!sector) {
|
||||||
m_sectors[p2d] = sector;
|
sector = new MapSector(this, p2d, m_gamedef);
|
||||||
|
m_sectors[p2d] = sector;
|
||||||
|
}
|
||||||
|
|
||||||
return sector;
|
return sector;
|
||||||
}
|
}
|
||||||
|
21
src/map.cpp
21
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){
|
if(m_sector_cache != NULL && p == m_sector_cache_p){
|
||||||
MapSector * sector = m_sector_cache;
|
MapSector * sector = m_sector_cache;
|
||||||
@ -117,24 +117,15 @@ MapSector * Map::getSectorNoGenerateNoExNoLock(v2s16 p)
|
|||||||
return sector;
|
return sector;
|
||||||
}
|
}
|
||||||
|
|
||||||
MapSector * Map::getSectorNoGenerateNoEx(v2s16 p)
|
|
||||||
{
|
|
||||||
return getSectorNoGenerateNoExNoLock(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
MapSector * Map::getSectorNoGenerate(v2s16 p)
|
MapSector * Map::getSectorNoGenerate(v2s16 p)
|
||||||
{
|
{
|
||||||
MapSector *sector = getSectorNoGenerateNoEx(p);
|
return getSectorNoGenerateNoLock(p);
|
||||||
if(sector == NULL)
|
|
||||||
throw InvalidPositionException();
|
|
||||||
|
|
||||||
return sector;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MapBlock * Map::getBlockNoCreateNoEx(v3s16 p3d)
|
MapBlock * Map::getBlockNoCreateNoEx(v3s16 p3d)
|
||||||
{
|
{
|
||||||
v2s16 p2d(p3d.X, p3d.Z);
|
v2s16 p2d(p3d.X, p3d.Z);
|
||||||
MapSector * sector = getSectorNoGenerateNoEx(p2d);
|
MapSector * sector = getSectorNoGenerate(p2d);
|
||||||
if(sector == NULL)
|
if(sector == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
MapBlock *block = sector->getBlockNoCreateNoEx(p3d.Y);
|
MapBlock *block = sector->getBlockNoCreateNoEx(p3d.Y);
|
||||||
@ -1404,7 +1395,7 @@ MapSector *ServerMap::createSector(v2s16 p2d)
|
|||||||
/*
|
/*
|
||||||
Check if it exists already in memory
|
Check if it exists already in memory
|
||||||
*/
|
*/
|
||||||
MapSector *sector = getSectorNoGenerateNoEx(p2d);
|
MapSector *sector = getSectorNoGenerate(p2d);
|
||||||
if (sector)
|
if (sector)
|
||||||
return sector;
|
return sector;
|
||||||
|
|
||||||
@ -2114,7 +2105,7 @@ MapBlock* ServerMap::loadBlock(v3s16 blockpos)
|
|||||||
Make sure sector is loaded
|
Make sure sector is loaded
|
||||||
*/
|
*/
|
||||||
|
|
||||||
MapSector *sector = getSectorNoGenerateNoEx(p2d);
|
MapSector *sector = getSectorNoGenerate(p2d);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Make sure file exists
|
Make sure file exists
|
||||||
@ -2157,7 +2148,7 @@ bool ServerMap::deleteBlock(v3s16 blockpos)
|
|||||||
MapBlock *block = getBlockNoCreateNoEx(blockpos);
|
MapBlock *block = getBlockNoCreateNoEx(blockpos);
|
||||||
if (block) {
|
if (block) {
|
||||||
v2s16 p2d(blockpos.X, blockpos.Z);
|
v2s16 p2d(blockpos.X, blockpos.Z);
|
||||||
MapSector *sector = getSectorNoGenerateNoEx(p2d);
|
MapSector *sector = getSectorNoGenerate(p2d);
|
||||||
if (!sector)
|
if (!sector)
|
||||||
return false;
|
return false;
|
||||||
sector->deleteBlock(block);
|
sector->deleteBlock(block);
|
||||||
|
@ -155,10 +155,8 @@ public:
|
|||||||
void dispatchEvent(MapEditEvent *event);
|
void dispatchEvent(MapEditEvent *event);
|
||||||
|
|
||||||
// On failure returns NULL
|
// On failure returns NULL
|
||||||
MapSector * getSectorNoGenerateNoExNoLock(v2s16 p2d);
|
MapSector * getSectorNoGenerateNoLock(v2s16 p2d);
|
||||||
// Same as the above (there exists no lock anymore)
|
// Same as the above (there exists no lock anymore)
|
||||||
MapSector * getSectorNoGenerateNoEx(v2s16 p2d);
|
|
||||||
// On failure throws InvalidPositionException
|
|
||||||
MapSector * getSectorNoGenerate(v2s16 p2d);
|
MapSector * getSectorNoGenerate(v2s16 p2d);
|
||||||
// Gets an existing sector or creates an empty one
|
// Gets an existing sector or creates an empty one
|
||||||
//MapSector * getSectorCreate(v2s16 p2d);
|
//MapSector * getSectorCreate(v2s16 p2d);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user