]> git.lizzy.rs Git - minetest.git/blobdiff - src/map.cpp
Disable word wrap in vertical texts in main menu
[minetest.git] / src / map.cpp
index 4db5a3d1a68879dae5f8fe831f5d4e0f51b15fa6..b3954019b84951b0691aa591d710532a10af3bd6 100644 (file)
@@ -21,18 +21,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "mapsector.h"
 #include "mapblock.h"
 #include "main.h"
-#ifndef SERVER
-#include "client.h"
-#endif
 #include "filesys.h"
 #include "utility.h"
 #include "voxel.h"
 #include "porting.h"
 #include "mapgen.h"
 #include "nodemetadata.h"
-#ifndef SERVER
-#include <IMaterialRenderer.h>
-#endif
 #include "settings.h"
 #include "log.h"
 #include "profiler.h"
@@ -208,6 +202,15 @@ void Map::setNode(v3s16 p, MapNode & n)
        v3s16 blockpos = getNodeBlockPos(p);
        MapBlock *block = getBlockNoCreate(blockpos);
        v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
+       // Never allow placing CONTENT_IGNORE, it fucks up stuff
+       if(n.getContent() == CONTENT_IGNORE){
+               errorstream<<"Map::setNode(): Not allowing to place CONTENT_IGNORE"
+                               <<" while trying to replace \""
+                               <<m_gamedef->ndef()->get(block->getNodeNoCheck(relpos)).name
+                               <<"\" at "<<PP(p)<<" (block "<<PP(blockpos)<<")"<<std::endl;
+               debug_stacks_print_to(infostream);
+               return;
+       }
        block->setNodeNoCheck(relpos, n);
 }
 
