]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/main.cpp
Mapgen is better now. Not a lot, but a bit!
[dragonfireclient.git] / src / main.cpp
index 1f8091a7f9baf730af55acf8e3c7736cbb23b572..fb1b2d8fd9a80d00f4c6d0f59a41279d144a1425 100644 (file)
@@ -28,6 +28,9 @@ NOTE: VBO cannot be turned on for fast-changing stuff because there
 NOTE: iostream.imbue(std::locale("C")) is very slow\r
 NOTE: Global locale is now set at initialization\r
 \r
+Random suggeestions:\r
+--------------------\r
+\r
 SUGG: Fix address to be ipv6 compatible\r
 \r
 NOTE: When a new sector is generated, it may change the ground level\r
@@ -116,11 +119,6 @@ Gaming ideas:
 Build system / running:\r
 -----------------------\r
 \r
-FIXME: Some network errors on Windows that cause local game to not work\r
-       - See siggjen's emails.\r
-          - Is this the famous "windows 7 problem"?\r
-       - Apparently there might be other errors too\r
-\r
 Networking and serialization:\r
 -----------------------------\r
 \r
@@ -160,66 +158,53 @@ TODO: Make fetching sector's blocks more efficient when rendering
 \r
 TODO: Flowing water animation\r
 \r
-NOTE(FIXED): A lock condition is possible:\r
-       1) MapBlock::updateMesh() is called from client asynchronously:\r
-          - AsyncProcessData() -> Map::updateMeshes()\r
-       2) Asynchronous locks m_temp_mods_mutex\r
-       3) MapBlock::updateMesh() is called from client synchronously:\r
-          - Client::step() -> Environment::step()\r
-       4) Synchronous starts waiting for m_temp_mods_mutex\r
-       5) Asynchronous calls getTexture, which starts waiting for main thread\r
+* Combine meshes to bigger ones in ClientMap and set them EHM_STATIC\r
+\r
+SUGG: Draw cubes in inventory directly with 3D drawing commands, so that\r
+      animating them is easier.\r
 \r
 Configuration:\r
 --------------\r
 \r
-TODO: Make the video backend selectable\r
-\r
 Client:\r
 -------\r
 \r
 TODO: Untie client network operations from framerate\r
       - Needs some input queues or something\r
 \r
-TODO: Make morning and evening transition more smooth and maybe shorter\r
+SUGG: Make morning and evening transition more smooth and maybe shorter\r
 \r
-TODO: Don't update all meshes always on single node changes, but\r
+SUGG: Don't update all meshes always on single node changes, but\r
       check which ones should be updated\r
          - implement Map::updateNodeMeshes()\r
 \r
+TODO: Remove IrrlichtWrapper\r
+\r
 Server:\r
 -------\r
 \r
 TODO: When player dies, throw items on map\r
 \r
-TODO: Make an option to the server to disable building and digging near\r
+SUGG: Make an option to the server to disable building and digging near\r
       the starting position\r
 \r
-TODO: Save players with inventories to disk\r
-TODO: Players to be saved as text in map/players/<name>\r
-\r
 TODO: Copy the text of the last picked sign to inventory in creative\r
       mode\r
 \r
 TODO: Check what goes wrong with caching map to disk (Kray)\r
       - Nothing?\r
 \r
-TODO: When server sees that client is removing an inexistent block to\r
-      an existent position, resend the MapBlock.\r
+FIXME: Server sometimes goes into some infinite PeerNotFoundException loop\r
 \r
-FIXME: Server went into some infinite PeerNotFoundException loop\r
+* Fix the problem with the server constantly saving one or a few\r
+  blocks? List the first saved block, maybe it explains.\r
+  - It is probably caused by oscillating water\r
+* Make a small history check to transformLiquids to detect and log\r
+  continuous oscillations, in such detail that they can be fixed.\r
 \r
 Objects:\r
 --------\r
 \r
-TODO: Better handling of objects and mobs\r
-      - Scripting?\r
-      - There has to be some way to do it with less messy code\r
-         - Make separate classes for client and server\r
-           - Client should not discriminate between blocks, server should\r
-           - Make other players utilize the same framework\r
-               - This is also needed for objects that don't get sent to client\r
-                 but are used for triggers etc\r
-\r
 TODO: There has to be some better way to handle static objects than to\r
       send them all the time. This affects signs and item objects.\r
 SUGG: Signs could be done in the same way as torches. For this, blocks\r
@@ -237,6 +222,20 @@ Block object server side:
            - TODO: For incoming blocks, time difference is calculated and\r
              objects are stepped according to it.\r
 \r
+- When an active object goes far from a player, either delete\r
+  it or store it statically.\r
+- When a statically stored active object comes near a player,\r
+  recreate the active object\r
+\r
+* Continue making the scripting system:\r
+  * Make updateNodeMesh for a less verbose mesh update on add/removenode\r
+  * Switch to using a safe way for the self and env pointers\r
+  * Make some global environment hooks, like node placed and general\r
+    on_step()\r
+* Add a global Lua spawn handler and such\r
+* Get rid of MapBlockObjects\r
+* Other players could be sent to clients as LuaCAOs\r
+\r
 Map:\r
 ----\r
 \r
@@ -246,9 +245,6 @@ TODO: Mineral and ground material properties
 \r
 TODO: Flowing water to actually contain flow direction information\r
 \r
-TODO: Remove duplicate lighting implementation from Map (leave\r
-      VoxelManipulator, which is faster)\r
-\r
 FEATURE: Create a system that allows a huge amount of different "map\r
             generator modules/filters"\r
 \r
@@ -263,49 +259,58 @@ FEATURE: Erosion simulation at map generation time
                - Simulate rock falling from cliffs when water has removed\r
                  enough solid rock from the bottom\r
 \r
-Doing now (most important at the top):\r
---------------------------------------\r
-# maybe done\r
-* not done\r
-\r
-=== Stuff to do before release\r
-* Make server find the spawning place from the real map data, not from\r
-  the heightmap\r
-  - But the changing borders of chunk have to be avoided, because\r
-    there is time to generate only one chunk.\r
+Mapgen v2 (not doing):\r
+* only_from_disk might not work anymore - check and fix it.\r
 * Make the generator to run in background and not blocking block\r
   placement and transfer\r
