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
experimental
Loïc Blot 2017-08-18 18:18:25 +02:00 committed by GitHub
parent fb196be8cf
commit c427533389
34 changed files with 254 additions and 355 deletions

View 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")) {

View 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()
{

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

View File

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

View 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.

View File

@ -122,7 +122,7 @@ enum MapgenType {
};
struct MapgenParams {
MapgenParams() {}
MapgenParams() = default;
virtual ~MapgenParams();
MapgenType mgtype = MAPGEN_DEFAULT;

View 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;

View 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
}

View 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;

View File

@ -46,11 +46,6 @@ MapgenSinglenode::MapgenSinglenode(int mapgenid,
}
MapgenSinglenode::~MapgenSinglenode()
{
}
//////////////////////// Map generator
void MapgenSinglenode::makeChunk(BlockMakeData *data)

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

View 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

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

View 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;

View 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--;

View 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;

View 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.

View 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;

View 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)
{

View 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),

View 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

View 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
{

View 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])

View 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)

View 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();

View 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
{

View 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
{

View 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;

View 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,

View File

@ -125,7 +125,7 @@ public:
class SchematicManager : public ObjDefManager {
public:
SchematicManager(Server *server);
virtual ~SchematicManager() {}
virtual ~SchematicManager() = default;
virtual void clear();

View 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);
}
}

View 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();
}
}

View 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;

View 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();