New map generator added (and SQLite, messed up the commits at that time...) (import...
[oweals/minetest.git] / src / farmesh.cpp
index 3faac163d91d06d25dd52ac62c22cf7f2df7a6f3..dbff728b199d1610d3d8093a52a732f2af5d3483 100644 (file)
@@ -33,8 +33,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
        Temporarily exposed map generator stuff
        Should only be used for testing
 */
-extern double base_rock_level_2d(u64 seed, v2s16 p);
-extern double get_mud_add_amount(u64 seed, v2s16 p);
+//extern double base_rock_level_2d(u64 seed, v2s16 p);
+//extern double get_mud_add_amount(u64 seed, v2s16 p);
+extern s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
 extern bool get_have_sand(u64 seed, v2s16 p2d);
 extern double tree_amount_2d(u64 seed, v2s16 p);
 
@@ -50,7 +51,8 @@ FarMesh::FarMesh(
        m_seed(seed),
        m_camera_pos(0,0),
        m_time(0),
-       m_client(client)
+       m_client(client),
+       m_render_range(20*MAP_BLOCKSIZE)
 {
        dstream<<__FUNCTION_NAME<<std::endl;
        
@@ -125,17 +127,20 @@ HeightPoint ground_height(u64 seed, v2s16 p2d)
        if(n)
                return n->getValue();
        HeightPoint hp;
-       hp.gh = BS*base_rock_level_2d(seed, p2d);
-       hp.gh -= BS*2; // Lower a bit so that it is not that much in the way
-       hp.ma = BS*get_mud_add_amount(seed, p2d);
+       s16 level = find_ground_level_from_noise(seed, p2d, 3);
+       hp.gh = (level-4)*BS;
+       hp.ma = (4)*BS;
+       /*hp.gh = BS*base_rock_level_2d(seed, p2d);
+       hp.ma = BS*get_mud_add_amount(seed, p2d);*/
        hp.have_sand = get_have_sand(seed, p2d);
        if(hp.gh > BS*WATER_LEVEL)
                hp.tree_amount = tree_amount_2d(seed, p2d);
        else
                hp.tree_amount = 0;
-       // No mud has been added if mud amount is less than 2
-       if(hp.ma < 2.0*BS)
+       // No mud has been added if mud amount is less than 1
+       if(hp.ma < 1.0*BS)
                hp.ma = 0.0;
+       //hp.gh -= BS*3; // Lower a bit so that it is not that much in the way
        g_heights[p2d] = hp;
        return hp;
 }
@@ -155,7 +160,7 @@ void FarMesh::render()
        
        //const s16 grid_radius_i = 12;
        //const float grid_size = BS*50;
-       const s16 grid_radius_i = 20;
+       const s16 grid_radius_i = m_render_range/MAP_BLOCKSIZE;
        const float grid_size = BS*MAP_BLOCKSIZE;
        const v2f grid_speed(-BS*0, 0);
        
@@ -274,7 +279,10 @@ void FarMesh::render()
                //light_f /= 2.0;
                
                v2f p1 = p0 + v2f(1,1)*grid_size;
-
+               
+               bool ground_is_sand = false;
+               bool ground_is_rock = false;
+               bool ground_is_mud = false;
                video::SColor c;
                // Detect water
                if(h_avg < WATER_LEVEL*BS && h_max < (WATER_LEVEL+5)*BS)
@@ -294,6 +302,7 @@ void FarMesh::render()
                else if(steepness > 2.0)
                {
                        c = video::SColor(255,128,128,128);
+                       ground_is_rock = true;
                }
                // Basic ground
                else
@@ -301,11 +310,15 @@ void FarMesh::render()
                        if(ma_avg < 2.0*BS)
                        {
                                c = video::SColor(255,128,128,128);
+                               ground_is_rock = true;
                        }
                        else
                        {
                                if(h_avg <= 2.5*BS && have_sand_count >= 2)
+                               {
                                        c = video::SColor(255,210,194,156);
+                                       ground_is_sand = true;
+                               }
                                else
                                {
                                        /*// Trees if there are over 0.01 trees per MapNode
@@ -314,6 +327,7 @@ void FarMesh::render()
                                        else
                                                c = video::SColor(255,107,134,51);*/
                                        c = video::SColor(255,107,134,51);
+                                       ground_is_mud = true;
                                }
                        }
                }
@@ -345,8 +359,8 @@ void FarMesh::render()
                                video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
 
                // Add some trees if appropriate
-               if(tree_amount_avg > 0.006 && steepness < 1.0
-                               && ma_avg >= 2.0*BS && have_sand_count <= 2)
+               if(tree_amount_avg >= 0.0065 && steepness < 1.4
+                               && ground_is_mud == true)
                {
                        driver->setMaterial(m_materials[1]);
                        
@@ -358,11 +372,11 @@ void FarMesh::render()
                                {
                                        video::S3DVertex(p0.X,noise[0],p0.Y,
                                                        0,0,0, c, 0,1),
-                                       video::S3DVertex(p0.X,noise[1]+BS*MAP_BLOCKSIZE,p0.Y,
+                                       video::S3DVertex(p0.X,noise[0]+BS*MAP_BLOCKSIZE,p0.Y,
                                                        0,0,0, c, 0,0),
                                        video::S3DVertex(p1.X,noise[2]+BS*MAP_BLOCKSIZE,p1.Y,
                                                        0,0,0, c, 1,0),
-                                       video::S3DVertex(p1.X,noise[3],p1.Y,
+                                       video::S3DVertex(p1.X,noise[2],p1.Y,
                                                        0,0,0, c, 1,1),
                                };
                                u16 indices[] = {0,1,2,2,3,0};
@@ -373,13 +387,13 @@ void FarMesh::render()
                        {
                                video::S3DVertex vertices[4] =
                                {
-                                       video::S3DVertex(p1.X,noise[0],p0.Y,
+                                       video::S3DVertex(p1.X,noise[3],p0.Y,
                                                        0,0,0, c, 0,1),
-                                       video::S3DVertex(p1.X,noise[1]+BS*MAP_BLOCKSIZE,p0.Y,
+                                       video::S3DVertex(p1.X,noise[3]+BS*MAP_BLOCKSIZE,p0.Y,
                                                        0,0,0, c, 0,0),
-                                       video::S3DVertex(p0.X,noise[2]+BS*MAP_BLOCKSIZE,p1.Y,
+                                       video::S3DVertex(p0.X,noise[1]+BS*MAP_BLOCKSIZE,p1.Y,
                                                        0,0,0, c, 1,0),
-                                       video::S3DVertex(p0.X,noise[3],p1.Y,
+                                       video::S3DVertex(p0.X,noise[1],p1.Y,
                                                        0,0,0, c, 1,1),
                                };
                                u16 indices[] = {0,1,2,2,3,0};
@@ -398,10 +412,11 @@ void FarMesh::step(float dtime)
        m_time += dtime;
 }
 
-void FarMesh::update(v2f camera_p, float brightness)
+void FarMesh::update(v2f camera_p, float brightness, s16 render_range)
 {
        m_camera_pos = camera_p;
        m_brightness = brightness;
+       m_render_range = render_range;
 }