-* only_from_disk might not work anymore - check and fix it.\r
-* Check the fixmes in the list above\r
-* FIXME: Sneaking doesn't switch sneak node when moving sideways\r
-\r
-=== Making it more portable\r
-* Some MSVC: std::sto* are defined without a namespace and collide\r
-  with the ones in utility.h\r
-* On Kray's machine, the new find_library(XXF86VM_LIBRARY, Xxf86vm)\r
-  line doesn't find the library.\r
-\r
-=== Stuff to do after release\r
-* Make an "environment metafile" to store at least time of day\r
-* Move digging property stuff from material.{h,cpp} to mapnode.cpp...\r
-  - Or maybe move content_features to material.{h,cpp}?\r
 * Add some kind of erosion and other stuff that now is possible\r
 * Make client to fetch stuff asynchronously\r
   - Needs method SyncProcessData\r
-* Fix the problem with the server constantly saving one or a few\r
-  blocks? List the first saved block, maybe it explains.\r
-  - It is probably caused by oscillating water\r
-* Water doesn't start flowing after map generation like it should\r
-  - Are there still problems?\r
 * Better water generation (spread it to underwater caverns but don't\r
   fill dungeons that don't touch big water masses)\r
 * When generating a chunk and the neighboring chunk doesn't have mud\r
   and stuff yet and the ground is fairly flat, the mud will flow to\r
   the other chunk making nasty straight walls when the other chunk\r
   is generated. Fix it.\r
-* Make a small history check to transformLiquids to detect and log\r
-  continuous oscillations, in such detail that they can be fixed.\r
-* Combine meshes to bigger ones in ClientMap and set them EHM_STATIC\r
+\r
+Mapgen v4 (not doing):\r
+* only_from_disk might not work anymore - check and fix it.\r
+* Make the generator to run in background and not blocking block\r
+  placement and transfer\r
+* Make chunks to be tiled vertically too\r
+* MAKE IT FASTER\r
+\r
+Mapgen v3 (not doing):\r
+* Generate trees better\r
+  - Add a "trees_added" flag to sector, or something\r
+* How 'bout making turbulence controlled so that for a given 2d position\r
+  it can be completely turned off, and is usually so. This way generation\r
+  can be sped up a lot.\r
+* Add a way to generate a block partly, so that trees are not added, like\r
+  the chunks in v2\r
+* Add mud "discretely", not by guessing from the noise\r
+\r
+Mapgen v4:\r
+* This will be the final way.\r
+* Generate blocks in the same way as chunks, by copying a VoxelManipulator\r
+  from the map that is one block larger in all directions.\r
+\r
+Misc. stuff:\r
+------------\r
+* Make an "environment metafile" to store at least time of day\r
+* Move digging property stuff from material.{h,cpp} to mapnode.cpp...\r
+  - Or maybe move content_features to material.{h,cpp}?\r
+* Maybe:\r
+  Make a system for pregenerating quick information for mapblocks, so\r
+  that the client can show them as cubes before they are actually sent\r
+  or even generated.\r
+* Optimize VoxelManipulator lighting implementation by using indices\r
+  in place of coordinates?\r
+\r
+Making it more portable:\r
+------------------------\r
+* Some MSVC: std::sto* are defined without a namespace and collide\r
+  with the ones in utility.h\r
 \r
 ======================================================================\r
 \r
@@ -347,18 +352,18 @@ Doing now (most important at the top):
 #include <fstream>\r
 #include <jmutexautolock.h>\r
 #include <locale.h>\r
+#include "main.h"\r
 #include "common_irrlicht.h"\r
 #include "debug.h"\r
 #include "map.h"\r
 #include "player.h"\r
-#include "main.h"\r
 #include "test.h"\r
-#include "environment.h"\r
+//#include "environment.h"\r
 #include "server.h"\r
 #include "client.h"\r
-#include "serialization.h"\r
+//#include "serialization.h"\r
 #include "constants.h"\r
-#include "strfnd.h"\r
+//#include "strfnd.h"\r
 #include "porting.h"\r
 #include "irrlichtwrapper.h"\r
 #include "gettime.h"\r
@@ -399,11 +404,14 @@ extern void set_default_settings();
 IrrlichtDevice *g_device = NULL;\r
 Client *g_client = NULL;\r
 \r
-//const s16 quickinv_size = 48;\r
-//const s16 quickinv_spacing = 64;\r
-const s16 quickinv_size = 32;\r
-const s16 quickinv_spacing = 40;\r
-const s16 quickinv_itemcount = 8;\r
+/*const s16 quickinv_size = 40;\r
+const s16 quickinv_padding = 8;\r
+const s16 quickinv_spacing = quickinv_size + quickinv_padding;\r
+const s16 quickinv_outer_padding = 4;\r
+const s16 quickinv_itemcount = 8;*/\r
+\r
+const s32 hotbar_itemcount = 8;\r
+const s32 hotbar_imagesize = 36;\r
 \r
 /*\r
        GUI Stuff\r
@@ -496,6 +504,9 @@ Inventory local_inventory;
 \r
 u16 g_selected_item = 0;\r
 \r
+bool g_show_map_plot = false;\r
+bool g_refresh_map_plot = false;\r
+\r
 /*\r
        Debug streams\r
 */\r
@@ -564,7 +575,25 @@ struct TextDestChat : public TextDest
        }\r
        void gotText(std::wstring text)\r
        {\r
+               // Discard empty line\r
+               if(text == L"")\r
+                       return;\r
+               \r
+               // Parse command (server command starts with "/#")\r
+               if(text[0] == L'/' && text[1] != L'#')\r
+               {\r
+                       std::wstring reply = L"Local: ";\r
+\r
+                       reply += L"Local commands not yet supported. "\r
+                                       L"Server prefix is \"/#\".";\r
+                       \r
+                       m_client->addChatMessage(reply);\r
+                       return;\r
+               }\r
+\r
+               // Send to others\r
                m_client->sendChatMessage(text);\r
+               // Show locally\r
                m_client->addChatMessage(text);\r
        }\r
 \r
