Skip to content

Commit

Permalink
Add hack to avoid 2s startup delay on local games
Browse files Browse the repository at this point in the history
  • Loading branch information
sapier authored and sapier committed May 1, 2014
1 parent 4b44d35 commit 9370f56
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/client.cpp
Expand Up @@ -221,6 +221,11 @@ Client::Client(
MtEventManager *event, MtEventManager *event,
bool ipv6 bool ipv6
): ):
m_packetcounter_timer(0.0),
m_connection_reinit_timer(0.1),
m_avg_rtt_timer(0.0),
m_playerpos_send_timer(0.0),
m_ignore_damage_timer(0.0),
m_tsrc(tsrc), m_tsrc(tsrc),
m_shsrc(shsrc), m_shsrc(shsrc),
m_itemdef(itemdef), m_itemdef(itemdef),
Expand Down Expand Up @@ -258,13 +263,6 @@ Client::Client(
m_removed_sounds_check_timer(0), m_removed_sounds_check_timer(0),
m_state(LC_Created) m_state(LC_Created)
{ {
m_packetcounter_timer = 0.0;
//m_delete_unused_sectors_timer = 0.0;
m_connection_reinit_timer = 0.0;
m_avg_rtt_timer = 0.0;
m_playerpos_send_timer = 0.0;
m_ignore_damage_timer = 0.0;

/* /*
Add local player Add local player
*/ */
Expand Down Expand Up @@ -332,11 +330,11 @@ void Client::connect(Address address)
void Client::step(float dtime) void Client::step(float dtime)
{ {
DSTACK(__FUNCTION_NAME); DSTACK(__FUNCTION_NAME);

// Limit a bit // Limit a bit
if(dtime > 2.0) if(dtime > 2.0)
dtime = 2.0; dtime = 2.0;

if(m_ignore_damage_timer > dtime) if(m_ignore_damage_timer > dtime)
m_ignore_damage_timer -= dtime; m_ignore_damage_timer -= dtime;
else else
Expand All @@ -360,7 +358,8 @@ void Client::step(float dtime)
{ {
counter = 20.0; counter = 20.0;


infostream<<"Client packetcounter (20s):"<<std::endl; infostream << "Client packetcounter (" << m_packetcounter_timer
<< "):"<<std::endl;
m_packetcounter.print(infostream); m_packetcounter.print(infostream);
m_packetcounter.clear(); m_packetcounter.clear();
} }
Expand Down Expand Up @@ -456,8 +455,13 @@ void Client::step(float dtime)
} }
} }
#endif #endif

// UGLY hack to fix 2 second startup delay caused by non existent
if(m_state == LC_Created) // server client startup synchronization in local server or singleplayer mode
static bool initial_step = true;
if (initial_step) {
initial_step = false;
}
else if(m_state == LC_Created)
{ {
float &counter = m_connection_reinit_timer; float &counter = m_connection_reinit_timer;
counter -= dtime; counter -= dtime;
Expand All @@ -469,7 +473,6 @@ void Client::step(float dtime)


Player *myplayer = m_env.getLocalPlayer(); Player *myplayer = m_env.getLocalPlayer();
assert(myplayer != NULL); assert(myplayer != NULL);

// Send TOSERVER_INIT // Send TOSERVER_INIT
// [0] u16 TOSERVER_INIT // [0] u16 TOSERVER_INIT
// [2] u8 SER_FMT_VER_HIGHEST_READ // [2] u8 SER_FMT_VER_HIGHEST_READ
Expand Down

0 comments on commit 9370f56

Please sign in to comment.