1
0
mirror of https://github.com/moparisthebest/minetest synced 2024-12-22 15:48:48 -05:00

Camera: remove auto tune FPS, single view range setting

This commit is contained in:
RealBadAngel 2016-02-20 04:42:35 +01:00 committed by est31
parent 2f4cf0bcca
commit b2aabdfe07
8 changed files with 33 additions and 207 deletions

View File

@ -209,11 +209,11 @@ keymap_toggle_profiler (Profiler toggle key) key KEY_F6
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3 # See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_camera_mode (Toggle camera mode key) key KEY_F7 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 # See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_increase_viewing_range_min (View range increase key) key + 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 # See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
keymap_decrease_viewing_range_min (View range decrease key) key - keymap_decrease_viewing_range_min (View range decrease key) key -
@ -388,10 +388,6 @@ enable_waving_plants (Waving plants) bool false
[***Advanced] [***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 # If FPS would go higher than this, limit it by sleeping
# to not waste CPU power for no benefit. # to not waste CPU power for no benefit.
fps_max (Maximum FPS) int 60 fps_max (Maximum FPS) int 60
@ -399,13 +395,9 @@ fps_max (Maximum FPS) int 60
# Maximum FPS when game is paused. # Maximum FPS when game is paused.
pause_fps_max (FPS in pause menu) int 20 pause_fps_max (FPS in pause menu) int 20
# The allowed adjustment range for the automatic rendering range adjustment. # View distance in nodes.
# Set this to be equal to viewing range minimum to disable the auto-adjustment algorithm. # Min = 20
viewing_range_nodes_max (Viewing range maximum) int 160 viewing_range (Viewing range) int 100
# 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
# Width component of the initial window size. # Width component of the initial window size.
screenW (Screen width) int 800 screenW (Screen width) int 800

View File

@ -214,12 +214,12 @@
# type: key # type: key
# keymap_camera_mode = KEY_F7 # 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 # See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
# type: key # type: key
# keymap_increase_viewing_range_min = + # 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 # See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
# type: key # type: key
# keymap_decrease_viewing_range_min = - # keymap_decrease_viewing_range_min = -
@ -431,11 +431,6 @@
#### Advanced #### 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 # If FPS would go higher than this, limit it by sleeping
# to not waste CPU power for no benefit. # to not waste CPU power for no benefit.
# type: int # type: int
@ -445,15 +440,10 @@
# type: int # type: int
# pause_fps_max = 20 # pause_fps_max = 20
# The allowed adjustment range for the automatic rendering range adjustment. # View range in nodes.
# Set this to be equal to viewing range minimum to disable the auto-adjustment algorithm. # Min = 20.
# type: int # type: int
# viewing_range_nodes_max = 160 # viewing_range = 100
# 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.
# type: int
# viewing_range_nodes_min = 35
# Width component of the initial window size. # Width component of the initial window size.
# type: int # type: int

View File

@ -60,13 +60,6 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control,
m_fov_x(1.0), m_fov_x(1.0),
m_fov_y(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_anim(0),
m_view_bobbing_state(0), m_view_bobbing_state(0),
m_view_bobbing_speed(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_fall_bobbing_amount = g_settings->getFloat("fall_bobbing_amount");
m_cache_view_bobbing_amount = g_settings->getFloat("view_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_fov = g_settings->getFloat("fov");
m_cache_view_bobbing = g_settings->getBool("view_bobbing"); m_cache_view_bobbing = g_settings->getBool("view_bobbing");
m_nametags.clear(); m_nametags.clear();
@ -455,8 +447,8 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime,
m_wieldnode->setColor(player->light_color); m_wieldnode->setColor(player->light_color);
// Render distance feedback loop // Set render distance
updateViewingRange(frametime, busytime); updateViewingRange();
// If the player is walking, swimming, or climbing, // If the player is walking, swimming, or climbing,
// view bobbing is enabled and free_move is off, // 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) {
return; m_cameranode->setFarValue(100000.0);
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; return;
} }
f32 range = m_draw_control.wanted_range; f32 viewing_range = g_settings->getFloat("viewing_range");
f32 new_range = range; m_draw_control.wanted_range = viewing_range;
m_cameranode->setFarValue((viewing_range < 2000) ? 2000 * BS : viewing_range * BS);
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;
} }
void Camera::setDigging(s32 button) void Camera::setDigging(s32 button)

View File

