Skip to content

Commit d382483

Browse files
committedAug 19, 2017
Code modernization: src/m* (part 3)
* empty function * default constructor/destructor * for range-based loops * use emplace_back instead of push_back * remove some unused headers in some cpp variable
1 parent b5f7249 commit d382483

11 files changed

+20
-31
lines changed
 

‎src/map.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -1925,9 +1925,8 @@ void ServerMap::save(ModifiedState save_level)
19251925
// Don't do anything with sqlite unless something is really saved
19261926
bool save_started = false;
19271927

1928-
for(std::map<v2s16, MapSector*>::iterator i = m_sectors.begin();
1929-
i != m_sectors.end(); ++i) {
1930-
ServerMapSector *sector = (ServerMapSector*)i->second;
1928+
for (auto &sector_it : m_sectors) {
1929+
ServerMapSector *sector = (ServerMapSector*) sector_it.second;
19311930
assert(sector->getId() == MAPSECTOR_SERVER);
19321931

19331932
if(sector->differs_from_disk || save_level == MOD_STATE_CLEAN) {

‎src/mapgen_valleys.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3030
#include "mapblock.h"
3131
#include "mapnode.h"
3232
#include "map.h"
33-
#include "content_sao.h"
3433
#include "nodedef.h"
3534
#include "voxelalgorithms.h"
3635
#include "settings.h" // For g_settings

‎src/mapnode.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ void transformNodeBox(const MapNode &n, const NodeBox &nodebox,
455455
}
456456
else // NODEBOX_REGULAR
457457
{
458-
boxes.push_back(aabb3f(-BS/2,-BS/2,-BS/2,BS/2,BS/2,BS/2));
458+
boxes.emplace_back(-BS/2,-BS/2,-BS/2,BS/2,BS/2,BS/2);
459459
}
460460
}
461461

@@ -764,7 +764,7 @@ void MapNode::deSerializeBulk(std::istream &is, int version,
764764
/*
765765
Legacy serialization
766766
*/
767-
void MapNode::deSerialize_pre22(u8 *source, u8 version)
767+
void MapNode::deSerialize_pre22(const u8 *source, u8 version)
768768
{
769769
if(version <= 1)
770770
{

‎src/mapnode.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,5 +300,5 @@ struct MapNode
300300

301301
private:
302302
// Deprecated serialization methods
303-
void deSerialize_pre22(u8 *source, u8 version);
303+
void deSerialize_pre22(const u8 *source, u8 version);
304304
};

‎src/mesh_generator_thread.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct CachedMapBlockData
3232
int refcount_from_queue = 0;
3333
std::time_t last_used_timestamp = std::time(0);
3434

35-
CachedMapBlockData() {}
35+
CachedMapBlockData() = default;
3636
~CachedMapBlockData();
3737
};
3838

@@ -45,7 +45,7 @@ struct QueuedMeshUpdate
4545
v3s16 crack_pos;
4646
MeshMakeData *data = nullptr; // This is generated in MeshUpdateQueue::pop()
4747

48-
QueuedMeshUpdate(){};
48+
QueuedMeshUpdate() = default;
4949
~QueuedMeshUpdate();
5050
};
5151

@@ -105,7 +105,7 @@ struct MeshUpdateResult
105105
MapBlockMesh *mesh = nullptr;
106106
bool ack_block_to_server = false;
107107

108-
MeshUpdateResult() {}
108+
MeshUpdateResult() = default;
109109
};
110110

111111
class MeshUpdateThread : public UpdateThread

‎src/metadata.cpp

+6-12
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1818
*/
1919

2020
#include "metadata.h"
21-
#include "exceptions.h"
22-
#include "gamedef.h"
2321
#include "log.h"
24-
#include <sstream>
25-
#include "constants.h" // MAP_BLOCKSIZE
26-
#include <sstream>
2722

2823
/*
2924
Metadata
@@ -36,7 +31,7 @@ void Metadata::clear()
3631

3732
bool Metadata::empty() const
3833
{
39-
return m_stringvars.size() == 0;
34+
return m_stringvars.empty();
4035
}
4136

4237
size_t Metadata::size() const
@@ -54,10 +49,9 @@ bool Metadata::operator==(const Metadata &other) const
5449
if (size() != other.size())
5550
return false;
5651

57-
for (StringMap::const_iterator it = m_stringvars.begin();
58-
it != m_stringvars.end(); ++it) {
59-
if (!other.contains(it->first) ||
60-
other.getString(it->first) != it->second)
52+
for (const auto &sv : m_stringvars) {
53+
if (!other.contains(sv.first) ||
54+
other.getString(sv.first) != sv.second)
6155
return false;
6256
}
6357

@@ -102,7 +96,7 @@ const std::string &Metadata::resolveString(const std::string &str, u16 recursion
10296
{
10397
if (recursion <= 1 && str.substr(0, 2) == "${" && str[str.length() - 1] == '}') {
10498
return getString(str.substr(2, str.length() - 3), recursion + 1);
105-
} else {
106-
return str;
10799
}
100+
101+
return str;
108102
}

‎src/metadata.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2727
class Metadata
2828
{
2929
public:
30-
virtual ~Metadata() {}
30+
virtual ~Metadata() = default;
3131

3232
virtual void clear();
3333
virtual bool empty() const;

‎src/mg_ore.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Ore : public ObjDef, public NodeResolver {
6464
Noise *noise = nullptr;
6565
std::unordered_set<u8> biomes;
6666

67-
Ore() {};
67+
Ore() = default;;
6868
virtual ~Ore();
6969

7070
virtual void resolveNodeNames();
@@ -136,7 +136,7 @@ class OreVein : public Ore {
136136
class OreManager : public ObjDefManager {
137137
public:
138138
OreManager(IGameDef *gamedef);
139-
virtual ~OreManager() {}
139+
virtual ~OreManager() = default;
140140

141141
const char *getObjectTitle() const
142142
{

‎src/mg_schematic.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void SchematicManager::clear()
5656
DecoSchematic *dschem = dynamic_cast<DecoSchematic *>(deco);
5757
if (dschem)
5858
dschem->schematic = NULL;
59-
} catch (std::bad_cast) {
59+
} catch (const std::bad_cast &) {
6060
}
6161
}
6262

@@ -68,8 +68,7 @@ void SchematicManager::clear()
6868

6969

7070
Schematic::Schematic()
71-
{
72-
}
71+
= default;
7372

7473

7574
Schematic::~Schematic()

‎src/minimap.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ void MinimapUpdateThread::doUpdate()
115115

116116
void MinimapUpdateThread::getMap(v3s16 pos, s16 size, s16 height)
117117
{
118-
v3s16 region(size, 0, size);
119118
v3s16 pos_min(pos.X - size / 2, pos.Y - height / 2, pos.Z - size / 2);
120119
v3s16 pos_max(pos_min.X + size - 1, pos.Y + height / 2, pos_min.Z + size - 1);
121120
v3s16 blockpos_min = getNodeBlockPos(pos_min);

‎src/mods.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1919

2020
#include <cctype>
2121
#include <fstream>
22+
#include <json/json.h>
2223
#include "mods.h"
2324
#include "filesys.h"
2425
#include "log.h"
2526
#include "subgame.h"
2627
#include "settings.h"
27-
#include "convert_json.h"
28-
#include "exceptions.h"
2928
#include "porting.h"
3029

3130
static bool parseDependsLine(std::istream &is,

0 commit comments

Comments
 (0)
Please sign in to comment.