]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/client.cpp
Wieldmesh: don't force anisotropic filtering on, instead disable mipmaps
[dragonfireclient.git] / src / client.cpp
index accff4b01c024d69567adaae08425ce771b26f80..074ac9ba60c9b342b061a2a5cb4c2717be84c5d8 100644 (file)
@@ -17,13 +17,19 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
-#include "client.h"
 #include <iostream>
 #include <algorithm>
-#include "clientserver.h"
+#include <sstream>
+#include <IFileSystem.h>
 #include "jthread/jmutexautolock.h"
+#include "util/directiontables.h"
+#include "util/pointedthing.h"
+#include "util/serialize.h"
+#include "util/string.h"
+#include "strfnd.h"
+#include "client.h"
+#include "clientserver.h"
 #include "main.h"
-#include <sstream>
 #include "filesys.h"
 #include "porting.h"
 #include "mapsector.h"
@@ -37,20 +43,19 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "nodedef.h"
 #include "itemdef.h"
 #include "shader.h"
-#include <IFileSystem.h>
 #include "base64.h"
 #include "clientmap.h"
 #include "clientmedia.h"
 #include "sound.h"
-#include "util/string.h"
 #include "IMeshCache.h"
 #include "serialization.h"
-#include "util/serialize.h"
 #include "config.h"
-#include "util/directiontables.h"
-#include "util/pointedthing.h"
 #include "version.h"
 #include "drawscene.h"
+#include "subgame.h"
+#include "server.h"
+#include "database.h"
+#include "database-sqlite3.h"
 
 extern gui::IGUIEnvironment* guienv;
 
@@ -214,6 +219,7 @@ Client::Client(
                IrrlichtDevice *device,
                const char *playername,
                std::string password,
+               bool is_simple_singleplayer_game,
                MapDrawControl &control,
                IWritableTextureSource *tsrc,
                IWritableShaderSource *shsrc,
@@ -249,6 +255,7 @@ Client::Client(
        m_inventory_updated(false),
        m_inventory_from_server(NULL),
        m_inventory_from_server_age(0.0),
+       m_show_hud(true),
        m_animation_time(0),
        m_crack_level(-1),
        m_crack_pos(0,0,0),
@@ -269,18 +276,48 @@ Client::Client(
                Add local player
        */
        {
-               Player *player = new LocalPlayer(this);
-
-               player->updateName(playername);
+               Player *player = new LocalPlayer(this, playername);
 
                m_env.addPlayer(player);
        }
+
+       if (g_settings->getBool("enable_local_map_saving")
+                       && !is_simple_singleplayer_game) {
+               const std::string world_path = porting::path_user + DIR_DELIM + "worlds"
+                               + DIR_DELIM + "server_" + g_settings->get("address")
+                               + "_" + g_settings->get("remote_port");
+
+               SubgameSpec gamespec;
+               if (!getWorldExists(world_path)) {
+                       gamespec = findSubgame(g_settings->get("default_game"));
+                       if (!gamespec.isValid())
+                               gamespec = findSubgame("minimal");
+               } else {
+                       std::string world_gameid = getWorldGameId(world_path, false);
+                       gamespec = findWorldSubgame(world_path);
+               }
+               if (!gamespec.isValid()) {
+                       errorstream << "Couldn't find subgame for local map saving." << std::endl;
+                       return;
+               }
+
+               localserver = new Server(world_path, gamespec, false, false);
+               localdb = new Database_SQLite3(&(ServerMap&)localserver->getMap(), world_path);
+               localdb->beginSave();
+               actionstream << "Local map saving started, map will be saved at '" << world_path << "'" << std::endl;
+       } else {
+               localdb = NULL;
+       }
 }
 
 void Client::Stop()
 {
        //request all client managed threads to stop
        m_mesh_update_thread.Stop();
+       if (localdb != NULL) {
+               actionstream << "Local map saving ended" << std::endl;
+               localdb->endSave();
+       }
 }
 
 bool Client::isShutdown()
@@ -1156,6 +1193,10 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
                        sector->insertBlock(block);
                }
 
+               if (localdb != NULL) {
+                       ((ServerMap&) localserver->getMap()).saveBlock(block, localdb);
+               }
+
                /*
                        Add it to mesh update queue and set it to be acknowledged after update.
                */
@@ -2300,20 +2341,19 @@ void Client::removeNode(v3s16 p)
        {
        }
        
-       // add urgent task to update the modified node
-       addUpdateMeshTaskForNode(p, false, true);
-
        for(std::map<v3s16, MapBlock * >::iterator
                        i = modified_blocks.begin();
                        i != modified_blocks.end(); ++i)
        {
-               addUpdateMeshTaskWithEdge(i->first);
+               addUpdateMeshTask(i->first, false, false);
        }
+       // add urgent task to update the modified node
+       addUpdateMeshTaskForNode(p, false, true);
 }
 
 void Client::addNode(v3s16 p, MapNode n, bool remove_metadata)
 {
-       TimeTaker timer1("Client::addNode()");
+       //TimeTaker timer1("Client::addNode()");
 
        std::map<v3s16, MapBlock*> modified_blocks;
 
@@ -2329,7 +2369,7 @@ void Client::addNode(v3s16 p, MapNode n, bool remove_metadata)
                        i = modified_blocks.begin();
                        i != modified_blocks.end(); ++i)
        {
-               addUpdateMeshTaskWithEdge(i->first);
+               addUpdateMeshTask(i->first, false, false);
        }
 }
        
@@ -2679,7 +2719,7 @@ void Client::afterContentReceived(IrrlichtDevice *device, gui::IGUIFont* font)
 
        // Update node textures and assign shaders to each tile
        infostream<<"- Updating node textures"<<std::endl;
-       m_nodedef->updateTextures(m_tsrc, m_shsrc);
+       m_nodedef->updateTextures(this);
 
        // Preload item textures and meshes if configured to
        if(g_settings->getBool("preload_item_visuals"))
@@ -2781,6 +2821,10 @@ IShaderSource* Client::getShaderSource()
 {
        return m_shsrc;
 }
+scene::ISceneManager* Client::getSceneManager()
+{
+       return m_device->getSceneManager();
+}
 u16 Client::allocateUnknownNodeId(const std::string &name)
 {
        errorstream<<"Client::allocateUnknownNodeId(): "