187 changes: 88 additions & 99 deletions src/map.cpp

Large diffs are not rendered by default.

59 changes: 27 additions & 32 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <jthread.h>
#include <iostream>
#include <sstream>
#include <set>
#include <map>

#include "irrlichttypes_bloated.h"
#include "mapnode.h"
Expand Down Expand Up @@ -75,7 +77,7 @@ struct MapEditEvent
MapEditEventType type;
v3s16 p;
MapNode n;
core::map<v3s16, bool> modified_blocks;
std::set<v3s16> modified_blocks;
u16 already_known_by_peer;

MapEditEvent():
Expand All @@ -90,14 +92,7 @@ struct MapEditEvent
event->type = type;
event->p = p;
event->n = n;
for(core::map<v3s16, bool>::Iterator
i = modified_blocks.getIterator();
i.atEnd()==false; i++)
{
v3s16 p = i.getNode()->getKey();
bool v = i.getNode()->getValue();
event->modified_blocks.insert(p, v);
}
event->modified_blocks = modified_blocks;
return event;
}

Expand All @@ -117,11 +112,11 @@ struct MapEditEvent
case MEET_OTHER:
{
VoxelArea a;
for(core::map<v3s16, bool>::Iterator
i = modified_blocks.getIterator();
i.atEnd()==false; i++)
for(std::set<v3s16>::iterator
i = modified_blocks.begin();
i != modified_blocks.end(); ++i)
{
v3s16 p = i.getNode()->getKey();
v3s16 p = *i;
v3s16 np1 = p*MAP_BLOCKSIZE;
v3s16 np2 = np1 + v3s16(1,1,1)*MAP_BLOCKSIZE - v3s16(1,1,1);
a.addPoint(np1);
Expand Down Expand Up @@ -212,42 +207,42 @@ class Map /*: public NodeContainer*/
MapNode getNodeNoEx(v3s16 p);

void unspreadLight(enum LightBank bank,
core::map<v3s16, u8> & from_nodes,
core::map<v3s16, bool> & light_sources,
core::map<v3s16, MapBlock*> & modified_blocks);
std::map<v3s16, u8> & from_nodes,
std::set<v3s16> & light_sources,
std::map<v3s16, MapBlock*> & modified_blocks);

void unLightNeighbors(enum LightBank bank,
v3s16 pos, u8 lightwas,
core::map<v3s16, bool> & light_sources,
core::map<v3s16, MapBlock*> & modified_blocks);
std::set<v3s16> & light_sources,
std::map<v3s16, MapBlock*> & modified_blocks);

void spreadLight(enum LightBank bank,
core::map<v3s16, bool> & from_nodes,
core::map<v3s16, MapBlock*> & modified_blocks);
std::set<v3s16> & from_nodes,
std::map<v3s16, MapBlock*> & modified_blocks);

void lightNeighbors(enum LightBank bank,
v3s16 pos,
core::map<v3s16, MapBlock*> & modified_blocks);
std::map<v3s16, MapBlock*> & modified_blocks);

v3s16 getBrightestNeighbour(enum LightBank bank, v3s16 p);

s16 propagateSunlight(v3s16 start,
core::map<v3s16, MapBlock*> & modified_blocks);
std::map<v3s16, MapBlock*> & modified_blocks);

void updateLighting(enum LightBank bank,
core::map<v3s16, MapBlock*> & a_blocks,
core::map<v3s16, MapBlock*> & modified_blocks);
std::map<v3s16, MapBlock*> & a_blocks,
std::map<v3s16, MapBlock*> & modified_blocks);

void updateLighting(core::map<v3s16, MapBlock*> & a_blocks,
core::map<v3s16, MapBlock*> & modified_blocks);
void updateLighting(std::map<v3s16, MapBlock*> & a_blocks,
std::map<v3s16, MapBlock*> & modified_blocks);

/*
These handle lighting but not faces.
*/
void addNodeAndUpdate(v3s16 p, MapNode n,
core::map<v3s16, MapBlock*> &modified_blocks);
std::map<v3s16, MapBlock*> &modified_blocks);
void removeNodeAndUpdate(v3s16 p,
core::map<v3s16, MapBlock*> &modified_blocks);
std::map<v3s16, MapBlock*> &modified_blocks);

/*
Wrappers for the latter ones.
Expand Down Expand Up @@ -301,7 +296,7 @@ class Map /*: public NodeContainer*/
// For debug printing. Prints "Map: ", "ServerMap: " or "ClientMap: "
virtual void PrintInfo(std::ostream &out);

void transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks);
void transformLiquids(std::map<v3s16, MapBlock*> & modified_blocks);

/*
Node metadata
Expand Down Expand Up @@ -381,12 +376,12 @@ class ServerMap : public Map
*/
void initBlockMake(mapgen::BlockMakeData *data, v3s16 blockpos);
MapBlock* finishBlockMake(mapgen::BlockMakeData *data,
core::map<v3s16, MapBlock*> &changed_blocks);
std::map<v3s16, MapBlock*> &changed_blocks);

// A non-threaded wrapper to the above
MapBlock * generateBlock(
v3s16 p,
core::map<v3s16, MapBlock*> &modified_blocks
std::map<v3s16, MapBlock*> &modified_blocks
);

