Skip to content

Commit

Permalink
Cache some settings
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy authored and paramat committed Feb 26, 2016
1 parent f77b35b commit 4efb7eb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
10 changes: 4 additions & 6 deletions src/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,8 @@ void ServerEnvironment::step(float dtime)
// Update this one
// NOTE: This is kind of funny on a singleplayer game, but doesn't
// really matter that much.
m_recommended_send_interval = g_settings->getFloat("dedicated_server_step");
static const float server_step = g_settings->getFloat("dedicated_server_step");
m_recommended_send_interval = server_step;

/*
Increment game time
Expand Down Expand Up @@ -1086,7 +1087,7 @@ void ServerEnvironment::step(float dtime)
/*
Update list of active blocks, collecting changes
*/
const s16 active_block_range = g_settings->getS16("active_block_range");
static const s16 active_block_range = g_settings->getS16("active_block_range");
std::set<v3s16> blocks_removed;
std::set<v3s16> blocks_added;
m_active_blocks.update(players_blockpos, active_block_range,
Expand All @@ -1101,8 +1102,7 @@ void ServerEnvironment::step(float dtime)

for(std::set<v3s16>::iterator
i = blocks_removed.begin();
i != blocks_removed.end(); ++i)
{
i != blocks_removed.end(); ++i) {
v3s16 p = *i;

/* infostream<<"Server: Block " << PP(p)
Expand Down Expand Up @@ -2636,5 +2636,3 @@ ClientEnvEvent ClientEnvironment::getClientEvent()
}

#endif // #ifndef SERVER


39 changes: 20 additions & 19 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,16 +671,18 @@ void Server::AsyncRunStep(bool initial_step)
ScopeProfiler sp(g_profiler, "Server: checking added and deleted objs");

// Radius inside which objects are active
s16 radius = g_settings->getS16("active_object_send_range_blocks");
s16 player_radius = g_settings->getS16("player_transfer_distance");

if (player_radius == 0 && g_settings->exists("unlimited_player_transfer_distance") &&
!g_settings->getBool("unlimited_player_transfer_distance"))
static const s16 radius =
g_settings->getS16("active_object_send_range_blocks") * MAP_BLOCKSIZE;

// Radius inside which players are active
static const bool is_transfer_limited =
g_settings->exists("unlimited_player_transfer_distance") &&
!g_settings->getBool("unlimited_player_transfer_distance");
static const s16 player_transfer_dist = g_settings->getS16("player_transfer_distance") * MAP_BLOCKSIZE;
s16 player_radius = player_transfer_dist;
if (player_radius == 0 && is_transfer_limited)
player_radius = radius;

radius *= MAP_BLOCKSIZE;
player_radius *= MAP_BLOCKSIZE;

for (std::map<u16, RemoteClient*>::iterator
i = clients.begin();
i != clients.end(); ++i) {
Expand Down Expand Up @@ -984,8 +986,7 @@ void Server::AsyncRunStep(bool initial_step)
{
float &counter = m_emergethread_trigger_timer;
counter += dtime;
if(counter >= 2.0)
{
if (counter >= 2.0) {
counter = 0.0;

m_emerge->startThreads();
Expand All @@ -996,8 +997,9 @@ void Server::AsyncRunStep(bool initial_step)
{
float &counter = m_savemap_timer;
counter += dtime;
if(counter >= g_settings->getFloat("server_map_save_interval"))
{
static const float save_interval =
g_settings->getFloat("server_map_save_interval");
if (counter >= save_interval) {
counter = 0.0;
MutexAutoLock lock(m_env_mutex);

Expand Down Expand Up @@ -3512,9 +3514,11 @@ void dedicated_server_loop(Server &server, bool &kill)

IntervalLimiter m_profiler_interval;

for(;;)
{
float steplen = g_settings->getFloat("dedicated_server_step");
static const float steplen = g_settings->getFloat("dedicated_server_step");
static const float profiler_print_interval =
g_settings->getFloat("profiler_print_interval");

for(;;) {
// This is kind of a hack but can be done like this
// because server.step() is very light
{
Expand All @@ -3536,10 +3540,7 @@ void dedicated_server_loop(Server &server, bool &kill)
/*
Profiler
*/
float profiler_print_interval =
g_settings->getFloat("profiler_print_interval");
if(profiler_print_interval != 0)
{
if (profiler_print_interval != 0) {
if(m_profiler_interval.step(steplen, profiler_print_interval))
{
infostream<<"Profiler:"<<std::endl;
Expand Down

0 comments on commit 4efb7eb

Please sign in to comment.