]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/drawscene.cpp
Hard-coded undersampling.
[dragonfireclient.git] / src / drawscene.cpp
index c3c3b2ef207d2c2e3b739104a8585d77f756b7ee..421b96f124bef3e86e2e11618c454dbf39b08345 100644 (file)
@@ -18,13 +18,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 */
 
 #include "drawscene.h"
-#include "main.h" // for g_settings
 #include "settings.h"
 #include "clouds.h"
 #include "clientmap.h"
 #include "util/timetaker.h"
 #include "fontengine.h"
 #include "guiscalingfilter.h"
+#include "filesys.h"
 
 typedef enum {
        LEFT = -1,
@@ -32,27 +32,9 @@ typedef enum {
        EYECOUNT = 2
 } paralax_sign;
 
-
-void draw_selectionbox(video::IVideoDriver* driver, Hud& hud,
-               std::vector<aabb3f>& hilightboxes, bool show_hud)
-{
-       static const s16 selectionbox_width = rangelim(g_settings->getS16("selectionbox_width"), 1, 5);
-
-       if (!show_hud)
-               return;
-
-       video::SMaterial oldmaterial = driver->getMaterial2D();
-       video::SMaterial m;
-       m.Thickness = selectionbox_width;
-       m.Lighting = false;
-       driver->setMaterial(m);
-       hud.drawSelectionBoxes(hilightboxes);
-       driver->setMaterial(oldmaterial);
-}
-
 void draw_anaglyph_3d_mode(Camera& camera, bool show_hud, Hud& hud,
-               std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
-               scene::ISceneManager* smgr, bool draw_wield_tool, Client& client,
+               video::IVideoDriver* driver, scene::ISceneManager* smgr,
+               bool draw_wield_tool, Client& client,
                gui::IGUIEnvironment* guienv )
 {
 
@@ -86,10 +68,8 @@ void draw_anaglyph_3d_mode(Camera& camera, bool show_hud, Hud& hud,
        camera.getCameraNode()->setTarget(focusPoint);
        smgr->drawAll();
        driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
-       if (show_hud)
-       {
-               draw_selectionbox(driver, hud, hilightboxes, show_hud);
-
+       if (show_hud) {
+               hud.drawSelectionMesh();
                if (draw_wield_tool)
                        camera.drawWieldedTool(&leftMove);
        }
@@ -116,10 +96,8 @@ void draw_anaglyph_3d_mode(Camera& camera, bool show_hud, Hud& hud,
        camera.getCameraNode()->setTarget(focusPoint);
        smgr->drawAll();
        driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
-       if (show_hud)
-       {
-               draw_selectionbox(driver, hud, hilightboxes, show_hud);
-
+       if (show_hud) {
+               hud.drawSelectionMesh();
                if (draw_wield_tool)
                        camera.drawWieldedTool(&rightMove);
        }
@@ -145,16 +123,15 @@ void init_texture(video::IVideoDriver* driver, const v2u32& screensize,
                        irr::video::ECF_A8R8G8B8);
 }
 
-video::ITexture* draw_image(const v2u32& screensize,
-               paralax_sign psign, const irr::core::matrix4& startMatrix,
-               const irr::core::vector3df& focusPoint, bool show_hud,
-               video::IVideoDriver* driver, Camera& camera, scene::ISceneManager* smgr,
-               Hud& hud, std::vector<aabb3f>& hilightboxes,
-               bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
-               video::SColor skycolor )
+video::ITexture* draw_image(const v2u32 &screensize,
+               paralax_sign psign, const irr::core::matrix4 &startMatrix,
+               const irr::core::vector3df &focusPoint, bool show_hud,
+               video::IVideoDriver *driver, Camera &camera, scene::ISceneManager *smgr,
+               Hud &hud, bool draw_wield_tool, Client &client,
+               gui::IGUIEnvironment *guienv, const video::SColor &skycolor)
 {
        static video::ITexture* images[2] = { NULL, NULL };
-       static v2u32 last_screensize = v2u32(0,0);
+       static v2u32 last_screensize = v2u32(0, 0);
 
        video::ITexture* image = NULL;
 
@@ -188,10 +165,8 @@ video::ITexture* draw_image(const v2u32& screensize,
 
        driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
 
-       if (show_hud)
-       {
-               draw_selectionbox(driver, hud, hilightboxes, show_hud);
-
+       if (show_hud) {
+               hud.drawSelectionMesh();
                if (draw_wield_tool)
                        camera.drawWieldedTool(&movement);
        }
@@ -221,7 +196,7 @@ video::ITexture*  draw_hud(video::IVideoDriver* driver, const v2u32& screensize,
                        hud.drawCrosshair();
                hud.drawHotbar(client.getPlayerItem());
                hud.drawLuaElements(camera.getOffset());
-
+               camera.drawNametags();
                guienv->drawAll();
        }
 
@@ -233,7 +208,7 @@ video::ITexture*  draw_hud(video::IVideoDriver* driver, const v2u32& screensize,
 }
 
 void draw_interlaced_3d_mode(Camera& camera, bool show_hud,
-               Hud& hud, std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
+               Hud& hud, video::IVideoDriver* driver,
                scene::ISceneManager* smgr, const v2u32& screensize,
                bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
                video::SColor skycolor )
@@ -249,7 +224,7 @@ void draw_interlaced_3d_mode(Camera& camera, bool show_hud,
 
        /* create left view */
        video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
-                       focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
+                       focusPoint, show_hud, driver, camera, smgr, hud,
                        draw_wield_tool, client, guienv, skycolor);
 
        //Right eye...
@@ -268,10 +243,8 @@ void draw_interlaced_3d_mode(Camera& camera, bool show_hud,
 
        driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
 
-       if (show_hud)
-       {
-               draw_selectionbox(driver, hud, hilightboxes, show_hud);
-
+       if (show_hud) {
+               hud.drawSelectionMesh();
                if(draw_wield_tool)
                        camera.drawWieldedTool(&rightMove);
        }
@@ -294,7 +267,7 @@ void draw_interlaced_3d_mode(Camera& camera, bool show_hud,
 }
 
 void draw_sidebyside_3d_mode(Camera& camera, bool show_hud,
-               Hud& hud, std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
+               Hud& hud, video::IVideoDriver* driver,
                scene::ISceneManager* smgr, const v2u32& screensize,
                bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
                video::SColor skycolor )
@@ -310,12 +283,12 @@ void draw_sidebyside_3d_mode(Camera& camera, bool show_hud,
 
        /* create left view */
        video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
-                       focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
+                       focusPoint, show_hud, driver, camera, smgr, hud,
                        draw_wield_tool, client, guienv, skycolor);
 
        /* create right view */
        video::ITexture* right_image = draw_image(screensize, RIGHT, startMatrix,
-                       focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
+                       focusPoint, show_hud, driver, camera, smgr, hud,
                        draw_wield_tool, client, guienv, skycolor);
 
        /* create hud overlay */
@@ -350,7 +323,7 @@ void draw_sidebyside_3d_mode(Camera& camera, bool show_hud,
 }
 
 void draw_top_bottom_3d_mode(Camera& camera, bool show_hud,
-               Hud& hud, std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
+               Hud& hud, video::IVideoDriver* driver,
                scene::ISceneManager* smgr, const v2u32& screensize,
                bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
                video::SColor skycolor )
@@ -366,12 +339,12 @@ void draw_top_bottom_3d_mode(Camera& camera, bool show_hud,
 
        /* create left view */
        video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
-                       focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
+                       focusPoint, show_hud, driver, camera, smgr, hud,
                        draw_wield_tool, client, guienv, skycolor);
 
        /* create right view */
        video::ITexture* right_image = draw_image(screensize, RIGHT, startMatrix,
-                       focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
+                       focusPoint, show_hud, driver, camera, smgr, hud,
                        draw_wield_tool, client, guienv, skycolor);
 
        /* create hud overlay */
@@ -405,22 +378,140 @@ void draw_top_bottom_3d_mode(Camera& camera, bool show_hud,
        camera.getCameraNode()->setTarget(oldTarget);
 }
 
-void draw_plain(Camera& camera, bool show_hud, Hud& hud,
-               std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
-               bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv)
+void draw_pageflip_3d_mode(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)
 {
+#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8
+       errorstream << "Pageflip 3D mode is not supported"
+               << " with your Irrlicht version!" << std::endl;
+#else
+       /* preserve old setup*/
+       irr::core::vector3df oldPosition = camera.getCameraNode()->getPosition();
+       irr::core::vector3df oldTarget   = camera.getCameraNode()->getTarget();
+
+       irr::core::matrix4 startMatrix =
+                       camera.getCameraNode()->getAbsoluteTransformation();
+       irr::core::vector3df focusPoint = (camera.getCameraNode()->getTarget()
+                       - camera.getCameraNode()->getAbsolutePosition()).setLength(1)
+                       + camera.getCameraNode()->getAbsolutePosition();
+
+       //Left eye...
+       driver->setRenderTarget(irr::video::ERT_STEREO_LEFT_BUFFER);
+
+       irr::core::vector3df leftEye;
+       irr::core::matrix4 leftMove;
+       leftMove.setTranslation(
+                       irr::core::vector3df(-g_settings->getFloat("3d_paralax_strength"),
+                                       0.0f, 0.0f));
+       leftEye = (startMatrix * leftMove).getTranslation();
+
+       //clear the depth buffer, and color
+       driver->beginScene(true, true, irr::video::SColor(200, 200, 200, 255));
+       camera.getCameraNode()->setPosition(leftEye);
+       camera.getCameraNode()->setTarget(focusPoint);
+       smgr->drawAll();
+       driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
+
+       if (show_hud) {
+               hud.drawSelectionMesh();
+               if (draw_wield_tool)
+                       camera.drawWieldedTool(&leftMove);
+               hud.drawHotbar(client.getPlayerItem());
+               hud.drawLuaElements(camera.getOffset());
+               camera.drawNametags();
+       }
+
+       guienv->drawAll();
+
+       //Right eye...
+       driver->setRenderTarget(irr::video::ERT_STEREO_RIGHT_BUFFER);
+
+       irr::core::vector3df rightEye;
+       irr::core::matrix4 rightMove;
+       rightMove.setTranslation(
+                       irr::core::vector3df(g_settings->getFloat("3d_paralax_strength"),
+                                       0.0f, 0.0f));
+       rightEye = (startMatrix * rightMove).getTranslation();
+
+       //clear the depth buffer, and color
+       driver->beginScene(true, true, irr::video::SColor(200, 200, 200, 255));
+       camera.getCameraNode()->setPosition(rightEye);
+       camera.getCameraNode()->setTarget(focusPoint);
+       smgr->drawAll();
        driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
 
-       draw_selectionbox(driver, hud, hilightboxes, show_hud);
+       if (show_hud) {
+               hud.drawSelectionMesh();
+               if (draw_wield_tool)
+                       camera.drawWieldedTool(&rightMove);
+               hud.drawHotbar(client.getPlayerItem());
+               hud.drawLuaElements(camera.getOffset());
+               camera.drawNametags();
+       }
+
+       guienv->drawAll();
+
+       camera.getCameraNode()->setPosition(oldPosition);
+       camera.getCameraNode()->setTarget(oldTarget);
+#endif
+}
+
+// returns (size / coef), rounded upwards
+inline int scaledown(int coef, int size)
+{
+       return (size + coef - 1) / coef;
+}
 
-       if(draw_wield_tool)
-               camera.drawWieldedTool();
+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);
+       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();
+               if (draw_wield_tool) {
+                       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, Client& client, LocalPlayer* player, Hud& hud,
-               gui::IGUIEnvironment* guienv, std::vector<aabb3f> hilightboxes,
-               const v2u32& screensize, video::SColor skycolor, bool show_hud)
+void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
+               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)
 {
        TimeTaker timer("smgr");
 
@@ -438,37 +529,42 @@ 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")
        {
-               draw_anaglyph_3d_mode(camera, show_hud, hud, hilightboxes, driver,
+               draw_anaglyph_3d_mode(camera, show_hud, hud, driver,
                                smgr, draw_wield_tool, client, guienv);
                draw_crosshair = false;
        }
        else if (draw_mode == "interlaced")
        {
-               draw_interlaced_3d_mode(camera, show_hud, hud, hilightboxes, driver,
+               draw_interlaced_3d_mode(camera, show_hud, hud, driver,
                                smgr, screensize, draw_wield_tool, client, guienv, skycolor);
                draw_crosshair = false;
        }
        else if (draw_mode == "sidebyside")
        {
-               draw_sidebyside_3d_mode(camera, show_hud, hud, hilightboxes, driver,
+               draw_sidebyside_3d_mode(camera, show_hud, hud, driver,
                                smgr, screensize, draw_wield_tool, client, guienv, skycolor);
                show_hud = false;
        }
        else if (draw_mode == "topbottom")
        {
-               draw_top_bottom_3d_mode(camera, show_hud, hud, hilightboxes, driver,
+               draw_top_bottom_3d_mode(camera, show_hud, hud, driver,
                                smgr, screensize, draw_wield_tool, client, guienv, skycolor);
                show_hud = false;
        }
+       else if (draw_mode == "pageflip")
+       {
+               draw_pageflip_3d_mode(camera, show_hud, hud, driver,
+                               smgr, screensize, draw_wield_tool, client, guienv, skycolor);
+               draw_crosshair = false;
+               show_hud = false;
+       }
        else {
-               draw_plain(camera, show_hud, hud, hilightboxes, driver,
-                               draw_wield_tool, client, guienv);
+               draw_plain(camera, show_hud, hud, driver,
+                               smgr, screensize, draw_wield_tool, client, guienv, skycolor);
        }
 
        /*
@@ -483,8 +579,13 @@ void draw_scene(video::IVideoDriver* driver, scene::ISceneManager* smgr,
        {
                if (draw_crosshair)
                        hud.drawCrosshair();
+
                hud.drawHotbar(client.getPlayerItem());
                hud.drawLuaElements(camera.getOffset());
+               camera.drawNametags();
+
+               if (show_minimap)
+                       mapper.drawMinimap();
        }
 
        guienv->drawAll();
@@ -523,30 +624,56 @@ void draw_load_screen(const std::wstring &text, IrrlichtDevice* device,
                driver->beginScene(true, true, video::SColor(255, 0, 0, 0));
 
        // draw progress bar
-       if ((percent >= 0) && (percent <= 100))
-       {
-               v2s32 barsize(
-                               // 342 is (approximately) 256/0.75 to keep bar on same size as
-                               // before with default settings
-                               342 * porting::getDisplayDensity() *
-                               g_settings->getFloat("gui_scaling"),
-                               g_fontengine->getTextHeight() * 2);
-
-               core::rect<s32> barrect(center - barsize / 2, center + barsize / 2);
-               driver->draw2DRectangle(video::SColor(255, 255, 255, 255),barrect, NULL); // border
-               driver->draw2DRectangle(video::SColor(255, 64, 64, 64), core::rect<s32> (
-                               barrect.UpperLeftCorner + 1,
-                               barrect.LowerRightCorner-1), NULL); // black inside the bar
-               driver->draw2DRectangle(video::SColor(255, 128, 128, 128), core::rect<s32> (
-                               barrect.UpperLeftCorner + 1,
-                               core::vector2d<s32>(
-                                               barrect.LowerRightCorner.X -
-                                               (barsize.X - 1) + percent * (barsize.X - 2) / 100,
-                                               barrect.LowerRightCorner.Y - 1)), NULL); // the actual progress
+       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());
+
+               if (progress_img && progress_img_bg) {
+                       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);
+                       v2s32 img_pos((screensize.X - imgW) / 2, (screensize.Y - imgH) / 2);
+
+                       draw2DImageFilterScaled(
+                               driver, progress_img_bg,
+                               core::rect<s32>(img_pos.X,
+                                               img_pos.Y,
+                                               img_pos.X + imgW,
+                                               img_pos.Y + imgH),
+                               core::rect<s32>(0, 0,
+                                               img_size.Width,
+                                               img_size.Height),
+                               0, 0, true);
+
+                       draw2DImageFilterScaled(
+                               driver, progress_img,
+                               core::rect<s32>(img_pos.X,
+                                               img_pos.Y,
+                                               img_pos.X + (percent * imgW) / 100,
+                                               img_pos.Y + imgH),
+                               core::rect<s32>(0, 0,
+                                               (percent * img_size.Width) / 100,
+                                               img_size.Height),
+                               0, 0, true);
+               }
        }
+
        guienv->drawAll();
        driver->endScene();
-
        guitext->remove();
 
        //return guitext;