@@ -594,6 +623,15 @@ class MyEventReceiver : public IEventReceiver
                        if(event.KeyInput.PressedDown)\r
                        {\r
                                //dstream<<"Pressed key: "<<(char)event.KeyInput.Key<<std::endl;\r
+                               if(g_show_map_plot)\r
+                               {\r
+                                       if(event.KeyInput.Key == irr::KEY_ESCAPE\r
+                                               || event.KeyInput.Key == irr::KEY_KEY_M)\r
+                                       {\r
+                                               g_show_map_plot = false;\r
+                                       }\r
+                                       return true;\r
+                               }\r
                                \r
                                /*\r
                                        Launch menus\r
@@ -629,24 +667,14 @@ class MyEventReceiver : public IEventReceiver
                                        }\r
                                }\r
 \r
-                               // Material selection\r
-                               /*if(event.KeyInput.Key == irr::KEY_KEY_F)\r
-                               {\r
-                                       if(g_selected_item < PLAYER_INVENTORY_SIZE-1)\r
-                                               g_selected_item++;\r
-                                       else\r
-                                               g_selected_item = 0;\r
-                                       dstream<<DTIME<<"Selected item: "\r
-                                                       <<g_selected_item<<std::endl;\r
-                               }*/\r
-\r
+                               // Item selection\r
                                if(event.KeyInput.Key >= irr::KEY_KEY_0\r
                                                && event.KeyInput.Key <= irr::KEY_KEY_9)\r
                                {\r
                                        u16 s1 = event.KeyInput.Key - irr::KEY_KEY_0;\r
                                        if(event.KeyInput.Key == irr::KEY_KEY_0)\r
                                                s1 = 10;\r
-                                       if(s1 < PLAYER_INVENTORY_SIZE)\r
+                                       if(s1 < PLAYER_INVENTORY_SIZE && s1 < hotbar_itemcount)\r
                                                g_selected_item = s1-1;\r
                                        dstream<<DTIME<<"Selected item: "\r
                                                        <<g_selected_item<<std::endl;\r
@@ -677,6 +705,16 @@ class MyEventReceiver : public IEventReceiver
                                                        <<std::endl;\r
                                        debug_stacks_print();\r
                                }\r
+\r
+                               // Map plot\r
+                               if(event.KeyInput.Key == irr::KEY_KEY_M)\r
+                               {\r
+                                       dstream<<"Map plot requested"<<std::endl;\r
+                                       g_show_map_plot = !g_show_map_plot;\r
+                                       if(g_show_map_plot)\r
+                                               g_refresh_map_plot = true;\r
+                               }\r
+                               \r
                        }\r
                }\r
 \r
@@ -715,9 +753,12 @@ class MyEventReceiver : public IEventReceiver
                                {\r
                                        /*dstream<<"event.MouseInput.Wheel="\r
                                                        <<event.MouseInput.Wheel<<std::endl;*/\r
+                                       \r
+                                       u16 max_item = MYMIN(PLAYER_INVENTORY_SIZE-1,\r
+                                                       hotbar_itemcount-1);\r
                                        if(event.MouseInput.Wheel < 0)\r
                                        {\r
-                                               if(g_selected_item < PLAYER_INVENTORY_SIZE-1)\r
+                                               if(g_selected_item < max_item)\r
                                                        g_selected_item++;\r
                                                else\r
                                                        g_selected_item = 0;\r
@@ -727,7 +768,7 @@ class MyEventReceiver : public IEventReceiver
                                                if(g_selected_item > 0)\r
                                                        g_selected_item--;\r
                                                else\r
-                                                       g_selected_item = PLAYER_INVENTORY_SIZE-1;\r
+                                                       g_selected_item = max_item;\r
                                        }\r
                                }\r
                        }\r
@@ -893,8 +934,12 @@ class RandomInputHandler : public InputHandler
 public:\r
        RandomInputHandler()\r
        {\r
+               leftdown = false;\r
+               rightdown = false;\r
                leftclicked = false;\r
                rightclicked = false;\r
+               leftreleased = false;\r
+               rightreleased = false;\r
                for(u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)\r
                        keydown[i] = false;\r
        }\r
@@ -913,11 +958,11 @@ class RandomInputHandler : public InputHandler
 \r
        virtual bool getLeftState()\r
        {\r
-               return false;\r
+               return leftdown;\r
        }\r
        virtual bool getRightState()\r
        {\r
-               return false;\r
+               return rightdown;\r
        }\r
 \r
        virtual bool getLeftClicked()\r
