From c32da52104cc6bbe8ed0bf1ba1a7874f015cb738 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 26 Dec 2010 13:51:56 +0200 Subject: working good --- src/main.cpp | 148 ++++++----------------------------------------------------- 1 file changed, 15 insertions(+), 133 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 2f22caeb0..bd0ebd8ca 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -820,7 +820,7 @@ public: s32 Rand(s32 min, s32 max) { - return (rand()%(max-min+1))+min; + return (myrand()%(max-min+1))+min; } private: bool keydown[KEY_KEY_CODES_COUNT]; @@ -830,124 +830,6 @@ private: bool rightclicked; }; -#if 0 -void updateViewingRange(f32 frametime, Client *client) -{ - // Range_all messes up frametime_avg - if(draw_control.range_all == true) - return; - - float wanted_fps = g_settings.getFloat("wanted_fps"); - - // 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; - if(counter > 0){ - counter -= frametime; - return; - } - //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; - float freetime_ratio = FREETIME_RATIO; - - float frametime_wanted = (1.0/(wanted_fps/(1.0-freetime_ratio))); - - //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)draw_control.wanted_range); - - /*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;*/ - - //float fraction = frametime_avg / frametime_wanted; - - static bool fraction_is_good = false; - - //float fraction_good_threshold = 0.1; - //float fraction_bad_threshold = 0.25; - - /*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. - if(fraction_is_good && fraction > 1.0) - fraction_limit = fraction_bad_threshold; - else - fraction_limit = fraction_good_threshold; - - //if(fabs(fraction - 1.0) < fraction_limit) - if(fabs(fraction_unbiased - 1.0) < fraction_limit) - { - fraction_is_good = true; - return; - } - else - { - fraction_is_good = false; - } - - //dstream<<"frametime_avg="< viewing_range_nodes_max) - n = viewing_range_nodes_max; - - bool can_change = true; - - if(client->isFetchingBlocks() == true && n > draw_control.wanted_range) - can_change = false; - - if(can_change) - draw_control.wanted_range = n; - - /*dstream<<"draw_control.wanted_range = " - <