diff options
author | RealBadAngel <maciej.kasatkin@o2.pl> | 2016-02-20 04:42:35 +0100 |
---|---|---|
committer | est31 <MTest31@outlook.com> | 2016-02-21 18:18:13 +0100 |
commit | b2aabdfe074d361b69c59f7ea29a85f060330f12 (patch) | |
tree | 9215a97d588d6a140e88461520f13e0dcb5a45e0 /src/camera.cpp | |
parent | 2f4cf0bcca1ce5941dd3d2625fe4636e86e73e75 (diff) | |
download | minetest-b2aabdfe074d361b69c59f7ea29a85f060330f12.tar.gz minetest-b2aabdfe074d361b69c59f7ea29a85f060330f12.tar.bz2 minetest-b2aabdfe074d361b69c59f7ea29a85f060330f12.zip |
Camera: remove auto tune FPS, single view range setting
Diffstat (limited to 'src/camera.cpp')
-rw-r--r-- | src/camera.cpp | 151 |
1 files changed, 8 insertions, 143 deletions
diff --git a/src/camera.cpp b/src/camera.cpp index 0ce6bb345..6c0f5d546 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -60,13 +60,6 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control, m_fov_x(1.0), m_fov_y(1.0), - m_added_busytime(0), - m_added_frames(0), - m_range_old(0), - m_busytime_old(0), - m_frametime_counter(0), - m_time_per_range(30. / 50), // a sane default of 30ms per 50 nodes of range - m_view_bobbing_anim(0), m_view_bobbing_state(0), m_view_bobbing_speed(0), @@ -109,7 +102,6 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control, */ m_cache_fall_bobbing_amount = g_settings->getFloat("fall_bobbing_amount"); m_cache_view_bobbing_amount = g_settings->getFloat("view_bobbing_amount"); - m_cache_wanted_fps = g_settings->getFloat("wanted_fps"); m_cache_fov = g_settings->getFloat("fov"); m_cache_view_bobbing = g_settings->getBool("view_bobbing"); m_nametags.clear(); @@ -455,8 +447,8 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, m_wieldnode->setColor(player->light_color); - // Render distance feedback loop - updateViewingRange(frametime, busytime); + // Set render distance + updateViewingRange(); // If the player is walking, swimming, or climbing, // view bobbing is enabled and free_move is off, @@ -484,143 +476,16 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, } } -void Camera::updateViewingRange(f32 frametime_in, f32 busytime_in) +void Camera::updateViewingRange() { - if (m_draw_control.range_all) + if (m_draw_control.range_all) { + m_cameranode->setFarValue(100000.0); return; - - m_added_busytime += busytime_in; - m_added_frames += 1; - - m_frametime_counter -= frametime_in; - if (m_frametime_counter > 0) - return; - m_frametime_counter = 0.2; // Same as ClientMap::updateDrawList interval - - /*dstream<<FUNCTION_NAME - <<": Collected "<<m_added_frames<<" frames, total of " - <<m_added_busytime<<"s."<<std::endl; - - dstream<<"m_draw_control.blocks_drawn=" - <<m_draw_control.blocks_drawn - <<", m_draw_control.blocks_would_have_drawn=" - <<m_draw_control.blocks_would_have_drawn - <<std::endl;*/ - - // Get current viewing range and FPS settings - f32 viewing_range_min = g_settings->getFloat("viewing_range_nodes_min"); - viewing_range_min = MYMAX(15.0, viewing_range_min); - - f32 viewing_range_max = g_settings->getFloat("viewing_range_nodes_max"); - viewing_range_max = MYMAX(viewing_range_min, viewing_range_max); - - // Immediately apply hard limits - if(m_draw_control.wanted_range < viewing_range_min) - m_draw_control.wanted_range = viewing_range_min; - if(m_draw_control.wanted_range > viewing_range_max) - m_draw_control.wanted_range = viewing_range_max; - - // Just so big a value that everything rendered is visible - // Some more allowance than viewing_range_max * BS because of clouds, - // active objects, etc. - if(viewing_range_max < 200*BS) - m_cameranode->setFarValue(200 * BS * 10); - else - m_cameranode->setFarValue(viewing_range_max * BS * 10); - - f32 wanted_fps = m_cache_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; - - f32 block_draw_ratio = 1.0; - if (m_draw_control.blocks_would_have_drawn != 0) - { - block_draw_ratio = (f32)m_draw_control.blocks_drawn - / (f32)m_draw_control.blocks_would_have_drawn; } - // Calculate the average frametime in the case that all wanted - // blocks had been drawn - f32 frametime = m_added_busytime / m_added_frames / block_draw_ratio; - - m_added_busytime = 0.0; - m_added_frames = 0; - - f32 wanted_frametime_change = wanted_frametime - frametime; - //dstream<<"wanted_frametime_change="<<wanted_frametime_change<<std::endl; - g_profiler->avg("wanted_frametime_change", wanted_frametime_change); - - // If needed frametime change is small, just return - // This value was 0.4 for many months until 2011-10-18 by c55; - if (fabs(wanted_frametime_change) < wanted_frametime*0.33) - { - //dstream<<"ignoring small wanted_frametime_change"<<std::endl; - return; - } - - f32 range = m_draw_control.wanted_range; - f32 new_range = range; - - f32 d_range = range - m_range_old; - f32 d_busytime = busytime_in - m_busytime_old; - if (d_range != 0) - { - m_time_per_range = d_busytime / d_range; - } - //dstream<<"time_per_range="<<m_time_per_range<<std::endl; - g_profiler->avg("time_per_range", m_time_per_range); - - // The minimum allowed calculated frametime-range derivative: - // Practically this sets the maximum speed of changing the range. - // The lower this value, the higher the maximum changing speed. - // A low value here results in wobbly range (0.001) - // A low value can cause oscillation in very nonlinear time/range curves. - // A high value here results in slow changing range (0.0025) - // SUGG: This could be dynamically adjusted so that when - // the camera is turning, this is lower - //f32 min_time_per_range = 0.0010; // Up to 0.4.7 - f32 min_time_per_range = 0.0005; - if(m_time_per_range < min_time_per_range) - { - m_time_per_range = min_time_per_range; - //dstream<<"m_time_per_range="<<m_time_per_range<<" (min)"<<std::endl; - } - else - { - //dstream<<"m_time_per_range="<<m_time_per_range<<std::endl; - } - - f32 wanted_range_change = wanted_frametime_change / m_time_per_range; - // Dampen the change a bit to kill oscillations - //wanted_range_change *= 0.9; - //wanted_range_change *= 0.75; - wanted_range_change *= 0.5; - //dstream<<"wanted_range_change="<<wanted_range_change<<std::endl; - - // If needed range change is very small, just return - if(fabs(wanted_range_change) < 0.001) - { - //dstream<<"ignoring small wanted_range_change"<<std::endl; - return; - } - - new_range += wanted_range_change; - - //f32 new_range_unclamped = new_range; - 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;*/ - - m_range_old = m_draw_control.wanted_range; - m_busytime_old = busytime_in; - - m_draw_control.wanted_range = new_range; + f32 viewing_range = g_settings->getFloat("viewing_range"); + m_draw_control.wanted_range = viewing_range; + m_cameranode->setFarValue((viewing_range < 2000) ? 2000 * BS : viewing_range * BS); } void Camera::setDigging(s32 button) |