]> git.lizzy.rs Git - minetest.git/blobdiff - src/game.cpp
changed water color in farmesh
[minetest.git] / src / game.cpp
index e8e6cb71f042f6364e6e2da0f7300346a39a5ebc..59f14d37dc0126eb5941a03d3f54195e2b0484b2 100644 (file)
@@ -25,11 +25,19 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "guiPasswordChange.h"
 #include "guiInventoryMenu.h"
 #include "guiTextInputMenu.h"
-#include "guiFurnaceMenu.h"
 #include "materials.h"
 #include "config.h"
 #include "clouds.h"
 #include "keycode.h"
+#include "farmesh.h"
+#include "mapblock.h"
+
+/*
+       TODO: Move content-aware stuff to separate file by adding properties
+             and virtual interfaces
+*/
+#include "content_mapnode.h"
+#include "content_nodemeta.h"
 
 /*
        Setting this to 1 enables a special camera mode that forces
@@ -358,7 +366,7 @@ void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,
                                core::rect<s32>(core::position2d<s32>(0,0),
                                core::dimension2di(heart_texture->getOriginalSize())),
                                NULL, colors, true);
-                       p += v2s32(20,0);
+                       p += v2s32(16,0);
                }
                if(halfheartcount % 2 == 1)
                {
@@ -371,7 +379,7 @@ void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,
                        driver->draw2DImage(heart_texture, rect,
                                core::rect<s32>(core::position2d<s32>(0,0), srcd),
                                NULL, colors, true);
-                       p += v2s32(20,0);
+                       p += v2s32(16,0);
                }
        }
 }
@@ -595,6 +603,10 @@ void update_skybox(video::IVideoDriver* driver,
                skybox->remove();
        }
        
+       /*// Disable skybox if FarMesh is enabled
+       if(g_settings.getBool("enable_farmesh"))
+               return;*/
+       
        if(brightness >= 0.5)
        {
                skybox = smgr->addSkyBoxSceneNode(
@@ -649,7 +661,9 @@ void the_game(
        screensize = driver->getScreenSize();
 
        const s32 hotbar_itemcount = 8;
-       const s32 hotbar_imagesize = 36;
+       //const s32 hotbar_imagesize = 36;
+       //const s32 hotbar_imagesize = 64;
+       s32 hotbar_imagesize = 48;
        
        // The color of the sky
 
@@ -815,8 +829,21 @@ void the_game(
        
        float cloud_height = BS*100;
        Clouds *clouds = NULL;
-       clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1,
-                       cloud_height, time(0));
+       if(g_settings.getBool("enable_clouds"))
+       {
+               clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1,
+                               cloud_height, time(0));
+       }
+       
+       /*
+               FarMesh
+       */
+
+       FarMesh *farmesh = NULL;
+       if(g_settings.getBool("enable_farmesh"))
+       {
+               farmesh = new FarMesh(smgr->getRootSceneNode(), smgr, -1, client.getMapSeed(), &client);
+       }
 
        /*
                Move into game
@@ -850,8 +877,8 @@ void the_game(
        gui::IGUIStaticText *guitext_chat = guienv->addStaticText(
                        L"",
                        core::rect<s32>(0,0,0,0),
-                       false, false); // Disable word wrap as of now
-                       //false, true);
+                       //false, false); // Disable word wrap as of now
+                       false, true);
        //guitext_chat->setBackgroundColor(video::SColor(96,0,0,0));
        core::list<ChatLine> chat_lines;
        
@@ -894,6 +921,7 @@ void the_game(
        core::list<float> frametime_log;
 
        float damage_flash_timer = 0;
+       s16 farmesh_range = 20*MAP_BLOCKSIZE;
        
        bool invert_mouse = g_settings.getBool("invert_mouse");
 
@@ -914,6 +942,8 @@ void the_game(
 
        while(device->run() && kill == false)
        {
+               //std::cerr<<"frame"<<std::endl;
+
                if(g_gamecallback->disconnect_requested)
                {
                        g_gamecallback->disconnect_requested = false;
@@ -939,6 +969,14 @@ void the_game(
                screensize = driver->getScreenSize();
                v2s32 displaycenter(screensize.X/2,screensize.Y/2);
                //bool screensize_changed = screensize != last_screensize;
+
+               // Resize hotbar
+               if(screensize.Y <= 600)
+                       hotbar_imagesize = 32;
+               else if(screensize.Y <= 1024)
+                       hotbar_imagesize = 48;
+               else
+                       hotbar_imagesize = 64;
                
                // Hilight boxes collected during the loop and displayed
                core::list< core::aabbox3d<f32> > hilightboxes;
@@ -1169,6 +1207,45 @@ void the_game(
                                        &g_menumgr, dest,
                                        L""))->drop();
                }
+               else if(input->wasKeyDown(getKeySetting("keymap_freemove")))
+               {
+                       if(g_settings.getBool("free_move"))
+                       {
+                               g_settings.set("free_move","false");
+                               chat_lines.push_back(ChatLine(L"free_move disabled"));
+                       }
+                       else
+                       {
+                               g_settings.set("free_move","true");
+                               chat_lines.push_back(ChatLine(L"free_move enabled"));
+                       }
+               }
+               else if(input->wasKeyDown(getKeySetting("keymap_fastmove")))
+               {
+                       if(g_settings.getBool("fast_move"))
+                       {
+                               g_settings.set("fast_move","false");
+                               chat_lines.push_back(ChatLine(L"fast_move disabled"));
+                       }
+                       else
+                       {
+                               g_settings.set("fast_move","true");
+                               chat_lines.push_back(ChatLine(L"fast_move enabled"));
+                       }
+               }
+               else if(input->wasKeyDown(getKeySetting("keymap_frametime_graph")))
+               {
+                       if(g_settings.getBool("frametime_graph"))
+                       {
+                               g_settings.set("frametime_graph","false");
+                               chat_lines.push_back(ChatLine(L"frametime_graph disabled"));
+                       }
+                       else
+                       {
+                               g_settings.set("frametime_graph","true");
+                               chat_lines.push_back(ChatLine(L"frametime_graph enabled"));
+                       }
+               }
 
                // Item selection with mouse wheel
                {
@@ -1318,7 +1395,11 @@ void the_game(
                if((device->isWindowActive() && noMenuActive()) || random_input)
                {
                        if(!random_input)
-                               device->getCursorControl()->setVisible(false);
+                       {
+                               // Mac OSX gets upset if this is set every frame
+                               if(device->getCursorControl()->isVisible())
+                                       device->getCursorControl()->setVisible(false);
+                       }
 
                        if(first_loop_after_window_activation){
                                //std::cout<<"window active, first loop"<<std::endl;
@@ -1349,7 +1430,9 @@ void the_game(
                        input->setMousePos(displaycenter.X, displaycenter.Y);
                }
                else{
-                       device->getCursorControl()->setVisible(true);
+                       // Mac OSX gets upset if this is set every frame
+                       if(device->getCursorControl()->isVisible() == false)
+                               device->getCursorControl()->setVisible(true);
 
                        //std::cout<<"window inactive"<<std::endl;
                        first_loop_after_window_activation = true;
@@ -1661,67 +1744,56 @@ void the_game(
                        {
                                std::cout<<DTIME<<"Ground right-clicked"<<std::endl;
                                
-                               if(meta && meta->typeId() == CONTENT_SIGN_WALL && !random_input)
+                               // If metadata provides an inventory view, activate it
+                               if(meta && meta->getInventoryDrawSpecString() != "" && !random_input)
                                {
-                                       dstream<<"Sign node right-clicked"<<std::endl;
-                                       
-                                       SignNodeMetadata *signmeta = (SignNodeMetadata*)meta;
+                                       dstream<<DTIME<<"Launching custom inventory view"<<std::endl;
+                                       /*
+                                               Construct the unique identification string of the node
+                                       */
+                                       std::string current_name;
+                                       current_name += "nodemeta:";
+                                       current_name += itos(nodepos.X);
+                                       current_name += ",";
+                                       current_name += itos(nodepos.Y);
+                                       current_name += ",";
+                                       current_name += itos(nodepos.Z);
                                        
-                                       // Get a new text for it
+                                       /*
+                                               Create menu
+                                       */
 
-                                       TextDest *dest = new TextDestSignNode(nodepos, &client);
-
-                                       std::wstring wtext =
-                                                       narrow_to_wide(signmeta->getText());
+                                       core::array<GUIInventoryMenu::DrawSpec> draw_spec;
+                                       v2s16 invsize =
+                                               GUIInventoryMenu::makeDrawSpecArrayFromString(
+                                                       draw_spec,
+                                                       meta->getInventoryDrawSpecString(),
+                                                       current_name);
 
-                                       (new GUITextInputMenu(guienv, guiroot, -1,
-                                                       &g_menumgr, dest,
-                                                       wtext))->drop();
-                               }
-                               else if(meta && meta->typeId() == CONTENT_CHEST && !random_input)
-                               {
-                                       dstream<<"Chest node right-clicked"<<std::endl;
-                                       
-                                       //ChestNodeMetadata *chestmeta = (ChestNodeMetadata*)meta;
-
-                                       std::string chest_inv_id;
-                                       chest_inv_id += "nodemeta:";
-                                       chest_inv_id += itos(nodepos.X);
-                                       chest_inv_id += ",";
-                                       chest_inv_id += itos(nodepos.Y);
-                                       chest_inv_id += ",";
-                                       chest_inv_id += itos(nodepos.Z);
-                                       
                                        GUIInventoryMenu *menu =
                                                new GUIInventoryMenu(guienv, guiroot, -1,
-                                                       &g_menumgr, v2s16(8,9),
+                                                       &g_menumgr, invsize,
                                                        client.getInventoryContext(),
                                                        &client);
-
-                                       core::array<GUIInventoryMenu::DrawSpec> draw_spec;
-                                       
-                                       draw_spec.push_back(GUIInventoryMenu::DrawSpec(
-                                                       "list", chest_inv_id, "0",
-                                                       v2s32(0, 0), v2s32(8, 4)));
-                                       draw_spec.push_back(GUIInventoryMenu::DrawSpec(
-                                                       "list", "current_player", "main",
-                                                       v2s32(0, 5), v2s32(8, 4)));
-
                                        menu->setDrawSpec(draw_spec);
-
                                        menu->drop();
-
                                }
-                               else if(meta && meta->typeId() == CONTENT_FURNACE && !random_input)
+                               else if(meta && meta->typeId() == CONTENT_SIGN_WALL && !random_input)
                                {
-                                       dstream<<"Furnace node right-clicked"<<std::endl;
+                                       dstream<<"Sign node right-clicked"<<std::endl;
                                        
-                                       GUIFurnaceMenu *menu =
-                                               new GUIFurnaceMenu(guienv, guiroot, -1,
-                                                       &g_menumgr, nodepos, &client);
+                                       SignNodeMetadata *signmeta = (SignNodeMetadata*)meta;
+                                       
+                                       // Get a new text for it
 
-                                       menu->drop();
+                                       TextDest *dest = new TextDestSignNode(nodepos, &client);
+
+                                       std::wstring wtext =
+                                                       narrow_to_wide(signmeta->getText());
 
+                                       (new GUITextInputMenu(guienv, guiroot, -1,
+                                                       &g_menumgr, dest,
+                                                       wtext))->drop();
                                }
                                else
                                {
@@ -1789,6 +1861,22 @@ void the_game(
                                        0.05+brightness*0.95);
                }
                
+               /*
+                       Update farmesh
+               */
+               if(farmesh)
+               {
+                       farmesh_range = draw_control.wanted_range * 10;
+                       if(draw_control.range_all && farmesh_range < 500)
+                               farmesh_range = 500;
+                       if(farmesh_range > 1000)
+                               farmesh_range = 1000;
+
+                       farmesh->step(dtime);
+                       farmesh->update(v2f(player_position.X, player_position.Z),
+                                       0.05+brightness*0.95, farmesh_range);
+               }
+               
                // Store brightness value
                old_brightness = brightness;
 
@@ -1798,11 +1886,19 @@ void the_game(
                
                if(g_settings.getBool("enable_fog") == true)
                {
-                       f32 range = draw_control.wanted_range*BS + MAP_BLOCKSIZE*BS*1.5;
-                       if(draw_control.range_all)
-                               range = 100000*BS;
-                       if(range < 50*BS)
-                               range = range * 0.5 + 25*BS;
+                       f32 range;
+                       if(farmesh)
+                       {
+                               range = BS*farmesh_range;
+                       }
+                       else
+                       {
+                               range = draw_control.wanted_range*BS + MAP_BLOCKSIZE*BS*1.5;
+                               if(draw_control.range_all)
+                                       range = 100000*BS;
+                               if(range < 50*BS)
+                                       range = range * 0.5 + 25*BS;
+                       }
 
                        driver->setFog(
                                bgcolor,
@@ -1950,7 +2046,7 @@ void the_game(
                                        10,
                                        50,
                                        screensize.X - 10,
-                                       50 + text_height*chat_lines.size()
+                                       50 + guitext_chat->getTextHeight()
                        );
 
                        guitext_chat->setRelativePosition(rect);
@@ -1999,7 +2095,7 @@ void the_game(
                        //driver->beginScene(false, true, bgcolor);
                        beginscenetime = timer.stop(true);
                }
-
+               
                //timer3.stop();
                
                //std::cout<<DTIME<<"smgr->drawAll()"<<std::endl;
@@ -2131,7 +2227,8 @@ void the_game(
        /*
                Drop stuff
        */
-       clouds->drop();
+       if(clouds)
+               clouds->drop();
        
        /*
                Draw a "shutting down" screen, which will be shown while the map