@@ -939,37 +984,23 @@ class RandomInputHandler : public InputHandler
 \r
        virtual bool getLeftReleased()\r
        {\r
-               return false;\r
+               return leftreleased;\r
        }\r
        virtual bool getRightReleased()\r
        {\r
-               return false;\r
+               return rightreleased;\r
        }\r
        virtual void resetLeftReleased()\r
        {\r
+               leftreleased = false;\r
        }\r
        virtual void resetRightReleased()\r
        {\r
+               rightreleased = false;\r
        }\r
 \r
        virtual void step(float dtime)\r
        {\r
-               {\r
-                       static float counter1 = 0;\r
-                       counter1 -= dtime;\r
-                       if(counter1 < 0.0)\r
-                       {\r
-                               counter1 = 0.1*Rand(1,10);\r
-                               /*if(g_selected_material < USEFUL_CONTENT_COUNT-1)\r
-                                       g_selected_material++;\r
-                               else\r
-                                       g_selected_material = 0;*/\r
-                               if(g_selected_item < PLAYER_INVENTORY_SIZE-1)\r
-                                       g_selected_item++;\r
-                               else\r
-                                       g_selected_item = 0;\r
-                       }\r
-               }\r
                {\r
                        static float counter1 = 0;\r
                        counter1 -= dtime;\r
@@ -1021,7 +1052,11 @@ class RandomInputHandler : public InputHandler
                        if(counter1 < 0.0)\r
                        {\r
                                counter1 = 0.1*Rand(1, 30);\r
-                               leftclicked = true;\r
+                               leftdown = !leftdown;\r
+                               if(leftdown)\r
+                                       leftclicked = true;\r
+                               if(!leftdown)\r
+                                       leftreleased = true;\r
                        }\r
                }\r
                {\r
@@ -1029,8 +1064,12 @@ class RandomInputHandler : public InputHandler
                        counter1 -= dtime;\r
                        if(counter1 < 0.0)\r
                        {\r
-                               counter1 = 0.1*Rand(1, 20);\r
-                               rightclicked = true;\r
+                               counter1 = 0.1*Rand(1, 15);\r
+                               rightdown = !rightdown;\r
+                               if(rightdown)\r
+                                       rightclicked = true;\r
+                               if(!rightdown)\r
+                                       rightreleased = true;\r
                        }\r
                }\r
                mousepos += mousespeed;\r
@@ -1044,8 +1083,12 @@ class RandomInputHandler : public InputHandler
        bool keydown[KEY_KEY_CODES_COUNT];\r
        v2s32 mousepos;\r
        v2s32 mousespeed;\r
+       bool leftdown;\r
+       bool rightdown;\r
        bool leftclicked;\r
        bool rightclicked;\r
+       bool leftreleased;\r
+       bool rightreleased;\r
 };\r
 \r
 void updateViewingRange(f32 frametime_in, Client *client)\r
@@ -1103,8 +1146,8 @@ void updateViewingRange(f32 frametime_in, Client *client)
        f32 wanted_frametime_change = wanted_frametime - frametime;\r
        //dstream<<"wanted_frametime_change="<<wanted_frametime_change<<std::endl;\r
        \r
-       // If needed frametime change is very small, just return\r
-       if(fabs(wanted_frametime_change) < wanted_frametime*0.2)\r
+       // If needed frametime change is small, just return\r
+       if(fabs(wanted_frametime_change) < wanted_frametime*0.4)\r
        {\r
                //dstream<<"ignoring small wanted_frametime_change"<<std::endl;\r
                return;\r
@@ -1179,125 +1222,200 @@ void updateViewingRange(f32 frametime_in, Client *client)
        frametime_old = frametime;\r
 }\r
 \r
-class GUIQuickInventory\r
+void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,\r
+               v2s32 centerlowerpos, s32 imgsize, s32 itemcount,\r
+               Inventory *inventory)\r
 {\r
-public:\r
-       GUIQuickInventory(\r
-                       gui::IGUIEnvironment* env,\r
-                       gui::IGUIElement* parent,\r
-                       v2s32 pos,\r
-                       s32 itemcount,\r
-                       Inventory *inventory):\r
-               m_itemcount(itemcount),\r
-               m_inventory(inventory)\r
+       InventoryList *mainlist = inventory->getList("main");\r
+       if(mainlist == NULL)\r
        {\r
-               core::rect<s32> imgsize(0,0,quickinv_size,quickinv_size);\r
-               core::rect<s32> textsize(0,0,quickinv_size,quickinv_size);\r
-               for(s32 i=0; i<m_itemcount; i++)\r
-               {\r
-                       m_images.push_back(env->addImage(\r
-                               imgsize\r
-                       ));\r
-                       m_images[i]->setScaleImage(true);\r
-                       m_texts.push_back(env->addStaticText(\r
-                               L"",\r
-                               textsize,\r
-                               false, false\r
-                       ));\r
-                       /*m_texts[i]->setBackgroundColor(\r
-                                       video::SColor(128,0,0,0));*/\r
-                       m_texts[i]->setTextAlignment(\r
-                                       gui::EGUIA_LOWERRIGHT,\r
-                                       gui::EGUIA_LOWERRIGHT);\r
-               }\r
-\r
-               updatePosition(pos);\r
+               dstream<<"WARNING: draw_hotbar(): mainlist == NULL"<<std::endl;\r
+               return;\r
        }\r
+       \r
+       s32 padding = imgsize/12;\r
+       //s32 height = imgsize + padding*2;\r
+       s32 width = itemcount*(imgsize+padding*2);\r
+       \r
+       // Position of upper left corner of bar\r
+       v2s32 pos = centerlowerpos - v2s32(width/2, imgsize+padding*2);\r
+       \r
+       // Draw background color\r
+       /*core::rect<s32> barrect(0,0,width,height);\r
+       barrect += pos;\r
+       video::SColor bgcolor(255,128,128,128);\r
+       driver->draw2DRectangle(bgcolor, barrect, NULL);*/\r
 \r
-       ~GUIQuickInventory()\r
+       core::rect<s32> imgrect(0,0,imgsize,imgsize);\r
+\r
+       for(s32 i=0; i<itemcount; i++)\r
        {\r
-               for(u32 i=0; i<m_texts.size(); i++)\r
+               InventoryItem *item = mainlist->getItem(i);\r
+               \r
+               core::rect<s32> rect = imgrect + pos\r
+                               + v2s32(padding+i*(imgsize+padding*2), padding);\r
+               \r
+               if(g_selected_item == i)\r
                {\r
-                       m_texts[i]->remove();\r
+                       driver->draw2DRectangle(video::SColor(255,255,0,0),\r
+                                       core::rect<s32>(rect.UpperLeftCorner - v2s32(1,1)*padding,\r
+                                                       rect.LowerRightCorner + v2s32(1,1)*padding),\r
+                                       NULL);\r
                }\r
-               for(u32 i=0; i<m_images.size(); i++)\r
+               else\r
                {\r
-                       m_images[i]->remove();\r
+                       video::SColor bgcolor2(128,0,0,0);\r
+                       driver->draw2DRectangle(bgcolor2, rect, NULL);\r
                }\r
-       }\r
 \r
-       void updatePosition(v2s32 pos)\r
-       {\r
-               v2s32 spacing(quickinv_spacing, 0);\r
-               for(s32 i=0; i<m_itemcount; i++)\r
+               if(item != NULL)\r
                {\r
-                       m_images[i]->setRelativePosition(pos + spacing*i);\r
-                       m_texts[i]->setRelativePosition(pos + spacing*i);\r
+                       drawInventoryItem(driver, font, item, rect, NULL);\r
                }\r
        }\r
+}\r
 \r
