Code modernization: src/p*, src/q*, src/r*, src/s* (partial) (#6282)

* 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
This commit is contained in:
Loïc Blot 2017-08-19 14:25:35 +02:00 committed by GitHub
parent 1992db1395
commit 7528986e44
28 changed files with 363 additions and 443 deletions

View File

@ -582,9 +582,9 @@ void MapblockMeshGenerator::drawLiquidTop()
tcoord_translate.X -= floor(tcoord_translate.X); tcoord_translate.X -= floor(tcoord_translate.X);
tcoord_translate.Y -= floor(tcoord_translate.Y); tcoord_translate.Y -= floor(tcoord_translate.Y);
for (auto &vertice : vertices) { for (video::S3DVertex &vertex : vertices) {
vertice.TCoords.rotateBy(tcoord_angle, tcoord_center); vertex.TCoords.rotateBy(tcoord_angle, tcoord_center);
vertice.TCoords += tcoord_translate; vertex.TCoords += tcoord_translate;
} }
std::swap(vertices[0].TCoords, vertices[2].TCoords); std::swap(vertices[0].TCoords, vertices[2].TCoords);
@ -622,20 +622,20 @@ void MapblockMeshGenerator::drawGlasslikeNode()
v3f(-BS / 2, -BS / 2, -BS / 2), v3f(-BS / 2, -BS / 2, -BS / 2),
}; };
for (auto &vertice : vertices) { for (v3f &vertex : vertices) {
switch (face) { switch (face) {
case D6D_ZP: case D6D_ZP:
vertice.rotateXZBy(180); break; vertex.rotateXZBy(180); break;
case D6D_YP: case D6D_YP:
vertice.rotateYZBy( 90); break; vertex.rotateYZBy( 90); break;
case D6D_XP: case D6D_XP:
vertice.rotateXZBy( 90); break; vertex.rotateXZBy( 90); break;
case D6D_ZN: case D6D_ZN:
vertice.rotateXZBy( 0); break; vertex.rotateXZBy( 0); break;
case D6D_YN: case D6D_YN:
vertice.rotateYZBy(-90); break; vertex.rotateYZBy(-90); break;
case D6D_XN: case D6D_XN:
vertice.rotateXZBy(-90); break; vertex.rotateXZBy(-90); break;
} }
} }
drawQuad(vertices, dir); drawQuad(vertices, dir);
@ -795,20 +795,20 @@ void MapblockMeshGenerator::drawTorchlikeNode()
v3f(-size, -size, 0), v3f(-size, -size, 0),
}; };
for (auto &vertice : vertices) { for (v3f &vertex : vertices) {
switch (wall) { switch (wall) {
case DWM_YP: case DWM_YP:
vertice.rotateXZBy(-45); break; vertex.rotateXZBy(-45); break;
case DWM_YN: case DWM_YN:
vertice.rotateXZBy( 45); break; vertex.rotateXZBy( 45); break;
case DWM_XP: case DWM_XP:
vertice.rotateXZBy( 0); break; vertex.rotateXZBy( 0); break;
case DWM_XN: case DWM_XN:
vertice.rotateXZBy(180); break; vertex.rotateXZBy(180); break;
case DWM_ZP: case DWM_ZP:
vertice.rotateXZBy( 90); break; vertex.rotateXZBy( 90); break;
case DWM_ZN: case DWM_ZN:
vertice.rotateXZBy(-90); break; vertex.rotateXZBy(-90); break;
} }
} }
drawQuad(vertices); drawQuad(vertices);
@ -828,20 +828,20 @@ void MapblockMeshGenerator::drawSignlikeNode()
v3f(BS / 2 - offset, -size, size), v3f(BS / 2 - offset, -size, size),
}; };
for (auto &vertice : vertices) { for (v3f &vertex : vertices) {
switch (wall) { switch (wall) {
case DWM_YP: case DWM_YP:
vertice.rotateXYBy( 90); break; vertex.rotateXYBy( 90); break;
case DWM_YN: case DWM_YN:
vertice.rotateXYBy(-90); break; vertex.rotateXYBy(-90); break;
case DWM_XP: case DWM_XP:
vertice.rotateXZBy( 0); break; vertex.rotateXZBy( 0); break;
case DWM_XN: case DWM_XN:
vertice.rotateXZBy(180); break; vertex.rotateXZBy(180); break;
case DWM_ZP: case DWM_ZP:
vertice.rotateXZBy( 90); break; vertex.rotateXZBy( 90); break;
case DWM_ZN: case DWM_ZN:
vertice.rotateXZBy(-90); break; vertex.rotateXZBy(-90); break;
} }
} }
drawQuad(vertices); drawQuad(vertices);
@ -864,9 +864,9 @@ void MapblockMeshGenerator::drawPlantlikeQuad(float rotation, float quad_offset,
for (int i = 0; i < offset_count; i++) for (int i = 0; i < offset_count; i++)
vertices[i].Z += quad_offset; vertices[i].Z += quad_offset;
for (auto &vertice : vertices) { for (v3f &vertex : vertices) {
vertice.rotateXZBy(rotation + rotate_degree); vertex.rotateXZBy(rotation + rotate_degree);
vertice += offset; vertex += offset;
} }
drawQuad(vertices, v3s16(0, 0, 0), plant_height); 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), v3f(-scale, -BS / 2, 0),
}; };
for (auto &vertice : vertices) { for (v3f &vertex : vertices) {
vertice.rotateYZBy(opening_angle); vertex.rotateYZBy(opening_angle);
vertice.Z += offset_h; vertex.Z += offset_h;
vertice.rotateXZBy(rotation); vertex.rotateXZBy(rotation);
vertice.Y += offset_v; vertex.Y += offset_v;
} }
drawQuad(vertices); drawQuad(vertices);
} }
@ -1192,8 +1192,8 @@ void MapblockMeshGenerator::drawRaillikeNode()
v3f(-size, -size + offset, -size), v3f(-size, -size + offset, -size),
}; };
if (angle) if (angle)
for (auto &vertice : vertices) for (v3f &vertex : vertices)
vertice.rotateXZBy(angle); vertex.rotateXZBy(angle);
drawQuad(vertices); drawQuad(vertices);
} }

View File