@ -136,8 +136,8 @@ public:
void update(LocalPlayer* player, f32 frametime, f32 busytime, void update(LocalPlayer* player, f32 frametime, f32 busytime,
f32 tool_reload_ratio, ClientEnvironment &c_env); f32 tool_reload_ratio, ClientEnvironment &c_env);
// Render distance feedback loop // Update render distance
void updateViewingRange(f32 frametime_in, f32 busytime_in); void updateViewingRange();
// Start digging animation // Start digging animation
// Pass 0 for left click, 1 for right click // Pass 0 for left click, 1 for right click
@ -204,14 +204,6 @@ private:
f32 m_fov_x; f32 m_fov_x;
f32 m_fov_y; 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) // View bobbing animation frame (0 <= m_view_bobbing_anim < 1)
f32 m_view_bobbing_anim; f32 m_view_bobbing_anim;
// If 0, view bobbing is off (e.g. player is standing). // 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_fall_bobbing_amount;
f32 m_cache_view_bobbing_amount; f32 m_cache_view_bobbing_amount;
f32 m_cache_wanted_fps;
f32 m_cache_fov; f32 m_cache_fov;
bool m_cache_view_bobbing; bool m_cache_view_bobbing;

View File

@ -327,7 +327,7 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
blocks_would_have_drawn++; blocks_would_have_drawn++;
if (blocks_drawn >= m_control.wanted_max_blocks && if (blocks_drawn >= m_control.wanted_max_blocks &&
!m_control.range_all && !m_control.range_all &&
d > m_control.wanted_min_range * BS) d > m_control.wanted_range * BS)
continue; continue;
// Add to set // Add to set

View File

@ -30,9 +30,8 @@ struct MapDrawControl
{ {
MapDrawControl(): MapDrawControl():
range_all(false), range_all(false),
wanted_range(50), wanted_range(0),
wanted_max_blocks(0), wanted_max_blocks(0),
wanted_min_range(0),
blocks_drawn(0), blocks_drawn(0),
blocks_would_have_drawn(0), blocks_would_have_drawn(0),
farthest_drawn(0) farthest_drawn(0)
@ -44,8 +43,6 @@ struct MapDrawControl
float wanted_range; float wanted_range;
// Maximum number of blocks to draw // Maximum number of blocks to draw
u32 wanted_max_blocks; 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 // Number of blocks rendered is written here by the renderer
u32 blocks_drawn; u32 blocks_drawn;
// Number of blocks that would have been drawn in wanted_range // Number of blocks that would have been drawn in wanted_range

View File

@ -89,12 +89,9 @@ void set_default_settings(Settings *settings)
settings->setDefault("show_debug", "true"); settings->setDefault("show_debug", "true");
#endif #endif
settings->setDefault("wanted_fps", "30");
settings->setDefault("fps_max", "60"); settings->setDefault("fps_max", "60");
settings->setDefault("pause_fps_max", "20"); 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", "100");
settings->setDefault("viewing_range_nodes_max", "240");
settings->setDefault("viewing_range_nodes_min", "35");
settings->setDefault("map_generation_limit", "31000"); settings->setDefault("map_generation_limit", "31000");
settings->setDefault("screenW", "800"); settings->setDefault("screenW", "800");
settings->setDefault("screenH", "600"); settings->setDefault("screenH", "600");
@ -345,8 +342,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("emergequeue_limit_diskonly", "8"); settings->setDefault("emergequeue_limit_diskonly", "8");
settings->setDefault("emergequeue_limit_generate", "8"); settings->setDefault("emergequeue_limit_generate", "8");
settings->setDefault("viewing_range_nodes_max", "50"); settings->setDefault("viewing_range", "50");
settings->setDefault("viewing_range_nodes_min", "20");
settings->setDefault("inventory_image_hack", "false"); settings->setDefault("inventory_image_hack", "false");
//check for device with small screen //check for device with small screen

View File

@ -3039,10 +3039,10 @@ void Game::toggleProfiler(float *statustext_time, u32 *profiler_current_page,
void Game::increaseViewRange(float *statustext_time) 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; s16 range_new = range + 10;
g_settings->set("viewing_range_nodes_min", itos(range_new)); g_settings->set("viewing_range", itos(range_new));
statustext = utf8_to_wide("Minimum viewing range changed to " statustext = utf8_to_wide("Viewing range changed to "
+ itos(range_new)); + itos(range_new));
*statustext_time = 0; *statustext_time = 0;
} }
@ -3050,14 +3050,14 @@ void Game::increaseViewRange(float *statustext_time)
void Game::decreaseViewRange(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; s16 range_new = range - 10;
if (range_new < 0) if (range_new < 20)
range_new = range; range_new = 20;
g_settings->set("viewing_range_nodes_min", itos(range_new)); g_settings->set("viewing_range", itos(range_new));
statustext = utf8_to_wide("Minimum viewing range changed to " statustext = utf8_to_wide("Viewing range changed to "
+ itos(range_new)); + itos(range_new));
*statustext_time = 0; *statustext_time = 0;
} }
@ -3935,12 +3935,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats,
if (draw_control->range_all) { if (draw_control->range_all) {
runData->fog_range = 100000 * BS; runData->fog_range = 100000 * BS;
} else { } else {
runData->fog_range = draw_control->wanted_range * BS runData->fog_range = 0.9 * 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;
} }
/* /*