mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 10:03:45 +01:00
Code modernization: src/n*, src/o* (#6280)
* Code modernization: src/n*, src/o* * empty function * default constructor/destructor * for range-based loops * use emplace_back instead of push_back * remove unused IWritableNodeDefManager::clone() * C++ STL header style * Pointer constness in some functions
This commit is contained in:
parent
4a1265ceb5
commit
1992db1395
@ -50,8 +50,7 @@ bool Metadata::operator==(const Metadata &other) const
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (const auto &sv : m_stringvars) {
|
for (const auto &sv : m_stringvars) {
|
||||||
if (!other.contains(sv.first) ||
|
if (!other.contains(sv.first) || other.getString(sv.first) != sv.second)
|
||||||
other.getString(sv.first) != sv.second)
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,10 +25,9 @@ void NameIdMapping::serialize(std::ostream &os) const
|
|||||||
{
|
{
|
||||||
writeU8(os, 0); // version
|
writeU8(os, 0); // version
|
||||||
writeU16(os, m_id_to_name.size());
|
writeU16(os, m_id_to_name.size());
|
||||||
for (IdToNameMap::const_iterator i = m_id_to_name.begin();
|
for (const auto &i : m_id_to_name) {
|
||||||
i != m_id_to_name.end(); ++i) {
|
writeU16(os, i.first);
|
||||||
writeU16(os, i->first);
|
os << serializeString(i.second);
|
||||||
os << serializeString(i->second);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
222
src/nodedef.cpp
222
src/nodedef.cpp
@ -78,12 +78,9 @@ void NodeBox::serialize(std::ostream &os, u16 protocol_version) const
|
|||||||
writeU8(os, type);
|
writeU8(os, type);
|
||||||
|
|
||||||
writeU16(os, fixed.size());
|
writeU16(os, fixed.size());
|
||||||
for (std::vector<aabb3f>::const_iterator
|
for (const aabb3f &nodebox : fixed) {
|
||||||
i = fixed.begin();
|
writeV3F1000(os, nodebox.MinEdge);
|
||||||
i != fixed.end(); ++i)
|
writeV3F1000(os, nodebox.MaxEdge);
|
||||||
{
|
|
||||||
writeV3F1000(os, i->MinEdge);
|
|
||||||
writeV3F1000(os, i->MaxEdge);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NODEBOX_WALLMOUNTED:
|
case NODEBOX_WALLMOUNTED:
|
||||||
@ -108,14 +105,12 @@ void NodeBox::serialize(std::ostream &os, u16 protocol_version) const
|
|||||||
} else {
|
} else {
|
||||||
writeU8(os, type);
|
writeU8(os, type);
|
||||||
|
|
||||||
#define WRITEBOX(box) do { \
|
#define WRITEBOX(box) \
|
||||||
writeU16(os, (box).size()); \
|
writeU16(os, (box).size()); \
|
||||||
for (std::vector<aabb3f>::const_iterator \
|
for (const aabb3f &i: (box)) { \
|
||||||
i = (box).begin(); \
|
writeV3F1000(os, i.MinEdge); \
|
||||||
i != (box).end(); ++i) { \
|
writeV3F1000(os, i.MaxEdge); \
|
||||||
writeV3F1000(os, i->MinEdge); \
|
};
|
||||||
writeV3F1000(os, i->MaxEdge); \
|
|
||||||
}; } while (0)
|
|
||||||
|
|
||||||
WRITEBOX(fixed);
|
WRITEBOX(fixed);
|
||||||
WRITEBOX(connect_top);
|
WRITEBOX(connect_top);
|
||||||
@ -170,7 +165,7 @@ void NodeBox::deSerialize(std::istream &is)
|
|||||||
while (count--) { \
|
while (count--) { \
|
||||||
v3f min = readV3F1000(is); \
|
v3f min = readV3F1000(is); \
|
||||||
v3f max = readV3F1000(is); \
|
v3f max = readV3F1000(is); \
|
||||||
(box).push_back(aabb3f(min, max)); }; } while (0)
|
(box).emplace_back(min, max); }; } while (0)
|
||||||
|
|
||||||
u16 count;
|
u16 count;
|
||||||
|
|
||||||
@ -303,10 +298,6 @@ ContentFeatures::ContentFeatures()
|
|||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentFeatures::~ContentFeatures()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void ContentFeatures::reset()
|
void ContentFeatures::reset()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -334,15 +325,15 @@ void ContentFeatures::reset()
|
|||||||
drawtype = NDT_NORMAL;
|
drawtype = NDT_NORMAL;
|
||||||
mesh = "";
|
mesh = "";
|
||||||
#ifndef SERVER
|
#ifndef SERVER
|
||||||
for(u32 i = 0; i < 24; i++)
|
for (auto &i : mesh_ptr)
|
||||||
mesh_ptr[i] = NULL;
|
i = NULL;
|
||||||
minimap_color = video::SColor(0, 0, 0, 0);
|
minimap_color = video::SColor(0, 0, 0, 0);
|
||||||
#endif
|
#endif
|
||||||
visual_scale = 1.0;
|
visual_scale = 1.0;
|
||||||
for(u32 i = 0; i < 6; i++)
|
for (auto &i : tiledef)
|
||||||
tiledef[i] = TileDef();
|
i = TileDef();
|
||||||
for(u16 j = 0; j < CF_SPECIAL_COUNT; j++)
|
for (auto &j : tiledef_special)
|
||||||
tiledef_special[j] = TileDef();
|
j = TileDef();
|
||||||
alpha = 255;
|
alpha = 255;
|
||||||
post_effect_color = video::SColor(0, 0, 0, 0);
|
post_effect_color = video::SColor(0, 0, 0, 0);
|
||||||
param_type = CPT_NONE;
|
param_type = CPT_NONE;
|
||||||
@ -398,10 +389,9 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const
|
|||||||
// general
|
// general
|
||||||
os << serializeString(name);
|
os << serializeString(name);
|
||||||
writeU16(os, groups.size());
|
writeU16(os, groups.size());
|
||||||
for (ItemGroupList::const_iterator i = groups.begin(); i != groups.end();
|
for (const auto &group : groups) {
|
||||||
++i) {
|
os << serializeString(group.first);
|
||||||
os << serializeString(i->first);
|
writeS16(os, group.second);
|
||||||
writeS16(os, i->second);
|
|
||||||
}
|
}
|
||||||
writeU8(os, param_type);
|
writeU8(os, param_type);
|
||||||
writeU8(os, param_type_2);
|
writeU8(os, param_type_2);
|
||||||
@ -411,13 +401,13 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const
|
|||||||
os << serializeString(mesh);
|
os << serializeString(mesh);
|
||||||
writeF1000(os, visual_scale);
|
writeF1000(os, visual_scale);
|
||||||
writeU8(os, 6);
|
writeU8(os, 6);
|
||||||
for (u32 i = 0; i < 6; i++)
|
for (const TileDef &td : tiledef)
|
||||||
tiledef[i].serialize(os, protocol_version);
|
td.serialize(os, protocol_version);
|
||||||
for (u32 i = 0; i < 6; i++)
|
for (const TileDef &td : tiledef_overlay)
|
||||||
tiledef_overlay[i].serialize(os, protocol_version);
|
td.serialize(os, protocol_version);
|
||||||
writeU8(os, CF_SPECIAL_COUNT);
|
writeU8(os, CF_SPECIAL_COUNT);
|
||||||
for (u32 i = 0; i < CF_SPECIAL_COUNT; i++) {
|
for (const TileDef &td : tiledef_special) {
|
||||||
tiledef_special[i].serialize(os, protocol_version);
|
td.serialize(os, protocol_version);
|
||||||
}
|
}
|
||||||
writeU8(os, alpha);
|
writeU8(os, alpha);
|
||||||
writeU8(os, color.getRed());
|
writeU8(os, color.getRed());
|
||||||
@ -427,9 +417,8 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const
|
|||||||
writeU8(os, waving);
|
writeU8(os, waving);
|
||||||
writeU8(os, connect_sides);
|
writeU8(os, connect_sides);
|
||||||
writeU16(os, connects_to_ids.size());
|
writeU16(os, connects_to_ids.size());
|
||||||
for (std::set<content_t>::const_iterator i = connects_to_ids.begin();
|
for (u16 connects_to_id : connects_to_ids)
|
||||||
i != connects_to_ids.end(); ++i)
|
writeU16(os, connects_to_id);
|
||||||
writeU16(os, *i);
|
|
||||||
writeU8(os, post_effect_color.getAlpha());
|
writeU8(os, post_effect_color.getAlpha());
|
||||||
writeU8(os, post_effect_color.getRed());
|
writeU8(os, post_effect_color.getRed());
|
||||||
writeU8(os, post_effect_color.getGreen());
|
writeU8(os, post_effect_color.getGreen());
|
||||||
@ -485,7 +474,7 @@ void ContentFeatures::correctAlpha(TileDef *tiles, int length)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
if (tiles[i].name == "")
|
if (tiles[i].name.empty())
|
||||||
continue;
|
continue;
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
s << tiles[i].name << "^[noalpha^[opacity:" << ((int)alpha);
|
s << tiles[i].name << "^[noalpha^[opacity:" << ((int)alpha);
|
||||||
@ -500,7 +489,9 @@ void ContentFeatures::deSerialize(std::istream &is)
|
|||||||
if (version < 9) {
|
if (version < 9) {
|
||||||
deSerializeOld(is, version);
|
deSerializeOld(is, version);
|
||||||
return;
|
return;
|
||||||
} else if (version > 11) {
|
}
|
||||||
|
|
||||||
|
if (version > 11) {
|
||||||
throw SerializationError("unsupported ContentFeatures version");
|
throw SerializationError("unsupported ContentFeatures version");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -522,15 +513,15 @@ void ContentFeatures::deSerialize(std::istream &is)
|
|||||||
visual_scale = readF1000(is);
|
visual_scale = readF1000(is);
|
||||||
if (readU8(is) != 6)
|
if (readU8(is) != 6)
|
||||||
throw SerializationError("unsupported tile count");
|
throw SerializationError("unsupported tile count");
|
||||||
for (u32 i = 0; i < 6; i++)
|
for (TileDef &td : tiledef)
|
||||||
tiledef[i].deSerialize(is, version, drawtype);
|
td.deSerialize(is, version, drawtype);
|
||||||
if (version >= 10)
|
if (version >= 10)
|
||||||
for (u32 i = 0; i < 6; i++)
|
for (TileDef &td : tiledef_overlay)
|
||||||
tiledef_overlay[i].deSerialize(is, version, drawtype);
|
td.deSerialize(is, version, drawtype);
|
||||||
if (readU8(is) != CF_SPECIAL_COUNT)
|
if (readU8(is) != CF_SPECIAL_COUNT)
|
||||||
throw SerializationError("unsupported CF_SPECIAL_COUNT");
|
throw SerializationError("unsupported CF_SPECIAL_COUNT");
|
||||||
for (u32 i = 0; i < CF_SPECIAL_COUNT; i++)
|
for (TileDef &td : tiledef_special)
|
||||||
tiledef_special[i].deSerialize(is, version, drawtype);
|
td.deSerialize(is, version, drawtype);
|
||||||
alpha = readU8(is);
|
alpha = readU8(is);
|
||||||
color.setRed(readU8(is));
|
color.setRed(readU8(is));
|
||||||
color.setGreen(readU8(is));
|
color.setGreen(readU8(is));
|
||||||
@ -667,14 +658,14 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
|
|||||||
scene::IMeshManipulator *meshmanip, Client *client, const TextureSettings &tsettings)
|
scene::IMeshManipulator *meshmanip, Client *client, const TextureSettings &tsettings)
|
||||||
{
|
{
|
||||||
// minimap pixel color - the average color of a texture
|
// 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);
|
minimap_color = tsrc->getTextureAverageColor(tiledef[0].name);
|
||||||
|
|
||||||
// Figure out the actual tiles to use
|
// Figure out the actual tiles to use
|
||||||
TileDef tdef[6];
|
TileDef tdef[6];
|
||||||
for (u32 j = 0; j < 6; j++) {
|
for (u32 j = 0; j < 6; j++) {
|
||||||
tdef[j] = tiledef[j];
|
tdef[j] = tiledef[j];
|
||||||
if (tdef[j].name == "")
|
if (tdef[j].name.empty())
|
||||||
tdef[j].name = "unknown_node.png";
|
tdef[j].name = "unknown_node.png";
|
||||||
}
|
}
|
||||||
// also the overlay tiles
|
// also the overlay tiles
|
||||||
@ -739,7 +730,7 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
|
|||||||
visual_solidness = 1;
|
visual_solidness = 1;
|
||||||
} else if (tsettings.leaves_style == LEAVES_SIMPLE) {
|
} else if (tsettings.leaves_style == LEAVES_SIMPLE) {
|
||||||
for (u32 j = 0; j < 6; j++) {
|
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;
|
tdef[j].name = tdef_spec[j].name;
|
||||||
}
|
}
|
||||||
drawtype = NDT_GLASSLIKE;
|
drawtype = NDT_GLASSLIKE;
|
||||||
@ -748,8 +739,8 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
|
|||||||
} else {
|
} else {
|
||||||
drawtype = NDT_NORMAL;
|
drawtype = NDT_NORMAL;
|
||||||
solidness = 2;
|
solidness = 2;
|
||||||
for (u32 i = 0; i < 6; i++)
|
for (TileDef &td : tdef)
|
||||||
tdef[i].name += std::string("^[noalpha");
|
td.name += std::string("^[noalpha");
|
||||||
}
|
}
|
||||||
if (waving >= 1)
|
if (waving >= 1)
|
||||||
material_type = TILE_MATERIAL_WAVING_LEAVES;
|
material_type = TILE_MATERIAL_WAVING_LEAVES;
|
||||||
@ -805,7 +796,7 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
|
|||||||
fillTileAttribs(tsrc, &tiles[j].layers[0], &tdef[j], tile_shader,
|
fillTileAttribs(tsrc, &tiles[j].layers[0], &tdef[j], tile_shader,
|
||||||
tsettings.use_normal_texture,
|
tsettings.use_normal_texture,
|
||||||
tdef[j].backface_culling, material_type);
|
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],
|
fillTileAttribs(tsrc, &tiles[j].layers[1], &tdef_overlay[j],
|
||||||
overlay_shader, tsettings.use_normal_texture,
|
overlay_shader, tsettings.use_normal_texture,
|
||||||
tdef[j].backface_culling, overlay_material);
|
tdef[j].backface_culling, overlay_material);
|
||||||
@ -832,7 +823,7 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
|
|||||||
param_type_2 == CPT2_COLORED_WALLMOUNTED)
|
param_type_2 == CPT2_COLORED_WALLMOUNTED)
|
||||||
palette = tsrc->getPalette(palette_name);
|
palette = tsrc->getPalette(palette_name);
|
||||||
|
|
||||||
if ((drawtype == NDT_MESH) && (mesh != "")) {
|
if (drawtype == NDT_MESH && !mesh.empty()) {
|
||||||
// Meshnode drawtype
|
// Meshnode drawtype
|
||||||
// Read the mesh and apply scale
|
// Read the mesh and apply scale
|
||||||
mesh_ptr[0] = client->getMesh(mesh);
|
mesh_ptr[0] = client->getMesh(mesh);
|
||||||
@ -892,7 +883,7 @@ public:
|
|||||||
CNodeDefManager();
|
CNodeDefManager();
|
||||||
virtual ~CNodeDefManager();
|
virtual ~CNodeDefManager();
|
||||||
void clear();
|
void clear();
|
||||||
virtual IWritableNodeDefManager *clone();
|
|
||||||
inline virtual const ContentFeatures& get(content_t c) const;
|
inline virtual const ContentFeatures& get(content_t c) const;
|
||||||
inline virtual const ContentFeatures& get(const MapNode &n) const;
|
inline virtual const ContentFeatures& get(const MapNode &n) const;
|
||||||
virtual bool getId(const std::string &name, content_t &result) const;
|
virtual bool getId(const std::string &name, content_t &result) const;
|
||||||
@ -977,11 +968,10 @@ CNodeDefManager::CNodeDefManager()
|
|||||||
CNodeDefManager::~CNodeDefManager()
|
CNodeDefManager::~CNodeDefManager()
|
||||||
{
|
{
|
||||||
#ifndef SERVER
|
#ifndef SERVER
|
||||||
for (u32 i = 0; i < m_content_features.size(); i++) {
|
for (ContentFeatures &f : m_content_features) {
|
||||||
ContentFeatures *f = &m_content_features[i];
|
for (auto &j : f.mesh_ptr) {
|
||||||
for (u32 j = 0; j < 24; j++) {
|
if (j)
|
||||||
if (f->mesh_ptr[j])
|
j->drop();
|
||||||
f->mesh_ptr[j]->drop();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1057,14 +1047,6 @@ void CNodeDefManager::clear()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
IWritableNodeDefManager *CNodeDefManager::clone()
|
|
||||||
{
|
|
||||||
CNodeDefManager *mgr = new CNodeDefManager();
|
|
||||||
*mgr = *this;
|
|
||||||
return mgr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline const ContentFeatures& CNodeDefManager::get(content_t c) const
|
inline const ContentFeatures& CNodeDefManager::get(content_t c) const
|
||||||
{
|
{
|
||||||
return c < m_content_features.size()
|
return c < m_content_features.size()
|
||||||
@ -1116,10 +1098,9 @@ bool CNodeDefManager::getIds(const std::string &name,
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
const GroupItems &items = i->second;
|
const GroupItems &items = i->second;
|
||||||
for (GroupItems::const_iterator j = items.begin();
|
for (const auto &item : items) {
|
||||||
j != items.end(); ++j) {
|
if (item.second != 0)
|
||||||
if ((*j).second != 0)
|
result.insert(item.first);
|
||||||
result.insert((*j).first);
|
|
||||||
}
|
}
|
||||||
//printf("getIds: %dus\n", t.stop());
|
//printf("getIds: %dus\n", t.stop());
|
||||||
return true;
|
return true;
|
||||||
@ -1141,10 +1122,10 @@ content_t CNodeDefManager::allocateId()
|
|||||||
id >= m_next_id; // overflow?
|
id >= m_next_id; // overflow?
|
||||||
++id) {
|
++id) {
|
||||||
while (id >= m_content_features.size()) {
|
while (id >= m_content_features.size()) {
|
||||||
m_content_features.push_back(ContentFeatures());
|
m_content_features.emplace_back();
|
||||||
}
|
}
|
||||||
const ContentFeatures &f = m_content_features[id];
|
const ContentFeatures &f = m_content_features[id];
|
||||||
if (f.name == "") {
|
if (f.name.empty()) {
|
||||||
m_next_id = id + 1;
|
m_next_id = id + 1;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -1163,9 +1144,8 @@ content_t CNodeDefManager::allocateId()
|
|||||||
*/
|
*/
|
||||||
void boxVectorUnion(const std::vector<aabb3f> &boxes, aabb3f *box_union)
|
void boxVectorUnion(const std::vector<aabb3f> &boxes, aabb3f *box_union)
|
||||||
{
|
{
|
||||||
for (std::vector<aabb3f>::const_iterator it = boxes.begin();
|
for (const aabb3f &box : boxes) {
|
||||||
it != boxes.end(); ++it) {
|
box_union->addInternalBox(box);
|
||||||
box_union->addInternalBox(*it);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1202,9 +1182,9 @@ void getNodeBoxUnion(const NodeBox &nodebox, const ContentFeatures &features,
|
|||||||
fabsf(half_processed.MaxEdge.Y),
|
fabsf(half_processed.MaxEdge.Y),
|
||||||
fabsf(half_processed.MaxEdge.Z) };
|
fabsf(half_processed.MaxEdge.Z) };
|
||||||
f32 max = 0;
|
f32 max = 0;
|
||||||
for (int i = 0; i < 6; i++) {
|
for (float coord : coords) {
|
||||||
if (max < coords[i]) {
|
if (max < coord) {
|
||||||
max = coords[i];
|
max = coord;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Add the union of all possible rotated boxes
|
// Add the union of all possible rotated boxes
|
||||||
@ -1226,9 +1206,9 @@ void getNodeBoxUnion(const NodeBox &nodebox, const ContentFeatures &features,
|
|||||||
fabsf(nodebox.wall_side.MaxEdge.X),
|
fabsf(nodebox.wall_side.MaxEdge.X),
|
||||||
fabsf(nodebox.wall_side.MaxEdge.Z) };
|
fabsf(nodebox.wall_side.MaxEdge.Z) };
|
||||||
f32 max = 0;
|
f32 max = 0;
|
||||||
for (int i = 0; i < 4; i++) {
|
for (float coord : coords) {
|
||||||
if (max < coords[i]) {
|
if (max < coord) {
|
||||||
max = coords[i];
|
max = coord;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Add the union of all possible rotated boxes
|
// Add the union of all possible rotated boxes
|
||||||
@ -1308,18 +1288,16 @@ content_t CNodeDefManager::set(const std::string &name, const ContentFeatures &d
|
|||||||
// Add this content to the list of all groups it belongs to
|
// Add this content to the list of all groups it belongs to
|
||||||
// FIXME: This should remove a node from groups it no longer
|
// FIXME: This should remove a node from groups it no longer
|
||||||
// belongs to when a node is re-registered
|
// belongs to when a node is re-registered
|
||||||
for (ItemGroupList::const_iterator i = def.groups.begin();
|
for (const auto &group : def.groups) {
|
||||||
i != def.groups.end(); ++i) {
|
const std::string &group_name = group.first;
|
||||||
std::string group_name = i->first;
|
|
||||||
|
|
||||||
std::unordered_map<std::string, GroupItems>::iterator
|
std::unordered_map<std::string, GroupItems>::iterator
|
||||||
j = m_group_to_items.find(group_name);
|
j = m_group_to_items.find(group_name);
|
||||||
if (j == m_group_to_items.end()) {
|
if (j == m_group_to_items.end()) {
|
||||||
m_group_to_items[group_name].push_back(
|
m_group_to_items[group_name].emplace_back(id, group.second);
|
||||||
std::make_pair(id, i->second));
|
|
||||||
} else {
|
} else {
|
||||||
GroupItems &items = j->second;
|
GroupItems &items = j->second;
|
||||||
items.push_back(std::make_pair(id, i->second));
|
items.emplace_back(id, group.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
@ -1360,7 +1338,7 @@ void CNodeDefManager::removeNode(const std::string &name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if group is empty
|
// Check if group is empty
|
||||||
if (items.size() == 0)
|
if (items.empty())
|
||||||
m_group_to_items.erase(iter_groups++);
|
m_group_to_items.erase(iter_groups++);
|
||||||
else
|
else
|
||||||
++iter_groups;
|
++iter_groups;
|
||||||
@ -1373,9 +1351,7 @@ void CNodeDefManager::updateAliases(IItemDefManager *idef)
|
|||||||
std::set<std::string> all;
|
std::set<std::string> all;
|
||||||
idef->getAll(all);
|
idef->getAll(all);
|
||||||
m_name_id_mapping_with_aliases.clear();
|
m_name_id_mapping_with_aliases.clear();
|
||||||
for (std::set<std::string>::const_iterator
|
for (const std::string &name : all) {
|
||||||
i = all.begin(); i != all.end(); ++i) {
|
|
||||||
const std::string &name = *i;
|
|
||||||
const std::string &convert_to = idef->getAlias(name);
|
const std::string &convert_to = idef->getAlias(name);
|
||||||
content_t id;
|
content_t id;
|
||||||
if (m_name_id_mapping.getId(convert_to, id)) {
|
if (m_name_id_mapping.getId(convert_to, id)) {
|
||||||
@ -1395,7 +1371,7 @@ void CNodeDefManager::applyTextureOverrides(const std::string &override_filepath
|
|||||||
int line_c = 0;
|
int line_c = 0;
|
||||||
while (std::getline(infile, line)) {
|
while (std::getline(infile, line)) {
|
||||||
line_c++;
|
line_c++;
|
||||||
if (trim(line) == "")
|
if (trim(line).empty())
|
||||||
continue;
|
continue;
|
||||||
std::vector<std::string> splitted = str_split(line, ' ');
|
std::vector<std::string> splitted = str_split(line, ' ');
|
||||||
if (splitted.size() != 3) {
|
if (splitted.size() != 3) {
|
||||||
@ -1424,8 +1400,8 @@ void CNodeDefManager::applyTextureOverrides(const std::string &override_filepath
|
|||||||
else if (splitted[1] == "front")
|
else if (splitted[1] == "front")
|
||||||
nodedef.tiledef[5].name = splitted[2];
|
nodedef.tiledef[5].name = splitted[2];
|
||||||
else if (splitted[1] == "all" || splitted[1] == "*")
|
else if (splitted[1] == "all" || splitted[1] == "*")
|
||||||
for (int i = 0; i < 6; i++)
|
for (TileDef &i : nodedef.tiledef)
|
||||||
nodedef.tiledef[i].name = splitted[2];
|
i.name = splitted[2];
|
||||||
else if (splitted[1] == "sides")
|
else if (splitted[1] == "sides")
|
||||||
for (int i = 2; i < 6; i++)
|
for (int i = 2; i < 6; i++)
|
||||||
nodedef.tiledef[i].name = splitted[2];
|
nodedef.tiledef[i].name = splitted[2];
|
||||||
@ -1475,7 +1451,7 @@ void CNodeDefManager::serialize(std::ostream &os, u16 protocol_version) const
|
|||||||
|| i == CONTENT_UNKNOWN)
|
|| i == CONTENT_UNKNOWN)
|
||||||
continue;
|
continue;
|
||||||
const ContentFeatures *f = &m_content_features[i];
|
const ContentFeatures *f = &m_content_features[i];
|
||||||
if (f->name == "")
|
if (f->name.empty())
|
||||||
continue;
|
continue;
|
||||||
writeU16(os2, i);
|
writeU16(os2, i);
|
||||||
// Wrap it in a string to allow different lengths without
|
// Wrap it in a string to allow different lengths without
|
||||||
@ -1517,7 +1493,7 @@ void CNodeDefManager::deSerialize(std::istream &is)
|
|||||||
"not changing builtin node " << i << std::endl;
|
"not changing builtin node " << i << std::endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (f.name == "") {
|
if (f.name.empty()) {
|
||||||
warningstream << "NodeDefManager::deSerialize(): "
|
warningstream << "NodeDefManager::deSerialize(): "
|
||||||
"received empty name" << std::endl;
|
"received empty name" << std::endl;
|
||||||
continue;
|
continue;
|
||||||
@ -1580,7 +1556,7 @@ void ContentFeatures::serializeOld(std::ostream &os, u16 protocol_version) const
|
|||||||
TileDef compatible_tiles[6];
|
TileDef compatible_tiles[6];
|
||||||
for (u8 i = 0; i < 6; i++) {
|
for (u8 i = 0; i < 6; i++) {
|
||||||
compatible_tiles[i] = tiledef[i];
|
compatible_tiles[i] = tiledef[i];
|
||||||
if (tiledef_overlay[i].name != "") {
|
if (!tiledef_overlay[i].name.empty()) {
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
s << "(" << tiledef[i].name << ")^(" << tiledef_overlay[i].name
|
s << "(" << tiledef[i].name << ")^(" << tiledef_overlay[i].name
|
||||||
<< ")";
|
<< ")";
|
||||||
@ -1594,19 +1570,18 @@ void ContentFeatures::serializeOld(std::ostream &os, u16 protocol_version) const
|
|||||||
|
|
||||||
os << serializeString(name);
|
os << serializeString(name);
|
||||||
writeU16(os, groups.size());
|
writeU16(os, groups.size());
|
||||||
for (ItemGroupList::const_iterator i = groups.begin();
|
for (const auto &group : groups) {
|
||||||
i != groups.end(); ++i) {
|
os << serializeString(group.first);
|
||||||
os << serializeString(i->first);
|
writeS16(os, group.second);
|
||||||
writeS16(os, i->second);
|
|
||||||
}
|
}
|
||||||
writeU8(os, drawtype);
|
writeU8(os, drawtype);
|
||||||
writeF1000(os, compatible_visual_scale);
|
writeF1000(os, compatible_visual_scale);
|
||||||
writeU8(os, 6);
|
writeU8(os, 6);
|
||||||
for (u32 i = 0; i < 6; i++)
|
for (const auto &compatible_tile : compatible_tiles)
|
||||||
compatible_tiles[i].serialize(os, protocol_version);
|
compatible_tile.serialize(os, protocol_version);
|
||||||
writeU8(os, CF_SPECIAL_COUNT);
|
writeU8(os, CF_SPECIAL_COUNT);
|
||||||
for (u32 i = 0; i < CF_SPECIAL_COUNT; i++)
|
for (const TileDef &i : tiledef_special)
|
||||||
tiledef_special[i].serialize(os, protocol_version);
|
i.serialize(os, protocol_version);
|
||||||
writeU8(os, alpha);
|
writeU8(os, alpha);
|
||||||
writeU8(os, post_effect_color.getAlpha());
|
writeU8(os, post_effect_color.getAlpha());
|
||||||
writeU8(os, post_effect_color.getRed());
|
writeU8(os, post_effect_color.getRed());
|
||||||
@ -1646,9 +1621,8 @@ void ContentFeatures::serializeOld(std::ostream &os, u16 protocol_version) const
|
|||||||
collision_box.serialize(os, protocol_version);
|
collision_box.serialize(os, protocol_version);
|
||||||
writeU8(os, floodable);
|
writeU8(os, floodable);
|
||||||
writeU16(os, connects_to_ids.size());
|
writeU16(os, connects_to_ids.size());
|
||||||
for (std::set<content_t>::const_iterator i = connects_to_ids.begin();
|
for (content_t connects_to_id : connects_to_ids)
|
||||||
i != connects_to_ids.end(); ++i)
|
writeU16(os, connects_to_id);
|
||||||
writeU16(os, *i);
|
|
||||||
writeU8(os, connect_sides);
|
writeU8(os, connect_sides);
|
||||||
} else {
|
} else {
|
||||||
throw SerializationError("ContentFeatures::serialize(): "
|
throw SerializationError("ContentFeatures::serialize(): "
|
||||||
@ -1673,12 +1647,12 @@ void ContentFeatures::deSerializeOld(std::istream &is, int version)
|
|||||||
visual_scale = readF1000(is);
|
visual_scale = readF1000(is);
|
||||||
if (readU8(is) != 6)
|
if (readU8(is) != 6)
|
||||||
throw SerializationError("unsupported tile count");
|
throw SerializationError("unsupported tile count");
|
||||||
for (u32 i = 0; i < 6; i++)
|
for (TileDef &i : tiledef)
|
||||||
tiledef[i].deSerialize(is, version, drawtype);
|
i.deSerialize(is, version, drawtype);
|
||||||
if (readU8(is) != CF_SPECIAL_COUNT)
|
if (readU8(is) != CF_SPECIAL_COUNT)
|
||||||
throw SerializationError("unsupported CF_SPECIAL_COUNT");
|
throw SerializationError("unsupported CF_SPECIAL_COUNT");
|
||||||
for (u32 i = 0; i < CF_SPECIAL_COUNT; i++)
|
for (TileDef &i : tiledef_special)
|
||||||
tiledef_special[i].deSerialize(is, version, drawtype);
|
i.deSerialize(is, version, drawtype);
|
||||||
alpha = readU8(is);
|
alpha = readU8(is);
|
||||||
post_effect_color.setAlpha(readU8(is));
|
post_effect_color.setAlpha(readU8(is));
|
||||||
post_effect_color.setRed(readU8(is));
|
post_effect_color.setRed(readU8(is));
|
||||||
@ -1722,8 +1696,8 @@ void ContentFeatures::deSerializeOld(std::istream &is, int version)
|
|||||||
visual_scale = readF1000(is);
|
visual_scale = readF1000(is);
|
||||||
if (readU8(is) != 6)
|
if (readU8(is) != 6)
|
||||||
throw SerializationError("unsupported tile count");
|
throw SerializationError("unsupported tile count");
|
||||||
for (u32 i = 0; i < 6; i++)
|
for (TileDef &i : tiledef)
|
||||||
tiledef[i].deSerialize(is, version, drawtype);
|
i.deSerialize(is, version, drawtype);
|
||||||
// CF_SPECIAL_COUNT in version 6 = 2
|
// CF_SPECIAL_COUNT in version 6 = 2
|
||||||
if (readU8(is) != 2)
|
if (readU8(is) != 2)
|
||||||
throw SerializationError("unsupported CF_SPECIAL_COUNT");
|
throw SerializationError("unsupported CF_SPECIAL_COUNT");
|
||||||
@ -1777,12 +1751,12 @@ void ContentFeatures::deSerializeOld(std::istream &is, int version)
|
|||||||
visual_scale = readF1000(is);
|
visual_scale = readF1000(is);
|
||||||
if (readU8(is) != 6)
|
if (readU8(is) != 6)
|
||||||
throw SerializationError("unsupported tile count");
|
throw SerializationError("unsupported tile count");
|
||||||
for (u32 i = 0; i < 6; i++)
|
for (TileDef &i : tiledef)
|
||||||
tiledef[i].deSerialize(is, version, drawtype);
|
i.deSerialize(is, version, drawtype);
|
||||||
if (readU8(is) != CF_SPECIAL_COUNT)
|
if (readU8(is) != CF_SPECIAL_COUNT)
|
||||||
throw SerializationError("unsupported CF_SPECIAL_COUNT");
|
throw SerializationError("unsupported CF_SPECIAL_COUNT");
|
||||||
for (u32 i = 0; i < CF_SPECIAL_COUNT; i++)
|
for (TileDef &i : tiledef_special)
|
||||||
tiledef_special[i].deSerialize(is, version, drawtype);
|
i.deSerialize(is, version, drawtype);
|
||||||
alpha = readU8(is);
|
alpha = readU8(is);
|
||||||
post_effect_color.setAlpha(readU8(is));
|
post_effect_color.setAlpha(readU8(is));
|
||||||
post_effect_color.setRed(readU8(is));
|
post_effect_color.setRed(readU8(is));
|
||||||
@ -1886,13 +1860,13 @@ void CNodeDefManager::resetNodeResolveState()
|
|||||||
|
|
||||||
void CNodeDefManager::mapNodeboxConnections()
|
void CNodeDefManager::mapNodeboxConnections()
|
||||||
{
|
{
|
||||||
for (u32 i = 0; i < m_content_features.size(); i++) {
|
for (ContentFeatures &f : m_content_features) {
|
||||||
ContentFeatures *f = &m_content_features[i];
|
if (f.drawtype != NDT_NODEBOX || f.node_box.type != NODEBOX_CONNECTED)
|
||||||
if ((f->drawtype != NDT_NODEBOX) || (f->node_box.type != NODEBOX_CONNECTED))
|
|
||||||
continue;
|
continue;
|
||||||
for (std::vector<std::string>::iterator it = f->connects_to.begin();
|
|
||||||
it != f->connects_to.end(); ++it) {
|
for (std::vector<std::string>::const_iterator it = f.connects_to.begin();
|
||||||
getIds(*it, f->connects_to_ids);
|
it != f.connects_to.end(); ++it) {
|
||||||
|
getIds(*it, f.connects_to_ids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ public:
|
|||||||
bool enable_mesh_cache;
|
bool enable_mesh_cache;
|
||||||
bool enable_minimap;
|
bool enable_minimap;
|
||||||
|
|
||||||
TextureSettings() {}
|
TextureSettings() = default;
|
||||||
|
|
||||||
void readSettings();
|
void readSettings();
|
||||||
};
|
};
|
||||||
@ -369,7 +369,7 @@ struct ContentFeatures
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ContentFeatures();
|
ContentFeatures();
|
||||||
~ContentFeatures();
|
~ContentFeatures() = default;
|
||||||
void reset();
|
void reset();
|
||||||
void serialize(std::ostream &os, u16 protocol_version) const;
|
void serialize(std::ostream &os, u16 protocol_version) const;
|
||||||
void deSerialize(std::istream &is);
|
void deSerialize(std::istream &is);
|
||||||
@ -411,8 +411,9 @@ struct ContentFeatures
|
|||||||
|
|
||||||
class INodeDefManager {
|
class INodeDefManager {
|
||||||
public:
|
public:
|
||||||
INodeDefManager(){}
|
INodeDefManager() = default;
|
||||||
virtual ~INodeDefManager(){}
|
virtual ~INodeDefManager() = default;
|
||||||
|
|
||||||
// Get node definition
|
// Get node definition
|
||||||
virtual const ContentFeatures &get(content_t c) const=0;
|
virtual const ContentFeatures &get(content_t c) const=0;
|
||||||
virtual const ContentFeatures &get(const MapNode &n) const=0;
|
virtual const ContentFeatures &get(const MapNode &n) const=0;
|
||||||
@ -438,9 +439,9 @@ public:
|
|||||||
|
|
||||||
class IWritableNodeDefManager : public INodeDefManager {
|
class IWritableNodeDefManager : public INodeDefManager {
|
||||||
public:
|
public:
|
||||||
IWritableNodeDefManager(){}
|
IWritableNodeDefManager() = default;
|
||||||
virtual ~IWritableNodeDefManager(){}
|
virtual ~IWritableNodeDefManager() = default;
|
||||||
virtual IWritableNodeDefManager* clone()=0;
|
|
||||||
// Get node definition
|
// Get node definition
|
||||||
virtual const ContentFeatures &get(content_t c) const=0;
|
virtual const ContentFeatures &get(content_t c) const=0;
|
||||||
virtual const ContentFeatures &get(const MapNode &n) const=0;
|
virtual const ContentFeatures &get(const MapNode &n) const=0;
|
||||||
|
@ -44,15 +44,13 @@ void NodeMetadata::serialize(std::ostream &os, u8 version, bool disk) const
|
|||||||
{
|
{
|
||||||
int num_vars = disk ? m_stringvars.size() : countNonPrivate();
|
int num_vars = disk ? m_stringvars.size() : countNonPrivate();
|
||||||
writeU32(os, num_vars);
|
writeU32(os, num_vars);
|
||||||
for (StringMap::const_iterator
|
for (const auto &sv : m_stringvars) {
|
||||||
it = m_stringvars.begin();
|
bool priv = isPrivate(sv.first);
|
||||||
it != m_stringvars.end(); ++it) {
|
|
||||||
bool priv = isPrivate(it->first);
|
|
||||||
if (!disk && priv)
|
if (!disk && priv)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
os << serializeString(it->first);
|
os << serializeString(sv.first);
|
||||||
os << serializeLongString(it->second);
|
os << serializeLongString(sv.second);
|
||||||
if (version >= 2)
|
if (version >= 2)
|
||||||
writeU8(os, (priv) ? 1 : 0);
|
writeU8(os, (priv) ? 1 : 0);
|
||||||
}
|
}
|
||||||
@ -86,7 +84,7 @@ void NodeMetadata::clear()
|
|||||||
|
|
||||||
bool NodeMetadata::empty() const
|
bool NodeMetadata::empty() const
|
||||||
{
|
{
|
||||||
return Metadata::empty() && m_inventory->getLists().size() == 0;
|
return Metadata::empty() && m_inventory->getLists().empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -103,10 +101,8 @@ int NodeMetadata::countNonPrivate() const
|
|||||||
// m_privatevars can contain names not actually present
|
// m_privatevars can contain names not actually present
|
||||||
// DON'T: return m_stringvars.size() - m_privatevars.size();
|
// DON'T: return m_stringvars.size() - m_privatevars.size();
|
||||||
int n = 0;
|
int n = 0;
|
||||||
for (StringMap::const_iterator
|
for (const auto &sv : m_stringvars) {
|
||||||
it = m_stringvars.begin();
|
if (!isPrivate(sv.first))
|
||||||
it != m_stringvars.end(); ++it) {
|
|
||||||
if (isPrivate(it->first) == false)
|
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
@ -132,12 +128,9 @@ void NodeMetadataList::serialize(std::ostream &os, u8 blockver, bool disk) const
|
|||||||
writeU8(os, version);
|
writeU8(os, version);
|
||||||
writeU16(os, count);
|
writeU16(os, count);
|
||||||
|
|
||||||
for(std::map<v3s16, NodeMetadata*>::const_iterator
|
for (const auto &it : m_data) {
|
||||||
i = m_data.begin();
|
v3s16 p = it.first;
|
||||||
i != m_data.end(); ++i)
|
NodeMetadata *data = it.second;
|
||||||
{
|
|
||||||
v3s16 p = i->first;
|
|
||||||
NodeMetadata *data = i->second;
|
|
||||||
if (data->empty())
|
if (data->empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -60,12 +60,10 @@ void NodeTimerList::serialize(std::ostream &os, u8 map_format_version) const
|
|||||||
writeU16(os, m_timers.size());
|
writeU16(os, m_timers.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::multimap<double, NodeTimer>::const_iterator
|
for (const auto &timer : m_timers) {
|
||||||
i = m_timers.begin();
|
NodeTimer t = timer.second;
|
||||||
i != m_timers.end(); ++i) {
|
|
||||||
NodeTimer t = i->second;
|
|
||||||
NodeTimer nt = NodeTimer(t.timeout,
|
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;
|
v3s16 p = t.position;
|
||||||
|
|
||||||
u16 p16 = p.Z * MAP_BLOCKSIZE * MAP_BLOCKSIZE + p.Y * MAP_BLOCKSIZE + p.X;
|
u16 p16 = p.Z * MAP_BLOCKSIZE * MAP_BLOCKSIZE + p.Y * MAP_BLOCKSIZE + p.X;
|
||||||
|
@ -35,12 +35,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
class NodeTimer
|
class NodeTimer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NodeTimer() {}
|
NodeTimer() = default;
|
||||||
NodeTimer(const v3s16 &position_):
|
NodeTimer(const v3s16 &position_):
|
||||||
position(position_) {}
|
position(position_) {}
|
||||||
NodeTimer(f32 timeout_, f32 elapsed_, v3s16 position_):
|
NodeTimer(f32 timeout_, f32 elapsed_, v3s16 position_):
|
||||||
timeout(timeout_), elapsed(elapsed_), position(position_) {}
|
timeout(timeout_), elapsed(elapsed_), position(position_) {}
|
||||||
~NodeTimer() {}
|
~NodeTimer() = default;
|
||||||
|
|
||||||
void serialize(std::ostream &os) const;
|
void serialize(std::ostream &os) const;
|
||||||
void deSerialize(std::istream &is);
|
void deSerialize(std::istream &is);
|
||||||
@ -57,8 +57,8 @@ public:
|
|||||||
class NodeTimerList
|
class NodeTimerList
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NodeTimerList() {}
|
NodeTimerList() = default;
|
||||||
~NodeTimerList() {}
|
~NodeTimerList() = default;
|
||||||
|
|
||||||
void serialize(std::ostream &os, u8 map_format_version) const;
|
void serialize(std::ostream &os, u8 map_format_version) const;
|
||||||
void deSerialize(std::istream &is, u8 map_format_version);
|
void deSerialize(std::istream &is, u8 map_format_version);
|
||||||
@ -117,10 +117,6 @@ public:
|
|||||||
m_next_trigger_time = -1.;
|
m_next_trigger_time = -1.;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double getNextTriggerTime() {
|
|
||||||
return m_next_trigger_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move forward in time, returns elapsed timers
|
// Move forward in time, returns elapsed timers
|
||||||
std::vector<NodeTimer> step(float dtime);
|
std::vector<NodeTimer> step(float dtime);
|
||||||
|
|
||||||
|
@ -23,10 +23,10 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <math.h>
|
#include <cmath>
|
||||||
#include "noise.h"
|
#include "noise.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string.h> // memset
|
#include <cstring> // memset
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "util/numeric.h"
|
#include "util/numeric.h"
|
||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
@ -262,7 +262,7 @@ float noise2d_gradient(float x, float y, s32 seed, bool eased)
|
|||||||
// Interpolate
|
// Interpolate
|
||||||
if (eased)
|
if (eased)
|
||||||
return biLinearInterpolation(v00, v10, v01, v11, xl, yl);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,12 +292,12 @@ float noise3d_gradient(float x, float y, float z, s32 seed, bool eased)
|
|||||||
v000, v100, v010, v110,
|
v000, v100, v010, v110,
|
||||||
v001, v101, v011, v111,
|
v001, v101, v011, v111,
|
||||||
xl, yl, zl);
|
xl, yl, zl);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
return triLinearInterpolationNoEase(
|
return triLinearInterpolationNoEase(
|
||||||
v000, v100, v010, v110,
|
v000, v100, v010, v110,
|
||||||
v001, v101, v011, v111,
|
v001, v101, v011, v111,
|
||||||
xl, yl, zl);
|
xl, yl, zl);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -778,7 +778,7 @@ float *Noise::perlinMap3D(float x, float y, float z, float *persistence_map)
|
|||||||
|
|
||||||
|
|
||||||
void Noise::updateResults(float g, float *gmap,
|
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
|
// This looks very ugly, but it is 50-70% faster than having
|
||||||
// conditional statements inside the loop
|
// conditional statements inside the loop
|
||||||
|
@ -112,7 +112,7 @@ struct NoiseParams {
|
|||||||
|
|
||||||
NoiseParams() = default;
|
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_,
|
u16 octaves_, float persist_, float lacunarity_,
|
||||||
u32 flags_=NOISE_FLAG_DEFAULTS)
|
u32 flags_=NOISE_FLAG_DEFAULTS)
|
||||||
{
|
{
|
||||||
@ -180,7 +180,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
void allocBuffers();
|
void allocBuffers();
|
||||||
void resizeNoiseBuf(bool is3d);
|
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);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ enum ObjDefType {
|
|||||||
|
|
||||||
class ObjDef {
|
class ObjDef {
|
||||||
public:
|
public:
|
||||||
virtual ~ObjDef() {}
|
virtual ~ObjDef() = default;
|
||||||
|
|
||||||
u32 index;
|
u32 index;
|
||||||
u32 uid;
|
u32 uid;
|
||||||
|
@ -26,8 +26,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
ObjectProperties::ObjectProperties()
|
ObjectProperties::ObjectProperties()
|
||||||
{
|
{
|
||||||
textures.push_back("unknown_object.png");
|
textures.emplace_back("unknown_object.png");
|
||||||
colors.push_back(video::SColor(255,255,255,255));
|
colors.emplace_back(255,255,255,255);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ObjectProperties::dump()
|
std::string ObjectProperties::dump()
|
||||||
@ -42,13 +42,14 @@ std::string ObjectProperties::dump()
|
|||||||
os<<", mesh="<<mesh;
|
os<<", mesh="<<mesh;
|
||||||
os<<", visual_size="<<PP2(visual_size);
|
os<<", visual_size="<<PP2(visual_size);
|
||||||
os<<", textures=[";
|
os<<", textures=[";
|
||||||
for(u32 i=0; i<textures.size(); i++){
|
for (const std::string &texture : textures) {
|
||||||
os<<"\""<<textures[i]<<"\" ";
|
os<<"\""<< texture <<"\" ";
|
||||||
}
|
}
|
||||||
os<<"]";
|
os<<"]";
|
||||||
os<<", colors=[";
|
os<<", colors=[";
|
||||||
for(u32 i=0; i<colors.size(); i++){
|
for (const video::SColor &color : colors) {
|
||||||
os<<"\""<<colors[i].getAlpha()<<","<<colors[i].getRed()<<","<<colors[i].getGreen()<<","<<colors[i].getBlue()<<"\" ";
|
os << "\"" << color.getAlpha() << "," << color.getRed() << ","
|
||||||
|
<< color.getGreen() << "," << color.getBlue() << "\" ";
|
||||||
}
|
}
|
||||||
os<<"]";
|
os<<"]";
|
||||||
os<<", spritediv="<<PP2(spritediv);
|
os<<", spritediv="<<PP2(spritediv);
|
||||||
@ -74,8 +75,8 @@ void ObjectProperties::serialize(std::ostream &os) const
|
|||||||
os<<serializeString(visual);
|
os<<serializeString(visual);
|
||||||
writeV2F1000(os, visual_size);
|
writeV2F1000(os, visual_size);
|
||||||
writeU16(os, textures.size());
|
writeU16(os, textures.size());
|
||||||
for(u32 i=0; i<textures.size(); i++){
|
for (const std::string &texture : textures) {
|
||||||
os<<serializeString(textures[i]);
|
os << serializeString(texture);
|
||||||
}
|
}
|
||||||
writeV2S16(os, spritediv);
|
writeV2S16(os, spritediv);
|
||||||
writeV2S16(os, initial_sprite_basepos);
|
writeV2S16(os, initial_sprite_basepos);
|
||||||
@ -85,8 +86,8 @@ void ObjectProperties::serialize(std::ostream &os) const
|
|||||||
// Added in protocol version 14
|
// Added in protocol version 14
|
||||||
os<<serializeString(mesh);
|
os<<serializeString(mesh);
|
||||||
writeU16(os, colors.size());
|
writeU16(os, colors.size());
|
||||||
for(u32 i=0; i<colors.size(); i++){
|
for (video::SColor color : colors) {
|
||||||
writeARGB8(os, colors[i]);
|
writeARGB8(os, color);
|
||||||
}
|
}
|
||||||
writeU8(os, collideWithObjects);
|
writeU8(os, collideWithObjects);
|
||||||
writeF1000(os,stepheight);
|
writeF1000(os,stepheight);
|
||||||
|
@ -68,7 +68,7 @@ class PathCost {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
/** default constructor */
|
/** default constructor */
|
||||||
PathCost();
|
PathCost() = default;
|
||||||
|
|
||||||
/** copy constructor */
|
/** copy constructor */
|
||||||
PathCost(const PathCost &b);
|
PathCost(const PathCost &b);
|
||||||
@ -76,10 +76,10 @@ public:
|
|||||||
/** assignment operator */
|
/** assignment operator */
|
||||||
PathCost &operator= (const PathCost &b);
|
PathCost &operator= (const PathCost &b);
|
||||||
|
|
||||||
bool valid; /**< movement is possible */
|
bool valid = false; /**< movement is possible */
|
||||||
int value; /**< cost of movement */
|
int value = 0; /**< cost of movement */
|
||||||
int direction; /**< y-direction of movement */
|
int direction = 0; /**< y-direction of movement */
|
||||||
bool updated; /**< this cost has ben calculated */
|
bool updated = false; /**< this cost has ben calculated */
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ class PathGridnode {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
/** default constructor */
|
/** default constructor */
|
||||||
PathGridnode();
|
PathGridnode() = default;
|
||||||
|
|
||||||
/** copy constructor */
|
/** copy constructor */
|
||||||
PathGridnode(const PathGridnode &b);
|
PathGridnode(const PathGridnode &b);
|
||||||
@ -113,17 +113,17 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setCost(v3s16 dir, const PathCost &cost);
|
void setCost(v3s16 dir, const PathCost &cost);
|
||||||
|
|
||||||
bool valid; /**< node is on surface */
|
bool valid = false; /**< node is on surface */
|
||||||
bool target; /**< node is target position */
|
bool target = false; /**< node is target position */
|
||||||
bool source; /**< node is stating position */
|
bool source = false; /**< node is stating position */
|
||||||
int totalcost; /**< cost to move here from starting point */
|
int totalcost = -1; /**< cost to move here from starting point */
|
||||||
v3s16 sourcedir; /**< origin of movement for current cost */
|
v3s16 sourcedir; /**< origin of movement for current cost */
|
||||||
v3s16 pos; /**< real position of node */
|
v3s16 pos; /**< real position of node */
|
||||||
PathCost directions[4]; /**< cost in different directions */
|
PathCost directions[4]; /**< cost in different directions */
|
||||||
|
|
||||||
/* debug values */
|
/* debug values */
|
||||||
bool is_element; /**< node is element of path detected */
|
bool is_element = false; /**< node is element of path detected */
|
||||||
char type; /**< type of node */
|
char type = 'u'; /**< type of node */
|
||||||
};
|
};
|
||||||
|
|
||||||
class Pathfinder;
|
class Pathfinder;
|
||||||
@ -132,7 +132,8 @@ class Pathfinder;
|
|||||||
class GridNodeContainer {
|
class GridNodeContainer {
|
||||||
public:
|
public:
|
||||||
virtual PathGridnode &access(v3s16 p)=0;
|
virtual PathGridnode &access(v3s16 p)=0;
|
||||||
virtual ~GridNodeContainer() {}
|
virtual ~GridNodeContainer() = default;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Pathfinder *m_pathf;
|
Pathfinder *m_pathf;
|
||||||
|
|
||||||
@ -141,7 +142,8 @@ protected:
|
|||||||
|
|
||||||
class ArrayGridNodeContainer : public GridNodeContainer {
|
class ArrayGridNodeContainer : public GridNodeContainer {
|
||||||
public:
|
public:
|
||||||
virtual ~ArrayGridNodeContainer() {}
|
virtual ~ArrayGridNodeContainer() = default;
|
||||||
|
|
||||||
ArrayGridNodeContainer(Pathfinder *pathf, v3s16 dimensions);
|
ArrayGridNodeContainer(Pathfinder *pathf, v3s16 dimensions);
|
||||||
virtual PathGridnode &access(v3s16 p);
|
virtual PathGridnode &access(v3s16 p);
|
||||||
private:
|
private:
|
||||||
@ -154,7 +156,8 @@ private:
|
|||||||
|
|
||||||
class MapGridNodeContainer : public GridNodeContainer {
|
class MapGridNodeContainer : public GridNodeContainer {
|
||||||
public:
|
public:
|
||||||
virtual ~MapGridNodeContainer() {}
|
virtual ~MapGridNodeContainer() = default;
|
||||||
|
|
||||||
MapGridNodeContainer(Pathfinder *pathf);
|
MapGridNodeContainer(Pathfinder *pathf);
|
||||||
virtual PathGridnode &access(v3s16 p);
|
virtual PathGridnode &access(v3s16 p);
|
||||||
private:
|
private:
|
||||||
@ -168,7 +171,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* default constructor
|
* default constructor
|
||||||
*/
|
*/
|
||||||
Pathfinder();
|
Pathfinder() = default;
|
||||||
|
|
||||||
~Pathfinder();
|
~Pathfinder();
|
||||||
|
|
||||||
@ -281,7 +284,7 @@ private:
|
|||||||
* @param level current recursion depth
|
* @param level current recursion depth
|
||||||
* @return true/false path to destination has been found
|
* @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
|
* recursive try to find a patrh to destionation
|
||||||
@ -302,17 +305,17 @@ private:
|
|||||||
void buildPath(std::vector<v3s16> &path, v3s16 pos, int level);
|
void buildPath(std::vector<v3s16> &path, v3s16 pos, int level);
|
||||||
|
|
||||||
/* variables */
|
/* variables */
|
||||||
int m_max_index_x; /**< max index of search area in x direction */
|
int m_max_index_x = 0; /**< 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_y = 0; /**< 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_z = 0; /**< max index of search area in z direction */
|
||||||
|
|
||||||
|
|
||||||
int m_searchdistance; /**< max distance to search in each direction */
|
int m_searchdistance = 0; /**< max distance to search in each direction */
|
||||||
int m_maxdrop; /**< maximum number of blocks a path may drop */
|
int m_maxdrop = 0; /**< maximum number of blocks a path may drop */
|
||||||
int m_maxjump; /**< maximum number of blocks a path may jump */
|
int m_maxjump = 0; /**< maximum number of blocks a path may jump */
|
||||||
int m_min_target_distance; /**< current smalest path to target */
|
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_start; /**< source position */
|
||||||
v3s16 m_destination; /**< destination position */
|
v3s16 m_destination; /**< destination position */
|
||||||
@ -322,9 +325,9 @@ private:
|
|||||||
/** contains all map data already collected and analyzed.
|
/** contains all map data already collected and analyzed.
|
||||||
Access it via the getIndexElement/getIdxElem methods. */
|
Access it via the getIndexElement/getIdxElem methods. */
|
||||||
friend class GridNodeContainer;
|
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
|
#ifdef PATHFINDER_DEBUG
|
||||||
|
|
||||||
@ -394,16 +397,6 @@ std::vector<v3s16> get_path(ServerEnvironment* env,
|
|||||||
searchdistance, max_jump, max_drop, algo);
|
searchdistance, max_jump, max_drop, algo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
PathCost::PathCost()
|
|
||||||
: valid(false),
|
|
||||||
value(0),
|
|
||||||
direction(0),
|
|
||||||
updated(false)
|
|
||||||
{
|
|
||||||
//intentionaly empty
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
PathCost::PathCost(const PathCost &b)
|
PathCost::PathCost(const PathCost &b)
|
||||||
{
|
{
|
||||||
@ -424,20 +417,6 @@ PathCost &PathCost::operator= (const PathCost &b)
|
|||||||
return *this;
|
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)
|
PathGridnode::PathGridnode(const PathGridnode &b)
|
||||||
: valid(b.valid),
|
: valid(b.valid),
|
||||||
@ -728,9 +707,8 @@ std::vector<v3s16> Pathfinder::getPath(ServerEnvironment *env,
|
|||||||
|
|
||||||
//finalize path
|
//finalize path
|
||||||
std::vector<v3s16> full_path;
|
std::vector<v3s16> full_path;
|
||||||
for (std::vector<v3s16>::iterator i = path.begin();
|
for (const v3s16 &i : path) {
|
||||||
i != path.end(); ++i) {
|
full_path.push_back(getIndexElement(i).pos);
|
||||||
full_path.push_back(getIndexElement(*i).pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef PATHFINDER_DEBUG
|
#ifdef PATHFINDER_DEBUG
|
||||||
@ -763,24 +741,6 @@ std::vector<v3s16> Pathfinder::getPath(ServerEnvironment *env,
|
|||||||
return retval;
|
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()
|
Pathfinder::~Pathfinder()
|
||||||
{
|
{
|
||||||
delete m_nodes_container;
|
delete m_nodes_container;
|
||||||
@ -970,19 +930,19 @@ bool Pathfinder::updateAllCosts(v3s16 ipos,
|
|||||||
|
|
||||||
std::vector<v3s16> directions;
|
std::vector<v3s16> directions;
|
||||||
|
|
||||||
directions.push_back(v3s16( 1,0, 0));
|
directions.emplace_back(1,0, 0);
|
||||||
directions.push_back(v3s16(-1,0, 0));
|
directions.emplace_back(-1,0, 0);
|
||||||
directions.push_back(v3s16( 0,0, 1));
|
directions.emplace_back(0,0, 1);
|
||||||
directions.push_back(v3s16( 0,0,-1));
|
directions.emplace_back(0,0,-1);
|
||||||
|
|
||||||
for (unsigned int i=0; i < directions.size(); i++) {
|
for (v3s16 &direction : directions) {
|
||||||
if (directions[i] != srcdir) {
|
if (direction != srcdir) {
|
||||||
PathCost cost = g_pos.getCost(directions[i]);
|
PathCost cost = g_pos.getCost(direction);
|
||||||
|
|
||||||
if (cost.valid) {
|
if (cost.valid) {
|
||||||
directions[i].Y = cost.direction;
|
direction.Y = cost.direction;
|
||||||
|
|
||||||
v3s16 ipos2 = ipos + directions[i];
|
v3s16 ipos2 = ipos + direction;
|
||||||
|
|
||||||
if (!isValidIndex(ipos2)) {
|
if (!isValidIndex(ipos2)) {
|
||||||
DEBUG_OUT(LVL " Pathfinder: " << PP(ipos2) <<
|
DEBUG_OUT(LVL " Pathfinder: " << PP(ipos2) <<
|
||||||
@ -1013,7 +973,7 @@ bool Pathfinder::updateAllCosts(v3s16 ipos,
|
|||||||
DEBUG_OUT(LVL "Pathfinder: updating path at: "<<
|
DEBUG_OUT(LVL "Pathfinder: updating path at: "<<
|
||||||
PP(ipos2) << " from: " << g_pos2.totalcost << " to "<<
|
PP(ipos2) << " from: " << g_pos2.totalcost << " to "<<
|
||||||
new_cost << std::endl);
|
new_cost << std::endl);
|
||||||
if (updateAllCosts(ipos2, invert(directions[i]),
|
if (updateAllCosts(ipos2, invert(direction),
|
||||||
new_cost, level)) {
|
new_cost, level)) {
|
||||||
retval = true;
|
retval = true;
|
||||||
}
|
}
|
||||||
@ -1054,18 +1014,16 @@ v3s16 Pathfinder::getDirHeuristic(std::vector<v3s16> &directions, PathGridnode &
|
|||||||
DEBUG_OUT("Pathfinder: remaining dirs at beginning:"
|
DEBUG_OUT("Pathfinder: remaining dirs at beginning:"
|
||||||
<< directions.size() << std::endl);
|
<< directions.size() << std::endl);
|
||||||
|
|
||||||
for (std::vector<v3s16>::iterator iter = directions.begin();
|
for (v3s16 &direction : directions) {
|
||||||
iter != directions.end();
|
|
||||||
++iter) {
|
|
||||||
|
|
||||||
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);
|
int cur_manhattan = getXZManhattanDist(pos1);
|
||||||
PathCost cost = g_pos.getCost(*iter);
|
PathCost cost = g_pos.getCost(direction);
|
||||||
|
|
||||||
if (!cost.updated) {
|
if (!cost.updated) {
|
||||||
cost = calcCost(g_pos.pos, *iter);
|
cost = calcCost(g_pos.pos, direction);
|
||||||
g_pos.setCost(*iter, cost);
|
g_pos.setCost(direction, cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cost.valid) {
|
if (cost.valid) {
|
||||||
@ -1073,7 +1031,7 @@ v3s16 Pathfinder::getDirHeuristic(std::vector<v3s16> &directions, PathGridnode &
|
|||||||
|
|
||||||
if ((minscore < 0)|| (score < minscore)) {
|
if ((minscore < 0)|| (score < minscore)) {
|
||||||
minscore = score;
|
minscore = score;
|
||||||
retdir = *iter;
|
retdir = direction;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1123,10 +1081,10 @@ bool Pathfinder::updateCostHeuristic( v3s16 ipos,
|
|||||||
|
|
||||||
std::vector<v3s16> directions;
|
std::vector<v3s16> directions;
|
||||||
|
|
||||||
directions.push_back(v3s16( 1, 0, 0));
|
directions.emplace_back(1, 0, 0);
|
||||||
directions.push_back(v3s16(-1, 0, 0));
|
directions.emplace_back(-1, 0, 0);
|
||||||
directions.push_back(v3s16( 0, 0, 1));
|
directions.emplace_back(0, 0, 1);
|
||||||
directions.push_back(v3s16( 0, 0, -1));
|
directions.emplace_back(0, 0, -1);
|
||||||
|
|
||||||
v3s16 direction = getDirHeuristic(directions, g_pos);
|
v3s16 direction = getDirHeuristic(directions, g_pos);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user