-       void setSelection(s32 i)\r
-       {\r
-               m_selection = i;\r
-       }\r
-\r
-       void update()\r
-       {\r
-               s32 start = 0;\r
+video::ITexture *g_map_plot_texture = NULL;\r
+float g_map_plot_texture_scale = 4;\r
 \r
-               //start = m_selection - m_itemcount / 2;\r
+void updateMapPlotTexture(v2f centerpos, video::IVideoDriver* driver,\r
+               Client *client)\r
+{\r
+       assert(driver);\r
+       assert(client);\r
+\r
+       core::dimension2d<u32> dim(640,480);\r
+       video::IImage *img = driver->createImage(video::ECF_A8R8G8B8, dim);\r
+       assert(img);\r
+       for(u32 y=0; y<dim.Height; y++)\r
+       for(u32 x=0; x<dim.Width; x++)\r
+       {\r
+               v2f pf = v2f(x, dim.Height-y) - v2f(dim.Width, dim.Height)/2;\r
+               pf *= g_map_plot_texture_scale;\r
+               pf += centerpos;\r
+               double h = base_rock_level_2d(client->getMapSeed(), pf);\r
+               video::SColor c;\r
+               //double d1 = 50;\r
+               /*s32 ux = x - centerpos.X / g_map_plot_texture_scale;\r
+               s32 uy = y - centerpos.Y / g_map_plot_texture_scale;*/\r
+                       \r
+               // Screen coordinates that are based on multiples of\r
+               // 1000/g_map_plot_texture_scale and never negative\r
+               u32 ux = x + (u32)(1000/g_map_plot_texture_scale) * 10;\r
+               u32 uy = y + (u32)(1000/g_map_plot_texture_scale) * 10;\r
+               // Offset to center of image\r
+               ux -= dim.Width/2;\r
+               uy -= dim.Height/2;\r
+\r
+               if(uy % (u32)(1000/g_map_plot_texture_scale) == 0\r
+                               || ux % (u32)(1000/g_map_plot_texture_scale) == 0)\r
+                       c.set(255, 255, 255, 255);\r
+               else if(uy % (u32)(100/g_map_plot_texture_scale) == 0\r
+                               || ux % (u32)(100/g_map_plot_texture_scale) == 0)\r
+                       c.set(255, 160, 160, 160);\r
+               else if(h < WATER_LEVEL - 0.5) // Water\r
+                       c.set(255, 50, 50, 255);\r
+#if 0\r
+               else if(get_have_sand_ground(client->getMapSeed(), pf)\r
+                               || (h < WATER_LEVEL + 2\r
+                               && get_have_sand_coast(client->getMapSeed(), pf)))\r
+               {\r
+                       h -= WATER_LEVEL;\r
+                       h /= 50.0;\r
+                       h = 1.0 - exp(-h);\r
 \r
-               InventoryList *mainlist = m_inventory->getList("main");\r
+                       video::SColor c1(255,237,201,175);\r
+                       //video::SColor c2(255,20,20,20);\r
+                       video::SColor c2(255,150,0,0);\r
+                       c = c2.getInterpolated(c1, h);\r
+               }\r
+               else\r
+               {\r
+                       h -= WATER_LEVEL;\r
+                       h /= 50.0;\r
+                       h = 1.0 - exp(-h);\r
 \r
-               for(s32 i=0; i<m_itemcount; i++)\r
+                       video::SColor c1(255,110,185,90);\r
+                       //video::SColor c2(255,20,20,20);\r
+                       video::SColor c2(255,150,0,0);\r
+                       c = c2.getInterpolated(c1, h);\r
+               }\r
+#endif\r
+#if 1\r
+#if 0\r
+               else if(get_have_sand_ground(client->getMapSeed(), pf))\r
                {\r
-                       s32 j = i + start;\r
+                       h -= WATER_LEVEL;\r
+                       h /= 20.0;\r
+                       h = 1.0 - exp(-h);\r
 \r
-                       if(j > (s32)mainlist->getSize() - 1)\r
-                               j -= mainlist->getSize();\r
-                       if(j < 0)\r
-                               j += mainlist->getSize();\r
-                       \r
-                       InventoryItem *item = mainlist->getItem(j);\r
-                       // Null items\r
-                       if(item == NULL)\r
-                       {\r
-                               m_images[i]->setImage(NULL);\r
+                       video::SColor c1(255,237,201,175);\r
+                       //video::SColor c2(255,20,20,20);\r
+                       video::SColor c2(255,150,0,0);\r
+                       c = c2.getInterpolated(c1, h);\r
+               }\r
+#endif\r
+               // Sand\r
+               else if(h < WATER_LEVEL + 2\r
+                               && get_have_sand_coast(client->getMapSeed(), pf))\r
+                       c.set(255, 237, 201, 175);\r
+#if 1\r
+               else if(h < WATER_LEVEL + 10)\r
+                       c.set(255, 50, 150, 50); // Green\r
+               else if(h < WATER_LEVEL + 20)\r
+                       c.set(255, 110, 185, 50); // Yellowish green\r
+               else if(h < WATER_LEVEL + 40)\r
+                       c.set(255, 180, 210, 50); // Greenish yellow\r
+               else if(h < WATER_LEVEL + 60)\r
+                       c.set(255, 220, 220, 50); // Yellow\r
+               else if(h < WATER_LEVEL + 80)\r
+                       c.set(255, 200, 200, 110); // Yellowish white\r
+               else if(h < WATER_LEVEL + 100)\r
+                       c.set(255, 190, 190, 190); // Grey\r
+               else\r
+                       c.set(255, 255, 255, 255); // White\r
+#endif\r
+#endif\r
+#if 0\r
+               else\r
+               {\r
+                       h -= WATER_LEVEL;\r
+                       h /= 20.0;\r
+                       h = 1.0 - exp(-h);\r
 \r
-                               if(m_selection == j)\r
-                                       m_texts[i]->setText(L"<-");\r
-                               else\r
-                                       m_texts[i]->setText(L"");\r
+                       video::SColor c1(255,200,200,50);\r
+                       video::SColor c2(255,0,150,0);\r
+                       c = c1.getInterpolated(c2, h);\r
 \r
-                               // The next ifs will segfault with a NULL pointer\r
-                               continue;\r
-                       }\r
-                       \r
-                       \r
-                       m_images[i]->setImage(item->getImage());\r
-                       \r
-                       std::ostringstream os;\r
-                       os<<item->getText();\r
-                       if(m_selection == j)\r
-                               os<<" <-";\r
-                       m_texts[i]->setText(narrow_to_wide(os.str()).c_str());\r
-\r
-                       /*wchar_t t[10];\r
-                       if(m_selection == j)\r
-                               swprintf(t, 10, SWPRINTF_CHARSTRING L" <-", item->getText().c_str());\r
-                       else\r
-                               swprintf(t, 10, SWPRINTF_CHARSTRING, item->getText().c_str());\r
-                       m_texts[i]->setText(t);*/\r
+                       /*u32 a = (u32)(h*255);\r
+                       if(a > 255)\r
+                               a = 255;\r
+                       a = 255-a;\r
+                       c.set(255, a, a, a);*/\r
+               }\r
+#endif\r
+#if 1\r
+               if(h >= WATER_LEVEL - 0.5\r
+                       && get_have_sand_ground(client->getMapSeed(), pf))\r
+               {\r
+                       video::SColor c1(255,237,201,175);\r
+                       c = c.getInterpolated(c1, 0.5);\r
                }\r
+#endif\r
+#if 1\r
+               double tf = get_turbulence_factor_2d(client->getMapSeed(), pf);\r
+               if(tf > 0.001)\r
+               {\r
+                       video::SColor c1(255,255,0,0);\r
+                       c = c.getInterpolated(c1, 1.0-(0.5*tf));\r
+               }\r
+#endif\r
+               img->setPixel(x, y, c);\r
        }\r
-\r
-private:\r
-       s32 m_itemcount;\r
-       core::array<gui::IGUIStaticText*> m_texts;\r
-       core::array<gui::IGUIImage*> m_images;\r
-       Inventory *m_inventory;\r
-       s32 m_selection;\r
-};\r
+       g_map_plot_texture = driver->addTexture("map_plot", img);\r
+       img->drop();\r
+       assert(g_map_plot_texture);\r
+}\r
 \r
 // Chat data\r
 struct ChatLine\r
