Skip to content

Commit

Permalink
Code modernization: src/p*, src/q*, src/r*, src/s* (partial) (#6282)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nerzhul committed Aug 19, 2017
1 parent 1992db1 commit 7528986
Show file tree
Hide file tree
Showing 28 changed files with 355 additions and 435 deletions.
68 changes: 34 additions & 34 deletions src/content_mapblock.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down
8 changes: 4 additions & 4 deletions src/mapblock_mesh.cpp
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/mapnode.cpp
Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion src/player.h
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/porting.cpp
Expand Up @@ -59,7 +59,7 @@ namespace porting

bool g_killed = false;

bool * signal_handler_killstatus(void)
bool *signal_handler_killstatus()
{
return &g_killed;
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 6 additions & 5 deletions src/porting.h
Expand Up @@ -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__)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/porting_android.cpp
Expand Up @@ -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"
Expand Down
9 changes: 3 additions & 6 deletions src/profiler.h
Expand Up @@ -42,7 +42,7 @@ extern Profiler *g_profiler;
class Profiler
{
public:
Profiler() {}
Profiler() = default;

void add(const std::string &name, float value)
{
Expand Down Expand Up @@ -80,11 +80,8 @@ class Profiler
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();
}
Expand Down
10 changes: 4 additions & 6 deletions src/quicktune.h
Expand Up @@ -58,20 +58,18 @@ enum QuicktuneValueType{
};
struct QuicktuneValue
{
QuicktuneValueType type;
QuicktuneValueType type = QVT_NONE;
union{
struct{
float current;
float min;
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);
};
Expand Down
6 changes: 3 additions & 3 deletions src/quicktune_shortcutter.h
Expand Up @@ -28,16 +28,16 @@ class QuicktuneShortcutter
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 "";
}
Expand Down
8 changes: 5 additions & 3 deletions src/raycast.cpp
Expand Up @@ -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;
Expand Down
13 changes: 6 additions & 7 deletions src/remoteplayer.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {}
}
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/remoteplayer.h
Expand Up @@ -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);

Expand Down

0 comments on commit 7528986

Please sign in to comment.