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
This commit is contained in:
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

@ -211,7 +211,7 @@ int main(int argc, char *argv[])
#endif #endif
// Update configuration file // Update configuration file
if (g_settings_path != "") if (!g_settings_path.empty())
g_settings->updateConfigFile(g_settings_path.c_str()); g_settings->updateConfigFile(g_settings_path.c_str());
print_modified_quicktune_values(); 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) static void print_allowed_options(const OptionList &allowed_options)
{ {
for (OptionList::const_iterator i = allowed_options.begin(); for (const auto &allowed_option : allowed_options) {
i != allowed_options.end(); ++i) {
std::ostringstream os1(std::ios::binary); std::ostringstream os1(std::ios::binary);
os1 << " --" << i->first; os1 << " --" << allowed_option.first;
if (i->second.type != VALUETYPE_FLAG) if (allowed_option.second.type != VALUETYPE_FLAG)
os1 << _(" <value>"); os1 << _(" <value>");
std::cout << padStringRight(os1.str(), 30); std::cout << padStringRight(os1.str(), 30);
if (i->second.help) if (allowed_option.second.help)
std::cout << i->second.help; std::cout << allowed_option.second.help;
std::cout << std::endl; std::cout << std::endl;
} }
@ -335,9 +334,8 @@ static void print_version()
static void list_game_ids() static void list_game_ids()
{ {
std::set<std::string> gameids = getAvailableGameIds(); std::set<std::string> gameids = getAvailableGameIds();
for (std::set<std::string>::const_iterator i = gameids.begin(); for (const std::string &gameid : gameids)
i != gameids.end(); ++i) std::cout << gameid <<std::endl;
std::cout << (*i) <<std::endl;
} }
static void list_worlds() static void list_worlds()
@ -350,10 +348,10 @@ static void list_worlds()
static void print_worldspecs(const std::vector<WorldSpec> &worldspecs, static void print_worldspecs(const std::vector<WorldSpec> &worldspecs,
std::ostream &os) std::ostream &os)
{ {
for (size_t i = 0; i < worldspecs.size(); i++) { for (const WorldSpec &worldspec : worldspecs) {
std::string name = worldspecs[i].name; std::string name = worldspec.name;
std::string path = worldspecs[i].path; std::string path = worldspec.path;
if (name.find(" ") != std::string::npos) if (name.find(' ') != std::string::npos)
name = std::string("'") + name + "'"; name = std::string("'") + name + "'";
path = std::string("'") + path + "'"; path = std::string("'") + path + "'";
name = padStringRight(name, 14); name = padStringRight(name, 14);
@ -366,15 +364,15 @@ static void print_modified_quicktune_values()
bool header_printed = false; bool header_printed = false;
std::vector<std::string> names = getQuicktuneNames(); std::vector<std::string> names = getQuicktuneNames();
for (u32 i = 0; i < names.size(); i++) { for (const std::string &name : names) {
QuicktuneValue val = getQuicktuneValue(names[i]); QuicktuneValue val = getQuicktuneValue(name);
if (!val.modified) if (!val.modified)
continue; continue;
if (!header_printed) { if (!header_printed) {
dstream << "Modified quicktune values:" << std::endl; dstream << "Modified quicktune values:" << std::endl;
header_printed = true; 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"); DIR_DELIM + ".." + DIR_DELIM + ".." + DIR_DELIM + "minetest.conf");
#endif #endif
for (size_t i = 0; i < filenames.size(); i++) { for (const std::string &filename : filenames) {
bool r = g_settings->readConfigFile(filenames[i].c_str()); bool r = g_settings->readConfigFile(filename.c_str());
if (r) { if (r) {
g_settings_path = filenames[i]; g_settings_path = filename;
break; break;
} }
} }
// If no path found, use the first one (menu creates the file) // 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]; 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; 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); 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)) if (get_world_from_cmdline(game_params, cmd_args))
return true; return true;
if (get_world_from_config(game_params, cmd_args)) if (get_world_from_config(game_params, cmd_args))
return true; 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) static bool get_world_from_cmdline(GameParams *game_params, const Settings &cmd_args)
{ {
std::string commanded_world = ""; std::string commanded_world;
// World name // World name
std::string commanded_worldname = ""; std::string commanded_worldname;
if (cmd_args.exists("worldname")) if (cmd_args.exists("worldname"))
commanded_worldname = cmd_args.get("worldname"); commanded_worldname = cmd_args.get("worldname");
// If a world name was specified, convert it to a path // If a world name was specified, convert it to a path
if (commanded_worldname != "") { if (!commanded_worldname.empty()) {
// Get information about available worlds // Get information about available worlds
std::vector<WorldSpec> worldspecs = getAvailableWorlds(); std::vector<WorldSpec> worldspecs = getAvailableWorlds();
bool found = false; bool found = false;
for (u32 i = 0; i < worldspecs.size(); i++) { for (const WorldSpec &worldspec : worldspecs) {
std::string name = worldspecs[i].name; std::string name = worldspec.name;
if (name == commanded_worldname) { if (name == commanded_worldname) {
dstream << _("Using world specified by --worldname on the " dstream << _("Using world specified by --worldname on the "
"command line") << std::endl; "command line") << std::endl;
commanded_world = worldspecs[i].path; commanded_world = worldspec.path;
found = true; found = true;
break; 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); game_params->world_path = get_clean_world_path(commanded_world);
return commanded_world != ""; return !commanded_world.empty();
} }
if (cmd_args.exists("world")) 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"); commanded_world = cmd_args.get("nonopt0");
game_params->world_path = get_clean_world_path(commanded_world); 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) static bool get_world_from_config(GameParams *game_params, const Settings &cmd_args)
{ {
// World directory // World directory
std::string commanded_world = ""; std::string commanded_world;
if (g_settings->exists("map-dir")) if (g_settings->exists("map-dir"))
commanded_world = g_settings->get("map-dir"); commanded_world = g_settings->get("map-dir");
game_params->world_path = get_clean_world_path(commanded_world); 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) 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; verbosestream << _("Determining gameid/gamespec") << std::endl;
// If world doesn't exist // If world doesn't exist
if (game_params->world_path != "" if (!game_params->world_path.empty()
&& !getWorldExists(game_params->world_path)) { && !getWorldExists(game_params->world_path)) {
// Try to take gamespec from command line // Try to take gamespec from command line
if (game_params->game_spec.isValid()) { if (game_params->game_spec.isValid()) {
gamespec = game_params->game_spec; gamespec = game_params->game_spec;
@ -810,7 +809,8 @@ static bool run_dedicated_server(const GameParams &game_params, const Settings &
// Database migration // Database migration
if (cmd_args.exists("migrate")) if (cmd_args.exists("migrate"))
return migrate_map_database(game_params, cmd_args); 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); return ServerEnvironment::migratePlayersDatabase(game_params, cmd_args);
if (cmd_args.exists("terminal")) { if (cmd_args.exists("terminal")) {

@ -48,11 +48,8 @@ class MainMenuManager : public IMenuManager
public: public:
virtual void createdMenu(gui::IGUIElement *menu) virtual void createdMenu(gui::IGUIElement *menu)
{ {
for(std::list<gui::IGUIElement*>::iterator for (gui::IGUIElement *i : m_stack) {
i = m_stack.begin(); assert(i != menu);
i != m_stack.end(); ++i)
{
assert(*i != menu);
} }
if(!m_stack.empty()) if(!m_stack.empty())
@ -103,10 +100,8 @@ public:
bool pausesGame() bool pausesGame()
{ {
for(std::list<gui::IGUIElement*>::iterator for (gui::IGUIElement *i : m_stack) {
i = m_stack.begin(); i != m_stack.end(); ++i) GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(i);
{
GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(*i);
if (mm && mm->pausesGame()) if (mm && mm->pausesGame())
return true; return true;
} }
@ -123,8 +118,8 @@ extern bool isMenuActive();
class MainGameCallback : public IGameCallback class MainGameCallback : public IGameCallback
{ {
public: public:
MainGameCallback() {} MainGameCallback() = default;
virtual ~MainGameCallback() {} virtual ~MainGameCallback() = default;
virtual void exitToOS() virtual void exitToOS()
{ {

@ -527,14 +527,13 @@ void Map::unloadUnreferencedBlocks(std::vector<v3s16> *unloaded_blocks)
void Map::deleteSectors(std::vector<v2s16> &sectorList) void Map::deleteSectors(std::vector<v2s16> &sectorList)
{ {
for(std::vector<v2s16>::iterator j = sectorList.begin(); for (v2s16 j : sectorList) {
j != sectorList.end(); ++j) { MapSector *sector = m_sectors[j];
MapSector *sector = m_sectors[*j];
// If sector is in sector cache, remove it from there // If sector is in sector cache, remove it from there
if(m_sector_cache == sector) if(m_sector_cache == sector)
m_sector_cache = NULL; m_sector_cache = NULL;
// Remove from map and delete // Remove from map and delete
m_sectors.erase(*j); m_sectors.erase(j);
delete sector; delete sector;
} }
} }
@ -1724,7 +1723,7 @@ MapBlock * ServerMap::emergeBlock(v3s16 p, bool create_blank)
{ {
MapBlock *block = getBlockNoCreateNoEx(p); MapBlock *block = getBlockNoCreateNoEx(p);
if(block && block->isDummy() == false) if (block && !block->isDummy())
return block; return block;
} }
@ -1855,8 +1854,7 @@ bool ServerMap::loadFromFolders() {
void ServerMap::createDirs(std::string path) void ServerMap::createDirs(std::string path)
{ {
if(fs::CreateAllDirs(path) == false) if (!fs::CreateAllDirs(path)) {
{
m_dout<<"ServerMap: Failed to create directory " m_dout<<"ServerMap: Failed to create directory "
<<"\""<<path<<"\""<<std::endl; <<"\""<<path<<"\""<<std::endl;
throw BaseException("ServerMap failed to create directory"); throw BaseException("ServerMap failed to create directory");
@ -1940,7 +1938,7 @@ std::string ServerMap::getBlockFilename(v3s16 p)
void ServerMap::save(ModifiedState save_level) void ServerMap::save(ModifiedState save_level)
{ {
DSTACK(FUNCTION_NAME); DSTACK(FUNCTION_NAME);
if(m_map_saving_enabled == false) { if (!m_map_saving_enabled) {
warningstream<<"Not saving map, saving disabled."<<std::endl; warningstream<<"Not saving map, saving disabled."<<std::endl;
return; return;
} }
@ -2081,8 +2079,7 @@ MapSector* ServerMap::loadSectorMeta(std::string sectordir, bool save_after_load
std::string fullpath = sectordir + DIR_DELIM + "meta"; std::string fullpath = sectordir + DIR_DELIM + "meta";
std::ifstream is(fullpath.c_str(), std::ios_base::binary); 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 // If the directory exists anyway, it probably is in some old
// format. Just go ahead and create the sector. // format. Just go ahead and create the sector.
if(fs::PathExists(sectordir)) if(fs::PathExists(sectordir))
@ -2494,7 +2491,7 @@ MapBlock* ServerMap::loadBlock(v3s16 blockpos)
*/ */
std::string blockfilename = getBlockFilename(blockpos); std::string blockfilename = getBlockFilename(blockpos);
if (fs::PathExists(sectordir + DIR_DELIM + blockfilename) == false) if (!fs::PathExists(sectordir + DIR_DELIM + blockfilename))
return NULL; return NULL;
/* /*
@ -2667,8 +2664,8 @@ void MMVManip::blitBackAll(std::map<v3s16, MapBlock*> *modified_blocks,
v3s16 p = i->first; v3s16 p = i->first;
MapBlock *block = m_map->getBlockNoCreateNoEx(p); MapBlock *block = m_map->getBlockNoCreateNoEx(p);
bool existed = !(i->second & VMANIP_BLOCK_DATA_INEXIST); bool existed = !(i->second & VMANIP_BLOCK_DATA_INEXIST);
if ((existed == false) || (block == NULL) || if (!existed || (block == NULL) ||
(overwrite_generated == false && block->isGenerated() == true)) (!overwrite_generated && block->isGenerated()))
continue; continue;
block->copyFrom(*this); block->copyFrom(*this);

@ -77,7 +77,7 @@ struct MapEditEvent
std::set<v3s16> modified_blocks; std::set<v3s16> modified_blocks;
u16 already_known_by_peer = 0; u16 already_known_by_peer = 0;
MapEditEvent() {} MapEditEvent() = default;
MapEditEvent * clone() MapEditEvent * clone()
{ {
@ -107,11 +107,7 @@ struct MapEditEvent
case MEET_OTHER: case MEET_OTHER:
{ {
VoxelArea a; VoxelArea a;
for(std::set<v3s16>::iterator for (v3s16 p : modified_blocks) {
i = modified_blocks.begin();
i != modified_blocks.end(); ++i)
{
v3s16 p = *i;
v3s16 np1 = p*MAP_BLOCKSIZE; v3s16 np1 = p*MAP_BLOCKSIZE;
v3s16 np2 = np1 + v3s16(1,1,1)*MAP_BLOCKSIZE - v3s16(1,1,1); v3s16 np2 = np1 + v3s16(1,1,1)*MAP_BLOCKSIZE - v3s16(1,1,1);
a.addPoint(np1); a.addPoint(np1);
@ -216,8 +212,8 @@ public:
bool removeNodeWithEvent(v3s16 p); bool removeNodeWithEvent(v3s16 p);
// Call these before and after saving of many blocks // Call these before and after saving of many blocks
virtual void beginSave() { return; } virtual void beginSave() {}
virtual void endSave() { return; } virtual void endSave() {}
virtual void save(ModifiedState save_level) { FATAL_ERROR("FIXME"); } virtual void save(ModifiedState save_level) { FATAL_ERROR("FIXME"); }

@ -71,7 +71,7 @@ MapBlock::MapBlock(Map *parent, v3s16 pos, IGameDef *gamedef, bool dummy):
m_pos_relative(pos * MAP_BLOCKSIZE), m_pos_relative(pos * MAP_BLOCKSIZE),
m_gamedef(gamedef) m_gamedef(gamedef)
{ {
if(dummy == false) if (!dummy)
reallocate(); reallocate();
} }
@ -89,24 +89,22 @@ MapBlock::~MapBlock()
bool MapBlock::isValidPositionParent(v3s16 p) bool MapBlock::isValidPositionParent(v3s16 p)
{ {
if(isValidPosition(p)) if (isValidPosition(p)) {
{
return true; return true;
} }
else{
return m_parent->isValidPosition(getPosRelative() + p); return m_parent->isValidPosition(getPosRelative() + p);
}
} }
MapNode MapBlock::getNodeParent(v3s16 p, bool *is_valid_position) 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); return m_parent->getNodeNoEx(getPosRelative() + p, is_valid_position);
if (!data) { if (!data) {
if (is_valid_position) if (is_valid_position)
*is_valid_position = false; *is_valid_position = false;
return MapNode(CONTENT_IGNORE); return {CONTENT_IGNORE};
} }
if (is_valid_position) if (is_valid_position)
*is_valid_position = true; *is_valid_position = true;
@ -201,8 +199,7 @@ bool MapBlock::propagateSunlight(std::set<v3s16> & light_sources,
else else
{ {
MapNode n = getNodeNoEx(v3s16(x, MAP_BLOCKSIZE-1, z)); 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; no_sunlight = true;
} }
} }
@ -423,12 +420,11 @@ s16 MapBlock::getGroundLevel(v2s16 p2d)
for(; y>=0; y--) for(; y>=0; y--)
{ {
MapNode n = getNodeRef(p2d.X, y, p2d.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) if(y == MAP_BLOCKSIZE-1)
return -2; return -2;
else
return y; return y;
} }
} }
return -1; return -1;
@ -481,11 +477,9 @@ static void getBlockNodeIdMapping(NameIdMapping *nimap, MapNode *nodes,
// Update the MapNode // Update the MapNode
nodes[i].setContent(id); nodes[i].setContent(id);
} }
for(std::set<content_t>::const_iterator for (u16 unknown_content : unknown_contents) {
i = unknown_contents.begin(); errorstream << "getBlockNodeIdMapping(): IGNORING ERROR: "
i != unknown_contents.end(); ++i){ << "Name for node id " << unknown_content << " not known" << std::endl;
errorstream<<"getBlockNodeIdMapping(): IGNORING ERROR: "
<<"Name for node id "<<(*i)<<" not known"<<std::endl;
} }
} }
// Correct ids in the block to match nodedef based on names. // Correct ids in the block to match nodedef based on names.

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

@ -59,7 +59,7 @@ struct MapgenCarpathianParams : public MapgenParams
NoiseParams np_cavern; NoiseParams np_cavern;
MapgenCarpathianParams(); MapgenCarpathianParams();
~MapgenCarpathianParams() {} ~MapgenCarpathianParams() = default;
void readParams(const Settings *settings); void readParams(const Settings *settings);
void writeParams(Settings *settings) const; void writeParams(Settings *settings) const;

@ -148,10 +148,11 @@ int MapgenFlat::getSpawnLevelAtPoint(v2s16 p)
if (ground_level < water_level) // Ocean world, allow spawn in water if (ground_level < water_level) // Ocean world, allow spawn in water
return MYMAX(level_at_point, water_level); 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 return level_at_point; // Spawn on land
else
return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point
} }

@ -50,7 +50,7 @@ struct MapgenFractalParams : public MapgenParams
NoiseParams np_cave2; NoiseParams np_cave2;
MapgenFractalParams(); MapgenFractalParams();
~MapgenFractalParams() {} ~MapgenFractalParams() = default;
void readParams(const Settings *settings); void readParams(const Settings *settings);
void writeParams(Settings *settings) const; void writeParams(Settings *settings) const;

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

@ -25,8 +25,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
struct MapgenSinglenodeParams : public MapgenParams struct MapgenSinglenodeParams : public MapgenParams
{ {
MapgenSinglenodeParams() {} MapgenSinglenodeParams() = default;
~MapgenSinglenodeParams() {} ~MapgenSinglenodeParams() = default;
void readParams(const Settings *settings) {} void readParams(const Settings *settings) {}
void writeParams(Settings *settings) const {} void writeParams(Settings *settings) const {}
@ -40,7 +40,7 @@ public:
u8 set_light; u8 set_light;
MapgenSinglenode(int mapgenid, MapgenParams *params, EmergeManager *emerge); MapgenSinglenode(int mapgenid, MapgenParams *params, EmergeManager *emerge);
~MapgenSinglenode(); ~MapgenSinglenode() = default;
virtual MapgenType getType() const { return MAPGEN_SINGLENODE; } virtual MapgenType getType() const { return MAPGEN_SINGLENODE; }

@ -156,9 +156,9 @@ int MapgenV5::getSpawnLevelAtPoint(v2s16 p)
if (n_ground * f > y - h) { // If solid if (n_ground * f > y - h) { // If solid
if (y < water_level || y > max_spawn_y) if (y < water_level || y > max_spawn_y)
return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point
else
// y + 2 because y is surface and due to biome 'dust' nodes. // y + 2 because y is surface and due to biome 'dust' nodes.
return y + 2; return y + 2;
} }
} }
// Unsuitable spawn position, no ground found // Unsuitable spawn position, no ground found

@ -233,8 +233,8 @@ bool MapgenV6::block_is_underground(u64 seed, v3s16 blockpos)
if(blockpos.Y * MAP_BLOCKSIZE + MAP_BLOCKSIZE <= minimum_groundlevel) if(blockpos.Y * MAP_BLOCKSIZE + MAP_BLOCKSIZE <= minimum_groundlevel)
return true; return true;
else
return false; return false;
} }
@ -327,8 +327,8 @@ int MapgenV6::getSpawnLevelAtPoint(v2s16 p)
if (level_at_point <= water_level || if (level_at_point <= water_level ||
level_at_point > water_level + 16) level_at_point > water_level + 16)
return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point 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; float zeroval = -0.39;
if (noise < zeroval) if (noise < zeroval)
return 0; 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 (d > MGV6_FREQ_HOT + blend) {
if (h > MGV6_FREQ_JUNGLE + blend) if (h > MGV6_FREQ_JUNGLE + blend)
return BT_JUNGLE; return BT_JUNGLE;
else
return BT_DESERT; return BT_DESERT;
} else if (d < MGV6_FREQ_SNOW + blend) { }
if (d < MGV6_FREQ_SNOW + blend) {
if (h > MGV6_FREQ_TAIGA + blend) if (h > MGV6_FREQ_TAIGA + blend)
return BT_TAIGA; return BT_TAIGA;
else
return BT_TUNDRA; return BT_TUNDRA;
} else {
return BT_NORMAL;
} }
return BT_NORMAL;
} else { } else {
if (d > freq_desert) if (d > freq_desert)
return BT_DESERT; return BT_DESERT;
@ -463,8 +465,8 @@ BiomeV6Type MapgenV6::getBiome(int index, v2s16 p)
if ((spflags & MGV6_JUNGLES) && h > 0.75) if ((spflags & MGV6_JUNGLES) && h > 0.75)
return BT_JUNGLE; 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; u32 i2 = i;
vm->m_area.add_y(em, i2, -1); vm->m_area.add_y(em, i2, -1);
// Cancel if out of area // Cancel if out of area
if (vm->m_area.contains(i2) == false) if (!vm->m_area.contains(i2))
continue; continue;
MapNode *n2 = &vm->m_data[i2]; MapNode *n2 = &vm->m_data[i2];
if (n2->getContent() != c_dirt && if (n2->getContent() != c_dirt &&
@ -847,13 +849,12 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos)
} }
// Drop mud on side // Drop mud on side
for (u32 di = 0; di < 4; di++) { for (const v3s16 &dirp : dirs4) {
v3s16 dirp = dirs4[di];
u32 i2 = i; u32 i2 = i;
// Move to side // Move to side
vm->m_area.add_p(em, i2, dirp); vm->m_area.add_p(em, i2, dirp);
// Fail if out of area // Fail if out of area
if (vm->m_area.contains(i2) == false) if (!vm->m_area.contains(i2))
continue; continue;
// Check that side is air // Check that side is air
MapNode *n2 = &vm->m_data[i2]; MapNode *n2 = &vm->m_data[i2];
@ -861,7 +862,7 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos)
continue; continue;
// Check that under side is air // Check that under side is air
vm->m_area.add_y(em, i2, -1); vm->m_area.add_y(em, i2, -1);
if (vm->m_area.contains(i2) == false) if (!vm->m_area.contains(i2))
continue; continue;
n2 = &vm->m_data[i2]; n2 = &vm->m_data[i2];
if (ndef->get(*n2).walkable) 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); vm->m_area.add_y(em, i2, -1);
n2 = &vm->m_data[i2]; n2 = &vm->m_data[i2];
// if out of known area // if out of known area
if (vm->m_area.contains(i2) == false || if (!vm->m_area.contains(i2) ||
n2->getContent() == CONTENT_IGNORE) { n2->getContent() == CONTENT_IGNORE) {
dropped_to_unknown = true; dropped_to_unknown = true;
break; break;
} }
} while (ndef->get(*n2).walkable == false); } while (!ndef->get(*n2).walkable);
// Loop one up so that we're in air // Loop one up so that we're in air
vm->m_area.add_y(em, i2, 1); vm->m_area.add_y(em, i2, 1);

@ -72,7 +72,7 @@ struct MapgenV6Params : public MapgenParams {
NoiseParams np_apple_trees; NoiseParams np_apple_trees;
MapgenV6Params(); MapgenV6Params();
~MapgenV6Params() {} ~MapgenV6Params() = default;
void readParams(const Settings *settings); void readParams(const Settings *settings);
void writeParams(Settings *settings) const; void writeParams(Settings *settings) const;

@ -240,9 +240,9 @@ int MapgenV7::getSpawnLevelAtPoint(v2s16 p)
if (!(spflags & MGV7_MOUNTAINS)) { if (!(spflags & MGV7_MOUNTAINS)) {
if (y < water_level || y > max_spawn_y) if (y < water_level || y > max_spawn_y)
return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point
else
// y + 2 because y is surface level and due to biome 'dust' // y + 2 because y is surface level and due to biome 'dust'
return y + 2; return y + 2;
} }
// Search upwards for first node without mountain terrain // 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 (!getMountainTerrainAtPoint(p.X, y + 1, p.Y)) {
if (y <= water_level || y > max_spawn_y) if (y <= water_level || y > max_spawn_y)
return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point
else
// y + 1 due to biome 'dust' // y + 1 due to biome 'dust'
return y + 1; return y + 1;
} }
y++; y++;
iters--; iters--;

@ -65,7 +65,7 @@ struct MapgenV7Params : public MapgenParams {
NoiseParams np_cave2; NoiseParams np_cave2;
MapgenV7Params(); MapgenV7Params();
~MapgenV7Params() {} ~MapgenV7Params() = default;
void readParams(const Settings *settings); void readParams(const Settings *settings);
void writeParams(Settings *settings) const; void writeParams(Settings *settings) const;

@ -435,8 +435,8 @@ int MapgenValleys::getSpawnLevelAtPoint(v2s16 p)
if (level_at_point <= water_level || if (level_at_point <= water_level ||
level_at_point > water_level + 32) level_at_point > water_level + 32)
return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point 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. // Saves some time.
if (y > terrain + 10) if (y > terrain + 10)
continue; continue;
else if (y < terrain - 40)
if (y < terrain - 40)
underground = true; underground = true;
// Dig massive caves. // Dig massive caves.

@ -66,7 +66,7 @@ struct MapgenValleysParams : public MapgenParams {
NoiseParams np_valley_profile; NoiseParams np_valley_profile;
MapgenValleysParams(); MapgenValleysParams();
~MapgenValleysParams() {} ~MapgenValleysParams() = default;
void readParams(const Settings *settings); void readParams(const Settings *settings);
void writeParams(Settings *settings) const; void writeParams(Settings *settings) const;

@ -249,18 +249,12 @@ void transformNodeBox(const MapNode &n, const NodeBox &nodebox,
int facedir = n.getFaceDir(nodemgr); int facedir = n.getFaceDir(nodemgr);
u8 axisdir = facedir>>2; u8 axisdir = facedir>>2;
facedir&=0x03; facedir&=0x03;
for(std::vector<aabb3f>::const_iterator for (aabb3f box : fixed) {
i = fixed.begin();
i != fixed.end(); ++i)
{
aabb3f box = *i;
if (nodebox.type == NODEBOX_LEVELED) { if (nodebox.type == NODEBOX_LEVELED) {
box.MaxEdge.Y = -BS/2 + BS*((float)1/LEVELED_MAX) * n.getLevel(nodemgr); box.MaxEdge.Y = -BS/2 + BS*((float)1/LEVELED_MAX) * n.getLevel(nodemgr);
} }
switch (axisdir) switch (axisdir) {
{
case 0: case 0:
if(facedir == 1) if(facedir == 1)
{ {
@ -403,16 +397,15 @@ void transformNodeBox(const MapNode &n, const NodeBox &nodebox,
nodebox.wall_side.MaxEdge nodebox.wall_side.MaxEdge
}; };
for(s32 i=0; i<2; i++) for (v3f &vertice : vertices) {
{
if(dir == v3s16(-1,0,0)) if(dir == v3s16(-1,0,0))
vertices[i].rotateXZBy(0); vertice.rotateXZBy(0);
if(dir == v3s16(1,0,0)) if(dir == v3s16(1,0,0))
vertices[i].rotateXZBy(180); vertice.rotateXZBy(180);
if(dir == v3s16(0,0,-1)) if(dir == v3s16(0,0,-1))
vertices[i].rotateXZBy(90); vertice.rotateXZBy(90);
if(dir == v3s16(0,0,1)) if(dir == v3s16(0,0,1))
vertices[i].rotateXZBy(-90); vertice.rotateXZBy(-90);
} }
aabb3f box = aabb3f(vertices[0]); aabb3f box = aabb3f(vertices[0]);
@ -467,7 +460,7 @@ void transformNodeBox(const MapNode &n, const NodeBox &nodebox,
} }
static inline void getNeighborConnectingFace( static inline void getNeighborConnectingFace(
v3s16 p, INodeDefManager *nodedef, const v3s16 &p, INodeDefManager *nodedef,
Map *map, MapNode n, u8 bitmask, u8 *neighbors) Map *map, MapNode n, u8 bitmask, u8 *neighbors)
{ {
MapNode n2 = map->getNodeNoEx(p); MapNode n2 = map->getNodeNoEx(p);
@ -605,14 +598,16 @@ u32 MapNode::serializedLength(u8 version)
if(!ser_ver_supported(version)) if(!ser_ver_supported(version))
throw VersionMismatchException("ERROR: MapNode format not supported"); throw VersionMismatchException("ERROR: MapNode format not supported");
if(version == 0) if (version == 0)
return 1; return 1;
else if(version <= 9)
if (version <= 9)
return 2; return 2;
else if(version <= 23)
if (version <= 23)
return 3; return 3;
else
return 4; return 4;
} }
void MapNode::serialize(u8 *dest, u8 version) void MapNode::serialize(u8 *dest, u8 version)
{ {

@ -137,8 +137,7 @@ struct MapNode
*/ */
u8 param2; u8 param2;
MapNode() MapNode() = default;
{ }
MapNode(content_t content, u8 a_param1=0, u8 a_param2=0) MapNode(content_t content, u8 a_param1=0, u8 a_param2=0)
: param0(content), : param0(content),

@ -40,9 +40,8 @@ void MapSector::deleteBlocks()
m_block_cache = nullptr; m_block_cache = nullptr;
// Delete all // Delete all
for (std::unordered_map<s16, MapBlock*>::iterator i = m_blocks.begin(); for (auto &block : m_blocks) {
i != m_blocks.end(); ++i) { delete block.second;
delete i->second;
} }
// Clear container // Clear container
@ -125,9 +124,8 @@ void MapSector::deleteBlock(MapBlock *block)
void MapSector::getBlocks(MapBlockVect &dest) void MapSector::getBlocks(MapBlockVect &dest)
{ {
for (std::unordered_map<s16, MapBlock*>::iterator bi = m_blocks.begin(); for (auto &block : m_blocks) {
bi != m_blocks.end(); ++bi) { dest.push_back(block.second);
dest.push_back(bi->second);
} }
} }
@ -140,10 +138,6 @@ ServerMapSector::ServerMapSector(Map *parent, v2s16 pos, IGameDef *gamedef):
{ {
} }
ServerMapSector::~ServerMapSector()
{
}
void ServerMapSector::serialize(std::ostream &os, u8 version) void ServerMapSector::serialize(std::ostream &os, u8 version)
{ {
if(!ser_ver_supported(version)) if(!ser_ver_supported(version))
@ -212,11 +206,9 @@ ServerMapSector* ServerMapSector::deSerialize(
assert(sector->getId() == MAPSECTOR_SERVER); assert(sector->getId() == MAPSECTOR_SERVER);
return (ServerMapSector*)sector; return (ServerMapSector*)sector;
} }
else
{ sector = new ServerMapSector(parent, p2d, gamedef);
sector = new ServerMapSector(parent, p2d, gamedef); sectors[p2d] = sector;
sectors[p2d] = sector;
}
/* /*
Set stuff in sector Set stuff in sector
@ -236,11 +228,6 @@ ClientMapSector::ClientMapSector(Map *parent, v2s16 pos, IGameDef *gamedef):
MapSector(parent, pos, gamedef) MapSector(parent, pos, gamedef)
{ {
} }
ClientMapSector::~ClientMapSector()
{
}
#endif // !SERVER #endif // !SERVER
//END //END

@ -94,7 +94,7 @@ class ServerMapSector : public MapSector
{ {
public: public:
ServerMapSector(Map *parent, v2s16 pos, IGameDef *gamedef); ServerMapSector(Map *parent, v2s16 pos, IGameDef *gamedef);
~ServerMapSector(); ~ServerMapSector() = default;
u32 getId() const u32 getId() const
{ {
@ -124,7 +124,7 @@ class ClientMapSector : public MapSector
{ {
public: public:
ClientMapSector(Map *parent, v2s16 pos, IGameDef *gamedef); ClientMapSector(Map *parent, v2s16 pos, IGameDef *gamedef);
~ClientMapSector(); ~ClientMapSector() = default;
u32 getId() const u32 getId() const
{ {

@ -453,11 +453,7 @@ scene::IMesh* convertNodeboxesToMesh(const std::vector<aabb3f> &boxes,
video::SColor c(255,255,255,255); video::SColor c(255,255,255,255);
for (std::vector<aabb3f>::const_iterator for (aabb3f box : boxes) {
i = boxes.begin();
i != boxes.end(); ++i)
{
aabb3f box = *i;
box.repair(); box.repair();
box.MinEdge.X -= expand; box.MinEdge.X -= expand;
@ -614,9 +610,8 @@ class f_lru
public: public:
f_lru(vcache *v, tcache *t): vc(v), tc(t) f_lru(vcache *v, tcache *t): vc(v), tc(t)
{ {
for (u16 i = 0; i < cachesize; i++) for (int &i : cache) {
{ i = -1;
cache[i] = -1;
} }
} }
@ -671,15 +666,14 @@ public:
} }
// Update triangle scores // Update triangle scores
for (u16 i = 0; i < cachesize; i++) for (int i : cache) {
{ if (i == -1)
if (cache[i] == -1)
break; break;
const u16 trisize = vc[cache[i]].tris.size(); const u16 trisize = vc[i].tris.size();
for (u16 t = 0; t < trisize; t++) for (u16 t = 0; t < trisize; t++)
{ {
tcache *tri = &tc[vc[cache[i]].tris[t]]; tcache *tri = &tc[vc[i].tris[t]];
tri->score = tri->score =
vc[tri->ind[0]].score + vc[tri->ind[0]].score +
@ -689,7 +683,7 @@ public:
if (tri->score > hiscore) if (tri->score > hiscore)
{ {
hiscore = tri->score; 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; tc[highest].drawn = true;
for (u16 j = 0; j < 3; j++) for (u16 j : tc[highest].ind) {
{ vcache *vert = &vc[j];
vcache *vert = &vc[tc[highest].ind[j]];
for (u16 t = 0; t < vert->tris.size(); t++) for (u16 t = 0; t < vert->tris.size(); t++)
{ {
if (highest == vert->tris[t]) if (highest == vert->tris[t])
@ -988,9 +981,8 @@ scene::IMesh* createForsythOptimizedMesh(const scene::IMesh *mesh)
tc[highest].drawn = true; tc[highest].drawn = true;
for (u16 j = 0; j < 3; j++) for (u16 j : tc[highest].ind) {
{ vcache *vert = &vc[j];
vcache *vert = &vc[tc[highest].ind[j]];
for (u16 t = 0; t < vert->tris.size(); t++) for (u16 t = 0; t < vert->tris.size(); t++)
{ {
if (highest == vert->tris[t]) if (highest == vert->tris[t])
@ -1101,9 +1093,8 @@ scene::IMesh* createForsythOptimizedMesh(const scene::IMesh *mesh)
tc[highest].drawn = true; tc[highest].drawn = true;
for (u16 j = 0; j < 3; j++) for (u16 j : tc[highest].ind) {
{ vcache *vert = &vc[j];
vcache *vert = &vc[tc[highest].ind[j]];
for (u16 t = 0; t < vert->tris.size(); t++) for (u16 t = 0; t < vert->tris.size(); t++)
{ {
if (highest == vert->tris[t]) if (highest == vert->tris[t])

@ -63,14 +63,11 @@ MeshUpdateQueue::~MeshUpdateQueue()
{ {
MutexAutoLock lock(m_mutex); MutexAutoLock lock(m_mutex);
for (std::map<v3s16, CachedMapBlockData *>::iterator i = m_cache.begin(); for (auto &i : m_cache) {
i != m_cache.end(); ++i) { delete i.second;
delete i->second;
} }
for (std::vector<QueuedMeshUpdate*>::iterator i = m_queue.begin(); for (QueuedMeshUpdate *q : m_queue) {
i != m_queue.end(); ++i) {
QueuedMeshUpdate *q = *i;
delete q; 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. Find if block is already in queue.
If it is, update the data and quit. If it is, update the data and quit.
*/ */
for (std::vector<QueuedMeshUpdate*>::iterator i = m_queue.begin(); for (QueuedMeshUpdate *q : m_queue) {
i != m_queue.end(); ++i) {
QueuedMeshUpdate *q = *i;
if (q->p == p) { if (q->p == p) {
// NOTE: We are not adding a new position to the queue, thus // NOTE: We are not adding a new position to the queue, thus
// refcount_from_queue stays the same. // 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); m_queue.push_back(q);
// This queue entry is a new reference to the cached blocks // This queue entry is a new reference to the cached blocks
for (size_t i=0; i<cached_blocks.size(); i++) { for (CachedMapBlockData *cached_block : cached_blocks) {
cached_blocks[i]->refcount_from_queue++; cached_block->refcount_from_queue++;
} }
} }
@ -191,19 +186,19 @@ CachedMapBlockData* MeshUpdateQueue::cacheBlock(Map *map, v3s16 p, UpdateMode mo
cached_block->data = NULL; cached_block->data = NULL;
} }
return cached_block; 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) CachedMapBlockData* MeshUpdateQueue::getCachedBlock(const v3s16 &p)

@ -51,25 +51,20 @@ BiomeManager::BiomeManager(Server *server) :
b->heat_point = 0.0; b->heat_point = 0.0;
b->humidity_point = 0.0; b->humidity_point = 0.0;
b->m_nodenames.push_back("mapgen_stone"); b->m_nodenames.emplace_back("mapgen_stone");
b->m_nodenames.push_back("mapgen_stone"); b->m_nodenames.emplace_back("mapgen_stone");
b->m_nodenames.push_back("mapgen_stone"); b->m_nodenames.emplace_back("mapgen_stone");
b->m_nodenames.push_back("mapgen_water_source"); b->m_nodenames.emplace_back("mapgen_water_source");
b->m_nodenames.push_back("mapgen_water_source"); b->m_nodenames.emplace_back("mapgen_water_source");
b->m_nodenames.push_back("mapgen_river_water_source"); b->m_nodenames.emplace_back("mapgen_river_water_source");
b->m_nodenames.push_back("mapgen_stone"); b->m_nodenames.emplace_back("mapgen_stone");
b->m_nodenames.push_back("ignore"); b->m_nodenames.emplace_back("ignore");
m_ndef->pendNodeResolve(b); m_ndef->pendNodeResolve(b);
add(b); add(b);
} }
BiomeManager::~BiomeManager()
{
}
void BiomeManager::clear() void BiomeManager::clear()
{ {
EmergeManager *emerge = m_server->getEmergeManager(); EmergeManager *emerge = m_server->getEmergeManager();

@ -83,14 +83,15 @@ enum BiomeGenType {
struct BiomeParams { struct BiomeParams {
virtual void readParams(const Settings *settings) = 0; virtual void readParams(const Settings *settings) = 0;
virtual void writeParams(Settings *settings) const = 0; virtual void writeParams(Settings *settings) const = 0;
virtual ~BiomeParams() {} virtual ~BiomeParams() = default;
s32 seed; s32 seed;
}; };
class BiomeGen { class BiomeGen {
public: public:
virtual ~BiomeGen() {} virtual ~BiomeGen() = default;
virtual BiomeGenType getType() const = 0; virtual BiomeGenType getType() const = 0;
// Calculates the biome at the exact position provided. This function can // Calculates the biome at the exact position provided. This function can
@ -188,7 +189,7 @@ private:
class BiomeManager : public ObjDefManager { class BiomeManager : public ObjDefManager {
public: public:
BiomeManager(Server *server); BiomeManager(Server *server);
virtual ~BiomeManager(); virtual ~BiomeManager() = default;
const char *getObjectTitle() const const char *getObjectTitle() const
{ {

@ -63,8 +63,8 @@ struct CutoffData {
class Decoration : public ObjDef, public NodeResolver { class Decoration : public ObjDef, public NodeResolver {
public: public:
Decoration() {}; Decoration() = default;
virtual ~Decoration() {}; virtual ~Decoration() = default;
virtual void resolveNodeNames(); virtual void resolveNodeNames();
@ -104,7 +104,7 @@ public:
class DecoSchematic : public Decoration { class DecoSchematic : public Decoration {
public: public:
DecoSchematic() {}; DecoSchematic() = default;
virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p); virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p);
virtual int getHeight(); virtual int getHeight();
@ -124,7 +124,7 @@ public:
class DecorationManager : public ObjDefManager { class DecorationManager : public ObjDefManager {
public: public:
DecorationManager(IGameDef *gamedef); DecorationManager(IGameDef *gamedef);
virtual ~DecorationManager() {} virtual ~DecorationManager() = default;
const char *getObjectTitle() const const char *getObjectTitle() const
{ {

@ -64,8 +64,8 @@ size_t OreManager::placeAllOres(Mapgen *mg, u32 blockseed,
void OreManager::clear() void OreManager::clear()
{ {
for (size_t i = 0; i < m_objects.size(); i++) { for (ObjDef *object : m_objects) {
Ore *ore = (Ore *)m_objects[i]; Ore *ore = (Ore *) object;
delete ore; delete ore;
} }
m_objects.clear(); m_objects.clear();
@ -221,13 +221,6 @@ void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed,
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
OrePuff::OrePuff() :
Ore()
{
}
OrePuff::~OrePuff() OrePuff::~OrePuff()
{ {
delete noise_puff_top; delete noise_puff_top;
@ -372,13 +365,6 @@ void OreBlob::generate(MMVManip *vm, int mapseed, u32 blockseed,
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
OreVein::OreVein() :
Ore()
{
}
OreVein::~OreVein() OreVein::~OreVein()
{ {
delete noise2; delete noise2;

@ -104,7 +104,7 @@ public:
Noise *noise_puff_top = nullptr; Noise *noise_puff_top = nullptr;
Noise *noise_puff_bottom = nullptr; Noise *noise_puff_bottom = nullptr;
OrePuff(); OrePuff() = default;
virtual ~OrePuff(); virtual ~OrePuff();
virtual void generate(MMVManip *vm, int mapseed, u32 blockseed, virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
@ -126,7 +126,7 @@ public:
float random_factor; float random_factor;
Noise *noise2 = nullptr; Noise *noise2 = nullptr;
OreVein(); OreVein() = default;
virtual ~OreVein(); virtual ~OreVein();
virtual void generate(MMVManip *vm, int mapseed, u32 blockseed, virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,

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

@ -46,10 +46,7 @@ bool MinimapUpdateThread::pushBlockUpdate(v3s16 pos, MinimapMapblock *data)
// Find if block is already in queue. // Find if block is already in queue.
// If it is, update the data and quit. // If it is, update the data and quit.
for (std::deque<QueuedMinimapUpdate>::iterator for (QueuedMinimapUpdate &q : m_update_queue) {
it = m_update_queue.begin();
it != m_update_queue.end(); ++it) {
QueuedMinimapUpdate &q = *it;
if (q.pos == pos) { if (q.pos == pos) {
delete q.data; delete q.data;
q.data = data; q.data = data;
@ -277,9 +274,9 @@ MinimapShape Minimap::getMinimapShape()
{ {
if (data->minimap_shape_round) { if (data->minimap_shape_round) {
return MINIMAP_SHAPE_ROUND; return MINIMAP_SHAPE_ROUND;
} else {
return MINIMAP_SHAPE_SQUARE;
} }
return MINIMAP_SHAPE_SQUARE;
} }
void Minimap::setMinimapMode(MinimapMode mode) void Minimap::setMinimapMode(MinimapMode mode)
@ -434,9 +431,9 @@ v3f Minimap::getYawVec()
cos(m_angle * core::DEGTORAD), cos(m_angle * core::DEGTORAD),
sin(m_angle * core::DEGTORAD), sin(m_angle * core::DEGTORAD),
1.0); 1.0);
} else {
return v3f(1.0, 0.0, 1.0);
} }
return v3f(1.0, 0.0, 1.0);
} }
scene::SMeshBuffer *Minimap::getMinimapMeshBuffer() scene::SMeshBuffer *Minimap::getMinimapMeshBuffer()
@ -568,9 +565,8 @@ void Minimap::updateActiveMarkers()
m_active_markers.clear(); m_active_markers.clear();
for (std::list<Nametag *>::const_iterator i = nametags.begin(); for (Nametag *nametag : nametags) {
i != nametags.end(); ++i) { v3s16 pos = floatToInt(nametag->parent_node->getPosition() +
v3s16 pos = floatToInt((*i)->parent_node->getPosition() +
intToFloat(client->getCamera()->getOffset(), BS), BS); intToFloat(client->getCamera()->getOffset(), BS), BS);
pos -= data->pos - v3s16(data->map_size / 2, pos -= data->pos - v3s16(data->map_size / 2,
data->scan_height / 2, data->scan_height / 2,
@ -586,8 +582,9 @@ void Minimap::updateActiveMarkers()
if (!mask_col.getAlpha()) { if (!mask_col.getAlpha()) {
continue; 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);
} }
} }

@ -111,16 +111,12 @@ public:
{ {
const core::list<gui::IGUIElement*> &children = getChildren(); const core::list<gui::IGUIElement*> &children = getChildren();
core::list<gui::IGUIElement*> children_copy; core::list<gui::IGUIElement*> children_copy;
for(core::list<gui::IGUIElement*>::ConstIterator for (gui::IGUIElement *i : children) {
i = children.begin(); i != children.end(); i++) children_copy.push_back(i);
{
children_copy.push_back(*i);
} }
for(core::list<gui::IGUIElement*>::Iterator
i = children_copy.begin(); for (gui::IGUIElement *i : children_copy) {
i != children_copy.end(); i++) i->remove();
{
(*i)->remove();
} }
} }

@ -41,7 +41,7 @@ static bool parseDependsLine(std::istream &is,
--pos; --pos;
} }
dep = trim(dep.substr(0, pos)); dep = trim(dep.substr(0, pos));
return dep != ""; return !dep.empty();
} }
void parseModContents(ModSpec &spec) 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::map<std::string, ModSpec> result;
std::vector<fs::DirListNode> dirlist = fs::GetDirListing(path); std::vector<fs::DirListNode> dirlist = fs::GetDirListing(path);
for(u32 j=0; j<dirlist.size(); j++){ for (const fs::DirListNode &dln : dirlist) {
if(!dirlist[j].dir) if(!dln.dir)
continue; continue;
std::string modname = dirlist[j].name; const std::string &modname = dln.name;
// Ignore all directories beginning with a ".", especially // Ignore all directories beginning with a ".", especially
// VCS directories like ".git" or ".svn" // VCS directories like ".git" or ".svn"
if(modname[0] == '.') if (modname[0] == '.')
continue; continue;
std::string modpath = path + DIR_DELIM + modname; 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> flattenMods(std::map<std::string, ModSpec> mods)
{ {
std::vector<ModSpec> result; std::vector<ModSpec> result;
for(std::map<std::string,ModSpec>::iterator it = mods.begin(); for (const auto &it : mods) {
it != mods.end(); ++it) const ModSpec &mod = it.second;
{ if (mod.is_modpack) {
ModSpec mod = (*it).second;
if(mod.is_modpack)
{
std::vector<ModSpec> content = flattenMods(mod.modpack_content); std::vector<ModSpec> content = flattenMods(mod.modpack_content);
result.reserve(result.size() + content.size()); result.reserve(result.size() + content.size());
result.insert(result.end(),content.begin(),content.end()); result.insert(result.end(),content.begin(),content.end());
@ -131,23 +128,16 @@ std::vector<ModSpec> flattenMods(std::map<std::string, ModSpec> mods)
return result; return result;
} }
ModConfiguration::ModConfiguration(const std::string &worldpath): ModConfiguration::ModConfiguration(const std::string &worldpath)
m_unsatisfied_mods(),
m_sorted_mods(),
m_name_conflicts()
{ {
} }
void ModConfiguration::printUnsatisfiedModsError() const void ModConfiguration::printUnsatisfiedModsError() const
{ {
for (std::vector<ModSpec>::const_iterator it = m_unsatisfied_mods.begin(); for (const ModSpec &mod : m_unsatisfied_mods) {
it != m_unsatisfied_mods.end(); ++it) {
ModSpec mod = *it;
errorstream << "mod \"" << mod.name << "\" has unsatisfied dependencies: "; errorstream << "mod \"" << mod.name << "\" has unsatisfied dependencies: ";
for (std::unordered_set<std::string>::iterator dep_it = for (const std::string &unsatisfied_depend : mod.unsatisfied_depends)
mod.unsatisfied_depends.begin(); errorstream << " \"" << unsatisfied_depend << "\"";
dep_it != mod.unsatisfied_depends.end(); ++dep_it)
errorstream << " \"" << *dep_it << "\"";
errorstream << std::endl; errorstream << std::endl;
} }
} }
@ -175,17 +165,15 @@ void ModConfiguration::addMods(const std::vector<ModSpec> &new_mods)
std::set<std::string> seen_this_iteration; std::set<std::string> seen_this_iteration;
for (std::vector<ModSpec>::const_iterator it = new_mods.begin(); for (const ModSpec &mod : new_mods) {
it != new_mods.end(); ++it) { if (mod.part_of_modpack != (bool)want_from_modpack)
const ModSpec &mod = *it;
if(mod.part_of_modpack != (bool)want_from_modpack)
continue; continue;
if(existing_mods.count(mod.name) == 0){
if (existing_mods.count(mod.name) == 0) {
// GOOD CASE: completely new mod. // GOOD CASE: completely new mod.
m_unsatisfied_mods.push_back(mod); m_unsatisfied_mods.push_back(mod);
existing_mods[mod.name] = m_unsatisfied_mods.size() - 1; 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. // BAD CASE: name conflict in different levels.
u32 oldindex = existing_mods[mod.name]; u32 oldindex = existing_mods[mod.name];
const ModSpec &oldmod = m_unsatisfied_mods[oldindex]; 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 // If there was a "VERY BAD CASE" name conflict
// in an earlier level, ignore it. // in an earlier level, ignore it.
m_name_conflicts.erase(mod.name); m_name_conflicts.erase(mod.name);
} } else {
else{
// VERY BAD CASE: name conflict in the same level. // VERY BAD CASE: name conflict in the same level.
u32 oldindex = existing_mods[mod.name]; u32 oldindex = existing_mods[mod.name];
const ModSpec &oldmod = m_unsatisfied_mods[oldindex]; 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_unsatisfied_mods[oldindex] = mod;
m_name_conflicts.insert(mod.name); m_name_conflicts.insert(mod.name);
} }
seen_this_iteration.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()); conf.readConfigFile(settings_path.c_str());
std::vector<std::string> names = conf.getNames(); std::vector<std::string> names = conf.getNames();
for (std::vector<std::string>::iterator it = names.begin(); for (const std::string &name : names) {
it != names.end(); ++it) {
std::string name = *it;
if (name.compare(0,9,"load_mod_")==0 && conf.getBool(name)) if (name.compare(0,9,"load_mod_")==0 && conf.getBool(name))
load_mod_names.insert(name.substr(9)); load_mod_names.insert(name.substr(9));
} }
std::vector<ModSpec> addon_mods; std::vector<ModSpec> addon_mods;
for (std::set<std::string>::const_iterator i = mods.begin(); for (const std::string &i : mods) {
i != mods.end(); ++i) { std::vector<ModSpec> addon_mods_in_path = flattenMods(getModsInPath(i));
std::vector<ModSpec> addon_mods_in_path = flattenMods(getModsInPath(*i));
for (std::vector<ModSpec>::const_iterator it = addon_mods_in_path.begin(); for (std::vector<ModSpec>::const_iterator it = addon_mods_in_path.begin();
it != addon_mods_in_path.end(); ++it) { it != addon_mods_in_path.end(); ++it) {
const ModSpec& mod = *it; const ModSpec& mod = *it;
@ -248,18 +233,18 @@ void ModConfiguration::addModsFormConfig(const std::string &settings_path, const
checkConflictsAndDeps(); checkConflictsAndDeps();
// complain about mods declared to be loaded, but not found // complain about mods declared to be loaded, but not found
for (std::vector<ModSpec>::iterator it = addon_mods.begin(); for (const ModSpec &addon_mod : addon_mods)
it != addon_mods.end(); ++it) load_mod_names.erase(addon_mod.name);
load_mod_names.erase((*it).name);
std::vector<ModSpec> UnsatisfiedMods = getUnsatisfiedMods(); std::vector<ModSpec> unsatisfiedMods = getUnsatisfiedMods();
for (std::vector<ModSpec>::iterator it = UnsatisfiedMods.begin();
it != UnsatisfiedMods.end(); ++it) for (const ModSpec &unsatisfiedMod : unsatisfiedMods)
load_mod_names.erase((*it).name); load_mod_names.erase(unsatisfiedMod.name);
if (!load_mod_names.empty()) { if (!load_mod_names.empty()) {
errorstream << "The following mods could not be found:"; errorstream << "The following mods could not be found:";
for (std::set<std::string>::iterator it = load_mod_names.begin(); for (const std::string &mod : load_mod_names)
it != load_mod_names.end(); ++it) errorstream << " \"" << mod << "\"";
errorstream << " \"" << (*it) << "\"";
errorstream << std::endl; errorstream << std::endl;
} }
} }
@ -286,23 +271,18 @@ void ModConfiguration::resolveDependencies()
{ {
// Step 1: Compile a list of the mod names we're working with // Step 1: Compile a list of the mod names we're working with
std::set<std::string> modnames; std::set<std::string> modnames;
for(std::vector<ModSpec>::iterator it = m_unsatisfied_mods.begin(); for (const ModSpec &mod : m_unsatisfied_mods) {
it != m_unsatisfied_mods.end(); ++it){ modnames.insert(mod.name);
modnames.insert((*it).name);
} }
// Step 2: get dependencies (including optional dependencies) // Step 2: get dependencies (including optional dependencies)
// of each mod, split mods into satisfied and unsatisfied // of each mod, split mods into satisfied and unsatisfied
std::list<ModSpec> satisfied; std::list<ModSpec> satisfied;
std::list<ModSpec> unsatisfied; std::list<ModSpec> unsatisfied;
for (std::vector<ModSpec>::iterator it = m_unsatisfied_mods.begin(); for (ModSpec mod : m_unsatisfied_mods) {
it != m_unsatisfied_mods.end(); ++it) {
ModSpec mod = *it;
mod.unsatisfied_depends = mod.depends; mod.unsatisfied_depends = mod.depends;
// check which optional dependencies actually exist // check which optional dependencies actually exist
for (std::unordered_set<std::string>::iterator it_optdep = mod.optdepends.begin(); for (const std::string &optdep : mod.optdepends) {
it_optdep != mod.optdepends.end(); ++it_optdep) {
std::string optdep = *it_optdep;
if (modnames.count(optdep) != 0) if (modnames.count(optdep) != 0)
mod.unsatisfied_depends.insert(optdep); mod.unsatisfied_depends.insert(optdep);
} }
@ -319,15 +299,13 @@ void ModConfiguration::resolveDependencies()
ModSpec mod = satisfied.back(); ModSpec mod = satisfied.back();
m_sorted_mods.push_back(mod); m_sorted_mods.push_back(mod);
satisfied.pop_back(); satisfied.pop_back();
for(std::list<ModSpec>::iterator it = unsatisfied.begin(); for (auto it = unsatisfied.begin(); it != unsatisfied.end(); ) {
it != unsatisfied.end(); ){
ModSpec& mod2 = *it; ModSpec& mod2 = *it;
mod2.unsatisfied_depends.erase(mod.name); mod2.unsatisfied_depends.erase(mod.name);
if(mod2.unsatisfied_depends.empty()){ if (mod2.unsatisfied_depends.empty()) {
satisfied.push_back(mod2); satisfied.push_back(mod2);
it = unsatisfied.erase(it); it = unsatisfied.erase(it);
} } else {
else{
++it; ++it;
} }
} }
@ -425,10 +403,9 @@ bool ModMetadata::load(const std::string &root_path)
} }
const Json::Value::Members attr_list = root.getMemberNames(); const Json::Value::Members attr_list = root.getMemberNames();
for (Json::Value::Members::const_iterator it = attr_list.begin(); for (const auto &it : attr_list) {
it != attr_list.end(); ++it) { Json::Value attr_value = root[it];
Json::Value attr_value = root[*it]; m_stringvars[it] = attr_value.asString();
m_stringvars[*it] = attr_value.asString();
} }
return true; return true;

@ -121,7 +121,7 @@ private:
std::unordered_set<std::string> m_name_conflicts; std::unordered_set<std::string> m_name_conflicts;
// Deleted default constructor // Deleted default constructor
ModConfiguration() {} ModConfiguration() = default;
}; };
@ -155,7 +155,7 @@ class ModMetadata: public Metadata
{ {
public: public:
ModMetadata(const std::string &mod_name); ModMetadata(const std::string &mod_name);
~ModMetadata() {} ~ModMetadata() = default;
virtual void clear(); virtual void clear();