From b2aabdfe074d361b69c59f7ea29a85f060330f12 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Sat, 20 Feb 2016 04:42:35 +0100 Subject: [PATCH] Camera: remove auto tune FPS, single view range setting --- builtin/settingtypes.txt | 18 ++--- minetest.conf.example | 20 ++---- src/camera.cpp | 151 +++------------------------------------ src/camera.h | 13 +--- src/clientmap.cpp | 2 +- src/clientmap.h | 5 +- src/defaultsettings.cpp | 8 +-- src/game.cpp | 23 +++--- 8 files changed, 33 insertions(+), 207 deletions(-) diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index df9158254..c21a0325f 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -209,11 +209,11 @@ keymap_toggle_profiler (Profiler toggle key) key KEY_F6 # See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3 keymap_camera_mode (Toggle camera mode key) key KEY_F7 -# Key for increasing the viewing range. Modifies the minimum viewing range. +# Key for increasing the viewing range. # See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3 keymap_increase_viewing_range_min (View range increase key) key + -# Key for decreasing the viewing range. Modifies the minimum viewing range. +# Key for decreasing the viewing range. # See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3 keymap_decrease_viewing_range_min (View range decrease key) key - @@ -388,10 +388,6 @@ enable_waving_plants (Waving plants) bool false [***Advanced] -# Minimum wanted FPS. -# The amount of rendered stuff is dynamically set according to this. and viewing range min and max. -wanted_fps (Wanted FPS) int 30 - # If FPS would go higher than this, limit it by sleeping # to not waste CPU power for no benefit. fps_max (Maximum FPS) int 60 @@ -399,13 +395,9 @@ fps_max (Maximum FPS) int 60 # Maximum FPS when game is paused. pause_fps_max (FPS in pause menu) int 20 -# The allowed adjustment range for the automatic rendering range adjustment. -# Set this to be equal to viewing range minimum to disable the auto-adjustment algorithm. -viewing_range_nodes_max (Viewing range maximum) int 160 - -# The allowed adjustment range for the automatic rendering range adjustment. -# Set this to be equal to viewing range maximum to disable the auto-adjustment algorithm. -viewing_range_nodes_min (Viewing range minimum) int 35 +# View distance in nodes. +# Min = 20 +viewing_range (Viewing range) int 100 # Width component of the initial window size. screenW (Screen width) int 800 diff --git a/minetest.conf.example b/minetest.conf.example index 4813adadc..ee6054536 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -214,12 +214,12 @@ # type: key # keymap_camera_mode = KEY_F7 -# Key for increasing the viewing range. Modifies the minimum viewing range. +# Key for increasing the viewing range. # See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3 # type: key # keymap_increase_viewing_range_min = + -# Key for decreasing the viewing range. Modifies the minimum viewing range. +# Key for decreasing the viewing range. # See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3 # type: key # keymap_decrease_viewing_range_min = - @@ -431,11 +431,6 @@ #### Advanced -# Minimum wanted FPS. -# The amount of rendered stuff is dynamically set according to this. and viewing range min and max. -# type: int -# wanted_fps = 30 - # If FPS would go higher than this, limit it by sleeping # to not waste CPU power for no benefit. # type: int @@ -445,15 +440,10 @@ # type: int # pause_fps_max = 20 -# The allowed adjustment range for the automatic rendering range adjustment. -# Set this to be equal to viewing range minimum to disable the auto-adjustment algorithm. -# type: int -# viewing_range_nodes_max = 160 - -# The allowed adjustment range for the automatic rendering range adjustment. -# Set this to be equal to viewing range maximum to disable the auto-adjustment algorithm. +# View range in nodes. +# Min = 20. # type: int -# viewing_range_nodes_min = 35 +# viewing_range = 100 # Width component of the initial window size. # type: int 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<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="<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"<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) diff --git a/src/camera.h b/src/camera.h index 36fc72f1a..ce46c3190 100644 --- a/src/camera.h +++ b/src/camera.h @@ -136,8 +136,8 @@ public: void update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_reload_ratio, ClientEnvironment &c_env); - // Render distance feedback loop - void updateViewingRange(f32 frametime_in, f32 busytime_in); + // Update render distance + void updateViewingRange(); // Start digging animation // Pass 0 for left click, 1 for right click @@ -204,14 +204,6 @@ private: f32 m_fov_x; f32 m_fov_y; - // Stuff for viewing range calculations - f32 m_added_busytime; - s16 m_added_frames; - f32 m_range_old; - f32 m_busytime_old; - f32 m_frametime_counter; - f32 m_time_per_range; - // View bobbing animation frame (0 <= m_view_bobbing_anim < 1) f32 m_view_bobbing_anim; // If 0, view bobbing is off (e.g. player is standing). @@ -238,7 +230,6 @@ private: f32 m_cache_fall_bobbing_amount; f32 m_cache_view_bobbing_amount; - f32 m_cache_wanted_fps; f32 m_cache_fov; bool m_cache_view_bobbing; diff --git a/src/clientmap.cpp b/src/clientmap.cpp index ea2b8e4e3..a0a780250 100644 --- a/src/clientmap.cpp +++ b/src/clientmap.cpp @@ -327,7 +327,7 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver) blocks_would_have_drawn++; if (blocks_drawn >= m_control.wanted_max_blocks && !m_control.range_all && - d > m_control.wanted_min_range * BS) + d > m_control.wanted_range * BS) continue; // Add to set diff --git a/src/clientmap.h b/src/clientmap.h index 445f10c97..396e68f64 100644 --- a/src/clientmap.h +++ b/src/clientmap.h @@ -30,9 +30,8 @@ struct MapDrawControl { MapDrawControl(): range_all(false), - wanted_range(50), + wanted_range(0), wanted_max_blocks(0), - wanted_min_range(0), blocks_drawn(0), blocks_would_have_drawn(0), farthest_drawn(0) @@ -44,8 +43,6 @@ struct MapDrawControl float wanted_range; // Maximum number of blocks to draw u32 wanted_max_blocks; - // Blocks in this range are drawn regardless of number of blocks drawn - float wanted_min_range; // Number of blocks rendered is written here by the renderer u32 blocks_drawn; // Number of blocks that would have been drawn in wanted_range diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index a043ef003..b1e754870 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -89,12 +89,9 @@ void set_default_settings(Settings *settings) settings->setDefault("show_debug", "true"); #endif - settings->setDefault("wanted_fps", "30"); settings->setDefault("fps_max", "60"); settings->setDefault("pause_fps_max", "20"); - // A bit more than the server will send around the player, to make fog blend well - settings->setDefault("viewing_range_nodes_max", "240"); - settings->setDefault("viewing_range_nodes_min", "35"); + settings->setDefault("viewing_range", "100"); settings->setDefault("map_generation_limit", "31000"); settings->setDefault("screenW", "800"); settings->setDefault("screenH", "600"); @@ -345,8 +342,7 @@ void set_default_settings(Settings *settings) settings->setDefault("emergequeue_limit_diskonly", "8"); settings->setDefault("emergequeue_limit_generate", "8"); - settings->setDefault("viewing_range_nodes_max", "50"); - settings->setDefault("viewing_range_nodes_min", "20"); + settings->setDefault("viewing_range", "50"); settings->setDefault("inventory_image_hack", "false"); //check for device with small screen diff --git a/src/game.cpp b/src/game.cpp index 53db14fb3..9729ca477 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -3039,10 +3039,10 @@ void Game::toggleProfiler(float *statustext_time, u32 *profiler_current_page, void Game::increaseViewRange(float *statustext_time) { - s16 range = g_settings->getS16("viewing_range_nodes_min"); + s16 range = g_settings->getS16("viewing_range"); s16 range_new = range + 10; - g_settings->set("viewing_range_nodes_min", itos(range_new)); - statustext = utf8_to_wide("Minimum viewing range changed to " + g_settings->set("viewing_range", itos(range_new)); + statustext = utf8_to_wide("Viewing range changed to " + itos(range_new)); *statustext_time = 0; } @@ -3050,14 +3050,14 @@ void Game::increaseViewRange(float *statustext_time) void Game::decreaseViewRange(float *statustext_time) { - s16 range = g_settings->getS16("viewing_range_nodes_min"); + s16 range = g_settings->getS16("viewing_range"); s16 range_new = range - 10; - if (range_new < 0) - range_new = range; + if (range_new < 20) + range_new = 20; - g_settings->set("viewing_range_nodes_min", itos(range_new)); - statustext = utf8_to_wide("Minimum viewing range changed to " + g_settings->set("viewing_range", itos(range_new)); + statustext = utf8_to_wide("Viewing range changed to " + itos(range_new)); *statustext_time = 0; } @@ -3935,12 +3935,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, if (draw_control->range_all) { runData->fog_range = 100000 * BS; } else { - runData->fog_range = draw_control->wanted_range * BS - + 0.0 * MAP_BLOCKSIZE * BS; - runData->fog_range = MYMIN( - runData->fog_range, - (draw_control->farthest_drawn + 20) * BS); - runData->fog_range *= 0.9; + runData->fog_range = 0.9 * draw_control->wanted_range * BS; } /* -- 2.25.1