From c42753338924bb29c61081c9f269772f89bcd808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Blot?= Date: Fri, 18 Aug 2017 18:18:25 +0200 Subject: [PATCH] Modernize various files (src/m*) (#6267) * 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 --- src/main.cpp | 70 +++++++++++----------- src/mainmenumanager.h | 17 ++---- src/map.cpp | 23 ++++---- src/map.h | 12 ++-- src/mapblock.cpp | 32 +++++----- src/mapgen.h | 2 +- src/mapgen_carpathian.h | 2 +- src/mapgen_flat.cpp | 7 ++- src/mapgen_fractal.h | 2 +- src/mapgen_singlenode.cpp | 5 -- src/mapgen_singlenode.h | 6 +- src/mapgen_v5.cpp | 6 +- src/mapgen_v6.cpp | 45 +++++++------- src/mapgen_v6.h | 2 +- src/mapgen_v7.cpp | 12 ++-- src/mapgen_v7.h | 2 +- src/mapgen_valleys.cpp | 7 ++- src/mapgen_valleys.h | 2 +- src/mapnode.cpp | 35 +++++------ src/mapnode.h | 3 +- src/mapsector.cpp | 27 +++------ src/mapsector.h | 4 +- src/mesh.cpp | 37 +++++------- src/mesh_generator_thread.cpp | 41 ++++++------- src/mg_biome.cpp | 21 +++---- src/mg_biome.h | 7 ++- src/mg_decoration.h | 8 +-- src/mg_ore.cpp | 18 +----- src/mg_ore.h | 4 +- src/mg_schematic.h | 2 +- src/minimap.cpp | 23 ++++---- src/modalMenu.h | 14 ++--- src/mods.cpp | 107 +++++++++++++--------------------- src/mods.h | 4 +- 34 files changed, 254 insertions(+), 355 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ee391cf68..303004f0c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 << _(" "); 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 gameids = getAvailableGameIds(); - for (std::set::const_iterator i = gameids.begin(); - i != gameids.end(); ++i) - std::cout << (*i) < &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 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 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")) { diff --git a/src/mainmenumanager.h b/src/mainmenumanager.h index 2618d3ccf..49bc88dff 100644 --- a/src/mainmenumanager.h +++ b/src/mainmenumanager.h @@ -48,11 +48,8 @@ class MainMenuManager : public IMenuManager public: virtual void createdMenu(gui::IGUIElement *menu) { - for(std::list::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::iterator - i = m_stack.begin(); i != m_stack.end(); ++i) - { - GUIModalMenu *mm = dynamic_cast(*i); + for (gui::IGUIElement *i : m_stack) { + GUIModalMenu *mm = dynamic_cast(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() { diff --git a/src/map.cpp b/src/map.cpp index 972c666e4..6cf838696 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -527,14 +527,13 @@ void Map::unloadUnreferencedBlocks(std::vector *unloaded_blocks) void Map::deleteSectors(std::vector §orList) { - for(std::vector::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 " <<"\""< *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); diff --git a/src/map.h b/src/map.h index 4dd2b7e30..81f32baea 100644 --- a/src/map.h +++ b/src/map.h @@ -77,7 +77,7 @@ struct MapEditEvent std::set 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::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"); } diff --git a/src/mapblock.cpp b/src/mapblock.cpp index ca5894794..48b7c1915 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -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 & 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::const_iterator - i = unknown_contents.begin(); - i != unknown_contents.end(); ++i){ - errorstream<<"getBlockNodeIdMapping(): IGNORING ERROR: " - <<"Name for node id "<<(*i)<<" not known"< 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 } diff --git a/src/mapgen_fractal.h b/src/mapgen_fractal.h index a83c5b317..be4941581 100644 --- a/src/mapgen_fractal.h +++ b/src/mapgen_fractal.h @@ -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; diff --git a/src/mapgen_singlenode.cpp b/src/mapgen_singlenode.cpp index f49059f7f..ee8746b83 100644 --- a/src/mapgen_singlenode.cpp +++ b/src/mapgen_singlenode.cpp @@ -46,11 +46,6 @@ MapgenSinglenode::MapgenSinglenode(int mapgenid, } -MapgenSinglenode::~MapgenSinglenode() -{ -} - - //////////////////////// Map generator void MapgenSinglenode::makeChunk(BlockMakeData *data) diff --git a/src/mapgen_singlenode.h b/src/mapgen_singlenode.h index 38bc3e020..7678613e5 100644 --- a/src/mapgen_singlenode.h +++ b/src/mapgen_singlenode.h @@ -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; } diff --git a/src/mapgen_v5.cpp b/src/mapgen_v5.cpp index 2cfb065f9..d7e9d6664 100644 --- a/src/mapgen_v5.cpp +++ b/src/mapgen_v5.cpp @@ -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 diff --git a/src/mapgen_v6.cpp b/src/mapgen_v6.cpp index cbc4a19c3..ec33fee08 100644 --- a/src/mapgen_v6.cpp +++ b/src/mapgen_v6.cpp @@ -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); diff --git a/src/mapgen_v6.h b/src/mapgen_v6.h index f92e90695..872679683 100644 --- a/src/mapgen_v6.h +++ b/src/mapgen_v6.h @@ -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; diff --git a/src/mapgen_v7.cpp b/src/mapgen_v7.cpp index 3ce22dbb1..d27e339ce 100644 --- a/src/mapgen_v7.cpp +++ b/src/mapgen_v7.cpp @@ -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--; diff --git a/src/mapgen_v7.h b/src/mapgen_v7.h index f4d397135..877f3d089 100644 --- a/src/mapgen_v7.h +++ b/src/mapgen_v7.h @@ -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; diff --git a/src/mapgen_valleys.cpp b/src/mapgen_valleys.cpp index f0c145934..d8b3193a6 100644 --- a/src/mapgen_valleys.cpp +++ b/src/mapgen_valleys.cpp @@ -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. diff --git a/src/mapgen_valleys.h b/src/mapgen_valleys.h index 1cb94860c..7b5eb187d 100644 --- a/src/mapgen_valleys.h +++ b/src/mapgen_valleys.h @@ -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; diff --git a/src/mapnode.cpp b/src/mapnode.cpp index fd28910ff..b06b42ba8 100644 --- a/src/mapnode.cpp +++ b/src/mapnode.cpp @@ -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::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) { diff --git a/src/mapnode.h b/src/mapnode.h index 200a51207..4b75fe227 100644 --- a/src/mapnode.h +++ b/src/mapnode.h @@ -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), diff --git a/src/mapsector.cpp b/src/mapsector.cpp index 446b43747..c6832a012 100644 --- a/src/mapsector.cpp +++ b/src/mapsector.cpp @@ -40,9 +40,8 @@ void MapSector::deleteBlocks() m_block_cache = nullptr; // Delete all - for (std::unordered_map::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::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 diff --git a/src/mapsector.h b/src/mapsector.h index ff1ca7be6..b0ed9c88c 100644 --- a/src/mapsector.h +++ b/src/mapsector.h @@ -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 { diff --git a/src/mesh.cpp b/src/mesh.cpp index 3ab67510a..218e2d0b2 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -453,11 +453,7 @@ scene::IMesh* convertNodeboxesToMesh(const std::vector &boxes, video::SColor c(255,255,255,255); - for (std::vector::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]) diff --git a/src/mesh_generator_thread.cpp b/src/mesh_generator_thread.cpp index b69d7f484..01f4fbd7e 100644 --- a/src/mesh_generator_thread.cpp +++ b/src/mesh_generator_thread.cpp @@ -63,14 +63,11 @@ MeshUpdateQueue::~MeshUpdateQueue() { MutexAutoLock lock(m_mutex); - for (std::map::iterator i = m_cache.begin(); - i != m_cache.end(); ++i) { - delete i->second; + for (auto &i : m_cache) { + delete i.second; } - for (std::vector::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::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; irefcount_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) diff --git a/src/mg_biome.cpp b/src/mg_biome.cpp index 2ef2ed16a..8dbb78e59 100644 --- a/src/mg_biome.cpp +++ b/src/mg_biome.cpp @@ -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(); diff --git a/src/mg_biome.h b/src/mg_biome.h index e64f36b13..f45238f28 100644 --- a/src/mg_biome.h +++ b/src/mg_biome.h @@ -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 { diff --git a/src/mg_decoration.h b/src/mg_decoration.h index 8feaa9850..fd6e89e79 100644 --- a/src/mg_decoration.h +++ b/src/mg_decoration.h @@ -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 { diff --git a/src/mg_ore.cpp b/src/mg_ore.cpp index 044d58db8..5f11dda92 100644 --- a/src/mg_ore.cpp +++ b/src/mg_ore.cpp @@ -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; diff --git a/src/mg_ore.h b/src/mg_ore.h index dea1d4272..eaaf2b883 100644 --- a/src/mg_ore.h +++ b/src/mg_ore.h @@ -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, diff --git a/src/mg_schematic.h b/src/mg_schematic.h index fc6488c4d..069b594f1 100644 --- a/src/mg_schematic.h +++ b/src/mg_schematic.h @@ -125,7 +125,7 @@ public: class SchematicManager : public ObjDefManager { public: SchematicManager(Server *server); - virtual ~SchematicManager() {} + virtual ~SchematicManager() = default; virtual void clear(); diff --git a/src/minimap.cpp b/src/minimap.cpp index dab5f3aa5..f35330963 100644 --- a/src/minimap.cpp +++ b/src/minimap.cpp @@ -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::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::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); } } diff --git a/src/modalMenu.h b/src/modalMenu.h index eeffc6195..f41591c3f 100644 --- a/src/modalMenu.h +++ b/src/modalMenu.h @@ -111,16 +111,12 @@ public: { const core::list &children = getChildren(); core::list children_copy; - for(core::list::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::Iterator - i = children_copy.begin(); - i != children_copy.end(); i++) - { - (*i)->remove(); + + for (gui::IGUIElement *i : children_copy) { + i->remove(); } } diff --git a/src/mods.cpp b/src/mods.cpp index 7e2d83944..d28288a89 100644 --- a/src/mods.cpp +++ b/src/mods.cpp @@ -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 getModsInPath(std::string path, bool part_of_modp std::map result; std::vector dirlist = fs::GetDirListing(path); - for(u32 j=0; j getModsInPath(std::string path, bool part_of_modp std::vector flattenMods(std::map mods) { std::vector result; - for(std::map::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 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 flattenMods(std::map 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::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::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 &new_mods) std::set seen_this_iteration; - for (std::vector::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 &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 &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 names = conf.getNames(); - for (std::vector::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 addon_mods; - for (std::set::const_iterator i = mods.begin(); - i != mods.end(); ++i) { - std::vector addon_mods_in_path = flattenMods(getModsInPath(*i)); + for (const std::string &i : mods) { + std::vector addon_mods_in_path = flattenMods(getModsInPath(i)); for (std::vector::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::iterator it = addon_mods.begin(); - it != addon_mods.end(); ++it) - load_mod_names.erase((*it).name); - std::vector UnsatisfiedMods = getUnsatisfiedMods(); - for (std::vector::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 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::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 modnames; - for(std::vector::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 satisfied; std::list unsatisfied; - for (std::vector::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::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::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; diff --git a/src/mods.h b/src/mods.h index 63927a9d0..27464b86e 100644 --- a/src/mods.h +++ b/src/mods.h @@ -121,7 +121,7 @@ private: std::unordered_set 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();