]> git.lizzy.rs Git - minetest.git/blobdiff - src/client.cpp
Deduplicate code and use stdlib in string functions
[minetest.git] / src / client.cpp
index 074ac9ba60c9b342b061a2a5cb4c2717be84c5d8..cfa8704b3b140e1ba943858a108d52f2f1ebbe66 100644 (file)
@@ -255,10 +255,11 @@ Client::Client(
        m_inventory_updated(false),
        m_inventory_from_server(NULL),
        m_inventory_from_server_age(0.0),
-       m_show_hud(true),
+       m_show_highlighted(false),
        m_animation_time(0),
        m_crack_level(-1),
        m_crack_pos(0,0,0),
+       m_highlighted_pos(0,0,0),
        m_map_seed(0),
        m_password(password),
        m_access_denied(false),
@@ -308,6 +309,8 @@ Client::Client(
        } else {
                localdb = NULL;
        }
+
+       m_cache_smooth_lighting = g_settings->getBool("smooth_lighting");
 }
 
 void Client::Stop()
@@ -574,7 +577,7 @@ void Client::step(float dtime)
                {
                        if(sendlist.size() == 255 || i == deleted_blocks.end())
                        {
-                               if(sendlist.size() == 0)
+                               if(sendlist.empty())
                                        break;
                                /*
                                        [0] u16 command
@@ -810,7 +813,7 @@ void Client::step(float dtime)
                        }
                }
                // Sync to server
-               if(removed_server_ids.size() != 0)
+               if(!removed_server_ids.empty())
                {
                        std::ostringstream os(std::ios_base::binary);
                        writeU16(os, TOSERVER_REMOVED_SOUNDS);
@@ -2345,10 +2348,8 @@ void Client::removeNode(v3s16 p)
                        i = modified_blocks.begin();
                        i != modified_blocks.end(); ++i)
        {
-               addUpdateMeshTask(i->first, false, false);
+               addUpdateMeshTaskWithEdge(i->first, false, true);
        }
-       // add urgent task to update the modified node
-       addUpdateMeshTaskForNode(p, false, true);
 }
 
 void Client::addNode(v3s16 p, MapNode n, bool remove_metadata)
@@ -2369,7 +2370,7 @@ void Client::addNode(v3s16 p, MapNode n, bool remove_metadata)
                        i = modified_blocks.begin();
                        i != modified_blocks.end(); ++i)
        {
-               addUpdateMeshTask(i->first, false, false);
+               addUpdateMeshTaskWithEdge(i->first, false, true);
        }
 }
        
@@ -2515,9 +2516,9 @@ int Client::getCrackLevel()
        return m_crack_level;
 }
 
-void Client::setHighlighted(v3s16 pos, bool show_hud)
+void Client::setHighlighted(v3s16 pos, bool show_highlighted)
 {
-       m_show_hud = show_hud;
+       m_show_highlighted = show_highlighted;
        v3s16 old_highlighted_pos = m_highlighted_pos;
        m_highlighted_pos = pos;
        addUpdateMeshTaskForNode(old_highlighted_pos, false, true);
@@ -2607,8 +2608,8 @@ void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server, bool urgent)
                // Debug: 1-6ms, avg=2ms
                data->fill(b);
                data->setCrack(m_crack_level, m_crack_pos);
-               data->setHighlighted(m_highlighted_pos, m_show_hud);
-               data->setSmoothLighting(g_settings->getBool("smooth_lighting"));
+               data->setHighlighted(m_highlighted_pos, m_show_highlighted);
+               data->setSmoothLighting(m_cache_smooth_lighting);
        }
 
        // Add task to queue
@@ -2618,9 +2619,7 @@ void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server, bool urgent)
 void Client::addUpdateMeshTaskWithEdge(v3s16 blockpos, bool ack_to_server, bool urgent)
 {
        try{
-               v3s16 p = blockpos + v3s16(0,0,0);
-               //MapBlock *b = m_env.getMap().getBlockNoCreate(p);
-               addUpdateMeshTask(p, ack_to_server, urgent);
+               addUpdateMeshTask(blockpos, ack_to_server, urgent);
        }
        catch(InvalidPositionException &e){}
 
@@ -2648,8 +2647,7 @@ void Client::addUpdateMeshTaskForNode(v3s16 nodepos, bool ack_to_server, bool ur
        v3s16 blockpos_relative = blockpos * MAP_BLOCKSIZE;
 
        try{
-               v3s16 p = blockpos + v3s16(0,0,0);
-               addUpdateMeshTask(p, ack_to_server, urgent);
+               addUpdateMeshTask(blockpos, ack_to_server, urgent);
        }
        catch(InvalidPositionException &e){}
 
@@ -2705,17 +2703,27 @@ void Client::afterContentReceived(IrrlichtDevice *device, gui::IGUIFont* font)
        assert(m_nodedef_received);
        assert(mediaReceived());
        
+       wchar_t* text = wgettext("Loading textures...");
+
        // Rebuild inherited images and recreate textures
        infostream<<"- Rebuilding images and textures"<<std::endl;
+       draw_load_screen(text,device, guienv, 0, 70);
        m_tsrc->rebuildImagesAndTextures();
+       delete[] text;
 
        // Rebuild shaders
        infostream<<"- Rebuilding shaders"<<std::endl;
+       text = wgettext("Rebuilding shaders...");
+       draw_load_screen(text, device, guienv, 0, 75);
        m_shsrc->rebuildShaders();
+       delete[] text;
 
        // Update node aliases
        infostream<<"- Updating node aliases"<<std::endl;
+       text = wgettext("Initializing nodes...");
+       draw_load_screen(text, device, guienv, 0, 80);
        m_nodedef->updateAliases(m_itemdef);
+       delete[] text;
 
        // Update node textures and assign shaders to each tile
        infostream<<"- Updating node textures"<<std::endl;
@@ -2725,21 +2733,21 @@ void Client::afterContentReceived(IrrlichtDevice *device, gui::IGUIFont* font)
        if(g_settings->getBool("preload_item_visuals"))
        {
                verbosestream<<"Updating item textures and meshes"<<std::endl;
-               wchar_t* text = wgettext("Item textures...");
-               draw_load_screen(text, device, guienv, font, 0, 0);
+               text = wgettext("Item textures...");
+               draw_load_screen(text, device, guienv, 0, 0);
                std::set<std::string> names = m_itemdef->getAll();
                size_t size = names.size();
                size_t count = 0;
                int percent = 0;
                for(std::set<std::string>::const_iterator
-                               i = names.begin(); i != names.end(); ++i){
+                               i = names.begin(); i != names.end(); ++i)
+               {
                        // Asking for these caches the result
                        m_itemdef->getInventoryTexture(*i, this);
                        m_itemdef->getWieldMesh(*i, this);
                        count++;
-                       percent = count*100/size;
-                       if (count%50 == 0) // only update every 50 item
-                               draw_load_screen(text, device, guienv, font, 0, percent);
+                       percent = (count * 100 / size * 0.2) + 80;
+                       draw_load_screen(text, device, guienv, 0, percent);
                }
                delete[] text;
        }
@@ -2750,7 +2758,10 @@ void Client::afterContentReceived(IrrlichtDevice *device, gui::IGUIFont* font)
        
        m_state = LC_Ready;
        sendReady();
+       text = wgettext("Done!");
+       draw_load_screen(text, device, guienv, 0, 100);
        infostream<<"Client::afterContentReceived() done"<<std::endl;
+       delete[] text;
 }
 
 float Client::getRTT(void)
@@ -2775,7 +2786,7 @@ void Client::makeScreenshot(IrrlichtDevice *device)
        irr::video::IVideoDriver *driver = device->getVideoDriver();
        irr::video::IImage* const raw_image = driver->createScreenShot();
        if (raw_image) {
-               irr::video::IImage* const image = driver->createImage(video::ECF_R8G8B8, 
+               irr::video::IImage* const image = driver->createImage(video::ECF_R8G8B8,
                        raw_image->getDimension());
 
                if (image) {
@@ -2784,14 +2795,14 @@ void Client::makeScreenshot(IrrlichtDevice *device)
                        snprintf(filename, sizeof(filename), "%s" DIR_DELIM "screenshot_%u.png",
                                 g_settings->get("screenshot_path").c_str(),
                                 device->getTimer()->getRealTime());
-                       std::stringstream sstr;
+                       std::ostringstream sstr;
                        if (driver->writeImageToFile(image, filename)) {
                                sstr << "Saved screenshot to '" << filename << "'";
                        } else {
                                sstr << "Failed to save screenshot '" << filename << "'";
                        }
                        m_chat_queue.push_back(narrow_to_wide(sstr.str()));
-                       infostream << sstr << std::endl;
+                       infostream << sstr.str() << std::endl;
                        image->drop();
                }
                raw_image->drop();