f32 n = avgDiagNeighbours(center, a/2);
// Add (-1.0...1.0) * randmax
- n += ((float)rand() / (float)(RAND_MAX/2) - 1.0)*randmax;
+ n += ((float)myrand() / (float)(MYRAND_MAX/2) - 1.0)*randmax;
bool worked = setGroundHeightParent(center, n);
if(a >= 2 && worked)
f32 n = avgNeighbours(center, a/2);
// Add (-1.0...1.0) * randmax
- n += ((float)rand() / (float)(RAND_MAX/2) - 1.0)*randmax;
+ n += ((float)myrand() / (float)(MYRAND_MAX/2) - 1.0)*randmax;
bool worked = setGroundHeightParent(center, n);
if(a >= 4 && worked)
\r
s32 Rand(s32 min, s32 max)\r
{\r
- return (rand()%(max-min+1))+min;\r
+ return (myrand()%(max-min+1))+min;\r
}\r
private:\r
bool keydown[KEY_KEY_CODES_COUNT];\r
bool rightclicked;\r
};\r
\r
-#if 0\r
-void updateViewingRange(f32 frametime, Client *client)\r
-{\r
- // Range_all messes up frametime_avg\r
- if(draw_control.range_all == true)\r
- return;\r
-\r
- float wanted_fps = g_settings.getFloat("wanted_fps");\r
- \r
- // Initialize to the target value\r
- static float frametime_avg = 1.0/wanted_fps;\r
- //frametime_avg = frametime_avg * 0.9 + frametime * 0.1;\r
- //frametime_avg = frametime_avg * 0.7 + frametime * 0.3;\r
- //frametime_avg = frametime_avg * 0.5 + frametime * 0.5;\r
- //frametime_avg = frametime_avg * 0.0 + frametime * 1.0;\r
- frametime_avg = frametime_avg * 0.7 + frametime * 0.3;\r
-\r
- static f32 counter = 0;\r
- if(counter > 0){\r
- counter -= frametime;\r
- return;\r
- }\r
- //counter = 1.0; //seconds\r
- counter = 0.5; //seconds\r
- //counter += 0.1; //seconds\r
- //counter = 0.3; //seconds\r
-\r
- //float freetime_ratio = 0.2;\r
- //float freetime_ratio = 0.4;\r
- float freetime_ratio = FREETIME_RATIO;\r
-\r
- float frametime_wanted = (1.0/(wanted_fps/(1.0-freetime_ratio)));\r
-\r
- //float fraction = sqrt(frametime_avg / frametime_wanted);\r
- //float fraction = pow(frametime_avg / frametime_wanted, 1./3);\r
-\r
- float fraction_unbiased = frametime_avg / frametime_wanted;\r
-\r
- float fraction = pow(fraction_unbiased, 20./(float)draw_control.wanted_range);\r
- \r
- /*float fraction = 1.0;\r
- // If frametime is too high\r
- if(fraction_unbiased > 1.0)\r
- fraction = pow(fraction_unbiased, 1./2);\r
- // If frametime is too low\r
- else\r
- fraction = pow(fraction_unbiased, 1./5);*/\r
-\r
- /*float fraction = sqrt(frametime_avg / frametime_wanted) / 2.0\r
- + frametime_avg / frametime_wanted / 2.0;*/\r
- \r
- //float fraction = frametime_avg / frametime_wanted;\r
-\r
- static bool fraction_is_good = false;\r
- \r
- //float fraction_good_threshold = 0.1;\r
- //float fraction_bad_threshold = 0.25;\r
-\r
- /*float fraction_good_threshold = 0.075;\r
- float fraction_bad_threshold = 0.125;*/\r
- // If frametime is too low\r
- /*if(fraction < 1.0)\r
- {\r
- fraction_good_threshold = pow(fraction_good_threshold, 4);\r
- fraction_bad_threshold = pow(fraction_bad_threshold, 4);\r
- }*/\r
-\r
- float fraction_good_threshold = 0.23;\r
- float fraction_bad_threshold = 0.33;\r
- \r
- float fraction_limit;\r
- // Use high limit if fraction is good AND the fraction would\r
- // lower the range. We want to keep the range fairly high.\r
- if(fraction_is_good && fraction > 1.0)\r
- fraction_limit = fraction_bad_threshold;\r
- else\r
- fraction_limit = fraction_good_threshold;\r
-\r
- //if(fabs(fraction - 1.0) < fraction_limit)\r
- if(fabs(fraction_unbiased - 1.0) < fraction_limit)\r
- {\r
- fraction_is_good = true;\r
- return;\r
- }\r
- else\r
- {\r
- fraction_is_good = false;\r
- }\r
-\r
- //dstream<<"frametime_avg="<<frametime_avg<<std::endl;\r
- //dstream<<"frametime_wanted="<<frametime_wanted<<std::endl;\r
- /*dstream<<"fetching="<<client->isFetchingBlocks()\r
- <<" faction = "<<fraction<<std::endl;*/\r
-\r
- JMutexAutoLock lock(g_range_mutex);\r
- \r
- s16 viewing_range_nodes_min = g_settings.getS16("viewing_range_nodes_min");\r
- s16 viewing_range_nodes_max = g_settings.getS16("viewing_range_nodes_max");\r
-\r
- s16 n = (float)draw_control.wanted_range / fraction;\r
- if(n < viewing_range_nodes_min)\r
- n = viewing_range_nodes_min;\r
- if(n > viewing_range_nodes_max)\r
- n = viewing_range_nodes_max;\r
-\r
- bool can_change = true;\r
-\r
- if(client->isFetchingBlocks() == true && n > draw_control.wanted_range)\r
- can_change = false;\r
- \r
- if(can_change)\r
- draw_control.wanted_range = n;\r
-\r
- /*dstream<<"draw_control.wanted_range = "\r
- <<draw_control.wanted_range<<std::endl;*/\r
-}\r
-#endif\r
-\r
void updateViewingRange(f32 frametime_in, Client *client)\r
{\r
if(draw_control.range_all == true)\r
//counter = 0.1;\r
counter = 0.2;\r
\r
- dstream<<__FUNCTION_NAME\r
+ /*dstream<<__FUNCTION_NAME\r
<<": Collected "<<added_frames<<" frames, total of "\r
- <<added_frametime<<"s."<<std::endl;\r
+ <<added_frametime<<"s."<<std::endl;*/\r
\r
- dstream<<"draw_control.blocks_drawn="\r
+ /*dstream<<"draw_control.blocks_drawn="\r
<<draw_control.blocks_drawn\r
<<", draw_control.blocks_would_have_drawn="\r
<<draw_control.blocks_would_have_drawn\r
- <<std::endl;\r
+ <<std::endl;*/\r
\r
float range_min = g_settings.getS16("viewing_range_nodes_min");\r
float range_max = g_settings.getS16("viewing_range_nodes_max");\r
float wanted_frametime = 1.0 / wanted_fps;\r
\r
f32 wanted_frametime_change = wanted_frametime - frametime;\r
- dstream<<"wanted_frametime_change="<<wanted_frametime_change<<std::endl;\r
+ //dstream<<"wanted_frametime_change="<<wanted_frametime_change<<std::endl;\r
\r
// If needed frametime change is very small, just return\r
if(fabs(wanted_frametime_change) < wanted_frametime*0.2)\r
{\r
- dstream<<"ignoring small wanted_frametime_change"<<std::endl;\r
+ //dstream<<"ignoring small wanted_frametime_change"<<std::endl;\r
return;\r
}\r
\r
if(time_per_range < min_time_per_range)\r
{\r
time_per_range = min_time_per_range;\r
- dstream<<"time_per_range="<<time_per_range<<" (min)"<<std::endl;\r
+ //dstream<<"time_per_range="<<time_per_range<<" (min)"<<std::endl;\r
}\r
else\r
{\r
- dstream<<"time_per_range="<<time_per_range<<std::endl;\r
+ //dstream<<"time_per_range="<<time_per_range<<std::endl;\r
}\r
\r
f32 wanted_range_change = wanted_frametime_change / time_per_range;\r
//wanted_range_change *= 0.9;\r
//wanted_range_change *= 0.75;\r
wanted_range_change *= 0.5;\r
- dstream<<"wanted_range_change="<<wanted_range_change<<std::endl;\r
+ //dstream<<"wanted_range_change="<<wanted_range_change<<std::endl;\r
\r
// If needed range change is very small, just return\r
if(fabs(wanted_range_change) < 0.001)\r
{\r
- dstream<<"ignoring small wanted_range_change"<<std::endl;\r
+ //dstream<<"ignoring small wanted_range_change"<<std::endl;\r
return;\r
}\r
\r
new_range += wanted_range_change;\r
- dstream<<"new_range="<<new_range/*<<std::endl*/;\r
+ //dstream<<"new_range="<<new_range/*<<std::endl*/;\r
\r
- float new_range_unclamped = new_range;\r
+ //float new_range_unclamped = new_range;\r
if(new_range < range_min)\r
new_range = range_min;\r
if(new_range > range_max)\r
new_range = range_max;\r
\r
- if(new_range != new_range_unclamped)\r
+ /*if(new_range != new_range_unclamped)\r
dstream<<", clamped to "<<new_range<<std::endl;\r
else\r
- dstream<<std::endl;\r
+ dstream<<std::endl;*/\r
\r
draw_control.wanted_range = new_range;\r
\r
#include "voxel.h"
#include "porting.h"
-#if 0
-MapBlockPointerCache::MapBlockPointerCache(Map *map)
-{
- m_map = map;
- m_map->m_blockcachelock.cacheCreated();
-
- m_from_cache_count = 0;
- m_from_map_count = 0;
-}
-
-MapBlockPointerCache::~MapBlockPointerCache()
-{
- m_map->m_blockcachelock.cacheRemoved();
-
- /*dstream<<"MapBlockPointerCache:"
- <<" from_cache_count="<<m_from_cache_count
- <<" from_map_count="<<m_from_map_count
- <<std::endl;*/
-}
-
-MapBlock * MapBlockPointerCache::getBlockNoCreate(v3s16 p)
-{
- core::map<v3s16, MapBlock*>::Node *n = NULL;
- n = m_blocks.find(p);
- if(n != NULL)
- {
- m_from_cache_count++;
- return n->getValue();
- }
-
- m_from_map_count++;
-
- // Throws InvalidPositionException if not found
- MapBlock *b = m_map->getBlockNoCreate(p);
- m_blocks[p] = b;
- return b;
-}
-#endif
-
/*
Map
*/
tree_max = a / (t/0.03);
else
tree_max = a;
- u32 count = (rand()%(tree_max+1));
+ u32 count = (myrand()%(tree_max+1));
//u32 count = tree_max;
for(u32 i=0; i<count; i++)
{
- s16 x = (rand()%(MAP_BLOCKSIZE-2))+1;
- s16 z = (rand()%(MAP_BLOCKSIZE-2))+1;
+ s16 x = (myrand()%(MAP_BLOCKSIZE-2))+1;
+ s16 z = (myrand()%(MAP_BLOCKSIZE-2))+1;
s16 y = sector->getGroundHeight(v2s16(x,z))+1;
if(y < WATER_LEVEL)
continue;
bush_max = (pitness*a*4);
if(bush_max > a)
bush_max = a;
- u32 count = (rand()%(bush_max+1));
+ u32 count = (myrand()%(bush_max+1));
for(u32 i=0; i<count; i++)
{
- s16 x = rand()%(MAP_BLOCKSIZE-0)+0;
- s16 z = rand()%(MAP_BLOCKSIZE-0)+0;
+ s16 x = myrand()%(MAP_BLOCKSIZE-0)+0;
+ s16 z = myrand()%(MAP_BLOCKSIZE-0)+0;
s16 y = sector->getGroundHeight(v2s16(x,z))+1;
if(y < WATER_LEVEL)
continue;
*/
if(m_params.ravines_amount != 0)
{
- if(rand()%(s32)(20.0 / m_params.ravines_amount) == 0)
+ if(myrand()%(s32)(20.0 / m_params.ravines_amount) == 0)
{
s16 s = 6;
- s16 x = rand()%(MAP_BLOCKSIZE-s*2-1)+s;
- s16 z = rand()%(MAP_BLOCKSIZE-s*2-1)+s;
+ s16 x = myrand()%(MAP_BLOCKSIZE-s*2-1)+s;
+ s16 z = myrand()%(MAP_BLOCKSIZE-s*2-1)+s;
/*s16 x = 8;
s16 z = 8;*/
s16 y = sector->getGroundHeight(v2s16(x,z))+1;
const s32 ued_max = 5;
const s32 ued_min = 3;
bool underground_emptiness[ued_max*ued_max*ued_max];
- s32 ued = (rand()%(ued_max-ued_min+1))+1;
+ s32 ued = (myrand()%(ued_max-ued_min+1))+1;
//s32 ued = ued_max;
for(s32 i=0; i<ued*ued*ued; i++)
{
- underground_emptiness[i] = ((rand() % 5) == 0);
+ underground_emptiness[i] = ((myrand() % 5) == 0);
}
/*
*/
v3f orp(
- (float)(rand()%ued)+0.5,
- (float)(rand()%ued)+0.5,
- (float)(rand()%ued)+0.5
+ (float)(myrand()%ued)+0.5,
+ (float)(myrand()%ued)+0.5,
+ (float)(myrand()%ued)+0.5
);
// Check z-
for(u16 i=0; i<3; i++)
{
v3f rp(
- (float)(rand()%ued)+0.5,
- (float)(rand()%ued)+0.5,
- (float)(rand()%ued)+0.5
+ (float)(myrand()%ued)+0.5,
+ (float)(myrand()%ued)+0.5,
+ (float)(myrand()%ued)+0.5
);
s16 min_d = 0;
s16 max_d = 4;
- s16 rs = (rand()%(max_d-min_d+1))+min_d;
+ s16 rs = (myrand()%(max_d-min_d+1))+min_d;
v3f vec = rp - orp;
*/
for(s16 i=0; i<underground_level*1; i++)
{
- if(rand()%2 == 0)
+ if(myrand()%2 == 0)
{
v3s16 cp(
- (rand()%(MAP_BLOCKSIZE-2))+1,
- (rand()%(MAP_BLOCKSIZE-2))+1,
- (rand()%(MAP_BLOCKSIZE-2))+1
+ (myrand()%(MAP_BLOCKSIZE-2))+1,
+ (myrand()%(MAP_BLOCKSIZE-2))+1,
+ (myrand()%(MAP_BLOCKSIZE-2))+1
);
MapNode n;
//if(is_ground_content(block->getNode(cp).d))
if(block->getNode(cp).d == CONTENT_STONE)
- if(rand()%8 == 0)
+ if(myrand()%8 == 0)
block->setNode(cp, n);
for(u16 i=0; i<26; i++)
{
//if(is_ground_content(block->getNode(cp+g_26dirs[i]).d))
if(block->getNode(cp+g_26dirs[i]).d == CONTENT_STONE)
- if(rand()%8 == 0)
+ if(myrand()%8 == 0)
block->setNode(cp+g_26dirs[i], n);
}
}
u16 coal_rareness = 60 / coal_amount;
if(coal_rareness == 0)
coal_rareness = 1;
- if(rand()%coal_rareness == 0)
+ if(myrand()%coal_rareness == 0)
{
- u16 a = rand() % 16;
+ u16 a = myrand() % 16;
u16 amount = coal_amount * a*a*a / 1000;
for(s16 i=0; i<amount; i++)
{
v3s16 cp(
- (rand()%(MAP_BLOCKSIZE-2))+1,
- (rand()%(MAP_BLOCKSIZE-2))+1,
- (rand()%(MAP_BLOCKSIZE-2))+1
+ (myrand()%(MAP_BLOCKSIZE-2))+1,
+ (myrand()%(MAP_BLOCKSIZE-2))+1,
+ (myrand()%(MAP_BLOCKSIZE-2))+1
);
MapNode n;
//if(is_ground_content(block->getNode(cp).d))
if(block->getNode(cp).d == CONTENT_STONE)
- if(rand()%8 == 0)
+ if(myrand()%8 == 0)
block->setNode(cp, n);
for(u16 i=0; i<26; i++)
{
//if(is_ground_content(block->getNode(cp+g_26dirs[i]).d))
if(block->getNode(cp+g_26dirs[i]).d == CONTENT_STONE)
- if(rand()%8 == 0)
+ if(myrand()%8 == 0)
block->setNode(cp+g_26dirs[i], n);
}
}
//for(u16 i=0; i<2; i++)
{
v3s16 cp(
- (rand()%(MAP_BLOCKSIZE-2))+1,
- (rand()%(MAP_BLOCKSIZE-2))+1,
- (rand()%(MAP_BLOCKSIZE-2))+1
+ (myrand()%(MAP_BLOCKSIZE-2))+1,
+ (myrand()%(MAP_BLOCKSIZE-2))+1,
+ (myrand()%(MAP_BLOCKSIZE-2))+1
);
// Check that the place is empty
n.d = CONTENT_STONE;
MapNode n2;
n2.d = CONTENT_AIR;
- s16 depth = maxdepth + (rand()%10);
+ s16 depth = maxdepth + (myrand()%10);
s16 z = 0;
s16 minz = -6 - (-2);
s16 maxz = 6 -1;
for(s16 x=-6; x<=6; x++)
{
- z += -1 + (rand()%3);
+ z += -1 + (myrand()%3);
if(z < minz)
z = minz;
if(z > maxz)
z = maxz;
- for(s16 y=depth+(rand()%2); y<=6; y++)
+ for(s16 y=depth+(myrand()%2); y<=6; y++)
{
/*std::cout<<"("<<p2.X<<","<<p2.Y<<","<<p2.Z<<")"
<<std::endl;*/
m_spawn_timer -= dtime;
if(m_spawn_timer <= 0.0)
{
- m_spawn_timer += rand() % 300;
+ m_spawn_timer += myrand() % 300;
v2s16 p2d(
- (rand()%(MAP_BLOCKSIZE-1))+0,
- (rand()%(MAP_BLOCKSIZE-1))+0
+ (myrand()%(MAP_BLOCKSIZE-1))+0,
+ (myrand()%(MAP_BLOCKSIZE-1))+0
);
s16 y = getGroundLevel(p2d);
m_counter2 -= dtime;
if(m_counter2 < 0.0)
{
- m_counter2 += (float)(rand()%100)/100*3.0;
- m_yaw += ((float)(rand()%200)-100)/100*180;
+ m_counter2 += (float)(myrand()%100)/100*3.0;
+ m_yaw += ((float)(myrand()%200)-100)/100*180;
m_yaw = wrapDegrees(m_yaw);
}
}
#include <iostream>
#include <stdlib.h>
#include <errno.h>
+#include "utility.h"
// Debug printing options
#define DP 0
{
bool dumping_packet = false;
if(INTERNET_SIMULATOR)
- dumping_packet = (rand()%10==0); //easy
- //dumping_packet = (rand()%4==0); // hard
+ dumping_packet = (myrand()%10==0); //easy
+ //dumping_packet = (myrand()%4==0); // hard
if(DP){
/*dstream<<DPS<<"UDPSocket("<<(int)m_handle
void Random()
{
dstream<<"Running random code (get a human to check this)"<<std::endl;
- dstream<<"rand() values: ";
+ dstream<<"myrand() values: ";
for(u16 i=0; i<5; i++)
- dstream<<(u16)rand()<<" ";
+ dstream<<(u16)myrand()<<" ";
dstream<<std::endl;
const s16 BS1 = 8;
*/
s32 k = 0;
if(active_nodes.size() != 0)
- k = (s32)rand() % (s32)active_nodes.size();
+ k = (s32)myrand() % (s32)active_nodes.size();
// Flow water to active nodes
for(;;)