@@ -1485,6 +1603,9 @@ int main(int argc, char *argv[])
 \r
        DSTACK(__FUNCTION_NAME);\r
 \r
+       porting::signal_handler_init();\r
+       bool &kill = *porting::signal_handler_killstatus();\r
+       \r
        porting::initializePaths();\r
        // Create user data directory\r
        fs::CreateDir(porting::path_userdata);\r
@@ -1620,7 +1741,7 @@ int main(int argc, char *argv[])
                server.start(port);\r
                \r
                // Run server\r
-               dedicated_server_loop(server);\r
+               dedicated_server_loop(server, kill);\r
 \r
                return 0;\r
        }\r
@@ -1643,30 +1764,41 @@ int main(int argc, char *argv[])
        \r
        std::string playername = g_settings.get("name");\r
 \r
-       /*\r
-               Resolution selection\r
-       */\r
+       // Resolution selection\r
        \r
        bool fullscreen = false;\r
        u16 screenW = g_settings.getU16("screenW");\r
        u16 screenH = g_settings.getU16("screenH");\r
 \r
-       //\r
-\r
-       MyEventReceiver receiver;\r
+       // Determine driver\r
 \r
        video::E_DRIVER_TYPE driverType;\r
-\r
-#ifdef _WIN32\r
-       //driverType = video::EDT_DIRECT3D9;\r
-       driverType = video::EDT_OPENGL;\r
-#else\r
-       driverType = video::EDT_OPENGL;\r
-       //driverType = video::EDT_BURNINGSVIDEO; // Best software renderer\r
-#endif\r
+       \r
+       std::string driverstring = g_settings.get("video_driver");\r
+\r
+       if(driverstring == "null")\r
+               driverType = video::EDT_NULL;\r
+       else if(driverstring == "software")\r
+               driverType = video::EDT_SOFTWARE;\r
+       else if(driverstring == "burningsvideo")\r
+               driverType = video::EDT_BURNINGSVIDEO;\r
+       else if(driverstring == "direct3d8")\r
+               driverType = video::EDT_DIRECT3D8;\r
+       else if(driverstring == "direct3d9")\r
+               driverType = video::EDT_DIRECT3D9;\r
+       else if(driverstring == "opengl")\r
+               driverType = video::EDT_OPENGL;\r
+       else\r
+       {\r
+               dstream<<"WARNING: Invalid video_driver specified; defaulting "\r
+                               "to opengl"<<std::endl;\r
+               driverType = video::EDT_OPENGL;\r
+       }\r
 \r
        // create device and exit if creation failed\r
 \r
