Modernize various files (src/m*) (#6267)
authorLoïc Blot <nerzhul@users.noreply.github.com>
Fri, 18 Aug 2017 16:18:25 +0000 (18:18 +0200)
committerGitHub <noreply@github.com>
Fri, 18 Aug 2017 16:18:25 +0000 (18:18 +0200)
* Modernize various files (src/m*)

* range-based for loops
* code style
* C++ headers instead of C headers
* Default operators
* empty function

Thanks to clang-tidy

34 files changed:
src/main.cpp
src/mainmenumanager.h
src/map.cpp
src/map.h
src/mapblock.cpp
src/mapgen.h
src/mapgen_carpathian.h
src/mapgen_flat.cpp
src/mapgen_fractal.h
src/mapgen_singlenode.cpp
src/mapgen_singlenode.h
src/mapgen_v5.cpp
src/mapgen_v6.cpp
src/mapgen_v6.h
src/mapgen_v7.cpp
src/mapgen_v7.h
src/mapgen_valleys.cpp
src/mapgen_valleys.h
src/mapnode.cpp
src/mapnode.h
src/mapsector.cpp
src/mapsector.h
src/mesh.cpp
src/mesh_generator_thread.cpp
src/mg_biome.cpp
src/mg_biome.h
src/mg_decoration.h
src/mg_ore.cpp
src/mg_ore.h
src/mg_schematic.h
src/minimap.cpp
src/modalMenu.h
src/mods.cpp
src/mods.h

index ee391cf68d725341002d42f1efa627f12079b40e..303004f0c6baf7cd8cb330ca768fcc7c147452fa 100644 (file)
@@ -211,7 +211,7 @@ int main(int argc, char *argv[])
 #endif
 
        // Update configuration file
-       if (g_settings_path != "")
+       if (!g_settings_path.empty())
                g_settings->updateConfigFile(g_settings_path.c_str());
 
        print_modified_quicktune_values();
@@ -306,17 +306,16 @@ static void print_help(const OptionList &allowed_options)
 
 static void print_allowed_options(const OptionList &allowed_options)
 {
-       for (OptionList::const_iterator i = allowed_options.begin();
-                       i != allowed_options.end(); ++i) {
+       for (const auto &allowed_option : allowed_options) {
                std::ostringstream os1(std::ios::binary);
-               os1 << "  --" << i->first;
-               if (i->second.type != VALUETYPE_FLAG)
+               os1 << "  --" << allowed_option.first;
+               if (allowed_option.second.type != VALUETYPE_FLAG)
                        os1 << _(" <value>");
 
                std::cout << padStringRight(os1.str(), 30);
 
-               if (i->second.help)
-                       std::cout << i->second.help;
+               if (allowed_option.second.help)
+                       std::cout << allowed_option.second.help;
 
                std::cout << std::endl;
        }
@@ -335,9 +334,8 @@ static void print_version()
 static void list_game_ids()
 {
        std::set<std::string> gameids = getAvailableGameIds();
-       for (std::set<std::string>::const_iterator i = gameids.begin();
-                       i != gameids.end(); ++i)
-               std::cout << (*i) <<std::endl;
+       for (const std::string &gameid : gameids)
+               std::cout << gameid <<std::endl;
 }
 
 static void list_worlds()
@@ -350,10 +348,10 @@ static void list_worlds()
 static void print_worldspecs(const std::vector<WorldSpec> &worldspecs,
                                                         std::ostream &os)
 {
-       for (size_t i = 0; i < worldspecs.size(); i++) {
-               std::string name = worldspecs[i].name;
-               std::string path = worldspecs[i].path;
-               if (name.find(" ") != std::string::npos)
+       for (const WorldSpec &worldspec : worldspecs) {
+               std::string name = worldspec.name;
+               std::string path = worldspec.path;
+               if (name.find(' ') != std::string::npos)
                        name = std::string("'") + name + "'";
                path = std::string("'") + path + "'";
                name = padStringRight(name, 14);
@@ -366,15 +364,15 @@ static void print_modified_quicktune_values()
        bool header_printed = false;
        std::vector<std::string> names = getQuicktuneNames();
 
-       for (u32 i = 0; i < names.size(); i++) {
-               QuicktuneValue val = getQuicktuneValue(names[i]);
+       for (const std::string &name : names) {
+               QuicktuneValue val = getQuicktuneValue(name);
                if (!val.modified)
                        continue;
                if (!header_printed) {
                        dstream << "Modified quicktune values:" << std::endl;
                        header_printed = true;
                }
-               dstream << names[i] << " = " << val.getString() << std::endl;
+               dstream << name << " = " << val.getString() << std::endl;
        }
 }
 
@@ -485,16 +483,16 @@ static bool read_config_file(const Settings &cmd_args)
                                DIR_DELIM + ".." + DIR_DELIM + ".." + DIR_DELIM + "minetest.conf");
 #endif
 
-               for (size_t i = 0; i < filenames.size(); i++) {
-                       bool r = g_settings->readConfigFile(filenames[i].c_str());
+               for (const std::string &filename : filenames) {
+                       bool r = g_settings->readConfigFile(filename.c_str());
                        if (r) {
-                               g_settings_path = filenames[i];
+                               g_settings_path = filename;
                                break;
                        }
                }
 
                // If no path found, use the first one (menu creates the file)
-               if (g_settings_path == "")
+               if (g_settings_path.empty())
                        g_settings_path = filenames[0];
        }
 
@@ -540,7 +538,7 @@ static void init_log_streams(const Settings &cmd_args)
 
        verbosestream << "log_filename = " << log_filename << std::endl;
 
-       file_log_output.open(log_filename.c_str());
+       file_log_output.open(log_filename);
        g_logger.addOutputMaxLevel(&file_log_output, log_level);
 }
 
@@ -573,6 +571,7 @@ static bool game_configure_world(GameParams *game_params, const Settings &cmd_ar
 {
        if (get_world_from_cmdline(game_params, cmd_args))
                return true;
+
        if (get_world_from_config(game_params, cmd_args))
                return true;
 
@@ -581,24 +580,24 @@ static bool game_configure_world(GameParams *game_params, const Settings &cmd_ar
 
 static bool get_world_from_cmdline(GameParams *game_params, const Settings &cmd_args)
 {
-       std::string commanded_world = "";
+       std::string commanded_world;
 
        // World name
-       std::string commanded_worldname = "";
+       std::string commanded_worldname;
        if (cmd_args.exists("worldname"))
                commanded_worldname = cmd_args.get("worldname");
 
        // If a world name was specified, convert it to a path
-       if (commanded_worldname != "") {
+       if (!commanded_worldname.empty()) {
                // Get information about available worlds
                std::vector<WorldSpec> worldspecs = getAvailableWorlds();
                bool found = false;
-               for (u32 i = 0; i < worldspecs.size(); i++) {
-                       std::string name = worldspecs[i].name;
+               for (const WorldSpec &worldspec : worldspecs) {
+                       std::string name = worldspec.name;
                        if (name == commanded_worldname) {
                                dstream << _("Using world specified by --worldname on the "
                                        "command line") << std::endl;
-                               commanded_world = worldspecs[i].path;
+                               commanded_world = worldspec.path;
                                found = true;
                                break;
                        }
@@ -611,7 +610,7 @@ static bool get_world_from_cmdline(GameParams *game_params, const Settings &cmd_
                }
 
                game_params->world_path = get_clean_world_path(commanded_world);
-               return commanded_world != "";
+               return !commanded_world.empty();
        }
 
        if (cmd_args.exists("world"))
@@ -622,20 +621,20 @@ static bool get_world_from_cmdline(GameParams *game_params, const Settings &cmd_
                commanded_world = cmd_args.get("nonopt0");
 
        game_params->world_path = get_clean_world_path(commanded_world);
-       return commanded_world != "";
+       return !commanded_world.empty();
 }
 
 static bool get_world_from_config(GameParams *game_params, const Settings &cmd_args)
 {
        // World directory
-       std::string commanded_world = "";
+       std::string commanded_world;
 
        if (g_settings->exists("map-dir"))
                commanded_world = g_settings->get("map-dir");
 
        game_params->world_path = get_clean_world_path(commanded_world);
 
-       return commanded_world != "";
+       return !commanded_world.empty();
 }
 
 static bool auto_select_world(GameParams *game_params)
@@ -729,8 +728,8 @@ static bool determine_subgame(GameParams *game_params)
 
        verbosestream << _("Determining gameid/gamespec") << std::endl;
        // If world doesn't exist
-       if (game_params->world_path != ""
-                       && !getWorldExists(game_params->world_path)) {
+       if (!game_params->world_path.empty()
+               && !getWorldExists(game_params->world_path)) {
                // Try to take gamespec from command line
                if (game_params->game_spec.isValid()) {
                        gamespec = game_params->game_spec;
@@ -810,7 +809,8 @@ static bool run_dedicated_server(const GameParams &game_params, const Settings &
        // Database migration
        if (cmd_args.exists("migrate"))
                return migrate_map_database(game_params, cmd_args);
-       else if (cmd_args.exists("migrate-players"))
+
+       if (cmd_args.exists("migrate-players"))
                return ServerEnvironment::migratePlayersDatabase(game_params, cmd_args);
 
        if (cmd_args.exists("terminal")) {
index 2618d3ccfb948d8389a498cfa66ba0e233fb417a..49bc88dff27edbdc3bcbd3415fb5e7f3d8531c12 100644 (file)
@@ -48,11 +48,8 @@ class MainMenuManager : public IMenuManager
 public:
        virtual void createdMenu(gui::IGUIElement *menu)
        {
-               for(std::list<gui::IGUIElement*>::iterator
-                               i = m_stack.begin();
-                               i != m_stack.end(); ++i)
-               {
-                       assert(*i != menu);
+               for (gui::IGUIElement *i : m_stack) {
+                       assert(i != menu);
                }
 
                if(!m_stack.empty())
@@ -103,10 +100,8 @@ public:
 
        bool pausesGame()
        {
-               for(std::list<gui::IGUIElement*>::iterator
-                               i = m_stack.begin(); i != m_stack.end(); ++i)
-               {
-                       GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(*i);
+               for (gui::IGUIElement *i : m_stack) {
+                       GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(i);
                        if (mm && mm->pausesGame())
                                return true;
                }
@@ -123,8 +118,8 @@ extern bool isMenuActive();
 class MainGameCallback : public IGameCallback
 {
 public:
-       MainGameCallback() {}
-       virtual ~MainGameCallback() {}
+       MainGameCallback() = default;
+       virtual ~MainGameCallback() = default;
 
        virtual void exitToOS()
        {
index 972c666e4d6c4ce201824b033dc06140b3bdfffd..6cf838696926a103b0b75482e50f20cfb1d629fe 100644 (file)
@@ -527,14 +527,13 @@ void Map::unloadUnreferencedBlocks(std::vector<v3s16> *unloaded_blocks)
 
 void Map::deleteSectors(std::vector<v2s16> &sectorList)
 {
-       for(std::vector<v2s16>::iterator j = sectorList.begin();
-               j != sectorList.end(); ++j) {
-               MapSector *sector = m_sectors[*j];
+       for (v2s16 j : sectorList) {
+               MapSector *sector = m_sectors[j];
                // If sector is in sector cache, remove it from there
                if(m_sector_cache == sector)
                        m_sector_cache = NULL;
                // Remove from map and delete
-               m_sectors.erase(*j);
+               m_sectors.erase(j);
                delete sector;
        }
 }
@@ -1724,7 +1723,7 @@ MapBlock * ServerMap::emergeBlock(v3s16 p, bool create_blank)
 
        {
                MapBlock *block = getBlockNoCreateNoEx(p);
-               if(block && block->isDummy() == false)
+               if (block && !block->isDummy())
                        return block;
        }
 
@@ -1855,8 +1854,7 @@ bool ServerMap::loadFromFolders() {
 
 void ServerMap::createDirs(std::string path)
 {
-       if(fs::CreateAllDirs(path) == false)
-       {
+       if (!fs::CreateAllDirs(path)) {
                m_dout<<"ServerMap: Failed to create directory "
                                <<"\""<<path<<"\""<<std::endl;
                throw BaseException("ServerMap failed to create directory");
@@ -1940,7 +1938,7 @@ std::string ServerMap::getBlockFilename(v3s16 p)
 void ServerMap::save(ModifiedState save_level)
 {
        DSTACK(FUNCTION_NAME);
-       if(m_map_saving_enabled == false) {
+       if (!m_map_saving_enabled) {
                warningstream<<"Not saving map, saving disabled."<<std::endl;
                return;
        }
@@ -2081,8 +2079,7 @@ MapSector* ServerMap::loadSectorMeta(std::string sectordir, bool save_after_load
 
        std::string fullpath = sectordir + DIR_DELIM + "meta";
        std::ifstream is(fullpath.c_str(), std::ios_base::binary);
-       if(is.good() == false)
-       {
+       if (!is.good()) {
                // If the directory exists anyway, it probably is in some old
                // format. Just go ahead and create the sector.
                if(fs::PathExists(sectordir))
@@ -2494,7 +2491,7 @@ MapBlock* ServerMap::loadBlock(v3s16 blockpos)
                 */
 
                std::string blockfilename = getBlockFilename(blockpos);
-               if (fs::PathExists(sectordir + DIR_DELIM + blockfilename) == false)
+               if (!fs::PathExists(sectordir + DIR_DELIM + blockfilename))
                        return NULL;
 
                /*
@@ -2667,8 +2664,8 @@ void MMVManip::blitBackAll(std::map<v3s16, MapBlock*> *modified_blocks,
                v3s16 p = i->first;
                MapBlock *block = m_map->getBlockNoCreateNoEx(p);
                bool existed = !(i->second & VMANIP_BLOCK_DATA_INEXIST);
-               if ((existed == false) || (block == NULL) ||
-                       (overwrite_generated == false && block->isGenerated() == true))
+               if (!existed || (block == NULL) ||
+                       (!overwrite_generated && block->isGenerated()))
                        continue;
 
                block->copyFrom(*this);
index 4dd2b7e300ad55334f6ec4e68006383e99468a58..81f32baeaf9a6376b007a53aa8f051c293b282f5 100644 (file)
--- a/src/map.h
+++ b/src/map.h
@@ -77,7 +77,7 @@ struct MapEditEvent
        std::set<v3s16> modified_blocks;
        u16 already_known_by_peer = 0;
 
-       MapEditEvent() {}
+       MapEditEvent() = default;
 
        MapEditEvent * clone()
        {
@@ -107,11 +107,7 @@ struct MapEditEvent
                case MEET_OTHER:
                {
                        VoxelArea a;
-                       for(std::set<v3s16>::iterator
-                                       i = modified_blocks.begin();
-                                       i != modified_blocks.end(); ++i)
-                       {
-                               v3s16 p = *i;
+                       for (v3s16 p : modified_blocks) {
                                v3s16 np1 = p*MAP_BLOCKSIZE;
                                v3s16 np2 = np1 + v3s16(1,1,1)*MAP_BLOCKSIZE - v3s16(1,1,1);
                                a.addPoint(np1);
@@ -216,8 +212,8 @@ public:
        bool removeNodeWithEvent(v3s16 p);
 
        // Call these before and after saving of many blocks
-       virtual void beginSave() { return; }
-       virtual void endSave() { return; }
+       virtual void beginSave() {}
+       virtual void endSave() {}
 
        virtual void save(ModifiedState save_level) { FATAL_ERROR("FIXME"); }
 
index ca589479419438ab7df7ac56ad4822d0058730cc..48b7c19152b74f77da9b0d617ae117b03f2ac774 100644 (file)
@@ -71,7 +71,7 @@ MapBlock::MapBlock(Map *parent, v3s16 pos, IGameDef *gamedef, bool dummy):
                m_pos_relative(pos * MAP_BLOCKSIZE),
                m_gamedef(gamedef)
 {
-       if(dummy == false)
+       if (!dummy)
                reallocate();
 }
 
@@ -89,24 +89,22 @@ MapBlock::~MapBlock()
 
 bool MapBlock::isValidPositionParent(v3s16 p)
 {
-       if(isValidPosition(p))
-       {
+       if (isValidPosition(p)) {
                return true;
        }
-       else{
-               return m_parent->isValidPosition(getPosRelative() + p);
-       }
+
+       return m_parent->isValidPosition(getPosRelative() + p);
 }
 
 MapNode MapBlock::getNodeParent(v3s16 p, bool *is_valid_position)
 {
-       if (isValidPosition(p) == false)
+       if (!isValidPosition(p))
                return m_parent->getNodeNoEx(getPosRelative() + p, is_valid_position);
 
        if (!data) {
                if (is_valid_position)
                        *is_valid_position = false;
-               return MapNode(CONTENT_IGNORE);
+               return {CONTENT_IGNORE};
        }
        if (is_valid_position)
                *is_valid_position = true;
@@ -201,8 +199,7 @@ bool MapBlock::propagateSunlight(std::set<v3s16> & light_sources,
                                else
                                {
                                        MapNode n = getNodeNoEx(v3s16(x, MAP_BLOCKSIZE-1, z));
-                                       if(m_gamedef->ndef()->get(n).sunlight_propagates == false)
-                                       {
+                                       if (!m_gamedef->ndef()->get(n).sunlight_propagates) {
                                                no_sunlight = true;
                                        }
                                }
@@ -423,12 +420,11 @@ s16 MapBlock::getGroundLevel(v2s16 p2d)
                for(; y>=0; y--)
                {
                        MapNode n = getNodeRef(p2d.X, y, p2d.Y);
-                       if(m_gamedef->ndef()->get(n).walkable)
-                       {
+                       if (m_gamedef->ndef()->get(n).walkable) {
                                if(y == MAP_BLOCKSIZE-1)
                                        return -2;
-                               else
-                                       return y;
+
+                               return y;
                        }
                }
                return -1;
@@ -481,11 +477,9 @@ static void getBlockNodeIdMapping(NameIdMapping *nimap, MapNode *nodes,
                // Update the MapNode
                nodes[i].setContent(id);
        }
-       for(std::set<content_t>::const_iterator
-                       i = unknown_contents.begin();
-                       i != unknown_contents.end(); ++i){
-               errorstream<<"getBlockNodeIdMapping(): IGNORING ERROR: "
-                               <<"Name for node id "<<(*i)<<" not known"<<std::endl;
+       for (u16 unknown_content : unknown_contents) {
+               errorstream << "getBlockNodeIdMapping(): IGNORING ERROR: "
+                               << "Name for node id " << unknown_content << " not known" << std::endl;
        }
 }
 // Correct ids in the block to match nodedef based on names.
index 8a9b8057ec076043b9f957be4d3be8820bed8c84..6701cfdd0167d5c421b44c7f953fb10490cc50f0 100644 (file)
@@ -122,7 +122,7 @@ enum MapgenType {
 };
 
 struct MapgenParams {
-       MapgenParams() {}
+       MapgenParams() = default;
        virtual ~MapgenParams();
 
        MapgenType mgtype = MAPGEN_DEFAULT;
index 1e9bbcd31ee64966e0cfbfc6c7e837248f6d2ab3..b7c3935f7118b467d5d2d0e2856cef96881df9bd 100644 (file)
@@ -59,7 +59,7 @@ struct MapgenCarpathianParams : public MapgenParams
        NoiseParams np_cavern;
 
        MapgenCarpathianParams();
-       ~MapgenCarpathianParams() {}
+       ~MapgenCarpathianParams() = default;
 
        void readParams(const Settings *settings);
        void writeParams(Settings *settings) const;
index 34074c8b7e6ff9a533462a877de94bbeede78a1e..0343492d8c5b0107a410ee61c0292669e5fbb0bf 100644 (file)
@@ -148,10 +148,11 @@ int MapgenFlat::getSpawnLevelAtPoint(v2s16 p)
 
        if (ground_level < water_level)  // Ocean world, allow spawn in water
                return MYMAX(level_at_point, water_level);
-       else if (level_at_point > water_level)
+
+       if (level_at_point > water_level)
                return level_at_point;  // Spawn on land
-       else
-               return MAX_MAP_GENERATION_LIMIT;  // Unsuitable spawn point
+
+       return MAX_MAP_GENERATION_LIMIT;  // Unsuitable spawn point
 }
 
 
index a83c5b3176c24a1d162c6c6ccab9614521c321d3..be49415816d32531810d79bf58f73b87dcee4856 100644 (file)
@@ -50,7 +50,7 @@ struct MapgenFractalParams : public MapgenParams
        NoiseParams np_cave2;
 
        MapgenFractalParams();
-       ~MapgenFractalParams() {}
+       ~MapgenFractalParams() = default;
 
        void readParams(const Settings *settings);
        void writeParams(Settings *settings) const;
index f49059f7fc78342ee7d1cc381b2f43ad9e8b80c9..ee8746b832466a8dd67fe80f581f3e15dd1e6766 100644 (file)
@@ -46,11 +46,6 @@ MapgenSinglenode::MapgenSinglenode(int mapgenid,
 }
 
 
-MapgenSinglenode::~MapgenSinglenode()
-{
-}
-
-
 //////////////////////// Map generator
 
 void MapgenSinglenode::makeChunk(BlockMakeData *data)
index 38bc3e020ab2244c7470b7d1c84c36ad5976d867..7678613e5866de512e2a32d8bb10e74c82a9c046 100644 (file)
@@ -25,8 +25,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 struct MapgenSinglenodeParams : public MapgenParams
 {
-       MapgenSinglenodeParams() {}
-       ~MapgenSinglenodeParams() {}
+       MapgenSinglenodeParams() = default;
+       ~MapgenSinglenodeParams() = default;
 
        void readParams(const Settings *settings) {}
        void writeParams(Settings *settings) const {}
@@ -40,7 +40,7 @@ public:
        u8 set_light;
 
        MapgenSinglenode(int mapgenid, MapgenParams *params, EmergeManager *emerge);
-       ~MapgenSinglenode();
+       ~MapgenSinglenode() = default;
 
        virtual MapgenType getType() const { return MAPGEN_SINGLENODE; }
 
index 2cfb065f999638f28c5c8aedf6c75362090f9020..d7e9d6664cc3a5e7a716ac9ba18485b4f30e6bdb 100644 (file)
@@ -156,9 +156,9 @@ int MapgenV5::getSpawnLevelAtPoint(v2s16 p)
                if (n_ground * f > y - h) {  // If solid
                        if (y < water_level || y > max_spawn_y)
                                return MAX_MAP_GENERATION_LIMIT;  // Unsuitable spawn point
-                       else
-                               // y + 2 because y is surface and due to biome 'dust' nodes.
-                               return y + 2;
+
+                       // y + 2 because y is surface and due to biome 'dust' nodes.
+                       return y + 2;
                }
        }
        // Unsuitable spawn position, no ground found
index cbc4a19c3fb17d19497ec6ee4973f2330c65dbd6..ec33fee08413972332a24d88b09ab73e161c2b04 100644 (file)
@@ -233,8 +233,8 @@ bool MapgenV6::block_is_underground(u64 seed, v3s16 blockpos)
 
        if(blockpos.Y * MAP_BLOCKSIZE + MAP_BLOCKSIZE <= minimum_groundlevel)
                return true;
-       else
-               return false;
+
+       return false;
 }
 
 
@@ -327,8 +327,8 @@ int MapgenV6::getSpawnLevelAtPoint(v2s16 p)
        if (level_at_point <= water_level ||
                        level_at_point > water_level + 16)
                return MAX_MAP_GENERATION_LIMIT;  // Unsuitable spawn point
-       else
-               return level_at_point;
+
+       return level_at_point;
 }
 
 
@@ -385,8 +385,8 @@ float MapgenV6::getTreeAmount(v2s16 p)
        float zeroval = -0.39;
        if (noise < zeroval)
                return 0;
-       else
-               return 0.04 * (noise - zeroval) / (1.0 - zeroval);
+
+       return 0.04 * (noise - zeroval) / (1.0 - zeroval);
 }
 
 
@@ -443,16 +443,18 @@ BiomeV6Type MapgenV6::getBiome(int index, v2s16 p)
                if (d > MGV6_FREQ_HOT + blend) {
                        if (h > MGV6_FREQ_JUNGLE + blend)
                                return BT_JUNGLE;
-                       else
-                               return BT_DESERT;
-               } else if (d < MGV6_FREQ_SNOW + blend) {
+
+                       return BT_DESERT;
+               }
+
+               if (d < MGV6_FREQ_SNOW + blend) {
                        if (h > MGV6_FREQ_TAIGA + blend)
                                return BT_TAIGA;
-                       else
-                               return BT_TUNDRA;
-               } else {
-                       return BT_NORMAL;
+
+                       return BT_TUNDRA;
                }
+
+               return BT_NORMAL;
        } else {
                if (d > freq_desert)
                        return BT_DESERT;
@@ -463,8 +465,8 @@ BiomeV6Type MapgenV6::getBiome(int index, v2s16 p)
 
                if ((spflags & MGV6_JUNGLES) && h > 0.75)
                        return BT_JUNGLE;
-               else
-                       return BT_NORMAL;
+
+               return BT_NORMAL;
        }
 }
 
@@ -818,7 +820,7 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos)
                                                u32 i2 = i;
                                                vm->m_area.add_y(em, i2, -1);
                                                // Cancel if out of area
-                                               if (vm->m_area.contains(i2) == false)
+                                               if (!vm->m_area.contains(i2))
                                                        continue;
                                                MapNode *n2 = &vm->m_data[i2];
                                                if (n2->getContent() != c_dirt &&
@@ -847,13 +849,12 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos)
                                }
 
                                // Drop mud on side
-                               for (u32 di = 0; di < 4; di++) {
-                                       v3s16 dirp = dirs4[di];
+                               for (const v3s16 &dirp : dirs4) {
                                        u32 i2 = i;
                                        // Move to side
                                        vm->m_area.add_p(em, i2, dirp);
                                        // Fail if out of area
-                                       if (vm->m_area.contains(i2) == false)
+                                       if (!vm->m_area.contains(i2))
                                                continue;
                                        // Check that side is air
                                        MapNode *n2 = &vm->m_data[i2];
@@ -861,7 +862,7 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos)
                                                continue;
                                        // Check that under side is air
                                        vm->m_area.add_y(em, i2, -1);
-                                       if (vm->m_area.contains(i2) == false)
+                                       if (!vm->m_area.contains(i2))
                                                continue;
                                        n2 = &vm->m_data[i2];
                                        if (ndef->get(*n2).walkable)
@@ -872,12 +873,12 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos)
                                                vm->m_area.add_y(em, i2, -1);
                                                n2 = &vm->m_data[i2];
                                                // if out of known area
-                                               if (vm->m_area.contains(i2) == false ||
+                                               if (!vm->m_area.contains(i2) ||
                                                                n2->getContent() == CONTENT_IGNORE) {
                                                        dropped_to_unknown = true;
                                                        break;
                                                }
-                                       } while (ndef->get(*n2).walkable == false);
+                                       } while (!ndef->get(*n2).walkable);
                                        // Loop one up so that we're in air
                                        vm->m_area.add_y(em, i2, 1);
 
index f92e906952a584891bcc94e4d784ce4be09b3c3c..8726796830ebf604c6f1451210942988dc75b4d9 100644 (file)
@@ -72,7 +72,7 @@ struct MapgenV6Params : public MapgenParams {
        NoiseParams np_apple_trees;
 
        MapgenV6Params();
-       ~MapgenV6Params() {}
+       ~MapgenV6Params() = default;
 
        void readParams(const Settings *settings);
        void writeParams(Settings *settings) const;
index 3ce22dbb18214a924e2851842ed7c1c5b801e8b0..d27e339ce1415afed632fafeede04405b9095e3e 100644 (file)
@@ -240,9 +240,9 @@ int MapgenV7::getSpawnLevelAtPoint(v2s16 p)
        if (!(spflags & MGV7_MOUNTAINS)) {
                if (y < water_level || y > max_spawn_y)
                        return MAX_MAP_GENERATION_LIMIT;  // Unsuitable spawn point
-               else
-                       // y + 2 because y is surface level and due to biome 'dust'
-                       return y + 2;
+
+               // y + 2 because y is surface level and due to biome 'dust'
+               return y + 2;
        }
 
        // Search upwards for first node without mountain terrain
@@ -251,9 +251,9 @@ int MapgenV7::getSpawnLevelAtPoint(v2s16 p)
                if (!getMountainTerrainAtPoint(p.X, y + 1, p.Y)) {
                        if (y <= water_level || y > max_spawn_y)
                                return MAX_MAP_GENERATION_LIMIT;  // Unsuitable spawn point
-                       else
-                               // y + 1 due to biome 'dust'
-                               return y + 1;
+
+                       // y + 1 due to biome 'dust'
+                       return y + 1;
                }
                y++;
                iters--;
index f4d397135a41ffd464bd9e7c0dd984dd6192d24b..877f3d089adc6126de638985e92cef6a6004ffff 100644 (file)
@@ -65,7 +65,7 @@ struct MapgenV7Params : public MapgenParams {
        NoiseParams np_cave2;
 
        MapgenV7Params();
-       ~MapgenV7Params() {}
+       ~MapgenV7Params() = default;
 
        void readParams(const Settings *settings);
        void writeParams(Settings *settings) const;
index f0c145934aab7c73b1e7909e4005202ab4372c9c..d8b3193a6da54624721c6df0020b30eaa2a93904 100644 (file)
@@ -435,8 +435,8 @@ int MapgenValleys::getSpawnLevelAtPoint(v2s16 p)
        if (level_at_point <= water_level ||
                        level_at_point > water_level + 32)
                return MAX_MAP_GENERATION_LIMIT;  // Unsuitable spawn point
-       else
-               return level_at_point;
+
+       return level_at_point;
 }
 
 
@@ -670,7 +670,8 @@ void MapgenValleys::generateCaves(s16 max_stone_y, s16 large_cave_depth)
                        // Saves some time.
                        if (y > terrain + 10)
                                continue;
-                       else if (y < terrain - 40)
+
+                       if (y < terrain - 40)
                                underground = true;
 
                        // Dig massive caves.
index 1cb94860c499c56f700cef92187c1c27ca7f1364..7b5eb187df68d7bae7e8600d2afb5526f68e607a 100644 (file)
@@ -66,7 +66,7 @@ struct MapgenValleysParams : public MapgenParams {
        NoiseParams np_valley_profile;
 
        MapgenValleysParams();
-       ~MapgenValleysParams() {}
+       ~MapgenValleysParams() = default;
 
        void readParams(const Settings *settings);
        void writeParams(Settings *settings) const;
index fd28910ff6848f00a148bdf8829a8ff5f8daefe7..b06b42ba8f963ea3f3449d0cb213fe3a4a59a8ed 100644 (file)
@@ -249,18 +249,12 @@ void transformNodeBox(const MapNode &n, const NodeBox &nodebox,
                int facedir = n.getFaceDir(nodemgr);
                u8 axisdir = facedir>>2;
                facedir&=0x03;
-               for(std::vector<aabb3f>::const_iterator
-                               i = fixed.begin();
-                               i != fixed.end(); ++i)
-               {
-                       aabb3f box = *i;
-
+               for (aabb3f box : fixed) {
                        if (nodebox.type == NODEBOX_LEVELED) {
                                box.MaxEdge.Y = -BS/2 + BS*((float)1/LEVELED_MAX) * n.getLevel(nodemgr);
                        }
 
-                       switch (axisdir)
-                       {
+                       switch (axisdir) {
                        case 0:
                                if(facedir == 1)
                                {
@@ -403,16 +397,15 @@ void transformNodeBox(const MapNode &n, const NodeBox &nodebox,
                                nodebox.wall_side.MaxEdge
                        };
 
-                       for(s32 i=0; i<2; i++)
-                       {
+                       for (v3f &vertice : vertices) {
                                if(dir == v3s16(-1,0,0))
-                                       vertices[i].rotateXZBy(0);
+                                       vertice.rotateXZBy(0);
                                if(dir == v3s16(1,0,0))
-                                       vertices[i].rotateXZBy(180);
+                                       vertice.rotateXZBy(180);
                                if(dir == v3s16(0,0,-1))
-                                       vertices[i].rotateXZBy(90);
+                                       vertice.rotateXZBy(90);
                                if(dir == v3s16(0,0,1))
-                                       vertices[i].rotateXZBy(-90);
+                                       vertice.rotateXZBy(-90);
                        }
 
                        aabb3f box = aabb3f(vertices[0]);
@@ -467,7 +460,7 @@ void transformNodeBox(const MapNode &n, const NodeBox &nodebox,
 }
 
 static inline void getNeighborConnectingFace(
-       v3s16 p, INodeDefManager *nodedef,
+       const v3s16 &p, INodeDefManager *nodedef,
        Map *map, MapNode n, u8 bitmask, u8 *neighbors)
 {
        MapNode n2 = map->getNodeNoEx(p);
@@ -605,14 +598,16 @@ u32 MapNode::serializedLength(u8 version)
        if(!ser_ver_supported(version))
                throw VersionMismatchException("ERROR: MapNode format not supported");
 
-       if(version == 0)
+       if (version == 0)
                return 1;
-       else if(version <= 9)
+
+       if (version <= 9)
                return 2;
-       else if(version <= 23)
+
+       if (version <= 23)
                return 3;
-       else
-               return 4;
+
+       return 4;
 }
 void MapNode::serialize(u8 *dest, u8 version)
 {
index 200a512073b735d25295f5c44cb4fb4e319c1b92..4b75fe227eb82771d83e15525fbd0c27ebc90b12 100644 (file)
@@ -137,8 +137,7 @@ struct MapNode
        */
        u8 param2;
 
-       MapNode()
-       { }
+       MapNode() = default;
 
        MapNode(content_t content, u8 a_param1=0, u8 a_param2=0)
                : param0(content),
index 446b4374766712494a0df106e56245f41caba0aa..c6832a012469f7966ffa778c46583034cd8d16de 100644 (file)
@@ -40,9 +40,8 @@ void MapSector::deleteBlocks()
        m_block_cache = nullptr;
 
        // Delete all
-       for (std::unordered_map<s16, MapBlock*>::iterator i = m_blocks.begin();
-                       i != m_blocks.end(); ++i) {
-               delete i->second;
+       for (auto &block : m_blocks) {
+               delete block.second;
        }
 
        // Clear container
@@ -125,9 +124,8 @@ void MapSector::deleteBlock(MapBlock *block)
 
 void MapSector::getBlocks(MapBlockVect &dest)
 {
-       for (std::unordered_map<s16, MapBlock*>::iterator bi = m_blocks.begin();
-               bi != m_blocks.end(); ++bi) {
-               dest.push_back(bi->second);
+       for (auto &block : m_blocks) {
+               dest.push_back(block.second);
        }
 }
 
@@ -140,10 +138,6 @@ ServerMapSector::ServerMapSector(Map *parent, v2s16 pos, IGameDef *gamedef):
 {
 }
 
-ServerMapSector::~ServerMapSector()
-{
-}
-
 void ServerMapSector::serialize(std::ostream &os, u8 version)
 {
        if(!ser_ver_supported(version))
@@ -212,11 +206,9 @@ ServerMapSector* ServerMapSector::deSerialize(
                assert(sector->getId() == MAPSECTOR_SERVER);
                return (ServerMapSector*)sector;
        }
-       else
-       {
-               sector = new ServerMapSector(parent, p2d, gamedef);
-               sectors[p2d] = sector;
-       }
+
+       sector = new ServerMapSector(parent, p2d, gamedef);
+       sectors[p2d] = sector;
 
        /*
                Set stuff in sector
@@ -236,11 +228,6 @@ ClientMapSector::ClientMapSector(Map *parent, v2s16 pos, IGameDef *gamedef):
                MapSector(parent, pos, gamedef)
 {
 }
-
-ClientMapSector::~ClientMapSector()
-{
-}
-
 #endif // !SERVER
 
 //END
index ff1ca7be687ae9515214ab558ed6cfa532ff217a..b0ed9c88c5b713d65fc64cdafc8ba936756b9efc 100644 (file)
@@ -94,7 +94,7 @@ class ServerMapSector : public MapSector
 {
 public:
        ServerMapSector(Map *parent, v2s16 pos, IGameDef *gamedef);
-       ~ServerMapSector();
+       ~ServerMapSector() = default;
 
        u32 getId() const
        {
@@ -124,7 +124,7 @@ class ClientMapSector : public MapSector
 {
 public:
        ClientMapSector(Map *parent, v2s16 pos, IGameDef *gamedef);
-       ~ClientMapSector();
+       ~ClientMapSector() = default;
 
        u32 getId() const
        {
index 3ab67510a258893808fbd9c96a70a75896927506..218e2d0b2d1acffad9c2f1f0157c0bcd5b24a2dc 100644 (file)
@@ -453,11 +453,7 @@ scene::IMesh* convertNodeboxesToMesh(const std::vector<aabb3f> &boxes,
 
        video::SColor c(255,255,255,255);
 
-       for (std::vector<aabb3f>::const_iterator
-                       i = boxes.begin();
-                       i != boxes.end(); ++i)
-       {
-               aabb3f box = *i;
+       for (aabb3f box : boxes) {
                box.repair();
 
                box.MinEdge.X -= expand;
@@ -614,9 +610,8 @@ class f_lru
 public:
        f_lru(vcache *v, tcache *t): vc(v), tc(t)
        {
-               for (u16 i = 0; i < cachesize; i++)
-               {
-                       cache[i] = -1;
+               for (int &i : cache) {
+                       i = -1;
                }
        }
 
@@ -671,15 +666,14 @@ public:
                        }
 
                        // Update triangle scores
-                       for (u16 i = 0; i < cachesize; i++)
-                       {
-                               if (cache[i] == -1)
+                       for (int i : cache) {
+                               if (i == -1)
                                        break;
 
-                               const u16 trisize = vc[cache[i]].tris.size();
+                               const u16 trisize = vc[i].tris.size();
                                for (u16 t = 0; t < trisize; t++)
                                {
-                                       tcache *tri = &tc[vc[cache[i]].tris[t]];
+                                       tcache *tri = &tc[vc[i].tris[t]];
 
                                        tri->score =
                                                vc[tri->ind[0]].score +
@@ -689,7 +683,7 @@ public:
                                        if (tri->score > hiscore)
                                        {
                                                hiscore = tri->score;
-                                               highest = vc[cache[i]].tris[t];
+                                               highest = vc[i].tris[t];
                                        }
                                }
                        }
@@ -876,9 +870,8 @@ scene::IMesh* createForsythOptimizedMesh(const scene::IMesh *mesh)
 
                                        tc[highest].drawn = true;
 
-                                       for (u16 j = 0; j < 3; j++)
-                                       {
-                                               vcache *vert = &vc[tc[highest].ind[j]];
+                                       for (u16 j : tc[highest].ind) {
+                                               vcache *vert = &vc[j];
                                                for (u16 t = 0; t < vert->tris.size(); t++)
                                                {
                                                        if (highest == vert->tris[t])
@@ -988,9 +981,8 @@ scene::IMesh* createForsythOptimizedMesh(const scene::IMesh *mesh)
 
                                        tc[highest].drawn = true;
 
-                                       for (u16 j = 0; j < 3; j++)
-                                       {
-                                               vcache *vert = &vc[tc[highest].ind[j]];
+                                       for (u16 j : tc[highest].ind) {
+                                               vcache *vert = &vc[j];
                                                for (u16 t = 0; t < vert->tris.size(); t++)
                                                {
                                                        if (highest == vert->tris[t])
@@ -1101,9 +1093,8 @@ scene::IMesh* createForsythOptimizedMesh(const scene::IMesh *mesh)
 
                                        tc[highest].drawn = true;
 
-                                       for (u16 j = 0; j < 3; j++)
-                                       {
-                                               vcache *vert = &vc[tc[highest].ind[j]];
+                                       for (u16 j : tc[highest].ind) {
+                                               vcache *vert = &vc[j];
                                                for (u16 t = 0; t < vert->tris.size(); t++)
                                                {
                                                        if (highest == vert->tris[t])
index b69d7f484bfd3eb1c3078b1364dc0b1c4263be44..01f4fbd7e30b231df055669ce541b9207c965e11 100644 (file)
@@ -63,14 +63,11 @@ MeshUpdateQueue::~MeshUpdateQueue()
 {
        MutexAutoLock lock(m_mutex);
 
-       for (std::map<v3s16, CachedMapBlockData *>::iterator i = m_cache.begin();
-                       i != m_cache.end(); ++i) {
-               delete i->second;
+       for (auto &i : m_cache) {
+               delete i.second;
        }
 
-       for (std::vector<QueuedMeshUpdate*>::iterator i = m_queue.begin();
-                       i != m_queue.end(); ++i) {
-               QueuedMeshUpdate *q = *i;
+       for (QueuedMeshUpdate *q : m_queue) {
                delete q;
        }
 }
@@ -116,9 +113,7 @@ void MeshUpdateQueue::addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool
                Find if block is already in queue.
                If it is, update the data and quit.
        */
-       for (std::vector<QueuedMeshUpdate*>::iterator i = m_queue.begin();
-                       i != m_queue.end(); ++i) {
-               QueuedMeshUpdate *q = *i;
+       for (QueuedMeshUpdate *q : m_queue) {
                if (q->p == p) {
                        // NOTE: We are not adding a new position to the queue, thus
                        //       refcount_from_queue stays the same.
@@ -141,8 +136,8 @@ void MeshUpdateQueue::addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool
        m_queue.push_back(q);
 
        // This queue entry is a new reference to the cached blocks
-       for (size_t i=0; i<cached_blocks.size(); i++) {
-               cached_blocks[i]->refcount_from_queue++;
+       for (CachedMapBlockData *cached_block : cached_blocks) {
+               cached_block->refcount_from_queue++;
        }
 }
 
@@ -191,19 +186,19 @@ CachedMapBlockData* MeshUpdateQueue::cacheBlock(Map *map, v3s16 p, UpdateMode mo
                        cached_block->data = NULL;
                }
                return cached_block;
-       } else {
-               // Not yet in cache
-               CachedMapBlockData *cached_block = new CachedMapBlockData();
-               m_cache[p] = cached_block;
-               MapBlock *b = map->getBlockNoCreateNoEx(p);
-               if (b) {
-                       cached_block->data =
-                                       new MapNode[MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE];
-                       memcpy(cached_block->data, b->getData(),
-                                       MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE * sizeof(MapNode));
-               }
-               return cached_block;
        }
+
+       // Not yet in cache
+       CachedMapBlockData *cached_block = new CachedMapBlockData();
+       m_cache[p] = cached_block;
+       MapBlock *b = map->getBlockNoCreateNoEx(p);
+       if (b) {
+               cached_block->data =
+                               new MapNode[MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE];
+               memcpy(cached_block->data, b->getData(),
+                               MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE * sizeof(MapNode));
+       }
+       return cached_block;
 }
 
 CachedMapBlockData* MeshUpdateQueue::getCachedBlock(const v3s16 &p)
index 2ef2ed16a360bf37c23dc74fdd85b3c37515248d..8dbb78e59e092b692a4e88be0f79641cc5479bf3 100644 (file)
@@ -51,25 +51,20 @@ BiomeManager::BiomeManager(Server *server) :
        b->heat_point      = 0.0;
        b->humidity_point  = 0.0;
 
-       b->m_nodenames.push_back("mapgen_stone");
-       b->m_nodenames.push_back("mapgen_stone");
-       b->m_nodenames.push_back("mapgen_stone");
-       b->m_nodenames.push_back("mapgen_water_source");
-       b->m_nodenames.push_back("mapgen_water_source");
-       b->m_nodenames.push_back("mapgen_river_water_source");
-       b->m_nodenames.push_back("mapgen_stone");
-       b->m_nodenames.push_back("ignore");
+       b->m_nodenames.emplace_back("mapgen_stone");
+       b->m_nodenames.emplace_back("mapgen_stone");
+       b->m_nodenames.emplace_back("mapgen_stone");
+       b->m_nodenames.emplace_back("mapgen_water_source");
+       b->m_nodenames.emplace_back("mapgen_water_source");
+       b->m_nodenames.emplace_back("mapgen_river_water_source");
+       b->m_nodenames.emplace_back("mapgen_stone");
+       b->m_nodenames.emplace_back("ignore");
        m_ndef->pendNodeResolve(b);
 
        add(b);
 }
 
 
-BiomeManager::~BiomeManager()
-{
-}
-
-
 void BiomeManager::clear()
 {
        EmergeManager *emerge = m_server->getEmergeManager();
index e64f36b13c3a63f92ca98f5f01f9682472f3e2d7..f45238f28f6dd9d90933f8242467b06eb93b62e1 100644 (file)
@@ -83,14 +83,15 @@ enum BiomeGenType {
 struct BiomeParams {
        virtual void readParams(const Settings *settings) = 0;
        virtual void writeParams(Settings *settings) const = 0;
-       virtual ~BiomeParams() {}
+       virtual ~BiomeParams() = default;
 
        s32 seed;
 };
 
 class BiomeGen {
 public:
-       virtual ~BiomeGen() {}
+       virtual ~BiomeGen() = default;
+
        virtual BiomeGenType getType() const = 0;
 
        // Calculates the biome at the exact position provided.  This function can
@@ -188,7 +189,7 @@ private:
 class BiomeManager : public ObjDefManager {
 public:
        BiomeManager(Server *server);
-       virtual ~BiomeManager();
+       virtual ~BiomeManager() = default;
 
        const char *getObjectTitle() const
        {
index 8feaa98501089ed40004b5f51a688d5d8ec3a40c..fd6e89e798bb94d43204ef139454f6c4b07ed479 100644 (file)
@@ -63,8 +63,8 @@ struct CutoffData {
 
 class Decoration : public ObjDef, public NodeResolver {
 public:
-       Decoration() {};
-       virtual ~Decoration() {};
+       Decoration() = default;
+       virtual ~Decoration() = default;
 
        virtual void resolveNodeNames();
 
@@ -104,7 +104,7 @@ public:
 
 class DecoSchematic : public Decoration {
 public:
-       DecoSchematic() {};
+       DecoSchematic() = default;
 
        virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p);
        virtual int getHeight();
@@ -124,7 +124,7 @@ public:
 class DecorationManager : public ObjDefManager {
 public:
        DecorationManager(IGameDef *gamedef);
-       virtual ~DecorationManager() {}
+       virtual ~DecorationManager() = default;
 
        const char *getObjectTitle() const
        {
index 044d58db888de64829c54dd19d0a8370030bf989..5f11dda92cb70d65781a4ca83d98dafd9a84d756 100644 (file)
@@ -64,8 +64,8 @@ size_t OreManager::placeAllOres(Mapgen *mg, u32 blockseed,
 
 void OreManager::clear()
 {
-       for (size_t i = 0; i < m_objects.size(); i++) {
-               Ore *ore = (Ore *)m_objects[i];
+       for (ObjDef *object : m_objects) {
+               Ore *ore = (Ore *) object;
                delete ore;
        }
        m_objects.clear();
@@ -221,13 +221,6 @@ void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed,
 
 
 ///////////////////////////////////////////////////////////////////////////////
-
-OrePuff::OrePuff() :
-       Ore()
-{
-}
-
-
 OrePuff::~OrePuff()
 {
        delete noise_puff_top;
@@ -372,13 +365,6 @@ void OreBlob::generate(MMVManip *vm, int mapseed, u32 blockseed,
 
 
 ///////////////////////////////////////////////////////////////////////////////
-
-OreVein::OreVein() :
-       Ore()
-{
-}
-
-
 OreVein::~OreVein()
 {
        delete noise2;
index dea1d4272fbacb5c0b9b1a8f3ee8b8c9d69befa8..eaaf2b88323cd31a2f98389cec94b5cd1d05054c 100644 (file)
@@ -104,7 +104,7 @@ public:
        Noise *noise_puff_top = nullptr;
        Noise *noise_puff_bottom = nullptr;
 
-       OrePuff();
+       OrePuff() = default;
        virtual ~OrePuff();
 
        virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
@@ -126,7 +126,7 @@ public:
        float random_factor;
        Noise *noise2 = nullptr;
 
-       OreVein();
+       OreVein() = default;
        virtual ~OreVein();
 
        virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
index fc6488c4d092a6370274e16bc9425a2e7c9cad82..069b594f10e02018ba2c31f76100c63f3dda5c99 100644 (file)
@@ -125,7 +125,7 @@ public:
 class SchematicManager : public ObjDefManager {
 public:
        SchematicManager(Server *server);
-       virtual ~SchematicManager() {}
+       virtual ~SchematicManager() = default;
 
        virtual void clear();
 
index dab5f3aa5c9bb5e236744e03bc1765877e7640f3..f35330963d74c2afad5d917ee0f3c3be92750170 100644 (file)
@@ -46,10 +46,7 @@ bool MinimapUpdateThread::pushBlockUpdate(v3s16 pos, MinimapMapblock *data)
 
        // Find if block is already in queue.
        // If it is, update the data and quit.
-       for (std::deque<QueuedMinimapUpdate>::iterator
-                       it = m_update_queue.begin();
-                       it != m_update_queue.end(); ++it) {
-               QueuedMinimapUpdate &q = *it;
+       for (QueuedMinimapUpdate &q : m_update_queue) {
                if (q.pos == pos) {
                        delete q.data;
                        q.data = data;
@@ -277,9 +274,9 @@ MinimapShape Minimap::getMinimapShape()
 {
        if (data->minimap_shape_round) {
                return MINIMAP_SHAPE_ROUND;
-       } else {
-               return MINIMAP_SHAPE_SQUARE;
        }
+
+       return MINIMAP_SHAPE_SQUARE;
 }
 
 void Minimap::setMinimapMode(MinimapMode mode)
@@ -434,9 +431,9 @@ v3f Minimap::getYawVec()
                        cos(m_angle * core::DEGTORAD),
                        sin(m_angle * core::DEGTORAD),
                        1.0);
-       } else {
-               return v3f(1.0, 0.0, 1.0);
        }
+
+       return v3f(1.0, 0.0, 1.0);
 }
 
 scene::SMeshBuffer *Minimap::getMinimapMeshBuffer()
@@ -568,9 +565,8 @@ void Minimap::updateActiveMarkers()
 
        m_active_markers.clear();
 
-       for (std::list<Nametag *>::const_iterator i = nametags.begin();
-                       i != nametags.end(); ++i) {
-               v3s16 pos = floatToInt((*i)->parent_node->getPosition() +
+       for (Nametag *nametag : nametags) {
+               v3s16 pos = floatToInt(nametag->parent_node->getPosition() +
                        intToFloat(client->getCamera()->getOffset(), BS), BS);
                pos -= data->pos - v3s16(data->map_size / 2,
                                data->scan_height / 2,
@@ -586,8 +582,9 @@ void Minimap::updateActiveMarkers()
                if (!mask_col.getAlpha()) {
                        continue;
                }
-               m_active_markers.push_back(v2f(((float)pos.X / (float)MINIMAP_MAX_SX) - 0.5,
-                       (1.0 - (float)pos.Z / (float)MINIMAP_MAX_SY) - 0.5));
+
+               m_active_markers.emplace_back(((float)pos.X / (float)MINIMAP_MAX_SX) - 0.5,
+                       (1.0 - (float)pos.Z / (float)MINIMAP_MAX_SY) - 0.5);
        }
 }
 
index eeffc6195ca048d5cf7a757d25dd51624063da65..f41591c3f83df155ecb21f582f282100bea74b25 100644 (file)
@@ -111,16 +111,12 @@ public:
        {
                const core::list<gui::IGUIElement*> &children = getChildren();
                core::list<gui::IGUIElement*> children_copy;
-               for(core::list<gui::IGUIElement*>::ConstIterator
-                               i = children.begin(); i != children.end(); i++)
-               {
-                       children_copy.push_back(*i);
+               for (gui::IGUIElement *i : children) {
+                       children_copy.push_back(i);
                }
-               for(core::list<gui::IGUIElement*>::Iterator
-                               i = children_copy.begin();
-                               i != children_copy.end(); i++)
-               {
-                       (*i)->remove();
+
+               for (gui::IGUIElement *i : children_copy) {
+                       i->remove();
                }
        }
 
index 7e2d83944407c78a8cef5781a1cb60f5fb3f9754..d28288a89ba7432ecafdd8646778309d4151a347 100644 (file)
@@ -41,7 +41,7 @@ static bool parseDependsLine(std::istream &is,
                --pos;
        }
        dep = trim(dep.substr(0, pos));
-       return dep != "";
+       return !dep.empty();
 }
 
 void parseModContents(ModSpec &spec)
@@ -91,13 +91,13 @@ std::map<std::string, ModSpec> getModsInPath(std::string path, bool part_of_modp
 
        std::map<std::string, ModSpec> result;
        std::vector<fs::DirListNode> dirlist = fs::GetDirListing(path);
-       for(u32 j=0; j<dirlist.size(); j++){
-               if(!dirlist[j].dir)
+       for (const fs::DirListNode &dln : dirlist) {
+               if(!dln.dir)
                        continue;
-               std::string modname = dirlist[j].name;
+               const std::string &modname = dln.name;
                // Ignore all directories beginning with a ".", especially
                // VCS directories like ".git" or ".svn"
-               if(modname[0] == '.')
+               if (modname[0] == '.')
                        continue;
                std::string modpath = path + DIR_DELIM + modname;
 
@@ -112,12 +112,9 @@ std::map<std::string, ModSpec> getModsInPath(std::string path, bool part_of_modp
 std::vector<ModSpec> flattenMods(std::map<std::string, ModSpec> mods)
 {
        std::vector<ModSpec> result;
-       for(std::map<std::string,ModSpec>::iterator it = mods.begin();
-               it != mods.end(); ++it)
-       {
-               ModSpec mod = (*it).second;
-               if(mod.is_modpack)
-               {
+       for (const auto &it : mods) {
+               const ModSpec &mod = it.second;
+               if (mod.is_modpack) {
                        std::vector<ModSpec> content = flattenMods(mod.modpack_content);
                        result.reserve(result.size() + content.size());
                        result.insert(result.end(),content.begin(),content.end());
@@ -131,23 +128,16 @@ std::vector<ModSpec> flattenMods(std::map<std::string, ModSpec> mods)
        return result;
 }
 
-ModConfiguration::ModConfiguration(const std::string &worldpath):
-       m_unsatisfied_mods(),
-       m_sorted_mods(),
-       m_name_conflicts()
+ModConfiguration::ModConfiguration(const std::string &worldpath)
 {
 }
 
 void ModConfiguration::printUnsatisfiedModsError() const
 {
-       for (std::vector<ModSpec>::const_iterator it = m_unsatisfied_mods.begin();
-               it != m_unsatisfied_mods.end(); ++it) {
-               ModSpec mod = *it;
+       for (const ModSpec &mod : m_unsatisfied_mods) {
                errorstream << "mod \"" << mod.name << "\" has unsatisfied dependencies: ";
-               for (std::unordered_set<std::string>::iterator dep_it =
-                       mod.unsatisfied_depends.begin();
-                       dep_it != mod.unsatisfied_depends.end(); ++dep_it)
-                       errorstream << " \"" << *dep_it << "\"";
+               for (const std::string &unsatisfied_depend : mod.unsatisfied_depends)
+                       errorstream << " \"" << unsatisfied_depend << "\"";
                errorstream << std::endl;
        }
 }
@@ -175,17 +165,15 @@ void ModConfiguration::addMods(const std::vector<ModSpec> &new_mods)
 
                std::set<std::string> seen_this_iteration;
 
-               for (std::vector<ModSpec>::const_iterator it = new_mods.begin();
-                               it != new_mods.end(); ++it) {
-                       const ModSpec &mod = *it;
-                       if(mod.part_of_modpack != (bool)want_from_modpack)
+               for (const ModSpec &mod : new_mods) {
+                       if (mod.part_of_modpack != (bool)want_from_modpack)
                                continue;
-                       if(existing_mods.count(mod.name) == 0){
+
+                       if (existing_mods.count(mod.name) == 0) {
                                // GOOD CASE: completely new mod.
                                m_unsatisfied_mods.push_back(mod);
                                existing_mods[mod.name] = m_unsatisfied_mods.size() - 1;
-                       }
-                       else if(seen_this_iteration.count(mod.name) == 0){
+                       } else if(seen_this_iteration.count(mod.name) == 0) {
                                // BAD CASE: name conflict in different levels.
                                u32 oldindex = existing_mods[mod.name];
                                const ModSpec &oldmod = m_unsatisfied_mods[oldindex];
@@ -198,8 +186,7 @@ void ModConfiguration::addMods(const std::vector<ModSpec> &new_mods)
                                // If there was a "VERY BAD CASE" name conflict
                                // in an earlier level, ignore it.
                                m_name_conflicts.erase(mod.name);
-                       }
-                       else{
+                       } else {
                                // VERY BAD CASE: name conflict in the same level.
                                u32 oldindex = existing_mods[mod.name];
                                const ModSpec &oldmod = m_unsatisfied_mods[oldindex];
@@ -210,6 +197,7 @@ void ModConfiguration::addMods(const std::vector<ModSpec> &new_mods)
                                m_unsatisfied_mods[oldindex] = mod;
                                m_name_conflicts.insert(mod.name);
                        }
+
                        seen_this_iteration.insert(mod.name);
                }
        }
@@ -222,17 +210,14 @@ void ModConfiguration::addModsFormConfig(const std::string &settings_path, const
 
        conf.readConfigFile(settings_path.c_str());
        std::vector<std::string> names = conf.getNames();
-       for (std::vector<std::string>::iterator it = names.begin();
-               it != names.end(); ++it) {
-               std::string name = *it;
+       for (const std::string &name : names) {
                if (name.compare(0,9,"load_mod_")==0 && conf.getBool(name))
                        load_mod_names.insert(name.substr(9));
        }
 
        std::vector<ModSpec> addon_mods;
-       for (std::set<std::string>::const_iterator i = mods.begin();
-                       i != mods.end(); ++i) {
-               std::vector<ModSpec> addon_mods_in_path = flattenMods(getModsInPath(*i));
+       for (const std::string &i : mods) {
+               std::vector<ModSpec> addon_mods_in_path = flattenMods(getModsInPath(i));
                for (std::vector<ModSpec>::const_iterator it = addon_mods_in_path.begin();
                                it != addon_mods_in_path.end(); ++it) {
                        const ModSpec& mod = *it;
@@ -248,18 +233,18 @@ void ModConfiguration::addModsFormConfig(const std::string &settings_path, const
        checkConflictsAndDeps();
 
        // complain about mods declared to be loaded, but not found
-       for (std::vector<ModSpec>::iterator it = addon_mods.begin();
-                       it != addon_mods.end(); ++it)
-               load_mod_names.erase((*it).name);
-       std::vector<ModSpec> UnsatisfiedMods = getUnsatisfiedMods();
-       for (std::vector<ModSpec>::iterator it = UnsatisfiedMods.begin();
-                       it != UnsatisfiedMods.end(); ++it)
-               load_mod_names.erase((*it).name);
+       for (const ModSpec &addon_mod : addon_mods)
+               load_mod_names.erase(addon_mod.name);
+
+       std::vector<ModSpec> unsatisfiedMods = getUnsatisfiedMods();
+
+       for (const ModSpec &unsatisfiedMod : unsatisfiedMods)
+               load_mod_names.erase(unsatisfiedMod.name);
+
        if (!load_mod_names.empty()) {
                errorstream << "The following mods could not be found:";
-               for (std::set<std::string>::iterator it = load_mod_names.begin();
-                               it != load_mod_names.end(); ++it)
-                       errorstream << " \"" << (*it) << "\"";
+               for (const std::string &mod : load_mod_names)
+                       errorstream << " \"" << mod << "\"";
                errorstream << std::endl;
        }
 }
@@ -286,23 +271,18 @@ void ModConfiguration::resolveDependencies()
 {
        // Step 1: Compile a list of the mod names we're working with
        std::set<std::string> modnames;
-       for(std::vector<ModSpec>::iterator it = m_unsatisfied_mods.begin();
-               it != m_unsatisfied_mods.end(); ++it){
-               modnames.insert((*it).name);
+       for (const ModSpec &mod : m_unsatisfied_mods) {
+               modnames.insert(mod.name);
        }
 
        // Step 2: get dependencies (including optional dependencies)
        // of each mod, split mods into satisfied and unsatisfied
        std::list<ModSpec> satisfied;
        std::list<ModSpec> unsatisfied;
-       for (std::vector<ModSpec>::iterator it = m_unsatisfied_mods.begin();
-                       it != m_unsatisfied_mods.end(); ++it) {
-               ModSpec mod = *it;
+       for (ModSpec mod : m_unsatisfied_mods) {
                mod.unsatisfied_depends = mod.depends;
                // check which optional dependencies actually exist
-               for (std::unordered_set<std::string>::iterator it_optdep = mod.optdepends.begin();
-                               it_optdep != mod.optdepends.end(); ++it_optdep) {
-                       std::string optdep = *it_optdep;
+               for (const std::string &optdep : mod.optdepends) {
                        if (modnames.count(optdep) != 0)
                                mod.unsatisfied_depends.insert(optdep);
                }
@@ -319,15 +299,13 @@ void ModConfiguration::resolveDependencies()
                ModSpec mod = satisfied.back();
                m_sorted_mods.push_back(mod);
                satisfied.pop_back();
-               for(std::list<ModSpec>::iterator it = unsatisfied.begin();
-                               it != unsatisfied.end(); ){
+               for (auto it = unsatisfied.begin(); it != unsatisfied.end(); ) {
                        ModSpec& mod2 = *it;
                        mod2.unsatisfied_depends.erase(mod.name);
-                       if(mod2.unsatisfied_depends.empty()){
+                       if (mod2.unsatisfied_depends.empty()) {
                                satisfied.push_back(mod2);
                                it = unsatisfied.erase(it);
-                       }
-                       else{
+                       } else {
                                ++it;
                        }
                }
@@ -425,10 +403,9 @@ bool ModMetadata::load(const std::string &root_path)
        }
 
        const Json::Value::Members attr_list = root.getMemberNames();
-       for (Json::Value::Members::const_iterator it = attr_list.begin();
-                       it != attr_list.end(); ++it) {
-               Json::Value attr_value = root[*it];
-               m_stringvars[*it] = attr_value.asString();
+       for (const auto &it : attr_list) {
+               Json::Value attr_value = root[it];
+               m_stringvars[it] = attr_value.asString();
        }
 
        return true;
index 63927a9d052874db4aeb58db22d0464d4c55e5b2..27464b86ece65b66cde29352a9f473fe5ea9e0a8 100644 (file)
@@ -121,7 +121,7 @@ private:
        std::unordered_set<std::string> m_name_conflicts;
 
        // Deleted default constructor
-       ModConfiguration() {}
+       ModConfiguration() = default;
 
 };
 
@@ -155,7 +155,7 @@ class ModMetadata: public Metadata
 {
 public:
        ModMetadata(const std::string &mod_name);
-       ~ModMetadata() {}
+       ~ModMetadata() = default;
 
        virtual void clear();