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);
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);
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);
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);
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);
}
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);
}
v3f(-size, -size + offset, -size),
};
if (angle)
- for (auto &vertice : vertices)
- vertice.rotateXZBy(angle);
+ for (v3f &vertex : vertices)
+ vertex.rotateXZBy(angle);
drawQuad(vertices);
}
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);
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);
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]);
struct PlayerControl
{
- PlayerControl() {}
+ PlayerControl() = default;
PlayerControl(
bool a_up,
bool g_killed = false;
-bool * signal_handler_killstatus(void)
+bool *signal_handler_killstatus()
{
return &g_killed;
}
"bin\\Build",
NULL
};
- return (removeStringEnd(path, ends) != "");
+ return (!removeStringEnd(path, ends).empty());
}
std::string get_sysinfo()
// 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"
#endif
-void attachOrCreateConsole(void)
+void attachOrCreateConsole()
{
#ifdef _WIN32
static bool consoleAllocated = false;
#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__)
#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
{
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()
#include <sstream>
#include <exception>
-#include <stdlib.h>
+#include <cstdlib>
#ifdef GPROF
#include "prof.h"
class Profiler
{
public:
- Profiler() {}
+ Profiler() = default;
void add(const std::string &name, float value)
{
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();
}
};
struct QuicktuneValue
{
- QuicktuneValueType type;
+ QuicktuneValueType type = QVT_NONE;
union{
struct{
float current;
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);
};
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 "";
}
// 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;
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;
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) {}
}
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);
public:
RemotePlayer(const char *name, IItemDefManager *idef);
- virtual ~RemotePlayer() {}
+ virtual ~RemotePlayer() = default;
void deSerialize(std::istream &is, const std::string &playername, PlayerSAO *sao);
{
std::list<RollbackAction> actions;
- for (std::list<ActionRow>::const_iterator it = rows.begin();
- it != rows.end(); ++it) {
+ for (const ActionRow &row : rows) {
RollbackAction action;
- action.actor = (it->actor) ? getActorName(it->actor) : "";
- action.unix_time = it->timestamp;
- action.type = static_cast<RollbackAction::Type>(it->type);
+ action.actor = (row.actor) ? getActorName(row.actor) : "";
+ action.unix_time = row.timestamp;
+ action.type = static_cast<RollbackAction::Type>(row.type);
switch (action.type) {
case RollbackAction::TYPE_MODIFY_INVENTORY_STACK:
- action.inventory_location = it->location.c_str();
- action.inventory_list = it->list;
- action.inventory_index = it->index;
- action.inventory_add = it->add;
- action.inventory_stack = it->stack;
+ action.inventory_location = row.location;
+ action.inventory_list = row.list;
+ action.inventory_index = row.index;
+ action.inventory_add = row.add;
+ action.inventory_stack = row.stack;
if (action.inventory_stack.name.empty()) {
- action.inventory_stack.name = getNodeName(it->stack.id);
+ action.inventory_stack.name = getNodeName(row.stack.id);
}
break;
case RollbackAction::TYPE_SET_NODE:
- action.p = v3s16(it->x, it->y, it->z);
- action.n_old.name = getNodeName(it->oldNode);
- action.n_old.param1 = it->oldParam1;
- action.n_old.param2 = it->oldParam2;
- action.n_old.meta = it->oldMeta;
- action.n_new.name = getNodeName(it->newNode);
- action.n_new.param1 = it->newParam1;
- action.n_new.param2 = it->newParam2;
- action.n_new.meta = it->newMeta;
+ action.p = v3s16(row.x, row.y, row.z);
+ action.n_old.name = getNodeName(row.oldNode);
+ action.n_old.param1 = row.oldParam1;
+ action.n_old.param2 = row.oldParam2;
+ action.n_old.meta = row.oldMeta;
+ action.n_new.name = getNodeName(row.newNode);
+ action.n_new.param1 = row.newParam1;
+ action.n_new.param2 = row.newParam2;
+ action.n_new.meta = row.newMeta;
break;
default:
std::string RollbackManager::getSuspect(v3s16 p, float nearness_shortcut,
float min_nearness)
{
- if (current_actor != "") {
+ if (!current_actor.empty()) {
return current_actor;
}
int cur_time = time(0);
if (i->unix_time < first_time) {
break;
}
- if (i->actor == "") {
+ if (i->actor.empty()) {
continue;
}
// Find position of suspect or continue
for (iter = action_todisk_buffer.begin();
iter != action_todisk_buffer.end();
++iter) {
- if (iter->actor == "") {
+ if (iter->actor.empty()) {
continue;
}
}
bool operator != (const RollbackNode &other) { return !(*this == other); }
- RollbackNode() {}
+ RollbackNode() = default;
+
RollbackNode(Map *map, v3s16 p, IGameDef *gamedef);
};
TYPE_NOTHING,
TYPE_SET_NODE,
TYPE_MODIFY_INVENTORY_STACK,
- } type;
+ } type = TYPE_NOTHING;
- time_t unix_time;
+ time_t unix_time = 0;
std::string actor;
- bool actor_is_guess;
+ bool actor_is_guess = false;
v3s16 p;
RollbackNode n_old;
bool inventory_add;
ItemStack inventory_stack;
- RollbackAction():
- type(TYPE_NOTHING),
- unix_time(0),
- actor_is_guess(false)
- {}
+ RollbackAction() = default;
void setSetNode(v3s16 p_, const RollbackNode &n_old_,
const RollbackNode &n_new_)
}
void setModifyInventoryStack(const std::string &inventory_location_,
- const std::string &inventory_list_, int index_,
+ const std::string &inventory_list_, u32 index_,
bool add_, const ItemStack &inventory_stack_)
{
type = TYPE_MODIFY_INVENTORY_STACK;
virtual std::string getSuspect(v3s16 p, float nearness_shortcut,
float min_nearness) = 0;
- virtual ~IRollbackManager() {};
+ virtual ~IRollbackManager() = default;;
virtual void flush() = 0;
// Get all actors that did something to position p, but not further than
// <seconds> in history
delete m_script;
// Delete detached inventories
- for (std::map<std::string, Inventory*>::iterator
- i = m_detached_inventories.begin();
- i != m_detached_inventories.end(); ++i) {
- delete i->second;
+ for (auto &detached_inventory : m_detached_inventories) {
+ delete detached_inventory.second;
}
}
paths.push_back(porting::path_user + DIR_DELIM + "textures" + DIR_DELIM + "server");
// Collect media file information from paths into cache
- for(std::vector<std::string>::iterator i = paths.begin();
- i != paths.end(); ++i) {
- std::string mediapath = *i;
+ for (const std::string &mediapath : paths) {
std::vector<fs::DirListNode> dirlist = fs::GetDirListing(mediapath);
- for (u32 j = 0; j < dirlist.size(); j++) {
- if (dirlist[j].dir) // Ignode dirs
+ for (const fs::DirListNode &dln : dirlist) {
+ if (dln.dir) // Ignode dirs
continue;
- std::string filename = dirlist[j].name;
+ std::string filename = dln.name;
// If name contains illegal characters, ignore the file
if (!string_allowed(filename, TEXTURENAME_ALLOWED_CHARS)) {
infostream<<"Server: ignoring illegal file name: \""
continue;
}
// Ok, attempt to load the file and add to cache
- std::string filepath = mediapath + DIR_DELIM + filename;
+ std::string filepath;
+ filepath.append(mediapath).append(DIR_DELIM).append(filename);
+
// Read data
std::ifstream fis(filepath.c_str(), std::ios_base::binary);
if (!fis.good()) {
void LBMManager::addLBMDef(LoadingBlockModifierDef *lbm_def)
{
// Precondition, in query mode the map isn't used anymore
- FATAL_ERROR_IF(m_query_mode == true,
+ FATAL_ERROR_IF(m_query_mode,
"attempted to modify LBMManager in query mode");
if (!string_allowed(lbm_def->name, LBM_NAME_ALLOWED_CHARS)) {
size_t idx = 0;
size_t idx_new;
- while ((idx_new = times.find(";", idx)) != std::string::npos) {
+ while ((idx_new = times.find(';', idx)) != std::string::npos) {
std::string entry = times.substr(idx, idx_new - idx);
std::vector<std::string> components = str_split(entry, '~');
if (components.size() != 2)
std::string LBMManager::createIntroductionTimesString()
{
// Precondition, we must be in query mode
- FATAL_ERROR_IF(m_query_mode == false,
+ FATAL_ERROR_IF(!m_query_mode,
"attempted to query on non fully set up LBMManager");
std::ostringstream oss;
void LBMManager::applyLBMs(ServerEnvironment *env, MapBlock *block, u32 stamp)
{
// Precondition, we need m_lbm_lookup to be initialized
- FATAL_ERROR_IF(m_query_mode == false,
+ FATAL_ERROR_IF(!m_query_mode,
"attempted to query on non fully set up LBMManager");
v3s16 pos_of_block = block->getPosRelative();
v3s16 pos;
Create the new list
*/
std::set<v3s16> newlist = m_forceloaded_list;
- for(std::vector<v3s16>::iterator i = active_positions.begin();
- i != active_positions.end(); ++i)
- {
- fillRadiusBlock(*i, radius, newlist);
+ for (const v3s16 &active_position : active_positions) {
+ fillRadiusBlock(active_position, radius, newlist);
}
/*
Find out which blocks on the old list are not on the new list
*/
// Go through old list
- for(std::set<v3s16>::iterator i = m_list.begin();
- i != m_list.end(); ++i)
- {
- v3s16 p = *i;
+ for (v3s16 p : m_list) {
// If not on new list, it's been removed
- if(newlist.find(p) == newlist.end())
+ if (newlist.find(p) == newlist.end())
blocks_removed.insert(p);
}
Find out which blocks on the new list are not on the old list
*/
// Go through new list
- for(std::set<v3s16>::iterator i = newlist.begin();
- i != newlist.end(); ++i)
- {
- v3s16 p = *i;
+ for (v3s16 p : newlist) {
// If not on old list, it's been added
if(m_list.find(p) == m_list.end())
blocks_added.insert(p);
Update m_list
*/
m_list.clear();
- for(std::set<v3s16>::iterator i = newlist.begin();
- i != newlist.end(); ++i)
- {
- v3s16 p = *i;
+ for (v3s16 p : newlist) {
m_list.insert(p);
}
}
}
}
- std::string name = "";
+ std::string name;
conf.getNoEx("player_backend", name);
m_player_database = openPlayerDatabase(name, path_world, conf);
}
m_map->drop();
// Delete ActiveBlockModifiers
- for (std::vector<ABMWithState>::iterator
- i = m_abms.begin(); i != m_abms.end(); ++i){
- delete i->abm;
+ for (ABMWithState &m_abm : m_abms) {
+ delete m_abm.abm;
}
// Deallocate players
- for (std::vector<RemotePlayer *>::iterator i = m_players.begin();
- i != m_players.end(); ++i) {
- delete (*i);
+ for (RemotePlayer *m_player : m_players) {
+ delete m_player;
}
delete m_player_database;
RemotePlayer *ServerEnvironment::getPlayer(const u16 peer_id)
{
- for (std::vector<RemotePlayer *>::iterator i = m_players.begin();
- i != m_players.end(); ++i) {
- RemotePlayer *player = *i;
+ for (RemotePlayer *player : m_players) {
if (player->peer_id == peer_id)
return player;
}
RemotePlayer *ServerEnvironment::getPlayer(const char* name)
{
- for (std::vector<RemotePlayer *>::iterator i = m_players.begin();
- i != m_players.end(); ++i) {
- RemotePlayer *player = *i;
+ for (RemotePlayer *player : m_players) {
if (strcmp(player->getName(), name) == 0)
return player;
}
void ServerEnvironment::kickAllPlayers(AccessDeniedCode reason,
const std::string &str_reason, bool reconnect)
{
- for (std::vector<RemotePlayer *>::iterator it = m_players.begin();
- it != m_players.end(); ++it) {
- RemotePlayer *player = dynamic_cast<RemotePlayer *>(*it);
+ for (RemotePlayer *player : m_players) {
m_server->DenyAccessVerCompliant(player->peer_id,
player->protocol_version, reason, str_reason, reconnect);
}
std::string players_path = m_path_world + DIR_DELIM + "players";
fs::CreateDir(players_path);
- for (std::vector<RemotePlayer *>::iterator it = m_players.begin();
- it != m_players.end();
- ++it) {
- if ((*it)->checkModified() ||
- ((*it)->getPlayerSAO() && (*it)->getPlayerSAO()->extendedAttributesModified())) {
+ for (RemotePlayer *player : m_players) {
+ if (player->checkModified() || (player->getPlayerSAO() &&
+ player->getPlayerSAO()->extendedAttributesModified())) {
try {
- m_player_database->savePlayer(*it);
+ m_player_database->savePlayer(player);
} catch (DatabaseException &e) {
- errorstream << "Failed to save player " << (*it)->getName() << " exception: "
+ errorstream << "Failed to save player " << player->getName() << " exception: "
<< e.what() << std::endl;
throw;
}
// If missing, do as if clearObjects was never called
args.getU64("last_clear_objects_time") : 0;
- std::string lbm_introduction_times = "";
+ std::string lbm_introduction_times;
try {
u64 ver = args.getU64("lbm_introduction_times_version");
if (ver == 1) {
if(dtime_s < 0.001)
return;
INodeDefManager *ndef = env->getGameDef()->ndef();
- for(std::vector<ABMWithState>::iterator
- i = abms.begin(); i != abms.end(); ++i) {
- ActiveBlockModifier *abm = i->abm;
+ for (ABMWithState &abmws : abms) {
+ ActiveBlockModifier *abm = abmws.abm;
float trigger_interval = abm->getTriggerInterval();
if(trigger_interval < 0.001)
trigger_interval = 0.001;
float actual_interval = dtime_s;
if(use_timers){
- i->timer += dtime_s;
- if(i->timer < trigger_interval)
+ abmws.timer += dtime_s;
+ if(abmws.timer < trigger_interval)
continue;
- i->timer -= trigger_interval;
+ abmws.timer -= trigger_interval;
actual_interval = trigger_interval;
}
float chance = abm->getTriggerChance();
// Trigger neighbors
const std::set<std::string> &required_neighbors_s =
abm->getRequiredNeighbors();
- for (std::set<std::string>::iterator rn = required_neighbors_s.begin();
- rn != required_neighbors_s.end(); ++rn) {
- ndef->getIds(*rn, aabm.required_neighbors);
+ for (const std::string &required_neighbor_s : required_neighbors_s) {
+ ndef->getIds(required_neighbor_s, aabm.required_neighbors);
}
// Trigger contents
const std::set<std::string> &contents_s = abm->getTriggerContents();
- for (std::set<std::string>::iterator cs = contents_s.begin();
- cs != contents_s.end(); ++cs) {
+ for (const std::string &content_s : contents_s) {
std::set<content_t> ids;
- ndef->getIds(*cs, ids);
- for (std::set<content_t>::const_iterator k = ids.begin();
- k != ids.end(); ++k) {
- content_t c = *k;
+ ndef->getIds(content_s, ids);
+ for (content_t c : ids) {
if (c >= m_aabms.size())
m_aabms.resize(c + 256, NULL);
if (!m_aabms[c])
~ABMHandler()
{
- for (size_t i = 0; i < m_aabms.size(); i++)
- delete m_aabms[i];
+ for (auto &aabms : m_aabms)
+ delete aabms;
}
// Find out how many objects the given block and its neighbours contain.
continue;
v3s16 p = p0 + block->getPosRelative();
- for(std::vector<ActiveABM>::iterator
- i = m_aabms[c]->begin(); i != m_aabms[c]->end(); ++i) {
- if(myrand() % i->chance != 0)
+ for (ActiveABM &aabm : *m_aabms[c]) {
+ if (myrand() % aabm.chance != 0)
continue;
// Check neighbors
- if(!i->required_neighbors.empty())
- {
+ if (!aabm.required_neighbors.empty()) {
v3s16 p1;
for(p1.X = p0.X-1; p1.X <= p0.X+1; p1.X++)
for(p1.Y = p0.Y-1; p1.Y <= p0.Y+1; p1.Y++)
c = n.getContent();
}
std::set<content_t>::const_iterator k;
- k = i->required_neighbors.find(c);
- if(k != i->required_neighbors.end()){
+ k = aabm.required_neighbors.find(c);
+ if(k != aabm.required_neighbors.end()){
goto neighbor_found;
}
}
neighbor_found:
// Call all the trigger variations
- i->abm->trigger(m_env, p, n);
- i->abm->trigger(m_env, p, n,
+ aabm.abm->trigger(m_env, p, n);
+ aabm.abm->trigger(m_env, p, n,
active_object_count, active_object_count_wider);
// Count surrounding objects again if the abms added any
block->m_node_timers.step((float)dtime_s);
if (!elapsed_timers.empty()) {
MapNode n;
- for (std::vector<NodeTimer>::iterator
- i = elapsed_timers.begin();
- i != elapsed_timers.end(); ++i){
- n = block->getNodeNoEx(i->position);
- v3s16 p = i->position + block->getPosRelative();
- if (m_script->node_on_timer(p, n, i->elapsed))
- block->setNodeTimer(NodeTimer(i->timeout, 0, i->position));
+ for (const NodeTimer &elapsed_timer : elapsed_timers) {
+ n = block->getNodeNoEx(elapsed_timer.position);
+ v3s16 p = elapsed_timer.position + block->getPosRelative();
+ if (m_script->node_on_timer(p, n, elapsed_timer.elapsed))
+ block->setNodeTimer(NodeTimer(elapsed_timer.timeout, 0,
+ elapsed_timer.position));
}
}
void ServerEnvironment::addActiveBlockModifier(ActiveBlockModifier *abm)
{
- m_abms.push_back(ABMWithState(abm));
+ m_abms.emplace_back(abm);
}
void ServerEnvironment::addLoadingBlockModifierDef(LoadingBlockModifierDef *lbm)
void ServerEnvironment::getObjectsInsideRadius(std::vector<u16> &objects, v3f pos,
float radius)
{
- for (ServerActiveObjectMap::iterator i = m_active_objects.begin();
- i != m_active_objects.end(); ++i) {
- ServerActiveObject* obj = i->second;
- u16 id = i->first;
+ for (auto &activeObject : m_active_objects) {
+ ServerActiveObject* obj = activeObject.second;
+ u16 id = activeObject.first;
v3f objectpos = obj->getBasePosition();
if (objectpos.getDistanceFrom(pos) > radius)
continue;
infostream << "ServerEnvironment::clearObjects(): "
<< "Removing all active objects" << std::endl;
std::vector<u16> objects_to_remove;
- for (ServerActiveObjectMap::iterator i = m_active_objects.begin();
- i != m_active_objects.end(); ++i) {
- ServerActiveObject* obj = i->second;
+ for (auto &it : m_active_objects) {
+ ServerActiveObject* obj = it.second;
if (obj->getType() == ACTIVEOBJECT_TYPE_PLAYER)
continue;
- u16 id = i->first;
+ u16 id = it.first;
// Delete static object if block is loaded
if (obj->m_static_exists) {
MapBlock *block = m_map->getBlockNoCreateNoEx(obj->m_static_block);
}
// Remove references from m_active_objects
- for (std::vector<u16>::iterator i = objects_to_remove.begin();
- i != objects_to_remove.end(); ++i) {
- m_active_objects.erase(*i);
+ for (u16 i : objects_to_remove) {
+ m_active_objects.erase(i);
}
// Get list of loaded blocks
<< " blocks" << std::endl;
// Grab a reference on each loaded block to avoid unloading it
- for (std::vector<v3s16>::iterator i = loaded_blocks.begin();
- i != loaded_blocks.end(); ++i) {
- v3s16 p = *i;
+ for (v3s16 p : loaded_blocks) {
MapBlock *block = m_map->getBlockNoCreateNoEx(p);
assert(block != NULL);
block->refGrab();
u32 num_blocks_checked = 0;
u32 num_blocks_cleared = 0;
u32 num_objs_cleared = 0;
- for (std::vector<v3s16>::iterator i = loadable_blocks.begin();
+ for (auto i = loadable_blocks.begin();
i != loadable_blocks.end(); ++i) {
v3s16 p = *i;
MapBlock *block = m_map->emergeBlock(p, false);
m_map->unloadUnreferencedBlocks();
// Drop references that were added above
- for (std::vector<v3s16>::iterator i = loaded_blocks.begin();
- i != loaded_blocks.end(); ++i) {
- v3s16 p = *i;
+ for (v3s16 p : loaded_blocks) {
MapBlock *block = m_map->getBlockNoCreateNoEx(p);
assert(block);
block->refDrop();
send_recommended = true;
}
- for (ServerActiveObjectMap::iterator i = m_active_objects.begin();
- i != m_active_objects.end(); ++i) {
- ServerActiveObject* obj = i->second;
+ for (auto &ao_it : m_active_objects) {
+ ServerActiveObject* obj = ao_it.second;
// Don't step if is to be removed or stored statically
if(obj->m_removed || obj->m_pending_deactivation)
continue;
- discard objects that are found in current_objects.
- add remaining objects to added_objects
*/
- for (ServerActiveObjectMap::iterator i = m_active_objects.begin();
- i != m_active_objects.end(); ++i) {
- u16 id = i->first;
+ for (auto &ao_it : m_active_objects) {
+ u16 id = ao_it.first;
// Get object
- ServerActiveObject *object = i->second;
+ ServerActiveObject *object = ao_it.second;
if (object == NULL)
continue;
- object has m_removed=true, or
- object is too far away
*/
- for(std::set<u16>::iterator
- i = current_objects.begin();
- i != current_objects.end(); ++i)
- {
- u16 id = *i;
+ for (u16 id : current_objects) {
ServerActiveObject *object = getActiveObject(id);
if (object == NULL) {
if (!block)
return;
- for (std::map<u16, StaticObject>::iterator
- so_it = block->m_static_objects.m_active.begin();
- so_it != block->m_static_objects.m_active.end(); ++so_it) {
+ for (auto &so_it : block->m_static_objects.m_active) {
// Get the ServerActiveObject counterpart to this StaticObject
- ServerActiveObjectMap::const_iterator ao_it = m_active_objects.find(so_it->first);
+ ServerActiveObjectMap::const_iterator ao_it = m_active_objects.find(so_it.first);
if (ao_it == m_active_objects.end()) {
// If this ever happens, there must be some kind of nasty bug.
errorstream << "ServerEnvironment::setStaticForObjectsInBlock(): "
shootline_on_map.getLength() + 10.0f);
const v3f line_vector = shootline_on_map.getVector();
- for (u32 i = 0; i < objectIds.size(); i++) {
- ServerActiveObject* obj = getActiveObject(objectIds[i]);
+ for (u16 objectId : objectIds) {
+ ServerActiveObject* obj = getActiveObject(objectId);
aabb3f selection_box;
if (!obj->getSelectionBox(&selection_box))
v3s16 current_normal;
if (boxLineCollision(offsetted_box, shootline_on_map.start, line_vector,
¤t_intersection, ¤t_normal)) {
- objects.push_back(PointedThing(
- (s16) objectIds[i], current_intersection, current_normal,
- (current_intersection - shootline_on_map.start).getLengthSQ()));
+ objects.emplace_back(
+ (s16) objectId, current_intersection, current_normal,
+ (current_intersection - shootline_on_map.start).getLengthSQ());
}
}
}
{
// Add static object to active static list of the block
v3f objectpos = object->getBasePosition();
- std::string staticdata = "";
+ std::string staticdata;
object->getStaticData(&staticdata);
StaticObject s_obj(object->getType(), objectpos, staticdata);
// Add to the block where the object is located in
void ServerEnvironment::removeRemovedObjects()
{
std::vector<u16> objects_to_remove;
- for(ServerActiveObjectMap::iterator i = m_active_objects.begin();
- i != m_active_objects.end(); ++i) {
- u16 id = i->first;
- ServerActiveObject* obj = i->second;
+ for (auto &ao_it : m_active_objects) {
+ u16 id = ao_it.first;
+ ServerActiveObject* obj = ao_it.second;
// This shouldn't happen but check it
if(obj == NULL)
{
objects_to_remove.push_back(id);
}
// Remove references from m_active_objects
- for(std::vector<u16>::iterator i = objects_to_remove.begin();
- i != objects_to_remove.end(); ++i) {
- m_active_objects.erase(*i);
+ for (u16 i : objects_to_remove) {
+ m_active_objects.erase(i);
}
}
// Activate stored objects
std::vector<StaticObject> new_stored;
- for (std::vector<StaticObject>::iterator
- i = block->m_static_objects.m_stored.begin();
- i != block->m_static_objects.m_stored.end(); ++i) {
- StaticObject &s_obj = *i;
-
+ for (const StaticObject &s_obj : block->m_static_objects.m_stored) {
// Create an active object from the data
ServerActiveObject *obj = ServerActiveObject::create
((ActiveObjectType) s_obj.type, this, 0, s_obj.pos, s_obj.data);
// Clear stored list
block->m_static_objects.m_stored.clear();
// Add leftover failed stuff to stored list
- for(std::vector<StaticObject>::iterator
- i = new_stored.begin();
- i != new_stored.end(); ++i) {
- StaticObject &s_obj = *i;
+ for (const StaticObject &s_obj : new_stored) {
block->m_static_objects.m_stored.push_back(s_obj);
}
// Turn the active counterparts of activated objects not pending for
// deactivation
- for(std::map<u16, StaticObject>::iterator
- i = block->m_static_objects.m_active.begin();
- i != block->m_static_objects.m_active.end(); ++i)
- {
- u16 id = i->first;
+ for (auto &i : block->m_static_objects.m_active) {
+ u16 id = i.first;
ServerActiveObject *object = getActiveObject(id);
assert(object);
object->m_pending_deactivation = false;
void ServerEnvironment::deactivateFarObjects(bool _force_delete)
{
std::vector<u16> objects_to_remove;
- for (ServerActiveObjectMap::iterator i = m_active_objects.begin();
- i != m_active_objects.end(); ++i) {
+ for (auto &ao_it : m_active_objects) {
// force_delete might be overriden per object
bool force_delete = _force_delete;
- ServerActiveObject* obj = i->second;
+ ServerActiveObject* obj = ao_it.second;
assert(obj);
// Do not deactivate if static data creation not allowed
if(!force_delete && obj->m_pending_deactivation)
continue;
- u16 id = i->first;
+ u16 id = ao_it.first;
v3f objectpos = obj->getBasePosition();
// The block in which the object resides in
<<std::endl;
continue;
}
- std::string staticdata_new = "";
+ std::string staticdata_new;
obj->getStaticData(&staticdata_new);
StaticObject s_obj(obj->getType(), objectpos, staticdata_new);
block->m_static_objects.insert(id, s_obj);
if(obj->isStaticAllowed())
{
// Create new static object
- std::string staticdata_new = "";
+ std::string staticdata_new;
obj->getStaticData(&staticdata_new);
StaticObject s_obj(obj->getType(), objectpos, staticdata_new);
}
// Remove references from m_active_objects
- for(std::vector<u16>::iterator i = objects_to_remove.begin();
- i != objects_to_remove.end(); ++i) {
- m_active_objects.erase(*i);
+ for (u16 i : objects_to_remove) {
+ m_active_objects.erase(i);
}
}
if (name == "sqlite3")
return new PlayerDatabaseSQLite3(savedir);
- else if (name == "dummy")
+
+ if (name == "dummy")
return new Database_Dummy();
#if USE_POSTGRESQL
- else if (name == "postgresql") {
- std::string connect_string = "";
+ if (name == "postgresql") {
+ std::string connect_string;
conf.getNoEx("pgsql_player_connection", connect_string);
return new PlayerDatabasePostgreSQL(connect_string);
}
#endif
- else if (name == "files")
+ if (name == "files")
return new PlayerDatabaseFiles(savedir + DIR_DELIM + "players");
- else
- throw BaseException(std::string("Database backend ") + name + " not supported.");
+
+ throw BaseException(std::string("Database backend ") + name + " not supported.");
}
bool ServerEnvironment::migratePlayersDatabase(const GameParams &game_params,
class ActiveBlockModifier
{
public:
- ActiveBlockModifier(){};
- virtual ~ActiveBlockModifier(){};
+ ActiveBlockModifier() = default;
+ virtual ~ActiveBlockModifier() = default;
// Set of contents to trigger on
virtual const std::set<std::string> &getTriggerContents() const = 0;
std::string name;
bool run_at_every_load = false;
- virtual ~LoadingBlockModifierDef() {}
+ virtual ~LoadingBlockModifierDef() = default;
+
virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n){};
};
class LBMManager
{
public:
- LBMManager() {}
+ LBMManager() = default;
~LBMManager();
// Don't call this after loadIntroductionTimes() ran.
return server_list;
}
- for (unsigned int i = 0; i < root.size(); i++) {
- if (root[i].isObject()) {
- server_list.push_back(root[i]);
+ for (const Json::Value &i : root) {
+ if (i.isObject()) {
+ server_list.push_back(i);
}
}
const std::string serialize(const std::vector<ServerListSpec> &serverlist)
{
std::string liststring;
- for (std::vector<ServerListSpec>::const_iterator it = serverlist.begin();
- it != serverlist.end();
- ++it) {
+ for (const ServerListSpec &it : serverlist) {
liststring += "[server]\n";
- liststring += (*it)["name"].asString() + '\n';
- liststring += (*it)["address"].asString() + '\n';
- liststring += (*it)["port"].asString() + '\n';
- liststring += (*it)["description"].asString() + '\n';
+ liststring += it["name"].asString() + '\n';
+ liststring += it["address"].asString() + '\n';
+ liststring += it["port"].asString() + '\n';
+ liststring += it["description"].asString() + '\n';
liststring += '\n';
}
return liststring;
{
Json::Value root;
Json::Value list(Json::arrayValue);
- for (std::vector<ServerListSpec>::const_iterator it = serverlist.begin();
- it != serverlist.end();
- ++it) {
- list.append(*it);
+ for (const ServerListSpec &it : serverlist) {
+ list.append(it);
}
root["list"] = list;
Json::FastWriter writer;
server["clients"] = (int) clients_names.size();
server["clients_max"] = g_settings->getU16("max_users");
server["clients_list"] = Json::Value(Json::arrayValue);
- for (std::vector<std::string>::const_iterator it = clients_names.begin();
- it != clients_names.end();
- ++it) {
- server["clients_list"].append(*it);
+ for (const std::string &clients_name : clients_names) {
+ server["clients_list"].append(clients_name);
}
- if (gameid != "") server["gameid"] = gameid;
+ if (!gameid.empty())
+ server["gameid"] = gameid;
}
if (action == AA_START) {
server["privs"] = g_settings->get("default_privs");
server["can_see_far_names"] = g_settings->getS16("player_transfer_distance") <= 0;
server["mods"] = Json::Value(Json::arrayValue);
- for (std::vector<ModSpec>::const_iterator it = mods.begin();
- it != mods.end(); ++it) {
- server["mods"].append(it->name);
+ for (const ModSpec &mod : mods) {
+ server["mods"].append(mod.name);
}
actionstream << "Announcing to " << g_settings->get("serverlist_url") << std::endl;
} else if (action == AA_UPDATE) {
{
}
-ServerActiveObject::~ServerActiveObject()
-{
-}
-
ServerActiveObject* ServerActiveObject::create(ActiveObjectType type,
ServerEnvironment *env, u16 id, v3f pos,
const std::string &data)
Prototypes are used that way.
*/
ServerActiveObject(ServerEnvironment *env, v3f pos);
- virtual ~ServerActiveObject();
+ virtual ~ServerActiveObject() = default;
virtual ActiveObjectType getSendType() const
{ return getType(); }
{
MutexAutoLock lock(m_mutex);
- for (SettingEntries::const_iterator it = m_settings.begin();
- it != m_settings.end(); ++it)
- printEntry(os, it->first, it->second, tab_depth);
+ for (const auto &setting_it : m_settings)
+ printEntry(os, setting_it.first, setting_it.second, tab_depth);
}
ValueType type = n->second.type;
- std::string value = "";
+ std::string value;
if (type == VALUETYPE_FLAG) {
value = "true";
np.persist = stof(f.next(","));
std::string optional_params = f.next("");
- if (optional_params != "")
+ if (!optional_params.empty())
np.lacunarity = stof(optional_params);
return true;
std::vector<std::string> Settings::getNames() const
{
std::vector<std::string> names;
- for (SettingEntries::const_iterator i = m_settings.begin();
- i != m_settings.end(); ++i) {
- names.push_back(i->first);
+ for (const auto &settings_it : m_settings) {
+ names.push_back(settings_it.first);
}
return names;
}
delete it->second.group;
m_settings.erase(it);
return true;
- } else {
- return false;
}
+
+ return false;
}
MutexAutoLock lock(m_mutex);
try {
- std::string val = other.get(name);
- m_settings[name] = val;
+ m_settings[name] = other.get(name);
} catch (SettingNotFoundException &e) {
}
}
SettingsChangedCallback cbf, void *userdata)
{
MutexAutoLock lock(m_callback_mutex);
- m_callbacks[name].push_back(std::make_pair(cbf, userdata));
+ m_callbacks[name].emplace_back(cbf, userdata);
}
void Settings::deregisterChangedCallback(const std::string &name,
};
struct SettingsEntry {
- SettingsEntry() {}
+ SettingsEntry() = default;
SettingsEntry(const std::string &value_) :
value(value_)
class Settings {
public:
- Settings() {}
+ Settings() = default;
+
~Settings();
Settings & operator += (const Settings &other);
const std::string &filename)
{
std::string combined = name_of_shader + DIR_DELIM + filename;
- std::string fullpath = "";
+ std::string fullpath;
/*
Check from cache
*/
Check from shader_path
*/
std::string shader_path = g_settings->get("shader_path");
- if(shader_path != "")
- {
+ if (!shader_path.empty()) {
std::string testpath = shader_path + DIR_DELIM + combined;
if(fs::PathExists(testpath))
fullpath = testpath;
/*
Check from default data directory
*/
- if(fullpath == "")
- {
+ if (fullpath.empty()) {
std::string rel_path = std::string("client") + DIR_DELIM
+ "shaders" + DIR_DELIM
+ name_of_shader + DIR_DELIM
// Try to use local shader instead if asked to
if(prefer_local){
std::string path = getShaderPath(name_of_shader, filename);
- if(path != ""){
+ if(!path.empty()){
std::string p = readFile(path);
- if(p != ""){
+ if (!p.empty()) {
m_programs[combined] = p;
return;
}
if (n != m_programs.end())
return n->second;
std::string path = getShaderPath(name_of_shader, filename);
- if (path == "") {
+ if (path.empty()) {
infostream << "SourceShaderCache::getOrLoad(): No path found for \""
<< combined << "\"" << std::endl;
return "";
infostream << "SourceShaderCache::getOrLoad(): Loading path \""
<< path << "\"" << std::endl;
std::string p = readFile(path);
- if (p != "") {
+ if (!p.empty()) {
m_programs[combined] = p;
return p;
}
public:
ShaderCallback(const std::vector<IShaderConstantSetterFactory *> &factories)
{
- for (u32 i = 0; i < factories.size(); ++i)
- m_setters.push_back(factories[i]->create());
+ for (IShaderConstantSetterFactory *factory : factories)
+ m_setters.push_back(factory->create());
}
~ShaderCallback()
{
- for (u32 i = 0; i < m_setters.size(); ++i)
- delete m_setters[i];
+ for (IShaderConstantSetter *setter : m_setters)
+ delete setter;
}
virtual void OnSetConstants(video::IMaterialRendererServices *services, s32 userData)
bool is_highlevel = userData;
- for (u32 i = 0; i < m_setters.size(); ++i)
- m_setters[i]->onSetConstants(services, is_highlevel);
+ for (IShaderConstantSetter *setter : m_setters)
+ setter->onSetConstants(services, is_highlevel);
}
};
m_world_view_proj("mWorldViewProj"),
m_world("mWorld")
{}
- ~MainShaderConstantSetter() {}
+ ~MainShaderConstantSetter() = default;
virtual void onSetConstants(video::IMaterialRendererServices *services,
bool is_highlevel)
m_main_thread = std::this_thread::get_id();
// Add a dummy ShaderInfo as the first index, named ""
- m_shaderinfo_cache.push_back(ShaderInfo());
+ m_shaderinfo_cache.emplace_back();
// Add main global constant setter
addShaderConstantSetterFactory(new MainShaderConstantSetterFactory());
ShaderSource::~ShaderSource()
{
- for (std::vector<ShaderCallback *>::iterator iter = m_callbacks.begin();
- iter != m_callbacks.end(); ++iter) {
- delete *iter;
+ for (ShaderCallback *callback : m_callbacks) {
+ delete callback;
}
- for (std::vector<IShaderConstantSetterFactory *>::iterator iter = m_setter_factories.begin();
- iter != m_setter_factories.end(); ++iter) {
- delete *iter;
+ for (IShaderConstantSetterFactory *setter_factorie : m_setter_factories) {
+ delete setter_factorie;
}
}
if (std::this_thread::get_id() == m_main_thread) {
return getShaderIdDirect(name, material_type, drawtype);
- } else {
- /*errorstream<<"getShader(): Queued: name=\""<<name<<"\""<<std::endl;*/
+ }
- // We're gonna ask the result to be put into here
+ /*errorstream<<"getShader(): Queued: name=\""<<name<<"\""<<std::endl;*/
- static ResultQueue<std::string, u32, u8, u8> result_queue;
+ // We're gonna ask the result to be put into here
- // Throw a request in
- m_get_shader_queue.add(name, 0, 0, &result_queue);
+ static ResultQueue<std::string, u32, u8, u8> result_queue;
- /* infostream<<"Waiting for shader from main thread, name=\""
- <<name<<"\""<<std::endl;*/
+ // Throw a request in
+ m_get_shader_queue.add(name, 0, 0, &result_queue);
- while(true) {
- GetResult<std::string, u32, u8, u8>
- result = result_queue.pop_frontNoEx();
+ /* infostream<<"Waiting for shader from main thread, name=\""
+ <<name<<"\""<<std::endl;*/
- if (result.key == name) {
- return result.item;
- }
- else {
- errorstream << "Got shader with invalid name: " << result.key << std::endl;
- }
+ while(true) {
+ GetResult<std::string, u32, u8, u8>
+ result = result_queue.pop_frontNoEx();
+
+ if (result.key == name) {
+ return result.item;
}
+ errorstream << "Got shader with invalid name: " << result.key << std::endl;
}
- infostream<<"getShader(): Failed"<<std::endl;
+ infostream << "getShader(): Failed" << std::endl;
return 0;
}
//infostream<<"getShaderIdDirect(): name=\""<<name<<"\""<<std::endl;
// Empty name means shader 0
- if(name == ""){
+ if (name.empty()) {
infostream<<"getShaderIdDirect(): name is empty"<<std::endl;
return 0;
}
*/
// Recreate shaders
- for(u32 i=0; i<m_shaderinfo_cache.size(); i++){
- ShaderInfo *info = &m_shaderinfo_cache[i];
- if(info->name != ""){
+ for (ShaderInfo &i : m_shaderinfo_cache) {
+ ShaderInfo *info = &i;
+ if (!info->name.empty()) {
*info = generate_shader(info->name, info->material_type,
info->drawtype, m_callbacks,
m_setter_factories, &m_sourcecache);
enable_shaders, vertex_program, pixel_program,
geometry_program, is_highlevel);
// Check hardware/driver support
- if(vertex_program != "" &&
+ if (!vertex_program.empty() &&
!driver->queryFeature(video::EVDF_VERTEX_SHADER_1_1) &&
!driver->queryFeature(video::EVDF_ARB_VERTEX_PROGRAM_1)){
infostream<<"generate_shader(): vertex shaders disabled "
<<std::endl;
vertex_program = "";
}
- if(pixel_program != "" &&
+ if (!pixel_program.empty() &&
!driver->queryFeature(video::EVDF_PIXEL_SHADER_1_1) &&
!driver->queryFeature(video::EVDF_ARB_FRAGMENT_PROGRAM_1)){
infostream<<"generate_shader(): pixel shaders disabled "
<<std::endl;
pixel_program = "";
}
- if(geometry_program != "" &&
+ if (!geometry_program.empty() &&
!driver->queryFeature(video::EVDF_GEOMETRY_SHADER)){
infostream<<"generate_shader(): geometry shaders disabled "
"because of missing driver/hardware support."
}
// If no shaders are used, don't make a separate material type
- if(vertex_program == "" && pixel_program == "" && geometry_program == "")
+ if (vertex_program.empty() && pixel_program.empty() && geometry_program.empty())
return shaderinfo;
// Create shaders header
pixel_program = sourcecache->getOrLoad(name, "opengl_fragment.glsl");
geometry_program = sourcecache->getOrLoad(name, "opengl_geometry.glsl");
}
- if(vertex_program != "" || pixel_program != "" || geometry_program != ""){
+ if (!vertex_program.empty() || !pixel_program.empty() || !geometry_program.empty()){
is_highlevel = true;
return;
}
size_t pos = 0;
size_t prev = 0;
s16 line = 1;
- while ((pos = program.find("\n", prev)) != std::string::npos) {
+ while ((pos = program.find('\n', prev)) != std::string::npos) {
output_stream << line++ << ": "<< program.substr(prev, pos - prev) <<
std::endl;
prev = pos + 1;
u8 drawtype = 0;
u8 material_type = 0;
- ShaderInfo() {}
- virtual ~ShaderInfo() {}
+ ShaderInfo() = default;
+ virtual ~ShaderInfo() = default;
};
/*
class IShaderConstantSetter {
public:
- virtual ~IShaderConstantSetter(){};
+ virtual ~IShaderConstantSetter() = default;
virtual void onSetConstants(video::IMaterialRendererServices *services,
bool is_highlevel) = 0;
};
class IShaderConstantSetterFactory {
public:
- virtual ~IShaderConstantSetterFactory() {};
+ virtual ~IShaderConstantSetterFactory() = default;
virtual IShaderConstantSetter* create() = 0;
};
class IShaderSource {
public:
- IShaderSource(){}
- virtual ~IShaderSource(){}
+ IShaderSource() = default;
+ virtual ~IShaderSource() = default;
+
virtual u32 getShaderIdDirect(const std::string &name,
const u8 material_type, const u8 drawtype){return 0;}
virtual ShaderInfo getShaderInfo(u32 id){return ShaderInfo();}
class IWritableShaderSource : public IShaderSource {
public:
- IWritableShaderSource(){}
- virtual ~IWritableShaderSource(){}
+ IWritableShaderSource() = default;
+ virtual ~IWritableShaderSource() = default;
+
virtual u32 getShaderIdDirect(const std::string &name,
const u8 material_type, const u8 drawtype){return 0;}
virtual ShaderInfo getShaderInfo(u32 id){return ShaderInfo();}
m_materials[4].Lighting = true;
}
- for (u32 i = 0; i < SKY_STAR_COUNT; i++) {
- m_stars[i] = v3f(
+ for (v3f &star : m_stars) {
+ star = v3f(
myrand_range(-10000, 10000),
myrand_range(-10000, 10000),
myrand_range(-10000, 10000)
);
- m_stars[i].normalize();
+ star.normalize();
}
m_directional_colored_fog = g_settings->getBool("directional_colored_fog");
vertices[1] = video::S3DVertex( 1, 0.08, -1, 0, 0, 1, c, o, t);
vertices[2] = video::S3DVertex( 1, 0.12, -1, 0, 0, 1, c, o, o);
vertices[3] = video::S3DVertex(-1, 0.12, -1, 0, 0, 1, c, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
if (j == 0)
// Don't switch
{}
else if (j == 1)
// Switch from -Z (south) to +X (east)
- vertices[i].Pos.rotateXZBy(90);
+ vertex.Pos.rotateXZBy(90);
else if (j == 2)
// Switch from -Z (south) to -X (west)
- vertices[i].Pos.rotateXZBy(-90);
+ vertex.Pos.rotateXZBy(-90);
else
// Switch from -Z (south) to +Z (north)
- vertices[i].Pos.rotateXZBy(-180);
+ vertex.Pos.rotateXZBy(-180);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
}
vertices[1] = video::S3DVertex( 1, -1.0, -1, 0, 0, 1, c, o, t);
vertices[2] = video::S3DVertex( 1, 0.08, -1, 0, 0, 1, c, o, o);
vertices[3] = video::S3DVertex(-1, 0.08, -1, 0, 0, 1, c, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
if (j == 0)
// Don't switch
{}
else if (j == 1)
// Switch from -Z (south) to +X (east)
- vertices[i].Pos.rotateXZBy(90);
+ vertex.Pos.rotateXZBy(90);
else if (j == 2)
// Switch from -Z (south) to -X (west)
- vertices[i].Pos.rotateXZBy(-90);
+ vertex.Pos.rotateXZBy(-90);
else
// Switch from -Z (south) to +Z (north)
- vertices[i].Pos.rotateXZBy(-180);
+ vertex.Pos.rotateXZBy(-180);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
}
vertices[1] = video::S3DVertex( 1, -0.05 + y, -1, 0, 0, 1, c, o, t);
vertices[2] = video::S3DVertex( 1, 0.2 + y, -1, 0, 0, 1, c, o, o);
vertices[3] = video::S3DVertex(-1, 0.2 + y, -1, 0, 0, 1, c, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
if (wicked_time_of_day < 0.5)
// Switch from -Z (south) to +X (east)
- vertices[i].Pos.rotateXZBy(90);
+ vertex.Pos.rotateXZBy(90);
else
// Switch from -Z (south) to -X (west)
- vertices[i].Pos.rotateXZBy(-90);
+ vertex.Pos.rotateXZBy(-90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
}
vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, c, o, t);
vertices[2] = video::S3DVertex( d, d, -1, 0, 0, 1, c, o, o);
vertices[3] = video::S3DVertex(-d, d, -1, 0, 0, 1, c, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
// Switch from -Z (south) to +X (east)
- vertices[i].Pos.rotateXZBy(90);
- vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+ vertex.Pos.rotateXZBy(90);
+ vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, c, o, t);
vertices[2] = video::S3DVertex( d, d, -1, 0, 0, 1, c, o, o);
vertices[3] = video::S3DVertex(-d, d, -1, 0, 0, 1, c, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
// Switch from -Z (south) to +X (east)
- vertices[i].Pos.rotateXZBy(90);
- vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+ vertex.Pos.rotateXZBy(90);
+ vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, suncolor, o, t);
vertices[2] = video::S3DVertex( d, d, -1, 0, 0, 1, suncolor, o, o);
vertices[3] = video::S3DVertex(-d, d, -1, 0, 0, 1, suncolor, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
// Switch from -Z (south) to +X (east)
- vertices[i].Pos.rotateXZBy(90);
- vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+ vertex.Pos.rotateXZBy(90);
+ vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, suncolor2, o, t);
vertices[2] = video::S3DVertex( d, d, -1, 0, 0, 1, suncolor2, o, o);
vertices[3] = video::S3DVertex(-d, d, -1, 0, 0, 1, suncolor2, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
// Switch from -Z (south) to +X (east)
- vertices[i].Pos.rotateXZBy(90);
- vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+ vertex.Pos.rotateXZBy(90);
+ vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
} else {
vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, c, o, t);
vertices[2] = video::S3DVertex( d, d, -1, 0, 0, 1, c, o, o);
vertices[3] = video::S3DVertex(-d, d, -1, 0, 0, 1, c, t, o);
- for(u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
// Switch from -Z (south) to +X (east)
- vertices[i].Pos.rotateXZBy(90);
- vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+ vertex.Pos.rotateXZBy(90);
+ vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
}
vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, c, o, t);
vertices[2] = video::S3DVertex( d, d, -1, 0, 0, 1, c, o, o);
vertices[3] = video::S3DVertex(-d, d, -1, 0, 0, 1, c, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
// Switch from -Z (south) to -X (west)
- vertices[i].Pos.rotateXZBy(-90);
- vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+ vertex.Pos.rotateXZBy(-90);
+ vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, c, o, t);
vertices[2] = video::S3DVertex( d, d, -1, 0, 0, 1, c, o, o);
vertices[3] = video::S3DVertex(-d, d, -1, 0, 0, 1, c, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
// Switch from -Z (south) to -X (west)
- vertices[i].Pos.rotateXZBy(-90);
- vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+ vertex.Pos.rotateXZBy(-90);
+ vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, mooncolor, o, t);
vertices[2] = video::S3DVertex( d, d, -1, 0, 0, 1, mooncolor, o, o);
vertices[3] = video::S3DVertex(-d, d, -1, 0, 0, 1, mooncolor, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
// Switch from -Z (south) to -X (west)
- vertices[i].Pos.rotateXZBy(-90);
- vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+ vertex.Pos.rotateXZBy(-90);
+ vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
vertices[1] = video::S3DVertex( d2,-d, -1, 0, 0, 1, mooncolor2, o, t);
vertices[2] = video::S3DVertex( d2, d2, -1, 0, 0, 1, mooncolor2, o, o);
vertices[3] = video::S3DVertex(-d, d2, -1, 0, 0, 1, mooncolor2, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
// Switch from -Z (south) to -X (west)
- vertices[i].Pos.rotateXZBy(-90);
- vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+ vertex.Pos.rotateXZBy(-90);
+ vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
} else {
vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, c, o, t);
vertices[2] = video::S3DVertex( d, d, -1, 0, 0, 1, c, o, o);
vertices[3] = video::S3DVertex(-d, d, -1, 0, 0, 1, c, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
// Switch from -Z (south) to -X (west)
- vertices[i].Pos.rotateXZBy(-90);
- vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+ vertex.Pos.rotateXZBy(-90);
+ vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
}
vertices[1] = video::S3DVertex( 1, -1.0, -1, 0, 0, 1, c, o, t);
vertices[2] = video::S3DVertex( 1, -0.02, -1, 0, 0, 1, c, o, o);
vertices[3] = video::S3DVertex(-1, -0.02, -1, 0, 0, 1, c, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
//if (wicked_time_of_day < 0.5)
if (j == 0)
// Switch from -Z (south) to +X (east)
- vertices[i].Pos.rotateXZBy(90);
+ vertex.Pos.rotateXZBy(90);
else
// Switch from -Z (south) to -X (west)
- vertices[i].Pos.rotateXZBy(-90);
+ vertex.Pos.rotateXZBy(-90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
}
#endif
#include <ostream>
-#include <string.h>
+#include <cstring>
#include "irrlichttypes.h"
#include "exceptions.h"
class UDPSocket
{
public:
- UDPSocket() { }
+ UDPSocket() = default;
+
UDPSocket(bool ipv6);
~UDPSocket();
void Bind(Address addr);
#include <AL/alext.h>
#endif
#include <vorbis/vorbisfile.h>
-#include <assert.h>
+#include <cassert>
#include "log.h"
#include "util/numeric.h" // myrand()
#include "porting.h"