Page up and down change the minimum viewing range
authorKahrl <kahrl@gmx.net>
Wed, 1 Feb 2012 01:24:55 +0000 (02:24 +0100)
committerKahrl <kahrl@gmx.net>
Wed, 1 Feb 2012 01:24:55 +0000 (02:24 +0100)
src/camera.cpp
src/camera.h
src/defaultsettings.cpp
src/game.cpp

index 066208569b1702cedaed7efbff1bc5f12714e6c1..b36daf1d7aaa6d37040ce189012e42844c2080ea 100644 (file)
@@ -40,8 +40,6 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control):
        m_wieldlight(0),
 
        m_draw_control(draw_control),
-       m_viewing_range_min(5.0),
-       m_viewing_range_max(5.0),
 
        m_camera_position(0,0,0),
        m_camera_direction(0,0,0),
@@ -50,7 +48,6 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control):
        m_fov_x(1.0),
        m_fov_y(1.0),
 
-       m_wanted_frametime(0.0),
        m_added_frametime(0),
        m_added_frames(0),
        m_range_old(0),
@@ -79,8 +76,6 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control):
        m_wieldmgr = smgr->createNewSceneManager();
        m_wieldmgr->addCameraSceneNode();
        m_wieldnode = m_wieldmgr->addMeshSceneNode(createCubeMesh(v3f(1,1,1)), NULL);  // need a dummy mesh
-
-       updateSettings();
 }
 
 Camera::~Camera()
@@ -259,14 +254,17 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize)
        // *100.0 helps in large map coordinates
        m_cameranode->setTarget(m_camera_position + 100 * m_camera_direction);
 
-       // FOV and and aspect ratio
+       // Get FOV setting
+       f32 fov_degrees = g_settings->getFloat("fov");
+       fov_degrees = MYMAX(fov_degrees, 10.0);
+       fov_degrees = MYMIN(fov_degrees, 170.0);
+
+       // FOV and aspect ratio
        m_aspect = (f32)screensize.X / (f32) screensize.Y;
+       m_fov_y = fov_degrees * PI / 180.0;
        m_fov_x = 2 * atan(0.5 * m_aspect * tan(m_fov_y));
        m_cameranode->setAspectRatio(m_aspect);
        m_cameranode->setFOV(m_fov_y);
-       // Just so big a value that everything rendered is visible
-       // Some more allowance that m_viewing_range_max * BS because of active objects etc.
-       m_cameranode->setFarValue(m_viewing_range_max * BS * 10);
 
        // Position the wielded item
        v3f wield_position = v3f(45, -35, 65);
@@ -343,7 +341,18 @@ void Camera::updateViewingRange(f32 frametime_in)
                        <<m_draw_control.blocks_would_have_drawn
                        <<std::endl;*/
 
-       m_draw_control.wanted_min_range = m_viewing_range_min;
+       // Get current viewing range and FPS settings
+       f32 viewing_range_min = g_settings->getS16("viewing_range_nodes_min");
+       viewing_range_min = MYMAX(5.0, viewing_range_min);
+
+       f32 viewing_range_max = g_settings->getS16("viewing_range_nodes_max");
+       viewing_range_max = MYMAX(viewing_range_min, viewing_range_max);
+
+       f32 wanted_fps = g_settings->getFloat("wanted_fps");
+       wanted_fps = MYMAX(wanted_fps, 1.0);
+       f32 wanted_frametime = 1.0 / wanted_fps;
+
+       m_draw_control.wanted_min_range = viewing_range_min;
        m_draw_control.wanted_max_blocks = (2.0*m_draw_control.blocks_would_have_drawn)+1;
        if (m_draw_control.wanted_max_blocks < 10)
                m_draw_control.wanted_max_blocks = 10;
@@ -362,13 +371,13 @@ void Camera::updateViewingRange(f32 frametime_in)
        m_added_frametime = 0.0;
        m_added_frames = 0;
 
-       f32 wanted_frametime_change = m_wanted_frametime - frametime;
+       f32 wanted_frametime_change = wanted_frametime - frametime;
        //dstream<<"wanted_frametime_change="<<wanted_frametime_change<<std::endl;
 
        // If needed frametime change is small, just return
        // This value was 0.4 for many months until 2011-10-18 by c55;
        // Let's see how this works out.