+       MyEventReceiver receiver;\r
+\r
        IrrlichtDevice *device;\r
        device = createDevice(driverType,\r
                        core::dimension2d<u32>(screenW, screenH),\r
@@ -1712,7 +1844,7 @@ int main(int argc, char *argv[])
        //driver->setMinHardwareBufferVertexCount(50);\r
 \r
        scene::ISceneManager* smgr = device->getSceneManager();\r
-       \r
+\r
        guienv = device->getGUIEnvironment();\r
        gui::IGUISkin* skin = guienv->getSkin();\r
        gui::IGUIFont* font = guienv->getFont(porting::getDataPath("fontlucida.png").c_str());\r
@@ -1770,7 +1902,7 @@ int main(int argc, char *argv[])
        // Object infos are shown in this\r
        gui::IGUIStaticText *guitext_info = guienv->addStaticText(\r
                        L"",\r
-                       core::rect<s32>(100, 70, 100+400, 70+(text_height+5)),\r
+                       core::rect<s32>(0,0,400,text_height+5) + v2s32(100,200),\r
                        false, false);\r
        \r
        // Chat text\r
@@ -1792,7 +1924,7 @@ int main(int argc, char *argv[])
        /*\r
                Menu-game loop\r
        */\r
-       while(g_device->run())\r
+       while(g_device->run() && kill == false)\r
        {\r
        \r
        // This is used for catching disconnects\r
@@ -1804,7 +1936,7 @@ int main(int argc, char *argv[])
 \r
                Loop quits when menu returns proper parameters.\r
        */\r
-       for(;;)\r
+       while(kill == false)\r
        {\r
                // Cursor can be non-visible when coming from the game\r
                device->getCursorControl()->setVisible(true);\r
@@ -1842,7 +1974,7 @@ int main(int argc, char *argv[])
                \r
                dstream<<"Created main menu"<<std::endl;\r
 \r
-               while(g_device->run())\r
+               while(g_device->run() && kill == false)\r
                {\r
                        // Run global IrrlichtWrapper's main thread processing stuff\r
                        g_irrlicht->Run();\r
@@ -1857,7 +1989,7 @@ int main(int argc, char *argv[])
                }\r
                \r
                // Break out of menu-game loop to shut down cleanly\r
-               if(g_device->run() == false)\r
+               if(g_device->run() == false || kill == true)\r
                        break;\r
                \r
                dstream<<"Dropping main menu"<<std::endl;\r
@@ -2022,7 +2154,7 @@ int main(int argc, char *argv[])
 \r
        if(camera == NULL)\r
                return 1;\r
-       \r
+\r
        //video::SColor skycolor = video::SColor(255,90,140,200);\r
        //video::SColor skycolor = video::SColor(255,166,202,244);\r
        video::SColor skycolor = video::SColor(255,120,185,244);\r
@@ -2031,6 +2163,23 @@ int main(int argc, char *argv[])
 \r
        // Just so big a value that everything rendered is visible\r
        camera->setFarValue(100000*BS);\r
+       \r
+       /*\r
+               Lighting test code. Doesn't quite work this way.\r
+               The CPU-computed lighting is good.\r
+       */\r
+\r
+       /*\r
+       smgr->addLightSceneNode(NULL,\r
+               v3f(0, BS*1000000, 0),\r
+               video::SColorf(0.3,0.3,0.3),\r
+               BS*10000000);\r
+\r
+       smgr->setAmbientLight(video::SColorf(0.0, 0.0, 0.0));\r
+\r
+       scene::ILightSceneNode *light = smgr->addLightSceneNode(camera,\r
+                       v3f(0, 0, 0), video::SColorf(0.5,0.5,0.5), BS*4);\r
+       */\r
 \r
        f32 camera_yaw = 0; // "right/left"\r
        f32 camera_pitch = 0; // "up/down"\r
@@ -2047,8 +2196,8 @@ int main(int argc, char *argv[])
 \r
        /*GUIQuickInventory *quick_inventory = new GUIQuickInventory\r
                        (guienv, NULL, v2s32(10, 70), 5, &local_inventory);*/\r
-       GUIQuickInventory *quick_inventory = new GUIQuickInventory\r
-                       (guienv, NULL, v2s32(0, 0), quickinv_itemcount, &local_inventory);\r
+       /*GUIQuickInventory *quick_inventory = new GUIQuickInventory\r
+                       (guienv, NULL, v2s32(0, 0), quickinv_itemcount, &local_inventory);*/\r
        \r
        // Test the text input system\r
        /*(new GUITextInputMenu(guienv, guiroot, -1, &g_menumgr,\r
@@ -2097,7 +2246,7 @@ int main(int argc, char *argv[])
        // NOTE: So we have to use getTime() and call run()s between them\r
        u32 lasttime = device->getTimer()->getTime();\r
 \r
-       while(device->run())\r
+       while(device->run() && kill == false)\r
        {\r
                if(g_disconnect_requested)\r
                {\r
@@ -2121,7 +2270,7 @@ int main(int argc, char *argv[])
                last_screensize = screensize;\r
                screensize = driver->getScreenSize();\r
                v2s32 displaycenter(screensize.X/2,screensize.Y/2);\r
-               bool screensize_changed = screensize != last_screensize;\r
+               //bool screensize_changed = screensize != last_screensize;\r
                \r
                // Hilight boxes collected during the loop and displayed\r
                core::list< core::aabbox3d<f32> > hilightboxes;\r
@@ -2130,11 +2279,11 @@ int main(int argc, char *argv[])
                std::wstring infotext;\r
 \r
                // When screen size changes, update positions and sizes of stuff\r
-               if(screensize_changed)\r
+               /*if(screensize_changed)\r
                {\r
                        v2s32 pos(displaycenter.X-((quickinv_itemcount-1)*quickinv_spacing+quickinv_size)/2, screensize.Y-quickinv_spacing);\r
                        quick_inventory->updatePosition(pos);\r
-               }\r
+               }*/\r
 \r
                //TimeTaker //timer1("//timer1");\r
                \r
@@ -2281,6 +2430,10 @@ int main(int argc, char *argv[])
                */\r
                g_input->step(dtime);\r
 \r
+               /*\r
+                       Misc. stuff\r
+               */\r
+\r
                /*\r
                        Player speed control\r
                */\r
@@ -2378,11 +2531,9 @@ int main(int argc, char *argv[])
                camera->setTarget(camera_position + camera_direction * 100.0);\r
 \r
                if(FIELD_OF_VIEW_TEST){\r
-                       //client.m_env.getMap().updateCamera(v3f(0,0,0), v3f(0,0,1));\r
                        client.updateCamera(v3f(0,0,0), v3f(0,0,1));\r
                }\r
                else{\r
-                       //client.m_env.getMap().updateCamera(camera_position, camera_direction);\r
                        //TimeTaker timer("client.updateCamera");\r
                        client.updateCamera(camera_position, camera_direction);\r
                }\r
@@ -2477,7 +2628,7 @@ int main(int argc, char *argv[])
                core::aabbox3d<f32> nodehilightbox;\r
                f32 mindistance = BS * 1001;\r
                \r
-               v3s16 pos_i = floatToInt(player_position);\r
+               v3s16 pos_i = floatToInt(player_position, BS);\r
 \r
                /*std::cout<<"pos_i=("<<pos_i.X<<","<<pos_i.Y<<","<<pos_i.Z<<")"\r
                                <<std::endl;*/\r
@@ -2507,7 +2658,7 @@ int main(int argc, char *argv[])
                        }\r
 \r
                        v3s16 np(x,y,z);\r
-                       v3f npf = intToFloat(np);\r
+                       v3f npf = intToFloat(np, BS);\r
                        \r
                        f32 d = 0.01;\r
                        \r
@@ -2615,7 +2766,7 @@ int main(int argc, char *argv[])
                                                        const float d = 0.502;\r
                                                        core::aabbox3d<f32> nodebox\r
                                                                        (-BS*d, -BS*d, -BS*d, BS*d, BS*d, BS*d);\r
-                                                       v3f nodepos_f = intToFloat(nodepos);\r
+                                                       v3f nodepos_f = intToFloat(nodepos, BS);\r
                                                        nodebox.MinEdge += nodepos_f;\r
                                                        nodebox.MaxEdge += nodepos_f;\r
                                                        nodehilightbox = nodebox;\r
@@ -2819,7 +2970,7 @@ int main(int argc, char *argv[])
                        driver->setFog(\r
                                bgcolor,\r
                                video::EFT_FOG_LINEAR,\r
-                               range*0.6,\r
+                               range*0.4,\r
                                range*1.0,\r
                                0.01,\r
                                false, // pixel fog\r
@@ -2985,8 +3136,8 @@ int main(int argc, char *argv[])
                        old_selected_item = g_selected_item;\r
                        //std::cout<<"Updating local inventory"<<std::endl;\r
                        client.getLocalInventory(local_inventory);\r
-                       quick_inventory->setSelection(g_selected_item);\r
-                       quick_inventory->update();\r
+                       /*quick_inventory->setSelection(g_selected_item);\r
+                       quick_inventory->update();*/\r
                }\r
                \r
                /*\r
@@ -3051,16 +3202,6 @@ int main(int argc, char *argv[])
                        driver->draw3DBox(*i, video::SColor(255,0,0,0));\r
                }\r
 \r
-               /*\r
-                       Draw crosshair\r
-               */\r
-               driver->draw2DLine(displaycenter - core::vector2d<s32>(10,0),\r
-                               displaycenter + core::vector2d<s32>(10,0),\r
-                               video::SColor(255,255,255,255));\r
-               driver->draw2DLine(displaycenter - core::vector2d<s32>(0,10),\r
-                               displaycenter + core::vector2d<s32>(0,10),\r
-                               video::SColor(255,255,255,255));\r
-\r
                /*\r
                        Frametime log\r
                */\r
@@ -3079,6 +3220,31 @@ int main(int argc, char *argv[])
                        }\r
                }\r
 \r