@@ -851,15 +854,15 @@ void Map::updateLighting(enum LightBank bank,
                        for(s16 y=-1; y<=1; y++)
                        for(s16 x=-1; x<=1; x++)
                        {
-                               v3s16 p(x,y,z);
-                               MapBlock *block = getBlockNoCreateNoEx(p);
+                               v3s16 p2 = p + v3s16(x,y,z);
+                               MapBlock *block = getBlockNoCreateNoEx(p2);
                                if(block == NULL)
                                        continue;
                                if(block->isDummy())
                                        continue;
                                if(block->getLightingExpired())
                                        continue;
-                               vmanip.initialEmerge(p, p);
+                               vmanip.initialEmerge(p2, p2);
                        }*/
 
                        // Lighting of block will be updated completely
@@ -906,7 +909,7 @@ void Map::updateLighting(core::map<v3s16, MapBlock*> & a_blocks,
 /*
 */
 void Map::addNodeAndUpdate(v3s16 p, MapNode n,
-               core::map<v3s16, MapBlock*> &modified_blocks, std::string &player_name)
+               core::map<v3s16, MapBlock*> &modified_blocks)
 {
        INodeDefManager *nodemgr = m_gamedef->ndef();
 
@@ -994,13 +997,16 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
        /*
                Add intial metadata
        */
-
-       NodeMetadata *meta_proto = nodemgr->get(n).initial_metadata;
-       if(meta_proto)
-       {
-               NodeMetadata *meta = meta_proto->clone(m_gamedef);
-               meta->setOwner(player_name);
-               setNodeMetadata(p, meta);
+       
+       std::string metadata_name = nodemgr->get(n).metadata_name;
+       if(metadata_name != ""){
+               NodeMetadata *meta = NodeMetadata::create(metadata_name, m_gamedef);
+               if(!meta){
+                       errorstream<<"Failed to create node metadata \""
+                                       <<metadata_name<<"\""<<std::endl;
+               } else {
+                       setNodeMetadata(p, meta);
+               }
        }
 
        /*
@@ -1278,8 +1284,7 @@ bool Map::addNodeWithEvent(v3s16 p, MapNode n)
        bool succeeded = true;
        try{
                core::map<v3s16, MapBlock*> modified_blocks;
-               std::string st = std::string("");
-               addNodeAndUpdate(p, n, modified_blocks, st);
+               addNodeAndUpdate(p, n, modified_blocks);
 
                // Copy modified_blocks to event
                for(core::map<v3s16, MapBlock*>::Iterator
@@ -1397,6 +1402,7 @@ void Map::timerUpdate(float dtime, float unload_timeout,
        core::list<v2s16> sector_deletion_queue;
        u32 deleted_blocks_count = 0;
        u32 saved_blocks_count = 0;
+       u32 block_count_all = 0;
 
        core::map<v2s16, MapSector*>::Iterator si;
 
@@ -1442,6 +1448,7 @@ void Map::timerUpdate(float dtime, float unload_timeout,
                        else
                        {
                                all_blocks_deleted = false;
+                               block_count_all++;
                        }
                }
 
@@ -1462,10 +1469,13 @@ void Map::timerUpdate(float dtime, float unload_timeout,
                                <<" blocks from memory";
                if(save_before_unloading)
                        infostream<<", of which "<<saved_blocks_count<<" were written";
+               infostream<<", "<<block_count_all<<" blocks in memory";
                infostream<<"."<<std::endl;
-               PrintInfo(infostream); // ServerMap/ClientMap:
-               infostream<<"Blocks modified by: "<<std::endl;
-               modprofiler.print(infostream);
+               if(saved_blocks_count != 0){
+                       PrintInfo(infostream); // ServerMap/ClientMap:
+                       infostream<<"Blocks modified by: "<<std::endl;
+                       modprofiler.print(infostream);
+               }
        }
 }
 
@@ -1601,7 +1611,7 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
                switch (liquid_type) {
                        case LIQUID_SOURCE:
                                liquid_level = LIQUID_LEVEL_SOURCE;
-                               liquid_kind = nodemgr->get(n0).liquid_alternative_flowing;
+                               liquid_kind = nodemgr->getId(nodemgr->get(n0).liquid_alternative_flowing);
                                break;
                        case LIQUID_FLOWING:
                                liquid_level = (n0.param2 & LIQUID_LEVEL_MASK);
@@ -1661,18 +1671,20 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
                                case LIQUID_SOURCE:
                                        // if this node is not (yet) of a liquid type, choose the first liquid type we encounter 
                                        if (liquid_kind == CONTENT_AIR)
-                                               liquid_kind = nodemgr->get(nb.n.getContent()).liquid_alternative_flowing;
-                                       if (nodemgr->get(nb.n.getContent()).liquid_alternative_flowing !=liquid_kind) {
+                                               liquid_kind = nodemgr->getId(nodemgr->get(nb.n).liquid_alternative_flowing);
+                                       if (nodemgr->getId(nodemgr->get(nb.n).liquid_alternative_flowing) != liquid_kind) {
                                                neutrals[num_neutrals++] = nb;
                                        } else {
-                                               sources[num_sources++] = nb;
+                                               // Do not count bottom source, it will screw things up
+                                               if(dirs[i].Y != -1)
+                                                       sources[num_sources++] = nb;
                                        }
                                        break;
                                case LIQUID_FLOWING:
                                        // if this node is not (yet) of a liquid type, choose the first liquid type we encounter
                                        if (liquid_kind == CONTENT_AIR)
-                                               liquid_kind = nodemgr->get(nb.n.getContent()).liquid_alternative_flowing;
-                                       if (nodemgr->get(nb.n.getContent()).liquid_alternative_flowing != liquid_kind) {
+                                               liquid_kind = nodemgr->getId(nodemgr->get(nb.n).liquid_alternative_flowing);
+                                       if (nodemgr->getId(nodemgr->get(nb.n).liquid_alternative_flowing) != liquid_kind) {
                                                neutrals[num_neutrals++] = nb;
                                        } else {
                                                flows[num_flows++] = nb;
@@ -1693,7 +1705,7 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
                        // liquid_kind will be set to either the flowing alternative of the node (if it's a liquid)
                        // or the flowing alternative of the first of the surrounding sources (if it's air), so
                        // it's perfectly safe to use liquid_kind here to determine the new node content.
-                       new_node_content = nodemgr->get(liquid_kind).liquid_alternative_source;
+                       new_node_content = nodemgr->getId(nodemgr->get(liquid_kind).liquid_alternative_source);
                } else if (num_sources == 1 && sources[0].t != NEIGHBOR_LOWER) {
                        // liquid_kind is set properly, see above
                        new_node_content = liquid_kind;
@@ -1898,7 +1910,7 @@ ServerMap::ServerMap(std::string savedir, IGameDef *gamedef):
        m_database_read(NULL),
        m_database_write(NULL)
 {
-       infostream<<__FUNCTION_NAME<<std::endl;
+       verbosestream<<__FUNCTION_NAME<<std::endl;
 
        //m_chunksize = 8; // Takes a few seconds
 
@@ -1936,7 +1948,7 @@ ServerMap::ServerMap(std::string savedir, IGameDef *gamedef):
                        // If directory is empty, it is safe to save into it.
                        if(fs::GetDirListing(m_savedir).size() == 0)
                        {
-                               infostream<<"Server: Empty save directory is valid."
+                               infostream<<"ServerMap: Empty save directory is valid."
                                                <<std::endl;
                                m_map_saving_enabled = true;
                        }
@@ -1953,25 +1965,10 @@ ServerMap::ServerMap(std::string savedir, IGameDef *gamedef):
                                        //m_chunksize = 0;
                                }
 
-                               /*try{
-                                       // Load chunk metadata
-                                       loadChunkMeta();
-                               }
-                               catch(FileNotGoodException &e){
-                                       infostream<<"WARNING: Could not load chunk metadata."
-                                                       <<" Disabling chunk-based generator."
-                                                       <<std::endl;
-                                       m_chunksize = 0;
-                               }*/
-
-                               /*infostream<<"Server: Successfully loaded chunk "
-                                               "metadata and sector (0,0) from "<<savedir<<
-                                               ", assuming valid save directory."
-                                               <<std::endl;*/
-
-                               infostream<<"Server: Successfully loaded map "
-                                               <<"and chunk metadata from "<<savedir
+                               infostream<<"ServerMap: Successfully loaded map "
+                                               <<"metadata from "<<savedir
                                                <<", assuming valid save directory."
+                                               <<" seed="<<m_seed<<"."
                                                <<std::endl;
 
                                m_map_saving_enabled = true;
@@ -1986,7 +1983,7 @@ ServerMap::ServerMap(std::string savedir, IGameDef *gamedef):
        }
        catch(std::exception &e)
        {
-               infostream<<"WARNING: Server: Failed to load map from "<<savedir
+               infostream<<"WARNING: ServerMap: Failed to load map from "<<savedir
                                <<", exception: "<<e.what()<<std::endl;
                infostream<<"Please remove the map or fix it."<<std::endl;
                infostream<<"WARNING: Map saving will be disabled."<<std::endl;
@@ -1998,29 +1995,29 @@ ServerMap::ServerMap(std::string savedir, IGameDef *gamedef):
        emergeSector(v2s16(0,0));
 
        // Initially write whole map
-       save(false);
+       save(MOD_STATE_CLEAN);
 }
 
 ServerMap::~ServerMap()
 {
-       infostream<<__FUNCTION_NAME<<std::endl;
+       verbosestream<<__FUNCTION_NAME<<std::endl;
 
        try
        {
                if(m_map_saving_enabled)
                {
                        // Save only changed parts
-                       save(true);
-                       infostream<<"Server: saved map to "<<m_savedir<<std::endl;
+                       save(MOD_STATE_WRITE_AT_UNLOAD);
+                       infostream<<"ServerMap: Saved map to "<<m_savedir<<std::endl;
                }
                else
                {
-                       infostream<<"Server: map not saved"<<std::endl;
+                       infostream<<"ServerMap: Map not saved"<<std::endl;
                }
        }
        catch(std::exception &e)
        {
-               infostream<<"Server: Failed to save map to "<<m_savedir
+               infostream<<"ServerMap: Failed to save map to "<<m_savedir
                                <<", exception: "<<e.what()<<std::endl;
        }
 
@@ -2149,7 +2146,17 @@ MapBlock* ServerMap::finishBlockMake(mapgen::BlockMakeData *data,
 
        /*infostream<<"Resulting vmanip:"<<std::endl;
        data->vmanip.print(infostream);*/
-       
+
+       // Make sure affected blocks are loaded
+       for(s16 x=-1; x<=1; x++)
+       for(s16 z=-1; z<=1; z++)
+       for(s16 y=-1; y<=1; y++)
+       {
+               v3s16 p(blockpos.X+x, blockpos.Y+y, blockpos.Z+z);
+               // Load from disk if not already in memory
+               emergeBlock(p, false);
+       }
+
        /*
                Blit generated stuff to map
                NOTE: blitBackAll adds nearly everything to changed_blocks
@@ -2301,7 +2308,7 @@ MapBlock* ServerMap::finishBlockMake(mapgen::BlockMakeData *data,
                Save changed parts of map
                NOTE: Will be saved later.
        */
-       //save(true);
+       //save(MOD_STATE_WRITE_AT_UNLOAD);
 
        /*infostream<<"finishBlockMake() done for ("<<blockpos.X<<","<<blockpos.Y<<","
                        <<blockpos.Z<<")"<<std::endl;*/
@@ -2665,7 +2672,7 @@ void ServerMap::createDatabase() {
        if(e == SQLITE_ABORT)
                throw FileNotGoodException("Could not create database structure");
        else
-               infostream<<"Server: Database structure was created";
+               infostream<<"ServerMap: Database structure was created";
 }
 
 void ServerMap::verifyDatabase() {
@@ -2713,7 +2720,7 @@ void ServerMap::verifyDatabase() {
                        throw FileNotGoodException("Cannot prepare read statement");
                }
                
-               infostream<<"Server: Database opened"<<std::endl;
+               infostream<<"ServerMap: Database opened"<<std::endl;
        }
 }
 
@@ -2809,7 +2816,7 @@ std::string ServerMap::getBlockFilename(v3s16 p)
        return cc;
 }
 
-void ServerMap::save(bool only_changed)
+void ServerMap::save(ModifiedState save_level)
 {
        DSTACK(__FUNCTION_NAME);
        if(m_map_saving_enabled == false)
@@ -2818,11 +2825,11 @@ void ServerMap::save(bool only_changed)
                return;
        }
        
-       if(only_changed == false)
+       if(save_level == MOD_STATE_CLEAN)
                infostream<<"ServerMap: Saving whole map, this can take time."
                                <<std::endl;
        
-       if(only_changed == false || m_map_metadata_changed)
+       if(m_map_metadata_changed || save_level == MOD_STATE_CLEAN)
        {
                saveMapMeta();
        }
@@ -2834,14 +2841,16 @@ void ServerMap::save(bool only_changed)
        u32 block_count = 0;
        u32 block_count_all = 0; // Number of blocks in memory
        
-       beginSave();
+       // Don't do anything with sqlite unless something is really saved
+       bool save_started = false;
+
        core::map<v2s16, MapSector*>::Iterator i = m_sectors.getIterator();
        for(; i.atEnd() == false; i++)
        {
                ServerMapSector *sector = (ServerMapSector*)i.getNode()->getValue();
                assert(sector->getId() == MAPSECTOR_SERVER);
        
-               if(sector->differs_from_disk || only_changed == false)
+               if(sector->differs_from_disk || save_level == MOD_STATE_CLEAN)
                {
                        saveSectorMeta(sector);
                        sector_meta_count++;
@@ -2850,17 +2859,22 @@ void ServerMap::save(bool only_changed)
                sector->getBlocks(blocks);
                core::list<MapBlock*>::Iterator j;
                
-               //sqlite3_exec(m_database, "BEGIN;", NULL, NULL, NULL);
                for(j=blocks.begin(); j!=blocks.end(); j++)
                {
                        MapBlock *block = *j;
                        
                        block_count_all++;
 
-                       if(block->getModified() >= MOD_STATE_WRITE_NEEDED 
-                                       || only_changed == false)
+                       if(block->getModified() >= save_level)
                        {
+                               // Lazy beginSave()
+                               if(!save_started){
+                                       beginSave();
+                                       save_started = true;
+                               }
+
                                modprofiler.add(block->getModifiedReason(), 1);
+
                                saveBlock(block);
                                block_count++;
 
@@ -2870,15 +2884,15 @@ void ServerMap::save(bool only_changed)
                                                <<block->getPos().Z<<")"
                                                <<std::endl;*/
                        }
-               //sqlite3_exec(m_database, "COMMIT;", NULL, NULL, NULL);
                }
        }
-       endSave();
+       if(save_started)
+               endSave();
 
        /*
                Only print if something happened or saved whole map
        */
-       if(only_changed == false || sector_meta_count != 0
+       if(save_level == MOD_STATE_CLEAN || sector_meta_count != 0
                        || block_count != 0)
        {
                infostream<<"ServerMap: Written: "
@@ -2942,9 +2956,9 @@ void ServerMap::saveMapMeta()
 {
        DSTACK(__FUNCTION_NAME);
        
-       infostream<<"ServerMap::saveMapMeta(): "
+       /*infostream<<"ServerMap::saveMapMeta(): "
                        <<"seed="<<m_seed
-                       <<std::endl;
+                       <<std::endl;*/
 
        createDirs(m_savedir);
        
@@ -2971,8 +2985,8 @@ void ServerMap::loadMapMeta()
 {
        DSTACK(__FUNCTION_NAME);
        
-       infostream<<"ServerMap::loadMapMeta(): Loading map metadata"
-                       <<std::endl;
+       /*infostream<<"ServerMap::loadMapMeta(): Loading map metadata"
+                       <<std::endl;*/
 
        std::string fullpath = m_savedir + DIR_DELIM + "map_meta.txt";
        std::ifstream is(fullpath.c_str(), std::ios_base::binary);
@@ -3000,7 +3014,7 @@ void ServerMap::loadMapMeta()
 
        m_seed = params.getU64("seed");
 
-       infostream<<"ServerMap::loadMapMeta(): "<<"seed="<<m_seed<<std::endl;
+       verbosestream<<"ServerMap::loadMapMeta(): "<<"seed="<<m_seed<<std::endl;
 }
 
 void ServerMap::saveSectorMeta(ServerMapSector *sector)
@@ -3234,10 +3248,7 @@ void ServerMap::saveBlock(MapBlock *block)
        o.write((char*)&version, 1);
        
        // Write basic data
-       block->serialize(o, version);
-       
-       // Write extra data stored on disk
-       block->serializeDiskExtra(o, version);
+       block->serialize(o, version, true);
        
        // Write block to database
        
@@ -3299,11 +3310,8 @@ void ServerMap::loadBlock(std::string sectordir, std::string blockfile, MapSecto
                }
                
                // Read basic data
-               block->deSerialize(is, version);
+               block->deSerialize(is, version, true);
 
-               // Read extra data stored on disk
-               block->deSerializeDiskExtra(is, version);
-               
                // If it's a new block, insert it to the map
                if(created_new)
                        sector->insertBlock(block);
@@ -3369,10 +3377,7 @@ void ServerMap::loadBlock(std::string *blob, v3s16 p3d, MapSector *sector, bool
                }
                
                // Read basic data
-               block->deSerialize(is, version);
-
-               // Read extra data stored on disk
-               block->deSerializeDiskExtra(is, version);
+               block->deSerialize(is, version, true);
                
                // If it's a new block, insert it to the map
                if(created_new)
@@ -3504,744 +3509,6 @@ void ServerMap::PrintInfo(std::ostream &out)
        out<<"ServerMap: ";
 }
 
-#ifndef SERVER
-
-/*
-       ClientMap
-*/
-
-ClientMap::ClientMap(
-               Client *client,
-               IGameDef *gamedef,
-               MapDrawControl &control,
-               scene::ISceneNode* parent,
-               scene::ISceneManager* mgr,
-               s32 id
-):
-       Map(dout_client, gamedef),
-       scene::ISceneNode(parent, mgr, id),
-       m_client(client),
-       m_control(control),
-       m_camera_position(0,0,0),
-       m_camera_direction(0,0,1),
-       m_camera_fov(PI)
-{
-       m_camera_mutex.Init();
-       assert(m_camera_mutex.IsInitialized());
-       
-       m_box = core::aabbox3d<f32>(-BS*1000000,-BS*1000000,-BS*1000000,
-                       BS*1000000,BS*1000000,BS*1000000);
-}
-
-ClientMap::~ClientMap()
-{
-       /*JMutexAutoLock lock(mesh_mutex);
-       
-       if(mesh != NULL)
-       {
-               mesh->drop();
-               mesh = NULL;
-       }*/
-}
-
-MapSector * ClientMap::emergeSector(v2s16 p2d)
-{
-       DSTACK(__FUNCTION_NAME);
-       // Check that it doesn't exist already
-       try{
-               return getSectorNoGenerate(p2d);
-       }
-       catch(InvalidPositionException &e)
-       {
-       }
-       
-       // Create a sector
-       ClientMapSector *sector = new ClientMapSector(this, p2d, m_gamedef);
-       
-       {
-               //JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
-               m_sectors.insert(p2d, sector);
-       }
-       
-       return sector;
-}
-
-#if 0
-void ClientMap::deSerializeSector(v2s16 p2d, std::istream &is)
-{
-       DSTACK(__FUNCTION_NAME);
-       ClientMapSector *sector = NULL;
-
-       //JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
-       
-       core::map<v2s16, MapSector*>::Node *n = m_sectors.find(p2d);
-
-       if(n != NULL)
-       {
-               sector = (ClientMapSector*)n->getValue();
-               assert(sector->getId() == MAPSECTOR_CLIENT);
-       }
-       else
-       {
-               sector = new ClientMapSector(this, p2d);
-               {
-                       //JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
-                       m_sectors.insert(p2d, sector);
-               }
-       }
-
-       sector->deSerialize(is);
-}
-#endif
-
-void ClientMap::OnRegisterSceneNode()
-{
-       if(IsVisible)
-       {
-               SceneManager->registerNodeForRendering(this, scene::ESNRP_SOLID);
-               SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT);
-       }
-
-       ISceneNode::OnRegisterSceneNode();
-}
-
-static bool isOccluded(Map *map, v3s16 p0, v3s16 p1, float step, float stepfac,
-               float start_off, float end_off, u32 needed_count, INodeDefManager *nodemgr)
-{
-       float d0 = (float)BS * p0.getDistanceFrom(p1);
-       v3s16 u0 = p1 - p0;
-       v3f uf = v3f(u0.X, u0.Y, u0.Z) * BS;
-       uf.normalize();
-       v3f p0f = v3f(p0.X, p0.Y, p0.Z) * BS;
-       u32 count = 0;
-       for(float s=start_off; s<d0+end_off; s+=step){
-               v3f pf = p0f + uf * s;
-               v3s16 p = floatToInt(pf, BS);
-               MapNode n = map->getNodeNoEx(p);
-               bool is_transparent = false;
-               const ContentFeatures &f = nodemgr->get(n);
-               if(f.solidness == 0)
-                       is_transparent = (f.visual_solidness != 2);
-               else
-                       is_transparent = (f.solidness != 2);
-               if(!is_transparent){
-                       count++;
-                       if(count >= needed_count)
-                               return true;
-               }
-               step *= stepfac;
-       }
-       return false;
-}
-
-void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
-{
-       INodeDefManager *nodemgr = m_gamedef->ndef();
-
-       //m_dout<<DTIME<<"Rendering map..."<<std::endl;
-       DSTACK(__FUNCTION_NAME);
-
-       bool is_transparent_pass = pass == scene::ESNRP_TRANSPARENT;
-       
-       std::string prefix;
-       if(pass == scene::ESNRP_SOLID)
-               prefix = "CM: solid: ";
-       else
-               prefix = "CM: transparent: ";
-
-       /*
-               This is called two times per frame, reset on the non-transparent one
-       */
-       if(pass == scene::ESNRP_SOLID)
-       {
-               m_last_drawn_sectors.clear();
-       }
-
-       /*
-               Get time for measuring timeout.
-               
-               Measuring time is very useful for long delays when the
-               machine is swapping a lot.
-       */
-       int time1 = time(0);
-
-       //u32 daynight_ratio = m_client->getDayNightRatio();
-
-       m_camera_mutex.Lock();
-       v3f camera_position = m_camera_position;
-       v3f camera_direction = m_camera_direction;
-       f32 camera_fov = m_camera_fov;
-       m_camera_mutex.Unlock();
-
-       /*
-               Get all blocks and draw all visible ones
-       */
-
-       v3s16 cam_pos_nodes = floatToInt(camera_position, BS);
-       
-       v3s16 box_nodes_d = m_control.wanted_range * v3s16(1,1,1);
-
-       v3s16 p_nodes_min = cam_pos_nodes - box_nodes_d;
-       v3s16 p_nodes_max = cam_pos_nodes + box_nodes_d;
-
-       // Take a fair amount as we will be dropping more out later
-       // Umm... these additions are a bit strange but they are needed.
-       v3s16 p_blocks_min(
-                       p_nodes_min.X / MAP_BLOCKSIZE - 3,
-                       p_nodes_min.Y / MAP_BLOCKSIZE - 3,
-                       p_nodes_min.Z / MAP_BLOCKSIZE - 3);
-       v3s16 p_blocks_max(
-                       p_nodes_max.X / MAP_BLOCKSIZE + 1,
-                       p_nodes_max.Y / MAP_BLOCKSIZE + 1,
-                       p_nodes_max.Z / MAP_BLOCKSIZE + 1);
-       
-       u32 vertex_count = 0;
-       u32 meshbuffer_count = 0;
-       
-       // For limiting number of mesh updates per frame
-       u32 mesh_update_count = 0;
-       
-       // Number of blocks in rendering range
-       u32 blocks_in_range = 0;
-       // Number of blocks occlusion culled
-       u32 blocks_occlusion_culled = 0;
-       // Number of blocks in rendering range but don't have a mesh
-       u32 blocks_in_range_without_mesh = 0;
-       // Blocks that had mesh that would have been drawn according to
-       // rendering range (if max blocks limit didn't kick in)
-       u32 blocks_would_have_drawn = 0;
-       // Blocks that were drawn and had a mesh
-       u32 blocks_drawn = 0;
-       // Blocks which had a corresponding meshbuffer for this pass
-       u32 blocks_had_pass_meshbuf = 0;
-       // Blocks from which stuff was actually drawn
-       u32 blocks_without_stuff = 0;
-
-       /*
-               Collect a set of blocks for drawing
-       */
-       
-       core::map<v3s16, MapBlock*> drawset;
-
-       {
-       ScopeProfiler sp(g_profiler, prefix+"collecting blocks for drawing", SPT_AVG);
-
-       for(core::map<v2s16, MapSector*>::Iterator
-                       si = m_sectors.getIterator();
-                       si.atEnd() == false; si++)
-       {
-               MapSector *sector = si.getNode()->getValue();
-               v2s16 sp = sector->getPos();
-               
-               if(m_control.range_all == false)
-               {
-                       if(sp.X < p_blocks_min.X
-                       || sp.X > p_blocks_max.X
-                       || sp.Y < p_blocks_min.Z
-                       || sp.Y > p_blocks_max.Z)
-                               continue;
-               }
-
-               core::list< MapBlock * > sectorblocks;
-               sector->getBlocks(sectorblocks);
-               
-               /*
-                       Loop through blocks in sector
-               */
-
-               u32 sector_blocks_drawn = 0;
-               
-               core::list< MapBlock * >::Iterator i;
-               for(i=sectorblocks.begin(); i!=sectorblocks.end(); i++)
-               {
-                       MapBlock *block = *i;
-
-                       /*
-                               Compare block position to camera position, skip
-                               if not seen on display
-                       */
-                       
-                       float range = 100000 * BS;
-                       if(m_control.range_all == false)
-                               range = m_control.wanted_range * BS;
-
-                       float d = 0.0;
-                       if(isBlockInSight(block->getPos(), camera_position,
-                                       camera_direction, camera_fov,
-                                       range, &d) == false)
-                       {
-                               continue;
-                       }
-
-                       // This is ugly (spherical distance limit?)
-                       /*if(m_control.range_all == false &&
-                                       d - 0.5*BS*MAP_BLOCKSIZE > range)
-                               continue;*/
-
-                       blocks_in_range++;
-                       
-#if 1
-                       /*
-                               Update expired mesh (used for day/night change)
-
-                               It doesn't work exactly like it should now with the
-                               tasked mesh update but whatever.
-                       */
-
-                       bool mesh_expired = false;
-                       
-                       {
-                               JMutexAutoLock lock(block->mesh_mutex);
-
-                               mesh_expired = block->getMeshExpired();
-
-                               // Mesh has not been expired and there is no mesh:
-                               // block has no content
-                               if(block->mesh == NULL && mesh_expired == false){
-                                       blocks_in_range_without_mesh++;
-                                       continue;
-                               }
-                       }
-
-                       f32 faraway = BS*50;
-                       //f32 faraway = m_control.wanted_range * BS;
-                       
-                       /*
-                               This has to be done with the mesh_mutex unlocked
-                       */
-                       // Pretty random but this should work somewhat nicely
-                       if(mesh_expired && (
-                                       (mesh_update_count < 3
-                                               && (d < faraway || mesh_update_count < 2)
-                                       )
-                                       || 
-                                       (m_control.range_all && mesh_update_count < 20)
-                               )
-                       )
-                       /*if(mesh_expired && mesh_update_count < 6
-                                       && (d < faraway || mesh_update_count < 3))*/
-                       {
-                               mesh_update_count++;
-
-                               // Mesh has been expired: generate new mesh
-                               //block->updateMesh(daynight_ratio);
-                               m_client->addUpdateMeshTask(block->getPos());
-
-                               mesh_expired = false;
-                       }
-#endif
-
-                       /*
-                               Occlusion culling
-                       */
-
-                       v3s16 cpn = block->getPos() * MAP_BLOCKSIZE;
-                       cpn += v3s16(MAP_BLOCKSIZE/2, MAP_BLOCKSIZE/2, MAP_BLOCKSIZE/2);
-                       float step = BS*1;
-                       float stepfac = 1.1;
-                       float startoff = BS*1;
-                       float endoff = -BS*MAP_BLOCKSIZE*1.42*1.42;
-                       v3s16 spn = cam_pos_nodes + v3s16(0,0,0);
-                       s16 bs2 = MAP_BLOCKSIZE/2 + 1;
-                       u32 needed_count = 1;
-                       if(
-                               isOccluded(this, spn, cpn + v3s16(0,0,0),
-                                       step, stepfac, startoff, endoff, needed_count, nodemgr) &&
-                               isOccluded(this, spn, cpn + v3s16(bs2,bs2,bs2),
-                                       step, stepfac, startoff, endoff, needed_count, nodemgr) &&
-                               isOccluded(this, spn, cpn + v3s16(bs2,bs2,-bs2),
-                                       step, stepfac, startoff, endoff, needed_count, nodemgr) &&
-                               isOccluded(this, spn, cpn + v3s16(bs2,-bs2,bs2),
-                                       step, stepfac, startoff, endoff, needed_count, nodemgr) &&
-                               isOccluded(this, spn, cpn + v3s16(bs2,-bs2,-bs2),
-                                       step, stepfac, startoff, endoff, needed_count, nodemgr) &&
-                               isOccluded(this, spn, cpn + v3s16(-bs2,bs2,bs2),
-                                       step, stepfac, startoff, endoff, needed_count, nodemgr) &&
-                               isOccluded(this, spn, cpn + v3s16(-bs2,bs2,-bs2),
-                                       step, stepfac, startoff, endoff, needed_count, nodemgr) &&
-                               isOccluded(this, spn, cpn + v3s16(-bs2,-bs2,bs2),
-                                       step, stepfac, startoff, endoff, needed_count, nodemgr) &&
-                               isOccluded(this, spn, cpn + v3s16(-bs2,-bs2,-bs2),
-                                       step, stepfac, startoff, endoff, needed_count, nodemgr)
-                       )
-                       {
-                               blocks_occlusion_culled++;
-                               continue;
-                       }
-                       
-                       // This block is in range. Reset usage timer.
-                       block->resetUsageTimer();
-
-                       /*
-                               Ignore if mesh doesn't exist
-                       */
-                       {
-                               JMutexAutoLock lock(block->mesh_mutex);
-
-                               scene::SMesh *mesh = block->mesh;
-                               
-                               if(mesh == NULL){
-                                       blocks_in_range_without_mesh++;
-                                       continue;
-                               }
-                       }
-                       
-                       // Limit block count in case of a sudden increase
-                       blocks_would_have_drawn++;
-                       if(blocks_drawn >= m_control.wanted_max_blocks
-                                       && m_control.range_all == false
-                                       && d > m_control.wanted_min_range * BS)
-                               continue;
-                       
-                       // Add to set
-                       drawset[block->getPos()] = block;
-                       
-                       sector_blocks_drawn++;
-                       blocks_drawn++;
-
-               } // foreach sectorblocks
-
-               if(sector_blocks_drawn != 0)
-                       m_last_drawn_sectors[sp] = true;
-       }
-       } // ScopeProfiler
-       
-       /*
-               Draw the selected MapBlocks
-       */
-
-       {
-       ScopeProfiler sp(g_profiler, prefix+"drawing blocks", SPT_AVG);
-
-       int timecheck_counter = 0;
-       for(core::map<v3s16, MapBlock*>::Iterator
-                       i = drawset.getIterator();
-                       i.atEnd() == false; i++)
-       {
-               {
-                       timecheck_counter++;
-                       if(timecheck_counter > 50)
-                       {
-                               timecheck_counter = 0;
-                               int time2 = time(0);
-                               if(time2 > time1 + 4)
-                               {
-                                       infostream<<"ClientMap::renderMap(): "
-                                               "Rendering takes ages, returning."
-                                               <<std::endl;
-                                       return;
-                               }
-                       }
-               }
-               
-               MapBlock *block = i.getNode()->getValue();
-
-               /*
-                       Draw the faces of the block
-               */
-               {
-                       JMutexAutoLock lock(block->mesh_mutex);
-
-                       scene::SMesh *mesh = block->mesh;
-                       assert(mesh);
-                       
-                       u32 c = mesh->getMeshBufferCount();
-                       bool stuff_actually_drawn = false;
-                       for(u32 i=0; i<c; i++)
-                       {
-                               scene::IMeshBuffer *buf = mesh->getMeshBuffer(i);
-                               const video::SMaterial& material = buf->getMaterial();
-                               video::IMaterialRenderer* rnd =
-                                               driver->getMaterialRenderer(material.MaterialType);
-                               bool transparent = (rnd && rnd->isTransparent());
-                               // Render transparent on transparent pass and likewise.
-                               if(transparent == is_transparent_pass)
-                               {
-                                       if(buf->getVertexCount() == 0)
-                                               errorstream<<"Block ["<<analyze_block(block)
-                                                               <<"] contains an empty meshbuf"<<std::endl;
-                                       /*
-                                               This *shouldn't* hurt too much because Irrlicht
-                                               doesn't change opengl textures if the old
-                                               material has the same texture.
-                                       */
-                                       driver->setMaterial(buf->getMaterial());
-                                       driver->drawMeshBuffer(buf);
-                                       vertex_count += buf->getVertexCount();
-                                       meshbuffer_count++;
-                                       stuff_actually_drawn = true;
-                               }
-                       }
-                       if(stuff_actually_drawn)
-                               blocks_had_pass_meshbuf++;
-                       else
-                               blocks_without_stuff++;
-               }
-       }
-       } // ScopeProfiler
-       
-       // Log only on solid pass because values are the same
-       if(pass == scene::ESNRP_SOLID){
-               g_profiler->avg("CM: blocks in range", blocks_in_range);
-               g_profiler->avg("CM: blocks occlusion culled", blocks_occlusion_culled);
-               if(blocks_in_range != 0)
-                       g_profiler->avg("CM: blocks in range without mesh (frac)",
-                                       (float)blocks_in_range_without_mesh/blocks_in_range);
-               g_profiler->avg("CM: blocks drawn", blocks_drawn);
-       }
-       
-       g_profiler->avg(prefix+"vertices drawn", vertex_count);
-       if(blocks_had_pass_meshbuf != 0)
-               g_profiler->avg(prefix+"meshbuffers per block",
-                               (float)meshbuffer_count / (float)blocks_had_pass_meshbuf);
-       if(blocks_drawn != 0)
-               g_profiler->avg(prefix+"empty blocks (frac)",
-                               (float)blocks_without_stuff / blocks_drawn);
-
-       m_control.blocks_drawn = blocks_drawn;
-       m_control.blocks_would_have_drawn = blocks_would_have_drawn;
-
-       /*infostream<<"renderMap(): is_transparent_pass="<<is_transparent_pass
-                       <<", rendered "<<vertex_count<<" vertices."<<std::endl;*/
-}
-
-void ClientMap::renderPostFx()
-{
-       INodeDefManager *nodemgr = m_gamedef->ndef();
-
-       // Sadly ISceneManager has no "post effects" render pass, in that case we
-       // could just register for that and handle it in renderMap().
-
-       m_camera_mutex.Lock();
-       v3f camera_position = m_camera_position;
-       m_camera_mutex.Unlock();
-
-       MapNode n = getNodeNoEx(floatToInt(camera_position, BS));
-
-       // - If the player is in a solid node, make everything black.
-       // - If the player is in liquid, draw a semi-transparent overlay.
-       const ContentFeatures& features = nodemgr->get(n);
-       video::SColor post_effect_color = features.post_effect_color;
-       if(features.solidness == 2 && g_settings->getBool("free_move") == false)
-       {
-               post_effect_color = video::SColor(255, 0, 0, 0);
-       }
-       if (post_effect_color.getAlpha() != 0)
-       {
-               // Draw a full-screen rectangle
-               video::IVideoDriver* driver = SceneManager->getVideoDriver();
-               v2u32 ss = driver->getScreenSize();
-               core::rect<s32> rect(0,0, ss.X, ss.Y);
-               driver->draw2DRectangle(post_effect_color, rect);
-       }
-}
-
-bool ClientMap::setTempMod(v3s16 p, NodeMod mod,
-               core::map<v3s16, MapBlock*> *affected_blocks)
-{
-       bool changed = false;
-       /*
-               Add it to all blocks touching it
-       */
-       v3s16 dirs[7] = {
-               v3s16(0,0,0), // this
-               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
-       };
-       for(u16 i=0; i<7; i++)
-       {
-               v3s16 p2 = p + dirs[i];
-               // Block position of neighbor (or requested) node
-               v3s16 blockpos = getNodeBlockPos(p2);
-               MapBlock * blockref = getBlockNoCreateNoEx(blockpos);
-               if(blockref == NULL)
-                       continue;
-               // Relative position of requested node
-               v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
-               if(blockref->setTempMod(relpos, mod))
-               {
-                       changed = true;
-               }
-       }
-       if(changed && affected_blocks!=NULL)
-       {
-               for(u16 i=0; i<7; i++)
-               {
-                       v3s16 p2 = p + dirs[i];
-                       // Block position of neighbor (or requested) node
-                       v3s16 blockpos = getNodeBlockPos(p2);
-                       MapBlock * blockref = getBlockNoCreateNoEx(blockpos);
-                       if(blockref == NULL)
-                               continue;
-                       affected_blocks->insert(blockpos, blockref);
-               }
-       }
-       return changed;
-}
-
-bool ClientMap::clearTempMod(v3s16 p,
-               core::map<v3s16, MapBlock*> *affected_blocks)
-{
-       bool changed = false;
-       v3s16 dirs[7] = {
-               v3s16(0,0,0), // this
-               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
-       };
-       for(u16 i=0; i<7; i++)
-       {
-               v3s16 p2 = p + dirs[i];
-               // Block position of neighbor (or requested) node
-               v3s16 blockpos = getNodeBlockPos(p2);
-               MapBlock * blockref = getBlockNoCreateNoEx(blockpos);
-               if(blockref == NULL)
-                       continue;
-               // Relative position of requested node
-               v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
-               if(blockref->clearTempMod(relpos))
-               {
-                       changed = true;
-               }
-       }
-       if(changed && affected_blocks!=NULL)
-       {
-               for(u16 i=0; i<7; i++)
-               {
-                       v3s16 p2 = p + dirs[i];
-                       // Block position of neighbor (or requested) node
-                       v3s16 blockpos = getNodeBlockPos(p2);
-                       MapBlock * blockref = getBlockNoCreateNoEx(blockpos);
-                       if(blockref == NULL)
-                               continue;
-                       affected_blocks->insert(blockpos, blockref);
-               }
-       }
-       return changed;
-}
-
-void ClientMap::expireMeshes(bool only_daynight_diffed)
-{
-       TimeTaker timer("expireMeshes()");
-
-       core::map<v2s16, MapSector*>::Iterator si;
-       si = m_sectors.getIterator();
-       for(; si.atEnd() == false; si++)
-       {
-               MapSector *sector = si.getNode()->getValue();
-
-               core::list< MapBlock * > sectorblocks;
-               sector->getBlocks(sectorblocks);
-               
-               core::list< MapBlock * >::Iterator i;
-               for(i=sectorblocks.begin(); i!=sectorblocks.end(); i++)
-               {
-                       MapBlock *block = *i;
-
-                       if(only_daynight_diffed && dayNightDiffed(block->getPos()) == false)
-                       {
-                               continue;
-                       }
-                       
-                       {
-                               JMutexAutoLock lock(block->mesh_mutex);
-                               if(block->mesh != NULL)
-                               {
-                                       /*block->mesh->drop();
-                                       block->mesh = NULL;*/
-                                       block->setMeshExpired(true);
-                               }
-                       }
-               }
-       }
-}
-
-void ClientMap::updateMeshes(v3s16 blockpos, u32 daynight_ratio)
-{
-       assert(mapType() == MAPTYPE_CLIENT);
-
-       try{
-               v3s16 p = blockpos + v3s16(0,0,0);
-               MapBlock *b = getBlockNoCreate(p);
-               b->updateMesh(daynight_ratio);
-               //b->setMeshExpired(true);
-       }
-       catch(InvalidPositionException &e){}
-       // Leading edge
-       try{
-               v3s16 p = blockpos + v3s16(-1,0,0);
-               MapBlock *b = getBlockNoCreate(p);
-               b->updateMesh(daynight_ratio);
-               //b->setMeshExpired(true);
-       }
-       catch(InvalidPositionException &e){}
-       try{
-               v3s16 p = blockpos + v3s16(0,-1,0);
-               MapBlock *b = getBlockNoCreate(p);
-               b->updateMesh(daynight_ratio);
-               //b->setMeshExpired(true);
-       }
-       catch(InvalidPositionException &e){}
-       try{
-               v3s16 p = blockpos + v3s16(0,0,-1);
-               MapBlock *b = getBlockNoCreate(p);
-               b->updateMesh(daynight_ratio);
-               //b->setMeshExpired(true);
-       }
-       catch(InvalidPositionException &e){}
-}
-
-#if 0
-/*
-       Update mesh of block in which the node is, and if the node is at the
-       leading edge, update the appropriate leading blocks too.
-*/
-void ClientMap::updateNodeMeshes(v3s16 nodepos, u32 daynight_ratio)
-{
-       v3s16 dirs[4] = {
-               v3s16(0,0,0),
-               v3s16(-1,0,0),
-               v3s16(0,-1,0),
-               v3s16(0,0,-1),
-       };
-       v3s16 blockposes[4];
-       for(u32 i=0; i<4; i++)
-       {
-               v3s16 np = nodepos + dirs[i];
-               blockposes[i] = getNodeBlockPos(np);
-               // Don't update mesh of block if it has been done already
-               bool already_updated = false;
-               for(u32 j=0; j<i; j++)
-               {
-                       if(blockposes[j] == blockposes[i])
-                       {
-                               already_updated = true;
-                               break;
-                       }
-               }
-               if(already_updated)
-                       continue;
-               // Update mesh
-               MapBlock *b = getBlockNoCreate(blockposes[i]);
-               b->updateMesh(daynight_ratio);
-       }
-}
-#endif
-
-void ClientMap::PrintInfo(std::ostream &out)
-{
-       out<<"ClientMap: ";
-}
-
-#endif // !SERVER
-
 /*
        MapVoxelManipulator
 */