Paste #Po1 -- näytä pelkkänä tekstinä -- uusi tämän pohjalta
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | diff --git a/src/camera.cpp b/src/camera.cpp index 3d8713d..937ba38 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -33,6 +33,7 @@ #include "gamedef.h" #include "sound.h" #include "event.h" +#include "profiler.h" #include "util/numeric.h" #include "util/mathconstants.h" @@ -57,10 +58,10 @@ m_fov_x(1.0), m_fov_y(1.0), - m_added_frametime(0), + m_added_busytime(0), m_added_frames(0), m_range_old(0), - m_frametime_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 @@ -242,8 +243,8 @@ void Camera::step(f32 dtime) } } -void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize, - f32 tool_reload_ratio) +void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, + v2u32 screensize, f32 tool_reload_ratio) { // Get player position // Smooth the movement when walking up stairs @@ -416,7 +417,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize, m_wieldlight = player->light; // Render distance feedback loop - updateViewingRange(frametime); + updateViewingRange(frametime, busytime); // If the player seems to be walking on solid ground, // view bobbing is enabled and free_move is off, @@ -440,23 +441,22 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize, } } -void Camera::updateViewingRange(f32 frametime_in) +void Camera::updateViewingRange(f32 frametime_in, f32 busytime_in) { if (m_draw_control.range_all) return; - m_added_frametime += frametime_in; + m_added_busytime += busytime_in; m_added_frames += 1; - // Actually this counter kind of sucks because frametime is busytime m_frametime_counter -= frametime_in; if (m_frametime_counter > 0) return; - m_frametime_counter = 0.2; + m_frametime_counter = 0.2; // Same as ClientMap::updateDrawList interval /*dstream<<__FUNCTION_NAME <<": Collected "<<m_added_frames<<" frames, total of " - <<m_added_frametime<<"s."<<std::endl; + <<m_added_busytime<<"s."<<std::endl; dstream<<"m_draw_control.blocks_drawn=" <<m_draw_control.blocks_drawn @@ -466,7 +466,7 @@ void Camera::updateViewingRange(f32 frametime_in) // Get current viewing range and FPS settings f32 viewing_range_min = g_settings->getS16("viewing_range_nodes_min"); - viewing_range_min = MYMAX(5.0, viewing_range_min); + viewing_range_min = MYMAX(15.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); @@ -503,17 +503,17 @@ void Camera::updateViewingRange(f32 frametime_in) // Calculate the average frametime in the case that all wanted // blocks had been drawn - f32 frametime = m_added_frametime / m_added_frames / block_draw_ratio; + f32 frametime = m_added_busytime / m_added_frames / block_draw_ratio; - m_added_frametime = 0.0; + 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; - // Let's see how this works out. if (fabs(wanted_frametime_change) < wanted_frametime*0.33) { //dstream<<"ignoring small wanted_frametime_change"<<std::endl; @@ -524,22 +524,24 @@ void Camera::updateViewingRange(f32 frametime_in) f32 new_range = range; f32 d_range = range - m_range_old; - f32 d_frametime = frametime - m_frametime_old; + f32 d_busytime = busytime_in - m_busytime_old; if (d_range != 0) { - m_time_per_range = d_frametime / d_range; + 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.0015; - f32 min_time_per_range = 0.0010; - //f32 min_time_per_range = 0.05 / range; + //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; @@ -572,10 +574,10 @@ void Camera::updateViewingRange(f32 frametime_in) /*dstream<<"new_range="<<new_range_unclamped <<", clamped to "<<new_range<<std::endl;*/ - m_draw_control.wanted_range = new_range; + m_range_old = m_draw_control.wanted_range; + m_busytime_old = busytime_in; - m_range_old = new_range; - m_frametime_old = frametime; + m_draw_control.wanted_range = new_range; } void Camera::setDigging(s32 button) diff --git a/src/camera.h b/src/camera.h index c8a6e0b..aa91391 100644 --- a/src/camera.h +++ b/src/camera.h @@ -105,12 +105,12 @@ class Camera void step(f32 dtime); // Update the camera from the local player's position. - // frametime is used to adjust the viewing range. - void update(LocalPlayer* player, f32 frametime, v2u32 screensize, - f32 tool_reload_ratio); + // busytime is used to adjust the viewing range. + void update(LocalPlayer* player, f32 frametime, f32 busytime, + v2u32 screensize, f32 tool_reload_ratio); // Render distance feedback loop - void updateViewingRange(f32 frametime_in); + void updateViewingRange(f32 frametime_in, f32 busytime_in); // Start digging animation // Pass 0 for left click, 1 for right click @@ -151,10 +151,10 @@ class Camera f32 m_fov_y; // Stuff for viewing range calculations - f32 m_added_frametime; + f32 m_added_busytime; s16 m_added_frames; f32 m_range_old; - f32 m_frametime_old; + f32 m_busytime_old; f32 m_frametime_counter; f32 m_time_per_range; diff --git a/src/clientmap.cpp b/src/clientmap.cpp index c080683..e0c41c7 100644 --- a/src/clientmap.cpp +++ b/src/clientmap.cpp @@ -215,6 +215,8 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver) //u32 blocks_had_pass_meshbuf = 0; // Blocks from which stuff was actually drawn //u32 blocks_without_stuff = 0; + // Distance to farthest drawn block + float farthest_drawn = 0; for(std::map<v2s16, MapSector*>::iterator si = m_sectors.begin(); @@ -347,6 +349,8 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver) sector_blocks_drawn++; blocks_drawn++; + if(d/BS > farthest_drawn) + farthest_drawn = d/BS; } // foreach sectorblocks @@ -356,6 +360,7 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver) m_control.blocks_would_have_drawn = blocks_would_have_drawn; m_control.blocks_drawn = blocks_drawn; + m_control.farthest_drawn = farthest_drawn; g_profiler->avg("CM: blocks in range", blocks_in_range); g_profiler->avg("CM: blocks occlusion culled", blocks_occlusion_culled); @@ -363,6 +368,7 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver) g_profiler->avg("CM: blocks in range without mesh (frac)", (float)blocks_in_range_without_mesh/blocks_in_range); g_profiler->avg("CM: blocks drawn", blocks_drawn); + g_profiler->avg("CM: farthest drawn", farthest_drawn); g_profiler->avg("CM: wanted max blocks", m_control.wanted_max_blocks); } diff --git a/src/clientmap.h b/src/clientmap.h index 7f63704..f36e612 100644 --- a/src/clientmap.h +++ b/src/clientmap.h @@ -33,7 +33,8 @@ struct MapDrawControl wanted_max_blocks(0), wanted_min_range(0), blocks_drawn(0), - blocks_would_have_drawn(0) + blocks_would_have_drawn(0), + farthest_drawn(0) { } // Overrides limits by drawing everything @@ -48,6 +49,8 @@ struct MapDrawControl u32 blocks_drawn; // Number of blocks that would have been drawn in wanted_range u32 blocks_would_have_drawn; + // Distance to the farthest block drawn + float farthest_drawn; }; class Client; diff --git a/src/game.cpp b/src/game.cpp index 4f2d665..9a29877 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2456,7 +2456,8 @@ void the_game( float full_punch_interval = playeritem_toolcap.full_punch_interval; float tool_reload_ratio = time_from_last_punch / full_punch_interval; tool_reload_ratio = MYMIN(tool_reload_ratio, 1.0); - camera.update(player, busytime, screensize, tool_reload_ratio); + camera.update(player, dtime, busytime, screensize, + tool_reload_ratio); camera.step(dtime); v3f player_position = player->getPosition(); @@ -2875,6 +2876,7 @@ void the_game( else { fog_range = draw_control.wanted_range*BS + 0.0*MAP_BLOCKSIZE*BS; + fog_range = MYMIN(fog_range, (draw_control.farthest_drawn+30)*BS); fog_range *= 0.9; if(draw_control.range_all) fog_range = 100000*BS; |