]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/client.cpp
Cleanup and (mostly) document util/string.h and (very) minor refactoring
[dragonfireclient.git] / src / client.cpp
index 30280369f81f539c56ae5a56f5b858da0d093819..c6319d5846e8ca1eb536620b87641d9c6eefa280 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,18 +43,13 @@ 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"
 
@@ -249,6 +250,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,9 +271,7 @@ Client::Client(
                Add local player
        */
        {
-               Player *player = new LocalPlayer(this);
-
-               player->updateName(playername);
+               Player *player = new LocalPlayer(this, playername);
 
                m_env.addPlayer(player);
        }
@@ -2538,16 +2538,14 @@ void Client::typeChatMessage(const std::wstring &message)
        // Show locally
        if (message[0] == L'/')
        {
-               m_chat_queue.push_back(
-                               (std::wstring)L"issued command: "+message);
+               m_chat_queue.push_back((std::wstring)L"issued command: " + message);
        }
        else
        {
                LocalPlayer *player = m_env.getLocalPlayer();
                assert(player != NULL);
                std::wstring name = narrow_to_wide(player->getName());
-               m_chat_queue.push_back(
-                               (std::wstring)L"<"+name+L"> "+message);
+               m_chat_queue.push_back((std::wstring)L"<" + name + L"> " + message);
        }
 }
 
@@ -2681,7 +2679,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"))
@@ -2732,6 +2730,34 @@ float Client::getAvgRate(void)
                        m_con.getLocalStat(con::AVG_DL_RATE));
 }
 
+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, 
+                       raw_image->getDimension());
+
+               if (image) {
+                       raw_image->copyTo(image);
+                       irr::c8 filename[256];
+                       snprintf(filename, sizeof(filename), "%s" DIR_DELIM "screenshot_%u.png",
+                                g_settings->get("screenshot_path").c_str(),
+                                device->getTimer()->getRealTime());
+                       std::stringstream 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;
+                       image->drop();
+               }
+               raw_image->drop();
+       }
+}
+
 // IGameDef interface
 // Under envlock
 IItemDefManager* Client::getItemDefManager()
@@ -2755,6 +2781,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(): "