diff --git a/src/client.cpp b/src/client.cpp index b0750cae6..d43b97a3c 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -67,7 +67,7 @@ Client::Client( IrrlichtDevice *device, const char *playername, JMutex &range_mutex, - s16 &viewing_range_nodes, + float &viewing_range_nodes, bool &viewing_range_all): m_thread(this), m_env(new ClientMap(this, diff --git a/src/client.h b/src/client.h index b29358d93..e48c8ec69 100644 --- a/src/client.h +++ b/src/client.h @@ -111,7 +111,7 @@ public: IrrlichtDevice *device, const char *playername, JMutex &range_mutex, - s16 &viewing_range_nodes, + float &viewing_range_nodes, bool &viewing_range_all ); diff --git a/src/main.cpp b/src/main.cpp index d22da3ff7..b7a1b6b32 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -257,7 +257,7 @@ IrrlichtWrapper *g_irrlicht; JMutex g_range_mutex; // Blocks are viewed in this range from the player -s16 g_viewing_range_nodes = 60; +float g_viewing_range_nodes = 60; //s16 g_viewing_range_nodes = 0; // This is updated by the client's fetchBlocks routine @@ -849,6 +849,7 @@ private: bool rightclicked; }; +#if 0 void updateViewingRange(f32 frametime, Client *client) { // Range_all messes up frametime_avg @@ -860,6 +861,9 @@ void updateViewingRange(f32 frametime, Client *client) // Initialize to the target value static float frametime_avg = 1.0/wanted_fps; //frametime_avg = frametime_avg * 0.9 + frametime * 0.1; + //frametime_avg = frametime_avg * 0.7 + frametime * 0.3; + //frametime_avg = frametime_avg * 0.5 + frametime * 0.5; + //frametime_avg = frametime_avg * 0.0 + frametime * 1.0; frametime_avg = frametime_avg * 0.7 + frametime * 0.3; static f32 counter = 0; @@ -869,6 +873,8 @@ void updateViewingRange(f32 frametime, Client *client) } //counter = 1.0; //seconds counter = 0.5; //seconds + //counter += 0.1; //seconds + //counter = 0.3; //seconds //float freetime_ratio = 0.2; //float freetime_ratio = 0.4; @@ -876,7 +882,20 @@ void updateViewingRange(f32 frametime, Client *client) float frametime_wanted = (1.0/(wanted_fps/(1.0-freetime_ratio))); - float fraction = sqrt(frametime_avg / frametime_wanted); + //float fraction = sqrt(frametime_avg / frametime_wanted); + //float fraction = pow(frametime_avg / frametime_wanted, 1./3); + + float fraction_unbiased = frametime_avg / frametime_wanted; + + float fraction = pow(fraction_unbiased, 20./(float)g_viewing_range_nodes); + + /*float fraction = 1.0; + // If frametime is too high + if(fraction_unbiased > 1.0) + fraction = pow(fraction_unbiased, 1./2); + // If frametime is too low + else + fraction = pow(fraction_unbiased, 1./5);*/ /*float fraction = sqrt(frametime_avg / frametime_wanted) / 2.0 + frametime_avg / frametime_wanted / 2.0;*/ @@ -887,8 +906,19 @@ void updateViewingRange(f32 frametime, Client *client) //float fraction_good_threshold = 0.1; //float fraction_bad_threshold = 0.25; - float fraction_good_threshold = 0.075; - float fraction_bad_threshold = 0.125; + + /*float fraction_good_threshold = 0.075; + float fraction_bad_threshold = 0.125;*/ + // If frametime is too low + /*if(fraction < 1.0) + { + fraction_good_threshold = pow(fraction_good_threshold, 4); + fraction_bad_threshold = pow(fraction_bad_threshold, 4); + }*/ + + float fraction_good_threshold = 0.23; + float fraction_bad_threshold = 0.33; + float fraction_limit; // Use high limit if fraction is good AND the fraction would // lower the range. We want to keep the range fairly high. @@ -897,7 +927,8 @@ void updateViewingRange(f32 frametime, Client *client) else fraction_limit = fraction_good_threshold; - if(fabs(fraction - 1.0) < fraction_limit) + //if(fabs(fraction - 1.0) < fraction_limit) + if(fabs(fraction_unbiased - 1.0) < fraction_limit) { fraction_is_good = true; return; @@ -934,6 +965,113 @@ void updateViewingRange(f32 frametime, Client *client) /*dstream<<"g_viewing_range_nodes = " < 0) + return; + //counter = 0.1; + counter = 0.2; + + dstream<<__FUNCTION_NAME + <<": Collected "< range_max) + new_range = range_max; + + if(new_range != new_range_unclamped) + dstream<<", clamped to "<setText(temptext); diff --git a/src/map.cpp b/src/map.cpp index 59053f70c..d5a61d408 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -2890,7 +2890,7 @@ void ServerMap::PrintInfo(std::ostream &out) ClientMap::ClientMap( Client *client, JMutex &range_mutex, - s16 &viewing_range_nodes, + float &viewing_range_nodes, bool &viewing_range_all, scene::ISceneNode* parent, scene::ISceneManager* mgr, @@ -3013,7 +3013,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) all changed nodes in viewing range at the next step. */ - s16 viewing_range_nodes; + float viewing_range_nodes; bool viewing_range_all; { JMutexAutoLock lock(m_range_mutex); diff --git a/src/map.h b/src/map.h index 3c3fe9daf..8952bc110 100644 --- a/src/map.h +++ b/src/map.h @@ -551,7 +551,7 @@ public: ClientMap( Client *client, JMutex &range_mutex, - s16 &viewing_range_nodes, + float &viewing_range_nodes, bool &viewing_range_all, scene::ISceneNode* parent, scene::ISceneManager* mgr, @@ -620,7 +620,7 @@ private: JMutex mesh_mutex; JMutex &m_range_mutex; - s16 &m_viewing_range_nodes; + float &m_viewing_range_nodes; bool &m_viewing_range_all; };