]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/drawscene.cpp
Fix crash regression when chatting in the ncurses console
[dragonfireclient.git] / src / drawscene.cpp
index c716ca0d4093982d91d72ee0e312aab9f62246ee..c6abda4ac135b28efb588396a144ae5471c32437 100644 (file)
@@ -31,27 +31,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 )
 {
 
@@ -85,10 +67,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);
        }
@@ -115,10 +95,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);
        }
@@ -144,16 +122,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;
 
@@ -187,10 +164,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);
        }
@@ -220,7 +195,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();
        }
 
@@ -232,7 +207,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 )
@@ -248,7 +223,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...
@@ -267,10 +242,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);
        }
@@ -293,7 +266,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 )
@@ -309,12 +282,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 */
@@ -349,7 +322,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 )
@@ -365,12 +338,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,7 +378,7 @@ void draw_top_bottom_3d_mode(Camera& camera, bool show_hud,
 }
 
 void draw_pageflip_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)
@@ -438,13 +411,12 @@ void draw_pageflip_3d_mode(Camera& camera, bool show_hud,
        driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
 
        if (show_hud) {
-               draw_selectionbox(driver, hud, hilightboxes, show_hud);
-
+               hud.drawSelectionMesh();
                if (draw_wield_tool)
                        camera.drawWieldedTool(&leftMove);
-
                hud.drawHotbar(client.getPlayerItem());
                hud.drawLuaElements(camera.getOffset());
+               camera.drawNametags();
        }
 
        guienv->drawAll();
@@ -467,13 +439,12 @@ void draw_pageflip_3d_mode(Camera& camera, bool show_hud,
        driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
 
        if (show_hud) {
-               draw_selectionbox(driver, hud, hilightboxes, show_hud);
-
+               hud.drawSelectionMesh();
                if (draw_wield_tool)
                        camera.drawWieldedTool(&rightMove);
-
                hud.drawHotbar(client.getPlayerItem());
                hud.drawLuaElements(camera.getOffset());
+               camera.drawNametags();
        }
 
        guienv->drawAll();
@@ -482,23 +453,24 @@ void draw_pageflip_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_plain(Camera &camera, bool show_hud, Hud &hud,
+               video::IVideoDriver *driver, bool draw_wield_tool,
+               Client &client, gui::IGUIEnvironment *guienv)
 {
        driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
-
-       draw_selectionbox(driver, hud, hilightboxes, show_hud);
-
-       if(draw_wield_tool)
-               camera.drawWieldedTool();
+       if (show_hud) {
+               hud.drawSelectionMesh();
+               if (draw_wield_tool) {
+                       camera.drawWieldedTool();
+               }
+       }
 }
 
 void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
                Camera &camera, Client& client, LocalPlayer *player, Hud &hud,
                Mapper &mapper, gui::IGUIEnvironment *guienv,
-               std::vector<aabb3f> hilightboxes, const v2u32 &screensize,
-               video::SColor skycolor, bool show_hud, bool show_minimap)
+               const v2u32 &screensize, const video::SColor &skycolor,
+               bool show_hud, bool show_minimap)
 {
        TimeTaker timer("smgr");
 
@@ -522,37 +494,37 @@ void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
 
        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, hilightboxes, driver,
+               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_plain(camera, show_hud, hud, driver,
                                draw_wield_tool, client, guienv);
        }
 
@@ -568,8 +540,11 @@ 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();
        }