Clouds: Make cloud area radius settable in .conf
authorparamat <mat.gregory@virginmedia.com>
Mon, 4 May 2015 17:53:58 +0000 (18:53 +0100)
committerest31 <MTest31@outlook.com>
Mon, 4 May 2015 20:41:13 +0000 (22:41 +0200)
minetest.conf.example
src/clouds.cpp
src/clouds.h
src/defaultsettings.cpp

index 8967eff23f5904efb9f6c6834e3f3f3e96dd0106..2475235a22bfd0953d0376d2d76e616104b43874 100644 (file)
 #    Enable/disable clouds
 #enable_clouds = true
 #cloud_height = 120
+#    Radius of cloud area stated in number of 64 node cloud squares.
+#    Values > 22 will start to produce clipping of the cloud area corners.
+#cloud_radius = 12
 #enable_3d_clouds = true
 #    Use a cloud animation for the main menu background
 #menu_clouds = true
index 3409aac73ab6b08a8015950534ee470cbd6558e7..ff3f603d95454b13adb98de853be2cc4a8aec860 100644 (file)
@@ -55,6 +55,8 @@ Clouds::Clouds(
        m_cloud_y = BS * (cloudheight ? cloudheight :
                                g_settings->getS16("cloud_height"));
 
+       m_cloud_radius_i = g_settings->getU16("cloud_radius");
+
        m_box = core::aabbox3d<f32>(-BS*1000000,m_cloud_y-BS,-BS*1000000,
                        BS*1000000,m_cloud_y+BS,BS*1000000);
 
@@ -96,14 +98,13 @@ void Clouds::render()
        driver->setMaterial(m_material);
        
        /*
-               Clouds move from X+ towards X-
+               Clouds move from Z+ towards Z-
        */
 
-       const s16 cloud_radius_i = 12;
        const float cloud_size = BS * 64;
        const v2f cloud_speed(0, -BS * 2);
        
-       const float cloud_full_radius = cloud_size * cloud_radius_i;
+       const float cloud_full_radius = cloud_size * m_cloud_radius_i;
        
        // Position of cloud noise origin in world coordinates
        v2f world_cloud_origin_pos_f = m_time * cloud_speed;
@@ -165,14 +166,14 @@ void Clouds::render()
 
        // Read noise
 
-       bool *grid = new bool[cloud_radius_i * 2 * cloud_radius_i * 2];
+       bool *grid = new bool[m_cloud_radius_i * 2 * m_cloud_radius_i * 2];
 
        float cloud_size_noise = cloud_size / BS / 200;
 
-       for(s16 zi = -cloud_radius_i; zi < cloud_radius_i; zi++) {
-               u32 si = (zi + cloud_radius_i) * cloud_radius_i * 2 + cloud_radius_i;
+       for(s16 zi = -m_cloud_radius_i; zi < m_cloud_radius_i; zi++) {
+               u32 si = (zi + m_cloud_radius_i) * m_cloud_radius_i * 2 + m_cloud_radius_i;
 
-               for(s16 xi = -cloud_radius_i; xi < cloud_radius_i; xi++) {
+               for (s16 xi = -m_cloud_radius_i; xi < m_cloud_radius_i; xi++) {
                        u32 i = si + xi;
 
                        v2s16 p_in_noise_i(
@@ -192,23 +193,23 @@ void Clouds::render()
 #define INAREA(x, z, radius) \
        ((x) >= -(radius) && (x) < (radius) && (z) >= -(radius) && (z) < (radius))
 
-       for(s16 zi0=-cloud_radius_i; zi0<cloud_radius_i; zi0++)
-       for(s16 xi0=-cloud_radius_i; xi0<cloud_radius_i; xi0++)
+       for (s16 zi0= -m_cloud_radius_i; zi0 < m_cloud_radius_i; zi0++)
+       for (s16 xi0= -m_cloud_radius_i; xi0 < m_cloud_radius_i; xi0++)
        {
                s16 zi = zi0;
                s16 xi = xi0;
                // Draw from front to back (needed for transparency)
                /*if(zi <= 0)
-                       zi = -cloud_radius_i - zi;
+                       zi = -m_cloud_radius_i - zi;
                if(xi <= 0)
-                       xi = -cloud_radius_i - xi;*/
+                       xi = -m_cloud_radius_i - xi;*/
                // Draw from back to front
                if(zi >= 0)
-                       zi = cloud_radius_i - zi - 1;
+                       zi = m_cloud_radius_i - zi - 1;
                if(xi >= 0)
-                       xi = cloud_radius_i - xi - 1;
+                       xi = m_cloud_radius_i - xi - 1;
 
-               u32 i = GETINDEX(xi, zi, cloud_radius_i);
+               u32 i = GETINDEX(xi, zi, m_cloud_radius_i);
 
                if(grid[i] == false)
                        continue;
@@ -247,8 +248,8 @@ void Clouds::render()
                                v[3].Pos.set( rx, ry,-rz);
                                break;
                        case 1: // back
-                               if(INAREA(xi, zi-1, cloud_radius_i)){
-                                       u32 j = GETINDEX(xi, zi-1, cloud_radius_i);
+                               if (INAREA(xi, zi - 1, m_cloud_radius_i)) {
+                                       u32 j = GETINDEX(xi, zi - 1, m_cloud_radius_i);
                                        if(grid[j])
                                                continue;
                                }
@@ -262,8 +263,8 @@ void Clouds::render()
                                v[3].Pos.set(-rx,-ry,-rz);
                                break;
                        case 2: //right
-                               if(INAREA(xi+1, zi, cloud_radius_i)){
-                                       u32 j = GETINDEX(xi+1, zi, cloud_radius_i);
+                               if (INAREA(xi + 1, zi, m_cloud_radius_i)) {
+                                       u32 j = GETINDEX(xi+1, zi, m_cloud_radius_i);
                                        if(grid[j])
                                                continue;
                                }
@@ -277,8 +278,8 @@ void Clouds::render()
                                v[3].Pos.set( rx,-ry,-rz);
                                break;
                        case 3: // front
-                               if(INAREA(xi, zi+1, cloud_radius_i)){
-                                       u32 j = GETINDEX(xi, zi+1, cloud_radius_i);
+                               if (INAREA(xi, zi + 1, m_cloud_radius_i)) {
+                                       u32 j = GETINDEX(xi, zi + 1, m_cloud_radius_i);
                                        if(grid[j])
                                                continue;
                                }
@@ -292,8 +293,8 @@ void Clouds::render()
                                v[3].Pos.set( rx,-ry, rz);
                                break;
                        case 4: // left
-                               if(INAREA(xi-1, zi, cloud_radius_i)){
-                                       u32 j = GETINDEX(xi-1, zi, cloud_radius_i);
+                               if (INAREA(xi-1, zi, m_cloud_radius_i)) {
+                                       u32 j = GETINDEX(xi-1, zi, m_cloud_radius_i);
                                        if(grid[j])
                                                continue;
                                }
index add8a7247b2c0e5144c3ccf7aace5104069267f4..70f12239ebc8c02280be62171125e074846e8048 100644 (file)
@@ -87,6 +87,7 @@ private:
        video::SMaterial m_material;
        core::aabbox3d<f32> m_box;
        float m_cloud_y;
+       u16 m_cloud_radius_i;
        video::SColorf m_color;
        u32 m_seed;
        v2f m_camera_pos;
index e629377ee06d64c1a95f39ac1723828a9be069c7..45188f791a4bfffa284625fdb0e868d05257ed7c 100644 (file)
@@ -127,6 +127,7 @@ void set_default_settings(Settings *settings)
        settings->setDefault("fall_bobbing_amount", "0.0");
        settings->setDefault("enable_3d_clouds", "true");
        settings->setDefault("cloud_height", "120");
+       settings->setDefault("cloud_radius", "12");
        settings->setDefault("menu_clouds", "true");
        settings->setDefault("opaque_water", "false");
        settings->setDefault("console_color", "(0,0,0)");