+               /*\r
+                       Draw map plot\r
+               */\r
+               if(g_show_map_plot && g_map_plot_texture)\r
+               {\r
+                       core::dimension2d<u32> drawdim(640,480);\r
+                       core::rect<s32> dest(v2s32(0,0), drawdim);\r
+                       dest += v2s32(\r
+                               (screensize.X-drawdim.Width)/2,\r
+                               (screensize.Y-drawdim.Height)/2\r
+                       );\r
+                       core::rect<s32> source(v2s32(0,0), g_map_plot_texture->getSize());\r
+                       driver->draw2DImage(g_map_plot_texture, dest, source);\r
+               }\r
+\r
+               /*\r
+                       Draw crosshair\r
+               */\r
+               driver->draw2DLine(displaycenter - core::vector2d<s32>(10,0),\r
+                               displaycenter + core::vector2d<s32>(10,0),\r
+                               video::SColor(255,255,255,255));\r
+               driver->draw2DLine(displaycenter - core::vector2d<s32>(0,10),\r
+                               displaycenter + core::vector2d<s32>(0,10),\r
+                               video::SColor(255,255,255,255));\r
+\r
                } // timer\r
 \r
                //timer10.stop();\r
@@ -3089,6 +3255,14 @@ int main(int argc, char *argv[])
                */\r
                // 0-1ms\r
                guienv->drawAll();\r
+\r
+               /*\r
+                       Draw hotbar\r
+               */\r
+               {\r
+                       draw_hotbar(driver, font, v2s32(displaycenter.X, screensize.Y),\r
+                                       hotbar_imagesize, hotbar_itemcount, &local_inventory);\r
+               }\r
                \r
                // End drawing\r
                {\r
@@ -3100,8 +3274,23 @@ int main(int argc, char *argv[])
                drawtime = drawtimer.stop(true);\r
 \r
                /*\r
-                       Drawing ends\r
+                       End of drawing\r
                */\r
+\r
+               /*\r
+                       Refresh map plot if player has moved considerably\r
+               */\r
+               if(g_refresh_map_plot)\r
+               {\r
+                       static v3f old_player_pos = v3f(1,1,1) * 10000000;\r
+                       v3f p = client.getPlayerPosition() / BS;\r
+                       if(old_player_pos.getDistanceFrom(p) > 4 * g_map_plot_texture_scale)\r
+                       {\r
+                               updateMapPlotTexture(v2f(p.X,p.Z), driver, &client);\r
+                               old_player_pos = p;\r
+                       }\r
+                       g_refresh_map_plot = false;\r
+               }\r
                \r
                static s16 lastFPS = 0;\r
                //u16 fps = driver->getFPS();\r
@@ -3123,7 +3312,7 @@ int main(int argc, char *argv[])
                        device->yield();*/\r
        }\r
 \r
-       delete quick_inventory;\r
+       //delete quick_inventory;\r
 \r
        /*\r
                Disable texture fetches and other stuff that is queued\r