-       if (fabs(wanted_frametime_change) < m_wanted_frametime*0.33)
+       if (fabs(wanted_frametime_change) < wanted_frametime*0.33)
        {
                //dstream<<"ignoring small wanted_frametime_change"<<std::endl;
                return;
@@ -421,8 +430,8 @@ void Camera::updateViewingRange(f32 frametime_in)
        new_range += wanted_range_change;
        
        //f32 new_range_unclamped = new_range;
-       new_range = MYMAX(new_range, m_viewing_range_min);
-       new_range = MYMIN(new_range, m_viewing_range_max);
+       new_range = MYMAX(new_range, viewing_range_min);
+       new_range = MYMIN(new_range, viewing_range_max);
        /*dstream<<"new_range="<<new_range_unclamped
                        <<", clamped to "<<new_range<<std::endl;*/
 
@@ -430,24 +439,11 @@ void Camera::updateViewingRange(f32 frametime_in)
 
        m_range_old = new_range;
        m_frametime_old = frametime;
-}
-
-void Camera::updateSettings()
-{
-       m_viewing_range_min = g_settings->getS16("viewing_range_nodes_min");
-       m_viewing_range_min = MYMAX(5.0, m_viewing_range_min);
 
-       m_viewing_range_max = g_settings->getS16("viewing_range_nodes_max");
-       m_viewing_range_max = MYMAX(m_viewing_range_min, m_viewing_range_max);
-
-       f32 fov_degrees = g_settings->getFloat("fov");
-       fov_degrees = MYMAX(fov_degrees, 10.0);
-       fov_degrees = MYMIN(fov_degrees, 170.0);
-       m_fov_y = fov_degrees * PI / 180.0;
+       // Just so big a value that everything rendered is visible
+       // Some more allowance than viewing_range_max * BS because of active objects etc.
+       m_cameranode->setFarValue(viewing_range_max * BS * 10);
 
-       f32 wanted_fps = g_settings->getFloat("wanted_fps");
-       wanted_fps = MYMAX(wanted_fps, 1.0);
-       m_wanted_frametime = 1.0 / wanted_fps;
 }
 
 void Camera::setDigging(s32 button)
index 56c99d1014881a8ed1498d74ac7320ab196b039a..7be8162b56f14fc8cbd89d1434ce59f9a15f22c5 100644 (file)
@@ -110,9 +110,6 @@ public:
        // Render distance feedback loop
        void updateViewingRange(f32 frametime_in);
 
-       // Update settings from g_settings
-       void updateSettings();
-
        // Start digging animation
        // Pass 0 for left click, 1 for right click
        void setDigging(s32 button);
@@ -139,11 +136,6 @@ private:
        // draw control
        MapDrawControl& m_draw_control;
 
-       // viewing_range_min_nodes setting
-       f32 m_viewing_range_min;
-       // viewing_range_max_nodes setting
-       f32 m_viewing_range_max;
-
        // Absolute camera position
        v3f m_camera_position;
        // Absolute camera direction
@@ -155,7 +147,6 @@ private:
        f32 m_fov_y;
 
        // Stuff for viewing range calculations
-       f32 m_wanted_frametime;
        f32 m_added_frametime;
        s16 m_added_frames;
        f32 m_range_old;
index 2b604662cedbf05248a14e5bfe295fe7756526fc..2b6cb7f53794b891487c8a599fdac72701bcbf26 100644 (file)
@@ -50,6 +50,8 @@ void set_default_settings(Settings *settings)
        settings->setDefault("keymap_toggle_update_camera", "KEY_F4");
        settings->setDefault("keymap_toggle_debug", "KEY_F5");
        settings->setDefault("keymap_toggle_profiler", "KEY_F6");
+       settings->setDefault("keymap_increase_viewing_range_min", "KEY_PRIOR");
+       settings->setDefault("keymap_decrease_viewing_range_min", "KEY_NEXT");
        // Some (temporary) keys for debugging
        settings->setDefault("keymap_print_debug_stacks", "KEY_KEY_P");
 
index 76fdedcf0fed39e54325c7a9b5318bbb547d508b..f35b85cb6f7e7f4fd0645097468462bf21587806 100644 (file)
@@ -1507,6 +1507,36 @@ void the_game(
                                statustext_time = 0;
                        }
                }
+               else if(input->wasKeyDown(getKeySetting("keymap_increase_viewing_range_min")))
+               {
+                       s16 range = g_settings->getS16("viewing_range_nodes_min");
+                       s16 range_new = range + 10;
+                       g_settings->set("viewing_range_nodes_min", itos(range_new));
+                       statustext = narrow_to_wide(
+                                       "Minimum viewing range changed from "
+                                       + itos(range) + " to " + itos(range_new));
+                       statustext_time = 0;
+               }
+               else if(input->wasKeyDown(getKeySetting("keymap_decrease_viewing_range_min")))
+               {
+                       s16 range = g_settings->getS16("viewing_range_nodes_min");
+                       s16 range_new = range - 10;
+                       if(range_new >= 0)
+                       {
+                               g_settings->set("viewing_range_nodes_min",
+                                               itos(range_new));
+                               statustext = narrow_to_wide(
+                                               "Minimum viewing range changed from "
+                                               + itos(range) + " to "
+                                               + itos(range_new));
+                               statustext_time = 0;
+                       }
+                       else
+                       {
+                               statustext = L"Minimum viewing range already at minimum";
+                               statustext_time = 0;
+                       }
+               }
 
                // Item selection with mouse wheel
                u16 new_playeritem = client.getPlayerItem();