@ -1507,8 +1507,8 @@ void MeshCollector::applyTileColors()
video::SColor tc = pmb.layer.color; video::SColor tc = pmb.layer.color;
if (tc == video::SColor(0xFFFFFFFF)) if (tc == video::SColor(0xFFFFFFFF))
continue; continue;
for (auto &tangent_vertice : pmb.tangent_vertices) { for (video::S3DVertexTangents &tangent_vertex : pmb.tangent_vertices) {
video::SColor *c = &tangent_vertice.Color; video::SColor *c = &tangent_vertex.Color;
c->set(c->getAlpha(), c->getRed() * tc.getRed() / 255, c->set(c->getAlpha(), c->getRed() * tc.getRed() / 255,
c->getGreen() * tc.getGreen() / 255, c->getGreen() * tc.getGreen() / 255,
c->getBlue() * tc.getBlue() / 255); c->getBlue() * tc.getBlue() / 255);
@ -1521,8 +1521,8 @@ void MeshCollector::applyTileColors()
video::SColor tc = pmb.layer.color; video::SColor tc = pmb.layer.color;
if (tc == video::SColor(0xFFFFFFFF)) if (tc == video::SColor(0xFFFFFFFF))
continue; continue;
for (auto &vertice : pmb.vertices) { for (video::S3DVertex &vertex : pmb.vertices) {
video::SColor *c = &vertice.Color; video::SColor *c = &vertex.Color;
c->set(c->getAlpha(), c->getRed() * tc.getRed() / 255, c->set(c->getAlpha(), c->getRed() * tc.getRed() / 255,
c->getGreen() * tc.getGreen() / 255, c->getGreen() * tc.getGreen() / 255,
c->getBlue() * tc.getBlue() / 255); c->getBlue() * tc.getBlue() / 255);

View File

@ -397,15 +397,15 @@ void transformNodeBox(const MapNode &n, const NodeBox &nodebox,
nodebox.wall_side.MaxEdge nodebox.wall_side.MaxEdge
}; };
for (v3f &vertice : vertices) { for (v3f &vertex : vertices) {
if(dir == v3s16(-1,0,0)) if(dir == v3s16(-1,0,0))
vertice.rotateXZBy(0); vertex.rotateXZBy(0);
if(dir == v3s16(1,0,0)) if(dir == v3s16(1,0,0))
vertice.rotateXZBy(180); vertex.rotateXZBy(180);
if(dir == v3s16(0,0,-1)) if(dir == v3s16(0,0,-1))
vertice.rotateXZBy(90); vertex.rotateXZBy(90);
if(dir == v3s16(0,0,1)) if(dir == v3s16(0,0,1))
vertice.rotateXZBy(-90); vertex.rotateXZBy(-90);
} }
aabb3f box = aabb3f(vertices[0]); aabb3f box = aabb3f(vertices[0]);

View File

@ -33,7 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
struct PlayerControl struct PlayerControl
{ {
PlayerControl() {} PlayerControl() = default;
PlayerControl( PlayerControl(
bool a_up, bool a_up,

View File

@ -59,7 +59,7 @@ namespace porting
bool g_killed = false; bool g_killed = false;
bool * signal_handler_killstatus(void) bool *signal_handler_killstatus()
{ {
return &g_killed; return &g_killed;
} }
@ -167,7 +167,7 @@ bool detectMSVCBuildDir(const std::string &path)
"bin\\Build", "bin\\Build",
NULL NULL
}; };
return (removeStringEnd(path, ends) != ""); return (!removeStringEnd(path, ends).empty());
} }
std::string get_sysinfo() std::string get_sysinfo()
@ -388,7 +388,7 @@ bool setSystemPaths()
// It is identified by containing the subdirectory "builtin". // It is identified by containing the subdirectory "builtin".
std::list<std::string> trylist; std::list<std::string> trylist;
std::string static_sharedir = STATIC_SHAREDIR; 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(static_sharedir);
trylist.push_back(bindir + DIR_DELIM ".." DIR_DELIM "share" trylist.push_back(bindir + DIR_DELIM ".." DIR_DELIM "share"
@ -623,7 +623,7 @@ bool secure_rand_fill_buf(void *buf, size_t len)
#endif #endif
void attachOrCreateConsole(void) void attachOrCreateConsole()
{ {
#ifdef _WIN32 #ifdef _WIN32
static bool consoleAllocated = false; static bool consoleAllocated = false;

View File

@ -56,7 +56,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define sleep_ms(x) Sleep(x) #define sleep_ms(x) Sleep(x)
#else #else
#include <unistd.h> #include <unistd.h>
#include <stdint.h> //for uintptr_t #include <cstdint> //for uintptr_t
// Use standard Posix macro for Linux // Use standard Posix macro for Linux
#if (defined(linux) || defined(__linux)) && !defined(__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 #ifndef _WIN32 // Posix
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <ctime>
#if defined(__MACH__) && defined(__APPLE__)
#if defined(__MACH__) && defined(__APPLE__)
#include <mach/clock.h> #include <mach/clock.h>
#include <mach/mach.h> #include <mach/mach.h>
#endif #endif
@ -273,9 +274,9 @@ inline u64 getDeltaMs(u64 old_time_ms, u64 new_time_ms)
{ {
if (new_time_ms >= old_time_ms) { if (new_time_ms >= old_time_ms) {
return (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() inline const char *getPlatformName()

View File

@ -31,7 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <sstream> #include <sstream>
#include <exception> #include <exception>
#include <stdlib.h> #include <cstdlib>
#ifdef GPROF #ifdef GPROF
#include "prof.h" #include "prof.h"

View File

@ -42,7 +42,7 @@ extern Profiler *g_profiler;
class Profiler class Profiler
{ {
public: public:
Profiler() {} Profiler() = default;
void add(const std::string &name, float value) void add(const std::string &name, float value)
{ {
@ -80,11 +80,8 @@ public:
void clear() void clear()
{ {
MutexAutoLock lock(m_mutex); MutexAutoLock lock(m_mutex);
for(std::map<std::string, float>::iterator for (auto &it : m_data) {
i = m_data.begin(); it.second = 0;
i != m_data.end(); ++i)
{
i->second = 0;
} }
m_avgcounts.clear(); m_avgcounts.clear();
} }

View File

@ -58,7 +58,7 @@ enum QuicktuneValueType{
}; };
struct QuicktuneValue struct QuicktuneValue
{ {
QuicktuneValueType type; QuicktuneValueType type = QVT_NONE;
union{ union{
struct{ struct{
float current; float current;
@ -66,12 +66,10 @@ struct QuicktuneValue
float max; float max;
} value_QVT_FLOAT; } value_QVT_FLOAT;
}; };
bool modified; bool modified = false;
QuicktuneValue() = default;
QuicktuneValue():
type(QVT_NONE),
modified(false)
{}
std::string getString(); std::string getString();
void relativeAdd(float amount); void relativeAdd(float amount);
}; };

View File

@ -28,16 +28,16 @@ private:
u32 m_selected_i; u32 m_selected_i;
std::string m_message; std::string m_message;
public: public:
bool hasMessage() bool hasMessage() const
{ {
return m_message != ""; return !m_message.empty();
} }
std::string getMessage() std::string getMessage()
{ {
std::string s = m_message; std::string s = m_message;
m_message = ""; m_message = "";
if(s != "") if (!s.empty())
return std::string("[quicktune] ") + s; return std::string("[quicktune] ") + s;
return ""; return "";
} }

View File

@ -31,13 +31,15 @@ bool RaycastSort::operator() (const PointedThing &pt1,
// returns false if pt1 is nearer than pt2 // returns false if pt1 is nearer than pt2
if (pt1.distanceSq < pt2.distanceSq) { if (pt1.distanceSq < pt2.distanceSq) {
return false; return false;
} else if (pt1.distanceSq == pt2.distanceSq) { }
if (pt1.distanceSq == pt2.distanceSq) {
// Sort them to allow only one order // Sort them to allow only one order
if (pt1.type == POINTEDTHING_OBJECT) if (pt1.type == POINTEDTHING_OBJECT)
return (pt2.type == POINTEDTHING_OBJECT return (pt2.type == POINTEDTHING_OBJECT
&& pt1.object_id < pt2.object_id); && pt1.object_id < pt2.object_id);
else
return (pt2.type == POINTEDTHING_OBJECT return (pt2.type == POINTEDTHING_OBJECT
|| pt1.node_undersurface < pt2.node_undersurface); || pt1.node_undersurface < pt2.node_undersurface);
} }
return true; return true;

View File

@ -72,8 +72,8 @@ void RemotePlayer::serializeExtraAttributes(std::string &output)
assert(m_sao); assert(m_sao);
Json::Value json_root; Json::Value json_root;
const PlayerAttributes &attrs = m_sao->getExtendedAttributes(); const PlayerAttributes &attrs = m_sao->getExtendedAttributes();
for (PlayerAttributes::const_iterator it = attrs.begin(); it != attrs.end(); ++it) { for (const auto &attr : attrs) {
json_root[(*it).first] = (*it).second; json_root[attr.first] = attr.second;
} }
Json::FastWriter writer; Json::FastWriter writer;
@ -125,10 +125,9 @@ void RemotePlayer::deSerialize(std::istream &is, const std::string &playername,
reader.parse(extended_attributes, attr_root); reader.parse(extended_attributes, attr_root);
const Json::Value::Members attr_list = attr_root.getMemberNames(); const Json::Value::Members attr_list = attr_root.getMemberNames();
for (Json::Value::Members::const_iterator it = attr_list.begin(); for (const auto &it : attr_list) {
it != attr_list.end(); ++it) { Json::Value attr_value = attr_root[it];
Json::Value attr_value = attr_root[*it]; sao->setExtendedAttribute(it, attr_value.asString());
sao->setExtendedAttribute(*it, attr_value.asString());
} }
} catch (SettingNotFoundException &e) {} } catch (SettingNotFoundException &e) {}
} }
@ -165,7 +164,7 @@ void RemotePlayer::serialize(std::ostream &os)
args.setFloat("yaw", m_sao->getYaw()); args.setFloat("yaw", m_sao->getYaw());
args.setS32("breath", m_sao->getBreath()); args.setS32("breath", m_sao->getBreath());
std::string extended_attrs = ""; std::string extended_attrs;
serializeExtraAttributes(extended_attrs); serializeExtraAttributes(extended_attrs);
args.set("extended_attributes", extended_attrs); args.set("extended_attributes", extended_attrs);

View File

@ -41,7 +41,7 @@ class RemotePlayer : public Player
public: public:
RemotePlayer(const char *name, IItemDefManager *idef); RemotePlayer(const char *name, IItemDefManager *idef);
virtual ~RemotePlayer() {} virtual ~RemotePlayer() = default;
void deSerialize(std::istream &is, const std::string &playername, PlayerSAO *sao); void deSerialize(std::istream &is, const std::string &playername, PlayerSAO *sao);

View File

@ -577,35 +577,34 @@ const std::list<RollbackAction> RollbackManager::rollbackActionsFromActionRows(
{ {
std::list<RollbackAction> actions; std::list<RollbackAction> actions;
for (std::list<ActionRow>::const_iterator it = rows.begin(); for (const ActionRow &row : rows) {
it != rows.end(); ++it) {
RollbackAction action; RollbackAction action;
action.actor = (it->actor) ? getActorName(it->actor) : ""; action.actor = (row.actor) ? getActorName(row.actor) : "";
action.unix_time = it->timestamp; action.unix_time = row.timestamp;
action.type = static_cast<RollbackAction::Type>(it->type); action.type = static_cast<RollbackAction::Type>(row.type);
switch (action.type) { switch (action.type) {
case RollbackAction::TYPE_MODIFY_INVENTORY_STACK: case RollbackAction::TYPE_MODIFY_INVENTORY_STACK:
action.inventory_location = it->location.c_str(); action.inventory_location = row.location;
action.inventory_list = it->list; action.inventory_list = row.list;
action.inventory_index = it->index; action.inventory_index = row.index;
action.inventory_add = it->add; action.inventory_add = row.add;
action.inventory_stack = it->stack; action.inventory_stack = row.stack;
if (action.inventory_stack.name.empty()) { if (action.inventory_stack.name.empty()) {
action.inventory_stack.name = getNodeName(it->stack.id); action.inventory_stack.name = getNodeName(row.stack.id);
} }
break; break;
case RollbackAction::TYPE_SET_NODE: case RollbackAction::TYPE_SET_NODE:
action.p = v3s16(it->x, it->y, it->z); action.p = v3s16(row.x, row.y, row.z);
action.n_old.name = getNodeName(it->oldNode); action.n_old.name = getNodeName(row.oldNode);
action.n_old.param1 = it->oldParam1; action.n_old.param1 = row.oldParam1;
action.n_old.param2 = it->oldParam2; action.n_old.param2 = row.oldParam2;
action.n_old.meta = it->oldMeta; action.n_old.meta = row.oldMeta;
action.n_new.name = getNodeName(it->newNode); action.n_new.name = getNodeName(row.newNode);
action.n_new.param1 = it->newParam1; action.n_new.param1 = row.newParam1;
action.n_new.param2 = it->newParam2; action.n_new.param2 = row.newParam2;
action.n_new.meta = it->newMeta; action.n_new.meta = row.newMeta;
break; break;
default: default:
@ -870,7 +869,7 @@ void RollbackManager::setActor(const std::string & actor, bool is_guess)
std::string RollbackManager::getSuspect(v3s16 p, float nearness_shortcut, std::string RollbackManager::getSuspect(v3s16 p, float nearness_shortcut,
float min_nearness) float min_nearness)
{ {
if (current_actor != "") { if (!current_actor.empty()) {
return current_actor; return current_actor;
} }
int cur_time = time(0); int cur_time = time(0);
@ -883,7 +882,7 @@ std::string RollbackManager::getSuspect(v3s16 p, float nearness_shortcut,
if (i->unix_time < first_time) { if (i->unix_time < first_time) {
break; break;
} }
if (i->actor == "") { if (i->actor.empty()) {
continue; continue;
} }
// Find position of suspect or continue // Find position of suspect or continue
@ -919,7 +918,7 @@ void RollbackManager::flush()
for (iter = action_todisk_buffer.begin(); for (iter = action_todisk_buffer.begin();
iter != action_todisk_buffer.end(); iter != action_todisk_buffer.end();
++iter) { ++iter) {
if (iter->actor == "") { if (iter->actor.empty()) {
continue; continue;
} }

View File

@ -45,7 +45,8 @@ struct RollbackNode
} }
bool operator != (const RollbackNode &other) { return !(*this == other); } bool operator != (const RollbackNode &other) { return !(*this == other); }
RollbackNode() {} RollbackNode() = default;
RollbackNode(Map *map, v3s16 p, IGameDef *gamedef); RollbackNode(Map *map, v3s16 p, IGameDef *gamedef);
}; };
@ -56,11 +57,11 @@ struct RollbackAction
TYPE_NOTHING, TYPE_NOTHING,
TYPE_SET_NODE, TYPE_SET_NODE,
TYPE_MODIFY_INVENTORY_STACK, TYPE_MODIFY_INVENTORY_STACK,
} type; } type = TYPE_NOTHING;
time_t unix_time; time_t unix_time = 0;
std::string actor; std::string actor;
bool actor_is_guess; bool actor_is_guess = false;
v3s16 p; v3s16 p;
RollbackNode n_old; RollbackNode n_old;
@ -72,11 +73,7 @@ struct RollbackAction
bool inventory_add; bool inventory_add;
ItemStack inventory_stack; ItemStack inventory_stack;
RollbackAction(): RollbackAction() = default;
type(TYPE_NOTHING),
unix_time(0),
actor_is_guess(false)
{}
void setSetNode(v3s16 p_, const RollbackNode &n_old_, void setSetNode(v3s16 p_, const RollbackNode &n_old_,
const RollbackNode &n_new_) const RollbackNode &n_new_)
@ -88,7 +85,7 @@ struct RollbackAction
} }
void setModifyInventoryStack(const std::string &inventory_location_, 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_) bool add_, const ItemStack &inventory_stack_)
{ {
type = TYPE_MODIFY_INVENTORY_STACK; type = TYPE_MODIFY_INVENTORY_STACK;
@ -121,7 +118,7 @@ public:
virtual std::string getSuspect(v3s16 p, float nearness_shortcut, virtual std::string getSuspect(v3s16 p, float nearness_shortcut,
float min_nearness) = 0; float min_nearness) = 0;
virtual ~IRollbackManager() {}; virtual ~IRollbackManager() = default;;
virtual void flush() = 0; virtual void flush() = 0;
// Get all actors that did something to position p, but not further than // Get all actors that did something to position p, but not further than
// <seconds> in history // <seconds> in history

View File

@ -359,10 +359,8 @@ Server::~Server()
delete m_script; delete m_script;
// Delete detached inventories // Delete detached inventories
for (std::map<std::string, Inventory*>::iterator for (auto &detached_inventory : m_detached_inventories) {
i = m_detached_inventories.begin(); delete detached_inventory.second;
i != m_detached_inventories.end(); ++i) {
delete i->second;
} }
} }
@ -2298,14 +2296,12 @@ void Server::fillMediaCache()
paths.push_back(porting::path_user + DIR_DELIM + "textures" + DIR_DELIM + "server"); paths.push_back(porting::path_user + DIR_DELIM + "textures" + DIR_DELIM + "server");
// Collect media file information from paths into cache // Collect media file information from paths into cache
for(std::vector<std::string>::iterator i = paths.begin(); for (const std::string &mediapath : paths) {
i != paths.end(); ++i) {
std::string mediapath = *i;
std::vector<fs::DirListNode> dirlist = fs::GetDirListing(mediapath); std::vector<fs::DirListNode> dirlist = fs::GetDirListing(mediapath);
for (u32 j = 0; j < dirlist.size(); j++) { for (const fs::DirListNode &dln : dirlist) {
if (dirlist[j].dir) // Ignode dirs if (dln.dir) // Ignode dirs
continue; continue;
std::string filename = dirlist[j].name; std::string filename = dln.name;
// If name contains illegal characters, ignore the file // If name contains illegal characters, ignore the file
if (!string_allowed(filename, TEXTURENAME_ALLOWED_CHARS)) { if (!string_allowed(filename, TEXTURENAME_ALLOWED_CHARS)) {
infostream<<"Server: ignoring illegal file name: \"" infostream<<"Server: ignoring illegal file name: \""
@ -2326,7 +2322,9 @@ void Server::fillMediaCache()
continue; continue;
} }
// Ok, attempt to load the file and add to cache // 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 // Read data
std::ifstream fis(filepath.c_str(), std::ios_base::binary); std::ifstream fis(filepath.c_str(), std::ios_base::binary);
if (!fis.good()) { if (!fis.good()) {

View File

@ -129,7 +129,7 @@ LBMManager::~LBMManager()
void LBMManager::addLBMDef(LoadingBlockModifierDef *lbm_def) void LBMManager::addLBMDef(LoadingBlockModifierDef *lbm_def)
{ {
// Precondition, in query mode the map isn't used anymore // 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"); "attempted to modify LBMManager in query mode");
if (!string_allowed(lbm_def->name, LBM_NAME_ALLOWED_CHARS)) { 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 = 0;
size_t idx_new; 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::string entry = times.substr(idx, idx_new - idx);
std::vector<std::string> components = str_split(entry, '~'); std::vector<std::string> components = str_split(entry, '~');
if (components.size() != 2) if (components.size() != 2)
@ -224,7 +224,7 @@ void LBMManager::loadIntroductionTimes(const std::string &times,
std::string LBMManager::createIntroductionTimesString() std::string LBMManager::createIntroductionTimesString()
{ {
// Precondition, we must be in query mode // 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"); "attempted to query on non fully set up LBMManager");
std::ostringstream oss; std::ostringstream oss;
@ -246,7 +246,7 @@ std::string LBMManager::createIntroductionTimesString()
void LBMManager::applyLBMs(ServerEnvironment *env, MapBlock *block, u32 stamp) void LBMManager::applyLBMs(ServerEnvironment *env, MapBlock *block, u32 stamp)
{ {
// Precondition, we need m_lbm_lookup to be initialized // 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"); "attempted to query on non fully set up LBMManager");
v3s16 pos_of_block = block->getPosRelative(); v3s16 pos_of_block = block->getPosRelative();
v3s16 pos; v3s16 pos;
@ -300,22 +300,17 @@ void ActiveBlockList::update(std::vector<v3s16> &active_positions,
Create the new list Create the new list
*/ */
std::set<v3s16> newlist = m_forceloaded_list; std::set<v3s16> newlist = m_forceloaded_list;
for(std::vector<v3s16>::iterator i = active_positions.begin(); for (const v3s16 &active_position : active_positions) {
i != active_positions.end(); ++i) fillRadiusBlock(active_position, radius, newlist);
{
fillRadiusBlock(*i, radius, newlist);
} }
/* /*
Find out which blocks on the old list are not on the new list Find out which blocks on the old list are not on the new list
*/ */
// Go through old list // Go through old list
for(std::set<v3s16>::iterator i = m_list.begin(); for (v3s16 p : m_list) {
i != m_list.end(); ++i)
{
v3s16 p = *i;
// If not on new list, it's been removed // 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); 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 Find out which blocks on the new list are not on the old list
*/ */
// Go through new list // Go through new list
for(std::set<v3s16>::iterator i = newlist.begin(); for (v3s16 p : newlist) {
i != newlist.end(); ++i)
{
v3s16 p = *i;
// If not on old list, it's been added // If not on old list, it's been added
if(m_list.find(p) == m_list.end()) if(m_list.find(p) == m_list.end())
blocks_added.insert(p); blocks_added.insert(p);
@ -336,10 +328,7 @@ void ActiveBlockList::update(std::vector<v3s16> &active_positions,
Update m_list Update m_list
*/ */
m_list.clear(); m_list.clear();
for(std::set<v3s16>::iterator i = newlist.begin(); for (v3s16 p : newlist) {
i != newlist.end(); ++i)
{
v3s16 p = *i;
m_list.insert(p); m_list.insert(p);
} }
} }
@ -375,7 +364,7 @@ ServerEnvironment::ServerEnvironment(ServerMap *map,
} }
} }
std::string name = ""; std::string name;
conf.getNoEx("player_backend", name); conf.getNoEx("player_backend", name);
m_player_database = openPlayerDatabase(name, path_world, conf); m_player_database = openPlayerDatabase(name, path_world, conf);
} }
@ -393,15 +382,13 @@ ServerEnvironment::~ServerEnvironment()
m_map->drop(); m_map->drop();
// Delete ActiveBlockModifiers // Delete ActiveBlockModifiers
for (std::vector<ABMWithState>::iterator for (ABMWithState &m_abm : m_abms) {
i = m_abms.begin(); i != m_abms.end(); ++i){ delete m_abm.abm;
delete i->abm;
} }
// Deallocate players // Deallocate players
for (std::vector<RemotePlayer *>::iterator i = m_players.begin(); for (RemotePlayer *m_player : m_players) {
i != m_players.end(); ++i) { delete m_player;
delete (*i);
} }
delete m_player_database; delete m_player_database;
@ -419,9 +406,7 @@ ServerMap & ServerEnvironment::getServerMap()
RemotePlayer *ServerEnvironment::getPlayer(const u16 peer_id) RemotePlayer *ServerEnvironment::getPlayer(const u16 peer_id)
{ {
for (std::vector<RemotePlayer *>::iterator i = m_players.begin(); for (RemotePlayer *player : m_players) {
i != m_players.end(); ++i) {
RemotePlayer *player = *i;
if (player->peer_id == peer_id) if (player->peer_id == peer_id)
return player; return player;
} }
@ -430,9 +415,7 @@ RemotePlayer *ServerEnvironment::getPlayer(const u16 peer_id)
RemotePlayer *ServerEnvironment::getPlayer(const char* name) RemotePlayer *ServerEnvironment::getPlayer(const char* name)
{ {
for (std::vector<RemotePlayer *>::iterator i = m_players.begin(); for (RemotePlayer *player : m_players) {
i != m_players.end(); ++i) {
RemotePlayer *player = *i;
if (strcmp(player->getName(), name) == 0) if (strcmp(player->getName(), name) == 0)
return player; return player;
} }
@ -503,9 +486,7 @@ bool ServerEnvironment::line_of_sight(v3f pos1, v3f pos2, float stepsize, v3s16
void ServerEnvironment::kickAllPlayers(AccessDeniedCode reason, void ServerEnvironment::kickAllPlayers(AccessDeniedCode reason,
const std::string &str_reason, bool reconnect) const std::string &str_reason, bool reconnect)
{ {
for (std::vector<RemotePlayer *>::iterator it = m_players.begin(); for (RemotePlayer *player : m_players) {
it != m_players.end(); ++it) {
RemotePlayer *player = dynamic_cast<RemotePlayer *>(*it);
m_server->DenyAccessVerCompliant(player->peer_id, m_server->DenyAccessVerCompliant(player->peer_id,
player->protocol_version, reason, str_reason, reconnect); player->protocol_version, reason, str_reason, reconnect);
} }
@ -516,15 +497,13 @@ void ServerEnvironment::saveLoadedPlayers()
std::string players_path = m_path_world + DIR_DELIM + "players"; std::string players_path = m_path_world + DIR_DELIM + "players";
fs::CreateDir(players_path); fs::CreateDir(players_path);
for (std::vector<RemotePlayer *>::iterator it = m_players.begin(); for (RemotePlayer *player : m_players) {
it != m_players.end(); if (player->checkModified() || (player->getPlayerSAO() &&
++it) { player->getPlayerSAO()->extendedAttributesModified())) {
if ((*it)->checkModified() ||
((*it)->getPlayerSAO() && (*it)->getPlayerSAO()->extendedAttributesModified())) {
try { try {
m_player_database->savePlayer(*it); m_player_database->savePlayer(player);
} catch (DatabaseException &e) { } catch (DatabaseException &e) {
errorstream << "Failed to save player " << (*it)->getName() << " exception: " errorstream << "Failed to save player " << player->getName() << " exception: "
<< e.what() << std::endl; << e.what() << std::endl;
throw; throw;
} }
@ -641,7 +620,7 @@ void ServerEnvironment::loadMeta()
// If missing, do as if clearObjects was never called // If missing, do as if clearObjects was never called
args.getU64("last_clear_objects_time") : 0; args.getU64("last_clear_objects_time") : 0;
std::string lbm_introduction_times = ""; std::string lbm_introduction_times;
try { try {
u64 ver = args.getU64("lbm_introduction_times_version"); u64 ver = args.getU64("lbm_introduction_times_version");
if (ver == 1) { if (ver == 1) {
@ -685,18 +664,17 @@ public:
if(dtime_s < 0.001) if(dtime_s < 0.001)
return; return;
INodeDefManager *ndef = env->getGameDef()->ndef(); INodeDefManager *ndef = env->getGameDef()->ndef();
for(std::vector<ABMWithState>::iterator for (ABMWithState &abmws : abms) {
i = abms.begin(); i != abms.end(); ++i) { ActiveBlockModifier *abm = abmws.abm;
ActiveBlockModifier *abm = i->abm;
float trigger_interval = abm->getTriggerInterval(); float trigger_interval = abm->getTriggerInterval();
if(trigger_interval < 0.001) if(trigger_interval < 0.001)
trigger_interval = 0.001; trigger_interval = 0.001;
float actual_interval = dtime_s; float actual_interval = dtime_s;
if(use_timers){ if(use_timers){
i->timer += dtime_s; abmws.timer += dtime_s;
if(i->timer < trigger_interval) if(abmws.timer < trigger_interval)
continue; continue;
i->timer -= trigger_interval; abmws.timer -= trigger_interval;
actual_interval = trigger_interval; actual_interval = trigger_interval;
} }
float chance = abm->getTriggerChance(); float chance = abm->getTriggerChance();
@ -718,20 +696,16 @@ public:
// Trigger neighbors // Trigger neighbors
const std::set<std::string> &required_neighbors_s = const std::set<std::string> &required_neighbors_s =
abm->getRequiredNeighbors(); abm->getRequiredNeighbors();
for (std::set<std::string>::iterator rn = required_neighbors_s.begin(); for (const std::string &required_neighbor_s : required_neighbors_s) {
rn != required_neighbors_s.end(); ++rn) { ndef->getIds(required_neighbor_s, aabm.required_neighbors);
ndef->getIds(*rn, aabm.required_neighbors);
} }
// Trigger contents // Trigger contents
const std::set<std::string> &contents_s = abm->getTriggerContents(); const std::set<std::string> &contents_s = abm->getTriggerContents();
for (std::set<std::string>::iterator cs = contents_s.begin(); for (const std::string &content_s : contents_s) {
cs != contents_s.end(); ++cs) {
std::set<content_t> ids; std::set<content_t> ids;
ndef->getIds(*cs, ids); ndef->getIds(content_s, ids);
for (std::set<content_t>::const_iterator k = ids.begin(); for (content_t c : ids) {
k != ids.end(); ++k) {
content_t c = *k;
if (c >= m_aabms.size()) if (c >= m_aabms.size())
m_aabms.resize(c + 256, NULL); m_aabms.resize(c + 256, NULL);
if (!m_aabms[c]) if (!m_aabms[c])
@ -744,8 +718,8 @@ public:
~ABMHandler() ~ABMHandler()
{ {
for (size_t i = 0; i < m_aabms.size(); i++) for (auto &aabms : m_aabms)
delete m_aabms[i]; delete aabms;
} }
// Find out how many objects the given block and its neighbours contain. // Find out how many objects the given block and its neighbours contain.
@ -799,14 +773,12 @@ public:
continue; continue;
v3s16 p = p0 + block->getPosRelative(); v3s16 p = p0 + block->getPosRelative();
for(std::vector<ActiveABM>::iterator for (ActiveABM &aabm : *m_aabms[c]) {
i = m_aabms[c]->begin(); i != m_aabms[c]->end(); ++i) { if (myrand() % aabm.chance != 0)
if(myrand() % i->chance != 0)
continue; continue;
// Check neighbors // Check neighbors
if(!i->required_neighbors.empty()) if (!aabm.required_neighbors.empty()) {
{
v3s16 p1; v3s16 p1;
for(p1.X = p0.X-1; p1.X <= p0.X+1; p1.X++) 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++) for(p1.Y = p0.Y-1; p1.Y <= p0.Y+1; p1.Y++)
@ -826,8 +798,8 @@ public:
c = n.getContent(); c = n.getContent();
} }
std::set<content_t>::const_iterator k; std::set<content_t>::const_iterator k;
k = i->required_neighbors.find(c); k = aabm.required_neighbors.find(c);
if(k != i->required_neighbors.end()){ if(k != aabm.required_neighbors.end()){
goto neighbor_found; goto neighbor_found;
} }
} }
@ -837,8 +809,8 @@ public:
neighbor_found: neighbor_found:
// Call all the trigger variations // Call all the trigger variations
i->abm->trigger(m_env, p, n); aabm.abm->trigger(m_env, p, n);
i->abm->trigger(m_env, p, n, aabm.abm->trigger(m_env, p, n,
active_object_count, active_object_count_wider); active_object_count, active_object_count_wider);
// Count surrounding objects again if the abms added any // 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); block->m_node_timers.step((float)dtime_s);
if (!elapsed_timers.empty()) { if (!elapsed_timers.empty()) {
MapNode n; MapNode n;
for (std::vector<NodeTimer>::iterator for (const NodeTimer &elapsed_timer : elapsed_timers) {
i = elapsed_timers.begin(); n = block->getNodeNoEx(elapsed_timer.position);
i != elapsed_timers.end(); ++i){ v3s16 p = elapsed_timer.position + block->getPosRelative();
n = block->getNodeNoEx(i->position); if (m_script->node_on_timer(p, n, elapsed_timer.elapsed))
v3s16 p = i->position + block->getPosRelative(); block->setNodeTimer(NodeTimer(elapsed_timer.timeout, 0,
if (m_script->node_on_timer(p, n, i->elapsed)) elapsed_timer.position));
block->setNodeTimer(NodeTimer(i->timeout, 0, i->position));
} }
} }
@ -911,7 +882,7 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime)
void ServerEnvironment::addActiveBlockModifier(ActiveBlockModifier *abm) void ServerEnvironment::addActiveBlockModifier(ActiveBlockModifier *abm)
{ {
m_abms.push_back(ABMWithState(abm)); m_abms.emplace_back(abm);
} }
void ServerEnvironment::addLoadingBlockModifierDef(LoadingBlockModifierDef *lbm) 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, void ServerEnvironment::getObjectsInsideRadius(std::vector<u16> &objects, v3f pos,
float radius) float radius)
{ {
for (ServerActiveObjectMap::iterator i = m_active_objects.begin(); for (auto &activeObject : m_active_objects) {
i != m_active_objects.end(); ++i) { ServerActiveObject* obj = activeObject.second;
ServerActiveObject* obj = i->second; u16 id = activeObject.first;
u16 id = i->first;
v3f objectpos = obj->getBasePosition(); v3f objectpos = obj->getBasePosition();
if (objectpos.getDistanceFrom(pos) > radius) if (objectpos.getDistanceFrom(pos) > radius)
continue; continue;
@ -1001,12 +971,11 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode)
infostream << "ServerEnvironment::clearObjects(): " infostream << "ServerEnvironment::clearObjects(): "
<< "Removing all active objects" << std::endl; << "Removing all active objects" << std::endl;
std::vector<u16> objects_to_remove; std::vector<u16> objects_to_remove;
for (ServerActiveObjectMap::iterator i = m_active_objects.begin(); for (auto &it : m_active_objects) {
i != m_active_objects.end(); ++i) { ServerActiveObject* obj = it.second;
ServerActiveObject* obj = i->second;
if (obj->getType() == ACTIVEOBJECT_TYPE_PLAYER) if (obj->getType() == ACTIVEOBJECT_TYPE_PLAYER)
continue; continue;
u16 id = i->first; u16 id = it.first;
// Delete static object if block is loaded // Delete static object if block is loaded
if (obj->m_static_exists) { if (obj->m_static_exists) {
MapBlock *block = m_map->getBlockNoCreateNoEx(obj->m_static_block); MapBlock *block = m_map->getBlockNoCreateNoEx(obj->m_static_block);
@ -1037,9 +1006,8 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode)
} }
// Remove references from m_active_objects // Remove references from m_active_objects
for (std::vector<u16>::iterator i = objects_to_remove.begin(); for (u16 i : objects_to_remove) {
i != objects_to_remove.end(); ++i) { m_active_objects.erase(i);
m_active_objects.erase(*i);
} }
// Get list of loaded blocks // Get list of loaded blocks
@ -1069,9 +1037,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode)
<< " blocks" << std::endl; << " blocks" << std::endl;
// Grab a reference on each loaded block to avoid unloading it // Grab a reference on each loaded block to avoid unloading it
for (std::vector<v3s16>::iterator i = loaded_blocks.begin(); for (v3s16 p : loaded_blocks) {
i != loaded_blocks.end(); ++i) {
v3s16 p = *i;
MapBlock *block = m_map->getBlockNoCreateNoEx(p); MapBlock *block = m_map->getBlockNoCreateNoEx(p);
assert(block != NULL); assert(block != NULL);
block->refGrab(); block->refGrab();
@ -1087,7 +1053,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode)
u32 num_blocks_checked = 0; u32 num_blocks_checked = 0;
u32 num_blocks_cleared = 0; u32 num_blocks_cleared = 0;
u32 num_objs_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) { i != loadable_blocks.end(); ++i) {
v3s16 p = *i; v3s16 p = *i;
MapBlock *block = m_map->emergeBlock(p, false); MapBlock *block = m_map->emergeBlock(p, false);
@ -1124,9 +1090,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode)
m_map->unloadUnreferencedBlocks(); m_map->unloadUnreferencedBlocks();
// Drop references that were added above // Drop references that were added above
for (std::vector<v3s16>::iterator i = loaded_blocks.begin(); for (v3s16 p : loaded_blocks) {
i != loaded_blocks.end(); ++i) {
v3s16 p = *i;
MapBlock *block = m_map->getBlockNoCreateNoEx(p); MapBlock *block = m_map->getBlockNoCreateNoEx(p);
assert(block); assert(block);
block->refDrop(); block->refDrop();
@ -1341,9 +1305,8 @@ void ServerEnvironment::step(float dtime)
send_recommended = true; send_recommended = true;
} }
for (ServerActiveObjectMap::iterator i = m_active_objects.begin(); for (auto &ao_it : m_active_objects) {
i != m_active_objects.end(); ++i) { ServerActiveObject* obj = ao_it.second;
ServerActiveObject* obj = i->second;
// Don't step if is to be removed or stored statically // Don't step if is to be removed or stored statically
if(obj->m_removed || obj->m_pending_deactivation) if(obj->m_removed || obj->m_pending_deactivation)
continue; continue;
@ -1491,12 +1454,11 @@ void ServerEnvironment::getAddedActiveObjects(PlayerSAO *playersao, s16 radius,
- discard objects that are found in current_objects. - discard objects that are found in current_objects.
- add remaining objects to added_objects - add remaining objects to added_objects
*/ */
for (ServerActiveObjectMap::iterator i = m_active_objects.begin(); for (auto &ao_it : m_active_objects) {
i != m_active_objects.end(); ++i) { u16 id = ao_it.first;
u16 id = i->first;
// Get object // Get object
ServerActiveObject *object = i->second; ServerActiveObject *object = ao_it.second;
if (object == NULL) if (object == NULL)
continue; continue;
@ -1545,11 +1507,7 @@ void ServerEnvironment::getRemovedActiveObjects(PlayerSAO *playersao, s16 radius
- object has m_removed=true, or - object has m_removed=true, or
- object is too far away - object is too far away
*/ */
for(std::set<u16>::iterator for (u16 id : current_objects) {
i = current_objects.begin();
i != current_objects.end(); ++i)
{
u16 id = *i;
ServerActiveObject *object = getActiveObject(id); ServerActiveObject *object = getActiveObject(id);
if (object == NULL) { if (object == NULL) {
@ -1583,11 +1541,9 @@ void ServerEnvironment::setStaticForActiveObjectsInBlock(
if (!block) if (!block)
return; return;
for (std::map<u16, StaticObject>::iterator for (auto &so_it : block->m_static_objects.m_active) {
so_it = block->m_static_objects.m_active.begin();
so_it != block->m_static_objects.m_active.end(); ++so_it) {
// Get the ServerActiveObject counterpart to this StaticObject // 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 (ao_it == m_active_objects.end()) {
// If this ever happens, there must be some kind of nasty bug. // If this ever happens, there must be some kind of nasty bug.
errorstream << "ServerEnvironment::setStaticForObjectsInBlock(): " errorstream << "ServerEnvironment::setStaticForObjectsInBlock(): "
@ -1621,8 +1577,8 @@ void ServerEnvironment::getSelectedActiveObjects(
shootline_on_map.getLength() + 10.0f); shootline_on_map.getLength() + 10.0f);
const v3f line_vector = shootline_on_map.getVector(); const v3f line_vector = shootline_on_map.getVector();
for (u32 i = 0; i < objectIds.size(); i++) { for (u16 objectId : objectIds) {
ServerActiveObject* obj = getActiveObject(objectIds[i]); ServerActiveObject* obj = getActiveObject(objectId);
aabb3f selection_box; aabb3f selection_box;
if (!obj->getSelectionBox(&selection_box)) if (!obj->getSelectionBox(&selection_box))
@ -1637,9 +1593,9 @@ void ServerEnvironment::getSelectedActiveObjects(
v3s16 current_normal; v3s16 current_normal;
if (boxLineCollision(offsetted_box, shootline_on_map.start, line_vector, if (boxLineCollision(offsetted_box, shootline_on_map.start, line_vector,
&current_intersection, &current_normal)) { &current_intersection, &current_normal)) {
objects.push_back(PointedThing( objects.emplace_back(
(s16) objectIds[i], current_intersection, current_normal, (s16) objectId, current_intersection, current_normal,
(current_intersection - shootline_on_map.start).getLengthSQ())); (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 // Add static object to active static list of the block
v3f objectpos = object->getBasePosition(); v3f objectpos = object->getBasePosition();
std::string staticdata = ""; std::string staticdata;
object->getStaticData(&staticdata); object->getStaticData(&staticdata);
StaticObject s_obj(object->getType(), objectpos, staticdata); StaticObject s_obj(object->getType(), objectpos, staticdata);
// Add to the block where the object is located in // Add to the block where the object is located in
@ -1738,10 +1694,9 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
void ServerEnvironment::removeRemovedObjects() void ServerEnvironment::removeRemovedObjects()
{ {
std::vector<u16> objects_to_remove; std::vector<u16> objects_to_remove;
for(ServerActiveObjectMap::iterator i = m_active_objects.begin(); for (auto &ao_it : m_active_objects) {
i != m_active_objects.end(); ++i) { u16 id = ao_it.first;
u16 id = i->first; ServerActiveObject* obj = ao_it.second;
ServerActiveObject* obj = i->second;
// This shouldn't happen but check it // This shouldn't happen but check it
if(obj == NULL) if(obj == NULL)
{ {
@ -1814,9 +1769,8 @@ void ServerEnvironment::removeRemovedObjects()
objects_to_remove.push_back(id); objects_to_remove.push_back(id);
} }
// Remove references from m_active_objects // Remove references from m_active_objects
for(std::vector<u16>::iterator i = objects_to_remove.begin(); for (u16 i : objects_to_remove) {
i != objects_to_remove.end(); ++i) { m_active_objects.erase(i);
m_active_objects.erase(*i);
} }
} }
@ -1885,11 +1839,7 @@ void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s)
// Activate stored objects // Activate stored objects
std::vector<StaticObject> new_stored; std::vector<StaticObject> new_stored;
for (std::vector<StaticObject>::iterator for (const StaticObject &s_obj : block->m_static_objects.m_stored) {
i = block->m_static_objects.m_stored.begin();
i != block->m_static_objects.m_stored.end(); ++i) {
StaticObject &s_obj = *i;
// Create an active object from the data // Create an active object from the data
ServerActiveObject *obj = ServerActiveObject::create ServerActiveObject *obj = ServerActiveObject::create
((ActiveObjectType) s_obj.type, this, 0, s_obj.pos, s_obj.data); ((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 // Clear stored list
block->m_static_objects.m_stored.clear(); block->m_static_objects.m_stored.clear();
// Add leftover failed stuff to stored list // Add leftover failed stuff to stored list
for(std::vector<StaticObject>::iterator for (const StaticObject &s_obj : new_stored) {
i = new_stored.begin();
i != new_stored.end(); ++i) {
StaticObject &s_obj = *i;
block->m_static_objects.m_stored.push_back(s_obj); block->m_static_objects.m_stored.push_back(s_obj);
} }
// Turn the active counterparts of activated objects not pending for // Turn the active counterparts of activated objects not pending for
// deactivation // deactivation
for(std::map<u16, StaticObject>::iterator for (auto &i : block->m_static_objects.m_active) {
i = block->m_static_objects.m_active.begin(); u16 id = i.first;
i != block->m_static_objects.m_active.end(); ++i)
{
u16 id = i->first;
ServerActiveObject *object = getActiveObject(id); ServerActiveObject *object = getActiveObject(id);
assert(object); assert(object);
object->m_pending_deactivation = false; object->m_pending_deactivation = false;
@ -1956,12 +1900,11 @@ void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s)
void ServerEnvironment::deactivateFarObjects(bool _force_delete) void ServerEnvironment::deactivateFarObjects(bool _force_delete)
{ {
std::vector<u16> objects_to_remove; std::vector<u16> objects_to_remove;
for (ServerActiveObjectMap::iterator i = m_active_objects.begin(); for (auto &ao_it : m_active_objects) {
i != m_active_objects.end(); ++i) {
// force_delete might be overriden per object // force_delete might be overriden per object
bool force_delete = _force_delete; bool force_delete = _force_delete;
ServerActiveObject* obj = i->second; ServerActiveObject* obj = ao_it.second;
assert(obj); assert(obj);
// Do not deactivate if static data creation not allowed // 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) if(!force_delete && obj->m_pending_deactivation)
continue; continue;
u16 id = i->first; u16 id = ao_it.first;
v3f objectpos = obj->getBasePosition(); v3f objectpos = obj->getBasePosition();
// The block in which the object resides in // The block in which the object resides in
@ -1997,7 +1940,7 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete)
<<std::endl; <<std::endl;
continue; continue;
} }
std::string staticdata_new = ""; std::string staticdata_new;
obj->getStaticData(&staticdata_new); obj->getStaticData(&staticdata_new);
StaticObject s_obj(obj->getType(), objectpos, staticdata_new); StaticObject s_obj(obj->getType(), objectpos, staticdata_new);
block->m_static_objects.insert(id, s_obj); block->m_static_objects.insert(id, s_obj);
@ -2038,7 +1981,7 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete)
if(obj->isStaticAllowed()) if(obj->isStaticAllowed())
{ {
// Create new static object // Create new static object
std::string staticdata_new = ""; std::string staticdata_new;
obj->getStaticData(&staticdata_new); obj->getStaticData(&staticdata_new);
StaticObject s_obj(obj->getType(), objectpos, 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 // Remove references from m_active_objects
for(std::vector<u16>::iterator i = objects_to_remove.begin(); for (u16 i : objects_to_remove) {
i != objects_to_remove.end(); ++i) { m_active_objects.erase(i);
m_active_objects.erase(*i);
} }
} }
@ -2191,19 +2133,20 @@ PlayerDatabase *ServerEnvironment::openPlayerDatabase(const std::string &name,
if (name == "sqlite3") if (name == "sqlite3")
return new PlayerDatabaseSQLite3(savedir); return new PlayerDatabaseSQLite3(savedir);
else if (name == "dummy")
if (name == "dummy")
return new Database_Dummy(); return new Database_Dummy();
#if USE_POSTGRESQL #if USE_POSTGRESQL
else if (name == "postgresql") { if (name == "postgresql") {
std::string connect_string = ""; std::string connect_string;
conf.getNoEx("pgsql_player_connection", connect_string); conf.getNoEx("pgsql_player_connection", connect_string);
return new PlayerDatabasePostgreSQL(connect_string); return new PlayerDatabasePostgreSQL(connect_string);
} }
#endif #endif
else if (name == "files") if (name == "files")
return new PlayerDatabaseFiles(savedir + DIR_DELIM + "players"); 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, bool ServerEnvironment::migratePlayersDatabase(const GameParams &game_params,

View File

@ -49,8 +49,8 @@ class ServerScripting;
class ActiveBlockModifier class ActiveBlockModifier
{ {
public: public:
ActiveBlockModifier(){}; ActiveBlockModifier() = default;
virtual ~ActiveBlockModifier(){}; virtual ~ActiveBlockModifier() = default;
// Set of contents to trigger on // Set of contents to trigger on
virtual const std::set<std::string> &getTriggerContents() const = 0; virtual const std::set<std::string> &getTriggerContents() const = 0;
@ -84,7 +84,8 @@ struct LoadingBlockModifierDef
std::string name; std::string name;
bool run_at_every_load = false; bool run_at_every_load = false;
virtual ~LoadingBlockModifierDef() {} virtual ~LoadingBlockModifierDef() = default;
virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n){}; virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n){};
}; };
@ -106,7 +107,7 @@ struct LBMContentMapping
class LBMManager class LBMManager
{ {
public: public:
LBMManager() {} LBMManager() = default;
~LBMManager(); ~LBMManager();
// Don't call this after loadIntroductionTimes() ran. // Don't call this after loadIntroductionTimes() ran.

View File

@ -89,9 +89,9 @@ std::vector<ServerListSpec> getOnline()
return server_list; return server_list;
} }
for (unsigned int i = 0; i < root.size(); i++) { for (const Json::Value &i : root) {
if (root[i].isObject()) { if (i.isObject()) {
server_list.push_back(root[i]); 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) const std::string serialize(const std::vector<ServerListSpec> &serverlist)
{ {
std::string liststring; std::string liststring;
for (std::vector<ServerListSpec>::const_iterator it = serverlist.begin(); for (const ServerListSpec &it : serverlist) {
it != serverlist.end();
++it) {
liststring += "[server]\n"; liststring += "[server]\n";
liststring += (*it)["name"].asString() + '\n'; liststring += it["name"].asString() + '\n';
liststring += (*it)["address"].asString() + '\n'; liststring += it["address"].asString() + '\n';
liststring += (*it)["port"].asString() + '\n'; liststring += it["port"].asString() + '\n';
liststring += (*it)["description"].asString() + '\n'; liststring += it["description"].asString() + '\n';
liststring += '\n'; liststring += '\n';
} }
return liststring; return liststring;
@ -184,10 +182,8 @@ const std::string serializeJson(const std::vector<ServerListSpec> &serverlist)
{ {
Json::Value root; Json::Value root;
Json::Value list(Json::arrayValue); Json::Value list(Json::arrayValue);
for (std::vector<ServerListSpec>::const_iterator it = serverlist.begin(); for (const ServerListSpec &it : serverlist) {
it != serverlist.end(); list.append(it);
++it) {
list.append(*it);
} }
root["list"] = list; root["list"] = list;
Json::FastWriter writer; Json::FastWriter writer;
@ -231,12 +227,11 @@ void sendAnnounce(AnnounceAction action,
server["clients"] = (int) clients_names.size(); server["clients"] = (int) clients_names.size();
server["clients_max"] = g_settings->getU16("max_users"); server["clients_max"] = g_settings->getU16("max_users");
server["clients_list"] = Json::Value(Json::arrayValue); server["clients_list"] = Json::Value(Json::arrayValue);
for (std::vector<std::string>::const_iterator it = clients_names.begin(); for (const std::string &clients_name : clients_names) {
it != clients_names.end(); server["clients_list"].append(clients_name);
++it) {
server["clients_list"].append(*it);
} }
if (gameid != "") server["gameid"] = gameid; if (!gameid.empty())
server["gameid"] = gameid;
} }
if (action == AA_START) { if (action == AA_START) {
@ -246,9 +241,8 @@ void sendAnnounce(AnnounceAction action,
server["privs"] = g_settings->get("default_privs"); server["privs"] = g_settings->get("default_privs");
server["can_see_far_names"] = g_settings->getS16("player_transfer_distance") <= 0; server["can_see_far_names"] = g_settings->getS16("player_transfer_distance") <= 0;
server["mods"] = Json::Value(Json::arrayValue); server["mods"] = Json::Value(Json::arrayValue);
for (std::vector<ModSpec>::const_iterator it = mods.begin(); for (const ModSpec &mod : mods) {
it != mods.end(); ++it) { server["mods"].append(mod.name);
server["mods"].append(it->name);
} }
actionstream << "Announcing to " << g_settings->get("serverlist_url") << std::endl; actionstream << "Announcing to " << g_settings->get("serverlist_url") << std::endl;
} else if (action == AA_UPDATE) { } else if (action == AA_UPDATE) {

View File

@ -30,10 +30,6 @@ ServerActiveObject::ServerActiveObject(ServerEnvironment *env, v3f pos):
{ {
} }
ServerActiveObject::~ServerActiveObject()
{
}
ServerActiveObject* ServerActiveObject::create(ActiveObjectType type, ServerActiveObject* ServerActiveObject::create(ActiveObjectType type,
ServerEnvironment *env, u16 id, v3f pos, ServerEnvironment *env, u16 id, v3f pos,
const std::string &data) const std::string &data)

View File

@ -55,7 +55,7 @@ public:
Prototypes are used that way. Prototypes are used that way.
*/ */
ServerActiveObject(ServerEnvironment *env, v3f pos); ServerActiveObject(ServerEnvironment *env, v3f pos);
virtual ~ServerActiveObject(); virtual ~ServerActiveObject() = default;
virtual ActiveObjectType getSendType() const virtual ActiveObjectType getSendType() const
{ return getType(); } { return getType(); }

View File

@ -169,9 +169,8 @@ void Settings::writeLines(std::ostream &os, u32 tab_depth) const
{ {
MutexAutoLock lock(m_mutex); MutexAutoLock lock(m_mutex);
for (SettingEntries::const_iterator it = m_settings.begin(); for (const auto &setting_it : m_settings)
it != m_settings.end(); ++it) printEntry(os, setting_it.first, setting_it.second, tab_depth);
printEntry(os, it->first, it->second, tab_depth);
} }
@ -323,7 +322,7 @@ bool Settings::parseCommandLine(int argc, char *argv[],
ValueType type = n->second.type; ValueType type = n->second.type;
std::string value = ""; std::string value;
if (type == VALUETYPE_FLAG) { if (type == VALUETYPE_FLAG) {
value = "true"; value = "true";
@ -506,7 +505,7 @@ bool Settings::getNoiseParamsFromValue(const std::string &name,
np.persist = stof(f.next(",")); np.persist = stof(f.next(","));
std::string optional_params = f.next(""); std::string optional_params = f.next("");
if (optional_params != "") if (!optional_params.empty())
np.lacunarity = stof(optional_params); np.lacunarity = stof(optional_params);
return true; 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> Settings::getNames() const
{ {
std::vector<std::string> names; std::vector<std::string> names;
for (SettingEntries::const_iterator i = m_settings.begin(); for (const auto &settings_it : m_settings) {
i != m_settings.end(); ++i) { names.push_back(settings_it.first);
names.push_back(i->first);
} }
return names; return names;
} }
@ -861,9 +859,9 @@ bool Settings::remove(const std::string &name)
delete it->second.group; delete it->second.group;
m_settings.erase(it); m_settings.erase(it);
return true; 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); MutexAutoLock lock(m_mutex);
try { try {
std::string val = other.get(name); m_settings[name] = other.get(name);
m_settings[name] = val;
} catch (SettingNotFoundException &e) { } catch (SettingNotFoundException &e) {
} }
} }
@ -965,7 +962,7 @@ void Settings::registerChangedCallback(const std::string &name,
SettingsChangedCallback cbf, void *userdata) SettingsChangedCallback cbf, void *userdata)
{ {
MutexAutoLock lock(m_callback_mutex); 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, void Settings::deregisterChangedCallback(const std::string &name,

View File

@ -72,7 +72,7 @@ struct ValueSpec {
}; };
struct SettingsEntry { struct SettingsEntry {
SettingsEntry() {} SettingsEntry() = default;
SettingsEntry(const std::string &value_) : SettingsEntry(const std::string &value_) :
value(value_) value(value_)
@ -92,7 +92,8 @@ typedef std::unordered_map<std::string, SettingsEntry> SettingEntries;
class Settings { class Settings {
public: public:
Settings() {} Settings() = default;
~Settings(); ~Settings();
Settings & operator += (const Settings &other); Settings & operator += (const Settings &other);

View File

@ -56,7 +56,7 @@ std::string getShaderPath(const std::string &name_of_shader,
const std::string &filename) const std::string &filename)
{ {
std::string combined = name_of_shader + DIR_DELIM + filename; std::string combined = name_of_shader + DIR_DELIM + filename;
std::string fullpath = ""; std::string fullpath;
/* /*
Check from cache Check from cache
*/ */
@ -68,8 +68,7 @@ std::string getShaderPath(const std::string &name_of_shader,
Check from shader_path Check from shader_path
*/ */
std::string shader_path = g_settings->get("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; std::string testpath = shader_path + DIR_DELIM + combined;
if(fs::PathExists(testpath)) if(fs::PathExists(testpath))
fullpath = testpath; fullpath = testpath;
@ -78,8 +77,7 @@ std::string getShaderPath(const std::string &name_of_shader,
/* /*
Check from default data directory Check from default data directory
*/ */
if(fullpath == "") if (fullpath.empty()) {
{
std::string rel_path = std::string("client") + DIR_DELIM std::string rel_path = std::string("client") + DIR_DELIM
+ "shaders" + DIR_DELIM + "shaders" + DIR_DELIM
+ name_of_shader + DIR_DELIM + name_of_shader + DIR_DELIM
@ -110,9 +108,9 @@ public:
// Try to use local shader instead if asked to // Try to use local shader instead if asked to
if(prefer_local){ if(prefer_local){
std::string path = getShaderPath(name_of_shader, filename); std::string path = getShaderPath(name_of_shader, filename);
if(path != ""){ if(!path.empty()){
std::string p = readFile(path); std::string p = readFile(path);
if(p != ""){ if (!p.empty()) {
m_programs[combined] = p; m_programs[combined] = p;
return; return;
} }
@ -140,7 +138,7 @@ public:
if (n != m_programs.end()) if (n != m_programs.end())
return n->second; return n->second;
std::string path = getShaderPath(name_of_shader, filename); std::string path = getShaderPath(name_of_shader, filename);
if (path == "") { if (path.empty()) {
infostream << "SourceShaderCache::getOrLoad(): No path found for \"" infostream << "SourceShaderCache::getOrLoad(): No path found for \""
<< combined << "\"" << std::endl; << combined << "\"" << std::endl;
return ""; return "";
@ -148,7 +146,7 @@ public:
infostream << "SourceShaderCache::getOrLoad(): Loading path \"" infostream << "SourceShaderCache::getOrLoad(): Loading path \""
<< path << "\"" << std::endl; << path << "\"" << std::endl;
std::string p = readFile(path); std::string p = readFile(path);
if (p != "") { if (!p.empty()) {
m_programs[combined] = p; m_programs[combined] = p;
return p; return p;
} }
@ -180,14 +178,14 @@ class ShaderCallback : public video::IShaderConstantSetCallBack
public: public:
ShaderCallback(const std::vector<IShaderConstantSetterFactory *> &factories) ShaderCallback(const std::vector<IShaderConstantSetterFactory *> &factories)
{ {
for (u32 i = 0; i < factories.size(); ++i) for (IShaderConstantSetterFactory *factory : factories)
m_setters.push_back(factories[i]->create()); m_setters.push_back(factory->create());
} }
~ShaderCallback() ~ShaderCallback()
{ {
for (u32 i = 0; i < m_setters.size(); ++i) for (IShaderConstantSetter *setter : m_setters)
delete m_setters[i]; delete setter;
} }
virtual void OnSetConstants(video::IMaterialRendererServices *services, s32 userData) virtual void OnSetConstants(video::IMaterialRendererServices *services, s32 userData)
@ -197,8 +195,8 @@ public:
bool is_highlevel = userData; bool is_highlevel = userData;
for (u32 i = 0; i < m_setters.size(); ++i) for (IShaderConstantSetter *setter : m_setters)
m_setters[i]->onSetConstants(services, is_highlevel); setter->onSetConstants(services, is_highlevel);
} }
}; };
@ -217,7 +215,7 @@ public:
m_world_view_proj("mWorldViewProj"), m_world_view_proj("mWorldViewProj"),
m_world("mWorld") m_world("mWorld")
{} {}
~MainShaderConstantSetter() {} ~MainShaderConstantSetter() = default;
virtual void onSetConstants(video::IMaterialRendererServices *services, virtual void onSetConstants(video::IMaterialRendererServices *services,
bool is_highlevel) bool is_highlevel)
@ -357,7 +355,7 @@ ShaderSource::ShaderSource()
m_main_thread = std::this_thread::get_id(); m_main_thread = std::this_thread::get_id();
// Add a dummy ShaderInfo as the first index, named "" // 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 // Add main global constant setter
addShaderConstantSetterFactory(new MainShaderConstantSetterFactory()); addShaderConstantSetterFactory(new MainShaderConstantSetterFactory());
@ -365,13 +363,11 @@ ShaderSource::ShaderSource()
ShaderSource::~ShaderSource() ShaderSource::~ShaderSource()
{ {
for (std::vector<ShaderCallback *>::iterator iter = m_callbacks.begin(); for (ShaderCallback *callback : m_callbacks) {
iter != m_callbacks.end(); ++iter) { delete callback;
delete *iter;
} }
for (std::vector<IShaderConstantSetterFactory *>::iterator iter = m_setter_factories.begin(); for (IShaderConstantSetterFactory *setter_factorie : m_setter_factories) {
iter != m_setter_factories.end(); ++iter) { delete setter_factorie;
delete *iter;
} }
} }
@ -384,34 +380,32 @@ u32 ShaderSource::getShader(const std::string &name,
if (std::this_thread::get_id() == m_main_thread) { if (std::this_thread::get_id() == m_main_thread) {
return getShaderIdDirect(name, material_type, drawtype); 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
static ResultQueue<std::string, u32, u8, u8> result_queue;
// Throw a request in
m_get_shader_queue.add(name, 0, 0, &result_queue);
/* infostream<<"Waiting for shader from main thread, name=\""
<<name<<"\""<<std::endl;*/
while(true) {
GetResult<std::string, u32, u8, u8>
result = result_queue.pop_frontNoEx();
if (result.key == name) {
return result.item;
}
else {
errorstream << "Got shader with invalid name: " << result.key << std::endl;
}
}
} }
infostream<<"getShader(): Failed"<<std::endl; /*errorstream<<"getShader(): Queued: name=\""<<name<<"\""<<std::endl;*/
// We're gonna ask the result to be put into here
static ResultQueue<std::string, u32, u8, u8> result_queue;
// Throw a request in
m_get_shader_queue.add(name, 0, 0, &result_queue);
/* infostream<<"Waiting for shader from main thread, name=\""
<<name<<"\""<<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;
return 0; return 0;
} }
@ -425,7 +419,7 @@ u32 ShaderSource::getShaderIdDirect(const std::string &name,
//infostream<<"getShaderIdDirect(): name=\""<<name<<"\""<<std::endl; //infostream<<"getShaderIdDirect(): name=\""<<name<<"\""<<std::endl;
// Empty name means shader 0 // Empty name means shader 0
if(name == ""){ if (name.empty()) {
infostream<<"getShaderIdDirect(): name is empty"<<std::endl; infostream<<"getShaderIdDirect(): name is empty"<<std::endl;
return 0; return 0;
} }
@ -509,9 +503,9 @@ void ShaderSource::rebuildShaders()
*/ */
// Recreate shaders // Recreate shaders
for(u32 i=0; i<m_shaderinfo_cache.size(); i++){ for (ShaderInfo &i : m_shaderinfo_cache) {
ShaderInfo *info = &m_shaderinfo_cache[i]; ShaderInfo *info = &i;
if(info->name != ""){ if (!info->name.empty()) {
*info = generate_shader(info->name, info->material_type, *info = generate_shader(info->name, info->material_type,
info->drawtype, m_callbacks, info->drawtype, m_callbacks,
m_setter_factories, &m_sourcecache); 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, enable_shaders, vertex_program, pixel_program,
geometry_program, is_highlevel); geometry_program, is_highlevel);
// Check hardware/driver support // Check hardware/driver support
if(vertex_program != "" && if (!vertex_program.empty() &&
!driver->queryFeature(video::EVDF_VERTEX_SHADER_1_1) && !driver->queryFeature(video::EVDF_VERTEX_SHADER_1_1) &&
!driver->queryFeature(video::EVDF_ARB_VERTEX_PROGRAM_1)){ !driver->queryFeature(video::EVDF_ARB_VERTEX_PROGRAM_1)){
infostream<<"generate_shader(): vertex shaders disabled " infostream<<"generate_shader(): vertex shaders disabled "
@ -579,7 +573,7 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
<<std::endl; <<std::endl;
vertex_program = ""; vertex_program = "";
} }
if(pixel_program != "" && if (!pixel_program.empty() &&
!driver->queryFeature(video::EVDF_PIXEL_SHADER_1_1) && !driver->queryFeature(video::EVDF_PIXEL_SHADER_1_1) &&
!driver->queryFeature(video::EVDF_ARB_FRAGMENT_PROGRAM_1)){ !driver->queryFeature(video::EVDF_ARB_FRAGMENT_PROGRAM_1)){
infostream<<"generate_shader(): pixel shaders disabled " infostream<<"generate_shader(): pixel shaders disabled "
@ -587,7 +581,7 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
<<std::endl; <<std::endl;
pixel_program = ""; pixel_program = "";
} }
if(geometry_program != "" && if (!geometry_program.empty() &&
!driver->queryFeature(video::EVDF_GEOMETRY_SHADER)){ !driver->queryFeature(video::EVDF_GEOMETRY_SHADER)){
infostream<<"generate_shader(): geometry shaders disabled " infostream<<"generate_shader(): geometry shaders disabled "
"because of missing driver/hardware support." "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 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; return shaderinfo;
// Create shaders header // Create shaders header
@ -852,7 +846,7 @@ void load_shaders(std::string name, SourceShaderCache *sourcecache,
pixel_program = sourcecache->getOrLoad(name, "opengl_fragment.glsl"); pixel_program = sourcecache->getOrLoad(name, "opengl_fragment.glsl");
geometry_program = sourcecache->getOrLoad(name, "opengl_geometry.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; is_highlevel = true;
return; return;
} }
@ -868,7 +862,7 @@ void dumpShaderProgram(std::ostream &output_stream,
size_t pos = 0; size_t pos = 0;
size_t prev = 0; size_t prev = 0;
s16 line = 1; 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) << output_stream << line++ << ": "<< program.substr(prev, pos - prev) <<
std::endl; std::endl;
prev = pos + 1; prev = pos + 1;

View File

@ -49,8 +49,8 @@ struct ShaderInfo {
u8 drawtype = 0; u8 drawtype = 0;
u8 material_type = 0; u8 material_type = 0;
ShaderInfo() {} ShaderInfo() = default;
virtual ~ShaderInfo() {} virtual ~ShaderInfo() = default;
}; };
/* /*
@ -64,7 +64,7 @@ namespace irr { namespace video {
class IShaderConstantSetter { class IShaderConstantSetter {
public: public:
virtual ~IShaderConstantSetter(){}; virtual ~IShaderConstantSetter() = default;
virtual void onSetConstants(video::IMaterialRendererServices *services, virtual void onSetConstants(video::IMaterialRendererServices *services,
bool is_highlevel) = 0; bool is_highlevel) = 0;
}; };
@ -72,7 +72,7 @@ public:
class IShaderConstantSetterFactory { class IShaderConstantSetterFactory {
public: public:
virtual ~IShaderConstantSetterFactory() {}; virtual ~IShaderConstantSetterFactory() = default;
virtual IShaderConstantSetter* create() = 0; virtual IShaderConstantSetter* create() = 0;
}; };
@ -122,8 +122,9 @@ public:
class IShaderSource { class IShaderSource {
public: public:
IShaderSource(){} IShaderSource() = default;
virtual ~IShaderSource(){} virtual ~IShaderSource() = default;
virtual u32 getShaderIdDirect(const std::string &name, virtual u32 getShaderIdDirect(const std::string &name,
const u8 material_type, const u8 drawtype){return 0;} const u8 material_type, const u8 drawtype){return 0;}
virtual ShaderInfo getShaderInfo(u32 id){return ShaderInfo();} virtual ShaderInfo getShaderInfo(u32 id){return ShaderInfo();}
@ -133,8 +134,9 @@ public:
class IWritableShaderSource : public IShaderSource { class IWritableShaderSource : public IShaderSource {
public: public:
IWritableShaderSource(){} IWritableShaderSource() = default;
virtual ~IWritableShaderSource(){} virtual ~IWritableShaderSource() = default;
virtual u32 getShaderIdDirect(const std::string &name, virtual u32 getShaderIdDirect(const std::string &name,
const u8 material_type, const u8 drawtype){return 0;} const u8 material_type, const u8 drawtype){return 0;}
virtual ShaderInfo getShaderInfo(u32 id){return ShaderInfo();} virtual ShaderInfo getShaderInfo(u32 id){return ShaderInfo();}

View File

@ -68,13 +68,13 @@ Sky::Sky(s32 id, ITextureSource *tsrc):
m_materials[4].Lighting = true; m_materials[4].Lighting = true;
} }
for (u32 i = 0; i < SKY_STAR_COUNT; i++) { for (v3f &star : m_stars) {
m_stars[i] = v3f( star = v3f(
myrand_range(-10000, 10000), myrand_range(-10000, 10000),
myrand_range(-10000, 10000), 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"); 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[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[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); 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) if (j == 0)
// Don't switch // Don't switch
{} {}
else if (j == 1) else if (j == 1)
// Switch from -Z (south) to +X (east) // Switch from -Z (south) to +X (east)
vertices[i].Pos.rotateXZBy(90); vertex.Pos.rotateXZBy(90);
else if (j == 2) else if (j == 2)
// Switch from -Z (south) to -X (west) // Switch from -Z (south) to -X (west)
vertices[i].Pos.rotateXZBy(-90); vertex.Pos.rotateXZBy(-90);
else else
// Switch from -Z (south) to +Z (north) // Switch from -Z (south) to +Z (north)
vertices[i].Pos.rotateXZBy(-180); vertex.Pos.rotateXZBy(-180);
} }
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2); 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[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[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); 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) if (j == 0)
// Don't switch // Don't switch
{} {}
else if (j == 1) else if (j == 1)
// Switch from -Z (south) to +X (east) // Switch from -Z (south) to +X (east)
vertices[i].Pos.rotateXZBy(90); vertex.Pos.rotateXZBy(90);
else if (j == 2) else if (j == 2)
// Switch from -Z (south) to -X (west) // Switch from -Z (south) to -X (west)
vertices[i].Pos.rotateXZBy(-90); vertex.Pos.rotateXZBy(-90);
else else
// Switch from -Z (south) to +Z (north) // Switch from -Z (south) to +Z (north)
vertices[i].Pos.rotateXZBy(-180); vertex.Pos.rotateXZBy(-180);
} }
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2); 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[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[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); 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) if (wicked_time_of_day < 0.5)
// Switch from -Z (south) to +X (east) // Switch from -Z (south) to +X (east)
vertices[i].Pos.rotateXZBy(90); vertex.Pos.rotateXZBy(90);
else else
// Switch from -Z (south) to -X (west) // Switch from -Z (south) to -X (west)
vertices[i].Pos.rotateXZBy(-90); vertex.Pos.rotateXZBy(-90);
} }
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2); 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[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[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); 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) // Switch from -Z (south) to +X (east)
vertices[i].Pos.rotateXZBy(90); vertex.Pos.rotateXZBy(90);
vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90); vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
} }
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2); 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[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[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); 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) // Switch from -Z (south) to +X (east)
vertices[i].Pos.rotateXZBy(90); vertex.Pos.rotateXZBy(90);
vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90); vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
} }
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2); 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[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[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); 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) // Switch from -Z (south) to +X (east)
vertices[i].Pos.rotateXZBy(90); vertex.Pos.rotateXZBy(90);
vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90); vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
} }
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2); 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[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[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); 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) // Switch from -Z (south) to +X (east)
vertices[i].Pos.rotateXZBy(90); vertex.Pos.rotateXZBy(90);
vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90); vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
} }
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2); driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
} else { } else {
@ -330,10 +330,10 @@ void Sky::render()
vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, c, o, t); 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[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); 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) // Switch from -Z (south) to +X (east)
vertices[i].Pos.rotateXZBy(90); vertex.Pos.rotateXZBy(90);
vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90); vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
} }
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2); 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[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[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); 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) // Switch from -Z (south) to -X (west)
vertices[i].Pos.rotateXZBy(-90); vertex.Pos.rotateXZBy(-90);
vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90); vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
} }
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2); 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[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[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); 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) // Switch from -Z (south) to -X (west)
vertices[i].Pos.rotateXZBy(-90); vertex.Pos.rotateXZBy(-90);
vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90); vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
} }
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2); 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[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[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); 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) // Switch from -Z (south) to -X (west)
vertices[i].Pos.rotateXZBy(-90); vertex.Pos.rotateXZBy(-90);
vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90); vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
} }
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2); 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[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[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); 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) // Switch from -Z (south) to -X (west)
vertices[i].Pos.rotateXZBy(-90); vertex.Pos.rotateXZBy(-90);
vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90); vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
} }
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2); driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
} else { } else {
@ -406,10 +406,10 @@ void Sky::render()
vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, c, o, t); 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[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); 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) // Switch from -Z (south) to -X (west)
vertices[i].Pos.rotateXZBy(-90); vertex.Pos.rotateXZBy(-90);
vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90); vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
} }
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2); 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[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[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); 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 (wicked_time_of_day < 0.5)
if (j == 0) if (j == 0)
// Switch from -Z (south) to +X (east) // Switch from -Z (south) to +X (east)
vertices[i].Pos.rotateXZBy(90); vertex.Pos.rotateXZBy(90);
else else
// Switch from -Z (south) to -X (west) // Switch from -Z (south) to -X (west)
vertices[i].Pos.rotateXZBy(-90); vertex.Pos.rotateXZBy(-90);
} }
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2); driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
} }

View File

@ -32,7 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#endif #endif
#include <ostream> #include <ostream>
#include <string.h> #include <cstring>
#include "irrlichttypes.h" #include "irrlichttypes.h"
#include "exceptions.h" #include "exceptions.h"
@ -111,7 +111,8 @@ private:
class UDPSocket class UDPSocket
{ {
public: public:
UDPSocket() { } UDPSocket() = default;
UDPSocket(bool ipv6); UDPSocket(bool ipv6);
~UDPSocket(); ~UDPSocket();
void Bind(Address addr); void Bind(Address addr);

View File

@ -37,7 +37,7 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
#include <AL/alext.h> #include <AL/alext.h>
#endif #endif
#include <vorbis/vorbisfile.h> #include <vorbis/vorbisfile.h>
#include <assert.h> #include <cassert>
#include "log.h" #include "log.h"
#include "util/numeric.h" // myrand() #include "util/numeric.h" // myrand()
#include "porting.h" #include "porting.h"