return false;
for (const auto &sv : m_stringvars) {
- if (!other.contains(sv.first) ||
- other.getString(sv.first) != sv.second)
+ if (!other.contains(sv.first) || other.getString(sv.first) != sv.second)
return false;
}
{
writeU8(os, 0); // version
writeU16(os, m_id_to_name.size());
- for (IdToNameMap::const_iterator i = m_id_to_name.begin();
- i != m_id_to_name.end(); ++i) {
- writeU16(os, i->first);
- os << serializeString(i->second);
+ for (const auto &i : m_id_to_name) {
+ writeU16(os, i.first);
+ os << serializeString(i.second);
}
}
writeU8(os, type);
writeU16(os, fixed.size());
- for (std::vector<aabb3f>::const_iterator
- i = fixed.begin();
- i != fixed.end(); ++i)
- {
- writeV3F1000(os, i->MinEdge);
- writeV3F1000(os, i->MaxEdge);
+ for (const aabb3f &nodebox : fixed) {
+ writeV3F1000(os, nodebox.MinEdge);
+ writeV3F1000(os, nodebox.MaxEdge);
}
break;
case NODEBOX_WALLMOUNTED:
} else {
writeU8(os, type);
-#define WRITEBOX(box) do { \
+#define WRITEBOX(box) \
writeU16(os, (box).size()); \
- for (std::vector<aabb3f>::const_iterator \
- i = (box).begin(); \
- i != (box).end(); ++i) { \
- writeV3F1000(os, i->MinEdge); \
- writeV3F1000(os, i->MaxEdge); \
- }; } while (0)
+ for (const aabb3f &i: (box)) { \
+ writeV3F1000(os, i.MinEdge); \
+ writeV3F1000(os, i.MaxEdge); \
+ };
WRITEBOX(fixed);
WRITEBOX(connect_top);
while (count--) { \
v3f min = readV3F1000(is); \
v3f max = readV3F1000(is); \
- (box).push_back(aabb3f(min, max)); }; } while (0)
+ (box).emplace_back(min, max); }; } while (0)
u16 count;
reset();
}
-ContentFeatures::~ContentFeatures()
-{
-}
-
void ContentFeatures::reset()
{
/*
drawtype = NDT_NORMAL;
mesh = "";
#ifndef SERVER
- for(u32 i = 0; i < 24; i++)
- mesh_ptr[i] = NULL;
+ for (auto &i : mesh_ptr)
+ i = NULL;
minimap_color = video::SColor(0, 0, 0, 0);
#endif
visual_scale = 1.0;
- for(u32 i = 0; i < 6; i++)
- tiledef[i] = TileDef();
- for(u16 j = 0; j < CF_SPECIAL_COUNT; j++)
- tiledef_special[j] = TileDef();
+ for (auto &i : tiledef)
+ i = TileDef();
+ for (auto &j : tiledef_special)
+ j = TileDef();
alpha = 255;
post_effect_color = video::SColor(0, 0, 0, 0);
param_type = CPT_NONE;
// general
os << serializeString(name);
writeU16(os, groups.size());
- for (ItemGroupList::const_iterator i = groups.begin(); i != groups.end();
- ++i) {
- os << serializeString(i->first);
- writeS16(os, i->second);
+ for (const auto &group : groups) {
+ os << serializeString(group.first);
+ writeS16(os, group.second);
}
writeU8(os, param_type);
writeU8(os, param_type_2);
os << serializeString(mesh);
writeF1000(os, visual_scale);
writeU8(os, 6);
- for (u32 i = 0; i < 6; i++)
- tiledef[i].serialize(os, protocol_version);
- for (u32 i = 0; i < 6; i++)
- tiledef_overlay[i].serialize(os, protocol_version);
+ for (const TileDef &td : tiledef)
+ td.serialize(os, protocol_version);
+ for (const TileDef &td : tiledef_overlay)
+ td.serialize(os, protocol_version);
writeU8(os, CF_SPECIAL_COUNT);
- for (u32 i = 0; i < CF_SPECIAL_COUNT; i++) {
- tiledef_special[i].serialize(os, protocol_version);
+ for (const TileDef &td : tiledef_special) {
+ td.serialize(os, protocol_version);
}
writeU8(os, alpha);
writeU8(os, color.getRed());
writeU8(os, waving);
writeU8(os, connect_sides);
writeU16(os, connects_to_ids.size());
- for (std::set<content_t>::const_iterator i = connects_to_ids.begin();
- i != connects_to_ids.end(); ++i)
- writeU16(os, *i);
+ for (u16 connects_to_id : connects_to_ids)
+ writeU16(os, connects_to_id);
writeU8(os, post_effect_color.getAlpha());
writeU8(os, post_effect_color.getRed());
writeU8(os, post_effect_color.getGreen());
return;
for (int i = 0; i < length; i++) {
- if (tiles[i].name == "")
+ if (tiles[i].name.empty())
continue;
std::stringstream s;
s << tiles[i].name << "^[noalpha^[opacity:" << ((int)alpha);
if (version < 9) {
deSerializeOld(is, version);
return;
- } else if (version > 11) {
+ }
+
+ if (version > 11) {
throw SerializationError("unsupported ContentFeatures version");
}
visual_scale = readF1000(is);
if (readU8(is) != 6)
throw SerializationError("unsupported tile count");
- for (u32 i = 0; i < 6; i++)
- tiledef[i].deSerialize(is, version, drawtype);
+ for (TileDef &td : tiledef)
+ td.deSerialize(is, version, drawtype);
if (version >= 10)
- for (u32 i = 0; i < 6; i++)
- tiledef_overlay[i].deSerialize(is, version, drawtype);
+ for (TileDef &td : tiledef_overlay)
+ td.deSerialize(is, version, drawtype);
if (readU8(is) != CF_SPECIAL_COUNT)
throw SerializationError("unsupported CF_SPECIAL_COUNT");
- for (u32 i = 0; i < CF_SPECIAL_COUNT; i++)
- tiledef_special[i].deSerialize(is, version, drawtype);
+ for (TileDef &td : tiledef_special)
+ td.deSerialize(is, version, drawtype);
alpha = readU8(is);
color.setRed(readU8(is));
color.setGreen(readU8(is));
scene::IMeshManipulator *meshmanip, Client *client, const TextureSettings &tsettings)
{
// minimap pixel color - the average color of a texture
- if (tsettings.enable_minimap && tiledef[0].name != "")
+ if (tsettings.enable_minimap && !tiledef[0].name.empty())
minimap_color = tsrc->getTextureAverageColor(tiledef[0].name);
// Figure out the actual tiles to use
TileDef tdef[6];
for (u32 j = 0; j < 6; j++) {
tdef[j] = tiledef[j];
- if (tdef[j].name == "")
+ if (tdef[j].name.empty())
tdef[j].name = "unknown_node.png";
}
// also the overlay tiles
visual_solidness = 1;
} else if (tsettings.leaves_style == LEAVES_SIMPLE) {
for (u32 j = 0; j < 6; j++) {
- if (tdef_spec[j].name != "")
+ if (!tdef_spec[j].name.empty())
tdef[j].name = tdef_spec[j].name;
}
drawtype = NDT_GLASSLIKE;
} else {
drawtype = NDT_NORMAL;
solidness = 2;
- for (u32 i = 0; i < 6; i++)
- tdef[i].name += std::string("^[noalpha");
+ for (TileDef &td : tdef)
+ td.name += std::string("^[noalpha");
}
if (waving >= 1)
material_type = TILE_MATERIAL_WAVING_LEAVES;
fillTileAttribs(tsrc, &tiles[j].layers[0], &tdef[j], tile_shader,
tsettings.use_normal_texture,
tdef[j].backface_culling, material_type);
- if (tdef_overlay[j].name != "")
+ if (!tdef_overlay[j].name.empty())
fillTileAttribs(tsrc, &tiles[j].layers[1], &tdef_overlay[j],
overlay_shader, tsettings.use_normal_texture,
tdef[j].backface_culling, overlay_material);
param_type_2 == CPT2_COLORED_WALLMOUNTED)
palette = tsrc->getPalette(palette_name);
- if ((drawtype == NDT_MESH) && (mesh != "")) {
+ if (drawtype == NDT_MESH && !mesh.empty()) {
// Meshnode drawtype
// Read the mesh and apply scale
mesh_ptr[0] = client->getMesh(mesh);
CNodeDefManager();
virtual ~CNodeDefManager();
void clear();
- virtual IWritableNodeDefManager *clone();
+
inline virtual const ContentFeatures& get(content_t c) const;
inline virtual const ContentFeatures& get(const MapNode &n) const;
virtual bool getId(const std::string &name, content_t &result) const;
CNodeDefManager::~CNodeDefManager()
{
#ifndef SERVER
- for (u32 i = 0; i < m_content_features.size(); i++) {
- ContentFeatures *f = &m_content_features[i];
- for (u32 j = 0; j < 24; j++) {
- if (f->mesh_ptr[j])
- f->mesh_ptr[j]->drop();
+ for (ContentFeatures &f : m_content_features) {
+ for (auto &j : f.mesh_ptr) {
+ if (j)
+ j->drop();
}
}
#endif
}
-IWritableNodeDefManager *CNodeDefManager::clone()
-{
- CNodeDefManager *mgr = new CNodeDefManager();
- *mgr = *this;
- return mgr;
-}
-
-
inline const ContentFeatures& CNodeDefManager::get(content_t c) const
{
return c < m_content_features.size()
return true;
const GroupItems &items = i->second;
- for (GroupItems::const_iterator j = items.begin();
- j != items.end(); ++j) {
- if ((*j).second != 0)
- result.insert((*j).first);
+ for (const auto &item : items) {
+ if (item.second != 0)
+ result.insert(item.first);
}
//printf("getIds: %dus\n", t.stop());
return true;
id >= m_next_id; // overflow?
++id) {
while (id >= m_content_features.size()) {
- m_content_features.push_back(ContentFeatures());
+ m_content_features.emplace_back();
}
const ContentFeatures &f = m_content_features[id];
- if (f.name == "") {
+ if (f.name.empty()) {
m_next_id = id + 1;
return id;
}
*/
void boxVectorUnion(const std::vector<aabb3f> &boxes, aabb3f *box_union)
{
- for (std::vector<aabb3f>::const_iterator it = boxes.begin();
- it != boxes.end(); ++it) {
- box_union->addInternalBox(*it);
+ for (const aabb3f &box : boxes) {
+ box_union->addInternalBox(box);
}
}
fabsf(half_processed.MaxEdge.Y),
fabsf(half_processed.MaxEdge.Z) };
f32 max = 0;
- for (int i = 0; i < 6; i++) {
- if (max < coords[i]) {
- max = coords[i];
+ for (float coord : coords) {
+ if (max < coord) {
+ max = coord;
}
}
// Add the union of all possible rotated boxes
fabsf(nodebox.wall_side.MaxEdge.X),
fabsf(nodebox.wall_side.MaxEdge.Z) };
f32 max = 0;
- for (int i = 0; i < 4; i++) {
- if (max < coords[i]) {
- max = coords[i];
+ for (float coord : coords) {
+ if (max < coord) {
+ max = coord;
}
}
// Add the union of all possible rotated boxes
// Add this content to the list of all groups it belongs to
// FIXME: This should remove a node from groups it no longer
// belongs to when a node is re-registered
- for (ItemGroupList::const_iterator i = def.groups.begin();
- i != def.groups.end(); ++i) {
- std::string group_name = i->first;
+ for (const auto &group : def.groups) {
+ const std::string &group_name = group.first;
std::unordered_map<std::string, GroupItems>::iterator
j = m_group_to_items.find(group_name);
if (j == m_group_to_items.end()) {
- m_group_to_items[group_name].push_back(
- std::make_pair(id, i->second));
+ m_group_to_items[group_name].emplace_back(id, group.second);
} else {
GroupItems &items = j->second;
- items.push_back(std::make_pair(id, i->second));
+ items.emplace_back(id, group.second);
}
}
return id;
}
// Check if group is empty
- if (items.size() == 0)
+ if (items.empty())
m_group_to_items.erase(iter_groups++);
else
++iter_groups;
std::set<std::string> all;
idef->getAll(all);
m_name_id_mapping_with_aliases.clear();
- for (std::set<std::string>::const_iterator
- i = all.begin(); i != all.end(); ++i) {
- const std::string &name = *i;
+ for (const std::string &name : all) {
const std::string &convert_to = idef->getAlias(name);
content_t id;
if (m_name_id_mapping.getId(convert_to, id)) {
int line_c = 0;
while (std::getline(infile, line)) {
line_c++;
- if (trim(line) == "")
+ if (trim(line).empty())
continue;
std::vector<std::string> splitted = str_split(line, ' ');
if (splitted.size() != 3) {
else if (splitted[1] == "front")
nodedef.tiledef[5].name = splitted[2];
else if (splitted[1] == "all" || splitted[1] == "*")
- for (int i = 0; i < 6; i++)
- nodedef.tiledef[i].name = splitted[2];
+ for (TileDef &i : nodedef.tiledef)
+ i.name = splitted[2];
else if (splitted[1] == "sides")
for (int i = 2; i < 6; i++)
nodedef.tiledef[i].name = splitted[2];
|| i == CONTENT_UNKNOWN)
continue;
const ContentFeatures *f = &m_content_features[i];
- if (f->name == "")
+ if (f->name.empty())
continue;
writeU16(os2, i);
// Wrap it in a string to allow different lengths without
"not changing builtin node " << i << std::endl;
continue;
}
- if (f.name == "") {
+ if (f.name.empty()) {
warningstream << "NodeDefManager::deSerialize(): "
"received empty name" << std::endl;
continue;
TileDef compatible_tiles[6];
for (u8 i = 0; i < 6; i++) {
compatible_tiles[i] = tiledef[i];
- if (tiledef_overlay[i].name != "") {
+ if (!tiledef_overlay[i].name.empty()) {
std::stringstream s;
s << "(" << tiledef[i].name << ")^(" << tiledef_overlay[i].name
<< ")";
os << serializeString(name);
writeU16(os, groups.size());
- for (ItemGroupList::const_iterator i = groups.begin();
- i != groups.end(); ++i) {
- os << serializeString(i->first);
- writeS16(os, i->second);
+ for (const auto &group : groups) {
+ os << serializeString(group.first);
+ writeS16(os, group.second);
}
writeU8(os, drawtype);
writeF1000(os, compatible_visual_scale);
writeU8(os, 6);
- for (u32 i = 0; i < 6; i++)
- compatible_tiles[i].serialize(os, protocol_version);
+ for (const auto &compatible_tile : compatible_tiles)
+ compatible_tile.serialize(os, protocol_version);
writeU8(os, CF_SPECIAL_COUNT);
- for (u32 i = 0; i < CF_SPECIAL_COUNT; i++)
- tiledef_special[i].serialize(os, protocol_version);
+ for (const TileDef &i : tiledef_special)
+ i.serialize(os, protocol_version);
writeU8(os, alpha);
writeU8(os, post_effect_color.getAlpha());
writeU8(os, post_effect_color.getRed());
collision_box.serialize(os, protocol_version);
writeU8(os, floodable);
writeU16(os, connects_to_ids.size());
- for (std::set<content_t>::const_iterator i = connects_to_ids.begin();
- i != connects_to_ids.end(); ++i)
- writeU16(os, *i);
+ for (content_t connects_to_id : connects_to_ids)
+ writeU16(os, connects_to_id);
writeU8(os, connect_sides);
} else {
throw SerializationError("ContentFeatures::serialize(): "
visual_scale = readF1000(is);
if (readU8(is) != 6)
throw SerializationError("unsupported tile count");
- for (u32 i = 0; i < 6; i++)
- tiledef[i].deSerialize(is, version, drawtype);
+ for (TileDef &i : tiledef)
+ i.deSerialize(is, version, drawtype);
if (readU8(is) != CF_SPECIAL_COUNT)
throw SerializationError("unsupported CF_SPECIAL_COUNT");
- for (u32 i = 0; i < CF_SPECIAL_COUNT; i++)
- tiledef_special[i].deSerialize(is, version, drawtype);
+ for (TileDef &i : tiledef_special)
+ i.deSerialize(is, version, drawtype);
alpha = readU8(is);
post_effect_color.setAlpha(readU8(is));
post_effect_color.setRed(readU8(is));
visual_scale = readF1000(is);
if (readU8(is) != 6)
throw SerializationError("unsupported tile count");
- for (u32 i = 0; i < 6; i++)
- tiledef[i].deSerialize(is, version, drawtype);
+ for (TileDef &i : tiledef)
+ i.deSerialize(is, version, drawtype);
// CF_SPECIAL_COUNT in version 6 = 2
if (readU8(is) != 2)
throw SerializationError("unsupported CF_SPECIAL_COUNT");
visual_scale = readF1000(is);
if (readU8(is) != 6)
throw SerializationError("unsupported tile count");
- for (u32 i = 0; i < 6; i++)
- tiledef[i].deSerialize(is, version, drawtype);
+ for (TileDef &i : tiledef)
+ i.deSerialize(is, version, drawtype);
if (readU8(is) != CF_SPECIAL_COUNT)
throw SerializationError("unsupported CF_SPECIAL_COUNT");
- for (u32 i = 0; i < CF_SPECIAL_COUNT; i++)
- tiledef_special[i].deSerialize(is, version, drawtype);
+ for (TileDef &i : tiledef_special)
+ i.deSerialize(is, version, drawtype);
alpha = readU8(is);
post_effect_color.setAlpha(readU8(is));
post_effect_color.setRed(readU8(is));
void CNodeDefManager::mapNodeboxConnections()
{
- for (u32 i = 0; i < m_content_features.size(); i++) {
- ContentFeatures *f = &m_content_features[i];
- if ((f->drawtype != NDT_NODEBOX) || (f->node_box.type != NODEBOX_CONNECTED))
+ for (ContentFeatures &f : m_content_features) {
+ if (f.drawtype != NDT_NODEBOX || f.node_box.type != NODEBOX_CONNECTED)
continue;
- for (std::vector<std::string>::iterator it = f->connects_to.begin();
- it != f->connects_to.end(); ++it) {
- getIds(*it, f->connects_to_ids);
+
+ for (std::vector<std::string>::const_iterator it = f.connects_to.begin();
+ it != f.connects_to.end(); ++it) {
+ getIds(*it, f.connects_to_ids);
}
}
}
bool enable_mesh_cache;
bool enable_minimap;
- TextureSettings() {}
+ TextureSettings() = default;
void readSettings();
};
*/
ContentFeatures();
- ~ContentFeatures();
+ ~ContentFeatures() = default;
void reset();
void serialize(std::ostream &os, u16 protocol_version) const;
void deSerialize(std::istream &is);
class INodeDefManager {
public:
- INodeDefManager(){}
- virtual ~INodeDefManager(){}
+ INodeDefManager() = default;
+ virtual ~INodeDefManager() = default;
+
// Get node definition
virtual const ContentFeatures &get(content_t c) const=0;
virtual const ContentFeatures &get(const MapNode &n) const=0;
class IWritableNodeDefManager : public INodeDefManager {
public:
- IWritableNodeDefManager(){}
- virtual ~IWritableNodeDefManager(){}
- virtual IWritableNodeDefManager* clone()=0;
+ IWritableNodeDefManager() = default;
+ virtual ~IWritableNodeDefManager() = default;
+
// Get node definition
virtual const ContentFeatures &get(content_t c) const=0;
virtual const ContentFeatures &get(const MapNode &n) const=0;
{
int num_vars = disk ? m_stringvars.size() : countNonPrivate();
writeU32(os, num_vars);
- for (StringMap::const_iterator
- it = m_stringvars.begin();
- it != m_stringvars.end(); ++it) {
- bool priv = isPrivate(it->first);
+ for (const auto &sv : m_stringvars) {
+ bool priv = isPrivate(sv.first);
if (!disk && priv)
continue;
- os << serializeString(it->first);
- os << serializeLongString(it->second);
+ os << serializeString(sv.first);
+ os << serializeLongString(sv.second);
if (version >= 2)
writeU8(os, (priv) ? 1 : 0);
}
bool NodeMetadata::empty() const
{
- return Metadata::empty() && m_inventory->getLists().size() == 0;
+ return Metadata::empty() && m_inventory->getLists().empty();
}
// m_privatevars can contain names not actually present
// DON'T: return m_stringvars.size() - m_privatevars.size();
int n = 0;
- for (StringMap::const_iterator
- it = m_stringvars.begin();
- it != m_stringvars.end(); ++it) {
- if (isPrivate(it->first) == false)
+ for (const auto &sv : m_stringvars) {
+ if (!isPrivate(sv.first))
n++;
}
return n;
writeU8(os, version);
writeU16(os, count);
- for(std::map<v3s16, NodeMetadata*>::const_iterator
- i = m_data.begin();
- i != m_data.end(); ++i)
- {
- v3s16 p = i->first;
- NodeMetadata *data = i->second;
+ for (const auto &it : m_data) {
+ v3s16 p = it.first;
+ NodeMetadata *data = it.second;
if (data->empty())
continue;
writeU16(os, m_timers.size());
}
- for (std::multimap<double, NodeTimer>::const_iterator
- i = m_timers.begin();
- i != m_timers.end(); ++i) {
- NodeTimer t = i->second;
+ for (const auto &timer : m_timers) {
+ NodeTimer t = timer.second;
NodeTimer nt = NodeTimer(t.timeout,
- t.timeout - (f32)(i->first - m_time), t.position);
+ t.timeout - (f32)(timer.first - m_time), t.position);
v3s16 p = t.position;
u16 p16 = p.Z * MAP_BLOCKSIZE * MAP_BLOCKSIZE + p.Y * MAP_BLOCKSIZE + p.X;
class NodeTimer
{
public:
- NodeTimer() {}
+ NodeTimer() = default;
NodeTimer(const v3s16 &position_):
position(position_) {}
NodeTimer(f32 timeout_, f32 elapsed_, v3s16 position_):
timeout(timeout_), elapsed(elapsed_), position(position_) {}
- ~NodeTimer() {}
+ ~NodeTimer() = default;
void serialize(std::ostream &os) const;
void deSerialize(std::istream &is);
class NodeTimerList
{
public:
- NodeTimerList() {}
- ~NodeTimerList() {}
+ NodeTimerList() = default;
+ ~NodeTimerList() = default;
void serialize(std::ostream &os, u8 map_format_version) const;
void deSerialize(std::istream &is, u8 map_format_version);
m_next_trigger_time = -1.;
}
- inline double getNextTriggerTime() {
- return m_next_trigger_time;
- }
-
// Move forward in time, returns elapsed timers
std::vector<NodeTimer> step(float dtime);
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <math.h>
+#include <cmath>
#include "noise.h"
#include <iostream>
-#include <string.h> // memset
+#include <cstring> // memset
#include "debug.h"
#include "util/numeric.h"
#include "util/string.h"
// Interpolate
if (eased)
return biLinearInterpolation(v00, v10, v01, v11, xl, yl);
- else
- return biLinearInterpolationNoEase(v00, v10, v01, v11, xl, yl);
+
+ return biLinearInterpolationNoEase(v00, v10, v01, v11, xl, yl);
}
v000, v100, v010, v110,
v001, v101, v011, v111,
xl, yl, zl);
- } else {
- return triLinearInterpolationNoEase(
- v000, v100, v010, v110,
- v001, v101, v011, v111,
- xl, yl, zl);
}
+
+ return triLinearInterpolationNoEase(
+ v000, v100, v010, v110,
+ v001, v101, v011, v111,
+ xl, yl, zl);
}
void Noise::updateResults(float g, float *gmap,
- float *persistence_map, size_t bufsize)
+ const float *persistence_map, size_t bufsize)
{
// This looks very ugly, but it is 50-70% faster than having
// conditional statements inside the loop
NoiseParams() = default;
- NoiseParams(float offset_, float scale_, v3f spread_, s32 seed_,
+ NoiseParams(float offset_, float scale_, const v3f &spread_, s32 seed_,
u16 octaves_, float persist_, float lacunarity_,
u32 flags_=NOISE_FLAG_DEFAULTS)
{
private:
void allocBuffers();
void resizeNoiseBuf(bool is3d);
- void updateResults(float g, float *gmap, float *persistence_map, size_t bufsize);
+ void updateResults(float g, float *gmap, const float *persistence_map,
+ size_t bufsize);
};
class ObjDef {
public:
- virtual ~ObjDef() {}
+ virtual ~ObjDef() = default;
u32 index;
u32 uid;
ObjectProperties::ObjectProperties()
{
- textures.push_back("unknown_object.png");
- colors.push_back(video::SColor(255,255,255,255));
+ textures.emplace_back("unknown_object.png");
+ colors.emplace_back(255,255,255,255);
}
std::string ObjectProperties::dump()
os<<", mesh="<<mesh;
os<<", visual_size="<<PP2(visual_size);
os<<", textures=[";
- for(u32 i=0; i<textures.size(); i++){
- os<<"\""<<textures[i]<<"\" ";
+ for (const std::string &texture : textures) {
+ os<<"\""<< texture <<"\" ";
}
os<<"]";
os<<", colors=[";
- for(u32 i=0; i<colors.size(); i++){
- os<<"\""<<colors[i].getAlpha()<<","<<colors[i].getRed()<<","<<colors[i].getGreen()<<","<<colors[i].getBlue()<<"\" ";
+ for (const video::SColor &color : colors) {
+ os << "\"" << color.getAlpha() << "," << color.getRed() << ","
+ << color.getGreen() << "," << color.getBlue() << "\" ";
}
os<<"]";
os<<", spritediv="<<PP2(spritediv);
os<<serializeString(visual);
writeV2F1000(os, visual_size);
writeU16(os, textures.size());
- for(u32 i=0; i<textures.size(); i++){
- os<<serializeString(textures[i]);
+ for (const std::string &texture : textures) {
+ os << serializeString(texture);
}
writeV2S16(os, spritediv);
writeV2S16(os, initial_sprite_basepos);
// Added in protocol version 14
os<<serializeString(mesh);
writeU16(os, colors.size());
- for(u32 i=0; i<colors.size(); i++){
- writeARGB8(os, colors[i]);
+ for (video::SColor color : colors) {
+ writeARGB8(os, color);
}
writeU8(os, collideWithObjects);
writeF1000(os,stepheight);
public:
/** default constructor */
- PathCost();
+ PathCost() = default;
/** copy constructor */
PathCost(const PathCost &b);
/** assignment operator */
PathCost &operator= (const PathCost &b);
- bool valid; /**< movement is possible */
- int value; /**< cost of movement */
- int direction; /**< y-direction of movement */
- bool updated; /**< this cost has ben calculated */
+ bool valid = false; /**< movement is possible */
+ int value = 0; /**< cost of movement */
+ int direction = 0; /**< y-direction of movement */
+ bool updated = false; /**< this cost has ben calculated */
};
public:
/** default constructor */
- PathGridnode();
+ PathGridnode() = default;
/** copy constructor */
PathGridnode(const PathGridnode &b);
*/
void setCost(v3s16 dir, const PathCost &cost);
- bool valid; /**< node is on surface */
- bool target; /**< node is target position */
- bool source; /**< node is stating position */
- int totalcost; /**< cost to move here from starting point */
- v3s16 sourcedir; /**< origin of movement for current cost */
- v3s16 pos; /**< real position of node */
- PathCost directions[4]; /**< cost in different directions */
+ bool valid = false; /**< node is on surface */
+ bool target = false; /**< node is target position */
+ bool source = false; /**< node is stating position */
+ int totalcost = -1; /**< cost to move here from starting point */
+ v3s16 sourcedir; /**< origin of movement for current cost */
+ v3s16 pos; /**< real position of node */
+ PathCost directions[4]; /**< cost in different directions */
/* debug values */
- bool is_element; /**< node is element of path detected */
- char type; /**< type of node */
+ bool is_element = false; /**< node is element of path detected */
+ char type = 'u'; /**< type of node */
};
class Pathfinder;
class GridNodeContainer {
public:
virtual PathGridnode &access(v3s16 p)=0;
- virtual ~GridNodeContainer() {}
+ virtual ~GridNodeContainer() = default;
+
protected:
Pathfinder *m_pathf;
class ArrayGridNodeContainer : public GridNodeContainer {
public:
- virtual ~ArrayGridNodeContainer() {}
+ virtual ~ArrayGridNodeContainer() = default;
+
ArrayGridNodeContainer(Pathfinder *pathf, v3s16 dimensions);
virtual PathGridnode &access(v3s16 p);
private:
class MapGridNodeContainer : public GridNodeContainer {
public:
- virtual ~MapGridNodeContainer() {}
+ virtual ~MapGridNodeContainer() = default;
+
MapGridNodeContainer(Pathfinder *pathf);
virtual PathGridnode &access(v3s16 p);
private:
/**
* default constructor
*/
- Pathfinder();
+ Pathfinder() = default;
~Pathfinder();
* @param level current recursion depth
* @return true/false path to destination has been found
*/
- bool updateAllCosts(v3s16 ipos, v3s16 srcdir, int total_cost, int level);
+ bool updateAllCosts(v3s16 ipos, v3s16 srcdir, int current_cost, int level);
/**
* recursive try to find a patrh to destionation
void buildPath(std::vector<v3s16> &path, v3s16 pos, int level);
/* variables */
- int m_max_index_x; /**< max index of search area in x direction */
- int m_max_index_y; /**< max index of search area in y direction */
- int m_max_index_z; /**< max index of search area in z direction */
+ int m_max_index_x = 0; /**< max index of search area in x direction */
+ int m_max_index_y = 0; /**< max index of search area in y direction */
+ int m_max_index_z = 0; /**< max index of search area in z direction */
- int m_searchdistance; /**< max distance to search in each direction */
- int m_maxdrop; /**< maximum number of blocks a path may drop */
- int m_maxjump; /**< maximum number of blocks a path may jump */
- int m_min_target_distance; /**< current smalest path to target */
+ int m_searchdistance = 0; /**< max distance to search in each direction */
+ int m_maxdrop = 0; /**< maximum number of blocks a path may drop */
+ int m_maxjump = 0; /**< maximum number of blocks a path may jump */
+ int m_min_target_distance = 0; /**< current smalest path to target */
- bool m_prefetch; /**< prefetch cost data */
+ bool m_prefetch = true; /**< prefetch cost data */
v3s16 m_start; /**< source position */
v3s16 m_destination; /**< destination position */
/** contains all map data already collected and analyzed.
Access it via the getIndexElement/getIdxElem methods. */
friend class GridNodeContainer;
- GridNodeContainer *m_nodes_container;
+ GridNodeContainer *m_nodes_container = nullptr;
- ServerEnvironment *m_env; /**< minetest environment pointer */
+ ServerEnvironment *m_env = 0; /**< minetest environment pointer */
#ifdef PATHFINDER_DEBUG
searchdistance, max_jump, max_drop, algo);
}
-/******************************************************************************/
-PathCost::PathCost()
-: valid(false),
- value(0),
- direction(0),
- updated(false)
-{
- //intentionaly empty
-}
-
/******************************************************************************/
PathCost::PathCost(const PathCost &b)
{
return *this;
}
-/******************************************************************************/
-PathGridnode::PathGridnode()
-: valid(false),
- target(false),
- source(false),
- totalcost(-1),
- sourcedir(v3s16(0, 0, 0)),
- pos(v3s16(0, 0, 0)),
- is_element(false),
- type('u')
-{
- //intentionaly empty
-}
-
/******************************************************************************/
PathGridnode::PathGridnode(const PathGridnode &b)
: valid(b.valid),
//finalize path
std::vector<v3s16> full_path;
- for (std::vector<v3s16>::iterator i = path.begin();
- i != path.end(); ++i) {
- full_path.push_back(getIndexElement(*i).pos);
+ for (const v3s16 &i : path) {
+ full_path.push_back(getIndexElement(i).pos);
}
#ifdef PATHFINDER_DEBUG
return retval;
}
-/******************************************************************************/
-Pathfinder::Pathfinder() :
- m_max_index_x(0),
- m_max_index_y(0),
- m_max_index_z(0),
- m_searchdistance(0),
- m_maxdrop(0),
- m_maxjump(0),
- m_min_target_distance(0),
- m_prefetch(true),
- m_start(0, 0, 0),
- m_destination(0, 0, 0),
- m_nodes_container(NULL),
- m_env(0)
-{
- //intentionaly empty
-}
-
Pathfinder::~Pathfinder()
{
delete m_nodes_container;
std::vector<v3s16> directions;
- directions.push_back(v3s16( 1,0, 0));
- directions.push_back(v3s16(-1,0, 0));
- directions.push_back(v3s16( 0,0, 1));
- directions.push_back(v3s16( 0,0,-1));
+ directions.emplace_back(1,0, 0);
+ directions.emplace_back(-1,0, 0);
+ directions.emplace_back(0,0, 1);
+ directions.emplace_back(0,0,-1);
- for (unsigned int i=0; i < directions.size(); i++) {
- if (directions[i] != srcdir) {
- PathCost cost = g_pos.getCost(directions[i]);
+ for (v3s16 &direction : directions) {
+ if (direction != srcdir) {
+ PathCost cost = g_pos.getCost(direction);
if (cost.valid) {
- directions[i].Y = cost.direction;
+ direction.Y = cost.direction;
- v3s16 ipos2 = ipos + directions[i];
+ v3s16 ipos2 = ipos + direction;
if (!isValidIndex(ipos2)) {
DEBUG_OUT(LVL " Pathfinder: " << PP(ipos2) <<
DEBUG_OUT(LVL "Pathfinder: updating path at: "<<
PP(ipos2) << " from: " << g_pos2.totalcost << " to "<<
new_cost << std::endl);
- if (updateAllCosts(ipos2, invert(directions[i]),
+ if (updateAllCosts(ipos2, invert(direction),
new_cost, level)) {
retval = true;
}
DEBUG_OUT("Pathfinder: remaining dirs at beginning:"
<< directions.size() << std::endl);
- for (std::vector<v3s16>::iterator iter = directions.begin();
- iter != directions.end();
- ++iter) {
+ for (v3s16 &direction : directions) {
- v3s16 pos1 = v3s16(srcpos.X + iter->X, 0, srcpos.Z+iter->Z);
+ v3s16 pos1 = v3s16(srcpos.X + direction.X, 0, srcpos.Z+ direction.Z);
int cur_manhattan = getXZManhattanDist(pos1);
- PathCost cost = g_pos.getCost(*iter);
+ PathCost cost = g_pos.getCost(direction);
if (!cost.updated) {
- cost = calcCost(g_pos.pos, *iter);
- g_pos.setCost(*iter, cost);
+ cost = calcCost(g_pos.pos, direction);
+ g_pos.setCost(direction, cost);
}
if (cost.valid) {
if ((minscore < 0)|| (score < minscore)) {
minscore = score;
- retdir = *iter;
+ retdir = direction;
}
}
}
std::vector<v3s16> directions;
- directions.push_back(v3s16( 1, 0, 0));
- directions.push_back(v3s16(-1, 0, 0));
- directions.push_back(v3s16( 0, 0, 1));
- directions.push_back(v3s16( 0, 0, -1));
+ directions.emplace_back(1, 0, 0);
+ directions.emplace_back(-1, 0, 0);
+ directions.emplace_back(0, 0, 1);
+ directions.emplace_back(0, 0, -1);
v3s16 direction = getDirHeuristic(directions, g_pos);