Code modernization: src/p*, src/q*, src/r*, src/s* (partial) (#6282)
authorLoïc Blot <nerzhul@users.noreply.github.com>
Sat, 19 Aug 2017 12:25:35 +0000 (14:25 +0200)
committerGitHub <noreply@github.com>
Sat, 19 Aug 2017 12:25:35 +0000 (14:25 +0200)
* Code modernization: src/p*, src/q*, src/r*, src/s* (partial)

* empty function
* default constructor/destructor
* for range-based loops
* use emplace_back instead of push_back
* C++ STL header style
* Spelling: vertice -> vertex

28 files changed:
src/content_mapblock.cpp
src/mapblock_mesh.cpp
src/mapnode.cpp
src/player.h
src/porting.cpp
src/porting.h
src/porting_android.cpp
src/profiler.h
src/quicktune.h
src/quicktune_shortcutter.h
src/raycast.cpp
src/remoteplayer.cpp
src/remoteplayer.h
src/rollback.cpp
src/rollback_interface.h
src/server.cpp
src/serverenvironment.cpp
src/serverenvironment.h
src/serverlist.cpp
src/serverobject.cpp
src/serverobject.h
src/settings.cpp
src/settings.h
src/shader.cpp
src/shader.h
src/sky.cpp
src/socket.h
src/sound_openal.cpp

index 87a1624b5e5879b2f1e2d43a534b9b035b6dfe22..577fbc5f8b575b2e4d770adfa9d32177f4b5e0b9 100644 (file)
@@ -582,9 +582,9 @@ void MapblockMeshGenerator::drawLiquidTop()
        tcoord_translate.X -= floor(tcoord_translate.X);
        tcoord_translate.Y -= floor(tcoord_translate.Y);
 
-       for (auto &vertice : vertices) {
-               vertice.TCoords.rotateBy(tcoord_angle, tcoord_center);
-               vertice.TCoords += tcoord_translate;
+       for (video::S3DVertex &vertex : vertices) {
+               vertex.TCoords.rotateBy(tcoord_angle, tcoord_center);
+               vertex.TCoords += tcoord_translate;
        }
 
        std::swap(vertices[0].TCoords, vertices[2].TCoords);
@@ -622,20 +622,20 @@ void MapblockMeshGenerator::drawGlasslikeNode()
                        v3f(-BS / 2, -BS / 2, -BS / 2),
                };
 
-               for (auto &vertice : vertices) {
+               for (v3f &vertex : vertices) {
                        switch (face) {
                                case D6D_ZP:
-                                       vertice.rotateXZBy(180); break;
+                                       vertex.rotateXZBy(180); break;
                                case D6D_YP:
-                                       vertice.rotateYZBy( 90); break;
+                                       vertex.rotateYZBy( 90); break;
                                case D6D_XP:
-                                       vertice.rotateXZBy( 90); break;
+                                       vertex.rotateXZBy( 90); break;
                                case D6D_ZN:
-                                       vertice.rotateXZBy(  0); break;
+                                       vertex.rotateXZBy(  0); break;
                                case D6D_YN:
-                                       vertice.rotateYZBy(-90); break;
+                                       vertex.rotateYZBy(-90); break;
                                case D6D_XN:
-                                       vertice.rotateXZBy(-90); break;
+                                       vertex.rotateXZBy(-90); break;
                        }
                }
                drawQuad(vertices, dir);
@@ -795,20 +795,20 @@ void MapblockMeshGenerator::drawTorchlikeNode()
                v3f(-size, -size, 0),
        };
 
-       for (auto &vertice : vertices) {
+       for (v3f &vertex : vertices) {
                switch (wall) {
                        case DWM_YP:
-                               vertice.rotateXZBy(-45); break;
+                               vertex.rotateXZBy(-45); break;
                        case DWM_YN:
-                               vertice.rotateXZBy( 45); break;
+                               vertex.rotateXZBy( 45); break;
                        case DWM_XP:
-                               vertice.rotateXZBy(  0); break;
+                               vertex.rotateXZBy(  0); break;
                        case DWM_XN:
-                               vertice.rotateXZBy(180); break;
+                               vertex.rotateXZBy(180); break;
                        case DWM_ZP:
-                               vertice.rotateXZBy( 90); break;
+                               vertex.rotateXZBy( 90); break;
                        case DWM_ZN:
-                               vertice.rotateXZBy(-90); break;
+                               vertex.rotateXZBy(-90); break;
                }
        }
        drawQuad(vertices);
@@ -828,20 +828,20 @@ void MapblockMeshGenerator::drawSignlikeNode()
                v3f(BS / 2 - offset, -size,  size),
        };
 
-       for (auto &vertice : vertices) {
+       for (v3f &vertex : vertices) {
                switch (wall) {
                        case DWM_YP:
-                               vertice.rotateXYBy( 90); break;
+                               vertex.rotateXYBy( 90); break;
                        case DWM_YN:
-                               vertice.rotateXYBy(-90); break;
+                               vertex.rotateXYBy(-90); break;
                        case DWM_XP:
-                               vertice.rotateXZBy(  0); break;
+                               vertex.rotateXZBy(  0); break;
                        case DWM_XN:
-                               vertice.rotateXZBy(180); break;
+                               vertex.rotateXZBy(180); break;
                        case DWM_ZP:
-                               vertice.rotateXZBy( 90); break;
+                               vertex.rotateXZBy( 90); break;
                        case DWM_ZN:
-                               vertice.rotateXZBy(-90); break;
+                               vertex.rotateXZBy(-90); break;
                }
        }
        drawQuad(vertices);
@@ -864,9 +864,9 @@ void MapblockMeshGenerator::drawPlantlikeQuad(float rotation, float quad_offset,
        for (int i = 0; i < offset_count; i++)
                vertices[i].Z += quad_offset;
 
-       for (auto &vertice : vertices) {
-               vertice.rotateXZBy(rotation + rotate_degree);
-               vertice += offset;
+       for (v3f &vertex : vertices) {
+               vertex.rotateXZBy(rotation + rotate_degree);
+               vertex += offset;
        }
        drawQuad(vertices, v3s16(0, 0, 0), plant_height);
 }
@@ -971,11 +971,11 @@ void MapblockMeshGenerator::drawFirelikeQuad(float rotation, float opening_angle
                v3f(-scale, -BS / 2, 0),
        };
 
-       for (auto &vertice : vertices) {
-               vertice.rotateYZBy(opening_angle);
-               vertice.Z += offset_h;
-               vertice.rotateXZBy(rotation);
-               vertice.Y += offset_v;
+       for (v3f &vertex : vertices) {
+               vertex.rotateYZBy(opening_angle);
+               vertex.Z += offset_h;
+               vertex.rotateXZBy(rotation);
+               vertex.Y += offset_v;
        }
        drawQuad(vertices);
 }
@@ -1192,8 +1192,8 @@ void MapblockMeshGenerator::drawRaillikeNode()
                v3f(-size, -size + offset, -size),
        };
        if (angle)
-               for (auto &vertice : vertices)
-                       vertice.rotateXZBy(angle);
+               for (v3f &vertex : vertices)
+                       vertex.rotateXZBy(angle);
        drawQuad(vertices);
 }
 
index 2e408ba4b207eef947b7f0f52d22621b4ddd7faa..f2f013cbc9bbcc09bf8f2e754810d1e35de1ed64 100644 (file)
@@ -1507,8 +1507,8 @@ void MeshCollector::applyTileColors()
                                video::SColor tc = pmb.layer.color;
                                if (tc == video::SColor(0xFFFFFFFF))
                                        continue;
-                               for (auto &tangent_vertice : pmb.tangent_vertices) {
-                                       video::SColor *c = &tangent_vertice.Color;
+                               for (video::S3DVertexTangents &tangent_vertex : pmb.tangent_vertices) {
+                                       video::SColor *c = &tangent_vertex.Color;
                                        c->set(c->getAlpha(), c->getRed() * tc.getRed() / 255,
                                                c->getGreen() * tc.getGreen() / 255,
                                                c->getBlue() * tc.getBlue() / 255);
@@ -1521,8 +1521,8 @@ void MeshCollector::applyTileColors()
                                video::SColor tc = pmb.layer.color;
                                if (tc == video::SColor(0xFFFFFFFF))
                                        continue;
-                               for (auto &vertice : pmb.vertices) {
-                                       video::SColor *c = &vertice.Color;
+                               for (video::S3DVertex &vertex : pmb.vertices) {
+                                       video::SColor *c = &vertex.Color;
                                        c->set(c->getAlpha(), c->getRed() * tc.getRed() / 255,
                                                c->getGreen() * tc.getGreen() / 255,
                                                c->getBlue() * tc.getBlue() / 255);
index 2f92f0a216dc5884cd7622e100a559fcd8add03a..8799eb38042e3dc4c4f54ac33769d94582f2a60a 100644 (file)
@@ -397,15 +397,15 @@ void transformNodeBox(const MapNode &n, const NodeBox &nodebox,
                                nodebox.wall_side.MaxEdge
                        };
 
-                       for (v3f &vertice : vertices) {
+                       for (v3f &vertex : vertices) {
                                if(dir == v3s16(-1,0,0))
-                                       vertice.rotateXZBy(0);
+                                       vertex.rotateXZBy(0);
                                if(dir == v3s16(1,0,0))
-                                       vertice.rotateXZBy(180);
+                                       vertex.rotateXZBy(180);
                                if(dir == v3s16(0,0,-1))
-                                       vertice.rotateXZBy(90);
+                                       vertex.rotateXZBy(90);
                                if(dir == v3s16(0,0,1))
-                                       vertice.rotateXZBy(-90);
+                                       vertex.rotateXZBy(-90);
                        }
 
                        aabb3f box = aabb3f(vertices[0]);
index 596f04cfaf711abeb259cb3564f97677a2bb94a8..27da73c1604818d1328b28b5f55f51f83b9cdfd1 100644 (file)
@@ -33,7 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 struct PlayerControl
 {
-       PlayerControl() {}
+       PlayerControl() = default;
 
        PlayerControl(
                bool a_up,
index b453b7f76d0dbf02338a7d2c926814046bbd758f..04a7952c6ac73f8e7b4a61f179c25c8b60be26d0 100644 (file)
@@ -59,7 +59,7 @@ namespace porting
 
 bool g_killed = false;
 
-bool * signal_handler_killstatus(void)
+bool *signal_handler_killstatus()
 {
        return &g_killed;
 }
@@ -167,7 +167,7 @@ bool detectMSVCBuildDir(const std::string &path)
                "bin\\Build",
                NULL
        };
-       return (removeStringEnd(path, ends) != "");
+       return (!removeStringEnd(path, ends).empty());
 }
 
 std::string get_sysinfo()
@@ -388,7 +388,7 @@ bool setSystemPaths()
        // It is identified by containing the subdirectory "builtin".
        std::list<std::string> trylist;
        std::string static_sharedir = STATIC_SHAREDIR;
-       if (static_sharedir != "" && static_sharedir != ".")
+       if (!static_sharedir.empty() && static_sharedir != ".")
                trylist.push_back(static_sharedir);
 
        trylist.push_back(bindir + DIR_DELIM ".." DIR_DELIM "share"
@@ -623,7 +623,7 @@ bool secure_rand_fill_buf(void *buf, size_t len)
 
 #endif
 
-void attachOrCreateConsole(void)
+void attachOrCreateConsole()
 {
 #ifdef _WIN32
        static bool consoleAllocated = false;
index 4e663390a7050c26fed18bd5c03603311afaf288..304e4aff0d0c86303b3a7563d3b41959007ee3fb 100644 (file)
@@ -56,7 +56,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
        #define sleep_ms(x) Sleep(x)
 #else
        #include <unistd.h>
-       #include <stdint.h> //for uintptr_t
+       #include <cstdint> //for uintptr_t
 
        // Use standard Posix macro for Linux
        #if (defined(linux) || defined(__linux)) && !defined(__linux__)
@@ -112,8 +112,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #ifndef _WIN32 // Posix
        #include <sys/time.h>
-       #include <time.h>
-       #if defined(__MACH__) && defined(__APPLE__)
+       #include <ctime>
+
+#if defined(__MACH__) && defined(__APPLE__)
                #include <mach/clock.h>
                #include <mach/mach.h>
        #endif
@@ -273,9 +274,9 @@ inline u64 getDeltaMs(u64 old_time_ms, u64 new_time_ms)
 {
        if (new_time_ms >= old_time_ms) {
                return (new_time_ms - old_time_ms);
-       } else {
-               return (old_time_ms - new_time_ms);
        }
+
+       return (old_time_ms - new_time_ms);
 }
 
 inline const char *getPlatformName()
index 72b625d73a0dd4199d9ecd55bc6ba2da5106a427..7c74f7b5b22dda0d4d3e7fa1a16fc3e09d4f0e9c 100644 (file)
@@ -31,7 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include <sstream>
 #include <exception>
-#include <stdlib.h>
+#include <cstdlib>
 
 #ifdef GPROF
 #include "prof.h"
index 78055b0d4850aa470b64f91d8780cea363c7cd6d..6704afd514f96908920b4ea7f47b5e563efa00c0 100644 (file)
@@ -42,7 +42,7 @@ extern Profiler *g_profiler;
 class Profiler
 {
 public:
-       Profiler() {}
+       Profiler() = default;
 
        void add(const std::string &name, float value)
        {
@@ -80,11 +80,8 @@ public:
        void clear()
        {
                MutexAutoLock lock(m_mutex);
-               for(std::map<std::string, float>::iterator
-                               i = m_data.begin();
-                               i != m_data.end(); ++i)
-               {
-                       i->second = 0;
+               for (auto &it : m_data) {
+                       it.second = 0;
                }
                m_avgcounts.clear();
        }
index 1659e09f17c1ea017ca37d18ba0fe7c215b7e507..1943d19c2465dbcd09882f74a47a8cc97dc8ce00 100644 (file)
@@ -58,7 +58,7 @@ enum QuicktuneValueType{
 };
 struct QuicktuneValue
 {
-       QuicktuneValueType type;
+       QuicktuneValueType type = QVT_NONE;
        union{
                struct{
                        float current;
@@ -66,12 +66,10 @@ struct QuicktuneValue
                        float max;
                } value_QVT_FLOAT;
        };
-       bool modified;
+       bool modified = false;
+
+       QuicktuneValue() = default;
 
-       QuicktuneValue():
-               type(QVT_NONE),
-               modified(false)
-       {}
        std::string getString();
        void relativeAdd(float amount);
 };
index c8a449533b890fd997840843c7289dfbd501db8c..70a7b70b33212a329b0b759c5a29acba0fadfb1a 100644 (file)
@@ -28,16 +28,16 @@ private:
        u32 m_selected_i;
        std::string m_message;
 public:
-       bool hasMessage()
+       bool hasMessage() const
        {
-               return m_message != "";
+               return !m_message.empty();
        }
 
        std::string getMessage()
        {
                std::string s = m_message;
                m_message = "";
-               if(s != "")
+               if (!s.empty())
                        return std::string("[quicktune] ") + s;
                return "";
        }
index 42cc22587d69984d70ebd06d1af6c2c6db716e1d..2dbebd83b76a334313d62ade5f48492ad4d516fe 100644 (file)
@@ -31,13 +31,15 @@ bool RaycastSort::operator() (const PointedThing &pt1,
        // returns false if pt1 is nearer than pt2
        if (pt1.distanceSq < pt2.distanceSq) {
                return false;
-       } else if (pt1.distanceSq == pt2.distanceSq) {
+       }
+
+       if (pt1.distanceSq == pt2.distanceSq) {
                // Sort them to allow only one order
                if (pt1.type == POINTEDTHING_OBJECT)
                        return (pt2.type == POINTEDTHING_OBJECT
                                && pt1.object_id < pt2.object_id);
-               else
-                       return (pt2.type == POINTEDTHING_OBJECT
+
+               return (pt2.type == POINTEDTHING_OBJECT
                                || pt1.node_undersurface < pt2.node_undersurface);
        }
        return true;
index c276062c2ad50552ff6eea70ffc94ca516fb7bf1..20c18ee155c3ce18495f4f4e23472763163aa63f 100644 (file)
@@ -72,8 +72,8 @@ void RemotePlayer::serializeExtraAttributes(std::string &output)
        assert(m_sao);
        Json::Value json_root;
        const PlayerAttributes &attrs = m_sao->getExtendedAttributes();
-       for (PlayerAttributes::const_iterator it = attrs.begin(); it != attrs.end(); ++it) {
-               json_root[(*it).first] = (*it).second;
+       for (const auto &attr : attrs) {
+               json_root[attr.first] = attr.second;
        }
 
        Json::FastWriter writer;
@@ -125,10 +125,9 @@ void RemotePlayer::deSerialize(std::istream &is, const std::string &playername,
                        reader.parse(extended_attributes, attr_root);
 
                        const Json::Value::Members attr_list = attr_root.getMemberNames();
-                       for (Json::Value::Members::const_iterator it = attr_list.begin();
-                                       it != attr_list.end(); ++it) {
-                               Json::Value attr_value = attr_root[*it];
-                               sao->setExtendedAttribute(*it, attr_value.asString());
+                       for (const auto &it : attr_list) {
+                               Json::Value attr_value = attr_root[it];
+                               sao->setExtendedAttribute(it, attr_value.asString());
                        }
                } catch (SettingNotFoundException &e) {}
        }
@@ -165,7 +164,7 @@ void RemotePlayer::serialize(std::ostream &os)
        args.setFloat("yaw", m_sao->getYaw());
        args.setS32("breath", m_sao->getBreath());
 
-       std::string extended_attrs = "";
+       std::string extended_attrs;
        serializeExtraAttributes(extended_attrs);
        args.set("extended_attributes", extended_attrs);
 
index 32c78b5acdb619e65f7ae67864ae1be350161bc5..84978f343a09a8a1eb1f7642309862babccd79bd 100644 (file)
@@ -41,7 +41,7 @@ class RemotePlayer : public Player
 
 public:
        RemotePlayer(const char *name, IItemDefManager *idef);
-       virtual ~RemotePlayer() {}
+       virtual ~RemotePlayer() = default;
 
        void deSerialize(std::istream &is, const std::string &playername, PlayerSAO *sao);
 
index a77a9ee15d75761ce738143ef6e749f4d4c5b2cc..3cd9c7ce7c63c2e4ca748480dc7a2191924a1d99 100644 (file)
@@ -577,35 +577,34 @@ const std::list<RollbackAction> RollbackManager::rollbackActionsFromActionRows(
 {
        std::list<RollbackAction> actions;
 
-       for (std::list<ActionRow>::const_iterator it = rows.begin();
-                       it != rows.end(); ++it) {
+       for (const ActionRow &row : rows) {
                RollbackAction action;
-               action.actor     = (it->actor) ? getActorName(it->actor) : "";
-               action.unix_time = it->timestamp;
-               action.type      = static_cast<RollbackAction::Type>(it->type);
+               action.actor     = (row.actor) ? getActorName(row.actor) : "";
+               action.unix_time = row.timestamp;
+               action.type      = static_cast<RollbackAction::Type>(row.type);
 
                switch (action.type) {
                case RollbackAction::TYPE_MODIFY_INVENTORY_STACK:
-                       action.inventory_location = it->location.c_str();
-                       action.inventory_list     = it->list;
-                       action.inventory_index    = it->index;
-                       action.inventory_add      = it->add;
-                       action.inventory_stack    = it->stack;
+                       action.inventory_location = row.location;
+                       action.inventory_list     = row.list;
+                       action.inventory_index    = row.index;
+                       action.inventory_add      = row.add;
+                       action.inventory_stack    = row.stack;
                        if (action.inventory_stack.name.empty()) {
-                               action.inventory_stack.name = getNodeName(it->stack.id);
+                               action.inventory_stack.name = getNodeName(row.stack.id);
                        }
                        break;
 
                case RollbackAction::TYPE_SET_NODE:
-                       action.p            = v3s16(it->x, it->y, it->z);
-                       action.n_old.name   = getNodeName(it->oldNode);
-                       action.n_old.param1 = it->oldParam1;
-                       action.n_old.param2 = it->oldParam2;
-                       action.n_old.meta   = it->oldMeta;
-                       action.n_new.name   = getNodeName(it->newNode);
-                       action.n_new.param1 = it->newParam1;
-                       action.n_new.param2 = it->newParam2;
-                       action.n_new.meta   = it->newMeta;
+                       action.p            = v3s16(row.x, row.y, row.z);
+                       action.n_old.name   = getNodeName(row.oldNode);
+                       action.n_old.param1 = row.oldParam1;
+                       action.n_old.param2 = row.oldParam2;
+                       action.n_old.meta   = row.oldMeta;
+                       action.n_new.name   = getNodeName(row.newNode);
+                       action.n_new.param1 = row.newParam1;
+                       action.n_new.param2 = row.newParam2;
+                       action.n_new.meta   = row.newMeta;
                        break;
 
                default:
@@ -870,7 +869,7 @@ void RollbackManager::setActor(const std::string & actor, bool is_guess)
 std::string RollbackManager::getSuspect(v3s16 p, float nearness_shortcut,
                float min_nearness)
 {
-       if (current_actor != "") {
+       if (!current_actor.empty()) {
                return current_actor;
        }
        int cur_time = time(0);
@@ -883,7 +882,7 @@ std::string RollbackManager::getSuspect(v3s16 p, float nearness_shortcut,
                if (i->unix_time < first_time) {
                        break;
                }
-               if (i->actor == "") {
+               if (i->actor.empty()) {
                        continue;
                }
                // Find position of suspect or continue
@@ -919,7 +918,7 @@ void RollbackManager::flush()
        for (iter  = action_todisk_buffer.begin();
                        iter != action_todisk_buffer.end();
                        ++iter) {
-               if (iter->actor == "") {
+               if (iter->actor.empty()) {
                        continue;
                }
 
index 4b0ad0164b18278f5a9e63cb5307c54081fa73e9..94b800579ca1a20aac1f27ea3ff46c8477e104e6 100644 (file)
@@ -45,7 +45,8 @@ struct RollbackNode
        }
        bool operator != (const RollbackNode &other) { return !(*this == other); }
 
-       RollbackNode() {}
+       RollbackNode() = default;
+
        RollbackNode(Map *map, v3s16 p, IGameDef *gamedef);
 };
 
@@ -56,11 +57,11 @@ struct RollbackAction
                TYPE_NOTHING,
                TYPE_SET_NODE,
                TYPE_MODIFY_INVENTORY_STACK,
-       } type;
+       } type = TYPE_NOTHING;
 
-       time_t unix_time;
+       time_t unix_time = 0;
        std::string actor;
-       bool actor_is_guess;
+       bool actor_is_guess = false;
 
        v3s16 p;
        RollbackNode n_old;
@@ -72,11 +73,7 @@ struct RollbackAction
        bool inventory_add;
        ItemStack inventory_stack;
 
-       RollbackAction():
-               type(TYPE_NOTHING),
-               unix_time(0),
-               actor_is_guess(false)
-       {}
+       RollbackAction() = default;
 
        void setSetNode(v3s16 p_, const RollbackNode &n_old_,
                        const RollbackNode &n_new_)
@@ -88,7 +85,7 @@ struct RollbackAction
        }
 
        void setModifyInventoryStack(const std::string &inventory_location_,
-                       const std::string &inventory_list_, int index_,
+                       const std::string &inventory_list_, u32 index_,
                        bool add_, const ItemStack &inventory_stack_)
        {
                type = TYPE_MODIFY_INVENTORY_STACK;
@@ -121,7 +118,7 @@ public:
        virtual std::string getSuspect(v3s16 p, float nearness_shortcut,
                                       float min_nearness) = 0;
 
-       virtual ~IRollbackManager() {};
+       virtual ~IRollbackManager() = default;;
        virtual void flush() = 0;
        // Get all actors that did something to position p, but not further than
        // <seconds> in history
index c74cc539430fd546503ef9b7eed546d1a3d3f8b4..f48066fad51c742a2fe7c4c498e878d5e566dea4 100644 (file)
@@ -359,10 +359,8 @@ Server::~Server()
        delete m_script;
 
        // Delete detached inventories
-       for (std::map<std::string, Inventory*>::iterator
-                       i = m_detached_inventories.begin();
-                       i != m_detached_inventories.end(); ++i) {
-               delete i->second;
+       for (auto &detached_inventory : m_detached_inventories) {
+               delete detached_inventory.second;
        }
 }
 
@@ -2298,14 +2296,12 @@ void Server::fillMediaCache()
        paths.push_back(porting::path_user + DIR_DELIM + "textures" + DIR_DELIM + "server");
 
        // Collect media file information from paths into cache
-       for(std::vector<std::string>::iterator i = paths.begin();
-                       i != paths.end(); ++i) {
-               std::string mediapath = *i;
+       for (const std::string &mediapath : paths) {
                std::vector<fs::DirListNode> dirlist = fs::GetDirListing(mediapath);
-               for (u32 j = 0; j < dirlist.size(); j++) {
-                       if (dirlist[j].dir) // Ignode dirs
+               for (const fs::DirListNode &dln : dirlist) {
+                       if (dln.dir) // Ignode dirs
                                continue;
-                       std::string filename = dirlist[j].name;
+                       std::string filename = dln.name;
                        // If name contains illegal characters, ignore the file
                        if (!string_allowed(filename, TEXTURENAME_ALLOWED_CHARS)) {
                                infostream<<"Server: ignoring illegal file name: \""
@@ -2326,7 +2322,9 @@ void Server::fillMediaCache()
                                continue;
                        }
                        // Ok, attempt to load the file and add to cache
-                       std::string filepath = mediapath + DIR_DELIM + filename;
+                       std::string filepath;
+                       filepath.append(mediapath).append(DIR_DELIM).append(filename);
+
                        // Read data
                        std::ifstream fis(filepath.c_str(), std::ios_base::binary);
                        if (!fis.good()) {
index 4cc76b96fc514aefb0cdf78f52e3fd505b39b0ad..b552ad72fa28b73d4c604e9e4ee4ee0c7f9d6dae 100644 (file)
@@ -129,7 +129,7 @@ LBMManager::~LBMManager()
 void LBMManager::addLBMDef(LoadingBlockModifierDef *lbm_def)
 {
        // Precondition, in query mode the map isn't used anymore
-       FATAL_ERROR_IF(m_query_mode == true,
+       FATAL_ERROR_IF(m_query_mode,
                "attempted to modify LBMManager in query mode");
 
        if (!string_allowed(lbm_def->name, LBM_NAME_ALLOWED_CHARS)) {
@@ -160,7 +160,7 @@ void LBMManager::loadIntroductionTimes(const std::string &times,
 
        size_t idx = 0;
        size_t idx_new;
-       while ((idx_new = times.find(";", idx)) != std::string::npos) {
+       while ((idx_new = times.find(';', idx)) != std::string::npos) {
                std::string entry = times.substr(idx, idx_new - idx);
                std::vector<std::string> components = str_split(entry, '~');
                if (components.size() != 2)
@@ -224,7 +224,7 @@ void LBMManager::loadIntroductionTimes(const std::string &times,
 std::string LBMManager::createIntroductionTimesString()
 {
        // Precondition, we must be in query mode
-       FATAL_ERROR_IF(m_query_mode == false,
+       FATAL_ERROR_IF(!m_query_mode,
                "attempted to query on non fully set up LBMManager");
 
        std::ostringstream oss;
@@ -246,7 +246,7 @@ std::string LBMManager::createIntroductionTimesString()
 void LBMManager::applyLBMs(ServerEnvironment *env, MapBlock *block, u32 stamp)
 {
        // Precondition, we need m_lbm_lookup to be initialized
-       FATAL_ERROR_IF(m_query_mode == false,
+       FATAL_ERROR_IF(!m_query_mode,
                "attempted to query on non fully set up LBMManager");
        v3s16 pos_of_block = block->getPosRelative();
        v3s16 pos;
@@ -300,22 +300,17 @@ void ActiveBlockList::update(std::vector<v3s16> &active_positions,
                Create the new list
        */
        std::set<v3s16> newlist = m_forceloaded_list;
-       for(std::vector<v3s16>::iterator i = active_positions.begin();
-               i != active_positions.end(); ++i)
-       {
-               fillRadiusBlock(*i, radius, newlist);
+       for (const v3s16 &active_position : active_positions) {
+               fillRadiusBlock(active_position, radius, newlist);
        }
 
        /*
                Find out which blocks on the old list are not on the new list
        */
        // Go through old list
-       for(std::set<v3s16>::iterator i = m_list.begin();
-               i != m_list.end(); ++i)
-       {
-               v3s16 p = *i;
+       for (v3s16 p : m_list) {
                // If not on new list, it's been removed
-               if(newlist.find(p) == newlist.end())
+               if (newlist.find(p) == newlist.end())
                        blocks_removed.insert(p);
        }
 
@@ -323,10 +318,7 @@ void ActiveBlockList::update(std::vector<v3s16> &active_positions,
                Find out which blocks on the new list are not on the old list
        */
        // Go through new list
-       for(std::set<v3s16>::iterator i = newlist.begin();
-               i != newlist.end(); ++i)
-       {
-               v3s16 p = *i;
+       for (v3s16 p : newlist) {
                // If not on old list, it's been added
                if(m_list.find(p) == m_list.end())
                        blocks_added.insert(p);
@@ -336,10 +328,7 @@ void ActiveBlockList::update(std::vector<v3s16> &active_positions,
                Update m_list
        */
        m_list.clear();
-       for(std::set<v3s16>::iterator i = newlist.begin();
-               i != newlist.end(); ++i)
-       {
-               v3s16 p = *i;
+       for (v3s16 p : newlist) {
                m_list.insert(p);
        }
 }
@@ -375,7 +364,7 @@ ServerEnvironment::ServerEnvironment(ServerMap *map,
                }
        }
 
-       std::string name = "";
+       std::string name;
        conf.getNoEx("player_backend", name);
        m_player_database = openPlayerDatabase(name, path_world, conf);
 }
@@ -393,15 +382,13 @@ ServerEnvironment::~ServerEnvironment()
        m_map->drop();
 
        // Delete ActiveBlockModifiers
-       for (std::vector<ABMWithState>::iterator
-               i = m_abms.begin(); i != m_abms.end(); ++i){
-               delete i->abm;
+       for (ABMWithState &m_abm : m_abms) {
+               delete m_abm.abm;
        }
 
        // Deallocate players
-       for (std::vector<RemotePlayer *>::iterator i = m_players.begin();
-               i != m_players.end(); ++i) {
-               delete (*i);
+       for (RemotePlayer *m_player : m_players) {
+               delete m_player;
        }
 
        delete m_player_database;
@@ -419,9 +406,7 @@ ServerMap & ServerEnvironment::getServerMap()
 
 RemotePlayer *ServerEnvironment::getPlayer(const u16 peer_id)
 {
-       for (std::vector<RemotePlayer *>::iterator i = m_players.begin();
-               i != m_players.end(); ++i) {
-               RemotePlayer *player = *i;
+       for (RemotePlayer *player : m_players) {
                if (player->peer_id == peer_id)
                        return player;
        }
@@ -430,9 +415,7 @@ RemotePlayer *ServerEnvironment::getPlayer(const u16 peer_id)
 
 RemotePlayer *ServerEnvironment::getPlayer(const char* name)
 {
-       for (std::vector<RemotePlayer *>::iterator i = m_players.begin();
-               i != m_players.end(); ++i) {
-               RemotePlayer *player = *i;
+       for (RemotePlayer *player : m_players) {
                if (strcmp(player->getName(), name) == 0)
                        return player;
        }
@@ -503,9 +486,7 @@ bool ServerEnvironment::line_of_sight(v3f pos1, v3f pos2, float stepsize, v3s16
 void ServerEnvironment::kickAllPlayers(AccessDeniedCode reason,
        const std::string &str_reason, bool reconnect)
 {
-       for (std::vector<RemotePlayer *>::iterator it = m_players.begin();
-               it != m_players.end(); ++it) {
-               RemotePlayer *player = dynamic_cast<RemotePlayer *>(*it);
+       for (RemotePlayer *player : m_players) {
                m_server->DenyAccessVerCompliant(player->peer_id,
                        player->protocol_version, reason, str_reason, reconnect);
        }
@@ -516,15 +497,13 @@ void ServerEnvironment::saveLoadedPlayers()
        std::string players_path = m_path_world + DIR_DELIM + "players";
        fs::CreateDir(players_path);
 
-       for (std::vector<RemotePlayer *>::iterator it = m_players.begin();
-               it != m_players.end();
-               ++it) {
-               if ((*it)->checkModified() ||
-                       ((*it)->getPlayerSAO() && (*it)->getPlayerSAO()->extendedAttributesModified())) {
+       for (RemotePlayer *player : m_players) {
+               if (player->checkModified() || (player->getPlayerSAO() && 
+                               player->getPlayerSAO()->extendedAttributesModified())) {
                        try {
-                               m_player_database->savePlayer(*it);
+                               m_player_database->savePlayer(player);
                        } catch (DatabaseException &e) {
-                               errorstream << "Failed to save player " << (*it)->getName() << " exception: "
+                               errorstream << "Failed to save player " << player->getName() << " exception: "
                                        << e.what() << std::endl;
                                throw;
                        }
@@ -641,7 +620,7 @@ void ServerEnvironment::loadMeta()
                // If missing, do as if clearObjects was never called
                args.getU64("last_clear_objects_time") : 0;
 
-       std::string lbm_introduction_times = "";
+       std::string lbm_introduction_times;
        try {
                u64 ver = args.getU64("lbm_introduction_times_version");
                if (ver == 1) {
@@ -685,18 +664,17 @@ public:
                if(dtime_s < 0.001)
                        return;
                INodeDefManager *ndef = env->getGameDef()->ndef();
-               for(std::vector<ABMWithState>::iterator
-                       i = abms.begin(); i != abms.end(); ++i) {
-                       ActiveBlockModifier *abm = i->abm;
+               for (ABMWithState &abmws : abms) {
+                       ActiveBlockModifier *abm = abmws.abm;
                        float trigger_interval = abm->getTriggerInterval();
                        if(trigger_interval < 0.001)
                                trigger_interval = 0.001;
                        float actual_interval = dtime_s;
                        if(use_timers){
-                               i->timer += dtime_s;
-                               if(i->timer < trigger_interval)
+                               abmws.timer += dtime_s;
+                               if(abmws.timer < trigger_interval)
                                        continue;
-                               i->timer -= trigger_interval;
+                               abmws.timer -= trigger_interval;
                                actual_interval = trigger_interval;
                        }
                        float chance = abm->getTriggerChance();
@@ -718,20 +696,16 @@ public:
                        // Trigger neighbors
                        const std::set<std::string> &required_neighbors_s =
                                abm->getRequiredNeighbors();
-                       for (std::set<std::string>::iterator rn = required_neighbors_s.begin();
-                                       rn != required_neighbors_s.end(); ++rn) {
-                               ndef->getIds(*rn, aabm.required_neighbors);
+                       for (const std::string &required_neighbor_s : required_neighbors_s) {
+                               ndef->getIds(required_neighbor_s, aabm.required_neighbors);
                        }
 
                        // Trigger contents
                        const std::set<std::string> &contents_s = abm->getTriggerContents();
-                       for (std::set<std::string>::iterator cs = contents_s.begin();
-                                       cs != contents_s.end(); ++cs) {
+                       for (const std::string &content_s : contents_s) {
                                std::set<content_t> ids;
-                               ndef->getIds(*cs, ids);
-                               for (std::set<content_t>::const_iterator k = ids.begin();
-                                               k != ids.end(); ++k) {
-                                       content_t c = *k;
+                               ndef->getIds(content_s, ids);
+                               for (content_t c : ids) {
                                        if (c >= m_aabms.size())
                                                m_aabms.resize(c + 256, NULL);
                                        if (!m_aabms[c])
@@ -744,8 +718,8 @@ public:
 
        ~ABMHandler()
        {
-               for (size_t i = 0; i < m_aabms.size(); i++)
-                       delete m_aabms[i];
+               for (auto &aabms : m_aabms)
+                       delete aabms;
        }
 
        // Find out how many objects the given block and its neighbours contain.
@@ -799,14 +773,12 @@ public:
                                continue;
 
                        v3s16 p = p0 + block->getPosRelative();
-                       for(std::vector<ActiveABM>::iterator
-                               i = m_aabms[c]->begin(); i != m_aabms[c]->end(); ++i) {
-                               if(myrand() % i->chance != 0)
+                       for (ActiveABM &aabm : *m_aabms[c]) {
+                               if (myrand() % aabm.chance != 0)
                                        continue;
 
                                // Check neighbors
-                               if(!i->required_neighbors.empty())
-                               {
+                               if (!aabm.required_neighbors.empty()) {
                                        v3s16 p1;
                                        for(p1.X = p0.X-1; p1.X <= p0.X+1; p1.X++)
                                        for(p1.Y = p0.Y-1; p1.Y <= p0.Y+1; p1.Y++)
@@ -826,8 +798,8 @@ public:
                                                        c = n.getContent();
                                                }
                                                std::set<content_t>::const_iterator k;
-                                               k = i->required_neighbors.find(c);
-                                               if(k != i->required_neighbors.end()){
+                                               k = aabm.required_neighbors.find(c);
+                                               if(k != aabm.required_neighbors.end()){
                                                        goto neighbor_found;
                                                }
                                        }
@@ -837,8 +809,8 @@ public:
                                neighbor_found:
 
                                // Call all the trigger variations
-                               i->abm->trigger(m_env, p, n);
-                               i->abm->trigger(m_env, p, n,
+                               aabm.abm->trigger(m_env, p, n);
+                               aabm.abm->trigger(m_env, p, n,
                                        active_object_count, active_object_count_wider);
 
                                // Count surrounding objects again if the abms added any
@@ -894,13 +866,12 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime)
                block->m_node_timers.step((float)dtime_s);
        if (!elapsed_timers.empty()) {
                MapNode n;
-               for (std::vector<NodeTimer>::iterator
-                       i = elapsed_timers.begin();
-                       i != elapsed_timers.end(); ++i){
-                       n = block->getNodeNoEx(i->position);
-                       v3s16 p = i->position + block->getPosRelative();
-                       if (m_script->node_on_timer(p, n, i->elapsed))
-                               block->setNodeTimer(NodeTimer(i->timeout, 0, i->position));
+               for (const NodeTimer &elapsed_timer : elapsed_timers) {
+                       n = block->getNodeNoEx(elapsed_timer.position);
+                       v3s16 p = elapsed_timer.position + block->getPosRelative();
+                       if (m_script->node_on_timer(p, n, elapsed_timer.elapsed))
+                               block->setNodeTimer(NodeTimer(elapsed_timer.timeout, 0,
+                                       elapsed_timer.position));
                }
        }
 
@@ -911,7 +882,7 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime)
 
 void ServerEnvironment::addActiveBlockModifier(ActiveBlockModifier *abm)
 {
-       m_abms.push_back(ABMWithState(abm));
+       m_abms.emplace_back(abm);
 }
 
 void ServerEnvironment::addLoadingBlockModifierDef(LoadingBlockModifierDef *lbm)
@@ -985,10 +956,9 @@ bool ServerEnvironment::swapNode(v3s16 p, const MapNode &n)
 void ServerEnvironment::getObjectsInsideRadius(std::vector<u16> &objects, v3f pos,
        float radius)
 {
-       for (ServerActiveObjectMap::iterator i = m_active_objects.begin();
-               i != m_active_objects.end(); ++i) {
-               ServerActiveObject* obj = i->second;
-               u16 id = i->first;
+       for (auto &activeObject : m_active_objects) {
+               ServerActiveObject* obj = activeObject.second;
+               u16 id = activeObject.first;
                v3f objectpos = obj->getBasePosition();
                if (objectpos.getDistanceFrom(pos) > radius)
                        continue;
@@ -1001,12 +971,11 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode)
        infostream << "ServerEnvironment::clearObjects(): "
                << "Removing all active objects" << std::endl;
        std::vector<u16> objects_to_remove;
-       for (ServerActiveObjectMap::iterator i = m_active_objects.begin();
-               i != m_active_objects.end(); ++i) {
-               ServerActiveObject* obj = i->second;
+       for (auto &it : m_active_objects) {
+               ServerActiveObject* obj = it.second;
                if (obj->getType() == ACTIVEOBJECT_TYPE_PLAYER)
                        continue;
-               u16 id = i->first;
+               u16 id = it.first;
                // Delete static object if block is loaded
                if (obj->m_static_exists) {
                        MapBlock *block = m_map->getBlockNoCreateNoEx(obj->m_static_block);
@@ -1037,9 +1006,8 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode)
        }
 
        // Remove references from m_active_objects
-       for (std::vector<u16>::iterator i = objects_to_remove.begin();
-               i != objects_to_remove.end(); ++i) {
-               m_active_objects.erase(*i);
+       for (u16 i : objects_to_remove) {
+               m_active_objects.erase(i);
        }
 
        // Get list of loaded blocks
@@ -1069,9 +1037,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode)
                << " blocks" << std::endl;
 
        // Grab a reference on each loaded block to avoid unloading it
-       for (std::vector<v3s16>::iterator i = loaded_blocks.begin();
-               i != loaded_blocks.end(); ++i) {
-               v3s16 p = *i;
+       for (v3s16 p : loaded_blocks) {
                MapBlock *block = m_map->getBlockNoCreateNoEx(p);
                assert(block != NULL);
                block->refGrab();
@@ -1087,7 +1053,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode)
        u32 num_blocks_checked = 0;
        u32 num_blocks_cleared = 0;
        u32 num_objs_cleared = 0;
-       for (std::vector<v3s16>::iterator i = loadable_blocks.begin();
+       for (auto i = loadable_blocks.begin();
                i != loadable_blocks.end(); ++i) {
                v3s16 p = *i;
                MapBlock *block = m_map->emergeBlock(p, false);
@@ -1124,9 +1090,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode)
        m_map->unloadUnreferencedBlocks();
 
        // Drop references that were added above
-       for (std::vector<v3s16>::iterator i = loaded_blocks.begin();
-               i != loaded_blocks.end(); ++i) {
-               v3s16 p = *i;
+       for (v3s16 p : loaded_blocks) {
                MapBlock *block = m_map->getBlockNoCreateNoEx(p);
                assert(block);
                block->refDrop();
@@ -1341,9 +1305,8 @@ void ServerEnvironment::step(float dtime)
                        send_recommended = true;
                }
 
-               for (ServerActiveObjectMap::iterator i = m_active_objects.begin();
-                       i != m_active_objects.end(); ++i) {
-                       ServerActiveObject* obj = i->second;
+               for (auto &ao_it : m_active_objects) {
+                       ServerActiveObject* obj = ao_it.second;
                        // Don't step if is to be removed or stored statically
                        if(obj->m_removed || obj->m_pending_deactivation)
                                continue;
@@ -1491,12 +1454,11 @@ void ServerEnvironment::getAddedActiveObjects(PlayerSAO *playersao, s16 radius,
                - discard objects that are found in current_objects.
                - add remaining objects to added_objects
        */
-       for (ServerActiveObjectMap::iterator i = m_active_objects.begin();
-               i != m_active_objects.end(); ++i) {
-               u16 id = i->first;
+       for (auto &ao_it : m_active_objects) {
+               u16 id = ao_it.first;
 
                // Get object
-               ServerActiveObject *object = i->second;
+               ServerActiveObject *object = ao_it.second;
                if (object == NULL)
                        continue;
 
@@ -1545,11 +1507,7 @@ void ServerEnvironment::getRemovedActiveObjects(PlayerSAO *playersao, s16 radius
                - object has m_removed=true, or
                - object is too far away
        */
-       for(std::set<u16>::iterator
-               i = current_objects.begin();
-               i != current_objects.end(); ++i)
-       {
-               u16 id = *i;
+       for (u16 id : current_objects) {
                ServerActiveObject *object = getActiveObject(id);
 
                if (object == NULL) {
@@ -1583,11 +1541,9 @@ void ServerEnvironment::setStaticForActiveObjectsInBlock(
        if (!block)
                return;
 
-       for (std::map<u16, StaticObject>::iterator
-               so_it = block->m_static_objects.m_active.begin();
-               so_it != block->m_static_objects.m_active.end(); ++so_it) {
+       for (auto &so_it : block->m_static_objects.m_active) {
                // Get the ServerActiveObject counterpart to this StaticObject
-               ServerActiveObjectMap::const_iterator ao_it = m_active_objects.find(so_it->first);
+               ServerActiveObjectMap::const_iterator ao_it = m_active_objects.find(so_it.first);
                if (ao_it == m_active_objects.end()) {
                        // If this ever happens, there must be some kind of nasty bug.
                        errorstream << "ServerEnvironment::setStaticForObjectsInBlock(): "
@@ -1621,8 +1577,8 @@ void ServerEnvironment::getSelectedActiveObjects(
                shootline_on_map.getLength() + 10.0f);
        const v3f line_vector = shootline_on_map.getVector();
 
-       for (u32 i = 0; i < objectIds.size(); i++) {
-               ServerActiveObject* obj = getActiveObject(objectIds[i]);
+       for (u16 objectId : objectIds) {
+               ServerActiveObject* obj = getActiveObject(objectId);
 
                aabb3f selection_box;
                if (!obj->getSelectionBox(&selection_box))
@@ -1637,9 +1593,9 @@ void ServerEnvironment::getSelectedActiveObjects(
                v3s16 current_normal;
                if (boxLineCollision(offsetted_box, shootline_on_map.start, line_vector,
                                &current_intersection, &current_normal)) {
-                       objects.push_back(PointedThing(
-                               (s16) objectIds[i], current_intersection, current_normal,
-                               (current_intersection - shootline_on_map.start).getLengthSQ()));
+                       objects.emplace_back(
+                               (s16) objectId, current_intersection, current_normal,
+                               (current_intersection - shootline_on_map.start).getLengthSQ());
                }
        }
 }
@@ -1707,7 +1663,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
        {
                // Add static object to active static list of the block
                v3f objectpos = object->getBasePosition();
-               std::string staticdata = "";
+               std::string staticdata;
                object->getStaticData(&staticdata);
                StaticObject s_obj(object->getType(), objectpos, staticdata);
                // Add to the block where the object is located in
@@ -1738,10 +1694,9 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
 void ServerEnvironment::removeRemovedObjects()
 {
        std::vector<u16> objects_to_remove;
-       for(ServerActiveObjectMap::iterator i = m_active_objects.begin();
-               i != m_active_objects.end(); ++i) {
-               u16 id = i->first;
-               ServerActiveObject* obj = i->second;
+       for (auto &ao_it : m_active_objects) {
+               u16 id = ao_it.first;
+               ServerActiveObject* obj = ao_it.second;
                // This shouldn't happen but check it
                if(obj == NULL)
                {
@@ -1814,9 +1769,8 @@ void ServerEnvironment::removeRemovedObjects()
                objects_to_remove.push_back(id);
        }
        // Remove references from m_active_objects
-       for(std::vector<u16>::iterator i = objects_to_remove.begin();
-               i != objects_to_remove.end(); ++i) {
-               m_active_objects.erase(*i);
+       for (u16 i : objects_to_remove) {
+               m_active_objects.erase(i);
        }
 }
 
@@ -1885,11 +1839,7 @@ void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s)
 
        // Activate stored objects
        std::vector<StaticObject> new_stored;
-       for (std::vector<StaticObject>::iterator
-               i = block->m_static_objects.m_stored.begin();
-               i != block->m_static_objects.m_stored.end(); ++i) {
-               StaticObject &s_obj = *i;
-
+       for (const StaticObject &s_obj : block->m_static_objects.m_stored) {
                // Create an active object from the data
                ServerActiveObject *obj = ServerActiveObject::create
                        ((ActiveObjectType) s_obj.type, this, 0, s_obj.pos, s_obj.data);
@@ -1913,20 +1863,14 @@ void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s)
        // Clear stored list
        block->m_static_objects.m_stored.clear();
        // Add leftover failed stuff to stored list
-       for(std::vector<StaticObject>::iterator
-               i = new_stored.begin();
-               i != new_stored.end(); ++i) {
-               StaticObject &s_obj = *i;
+       for (const StaticObject &s_obj : new_stored) {
                block->m_static_objects.m_stored.push_back(s_obj);
        }
 
        // Turn the active counterparts of activated objects not pending for
        // deactivation
-       for(std::map<u16, StaticObject>::iterator
-               i = block->m_static_objects.m_active.begin();
-               i != block->m_static_objects.m_active.end(); ++i)
-       {
-               u16 id = i->first;
+       for (auto &i : block->m_static_objects.m_active) {
+               u16 id = i.first;
                ServerActiveObject *object = getActiveObject(id);
                assert(object);
                object->m_pending_deactivation = false;
@@ -1956,12 +1900,11 @@ void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s)
 void ServerEnvironment::deactivateFarObjects(bool _force_delete)
 {
        std::vector<u16> objects_to_remove;
-       for (ServerActiveObjectMap::iterator i = m_active_objects.begin();
-               i != m_active_objects.end(); ++i) {
+       for (auto &ao_it : m_active_objects) {
                // force_delete might be overriden per object
                bool force_delete = _force_delete;
 
-               ServerActiveObject* obj = i->second;
+               ServerActiveObject* obj = ao_it.second;
                assert(obj);
 
                // Do not deactivate if static data creation not allowed
@@ -1972,7 +1915,7 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete)
                if(!force_delete && obj->m_pending_deactivation)
                        continue;
 
-               u16 id = i->first;
+               u16 id = ao_it.first;
                v3f objectpos = obj->getBasePosition();
 
                // The block in which the object resides in
@@ -1997,7 +1940,7 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete)
                                        <<std::endl;
                                continue;
                        }
-                       std::string staticdata_new = "";
+                       std::string staticdata_new;
                        obj->getStaticData(&staticdata_new);
                        StaticObject s_obj(obj->getType(), objectpos, staticdata_new);
                        block->m_static_objects.insert(id, s_obj);
@@ -2038,7 +1981,7 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete)
                if(obj->isStaticAllowed())
                {
                        // Create new static object
-                       std::string staticdata_new = "";
+                       std::string staticdata_new;
                        obj->getStaticData(&staticdata_new);
                        StaticObject s_obj(obj->getType(), objectpos, staticdata_new);
 
@@ -2179,9 +2122,8 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete)
        }
 
        // Remove references from m_active_objects
-       for(std::vector<u16>::iterator i = objects_to_remove.begin();
-               i != objects_to_remove.end(); ++i) {
-               m_active_objects.erase(*i);
+       for (u16 i : objects_to_remove) {
+               m_active_objects.erase(i);
        }
 }
 
@@ -2191,19 +2133,20 @@ PlayerDatabase *ServerEnvironment::openPlayerDatabase(const std::string &name,
 
        if (name == "sqlite3")
                return new PlayerDatabaseSQLite3(savedir);
-       else if (name == "dummy")
+
+       if (name == "dummy")
                return new Database_Dummy();
 #if USE_POSTGRESQL
-       else if (name == "postgresql") {
-               std::string connect_string = "";
+       if (name == "postgresql") {
+               std::string connect_string;
                conf.getNoEx("pgsql_player_connection", connect_string);
                return new PlayerDatabasePostgreSQL(connect_string);
        }
 #endif
-       else if (name == "files")
+       if (name == "files")
                return new PlayerDatabaseFiles(savedir + DIR_DELIM + "players");
-       else
-               throw BaseException(std::string("Database backend ") + name + " not supported.");
+
+       throw BaseException(std::string("Database backend ") + name + " not supported.");
 }
 
 bool ServerEnvironment::migratePlayersDatabase(const GameParams &game_params,
index 36f3e20673bba32b6502438078ed75b4c24f5bf8..9d84d7a480c82108e7428211b8372fcb6cc03405 100644 (file)
@@ -49,8 +49,8 @@ class ServerScripting;
 class ActiveBlockModifier
 {
 public:
-       ActiveBlockModifier(){};
-       virtual ~ActiveBlockModifier(){};
+       ActiveBlockModifier() = default;
+       virtual ~ActiveBlockModifier() = default;
 
        // Set of contents to trigger on
        virtual const std::set<std::string> &getTriggerContents() const = 0;
@@ -84,7 +84,8 @@ struct LoadingBlockModifierDef
        std::string name;
        bool run_at_every_load = false;
 
-       virtual ~LoadingBlockModifierDef() {}
+       virtual ~LoadingBlockModifierDef() = default;
+
        virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n){};
 };
 
@@ -106,7 +107,7 @@ struct LBMContentMapping
 class LBMManager
 {
 public:
-       LBMManager() {}
+       LBMManager() = default;
        ~LBMManager();
 
        // Don't call this after loadIntroductionTimes() ran.
index cc38ec8ce5889dd440689536eec5bb5be14f2b02..ae3bd98a40081e169732551e881cff473037a419 100644 (file)
@@ -89,9 +89,9 @@ std::vector<ServerListSpec> getOnline()
                return server_list;
        }
 
-       for (unsigned int i = 0; i < root.size(); i++) {
-               if (root[i].isObject()) {
-                       server_list.push_back(root[i]);
+       for (const Json::Value &i : root) {
+               if (i.isObject()) {
+                       server_list.push_back(i);
                }
        }
 
@@ -167,14 +167,12 @@ std::vector<ServerListSpec> deSerialize(const std::string &liststring)
 const std::string serialize(const std::vector<ServerListSpec> &serverlist)
 {
        std::string liststring;
-       for (std::vector<ServerListSpec>::const_iterator it = serverlist.begin();
-                       it != serverlist.end();
-                       ++it) {
+       for (const ServerListSpec &it : serverlist) {
                liststring += "[server]\n";
-               liststring += (*it)["name"].asString() + '\n';
-               liststring += (*it)["address"].asString() + '\n';
-               liststring += (*it)["port"].asString() + '\n';
-               liststring += (*it)["description"].asString() + '\n';
+               liststring += it["name"].asString() + '\n';
+               liststring += it["address"].asString() + '\n';
+               liststring += it["port"].asString() + '\n';
+               liststring += it["description"].asString() + '\n';
                liststring += '\n';
        }
        return liststring;
@@ -184,10 +182,8 @@ const std::string serializeJson(const std::vector<ServerListSpec> &serverlist)
 {
        Json::Value root;
        Json::Value list(Json::arrayValue);
-       for (std::vector<ServerListSpec>::const_iterator it = serverlist.begin();
-                       it != serverlist.end();
-                       ++it) {
-               list.append(*it);
+       for (const ServerListSpec &it : serverlist) {
+               list.append(it);
        }
        root["list"] = list;
        Json::FastWriter writer;
@@ -231,12 +227,11 @@ void sendAnnounce(AnnounceAction action,
                server["clients"]      = (int) clients_names.size();
                server["clients_max"]  = g_settings->getU16("max_users");
                server["clients_list"] = Json::Value(Json::arrayValue);
-               for (std::vector<std::string>::const_iterator it = clients_names.begin();
-                               it != clients_names.end();
-                               ++it) {
-                       server["clients_list"].append(*it);
+               for (const std::string &clients_name : clients_names) {
+                       server["clients_list"].append(clients_name);
                }
-               if (gameid != "") server["gameid"] = gameid;
+               if (!gameid.empty())
+                       server["gameid"] = gameid;
        }
 
        if (action == AA_START) {
@@ -246,9 +241,8 @@ void sendAnnounce(AnnounceAction action,
                server["privs"]             = g_settings->get("default_privs");
                server["can_see_far_names"] = g_settings->getS16("player_transfer_distance") <= 0;
                server["mods"]              = Json::Value(Json::arrayValue);
-               for (std::vector<ModSpec>::const_iterator it = mods.begin();
-                               it != mods.end(); ++it) {
-                       server["mods"].append(it->name);
+               for (const ModSpec &mod : mods) {
+                       server["mods"].append(mod.name);
                }
                actionstream << "Announcing to " << g_settings->get("serverlist_url") << std::endl;
        } else if (action == AA_UPDATE) {
index f98290beaaaf334ac5aa0fb76a5d26bda834b76b..4eebc0da4e21554cff5f7d2b9434964a3aa96103 100644 (file)
@@ -30,10 +30,6 @@ ServerActiveObject::ServerActiveObject(ServerEnvironment *env, v3f pos):
 {
 }
 
-ServerActiveObject::~ServerActiveObject()
-{
-}
-
 ServerActiveObject* ServerActiveObject::create(ActiveObjectType type,
                ServerEnvironment *env, u16 id, v3f pos,
                const std::string &data)
index 140ff9f4ac2118347306760acc18fa2d12c27662..7d87a0f59ba960bccca7989fed8a5eae70ec0602 100644 (file)
@@ -55,7 +55,7 @@ public:
                Prototypes are used that way.
        */
        ServerActiveObject(ServerEnvironment *env, v3f pos);
-       virtual ~ServerActiveObject();
+       virtual ~ServerActiveObject() = default;
 
        virtual ActiveObjectType getSendType() const
        { return getType(); }
index 1fa4ac52837aea4282702ea352acab5888c42623..ea54ab3488de1785b058eca7f3af6c47c03d9557 100644 (file)
@@ -169,9 +169,8 @@ void Settings::writeLines(std::ostream &os, u32 tab_depth) const
 {
        MutexAutoLock lock(m_mutex);
 
-       for (SettingEntries::const_iterator it = m_settings.begin();
-                       it != m_settings.end(); ++it)
-               printEntry(os, it->first, it->second, tab_depth);
+       for (const auto &setting_it : m_settings)
+               printEntry(os, setting_it.first, setting_it.second, tab_depth);
 }
 
 
@@ -323,7 +322,7 @@ bool Settings::parseCommandLine(int argc, char *argv[],
 
                ValueType type = n->second.type;
 
-               std::string value = "";
+               std::string value;
 
                if (type == VALUETYPE_FLAG) {
                        value = "true";
@@ -506,7 +505,7 @@ bool Settings::getNoiseParamsFromValue(const std::string &name,
        np.persist  = stof(f.next(","));
 
        std::string optional_params = f.next("");
-       if (optional_params != "")
+       if (!optional_params.empty())
                np.lacunarity = stof(optional_params);
 
        return true;
@@ -549,9 +548,8 @@ bool Settings::exists(const std::string &name) const
 std::vector<std::string> Settings::getNames() const
 {
        std::vector<std::string> names;
-       for (SettingEntries::const_iterator i = m_settings.begin();
-                       i != m_settings.end(); ++i) {
-               names.push_back(i->first);
+       for (const auto &settings_it : m_settings) {
+               names.push_back(settings_it.first);
        }
        return names;
 }
@@ -861,9 +859,9 @@ bool Settings::remove(const std::string &name)
                delete it->second.group;
                m_settings.erase(it);
                return true;
-       } else {
-               return false;
        }
+
+       return false;
 }
 
 
@@ -887,8 +885,7 @@ void Settings::updateValue(const Settings &other, const std::string &name)
        MutexAutoLock lock(m_mutex);
 
        try {
-               std::string val = other.get(name);
-               m_settings[name] = val;
+               m_settings[name] = other.get(name);
        } catch (SettingNotFoundException &e) {
        }
 }
@@ -965,7 +962,7 @@ void Settings::registerChangedCallback(const std::string &name,
        SettingsChangedCallback cbf, void *userdata)
 {
        MutexAutoLock lock(m_callback_mutex);
-       m_callbacks[name].push_back(std::make_pair(cbf, userdata));
+       m_callbacks[name].emplace_back(cbf, userdata);
 }
 
 void Settings::deregisterChangedCallback(const std::string &name,
index 4c128b7b87354fa2f9e22e036c22fa01a39808a3..e01e86475b83c5d9a4dfe769ed09dc58dcef751c 100644 (file)
@@ -72,7 +72,7 @@ struct ValueSpec {
 };
 
 struct SettingsEntry {
-       SettingsEntry() {}
+       SettingsEntry() = default;
 
        SettingsEntry(const std::string &value_) :
                value(value_)
@@ -92,7 +92,8 @@ typedef std::unordered_map<std::string, SettingsEntry> SettingEntries;
 
 class Settings {
 public:
-       Settings() {}
+       Settings() = default;
+
        ~Settings();
 
        Settings & operator += (const Settings &other);
index e6e5e7b1fc097e2d3167215ef5f9056f766391e1..69ea4376c495d59c3adbcaddb2623cd57761ca78 100644 (file)
@@ -56,7 +56,7 @@ std::string getShaderPath(const std::string &name_of_shader,
                const std::string &filename)
 {
        std::string combined = name_of_shader + DIR_DELIM + filename;
-       std::string fullpath = "";
+       std::string fullpath;
        /*
                Check from cache
        */
@@ -68,8 +68,7 @@ std::string getShaderPath(const std::string &name_of_shader,
                Check from shader_path
        */
        std::string shader_path = g_settings->get("shader_path");
-       if(shader_path != "")
-       {
+       if (!shader_path.empty()) {
                std::string testpath = shader_path + DIR_DELIM + combined;
                if(fs::PathExists(testpath))
                        fullpath = testpath;
@@ -78,8 +77,7 @@ std::string getShaderPath(const std::string &name_of_shader,
        /*
                Check from default data directory
        */
-       if(fullpath == "")
-       {
+       if (fullpath.empty()) {
                std::string rel_path = std::string("client") + DIR_DELIM
                                + "shaders" + DIR_DELIM
                                + name_of_shader + DIR_DELIM
@@ -110,9 +108,9 @@ public:
                // Try to use local shader instead if asked to
                if(prefer_local){
                        std::string path = getShaderPath(name_of_shader, filename);
-                       if(path != ""){
+                       if(!path.empty()){
                                std::string p = readFile(path);
-                               if(p != ""){
+                               if (!p.empty()) {
                                        m_programs[combined] = p;
                                        return;
                                }
@@ -140,7 +138,7 @@ public:
                if (n != m_programs.end())
                        return n->second;
                std::string path = getShaderPath(name_of_shader, filename);
-               if (path == "") {
+               if (path.empty()) {
                        infostream << "SourceShaderCache::getOrLoad(): No path found for \""
                                << combined << "\"" << std::endl;
                        return "";
@@ -148,7 +146,7 @@ public:
                infostream << "SourceShaderCache::getOrLoad(): Loading path \""
                        << path << "\"" << std::endl;
                std::string p = readFile(path);
-               if (p != "") {
+               if (!p.empty()) {
                        m_programs[combined] = p;
                        return p;
                }
@@ -180,14 +178,14 @@ class ShaderCallback : public video::IShaderConstantSetCallBack
 public:
        ShaderCallback(const std::vector<IShaderConstantSetterFactory *> &factories)
        {
-               for (u32 i = 0; i < factories.size(); ++i)
-                       m_setters.push_back(factories[i]->create());
+               for (IShaderConstantSetterFactory *factory : factories)
+                       m_setters.push_back(factory->create());
        }
 
        ~ShaderCallback()
        {
-               for (u32 i = 0; i < m_setters.size(); ++i)
-                       delete m_setters[i];
+               for (IShaderConstantSetter *setter : m_setters)
+                       delete setter;
        }
 
        virtual void OnSetConstants(video::IMaterialRendererServices *services, s32 userData)
@@ -197,8 +195,8 @@ public:
 
                bool is_highlevel = userData;
 
-               for (u32 i = 0; i < m_setters.size(); ++i)
-                       m_setters[i]->onSetConstants(services, is_highlevel);
+               for (IShaderConstantSetter *setter : m_setters)
+                       setter->onSetConstants(services, is_highlevel);
        }
 };
 
@@ -217,7 +215,7 @@ public:
                m_world_view_proj("mWorldViewProj"),
                m_world("mWorld")
        {}
-       ~MainShaderConstantSetter() {}
+       ~MainShaderConstantSetter() = default;
 
        virtual void onSetConstants(video::IMaterialRendererServices *services,
                        bool is_highlevel)
@@ -357,7 +355,7 @@ ShaderSource::ShaderSource()
        m_main_thread = std::this_thread::get_id();
 
        // Add a dummy ShaderInfo as the first index, named ""
-       m_shaderinfo_cache.push_back(ShaderInfo());
+       m_shaderinfo_cache.emplace_back();
 
        // Add main global constant setter
        addShaderConstantSetterFactory(new MainShaderConstantSetterFactory());
@@ -365,13 +363,11 @@ ShaderSource::ShaderSource()
 
 ShaderSource::~ShaderSource()
 {
-       for (std::vector<ShaderCallback *>::iterator iter = m_callbacks.begin();
-                       iter != m_callbacks.end(); ++iter) {
-               delete *iter;
+       for (ShaderCallback *callback : m_callbacks) {
+               delete callback;
        }
-       for (std::vector<IShaderConstantSetterFactory *>::iterator iter = m_setter_factories.begin();
-                       iter != m_setter_factories.end(); ++iter) {
-               delete *iter;
+       for (IShaderConstantSetterFactory *setter_factorie : m_setter_factories) {
+               delete setter_factorie;
        }
 }
 
@@ -384,34 +380,32 @@ u32 ShaderSource::getShader(const std::string &name,
 
        if (std::this_thread::get_id() == m_main_thread) {
                return getShaderIdDirect(name, material_type, drawtype);
-       } else {
-               /*errorstream<<"getShader(): Queued: name=\""<<name<<"\""<<std::endl;*/
+       }
 
-               // We're gonna ask the result to be put into here
+       /*errorstream<<"getShader(): Queued: name=\""<<name<<"\""<<std::endl;*/
 
-               static ResultQueue<std::string, u32, u8, u8> result_queue;
+       // We're gonna ask the result to be put into here
 
-               // Throw a request in
-               m_get_shader_queue.add(name, 0, 0, &result_queue);
+       static ResultQueue<std::string, u32, u8, u8> result_queue;
 
-               /* infostream<<"Waiting for shader from main thread, name=\""
-                               <<name<<"\""<<std::endl;*/
+       // Throw a request in
+       m_get_shader_queue.add(name, 0, 0, &result_queue);
 
-               while(true) {
-                       GetResult<std::string, u32, u8, u8>
-                               result = result_queue.pop_frontNoEx();
+       /* infostream<<"Waiting for shader from main thread, name=\""
+                       <<name<<"\""<<std::endl;*/
 
-                       if (result.key == name) {
-                               return result.item;
-                       }
-                       else {
-                               errorstream << "Got shader with invalid name: " << result.key << std::endl;
-                       }
+       while(true) {
+               GetResult<std::string, u32, u8, u8>
+                       result = result_queue.pop_frontNoEx();
+
+               if (result.key == name) {
+                       return result.item;
                }
 
+               errorstream << "Got shader with invalid name: " << result.key << std::endl;
        }
 
-       infostream<<"getShader(): Failed"<<std::endl;
+       infostream << "getShader(): Failed" << std::endl;
 
        return 0;
 }
@@ -425,7 +419,7 @@ u32 ShaderSource::getShaderIdDirect(const std::string &name,
        //infostream<<"getShaderIdDirect(): name=\""<<name<<"\""<<std::endl;
 
        // Empty name means shader 0
-       if(name == ""){
+       if (name.empty()) {
                infostream<<"getShaderIdDirect(): name is empty"<<std::endl;
                return 0;
        }
@@ -509,9 +503,9 @@ void ShaderSource::rebuildShaders()
        */
 
        // Recreate shaders
-       for(u32 i=0; i<m_shaderinfo_cache.size(); i++){
-               ShaderInfo *info = &m_shaderinfo_cache[i];
-               if(info->name != ""){
+       for (ShaderInfo &i : m_shaderinfo_cache) {
+               ShaderInfo *info = &i;
+               if (!info->name.empty()) {
                        *info = generate_shader(info->name, info->material_type,
                                        info->drawtype, m_callbacks,
                                        m_setter_factories, &m_sourcecache);
@@ -571,7 +565,7 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
                        enable_shaders, vertex_program, pixel_program,
                        geometry_program, is_highlevel);
        // Check hardware/driver support
-       if(vertex_program != "" &&
+       if (!vertex_program.empty() &&
                        !driver->queryFeature(video::EVDF_VERTEX_SHADER_1_1) &&
                        !driver->queryFeature(video::EVDF_ARB_VERTEX_PROGRAM_1)){
                infostream<<"generate_shader(): vertex shaders disabled "
@@ -579,7 +573,7 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
                                <<std::endl;
                vertex_program = "";
        }
-       if(pixel_program != "" &&
+       if (!pixel_program.empty() &&
                        !driver->queryFeature(video::EVDF_PIXEL_SHADER_1_1) &&
                        !driver->queryFeature(video::EVDF_ARB_FRAGMENT_PROGRAM_1)){
                infostream<<"generate_shader(): pixel shaders disabled "
@@ -587,7 +581,7 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
                                <<std::endl;
                pixel_program = "";
        }
-       if(geometry_program != "" &&
+       if (!geometry_program.empty() &&
                        !driver->queryFeature(video::EVDF_GEOMETRY_SHADER)){
                infostream<<"generate_shader(): geometry shaders disabled "
                                "because of missing driver/hardware support."
@@ -596,7 +590,7 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
        }
 
        // If no shaders are used, don't make a separate material type
-       if(vertex_program == "" && pixel_program == "" && geometry_program == "")
+       if (vertex_program.empty() && pixel_program.empty() && geometry_program.empty())
                return shaderinfo;
 
        // Create shaders header
@@ -852,7 +846,7 @@ void load_shaders(std::string name, SourceShaderCache *sourcecache,
                        pixel_program = sourcecache->getOrLoad(name, "opengl_fragment.glsl");
                        geometry_program = sourcecache->getOrLoad(name, "opengl_geometry.glsl");
                }
-               if(vertex_program != "" || pixel_program != "" || geometry_program != ""){
+               if (!vertex_program.empty() || !pixel_program.empty() || !geometry_program.empty()){
                        is_highlevel = true;
                        return;
                }
@@ -868,7 +862,7 @@ void dumpShaderProgram(std::ostream &output_stream,
        size_t pos = 0;
        size_t prev = 0;
        s16 line = 1;
-       while ((pos = program.find("\n", prev)) != std::string::npos) {
+       while ((pos = program.find('\n', prev)) != std::string::npos) {
                output_stream << line++ << ": "<< program.substr(prev, pos - prev) <<
                        std::endl;
                prev = pos + 1;
index 7a7ee3e7bfe99531a995332342e72d296201a8e4..583c776f4fdfbca62746d98210bc4f93c6955f10 100644 (file)
@@ -49,8 +49,8 @@ struct ShaderInfo {
        u8 drawtype = 0;
        u8 material_type = 0;
 
-       ShaderInfo() {}
-       virtual ~ShaderInfo() {}
+       ShaderInfo() = default;
+       virtual ~ShaderInfo() = default;
 };
 
 /*
@@ -64,7 +64,7 @@ namespace irr { namespace video {
 
 class IShaderConstantSetter {
 public:
-       virtual ~IShaderConstantSetter(){};
+       virtual ~IShaderConstantSetter() = default;
        virtual void onSetConstants(video::IMaterialRendererServices *services,
                        bool is_highlevel) = 0;
 };
@@ -72,7 +72,7 @@ public:
 
 class IShaderConstantSetterFactory {
 public:
-       virtual ~IShaderConstantSetterFactory() {};
+       virtual ~IShaderConstantSetterFactory() = default;
        virtual IShaderConstantSetter* create() = 0;
 };
 
@@ -122,8 +122,9 @@ public:
 
 class IShaderSource {
 public:
-       IShaderSource(){}
-       virtual ~IShaderSource(){}
+       IShaderSource() = default;
+       virtual ~IShaderSource() = default;
+
        virtual u32 getShaderIdDirect(const std::string &name,
                const u8 material_type, const u8 drawtype){return 0;}
        virtual ShaderInfo getShaderInfo(u32 id){return ShaderInfo();}
@@ -133,8 +134,9 @@ public:
 
 class IWritableShaderSource : public IShaderSource {
 public:
-       IWritableShaderSource(){}
-       virtual ~IWritableShaderSource(){}
+       IWritableShaderSource() = default;
+       virtual ~IWritableShaderSource() = default;
+
        virtual u32 getShaderIdDirect(const std::string &name,
                const u8 material_type, const u8 drawtype){return 0;}
        virtual ShaderInfo getShaderInfo(u32 id){return ShaderInfo();}
index d92697f3041430fbbd0e30a47fd3d221f6e9ceb7..0bc344b3f36d243aa16bca0c360a070e42cb6bea 100644 (file)
@@ -68,13 +68,13 @@ Sky::Sky(s32 id, ITextureSource *tsrc):
                        m_materials[4].Lighting = true;
        }
 
-       for (u32 i = 0; i < SKY_STAR_COUNT; i++) {
-               m_stars[i] = v3f(
+       for (v3f &star : m_stars) {
+               star = v3f(
                        myrand_range(-10000, 10000),
                        myrand_range(-10000, 10000),
                        myrand_range(-10000, 10000)
                );
-               m_stars[i].normalize();
+               star.normalize();
        }
 
        m_directional_colored_fog = g_settings->getBool("directional_colored_fog");
@@ -184,19 +184,19 @@ void Sky::render()
                        vertices[1] = video::S3DVertex( 1, 0.08, -1, 0, 0, 1, c, o, t);
                        vertices[2] = video::S3DVertex( 1, 0.12, -1, 0, 0, 1, c, o, o);
                        vertices[3] = video::S3DVertex(-1, 0.12, -1, 0, 0, 1, c, t, o);
-                       for (u32 i = 0; i < 4; i++) {
+                       for (video::S3DVertex &vertex : vertices) {
                                if (j == 0)
                                        // Don't switch
                                        {}
                                else if (j == 1)
                                        // Switch from -Z (south) to +X (east)
-                                       vertices[i].Pos.rotateXZBy(90);
+                                       vertex.Pos.rotateXZBy(90);
                                else if (j == 2)
                                        // Switch from -Z (south) to -X (west)
-                                       vertices[i].Pos.rotateXZBy(-90);
+                                       vertex.Pos.rotateXZBy(-90);
                                else
                                        // Switch from -Z (south) to +Z (north)
-                                       vertices[i].Pos.rotateXZBy(-180);
+                                       vertex.Pos.rotateXZBy(-180);
                        }
                        driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
                }
@@ -208,19 +208,19 @@ void Sky::render()
                        vertices[1] = video::S3DVertex( 1, -1.0, -1, 0, 0, 1, c, o, t);
                        vertices[2] = video::S3DVertex( 1, 0.08, -1, 0, 0, 1, c, o, o);
                        vertices[3] = video::S3DVertex(-1, 0.08, -1, 0, 0, 1, c, t, o);
-                       for (u32 i = 0; i < 4; i++) {
+                       for (video::S3DVertex &vertex : vertices) {
                                if (j == 0)
                                        // Don't switch
                                        {}
                                else if (j == 1)
                                        // Switch from -Z (south) to +X (east)
-                                       vertices[i].Pos.rotateXZBy(90);
+                                       vertex.Pos.rotateXZBy(90);
                                else if (j == 2)
                                        // Switch from -Z (south) to -X (west)
-                                       vertices[i].Pos.rotateXZBy(-90);
+                                       vertex.Pos.rotateXZBy(-90);
                                else
                                        // Switch from -Z (south) to +Z (north)
-                                       vertices[i].Pos.rotateXZBy(-180);
+                                       vertex.Pos.rotateXZBy(-180);
                        }
                        driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
                }
@@ -252,13 +252,13 @@ void Sky::render()
                        vertices[1] = video::S3DVertex( 1, -0.05 + y, -1, 0, 0, 1, c, o, t);
                        vertices[2] = video::S3DVertex( 1,   0.2 + y, -1, 0, 0, 1, c, o, o);
                        vertices[3] = video::S3DVertex(-1,   0.2 + y, -1, 0, 0, 1, c, t, o);
-                       for (u32 i = 0; i < 4; i++) {
+                       for (video::S3DVertex &vertex : vertices) {
                                if (wicked_time_of_day < 0.5)
                                        // Switch from -Z (south) to +X (east)
-                                       vertices[i].Pos.rotateXZBy(90);
+                                       vertex.Pos.rotateXZBy(90);
                                else
                                        // Switch from -Z (south) to -X (west)
-                                       vertices[i].Pos.rotateXZBy(-90);
+                                       vertex.Pos.rotateXZBy(-90);
                        }
                        driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
                }
@@ -274,10 +274,10 @@ void Sky::render()
                                vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, c, o, t);
                                vertices[2] = video::S3DVertex( d,  d, -1, 0, 0, 1, c, o, o);
                                vertices[3] = video::S3DVertex(-d,  d, -1, 0, 0, 1, c, t, o);
-                               for (u32 i = 0; i < 4; i++) {
+                               for (video::S3DVertex &vertex : vertices) {
                                        // Switch from -Z (south) to +X (east)
-                                       vertices[i].Pos.rotateXZBy(90);
-                                       vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+                                       vertex.Pos.rotateXZBy(90);
+                                       vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
                                }
                                driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
 
@@ -288,10 +288,10 @@ void Sky::render()
                                vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, c, o, t);
                                vertices[2] = video::S3DVertex( d,  d, -1, 0, 0, 1, c, o, o);
                                vertices[3] = video::S3DVertex(-d,  d, -1, 0, 0, 1, c, t, o);
-                               for (u32 i = 0; i < 4; i++) {
+                               for (video::S3DVertex &vertex : vertices) {
                                        // Switch from -Z (south) to +X (east)
-                                       vertices[i].Pos.rotateXZBy(90);
-                                       vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+                                       vertex.Pos.rotateXZBy(90);
+                                       vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
                                }
                                driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
 
@@ -300,10 +300,10 @@ void Sky::render()
                                vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, suncolor, o, t);
                                vertices[2] = video::S3DVertex( d,  d, -1, 0, 0, 1, suncolor, o, o);
                                vertices[3] = video::S3DVertex(-d,  d, -1, 0, 0, 1, suncolor, t, o);
-                               for (u32 i = 0; i < 4; i++) {
+                               for (video::S3DVertex &vertex : vertices) {
                                        // Switch from -Z (south) to +X (east)
-                                       vertices[i].Pos.rotateXZBy(90);
-                                       vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+                                       vertex.Pos.rotateXZBy(90);
+                                       vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
                                }
                                driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
 
@@ -312,10 +312,10 @@ void Sky::render()
                                vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, suncolor2, o, t);
                                vertices[2] = video::S3DVertex( d,  d, -1, 0, 0, 1, suncolor2, o, o);
                                vertices[3] = video::S3DVertex(-d,  d, -1, 0, 0, 1, suncolor2, t, o);
-                               for (u32 i = 0; i < 4; i++) {
+                               for (video::S3DVertex &vertex : vertices) {
                                        // Switch from -Z (south) to +X (east)
-                                       vertices[i].Pos.rotateXZBy(90);
-                                       vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+                                       vertex.Pos.rotateXZBy(90);
+                                       vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
                                }
                                driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
                        } else {
@@ -330,10 +330,10 @@ void Sky::render()
                                vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, c, o, t);
                                vertices[2] = video::S3DVertex( d,  d, -1, 0, 0, 1, c, o, o);
                                vertices[3] = video::S3DVertex(-d,  d, -1, 0, 0, 1, c, t, o);
-                               for(u32 i = 0; i < 4; i++) {
+                               for (video::S3DVertex &vertex : vertices) {
                                        // Switch from -Z (south) to +X (east)
-                                       vertices[i].Pos.rotateXZBy(90);
-                                       vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+                                       vertex.Pos.rotateXZBy(90);
+                                       vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
                                }
                                driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
                        }
@@ -350,10 +350,10 @@ void Sky::render()
                                vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, c, o, t);
                                vertices[2] = video::S3DVertex( d,  d, -1, 0, 0, 1, c, o, o);
                                vertices[3] = video::S3DVertex(-d,  d, -1, 0, 0, 1, c, t, o);
-                               for (u32 i = 0; i < 4; i++) {
+                               for (video::S3DVertex &vertex : vertices) {
                                        // Switch from -Z (south) to -X (west)
-                                       vertices[i].Pos.rotateXZBy(-90);
-                                       vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+                                       vertex.Pos.rotateXZBy(-90);
+                                       vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
                                }
                                driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
 
@@ -364,10 +364,10 @@ void Sky::render()
                                vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, c, o, t);
                                vertices[2] = video::S3DVertex( d,  d, -1, 0, 0, 1, c, o, o);
                                vertices[3] = video::S3DVertex(-d,  d, -1, 0, 0, 1, c, t, o);
-                               for (u32 i = 0; i < 4; i++) {
+                               for (video::S3DVertex &vertex : vertices) {
                                        // Switch from -Z (south) to -X (west)
-                                       vertices[i].Pos.rotateXZBy(-90);
-                                       vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+                                       vertex.Pos.rotateXZBy(-90);
+                                       vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
                                }
                                driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
 
@@ -376,10 +376,10 @@ void Sky::render()
                                vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, mooncolor, o, t);
                                vertices[2] = video::S3DVertex( d,  d, -1, 0, 0, 1, mooncolor, o, o);
                                vertices[3] = video::S3DVertex(-d,  d, -1, 0, 0, 1, mooncolor, t, o);
-                               for (u32 i = 0; i < 4; i++) {
+                               for (video::S3DVertex &vertex : vertices) {
                                        // Switch from -Z (south) to -X (west)
-                                       vertices[i].Pos.rotateXZBy(-90);
-                                       vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+                                       vertex.Pos.rotateXZBy(-90);
+                                       vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
                                }
                                driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
 
@@ -388,10 +388,10 @@ void Sky::render()
                                vertices[1] = video::S3DVertex( d2,-d,  -1, 0, 0, 1, mooncolor2, o, t);
                                vertices[2] = video::S3DVertex( d2, d2, -1, 0, 0, 1, mooncolor2, o, o);
                                vertices[3] = video::S3DVertex(-d,  d2, -1, 0, 0, 1, mooncolor2, t, o);
-                               for (u32 i = 0; i < 4; i++) {
+                               for (video::S3DVertex &vertex : vertices) {
                                        // Switch from -Z (south) to -X (west)
-                                       vertices[i].Pos.rotateXZBy(-90);
-                                       vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+                                       vertex.Pos.rotateXZBy(-90);
+                                       vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
                                }
                                driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
                        } else {
@@ -406,10 +406,10 @@ void Sky::render()
                                vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, c, o, t);
                                vertices[2] = video::S3DVertex( d,  d, -1, 0, 0, 1, c, o, o);
                                vertices[3] = video::S3DVertex(-d,  d, -1, 0, 0, 1, c, t, o);
-                               for (u32 i = 0; i < 4; i++) {
+                               for (video::S3DVertex &vertex : vertices) {
                                        // Switch from -Z (south) to -X (west)
-                                       vertices[i].Pos.rotateXZBy(-90);
-                                       vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+                                       vertex.Pos.rotateXZBy(-90);
+                                       vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
                                }
                                driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
                        }
@@ -469,14 +469,14 @@ void Sky::render()
                        vertices[1] = video::S3DVertex( 1, -1.0,  -1, 0, 0, 1, c, o, t);
                        vertices[2] = video::S3DVertex( 1, -0.02, -1, 0, 0, 1, c, o, o);
                        vertices[3] = video::S3DVertex(-1, -0.02, -1, 0, 0, 1, c, t, o);
-                       for (u32 i = 0; i < 4; i++) {
+                       for (video::S3DVertex &vertex : vertices) {
                                //if (wicked_time_of_day < 0.5)
                                if (j == 0)
                                        // Switch from -Z (south) to +X (east)
-                                       vertices[i].Pos.rotateXZBy(90);
+                                       vertex.Pos.rotateXZBy(90);
                                else
                                        // Switch from -Z (south) to -X (west)
-                                       vertices[i].Pos.rotateXZBy(-90);
+                                       vertex.Pos.rotateXZBy(-90);
                        }
                        driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
                }
index 489818123b61c7927651b6acfd1a4c7fe763c719..2264679ed78f8361b73a556a115726cf63478395 100644 (file)
@@ -32,7 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #endif
 
 #include <ostream>
-#include <string.h>
+#include <cstring>
 #include "irrlichttypes.h"
 #include "exceptions.h"
 
@@ -111,7 +111,8 @@ private:
 class UDPSocket
 {
 public:
-       UDPSocket() { }
+       UDPSocket() = default;
+
        UDPSocket(bool ipv6);
        ~UDPSocket();
        void Bind(Address addr);
index 1772ee817f8fc81e8675215ea9421d280ab1da5e..adae0c769a4b0adafb419b13cd0b0719214cc187 100644 (file)
@@ -37,7 +37,7 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
        #include <AL/alext.h>
 #endif
 #include <vorbis/vorbisfile.h>
-#include <assert.h>
+#include <cassert>
 #include "log.h"
 #include "util/numeric.h" // myrand()
 #include "porting.h"