From: Kahrl Date: Wed, 1 Feb 2012 01:24:55 +0000 (+0100) Subject: Page up and down change the minimum viewing range X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=2cb96d9d6800a3fd74bb6264974e8811ff8d4acd;p=zefram%2Fminetest%2Fminetest_engine.git Page up and down change the minimum viewing range --- diff --git a/src/camera.cpp b/src/camera.cpp index 06620856..b36daf1d 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -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) <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="<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) diff --git a/src/camera.h b/src/camera.h index 56c99d10..7be8162b 100644 --- a/src/camera.h +++ b/src/camera.h @@ -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; diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 2b604662..2b6cb7f5 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -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"); diff --git a/src/game.cpp b/src/game.cpp index 76fdedcf..f35b85cb 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -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();