]> 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 a74685fa2a1480878e0684b76840334dbb117454..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,6 +158,11 @@ TODO: Make fetching sector's blocks more efficient when rendering
 \r
 TODO: Flowing water animation\r
 \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
@@ -182,7 +185,7 @@ TODO: Remove IrrlichtWrapper
 \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: Copy the text of the last picked sign to inventory in creative\r
@@ -191,10 +194,13 @@ TODO: Copy the text of the last picked sign to inventory in creative
 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 in\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
@@ -221,6 +227,15 @@ Block object server side:
 - 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
@@ -230,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
@@ -247,42 +259,10 @@ 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
-=== Next\r
-* Continue making the scripting system:\r
-  * Rip up everything unnecessary from the lua build 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
-\r
-=== Fixmes\r
-* Check the fixmes in the list above\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
-\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
-\r
-=== Features\r
-* Map should make the appropriate MapEditEvents\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
-* Add mud underground\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
@@ -292,12 +272,45 @@ Doing now (most important at the top):
   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
-* 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
-* 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
@@ -491,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
@@ -607,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
@@ -680,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
@@ -1111,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
@@ -1240,6 +1275,148 @@ void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,
        }\r
 }\r
 \r
+video::ITexture *g_map_plot_texture = NULL;\r
+float g_map_plot_texture_scale = 4;\r
+\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
+                       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
+                       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
+                       h -= WATER_LEVEL;\r
+                       h /= 20.0;\r
+                       h = 1.0 - exp(-h);\r
+\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
+                       video::SColor c1(255,200,200,50);\r
+                       video::SColor c2(255,0,150,0);\r
+                       c = c1.getInterpolated(c2, h);\r
+\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
+       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
 {\r
@@ -2253,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
@@ -2789,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
@@ -3021,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
@@ -3049,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
@@ -3078,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