// Increment timers
m_nothing_to_send_pause_timer -= dtime;
+ m_nearest_unsent_reset_timer += dtime;
if(m_nothing_to_send_pause_timer >= 0)
{
- // Keep this reset
- m_nearest_unsent_reset_timer = 0;
return;
}
/*infostream<<"m_nearest_unsent_reset_timer="
<<m_nearest_unsent_reset_timer<<std::endl;*/
- // This has to be incremented only when the nothing to send pause
- // is not active
- m_nearest_unsent_reset_timer += dtime;
-
- // Reset periodically to avoid possible bugs or other mishaps
- if(m_nearest_unsent_reset_timer > 10.0)
+ // Reset periodically to workaround for some bugs or stuff
+ if(m_nearest_unsent_reset_timer > 20.0)
{
m_nearest_unsent_reset_timer = 0;
m_nearest_unsent_d = 0;
- /*infostream<<"Resetting m_nearest_unsent_d for "
- <<server->getPlayerName(peer_id)<<std::endl;*/
+ //infostream<<"Resetting m_nearest_unsent_d for "
+ // <<server->getPlayerName(peer_id)<<std::endl;
}
//s16 last_nearest_unsent_d = m_nearest_unsent_d;
s16 d_max_gen = g_settings->getS16("max_block_generate_distance");
// Don't loop very much at a time
- if(d_max > d_start+1)
- d_max = d_start+1;
+ s16 max_d_increment_at_time = 2;
+ if(d_max > d_start + max_d_increment_at_time)
+ d_max = d_start + max_d_increment_at_time;
/*if(d_max_gen > d_start+2)
d_max_gen = d_start+2;*/
//infostream<<"Starting from "<<d_start<<std::endl;
- bool sending_something = false;
-
- bool no_blocks_found_for_sending = true;
-
+ s32 nearest_emerged_d = -1;
+ s32 nearest_emergefull_d = -1;
+ s32 nearest_sent_d = -1;
bool queue_is_full = false;
s16 d;
for(d = d_start; d <= d_max; d++)
{
+ /*errorstream<<"checking d="<<d<<" for "
+ <<server->getPlayerName(peer_id)<<std::endl;*/
//infostream<<"RemoteClient::SendBlocks(): d="<<d<<std::endl;
/*
if(abs(p.Y - center.Y) > d_max_gen - d_max_gen / 3)
generate = false;*/
- // Limit the send area vertically to 2/3
- if(abs(p.Y - center.Y) > d_max_gen - d_max_gen / 3)
+ // Limit the send area vertically to 1/2
+ if(abs(p.Y - center.Y) > d_max / 2)
continue;
}
-#if 1
+#if 0
/*
If block is far away, don't generate it unless it is
near ground level.
#endif
//infostream<<"d="<<d<<std::endl;
-
+#if 1
/*
Don't generate or send if not in sight
FIXME This only works if the client uses a small enough
{
continue;
}
-
+#endif
/*
Don't send already sent blocks
*/
Block is near ground level if night-time mesh
differs from day-time mesh.
*/
- if(d > 3)
+ if(d >= 4)
{
if(block->dayNightDiffed() == false)
continue;
continue;
}
- /*
- Record the lowest d from which a block has been
- found being not sent and possibly to exist
- */
- if(no_blocks_found_for_sending)
- {
- if(generate == true)
- new_nearest_unsent_d = d;
- }
-
- no_blocks_found_for_sending = false;
-
/*
Add inexistent block to emerge queue.
*/
// Allow only one block in emerge queue
//if(server->m_emerge_queue.peerItemCount(peer_id) < 1)
// Allow two blocks in queue per client
- if(server->m_emerge_queue.peerItemCount(peer_id) < 2)
+ //if(server->m_emerge_queue.peerItemCount(peer_id) < 2)
+ if(server->m_emerge_queue.peerItemCount(peer_id) < 25)
{
//infostream<<"Adding block to emerge queue"<<std::endl;
server->m_emerge_queue.addBlock(peer_id, p, flags);
server->m_emergethread.trigger();
+
+ if(nearest_emerged_d == -1)
+ nearest_emerged_d = d;
+ } else {
+ if(nearest_emergefull_d == -1)
+ nearest_emergefull_d = d;
}
// get next one.
continue;
}
+ if(nearest_sent_d == -1)
+ nearest_sent_d = d;
+
/*
Add block to send queue
*/
+ /*errorstream<<"sending from d="<<d<<" to "
+ <<server->getPlayerName(peer_id)<<std::endl;*/
+
PrioritySortedBlockTransfer q((float)d, p, peer_id);
dest.push_back(q);
num_blocks_selected += 1;
- sending_something = true;
}
}
queue_full_break:
//infostream<<"Stopped at "<<d<<std::endl;
- if(no_blocks_found_for_sending)
- {
- if(queue_is_full == false)
- new_nearest_unsent_d = d;
+ // If nothing was found for sending and nothing was queued for
+ // emerging, continue next time browsing from here
+ if(nearest_emerged_d != -1){
+ new_nearest_unsent_d = nearest_emerged_d;
+ } else if(nearest_emergefull_d != -1){
+ new_nearest_unsent_d = nearest_emergefull_d;
+ } else {
+ if(d > g_settings->getS16("max_block_send_distance")){
+ new_nearest_unsent_d = 0;
+ m_nothing_to_send_pause_timer = 2.0;
+ /*infostream<<"GetNextBlocks(): d wrapped around for "
+ <<server->getPlayerName(peer_id)
+ <<"; setting to 0 and pausing"<<std::endl;*/
+ } else {
+ if(nearest_sent_d != -1)
+ new_nearest_unsent_d = nearest_sent_d;
+ else
+ new_nearest_unsent_d = d;
+ }
}
if(new_nearest_unsent_d != -1)
m_nearest_unsent_d = new_nearest_unsent_d;
- if(sending_something == false)
- {
- m_nothing_to_send_counter++;
- if((s16)m_nothing_to_send_counter >=
- g_settings->getS16("max_block_send_distance"))
- {
- // Pause time in seconds
- m_nothing_to_send_pause_timer = 1.0;
- /*infostream<<"nothing to send to "
- <<server->getPlayerName(peer_id)
- <<" (d="<<d<<")"<<std::endl;*/
- }
- }
- else
- {
- m_nothing_to_send_counter = 0;
- }
-
/*timer_result = timer.stop(true);
if(timer_result != 0)
infostream<<"GetNextBlocks duration: "<<timer_result<<" (!=0)"<<std::endl;*/
JMutexAutoLock envlock(m_env_mutex);
JMutexAutoLock conlock(m_con_mutex);
- ScopeProfiler sp(g_profiler, "Server: sending object messages");
+ //ScopeProfiler sp(g_profiler, "Server: sending object messages");
// Key = object id
// Value = data sent by object
JMutexAutoLock lock1(m_env_mutex);
JMutexAutoLock lock2(m_con_mutex);
- ScopeProfiler sp(g_profiler, "Server: sending player positions");
+ //ScopeProfiler sp(g_profiler, "Server: sending player positions");
SendObjectData(counter);