LCOV - code coverage report
Current view: top level - src - drawscene.cpp (source / functions) Hit Total Coverage
Test: report Lines: 76 282 27.0 %
Date: 2015-07-11 18:23:49 Functions: 6 13 46.2 %

          Line data    Source code
       1             : /*
       2             : Minetest
       3             : Copyright (C) 2010-2014 celeron55, Perttu Ahola <celeron55@gmail.com>
       4             : 
       5             : This program is free software; you can redistribute it and/or modify
       6             : it under the terms of the GNU Lesser General Public License as published by
       7             : the Free Software Foundation; either version 2.1 of the License, or
       8             : (at your option) any later version.
       9             : 
      10             : This program is distributed in the hope that it will be useful,
      11             : but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13             : GNU Lesser General Public License for more details.
      14             : 
      15             : You should have received a copy of the GNU Lesser General Public License along
      16             : with this program; if not, write to the Free Software Foundation, Inc.,
      17             : 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      18             : */
      19             : 
      20             : #include "drawscene.h"
      21             : #include "settings.h"
      22             : #include "clouds.h"
      23             : #include "clientmap.h"
      24             : #include "util/timetaker.h"
      25             : #include "fontengine.h"
      26             : #include "guiscalingfilter.h"
      27             : 
      28             : typedef enum {
      29             :         LEFT = -1,
      30             :         RIGHT = 1,
      31             :         EYECOUNT = 2
      32             : } paralax_sign;
      33             : 
      34             : 
      35        1166 : void draw_selectionbox(video::IVideoDriver* driver, Hud& hud,
      36             :                 std::vector<aabb3f>& hilightboxes, bool show_hud)
      37             : {
      38        1166 :         static const s16 selectionbox_width = rangelim(g_settings->getS16("selectionbox_width"), 1, 5);
      39             : 
      40        1166 :         if (!show_hud)
      41           0 :                 return;
      42             : 
      43        2332 :         video::SMaterial oldmaterial = driver->getMaterial2D();
      44        2332 :         video::SMaterial m;
      45        1166 :         m.Thickness = selectionbox_width;
      46        1166 :         m.Lighting = false;
      47        1166 :         driver->setMaterial(m);
      48        1166 :         hud.drawSelectionBoxes(hilightboxes);
      49        1166 :         driver->setMaterial(oldmaterial);
      50             : }
      51             : 
      52           0 : void draw_anaglyph_3d_mode(Camera& camera, bool show_hud, Hud& hud,
      53             :                 std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
      54             :                 scene::ISceneManager* smgr, bool draw_wield_tool, Client& client,
      55             :                 gui::IGUIEnvironment* guienv )
      56             : {
      57             : 
      58             :         /* preserve old setup*/
      59           0 :         irr::core::vector3df oldPosition = camera.getCameraNode()->getPosition();
      60           0 :         irr::core::vector3df oldTarget   = camera.getCameraNode()->getTarget();
      61             : 
      62             :         irr::core::matrix4 startMatrix =
      63           0 :                         camera.getCameraNode()->getAbsoluteTransformation();
      64           0 :         irr::core::vector3df focusPoint = (camera.getCameraNode()->getTarget()
      65           0 :                         - camera.getCameraNode()->getAbsolutePosition()).setLength(1)
      66           0 :                         + camera.getCameraNode()->getAbsolutePosition();
      67             : 
      68             : 
      69             :         //Left eye...
      70           0 :         irr::core::vector3df leftEye;
      71           0 :         irr::core::matrix4 leftMove;
      72             :         leftMove.setTranslation(
      73           0 :                         irr::core::vector3df(-g_settings->getFloat("3d_paralax_strength"),
      74           0 :                                         0.0f, 0.0f));
      75           0 :         leftEye = (startMatrix * leftMove).getTranslation();
      76             : 
      77             :         //clear the depth buffer, and color
      78           0 :         driver->beginScene( true, true, irr::video::SColor(0, 200, 200, 255));
      79           0 :         driver->getOverrideMaterial().Material.ColorMask = irr::video::ECP_RED;
      80           0 :         driver->getOverrideMaterial().EnableFlags = irr::video::EMF_COLOR_MASK;
      81           0 :         driver->getOverrideMaterial().EnablePasses = irr::scene::ESNRP_SKY_BOX
      82             :                         + irr::scene::ESNRP_SOLID + irr::scene::ESNRP_TRANSPARENT
      83           0 :                         + irr::scene::ESNRP_TRANSPARENT_EFFECT + irr::scene::ESNRP_SHADOW;
      84           0 :         camera.getCameraNode()->setPosition(leftEye);
      85           0 :         camera.getCameraNode()->setTarget(focusPoint);
      86           0 :         smgr->drawAll();
      87           0 :         driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
      88           0 :         if (show_hud)
      89             :         {
      90           0 :                 draw_selectionbox(driver, hud, hilightboxes, show_hud);
      91             : 
      92           0 :                 if (draw_wield_tool)
      93           0 :                         camera.drawWieldedTool(&leftMove);
      94             :         }
      95             : 
      96           0 :         guienv->drawAll();
      97             : 
      98             :         //Right eye...
      99           0 :         irr::core::vector3df rightEye;
     100           0 :         irr::core::matrix4 rightMove;
     101             :         rightMove.setTranslation(
     102             :                         irr::core::vector3df(g_settings->getFloat("3d_paralax_strength"),
     103           0 :                                         0.0f, 0.0f));
     104           0 :         rightEye = (startMatrix * rightMove).getTranslation();
     105             : 
     106             :         //clear the depth buffer
     107           0 :         driver->clearZBuffer();
     108           0 :         driver->getOverrideMaterial().Material.ColorMask = irr::video::ECP_GREEN
     109           0 :                         + irr::video::ECP_BLUE;
     110           0 :         driver->getOverrideMaterial().EnableFlags = irr::video::EMF_COLOR_MASK;
     111           0 :         driver->getOverrideMaterial().EnablePasses = irr::scene::ESNRP_SKY_BOX
     112             :                         + irr::scene::ESNRP_SOLID + irr::scene::ESNRP_TRANSPARENT
     113           0 :                         + irr::scene::ESNRP_TRANSPARENT_EFFECT + irr::scene::ESNRP_SHADOW;
     114           0 :         camera.getCameraNode()->setPosition(rightEye);
     115           0 :         camera.getCameraNode()->setTarget(focusPoint);
     116           0 :         smgr->drawAll();
     117           0 :         driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
     118           0 :         if (show_hud)
     119             :         {
     120           0 :                 draw_selectionbox(driver, hud, hilightboxes, show_hud);
     121             : 
     122           0 :                 if (draw_wield_tool)
     123           0 :                         camera.drawWieldedTool(&rightMove);
     124             :         }
     125             : 
     126           0 :         guienv->drawAll();
     127             : 
     128           0 :         driver->getOverrideMaterial().Material.ColorMask = irr::video::ECP_ALL;
     129           0 :         driver->getOverrideMaterial().EnableFlags = 0;
     130           0 :         driver->getOverrideMaterial().EnablePasses = 0;
     131           0 :         camera.getCameraNode()->setPosition(oldPosition);
     132           0 :         camera.getCameraNode()->setTarget(oldTarget);
     133           0 : }
     134             : 
     135           0 : void init_texture(video::IVideoDriver* driver, const v2u32& screensize,
     136             :                 video::ITexture** texture, const char* name)
     137             : {
     138           0 :         if (*texture != NULL)
     139             :         {
     140           0 :                 driver->removeTexture(*texture);
     141             :         }
     142           0 :         *texture = driver->addRenderTargetTexture(
     143             :                         core::dimension2d<u32>(screensize.X, screensize.Y), name,
     144           0 :                         irr::video::ECF_A8R8G8B8);
     145           0 : }
     146             : 
     147           0 : video::ITexture* draw_image(const v2u32& screensize,
     148             :                 paralax_sign psign, const irr::core::matrix4& startMatrix,
     149             :                 const irr::core::vector3df& focusPoint, bool show_hud,
     150             :                 video::IVideoDriver* driver, Camera& camera, scene::ISceneManager* smgr,
     151             :                 Hud& hud, std::vector<aabb3f>& hilightboxes,
     152             :                 bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
     153             :                 video::SColor skycolor )
     154             : {
     155             :         static video::ITexture* images[2] = { NULL, NULL };
     156           0 :         static v2u32 last_screensize = v2u32(0,0);
     157             : 
     158           0 :         video::ITexture* image = NULL;
     159             : 
     160           0 :         if (screensize != last_screensize) {
     161           0 :                 init_texture(driver, screensize, &images[1], "mt_drawimage_img1");
     162           0 :                 init_texture(driver, screensize, &images[0], "mt_drawimage_img2");
     163           0 :                 last_screensize = screensize;
     164             :         }
     165             : 
     166           0 :         if (psign == RIGHT)
     167           0 :                 image = images[1];
     168             :         else
     169           0 :                 image = images[0];
     170             : 
     171           0 :         driver->setRenderTarget(image, true, true,
     172             :                         irr::video::SColor(255,
     173           0 :                                         skycolor.getRed(), skycolor.getGreen(), skycolor.getBlue()));
     174             : 
     175           0 :         irr::core::vector3df eye_pos;
     176           0 :         irr::core::matrix4 movement;
     177             :         movement.setTranslation(
     178             :                         irr::core::vector3df((int) psign *
     179           0 :                                         g_settings->getFloat("3d_paralax_strength"), 0.0f, 0.0f));
     180           0 :         eye_pos = (startMatrix * movement).getTranslation();
     181             : 
     182             :         //clear the depth buffer
     183           0 :         driver->clearZBuffer();
     184           0 :         camera.getCameraNode()->setPosition(eye_pos);
     185           0 :         camera.getCameraNode()->setTarget(focusPoint);
     186           0 :         smgr->drawAll();
     187             : 
     188           0 :         driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
     189             : 
     190           0 :         if (show_hud)
     191             :         {
     192           0 :                 draw_selectionbox(driver, hud, hilightboxes, show_hud);
     193             : 
     194           0 :                 if (draw_wield_tool)
     195           0 :                         camera.drawWieldedTool(&movement);
     196             :         }
     197             : 
     198           0 :         guienv->drawAll();
     199             : 
     200             :         /* switch back to real renderer */
     201           0 :         driver->setRenderTarget(0, true, true,
     202             :                         irr::video::SColor(0,
     203           0 :                                         skycolor.getRed(), skycolor.getGreen(), skycolor.getBlue()));
     204             : 
     205           0 :         return image;
     206             : }
     207             : 
     208           0 : video::ITexture*  draw_hud(video::IVideoDriver* driver, const v2u32& screensize,
     209             :                 bool show_hud, Hud& hud, Client& client, bool draw_crosshair,
     210             :                 video::SColor skycolor, gui::IGUIEnvironment* guienv, Camera& camera )
     211             : {
     212             :         static video::ITexture* image = NULL;
     213           0 :         init_texture(driver, screensize, &image, "mt_drawimage_hud");
     214           0 :         driver->setRenderTarget(image, true, true,
     215           0 :                         irr::video::SColor(255,0,0,0));
     216             : 
     217           0 :         if (show_hud)
     218             :         {
     219           0 :                 if (draw_crosshair)
     220           0 :                         hud.drawCrosshair();
     221           0 :                 hud.drawHotbar(client.getPlayerItem());
     222           0 :                 hud.drawLuaElements(camera.getOffset());
     223             : 
     224           0 :                 guienv->drawAll();
     225             :         }
     226             : 
     227           0 :         driver->setRenderTarget(0, true, true,
     228             :                         irr::video::SColor(0,
     229           0 :                                         skycolor.getRed(), skycolor.getGreen(), skycolor.getBlue()));
     230             : 
     231           0 :         return image;
     232             : }
     233             : 
     234           0 : void draw_interlaced_3d_mode(Camera& camera, bool show_hud,
     235             :                 Hud& hud, std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
     236             :                 scene::ISceneManager* smgr, const v2u32& screensize,
     237             :                 bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
     238             :                 video::SColor skycolor )
     239             : {
     240             :         /* save current info */
     241           0 :         irr::core::vector3df oldPosition = camera.getCameraNode()->getPosition();
     242           0 :         irr::core::vector3df oldTarget = camera.getCameraNode()->getTarget();
     243             :         irr::core::matrix4 startMatrix =
     244           0 :                         camera.getCameraNode()->getAbsoluteTransformation();
     245           0 :         irr::core::vector3df focusPoint = (camera.getCameraNode()->getTarget()
     246           0 :                         - camera.getCameraNode()->getAbsolutePosition()).setLength(1)
     247           0 :                         + camera.getCameraNode()->getAbsolutePosition();
     248             : 
     249             :         /* create left view */
     250           0 :         video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
     251             :                         focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
     252           0 :                         draw_wield_tool, client, guienv, skycolor);
     253             : 
     254             :         //Right eye...
     255           0 :         irr::core::vector3df rightEye;
     256           0 :         irr::core::matrix4 rightMove;
     257             :         rightMove.setTranslation(
     258             :                         irr::core::vector3df(g_settings->getFloat("3d_paralax_strength"),
     259           0 :                                         0.0f, 0.0f));
     260           0 :         rightEye = (startMatrix * rightMove).getTranslation();
     261             : 
     262             :         //clear the depth buffer
     263           0 :         driver->clearZBuffer();
     264           0 :         camera.getCameraNode()->setPosition(rightEye);
     265           0 :         camera.getCameraNode()->setTarget(focusPoint);
     266           0 :         smgr->drawAll();
     267             : 
     268           0 :         driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
     269             : 
     270           0 :         if (show_hud)
     271             :         {
     272           0 :                 draw_selectionbox(driver, hud, hilightboxes, show_hud);
     273             : 
     274           0 :                 if(draw_wield_tool)
     275           0 :                         camera.drawWieldedTool(&rightMove);
     276             :         }
     277           0 :         guienv->drawAll();
     278             : 
     279           0 :         for (unsigned int i = 0; i < screensize.Y; i+=2 ) {
     280             : #if (IRRLICHT_VERSION_MAJOR >= 1) && (IRRLICHT_VERSION_MINOR >= 8)
     281           0 :                 driver->draw2DImage(left_image, irr::core::position2d<s32>(0, i),
     282             : #else
     283             :                 driver->draw2DImage(left_image, irr::core::position2d<s32>(0, screensize.Y-i),
     284             : #endif
     285           0 :                                 irr::core::rect<s32>(0, i,screensize.X, i+1), 0,
     286             :                                 irr::video::SColor(255, 255, 255, 255),
     287           0 :                                 false);
     288             :         }
     289             : 
     290             :         /* cleanup */
     291           0 :         camera.getCameraNode()->setPosition(oldPosition);
     292           0 :         camera.getCameraNode()->setTarget(oldTarget);
     293           0 : }
     294             : 
     295           0 : void draw_sidebyside_3d_mode(Camera& camera, bool show_hud,
     296             :                 Hud& hud, std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
     297             :                 scene::ISceneManager* smgr, const v2u32& screensize,
     298             :                 bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
     299             :                 video::SColor skycolor )
     300             : {
     301             :         /* save current info */
     302           0 :         irr::core::vector3df oldPosition = camera.getCameraNode()->getPosition();
     303           0 :         irr::core::vector3df oldTarget = camera.getCameraNode()->getTarget();
     304             :         irr::core::matrix4 startMatrix =
     305           0 :                         camera.getCameraNode()->getAbsoluteTransformation();
     306           0 :         irr::core::vector3df focusPoint = (camera.getCameraNode()->getTarget()
     307           0 :                         - camera.getCameraNode()->getAbsolutePosition()).setLength(1)
     308           0 :                         + camera.getCameraNode()->getAbsolutePosition();
     309             : 
     310             :         /* create left view */
     311           0 :         video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
     312             :                         focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
     313           0 :                         draw_wield_tool, client, guienv, skycolor);
     314             : 
     315             :         /* create right view */
     316           0 :         video::ITexture* right_image = draw_image(screensize, RIGHT, startMatrix,
     317             :                         focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
     318           0 :                         draw_wield_tool, client, guienv, skycolor);
     319             : 
     320             :         /* create hud overlay */
     321           0 :         video::ITexture* hudtexture = draw_hud(driver, screensize, show_hud, hud, client,
     322           0 :                         false, skycolor, guienv, camera );
     323           0 :         driver->makeColorKeyTexture(hudtexture, irr::video::SColor(255, 0, 0, 0));
     324             :         //makeColorKeyTexture mirrors texture so we do it twice to get it right again
     325           0 :         driver->makeColorKeyTexture(hudtexture, irr::video::SColor(255, 0, 0, 0));
     326             : 
     327           0 :         draw2DImageFilterScaled(driver, left_image,
     328           0 :                         irr::core::rect<s32>(0, 0, screensize.X/2, screensize.Y),
     329           0 :                         irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, false);
     330             : 
     331           0 :         draw2DImageFilterScaled(driver, hudtexture,
     332           0 :                         irr::core::rect<s32>(0, 0, screensize.X/2, screensize.Y),
     333           0 :                         irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, true);
     334             : 
     335           0 :         draw2DImageFilterScaled(driver, right_image,
     336           0 :                         irr::core::rect<s32>(screensize.X/2, 0, screensize.X, screensize.Y),
     337           0 :                         irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, false);
     338             : 
     339           0 :         draw2DImageFilterScaled(driver, hudtexture,
     340           0 :                         irr::core::rect<s32>(screensize.X/2, 0, screensize.X, screensize.Y),
     341           0 :                         irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, true);
     342             : 
     343           0 :         left_image = NULL;
     344           0 :         right_image = NULL;
     345             : 
     346             :         /* cleanup */
     347           0 :         camera.getCameraNode()->setPosition(oldPosition);
     348           0 :         camera.getCameraNode()->setTarget(oldTarget);
     349           0 : }
     350             : 
     351           0 : void draw_top_bottom_3d_mode(Camera& camera, bool show_hud,
     352             :                 Hud& hud, std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
     353             :                 scene::ISceneManager* smgr, const v2u32& screensize,
     354             :                 bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
     355             :                 video::SColor skycolor )
     356             : {
     357             :         /* save current info */
     358           0 :         irr::core::vector3df oldPosition = camera.getCameraNode()->getPosition();
     359           0 :         irr::core::vector3df oldTarget = camera.getCameraNode()->getTarget();
     360             :         irr::core::matrix4 startMatrix =
     361           0 :                         camera.getCameraNode()->getAbsoluteTransformation();
     362           0 :         irr::core::vector3df focusPoint = (camera.getCameraNode()->getTarget()
     363           0 :                         - camera.getCameraNode()->getAbsolutePosition()).setLength(1)
     364           0 :                         + camera.getCameraNode()->getAbsolutePosition();
     365             : 
     366             :         /* create left view */
     367           0 :         video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
     368             :                         focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
     369           0 :                         draw_wield_tool, client, guienv, skycolor);
     370             : 
     371             :         /* create right view */
     372           0 :         video::ITexture* right_image = draw_image(screensize, RIGHT, startMatrix,
     373             :                         focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
     374           0 :                         draw_wield_tool, client, guienv, skycolor);
     375             : 
     376             :         /* create hud overlay */
     377           0 :         video::ITexture* hudtexture = draw_hud(driver, screensize, show_hud, hud, client,
     378           0 :                         false, skycolor, guienv, camera );
     379           0 :         driver->makeColorKeyTexture(hudtexture, irr::video::SColor(255, 0, 0, 0));
     380             :         //makeColorKeyTexture mirrors texture so we do it twice to get it right again
     381           0 :         driver->makeColorKeyTexture(hudtexture, irr::video::SColor(255, 0, 0, 0));
     382             : 
     383           0 :         draw2DImageFilterScaled(driver, left_image,
     384           0 :                         irr::core::rect<s32>(0, 0, screensize.X, screensize.Y/2),
     385           0 :                         irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, false);
     386             : 
     387           0 :         draw2DImageFilterScaled(driver, hudtexture,
     388           0 :                         irr::core::rect<s32>(0, 0, screensize.X, screensize.Y/2),
     389           0 :                         irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, true);
     390             : 
     391           0 :         draw2DImageFilterScaled(driver, right_image,
     392           0 :                         irr::core::rect<s32>(0, screensize.Y/2, screensize.X, screensize.Y),
     393           0 :                         irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, false);
     394             : 
     395           0 :         draw2DImageFilterScaled(driver, hudtexture,
     396           0 :                         irr::core::rect<s32>(0, screensize.Y/2, screensize.X, screensize.Y),
     397           0 :                         irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0, true);
     398             : 
     399           0 :         left_image = NULL;
     400           0 :         right_image = NULL;
     401             : 
     402             :         /* cleanup */
     403           0 :         camera.getCameraNode()->setPosition(oldPosition);
     404           0 :         camera.getCameraNode()->setTarget(oldTarget);
     405           0 : }
     406             : 
     407        1166 : void draw_plain(Camera& camera, bool show_hud, Hud& hud,
     408             :                 std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
     409             :                 bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv)
     410             : {
     411        1166 :         driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
     412             : 
     413        1166 :         draw_selectionbox(driver, hud, hilightboxes, show_hud);
     414             : 
     415        1166 :         if(draw_wield_tool)
     416        1166 :                 camera.drawWieldedTool();
     417        1166 : }
     418             : 
     419        1166 : void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
     420             :                 Camera &camera, Client& client, LocalPlayer *player, Hud &hud,
     421             :                 Mapper &mapper, gui::IGUIEnvironment *guienv,
     422             :                 std::vector<aabb3f> hilightboxes, const v2u32 &screensize,
     423             :                 video::SColor skycolor, bool show_hud, bool show_minimap)
     424             : {
     425        2332 :         TimeTaker timer("smgr");
     426             : 
     427        1166 :         bool draw_wield_tool = (show_hud &&
     428        2332 :                         (player->hud_flags & HUD_FLAG_WIELDITEM_VISIBLE) &&
     429        2332 :                         camera.getCameraMode() < CAMERA_MODE_THIRD );
     430             : 
     431        2332 :         bool draw_crosshair = ((player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE) &&
     432        2332 :                         (camera.getCameraMode() != CAMERA_MODE_THIRD_FRONT));
     433             : 
     434             : #ifdef HAVE_TOUCHSCREENGUI
     435             :         try {
     436             :                 draw_crosshair = !g_settings->getBool("touchtarget");
     437             :         }
     438             :         catch(SettingNotFoundException) {}
     439             : #endif
     440             : 
     441        2332 :         std::string draw_mode = g_settings->get("3d_mode");
     442             : 
     443        1166 :         smgr->drawAll();
     444             : 
     445        1166 :         if (draw_mode == "anaglyph")
     446             :         {
     447           0 :                 draw_anaglyph_3d_mode(camera, show_hud, hud, hilightboxes, driver,
     448           0 :                                 smgr, draw_wield_tool, client, guienv);
     449           0 :                 draw_crosshair = false;
     450             :         }
     451        1166 :         else if (draw_mode == "interlaced")
     452             :         {
     453           0 :                 draw_interlaced_3d_mode(camera, show_hud, hud, hilightboxes, driver,
     454           0 :                                 smgr, screensize, draw_wield_tool, client, guienv, skycolor);
     455           0 :                 draw_crosshair = false;
     456             :         }
     457        1166 :         else if (draw_mode == "sidebyside")
     458             :         {
     459           0 :                 draw_sidebyside_3d_mode(camera, show_hud, hud, hilightboxes, driver,
     460           0 :                                 smgr, screensize, draw_wield_tool, client, guienv, skycolor);
     461           0 :                 show_hud = false;
     462             :         }
     463        1166 :         else if (draw_mode == "topbottom")
     464             :         {
     465           0 :                 draw_top_bottom_3d_mode(camera, show_hud, hud, hilightboxes, driver,
     466           0 :                                 smgr, screensize, draw_wield_tool, client, guienv, skycolor);
     467           0 :                 show_hud = false;
     468             :         }
     469             :         else {
     470        2332 :                 draw_plain(camera, show_hud, hud, hilightboxes, driver,
     471        1166 :                                 draw_wield_tool, client, guienv);
     472             :         }
     473             : 
     474             :         /*
     475             :                 Post effects
     476             :         */
     477             :         {
     478        1166 :                 client.getEnv().getClientMap().renderPostFx(camera.getCameraMode());
     479             :         }
     480             : 
     481             :         //TODO how to make those 3d too
     482        1166 :         if (show_hud)
     483             :         {
     484        1166 :                 if (draw_crosshair)
     485        1166 :                         hud.drawCrosshair();
     486        1166 :                 hud.drawHotbar(client.getPlayerItem());
     487        1166 :                 hud.drawLuaElements(camera.getOffset());
     488        1166 :                 if (show_minimap)
     489        1166 :                         mapper.drawMinimap();
     490             :         }
     491             : 
     492        1166 :         guienv->drawAll();
     493             : 
     494        1166 :         timer.stop(true);
     495        1166 : }
     496             : 
     497             : /*
     498             :         Draws a screen with a single text on it.
     499             :         Text will be removed when the screen is drawn the next time.
     500             :         Additionally, a progressbar can be drawn when percent is set between 0 and 100.
     501             : */
     502          75 : void draw_load_screen(const std::wstring &text, IrrlichtDevice* device,
     503             :                 gui::IGUIEnvironment* guienv, float dtime, int percent, bool clouds )
     504             : {
     505          75 :         video::IVideoDriver* driver    = device->getVideoDriver();
     506          75 :         v2u32 screensize               = porting::getWindowSize();
     507             : 
     508          75 :         v2s32 textsize(g_fontengine->getTextWidth(text), g_fontengine->getLineHeight());
     509          75 :         v2s32 center(screensize.X / 2, screensize.Y / 2);
     510          75 :         core::rect<s32> textrect(center - textsize / 2, center + textsize / 2);
     511             : 
     512          75 :         gui::IGUIStaticText *guitext = guienv->addStaticText(
     513         150 :                         text.c_str(), textrect, false, false);
     514          75 :         guitext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
     515             : 
     516          75 :         bool cloud_menu_background = clouds && g_settings->getBool("menu_clouds");
     517          75 :         if (cloud_menu_background)
     518             :         {
     519          74 :                 g_menuclouds->step(dtime*3);
     520          74 :                 g_menuclouds->render();
     521          74 :                 driver->beginScene(true, true, video::SColor(255, 140, 186, 250));
     522          74 :                 g_menucloudsmgr->drawAll();
     523             :         }
     524             :         else
     525           1 :                 driver->beginScene(true, true, video::SColor(255, 0, 0, 0));
     526             : 
     527             :         // draw progress bar
     528          75 :         if ((percent >= 0) && (percent <= 100))
     529             :         {
     530             :                 v2s32 barsize(
     531             :                                 // 342 is (approximately) 256/0.75 to keep bar on same size as
     532             :                                 // before with default settings
     533         150 :                                 342 * porting::getDisplayDensity() *
     534         150 :                                 g_settings->getFloat("gui_scaling"),
     535         150 :                                 g_fontengine->getTextHeight() * 2);
     536             : 
     537          75 :                 core::rect<s32> barrect(center - barsize / 2, center + barsize / 2);
     538          75 :                 driver->draw2DRectangle(video::SColor(255, 255, 255, 255),barrect, NULL); // border
     539         150 :                 driver->draw2DRectangle(video::SColor(255, 64, 64, 64), core::rect<s32> (
     540         150 :                                 barrect.UpperLeftCorner + 1,
     541         225 :                                 barrect.LowerRightCorner-1), NULL); // black inside the bar
     542         375 :                 driver->draw2DRectangle(video::SColor(255, 128, 128, 128), core::rect<s32> (
     543         150 :                                 barrect.UpperLeftCorner + 1,
     544             :                                 core::vector2d<s32>(
     545         150 :                                                 barrect.LowerRightCorner.X -
     546         150 :                                                 (barsize.X - 1) + percent * (barsize.X - 2) / 100,
     547         150 :                                                 barrect.LowerRightCorner.Y - 1)), NULL); // the actual progress
     548             :         }
     549          75 :         guienv->drawAll();
     550          75 :         driver->endScene();
     551             : 
     552          75 :         guitext->remove();
     553             : 
     554             :         //return guitext;
     555          78 : }

Generated by: LCOV version 1.11