565 changes: 0 additions & 565 deletions src/map.cpp

Large diffs are not rendered by default.

16 changes: 0 additions & 16 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,22 +208,6 @@ class Map /*: public NodeContainer*/
// position is valid, otherwise false
MapNode getNodeNoEx(v3s16 p, bool *is_valid_position = NULL);

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

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

void updateLighting(enum LightBank bank,
std::map<v3s16, MapBlock*> & a_blocks,
std::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.
*/
Expand Down
10 changes: 3 additions & 7 deletions src/mg_schematic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/serialize.h"
#include "serialization.h"
#include "filesys.h"
#include "voxelalgorithms.h"

///////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -202,7 +203,7 @@ bool Schematic::placeOnVManip(MMVManip *vm, v3s16 p, u32 flags,
return vm->m_area.contains(VoxelArea(p, p + s - v3s16(1,1,1)));
}

void Schematic::placeOnMap(Map *map, v3s16 p, u32 flags,
void Schematic::placeOnMap(ServerMap *map, v3s16 p, u32 flags,
Rotation rot, bool force_place)
{
std::map<v3s16, MapBlock *> lighting_modified_blocks;
Expand Down Expand Up @@ -238,15 +239,10 @@ void Schematic::placeOnMap(Map *map, v3s16 p, u32 flags,

blitToVManip(&vm, p, rot, force_place);

vm.blitBackAll(&modified_blocks);
voxalgo::blit_back_with_light(map, &vm, &modified_blocks);

//// Carry out post-map-modification actions

//// Update lighting
// TODO: Optimize this by using Mapgen::calcLighting() instead
lighting_modified_blocks.insert(modified_blocks.begin(), modified_blocks.end());
map->updateLighting(lighting_modified_blocks, modified_blocks);

//// Create & dispatch map modification events to observers
MapEditEvent event;
event.type = MEET_OTHER;
Expand Down
3 changes: 2 additions & 1 deletion src/mg_schematic.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/string.h"

class Map;
class ServerMap;
class Mapgen;
class MMVManip;
class PseudoRandom;
Expand Down Expand Up @@ -108,7 +109,7 @@ class Schematic : public ObjDef, public NodeResolver {

void blitToVManip(MMVManip *vm, v3s16 p, Rotation rot, bool force_place);
bool placeOnVManip(MMVManip *vm, v3s16 p, u32 flags, Rotation rot, bool force_place);
void placeOnMap(Map *map, v3s16 p, u32 flags, Rotation rot, bool force_place);
void placeOnMap(ServerMap *map, v3s16 p, u32 flags, Rotation rot, bool force_place);

void applyProbabilities(v3s16 p0,
std::vector<std::pair<v3s16, u8> > *plist,
Expand Down
4 changes: 3 additions & 1 deletion src/script/lua_api/l_mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,9 @@ int ModApiMapgen::l_place_schematic(lua_State *L)
{
MAP_LOCK_REQUIRED;

Map *map = &(getEnv(L)->getMap());
GET_ENV_PTR;

ServerMap *map = &(env->getServerMap());
SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr;

//// Read position
Expand Down
46 changes: 17 additions & 29 deletions src/script/lua_api/l_vmanip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "map.h"
#include "server.h"
#include "mapgen.h"
#include "voxelalgorithms.h"

// garbage collector
int LuaVoxelManip::gc_object(lua_State *L)
Expand Down Expand Up @@ -109,10 +110,24 @@ int LuaVoxelManip::l_write_to_map(lua_State *L)
MAP_LOCK_REQUIRED;

LuaVoxelManip *o = checkobject(L, 1);
MMVManip *vm = o->vm;
GET_ENV_PTR;
ServerMap *map = &(env->getServerMap());
if (o->is_mapgen_vm) {
o->vm->blitBackAll(&(o->modified_blocks));
} else {
voxalgo::blit_back_with_light(map, o->vm,
&(o->modified_blocks));
}

vm->blitBackAll(&o->modified_blocks);
MapEditEvent event;
event.type = MEET_OTHER;
for (std::map<v3s16, MapBlock *>::iterator it = o->modified_blocks.begin();
it != o->modified_blocks.end(); ++it)
event.modified_blocks.insert(it->first);

map->dispatchEvent(&event);

o->modified_blocks.clear();
return 0;
}

Expand Down Expand Up @@ -322,33 +337,6 @@ int LuaVoxelManip::l_set_param2_data(lua_State *L)

int LuaVoxelManip::l_update_map(lua_State *L)
{
GET_ENV_PTR;

LuaVoxelManip *o = checkobject(L, 1);
if (o->is_mapgen_vm)
return 0;

Map *map = &(env->getMap());

// TODO: Optimize this by using Mapgen::calcLighting() instead
std::map<v3s16, MapBlock *> lighting_mblocks;
std::map<v3s16, MapBlock *> *mblocks = &o->modified_blocks;

lighting_mblocks.insert(mblocks->begin(), mblocks->end());

map->updateLighting(lighting_mblocks, *mblocks);

MapEditEvent event;
event.type = MEET_OTHER;
for (std::map<v3s16, MapBlock *>::iterator
it = mblocks->begin();
it != mblocks->end(); ++it)
event.modified_blocks.insert(it->first);

map->dispatchEvent(&event);

mblocks->clear();

return 0;
}

Expand Down
7 changes: 2 additions & 5 deletions src/treegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "serverenvironment.h"
#include "nodedef.h"
#include "treegen.h"
#include "voxelalgorithms.h"

namespace treegen
{
Expand Down Expand Up @@ -125,12 +126,8 @@ treegen::error spawn_ltree(ServerEnvironment *env, v3s16 p0,
if (e != SUCCESS)
return e;

vmanip.blitBackAll(&modified_blocks);
voxalgo::blit_back_with_light(map, &vmanip, &modified_blocks);

// update lighting
std::map<v3s16, MapBlock*> lighting_modified_blocks;
lighting_modified_blocks.insert(modified_blocks.begin(), modified_blocks.end());
map->updateLighting(lighting_modified_blocks, modified_blocks);
// Send a MEET_OTHER event
MapEditEvent event;
event.type = MEET_OTHER;
Expand Down
371 changes: 367 additions & 4 deletions src/voxelalgorithms.cpp

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/voxelalgorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/cpp11_container.h"

class Map;
class ServerMap;
class MapBlock;
class MMVManip;

namespace voxalgo
{
Expand Down Expand Up @@ -84,6 +86,17 @@ void update_lighting_nodes(
void update_block_border_lighting(Map *map, MapBlock *block,
std::map<v3s16, MapBlock*> &modified_blocks);

/*!
* Copies back nodes from a voxel manipulator
* to the map and updates lighting.
* For server use only.
*
* \param modified_blocks output, contains all map blocks that
* the function modified
*/
void blit_back_with_light(ServerMap *map, MMVManip *vm,
std::map<v3s16, MapBlock*> *modified_blocks);

/*!
* This class iterates trough voxels that intersect with
* a line. The collision detection does not see nodeboxes,
Expand Down