Skip to content
Permalink
Browse files

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
  • Loading branch information
nerzhul committed Aug 18, 2017
1 parent fb196be commit c42753338924bb29c61081c9f269772f89bcd808
@@ -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")) {
@@ -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 @@ class MainMenuManager : public IMenuManager

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()
{
@@ -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);
@@ -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 @@ class Map /*: public NodeContainer*/
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"); }

0 comments on commit c427533

Please sign in to comment.