Cpp11 initializers: last src root changeset (#6022)
[oweals/minetest.git] / src / drawscene.cpp
index e3e6301a8a7cefb9c1a79e18804b8b2c729eae80..2cf9689a8e5586b6fe8e3c2800365873169c9911 100644 (file)
@@ -459,10 +459,37 @@ void draw_pageflip_3d_mode(Camera& camera, bool show_hud,
 #endif
 }
 
-void draw_plain(Camera &camera, bool show_hud, Hud &hud,
-               video::IVideoDriver *driver, bool draw_wield_tool,
-               Client &client, gui::IGUIEnvironment *guienv)
+// returns (size / coef), rounded upwards
+inline int scaledown(int coef, int size)
 {
+       return (size + coef - 1) / coef;
+}
+
+void draw_plain(Camera &camera, bool show_hud,
+               Hud &hud, video::IVideoDriver *driver,
+               scene::ISceneManager *smgr, const v2u32 &screensize,
+               bool draw_wield_tool, Client &client, gui::IGUIEnvironment *guienv,
+               video::SColor skycolor)
+{
+       // Undersampling-specific stuff
+       static video::ITexture *image = NULL;
+       static v2u32 last_pixelated_size = v2u32(0, 0);
+       static thread_local int undersampling = g_settings->getU16("undersampling");
+       v2u32 pixelated_size;
+       v2u32 dest_size;
+       if (undersampling > 0) {
+               pixelated_size = v2u32(scaledown(undersampling, screensize.X),
+                               scaledown(undersampling, screensize.Y));
+               dest_size = v2u32(undersampling * pixelated_size.X, undersampling * pixelated_size.Y);
+               if (pixelated_size != last_pixelated_size) {
+                       init_texture(driver, pixelated_size, &image, "mt_drawimage_img1");
+                       last_pixelated_size = pixelated_size;
+               }
+               driver->setRenderTarget(image, true, true, skycolor);
+       }
+
+       // Render
+       smgr->drawAll();
        driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
        if (show_hud) {
                hud.drawSelectionMesh();
@@ -470,11 +497,19 @@ void draw_plain(Camera &camera, bool show_hud, Hud &hud,
                        camera.drawWieldedTool();
                }
        }
+
+       // Upscale lowres render
+       if (undersampling > 0) {
+               driver->setRenderTarget(0, true, true);
+               driver->draw2DImage(image,
+                               irr::core::rect<s32>(0, 0, dest_size.X, dest_size.Y),
+                               irr::core::rect<s32>(0, 0, pixelated_size.X, pixelated_size.Y));
+       }
 }
 
 void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
-               Camera &camera, Clientclient, LocalPlayer *player, Hud &hud,
-               Mapper &mapper, gui::IGUIEnvironment *guienv,
+               Camera &camera, Client &client, LocalPlayer *player, Hud &hud,
+               Minimap *mapper, gui::IGUIEnvironment *guienv,
                const v2u32 &screensize, const video::SColor &skycolor,
                bool show_hud, bool show_minimap)
 {
@@ -494,9 +529,7 @@ void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
        catch(SettingNotFoundException) {}
 #endif
 
-       std::string draw_mode = g_settings->get("3d_mode");
-
-       smgr->drawAll();
+       const std::string &draw_mode = g_settings->get("3d_mode");
 
        if (draw_mode == "anaglyph")
        {
@@ -531,7 +564,7 @@ void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
        }
        else {
                draw_plain(camera, show_hud, hud, driver,
-                               draw_wield_tool, client, guienv);
+                               smgr, screensize, draw_wield_tool, client, guienv, skycolor);
        }
 
        /*
@@ -551,8 +584,8 @@ void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
                hud.drawLuaElements(camera.getOffset());
                camera.drawNametags();
 
-               if (show_minimap)
-                       mapper.drawMinimap();
+               if (mapper && show_minimap)
+                       mapper->drawMinimap();
        }
 
        guienv->drawAll();
@@ -566,7 +599,8 @@ void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
        Additionally, a progressbar can be drawn when percent is set between 0 and 100.
 */
 void draw_load_screen(const std::wstring &text, IrrlichtDevice* device,
-               gui::IGUIEnvironment* guienv, float dtime, int percent, bool clouds )
+               gui::IGUIEnvironment* guienv, ITextureSource *tsrc,
+               float dtime, int percent, bool clouds)
 {
        video::IVideoDriver* driver    = device->getVideoDriver();
        v2u32 screensize               = porting::getWindowSize();
@@ -592,27 +626,20 @@ void draw_load_screen(const std::wstring &text, IrrlichtDevice* device,
 
        // draw progress bar
        if ((percent >= 0) && (percent <= 100)) {
-               const std::string &texture_path = g_settings->get("texture_path");
-               std::string tp_progress_bar = texture_path + "/progress_bar.png";
-               std::string tp_progress_bar_bg = texture_path + "/progress_bar_bg.png";
-
-               if (!(fs::PathExists(tp_progress_bar) &&
-                               fs::PathExists(tp_progress_bar_bg))) {
-                       std::string gamepath = fs::RemoveRelativePathComponents(
-                               porting::path_share + DIR_DELIM + "textures");
-                       tp_progress_bar = gamepath + "/base/pack/progress_bar.png";
-                       tp_progress_bar_bg = gamepath + "/base/pack/progress_bar_bg.png";
-               }
-
-               video::ITexture *progress_img =
-                       driver->getTexture(tp_progress_bar.c_str());
-               video::ITexture *progress_img_bg =
-                       driver->getTexture(tp_progress_bar_bg.c_str());
+               video::ITexture *progress_img = tsrc->getTexture("progress_bar.png");
+               video::ITexture *progress_img_bg = tsrc->getTexture("progress_bar_bg.png");
 
                if (progress_img && progress_img_bg) {
+#ifndef __ANDROID__
                        const core::dimension2d<u32> &img_size = progress_img_bg->getSize();
                        u32 imgW = rangelim(img_size.Width, 200, 600);
                        u32 imgH = rangelim(img_size.Height, 24, 72);
+#else
+                       const core::dimension2d<u32> img_size(256, 48);
+                       float imgRatio = (float) img_size.Height / img_size.Width;
+                       u32 imgW = screensize.X / 2.2f;
+                       u32 imgH = floor(imgW * imgRatio);
+#endif
                        v2s32 img_pos((screensize.X - imgW) / 2, (screensize.Y - imgH) / 2);
 
                        draw2DImageFilterScaled(