summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/map.cpp148
-rw-r--r--src/map.h4
-rw-r--r--src/mapblock.cpp22
-rw-r--r--src/mapblock.h27
-rw-r--r--src/mapblock_mesh.cpp136
-rw-r--r--src/mapgen.cpp18
-rw-r--r--src/mapgen.h6
-rw-r--r--src/mapgen_carpathian.cpp4
-rw-r--r--src/mapgen_flat.h2
-rw-r--r--src/mapgen_v5.h2
-rw-r--r--src/mapgen_v6.cpp21
-rw-r--r--src/util/directiontables.cpp11
-rw-r--r--src/util/directiontables.h2
13 files changed, 159 insertions, 244 deletions
diff --git a/src/map.cpp b/src/map.cpp
index 6cf838696..c6b4769d8 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -74,10 +74,8 @@ Map::~Map()
/*
Free all MapSectors
*/
- for(std::map<v2s16, MapSector*>::iterator i = m_sectors.begin();
- i != m_sectors.end(); ++i)
- {
- delete i->second;
+ for (auto &sector : m_sectors) {
+ delete sector.second;
}
}
@@ -93,11 +91,8 @@ void Map::removeEventReceiver(MapEventReceiver *event_receiver)
void Map::dispatchEvent(MapEditEvent *event)
{
- for(std::set<MapEventReceiver*>::iterator
- i = m_event_receivers.begin();
- i != m_event_receivers.end(); ++i)
- {
- (*i)->onMapEditEvent(event);
+ for (MapEventReceiver *event_receiver : m_event_receivers) {
+ event_receiver->onMapEditEvent(event);
}
}
@@ -110,7 +105,7 @@ MapSector * Map::getSectorNoGenerateNoExNoLock(v2s16 p)
std::map<v2s16, MapSector*>::iterator n = m_sectors.find(p);
- if(n == m_sectors.end())
+ if (n == m_sectors.end())
return NULL;
MapSector *sector = n->second;
@@ -182,7 +177,7 @@ MapNode Map::getNodeNoEx(v3s16 p, bool *is_valid_position)
if (block == NULL) {
if (is_valid_position != NULL)
*is_valid_position = false;
- return MapNode(CONTENT_IGNORE);
+ return {CONTENT_IGNORE};
}
v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
@@ -254,14 +249,11 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
// Update lighting
std::vector<std::pair<v3s16, MapNode> > oldnodes;
- oldnodes.push_back(std::pair<v3s16, MapNode>(p, oldnode));
+ oldnodes.emplace_back(p, oldnode);
voxalgo::update_lighting_nodes(this, oldnodes, modified_blocks);
- for(std::map<v3s16, MapBlock*>::iterator
- i = modified_blocks.begin();
- i != modified_blocks.end(); ++i)
- {
- i->second->expireDayNightDiff();
+ for (auto &modified_block : modified_blocks) {
+ modified_block.second->expireDayNightDiff();
}
// Report for rollback
@@ -277,18 +269,9 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
Add neighboring liquid nodes and this node to transform queue.
(it's vital for the node itself to get updated last, if it was removed.)
*/
- v3s16 dirs[7] = {
- v3s16(0,0,1), // back
- v3s16(0,1,0), // top
- v3s16(1,0,0), // right
- v3s16(0,0,-1), // front
- v3s16(0,-1,0), // bottom
- v3s16(-1,0,0), // left
- v3s16(0,0,0), // self
- };
- for(u16 i=0; i<7; i++)
- {
- v3s16 p2 = p + dirs[i];
+
+ for (const v3s16 &dir : g_7dirs) {
+ v3s16 p2 = p + dir;
bool is_valid_position;
MapNode n2 = getNodeNoEx(p2, &is_valid_position);
@@ -318,11 +301,8 @@ bool Map::addNodeWithEvent(v3s16 p, MapNode n, bool remove_metadata)
addNodeAndUpdate(p, n, modified_blocks, remove_metadata);
// Copy modified_blocks to event
- for(std::map<v3s16, MapBlock*>::iterator
- i = modified_blocks.begin();
- i != modified_blocks.end(); ++i)
- {
- event.modified_blocks.insert(i->first);
+ for (auto &modified_block : modified_blocks) {
+ event.modified_blocks.insert(modified_block.first);
}
}
catch(InvalidPositionException &e){
@@ -346,11 +326,8 @@ bool Map::removeNodeWithEvent(v3s16 p)
removeNodeAndUpdate(p, modified_blocks);
// Copy modified_blocks to event
- for(std::map<v3s16, MapBlock*>::iterator
- i = modified_blocks.begin();
- i != modified_blocks.end(); ++i)
- {
- event.modified_blocks.insert(i->first);
+ for (auto &modified_block : modified_blocks) {
+ event.modified_blocks.insert(modified_block.first);
}
}
catch(InvalidPositionException &e){
@@ -397,19 +374,15 @@ void Map::timerUpdate(float dtime, float unload_timeout, u32 max_loaded_blocks,
// If there is no practical limit, we spare creation of mapblock_queue
if (max_loaded_blocks == U32_MAX) {
- for (std::map<v2s16, MapSector*>::iterator si = m_sectors.begin();
- si != m_sectors.end(); ++si) {
- MapSector *sector = si->second;
+ for (auto &sector_it : m_sectors) {
+ MapSector *sector = sector_it.second;
bool all_blocks_deleted = true;
MapBlockVect blocks;
sector->getBlocks(blocks);
- for (MapBlockVect::iterator i = blocks.begin();
- i != blocks.end(); ++i) {
- MapBlock *block = (*i);
-
+ for (MapBlock *block : blocks) {
block->incrementUsageTimer(dtime);
if (block->refGet() == 0
@@ -439,22 +412,18 @@ void Map::timerUpdate(float dtime, float unload_timeout, u32 max_loaded_blocks,
}
if (all_blocks_deleted) {
- sector_deletion_queue.push_back(si->first);
+ sector_deletion_queue.push_back(sector_it.first);
}
}
} else {
std::priority_queue<TimeOrderedMapBlock> mapblock_queue;
- for (std::map<v2s16, MapSector*>::iterator si = m_sectors.begin();
- si != m_sectors.end(); ++si) {
- MapSector *sector = si->second;
+ for (auto &sector_it : m_sectors) {
+ MapSector *sector = sector_it.second;
MapBlockVect blocks;
sector->getBlocks(blocks);
- for(MapBlockVect::iterator i = blocks.begin();
- i != blocks.end(); ++i) {
- MapBlock *block = (*i);
-
+ for (MapBlock *block : blocks) {
block->incrementUsageTimer(dtime);
mapblock_queue.push(TimeOrderedMapBlock(sector, block));
}
@@ -491,10 +460,9 @@ void Map::timerUpdate(float dtime, float unload_timeout, u32 max_loaded_blocks,
block_count_all--;
}
// Delete empty sectors
- for (std::map<v2s16, MapSector*>::iterator si = m_sectors.begin();
- si != m_sectors.end(); ++si) {
- if (si->second->empty()) {
- sector_deletion_queue.push_back(si->first);
+ for (auto &sector_it : m_sectors) {
+ if (sector_it.second->empty()) {
+ sector_deletion_queue.push_back(sector_it.first);
}
}
}
@@ -876,7 +844,7 @@ void Map::transformLiquids(std::map<v3s16, MapBlock*> &modified_blocks,
MapBlock *block = getBlockNoCreateNoEx(blockpos);
if (block != NULL) {
modified_blocks[blockpos] = block;
- changed_nodes.push_back(std::pair<v3s16, MapNode>(p0, n00));
+ changed_nodes.emplace_back(p0, n00);
}
/*
@@ -902,8 +870,8 @@ void Map::transformLiquids(std::map<v3s16, MapBlock*> &modified_blocks,
}
//infostream<<"Map::transformLiquids(): loopcount="<<loopcount<<std::endl;
- for (std::deque<v3s16>::iterator iter = must_reflow.begin(); iter != must_reflow.end(); ++iter)
- m_transforming_liquid.push_back(*iter);
+ for (auto &iter : must_reflow)
+ m_transforming_liquid.push_back(iter);
voxalgo::update_lighting_nodes(this, changed_nodes, modified_blocks);
@@ -1205,14 +1173,11 @@ ServerMap::ServerMap(const std::string &savedir, IGameDef *gamedef,
m_savedir = savedir;
m_map_saving_enabled = false;
- try
- {
+ try {
// If directory exists, check contents and load if possible
- if(fs::PathExists(m_savedir))
- {
+ if (fs::PathExists(m_savedir)) {
// If directory is empty, it is safe to save into it.
- if(fs::GetDirListing(m_savedir).size() == 0)
- {
+ if (fs::GetDirListing(m_savedir).empty()) {
infostream<<"ServerMap: Empty save directory is valid."
<<std::endl;
m_map_saving_enabled = true;
@@ -1442,10 +1407,8 @@ void ServerMap::finishBlockMake(BlockMakeData *data,
data->transforming_liquid.pop_front();
}
- for (std::map<v3s16, MapBlock *>::iterator
- it = changed_blocks->begin();
- it != changed_blocks->end(); ++it) {
- MapBlock *block = it->second;
+ for (auto &changed_block : *changed_blocks) {
+ MapBlock *block = changed_block.second;
if (!block)
continue;
/*
@@ -1975,10 +1938,7 @@ void ServerMap::save(ModifiedState save_level)
MapBlockVect blocks;
sector->getBlocks(blocks);
- for(MapBlockVect::iterator j = blocks.begin();
- j != blocks.end(); ++j) {
- MapBlock *block = *j;
-
+ for (MapBlock *block : blocks) {
block_count_all++;
if(block->getModified() >= (u32)save_level) {
@@ -2032,17 +1992,14 @@ void ServerMap::listAllLoadableBlocks(std::vector<v3s16> &dst)
void ServerMap::listAllLoadedBlocks(std::vector<v3s16> &dst)
{
- for(std::map<v2s16, MapSector*>::iterator si = m_sectors.begin();
- si != m_sectors.end(); ++si)
- {
- MapSector *sector = si->second;
+ for (auto &sector_it : m_sectors) {
+ MapSector *sector = sector_it.second;
MapBlockVect blocks;
sector->getBlocks(blocks);
- for(MapBlockVect::iterator i = blocks.begin();
- i != blocks.end(); ++i) {
- v3s16 p = (*i)->getPos();
+ for (MapBlock *block : blocks) {
+ v3s16 p = block->getPos();
dst.push_back(p);
}
}
@@ -2232,22 +2189,22 @@ MapDatabase *ServerMap::createDatabase(
if (name == "dummy")
return new Database_Dummy();
#if USE_LEVELDB
- else if (name == "leveldb")
+ if (name == "leveldb")
return new Database_LevelDB(savedir);
#endif
#if USE_REDIS
- else if (name == "redis")
+ if (name == "redis")
return new Database_Redis(conf);
#endif
#if USE_POSTGRESQL
- else if (name == "postgresql") {
- std::string connect_string = "";
+ if (name == "postgresql") {
+ std::string connect_string;
conf.getNoEx("pgsql_connection", connect_string);
return new MapDatabasePostgreSQL(connect_string);
}
#endif
- else
- throw BaseException(std::string("Database backend ") + name + " not supported.");
+
+ throw BaseException(std::string("Database backend ") + name + " not supported.");
}
void ServerMap::beginSave()
@@ -2448,7 +2405,7 @@ MapBlock* ServerMap::loadBlock(v3s16 blockpos)
std::string ret;
dbase->loadBlock(blockpos, &ret);
- if (ret != "") {
+ if (!ret.empty()) {
loadBlock(&ret, blockpos, createSector(p2d), false);
} else {
// Not found in database, try the files
@@ -2556,10 +2513,6 @@ MMVManip::MMVManip(Map *map):
{
}
-MMVManip::~MMVManip()
-{
-}
-
void MMVManip::initialEmerge(v3s16 blockpos_min, v3s16 blockpos_max,
bool load_if_inexistent)
{
@@ -2657,13 +2610,10 @@ void MMVManip::blitBackAll(std::map<v3s16, MapBlock*> *modified_blocks,
/*
Copy data of all blocks
*/
- for(std::map<v3s16, u8>::iterator
- i = m_loaded_blocks.begin();
- i != m_loaded_blocks.end(); ++i)
- {
- v3s16 p = i->first;
+ for (auto &loaded_block : m_loaded_blocks) {
+ v3s16 p = loaded_block.first;
MapBlock *block = m_map->getBlockNoCreateNoEx(p);
- bool existed = !(i->second & VMANIP_BLOCK_DATA_INEXIST);
+ bool existed = !(loaded_block.second & VMANIP_BLOCK_DATA_INEXIST);
if (!existed || (block == NULL) ||
(!overwrite_generated && block->isGenerated()))
continue;
diff --git a/src/map.h b/src/map.h
index 93ab591a3..50fffa577 100644
--- a/src/map.h
+++ b/src/map.h
@@ -168,8 +168,6 @@ public:
their differing fetch methods.
*/
virtual MapSector * emergeSector(v2s16 p){ return NULL; }
- virtual MapSector * emergeSector(v2s16 p,
- std::map<v3s16, MapBlock*> &changed_blocks){ return NULL; }
// Returns InvalidPositionException if not found
MapBlock * getBlockNoCreate(v3s16 p);
@@ -496,7 +494,7 @@ class MMVManip : public VoxelManipulator
{
public:
MMVManip(Map *map);
- virtual ~MMVManip();
+ virtual ~MMVManip() = default;
virtual void clear()
{
diff --git a/src/mapblock.cpp b/src/mapblock.cpp
index 48b7c1915..88f04e0bb 100644
--- a/src/mapblock.cpp
+++ b/src/mapblock.cpp
@@ -250,9 +250,7 @@ bool MapBlock::propagateSunlight(std::set<v3s16> & light_sources,
else if(current_light == LIGHT_SUN && nodemgr->get(n).sunlight_propagates)
{
// Do nothing: Sunlight is continued
- }
- else if(nodemgr->get(n).light_propagates == false)
- {
+ } else if (!nodemgr->get(n).light_propagates) {
// A solid object is on the way.
stopped_to_solid_object = true;
@@ -305,10 +303,10 @@ bool MapBlock::propagateSunlight(std::set<v3s16> & light_sources,
if(nodemgr->get(n).light_propagates)
{
if(n.getLight(LIGHTBANK_DAY, nodemgr) == LIGHT_SUN
- && sunlight_should_go_down == false)
+ && !sunlight_should_go_down)
block_below_is_valid = false;
else if(n.getLight(LIGHTBANK_DAY, nodemgr) != LIGHT_SUN
- && sunlight_should_go_down == true)
+ && sunlight_should_go_down)
block_below_is_valid = false;
}
}
@@ -563,7 +561,7 @@ void MapBlock::serialize(std::ostream &os, u8 version, bool disk)
flags |= 0x01;
if(getDayNightDiff())
flags |= 0x02;
- if(m_generated == false)
+ if (!m_generated)
flags |= 0x08;
writeU8(os, flags);
if (version >= 27) {
@@ -659,13 +657,13 @@ void MapBlock::deSerialize(std::istream &is, u8 version, bool disk)
}
u8 flags = readU8(is);
- is_underground = (flags & 0x01) ? true : false;
- m_day_night_differs = (flags & 0x02) ? true : false;
+ is_underground = (flags & 0x01) != 0;
+ m_day_night_differs = (flags & 0x02) != 0;
if (version < 27)
m_lighting_complete = 0xFFFF;
else
m_lighting_complete = readU16(is);
- m_generated = (flags & 0x08) ? false : true;
+ m_generated = (flags & 0x08) == 0;
/*
Bulk node data
@@ -839,10 +837,10 @@ void MapBlock::deSerialize_pre22(std::istream &is, u8 version, bool disk)
} else { // All other versions (10 to 21)
u8 flags;
is.read((char*)&flags, 1);
- is_underground = (flags & 0x01) ? true : false;
- m_day_night_differs = (flags & 0x02) ? true : false;
+ is_underground = (flags & 0x01) != 0;
+ m_day_night_differs = (flags & 0x02) != 0;
if(version >= 18)
- m_generated = (flags & 0x08) ? false : true;
+ m_generated = (flags & 0x08) == 0;
// Uncompress data
std::ostringstream os(std::ios_base::binary);
diff --git a/src/mapblock.h b/src/mapblock.h
index 84991631d..83f13f302 100644
--- a/src/mapblock.h
+++ b/src/mapblock.h
@@ -255,7 +255,7 @@ public:
*valid_position = isValidPosition(x, y, z);
if (!*valid_position)
- return MapNode(CONTENT_IGNORE);
+ return {CONTENT_IGNORE};
return data[z * zstride + y * ystride + x];
}
@@ -292,8 +292,8 @@ public:
inline MapNode getNodeNoCheck(s16 x, s16 y, s16 z, bool *valid_position)
{
*valid_position = data != nullptr;
- if (!valid_position)
- return MapNode(CONTENT_IGNORE);
+ if (!*valid_position)
+ return {CONTENT_IGNORE};
return data[z * zstride + y * ystride + x];
}
@@ -456,12 +456,12 @@ public:
//// Node Timers
////
- inline NodeTimer getNodeTimer(v3s16 p)
+ inline NodeTimer getNodeTimer(const v3s16 &p)
{
return m_node_timers.get(p);
}
- inline void removeNodeTimer(v3s16 p)
+ inline void removeNodeTimer(const v3s16 &p)
{
m_node_timers.remove(p);
}
@@ -640,31 +640,16 @@ inline bool blockpos_over_max_limit(v3s16 p)
/*
Returns the position of the block where the node is located
*/
-inline v3s16 getNodeBlockPos(v3s16 p)
-{
- return getContainerPos(p, MAP_BLOCKSIZE);
-}
-
-inline v2s16 getNodeSectorPos(v2s16 p)
+inline v3s16 getNodeBlockPos(const v3s16 &p)
{
return getContainerPos(p, MAP_BLOCKSIZE);
}
-inline s16 getNodeBlockY(s16 y)
-{
- return getContainerPos(y, MAP_BLOCKSIZE);
-}
-
inline void getNodeBlockPosWithOffset(const v3s16 &p, v3s16 &block, v3s16 &offset)
{
getContainerPosWithOffset(p, MAP_BLOCKSIZE, block, offset);
}
-inline void getNodeSectorPosWithOffset(const v2s16 &p, v2s16 &block, v2s16 &offset)
-{
- getContainerPosWithOffset(p, MAP_BLOCKSIZE, block, offset);
-}
-
/*
Get a quick string to describe what a block actually contains
*/
diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp
index f1eb2c5b2..2e408ba4b 100644
--- a/src/mapblock_mesh.cpp
+++ b/src/mapblock_mesh.cpp
@@ -71,8 +71,7 @@ void MeshMakeData::fill(MapBlock *block)
// Get map for reading neigbhor blocks
Map *map = block->getParent();
- for (u16 i=0; i<26; i++) {
- const v3s16 &dir = g_26dirs[i];
+ for (const v3s16 &dir : g_26dirs) {
v3s16 bp = m_blockpos + dir;
MapBlock *b = map->getBlockNoCreateNoEx(bp);
if(b)
@@ -220,9 +219,8 @@ static u16 getSmoothLightCombined(const v3s16 &p, MeshMakeData *data)
u16 light_day = 0;
u16 light_night = 0;
- for (u32 i = 0; i < 8; i++)
- {
- MapNode n = data->m_vmanip.getNodeNoExNoEmerge(p - dirs8[i]);
+ for (const v3s16 &dir : dirs8) {
+ MapNode n = data->m_vmanip.getNodeNoExNoEmerge(p - dir);
// if it's CONTENT_IGNORE we can't do any light calculations
if (n.getContent() == CONTENT_IGNORE) {
@@ -426,7 +424,7 @@ struct FastFace
};
static void makeFastFace(const TileSpec &tile, u16 li0, u16 li1, u16 li2, u16 li3,
- v3f p, v3s16 dir, v3f scale, std::vector<FastFace> &dest)
+ const v3f &p, v3s16 dir, v3f scale, std::vector<FastFace> &dest)
{
// Position is at the center of the cube.
v3f pos = p * BS;
@@ -561,12 +559,11 @@ static void makeFastFace(const TileSpec &tile, u16 li0, u16 li1, u16 li2, u16 li
);
}
- for(u16 i=0; i<4; i++)
- {
- vertex_pos[i].X *= scale.X;
- vertex_pos[i].Y *= scale.Y;
- vertex_pos[i].Z *= scale.Z;
- vertex_pos[i] += pos;
+ for (v3f &vpos : vertex_pos) {
+ vpos.X *= scale.X;
+ vpos.Y *= scale.Y;
+ vpos.Z *= scale.Z;
+ vpos += pos;
}
f32 abs_scale = 1.0;
@@ -656,7 +653,7 @@ static u8 face_contents(content_t m1, content_t m2, bool *equivalent,
bool solidness_differs = (c1 != c2);
bool makes_face = contents_differ && solidness_differs;
- if(makes_face == false)
+ if (!makes_face)
return 0;
if(c1 == 0)
@@ -673,10 +670,10 @@ static u8 face_contents(content_t m1, content_t m2, bool *equivalent,
return 2;
}
- if(c1 > c2)
+ if (c1 > c2)
return 1;
- else
- return 2;
+
+ return 2;
}
/*
@@ -688,13 +685,12 @@ void getNodeTileN(MapNode mn, v3s16 p, u8 tileindex, MeshMakeData *data, TileSpe
const ContentFeatures &f = ndef->get(mn);
tile = f.tiles[tileindex];
TileLayer *top_layer = NULL;
- for (int layernum = 0; layernum < MAX_TILE_LAYERS; layernum++) {
- TileLayer *layer = &tile.layers[layernum];
- if (layer->texture_id == 0)
+ for (TileLayer &layer : tile.layers) {
+ if (layer.texture_id == 0)
continue;
- top_layer = layer;
- if (!layer->has_color)
- mn.getColor(f, &(layer->color));
+ top_layer = &layer;
+ if (!layer.has_color)
+ mn.getColor(f, &(layer.color));
}
// Apply temporary crack
if (p == data->m_crack_pos_relative)
@@ -826,9 +822,8 @@ static void getTileInfo(
// eg. water and glass
if (equivalent) {
- for (int layernum = 0; layernum < MAX_TILE_LAYERS; layernum++)
- tile.layers[layernum].material_flags |=
- MATERIAL_FLAG_BACKFACE_CULLING;
+ for (TileLayer &layer : tile.layers)
+ layer.material_flags |= MATERIAL_FLAG_BACKFACE_CULLING;
}
if (!data->m_smooth_lighting) {
@@ -1008,8 +1003,8 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
m_last_crack(-1),
m_last_daynight_ratio((u32) -1)
{
- for (int m = 0; m < MAX_TILE_LAYERS; m++)
- m_mesh[m] = new scene::SMesh();
+ for (auto &m : m_mesh)
+ m = new scene::SMesh();
m_enable_shaders = data->m_use_shaders;
m_use_tangent_vertices = data->m_use_tangent_vertices;
m_enable_vbo = g_settings->getBool("enable_vbo");
@@ -1052,9 +1047,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
// (NOTE: probably outdated)
//TimeTaker timer2("MeshCollector building");
- for (u32 i = 0; i < fastfaces_new.size(); i++) {
- FastFace &f = fastfaces_new[i];
-
+ for (const FastFace &f : fastfaces_new) {
const u16 indices[] = {0,1,2,2,3,0};
const u16 indices_alternate[] = {0,1,3,2,3,1};
@@ -1240,14 +1233,14 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
MapBlockMesh::~MapBlockMesh()
{
- for (int m = 0; m < MAX_TILE_LAYERS; m++) {
- if (m_enable_vbo && m_mesh[m])
- for (u32 i = 0; i < m_mesh[m]->getMeshBufferCount(); i++) {
- scene::IMeshBuffer *buf = m_mesh[m]->getMeshBuffer(i);
+ for (scene::IMesh *m : m_mesh) {
+ if (m_enable_vbo && m)
+ for (u32 i = 0; i < m->getMeshBufferCount(); i++) {
+ scene::IMeshBuffer *buf = m->getMeshBuffer(i);
RenderingEngine::get_video_driver()->removeHardwareBuffer(buf);
}
- m_mesh[m]->drop();
- m_mesh[m] = NULL;
+ m->drop();
+ m = NULL;
}
delete m_minimap_mapblock;
}
@@ -1263,13 +1256,11 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
m_animation_force_timer = myrand_range(5, 100);
// Cracks
- if(crack != m_last_crack)
- {
- for (std::map<std::pair<u8, u32>, std::string>::iterator i =
- m_crack_materials.begin(); i != m_crack_materials.end(); ++i) {
- scene::IMeshBuffer *buf = m_mesh[i->first.first]->
- getMeshBuffer(i->first.second);
- std::string basename = i->second;
+ if (crack != m_last_crack) {
+ for (auto &crack_material : m_crack_materials) {
+ scene::IMeshBuffer *buf = m_mesh[crack_material.first.first]->
+ getMeshBuffer(crack_material.first.second);
+ std::string basename = crack_material.second;
// Create new texture name from original
std::ostringstream os;
@@ -1281,14 +1272,13 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
// If the current material is also animated,
// update animation info
- std::map<std::pair<u8, u32>, TileLayer>::iterator anim_iter =
- m_animation_tiles.find(i->first);
+ auto anim_iter = m_animation_tiles.find(crack_material.first);
if (anim_iter != m_animation_tiles.end()){
TileLayer &tile = anim_iter->second;
tile.texture = new_texture;
tile.texture_id = new_texture_id;
// force animation update
- m_animation_frames[i->first] = -1;
+ m_animation_frames[crack_material.first] = -1;
}
}
@@ -1296,21 +1286,20 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
}
// Texture animation
- for (std::map<std::pair<u8, u32>, TileLayer>::iterator i =
- m_animation_tiles.begin(); i != m_animation_tiles.end(); ++i) {
- const TileLayer &tile = i->second;
+ for (auto &animation_tile : m_animation_tiles) {
+ const TileLayer &tile = animation_tile.second;
// Figure out current frame
- int frameoffset = m_animation_frame_offsets[i->first];
+ int frameoffset = m_animation_frame_offsets[animation_tile.first];
int frame = (int)(time * 1000 / tile.animation_frame_length_ms
+ frameoffset) % tile.animation_frame_count;
// If frame doesn't change, skip
- if(frame == m_animation_frames[i->first])
+ if(frame == m_animation_frames[animation_tile.first])
continue;
- m_animation_frames[i->first] = frame;
+ m_animation_frames[animation_tile.first] = frame;
- scene::IMeshBuffer *buf = m_mesh[i->first.first]->
- getMeshBuffer(i->first.second);
+ scene::IMeshBuffer *buf = m_mesh[animation_tile.first.first]->
+ getMeshBuffer(animation_tile.first.second);
const FrameSpec &animation_frame = (*tile.frames)[frame];
buf->getMaterial().setTexture(0, animation_frame.texture);
@@ -1327,20 +1316,17 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
{
// Force reload mesh to VBO
if (m_enable_vbo)
- for (int m = 0; m < MAX_TILE_LAYERS; m++)
- m_mesh[m]->setDirty();
+ for (scene::IMesh *m : m_mesh)
+ m->setDirty();
video::SColorf day_color;
get_sunlight_color(&day_color, daynight_ratio);
- for(std::map<std::pair<u8, u32>, std::map<u32, video::SColor > >::iterator
- i = m_daynight_diffs.begin();
- i != m_daynight_diffs.end(); ++i)
- {
- scene::IMeshBuffer *buf = m_mesh[i->first.first]->
- getMeshBuffer(i->first.second);
+
+ for (auto &daynight_diff : m_daynight_diffs) {
+ scene::IMeshBuffer *buf = m_mesh[daynight_diff.first.first]->
+ getMeshBuffer(daynight_diff.first.second);
video::S3DVertex *vertices = (video::S3DVertex *)buf->getVertices();
- for(std::map<u32, video::SColor >::iterator
- j = i->second.begin();
- j != i->second.end(); ++j)
+ for (auto j = daynight_diff.second.begin();
+ j != daynight_diff.second.end(); ++j)
{
final_color_blend(&(vertices[j->first].Color),
j->second, day_color);
@@ -1355,11 +1341,11 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
void MapBlockMesh::updateCameraOffset(v3s16 camera_offset)
{
if (camera_offset != m_camera_offset) {
- for (u8 layer = 0; layer < 2; layer++) {
- translateMesh(m_mesh[layer],
+ for (scene::IMesh *layer : m_mesh) {
+ translateMesh(layer,
intToFloat(m_camera_offset - camera_offset, BS));
if (m_enable_vbo) {
- m_mesh[layer]->setDirty();
+ layer->setDirty();
}
}
m_camera_offset = camera_offset;
@@ -1394,8 +1380,7 @@ void MeshCollector::append(const TileLayer &layer,
std::vector<PreMeshBuffer> *buffers = &prebuffers[layernum];
PreMeshBuffer *p = NULL;
- for (u32 i = 0; i < buffers->size(); i++) {
- PreMeshBuffer &pp = (*buffers)[i];
+ for (PreMeshBuffer &pp : *buffers) {
if (pp.layer != layer)
continue;
if (pp.indices.size() + numIndices > 65535)
@@ -1465,8 +1450,7 @@ void MeshCollector::append(const TileLayer &layer,
std::vector<PreMeshBuffer> *buffers = &prebuffers[layernum];
PreMeshBuffer *p = NULL;
- for (u32 i = 0; i < buffers->size(); i++) {
- PreMeshBuffer &pp = (*buffers)[i];
+ for (PreMeshBuffer &pp : *buffers) {
if(pp.layer != layer)
continue;
if(pp.indices.size() + numIndices > 65535)
@@ -1518,8 +1502,8 @@ void MeshCollector::append(const TileLayer &layer,
void MeshCollector::applyTileColors()
{
if (m_use_tangent_vertices)
- for (int layer = 0; layer < MAX_TILE_LAYERS; layer++) {
- for (auto &pmb : prebuffers[layer]) {
+ for (auto &prebuffer : prebuffers) {
+ for (PreMeshBuffer &pmb : prebuffer) {
video::SColor tc = pmb.layer.color;
if (tc == video::SColor(0xFFFFFFFF))
continue;
@@ -1532,8 +1516,8 @@ void MeshCollector::applyTileColors()
}
}
else
- for (int layer = 0; layer < MAX_TILE_LAYERS; layer++) {
- for (auto &pmb : prebuffers[layer]) {
+ for (auto &prebuffer : prebuffers) {
+ for (PreMeshBuffer &pmb : prebuffer) {
video::SColor tc = pmb.layer.color;
if (tc == video::SColor(0xFFFFFFFF))
continue;
diff --git a/src/mapgen.cpp b/src/mapgen.cpp
index cec59389d..fe7f74cfa 100644
--- a/src/mapgen.cpp
+++ b/src/mapgen.cpp
@@ -98,11 +98,6 @@ STATIC_ASSERT(
//// Mapgen
////
-Mapgen::Mapgen()
-{
-}
-
-
Mapgen::Mapgen(int mapgenid, MapgenParams *params, EmergeManager *emerge) :
gennotify(emerge->gen_notify_on, &emerge->gen_notify_on_deco_ids)
{
@@ -131,11 +126,6 @@ Mapgen::Mapgen(int mapgenid, MapgenParams *params, EmergeManager *emerge) :
}
-Mapgen::~Mapgen()
-{
-}
-
-
MapgenType Mapgen::getMapgenType(const std::string &mgname)
{
for (size_t i = 0; i != ARRLEN(g_reg_mapgens); i++) {
@@ -283,7 +273,8 @@ s16 Mapgen::findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax)
MapNode &n = vm->m_data[i];
if (ndef->get(n).walkable)
return -MAX_MAP_GENERATION_LIMIT;
- else if (ndef->get(n).isLiquid())
+
+ if (ndef->get(n).isLiquid())
break;
vm->m_area.add_y(em, i, -1);
@@ -939,11 +930,6 @@ void MapgenBasic::generateDungeons(s16 max_stone_y,
//// GenerateNotifier
////
-GenerateNotifier::GenerateNotifier()
-{
-}
-
-
GenerateNotifier::GenerateNotifier(u32 notify_on,
std::set<u32> *notify_on_deco_ids)
{
diff --git a/src/mapgen.h b/src/mapgen.h
index 7b7904189..8c34a9719 100644
--- a/src/mapgen.h
+++ b/src/mapgen.h
@@ -92,7 +92,7 @@ struct GenNotifyEvent {
class GenerateNotifier {
public:
- GenerateNotifier();
+ GenerateNotifier() = default;
GenerateNotifier(u32 notify_on, std::set<u32> *notify_on_deco_ids);
void setNotifyOn(u32 notify_on);
@@ -180,9 +180,9 @@ public:
BiomeGen *biomegen = nullptr;
GenerateNotifier gennotify;
- Mapgen();
+ Mapgen() = default;
Mapgen(int mapgenid, MapgenParams *params, EmergeManager *emerge);
- virtual ~Mapgen();
+ virtual ~Mapgen() = default;
DISABLE_CLASS_COPY(Mapgen);
virtual MapgenType getType() const { return MAPGEN_INVALID; }
diff --git a/src/mapgen_carpathian.cpp b/src/mapgen_carpathian.cpp
index 6a9daf759..c6ca1de20 100644
--- a/src/mapgen_carpathian.cpp
+++ b/src/mapgen_carpathian.cpp
@@ -300,8 +300,8 @@ int MapgenCarpathian::getSpawnLevelAtPoint(v2s16 p)
s16 level_at_point = terrainLevelAtPoint(p.X, p.Y);
if (level_at_point <= water_level || level_at_point > water_level + 32)
return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point
- else
- return level_at_point;
+
+ return level_at_point;
}
diff --git a/src/mapgen_flat.h b/src/mapgen_flat.h
index d34e4d86c..635d40625 100644
--- a/src/mapgen_flat.h
+++ b/src/mapgen_flat.h
@@ -47,7 +47,7 @@ struct MapgenFlatParams : public MapgenParams
NoiseParams np_cave2;
MapgenFlatParams();
- ~MapgenFlatParams() {}
+ ~MapgenFlatParams() = default;
void readParams(const Settings *settings);
void writeParams(Settings *settings) const;
diff --git a/src/mapgen_v5.h b/src/mapgen_v5.h
index f5afc3af1..44b0a09e7 100644
--- a/src/mapgen_v5.h
+++ b/src/mapgen_v5.h
@@ -48,7 +48,7 @@ struct MapgenV5Params : public MapgenParams
NoiseParams np_cavern;
MapgenV5Params();
- ~MapgenV5Params() {}
+ ~MapgenV5Params() = default;
void readParams(const Settings *settings);
void writeParams(Settings *settings) const;
diff --git a/src/mapgen_v6.cpp b/src/mapgen_v6.cpp
index ec33fee08..e67e78f6c 100644
--- a/src/mapgen_v6.cpp
+++ b/src/mapgen_v6.cpp
@@ -455,19 +455,20 @@ BiomeV6Type MapgenV6::getBiome(int index, v2s16 p)
}
return BT_NORMAL;
- } else {
- if (d > freq_desert)
- return BT_DESERT;
+ }
- if ((spflags & MGV6_BIOMEBLEND) && (d > freq_desert - 0.10) &&
- ((noise2d(p.X, p.Y, seed) + 1.0) > (freq_desert - d) * 20.0))
- return BT_DESERT;
+ if (d > freq_desert)
+ return BT_DESERT;
- if ((spflags & MGV6_JUNGLES) && h > 0.75)
- return BT_JUNGLE;
+ if ((spflags & MGV6_BIOMEBLEND) && (d > freq_desert - 0.10) &&
+ ((noise2d(p.X, p.Y, seed) + 1.0) > (freq_desert - d) * 20.0))
+ return BT_DESERT;
+
+ if ((spflags & MGV6_JUNGLES) && h > 0.75)
+ return BT_JUNGLE;
+
+ return BT_NORMAL;
- return BT_NORMAL;
- }
}
diff --git a/src/util/directiontables.cpp b/src/util/directiontables.cpp
index d6c154842..587b0caf7 100644
--- a/src/util/directiontables.cpp
+++ b/src/util/directiontables.cpp
@@ -30,6 +30,17 @@ const v3s16 g_6dirs[6] =
v3s16(-1, 0, 0) // left
};
+const v3s16 g_7dirs[7] =
+{
+ v3s16(0,0,1), // back
+ v3s16(0,1,0), // top
+ v3s16(1,0,0), // right
+ v3s16(0,0,-1), // front
+ v3s16(0,-1,0), // bottom
+ v3s16(-1,0,0), // left
+ v3s16(0,0,0), // self
+};
+
const v3s16 g_26dirs[26] =
{
// +right, +top, +back
diff --git a/src/util/directiontables.h b/src/util/directiontables.h
index ab5b63217..8464453bc 100644
--- a/src/util/directiontables.h
+++ b/src/util/directiontables.h
@@ -24,6 +24,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
extern const v3s16 g_6dirs[6];
+extern const v3s16 g_7dirs[7];
+
extern const v3s16 g_26dirs[26];
// 26th is (0,0,0)