/*
Expand Down Expand Up @@ -548,7 +543,7 @@ class ManualMapVoxelManipulator : public MapVoxelManipulator
void initialEmerge(v3s16 blockpos_min, v3s16 blockpos_max);

// This is much faster with big chunks of generated data
void blitBackAll(core::map<v3s16, MapBlock*> * modified_blocks);
void blitBackAll(std::map<v3s16, MapBlock*> * modified_blocks);

protected:
bool m_create_area;
Expand Down
4 changes: 2 additions & 2 deletions src/mapblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ MapNode MapBlock::getNodeParentNoEx(v3s16 p)
if black_air_left!=NULL, it is set to true if non-sunlighted
air is left in block.
*/
bool MapBlock::propagateSunlight(core::map<v3s16, bool> & light_sources,
bool MapBlock::propagateSunlight(std::set<v3s16> & light_sources,
bool remove_light, bool *black_air_left)
{
INodeDefManager *nodemgr = m_gamedef->ndef();
Expand Down Expand Up @@ -287,7 +287,7 @@ bool MapBlock::propagateSunlight(core::map<v3s16, bool> & light_sources,

if(diminish_light(current_light) != 0)
{
light_sources.insert(pos_relative + pos, true);
light_sources.insert(pos_relative + pos);
}

if(current_light == 0 && stopped_to_solid_object)
Expand Down
3 changes: 2 additions & 1 deletion src/mapblock.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <jmutex.h>
#include <jmutexautolock.h>
#include <exception>
#include <set>
#include "debug.h"
#include "irrlichttypes.h"
#include "irr_v3d.h"
Expand Down Expand Up @@ -352,7 +353,7 @@ class MapBlock /*: public NodeContainer*/
}

// See comments in mapblock.cpp
bool propagateSunlight(core::map<v3s16, bool> & light_sources,
bool propagateSunlight(std::set<v3s16> & light_sources,
bool remove_light=false, bool *black_air_left=NULL);

// Copies data to VoxelManipulator to getPosRelative()
Expand Down
38 changes: 18 additions & 20 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ void * EmergeThread::Thread()

MapBlock *block = NULL;
bool got_block = true;
core::map<v3s16, MapBlock*> modified_blocks;
std::map<v3s16, MapBlock*> modified_blocks;

/*
Try to fetch block from memory or disk.
Expand Down Expand Up @@ -361,7 +361,7 @@ void * EmergeThread::Thread()
*/
if(got_block)
{
modified_blocks.insert(p, block);
modified_blocks[p] = block;
}

/*
Expand Down Expand Up @@ -878,15 +878,15 @@ void RemoteClient::SetBlockNotSent(v3s16 p)
m_blocks_sent.remove(p);
}

void RemoteClient::SetBlocksNotSent(core::map<v3s16, MapBlock*> &blocks)
void RemoteClient::SetBlocksNotSent(std::map<v3s16, MapBlock*> &blocks)
{
m_nearest_unsent_d = 0;

for(core::map<v3s16, MapBlock*>::Iterator
i = blocks.getIterator();
i.atEnd()==false; i++)
for(std::map<v3s16, MapBlock*>::iterator
i = blocks.begin();
i != blocks.end(); ++i)
{
v3s16 p = i.getNode()->getKey();
v3s16 p = i->first;

if(m_blocks_sending.find(p) != NULL)
m_blocks_sending.remove(p);
Expand Down Expand Up @@ -1398,7 +1398,7 @@ void Server::AsyncRunStep()

ScopeProfiler sp(g_profiler, "Server: liquid transform");

core::map<v3s16, MapBlock*> modified_blocks;
std::map<v3s16, MapBlock*> modified_blocks;
m_env->getMap().transformLiquids(modified_blocks);
#if 0
/*
Expand Down Expand Up @@ -1802,12 +1802,11 @@ void Server::AsyncRunStep()
{
infostream<<"Server: MEET_OTHER"<<std::endl;
prof.add("MEET_OTHER", 1);
for(core::map<v3s16, bool>::Iterator
i = event->modified_blocks.getIterator();
i.atEnd()==false; i++)
for(std::set<v3s16>::iterator
i = event->modified_blocks.begin();
i != event->modified_blocks.end(); ++i)
{
v3s16 p = i.getNode()->getKey();
setBlockNotSent(p);
setBlockNotSent(*i);
}
}
else
Expand All @@ -1823,14 +1822,13 @@ void Server::AsyncRunStep()
if(far_players.size() > 0)
{
// Convert list format to that wanted by SetBlocksNotSent
core::map<v3s16, MapBlock*> modified_blocks2;
for(core::map<v3s16, bool>::Iterator
i = event->modified_blocks.getIterator();
i.atEnd()==false; i++)
std::map<v3s16, MapBlock*> modified_blocks2;
for(std::set<v3s16>::iterator
i = event->modified_blocks.begin();
i != event->modified_blocks.end(); ++i)
{
v3s16 p = i.getNode()->getKey();
modified_blocks2.insert(p,
m_env->getMap().getBlockNoCreateNoEx(p));
modified_blocks2[*i] =
m_env->getMap().getBlockNoCreateNoEx(*i);
}
// Set blocks not sent
for(core::list<u16>::Iterator
Expand Down
2 changes: 1 addition & 1 deletion src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class RemoteClient
void SentBlock(v3s16 p);

void SetBlockNotSent(v3s16 p);
void SetBlocksNotSent(core::map<v3s16, MapBlock*> &blocks);
void SetBlocksNotSent(std::map<v3s16, MapBlock*> &blocks);

s32 SendingCount()
{
Expand Down