X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fclient.cpp;h=30280369f81f539c56ae5a56f5b858da0d093819;hb=8852333eb3042580592ade478e5def20f8ed5d4c;hp=654052ac0a40076aba3c4cdba3facc255e9dbfd3;hpb=7cac34c807b6f38eaca3bc8296566493c8874e03;p=oweals%2Fminetest.git diff --git a/src/client.cpp b/src/client.cpp index 654052ac0..30280369f 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -50,6 +50,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/directiontables.h" #include "util/pointedthing.h" #include "version.h" +#include "drawscene.h" + +extern gui::IGUIEnvironment* guienv; /* QueuedMeshUpdate @@ -168,6 +171,8 @@ void * MeshUpdateThread::Thread() BEGIN_DEBUG_EXCEPTION_HANDLER + porting::setThreadName("MeshUpdateThread"); + while(!StopRequested()) { QueuedMeshUpdate *q = m_queue_in.pop(); @@ -218,6 +223,11 @@ Client::Client( MtEventManager *event, 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_shsrc(shsrc), m_itemdef(itemdef), @@ -252,15 +262,9 @@ Client::Client( m_last_time_of_day_f(-1), m_time_of_day_update_timer(0), m_recommended_send_interval(0.1), - m_removed_sounds_check_timer(0) + m_removed_sounds_check_timer(0), + 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 */ @@ -325,25 +329,14 @@ void Client::connect(Address address) m_con.Connect(address); } -bool Client::connectedAndInitialized() -{ - if(m_con.Connected() == false) - return false; - - if(m_server_ser_ver == SER_FMT_VER_INVALID) - return false; - - return true; -} - void Client::step(float dtime) { DSTACK(__FUNCTION_NAME); - + // Limit a bit if(dtime > 2.0) dtime = 2.0; - + if(m_ignore_damage_timer > dtime) m_ignore_damage_timer -= dtime; else @@ -367,14 +360,12 @@ void Client::step(float dtime) { counter = 20.0; - infostream<<"Client packetcounter (20s):"< data, bool reliable) void Client::interact(u8 action, const PointedThing& pointed) { - if(connectedAndInitialized() == false){ + if(m_state != LC_Ready){ infostream<<"Client::interact() " "cancelled (not connected)" < 0xFFFF) { + messagesize = 0xFFFF; + } + writeU16(buf, (u16) messagesize); os.write((char*)buf, 2); // Write string @@ -2152,6 +2185,27 @@ void Client::sendRespawn() Send(0, data, true); } +void Client::sendReady() +{ + DSTACK(__FUNCTION_NAME); + std::ostringstream os(std::ios_base::binary); + + writeU16(os, TOSERVER_CLIENT_READY); + writeU8(os,VERSION_MAJOR); + writeU8(os,VERSION_MINOR); + writeU8(os,VERSION_PATCH_ORIG); + writeU8(os,0); + + writeU16(os,strlen(minetest_version_hash)); + os.write(minetest_version_hash,strlen(minetest_version_hash)); + + // Make data buffer + std::string s = os.str(); + SharedBuffer data((u8*)s.c_str(), s.size()); + // Send as reliable + Send(0, data, true); +} + void Client::sendPlayerPos() { LocalPlayer *myplayer = m_env.getLocalPlayer(); @@ -2421,6 +2475,15 @@ int Client::getCrackLevel() return m_crack_level; } +void Client::setHighlighted(v3s16 pos, bool show_hud) +{ + m_show_hud = show_hud; + v3s16 old_highlighted_pos = m_highlighted_pos; + m_highlighted_pos = pos; + addUpdateMeshTaskForNode(old_highlighted_pos, false, true); + addUpdateMeshTaskForNode(m_highlighted_pos, false, true); +} + void Client::setCrack(int level, v3s16 pos) { int old_crack_level = m_crack_level; @@ -2493,22 +2556,23 @@ void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server, bool urgent) MapBlock *b = m_env.getMap().getBlockNoCreateNoEx(p); if(b == NULL) return; - + /* Create a task to update the mesh of the block */ - + MeshMakeData *data = new MeshMakeData(this); - + { //TimeTaker timer("data fill"); // Release: ~0ms // Debug: 1-6ms, avg=2ms data->fill(b); data->setCrack(m_crack_level, m_crack_pos); + data->setHighlighted(m_highlighted_pos, m_show_hud); data->setSmoothLighting(g_settings->getBool("smooth_lighting")); } - + // Add task to queue m_mesh_update_thread.m_queue_in.addBlock(p, data, ack_to_server, urgent); } @@ -2596,10 +2660,6 @@ float Client::mediaReceiveProgress() return 1.0; // downloader only exists when not yet done } -void draw_load_screen(const std::wstring &text, - IrrlichtDevice* device, gui::IGUIFont* font, - float dtime=0 ,int percent=0, bool clouds=true); - void Client::afterContentReceived(IrrlichtDevice *device, gui::IGUIFont* font) { infostream<<"Client::afterContentReceived() started"<updateAliases(m_itemdef); - // Update node textures + // Update node textures and assign shaders to each tile infostream<<"- Updating node textures"<updateTextures(m_tsrc); + m_nodedef->updateTextures(m_tsrc, m_shsrc); // Preload item textures and meshes if configured to if(g_settings->getBool("preload_item_visuals")) { verbosestream<<"Updating item textures and meshes"< names = m_itemdef->getAll(); size_t size = names.size(); size_t count = 0; @@ -2641,7 +2701,7 @@ void Client::afterContentReceived(IrrlichtDevice *device, gui::IGUIFont* font) count++; percent = count*100/size; if (count%50 == 0) // only update every 50 item - draw_load_screen(text,device,font,0,percent); + draw_load_screen(text, device, guienv, font, 0, percent); } delete[] text; } @@ -2650,16 +2710,26 @@ void Client::afterContentReceived(IrrlichtDevice *device, gui::IGUIFont* font) infostream<<"- Starting mesh update thread"<