aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRealBadAngel <maciej.kasatkin@o2.pl>2016-02-20 04:42:35 +0100
committerest31 <MTest31@outlook.com>2016-02-21 18:18:13 +0100
commitb2aabdfe074d361b69c59f7ea29a85f060330f12 (patch)
tree9215a97d588d6a140e88461520f13e0dcb5a45e0 /src
parent2f4cf0bcca1ce5941dd3d2625fe4636e86e73e75 (diff)
downloadminetest-b2aabdfe074d361b69c59f7ea29a85f060330f12.tar.gz
minetest-b2aabdfe074d361b69c59f7ea29a85f060330f12.tar.bz2
minetest-b2aabdfe074d361b69c59f7ea29a85f060330f12.zip
Camera: remove auto tune FPS, single view range setting
Diffstat (limited to 'src')
-rw-r--r--src/camera.cpp151
-rw-r--r--src/camera.h13
-rw-r--r--src/clientmap.cpp2
-rw-r--r--src/clientmap.h5
-rw-r--r--src/defaultsettings.cpp8
-rw-r--r--src/game.cpp23
6 files changed, 23 insertions, 179 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)
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;
}
/*