]> git.lizzy.rs Git - minetest.git/blobdiff - src/map.cpp
Initially add small and tight logging facility
[minetest.git] / src / map.cpp
index 46ee5b53ffe830fe8a50d50808a908b282112a9e..a13c028fa22f895d396eb536869db6ea261399c3 100644 (file)
@@ -28,6 +28,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "porting.h"
 #include "mapgen.h"
 #include "nodemetadata.h"
+#include "content_mapnode.h"
+#ifndef SERVER
+#include <IMaterialRenderer.h>
+#endif
+#include "settings.h"
 
 /*
        SQLite format specification:
@@ -770,7 +775,7 @@ void Map::updateLighting(enum LightBank bank,
                generation for testing or whatever
        */
 #if 0
-       //if(g_settings.get(""))
+       //if(g_settings->get(""))
        {
                core::map<v3s16, MapBlock*>::Iterator i;
                i = blocks_to_update.getIterator();
@@ -890,7 +895,7 @@ void Map::updateLighting(core::map<v3s16, MapBlock*> & a_blocks,
 /*
 */
 void Map::addNodeAndUpdate(v3s16 p, MapNode n,
-               core::map<v3s16, MapBlock*> &modified_blocks)
+               core::map<v3s16, MapBlock*> &modified_blocks, std::string &player_name)
 {
        /*PrintInfo(m_dout);
        m_dout<<DTIME<<"Map::addNodeAndUpdate(): p=("
@@ -1014,6 +1019,7 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
        if(meta_proto)
        {
                NodeMetadata *meta = meta_proto->clone();
+               meta->setOwner(player_name);
                setNodeMetadata(p, meta);
        }
 
@@ -1290,7 +1296,8 @@ bool Map::addNodeWithEvent(v3s16 p, MapNode n)
        bool succeeded = true;
        try{
                core::map<v3s16, MapBlock*> modified_blocks;
-               addNodeAndUpdate(p, n, modified_blocks);
+               std::string st = std::string("");
+               addNodeAndUpdate(p, n, modified_blocks, st);
 
                // Copy modified_blocks to event
                for(core::map<v3s16, MapBlock*>::Iterator
@@ -1408,6 +1415,7 @@ void Map::timerUpdate(float dtime, float unload_timeout,
 
        core::map<v2s16, MapSector*>::Iterator si;
 
+       beginSave();
        si = m_sectors.getIterator();
        for(; si.atEnd() == false; si++)
        {
@@ -1418,7 +1426,6 @@ void Map::timerUpdate(float dtime, float unload_timeout,
                core::list<MapBlock*> blocks;
                sector->getBlocks(blocks);
                
-               beginSave();
                for(core::list<MapBlock*>::Iterator i = blocks.begin();
                                i != blocks.end(); i++)
                {
@@ -1451,13 +1458,13 @@ void Map::timerUpdate(float dtime, float unload_timeout,
                                all_blocks_deleted = false;
                        }
                }
-               endSave();
 
                if(all_blocks_deleted)
                {
                        sector_deletion_queue.push_back(si.getNode()->getKey());
                }
        }
+       endSave();
        
        // Finally delete the empty sectors
        deleteSectors(sector_deletion_queue);
@@ -1894,10 +1901,17 @@ ServerMap::ServerMap(std::string savedir):
 
        //m_chunksize = 8; // Takes a few seconds
 
-       m_seed = (((u64)(myrand()%0xffff)<<0)
-                       + ((u64)(myrand()%0xffff)<<16)
-                       + ((u64)(myrand()%0xffff)<<32)
-                       + ((u64)(myrand()%0xffff)<<48));
+       if (g_settings->get("fixed_map_seed").empty())
+       {
+               m_seed = (((u64)(myrand()%0xffff)<<0)
+                               + ((u64)(myrand()%0xffff)<<16)
+                               + ((u64)(myrand()%0xffff)<<32)
+                               + ((u64)(myrand()%0xffff)<<48));
+       }
+       else
+       {
+               m_seed = g_settings->getU64("fixed_map_seed");
+       }
 
        /*
                Experimental and debug stuff
@@ -2034,7 +2048,7 @@ ServerMap::~ServerMap()
 
 void ServerMap::initBlockMake(mapgen::BlockMakeData *data, v3s16 blockpos)
 {
-       bool enable_mapgen_debug_info = g_settings.getBool("enable_mapgen_debug_info");
+       bool enable_mapgen_debug_info = g_settings->getBool("enable_mapgen_debug_info");
        if(enable_mapgen_debug_info)
                dstream<<"initBlockMake(): ("<<blockpos.X<<","<<blockpos.Y<<","
                                <<blockpos.Z<<")"<<std::endl;
@@ -2129,7 +2143,7 @@ MapBlock* ServerMap::finishBlockMake(mapgen::BlockMakeData *data,
                return NULL;
        }
 
-       bool enable_mapgen_debug_info = g_settings.getBool("enable_mapgen_debug_info");
+       bool enable_mapgen_debug_info = g_settings->getBool("enable_mapgen_debug_info");
 
        /*dstream<<"Resulting vmanip:"<<std::endl;
        data->vmanip.print(dstream);*/
@@ -2384,7 +2398,7 @@ MapBlock * ServerMap::generateBlock(
                        <<"("<<p.X<<","<<p.Y<<","<<p.Z<<")"
                        <<std::endl;*/
        
-       bool enable_mapgen_debug_info = g_settings.getBool("enable_mapgen_debug_info");
+       bool enable_mapgen_debug_info = g_settings->getBool("enable_mapgen_debug_info");
 
        TimeTaker timer("generateBlock");
        
@@ -3390,6 +3404,9 @@ void ServerMap::loadBlock(std::string sectordir, std::string blockfile, MapSecto
                if(version < SER_FMT_VER_HIGHEST || save_after_load)
                {
                        saveBlock(block);
+                       
+                       // Should be in database now, so delete the old file
+                       fs::RecursiveDelete(fullpath);
                }
                
                // We just loaded it from the disk, so it's up-to-date.
@@ -3594,7 +3611,8 @@ ClientMap::ClientMap(
        m_client(client),
        m_control(control),
        m_camera_position(0,0,0),
-       m_camera_direction(0,0,1)
+       m_camera_direction(0,0,1),
+       m_camera_fov(PI)
 {
        m_camera_mutex.Init();
        assert(m_camera_mutex.IsInitialized());
@@ -3703,6 +3721,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
        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();
 
        /*
@@ -3795,7 +3814,8 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
                        
                        float d = 0.0;
                        if(isBlockInSight(block->getPos(), camera_position,
-                                       camera_direction, range, &d) == false)
+                                       camera_direction, camera_fov,
+                                       range, &d) == false)
                        {
                                continue;
                        }
@@ -3915,6 +3935,35 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
                        <<", rendered "<<vertex_count<<" vertices."<<std::endl;*/
 }
 
+void ClientMap::renderPostFx()
+{
+       // 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.
+       ContentFeatures& features = content_features(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)
 {