ThreadStarted();
DSTACK(__FUNCTION_NAME);
-
-#if CATCH_UNHANDLED_EXCEPTIONS
- try
+
+ BEGIN_DEBUG_EXCEPTION_HANDLER
+
+ while(getRun())
{
-#endif
- while(getRun())
- {
- m_client->asyncStep();
+ m_client->asyncStep();
- //m_client->updateSomeExpiredMeshes();
+ //m_client->updateSomeExpiredMeshes();
- bool was = m_client->AsyncProcessData();
+ bool was = m_client->AsyncProcessData();
- if(was == false)
- sleep_ms(10);
- }
-#if CATCH_UNHANDLED_EXCEPTIONS
+ if(was == false)
+ sleep_ms(10);
}
- /*
- This is what has to be done in threads to get suitable debug info
- */
- catch(std::exception &e)
- {
- dstream<<std::endl<<DTIME<<"An unhandled exception occurred: "
- <<e.what()<<std::endl;
- assert(0);
- }
-#endif
+
+ END_DEBUG_EXCEPTION_HANDLER
return NULL;
}
Client::Client(
IrrlichtDevice *device,
const char *playername,
- JMutex &range_mutex,
- s16 &viewing_range_nodes,
- bool &viewing_range_all):
+ MapDrawControl &control):
m_thread(this),
- m_env(new ClientMap(this,
- range_mutex,
- viewing_range_nodes,
- viewing_range_all,
+ m_env(new ClientMap(this, control,
device->getSceneManager()->getRootSceneNode(),
device->getSceneManager(), 666),
dout_client),
Client::~Client()
{
+ {
+ JMutexAutoLock conlock(m_con_mutex);
+ m_con.Disconnect();
+ }
+
m_thread.setRun(false);
while(m_thread.IsRunning())
sleep_ms(100);
if(dtime > 2.0)
dtime = 2.0;
- /*
- Day/night
- */
- {
- s32 d = 8;
- s32 t = (((m_time_of_day.get() + 24000/d/2)%24000)/(24000/d));
- s32 dn = 0;
- if(t == d/4 || t == (d-d/4))
- dn = 1;
- else if(t < d/4 || t > (d-d/4))
- dn = 2;
- else
- dn = 0;
-
- u32 dr = 1000;
- if(dn == 0)
- dr = 1000;
- if(dn == 1)
- dr = 600;
- if(dn == 2)
- dr = 300;
-
- if(dr != m_env.getDayNightRatio())
- {
- //dstream<<"dr="<<dr<<std::endl;
- dout_client<<DTIME<<"Client: changing day-night ratio"<<std::endl;
- m_env.setDayNightRatio(dr);
- m_env.expireMeshes(true);
- }
- }
-
//dstream<<"Client steps "<<dtime<<std::endl;
addNode(p, n);
}
- if(command == TOCLIENT_PLAYERPOS)
+ else if(command == TOCLIENT_PLAYERPOS)
{
dstream<<"WARNING: Received deprecated TOCLIENT_PLAYERPOS"
<<std::endl;
our_peer_id = m_con.GetPeerID();
}
// Cancel if we don't have a peer id
- if(our_peer_id == PEER_ID_NEW){
+ if(our_peer_id == PEER_ID_INEXISTENT){
dout_client<<DTIME<<"TOCLIENT_PLAYERPOS cancelled: "
"we have no peer id"
<<std::endl;
our_peer_id = m_con.GetPeerID();
}
// Cancel if we don't have a peer id
- if(our_peer_id == PEER_ID_NEW){
+ if(our_peer_id == PEER_ID_INEXISTENT){
dout_client<<DTIME<<"TOCLIENT_PLAYERINFO cancelled: "
"we have no peer id"
<<std::endl;
time = time % 24000;
m_time_of_day.set(time);
//dstream<<"Client: time="<<time<<std::endl;
+
+ /*
+ Day/night
+
+ time_of_day:
+ 0 = midnight
+ 12000 = midday
+ */
+ {
+ const s32 daylength = 8;
+ const s32 nightlength = 2;
+ const s32 daytimelength = 4;
+ s32 d = daylength;
+ s32 t = (((m_time_of_day.get())%24000)/(24000/d));
+ u32 dr;
+ if(t < nightlength/2 || t >= d - nightlength/2)
+ dr = 350;
+ else if(t >= d/2 - daytimelength/2 && t < d/2 + daytimelength/2)
+ dr = 1000;
+ else
+ dr = 750;
+
+ dstream<<"time_of_day="<<m_time_of_day.get()
+ <<", t="<<t
+ <<", dr="<<dr
+ <<std::endl;
+
+ if(dr != m_env.getDayNightRatio())
+ {
+ //dstream<<"dr="<<dr<<std::endl;
+ dout_client<<DTIME<<"Client: changing day-night ratio"<<std::endl;
+ m_env.setDayNightRatio(dr);
+ m_env.expireMeshes(true);
+ }
+ }
+
}
else if(command == TOCLIENT_CHAT_MESSAGE)
{
m_con.Send(PEER_ID_SERVER, channelnum, data, reliable);
}
-bool Client::isFetchingBlocks()
-{
- JMutexAutoLock conlock(m_con_mutex);
- con::Peer *peer = m_con.GetPeerNoEx(PEER_ID_SERVER);
- // Not really fetching but can't fetch more.
- if(peer == NULL) return true;
-
- con::Channel *channel = &(peer->channels[1]);
- /*
- NOTE: Channel 0 should always be used for fetching blocks,
- and for nothing else.
- */
- if(channel->incoming_reliables.size() > 0)
- return true;
- if(channel->outgoing_reliables.size() > 0)
- return true;
- return false;
-}
-
IncomingPacket Client::getPacket()
{
JMutexAutoLock lock(m_incoming_queue_mutex);
}
// Set peer id if not set already
- if(myplayer->peer_id == PEER_ID_NEW)
+ if(myplayer->peer_id == PEER_ID_INEXISTENT)
myplayer->peer_id = our_peer_id;
// Check that an existing peer_id is the same as the connection's
assert(myplayer->peer_id == our_peer_id);