X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;ds=sidebyside;f=src%2Fclient.cpp;h=2148bfe59b438749d52dcac8ed668c3f6e5d080f;hb=569fca53089b7b7e87b02edd44e2ad47166f7af6;hp=0463aa81c9cf5f47f56bdeefb469267465829d01;hpb=b4dd5d3bd7d2152fdf02e0e7422b1305caf151f2;p=dragonfireclient.git diff --git a/src/client.cpp b/src/client.cpp index 0463aa81c..2148bfe59 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -37,10 +37,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "sha1.h" #include "base64.h" +#include "clientmap.h" static std::string getTextureCacheDir() { - return porting::path_userdata + DIR_DELIM + "cache" + DIR_DELIM + "texture"; + return porting::path_user + DIR_DELIM + "cache" + DIR_DELIM + "textures"; } struct TextureRequest @@ -82,8 +83,9 @@ MeshUpdateQueue::~MeshUpdateQueue() { JMutexAutoLock lock(m_mutex); - core::list::Iterator i; - for(i=m_queue.begin(); i!=m_queue.end(); i++) + for(std::vector::iterator + i = m_queue.begin(); + i != m_queue.end(); i++) { QueuedMeshUpdate *q = *i; delete q; @@ -93,7 +95,7 @@ MeshUpdateQueue::~MeshUpdateQueue() /* peer_id=0 adds with nobody to send to */ -void MeshUpdateQueue::addBlock(v3s16 p, MeshMakeData *data, bool ack_block_to_server) +void MeshUpdateQueue::addBlock(v3s16 p, MeshMakeData *data, bool ack_block_to_server, bool urgent) { DSTACK(__FUNCTION_NAME); @@ -101,12 +103,16 @@ void MeshUpdateQueue::addBlock(v3s16 p, MeshMakeData *data, bool ack_block_to_se JMutexAutoLock lock(m_mutex); + if(urgent) + m_urgents.insert(p); + /* Find if block is already in queue. If it is, update the data and quit. */ - core::list::Iterator i; - for(i=m_queue.begin(); i!=m_queue.end(); i++) + for(std::vector::iterator + i = m_queue.begin(); + i != m_queue.end(); i++) { QueuedMeshUpdate *q = *i; if(q->p == p) @@ -136,12 +142,19 @@ QueuedMeshUpdate * MeshUpdateQueue::pop() { JMutexAutoLock lock(m_mutex); - core::list::Iterator i = m_queue.begin(); - if(i == m_queue.end()) - return NULL; - QueuedMeshUpdate *q = *i; - m_queue.erase(i); - return q; + bool must_be_urgent = !m_urgents.empty(); + for(std::vector::iterator + i = m_queue.begin(); + i != m_queue.end(); i++) + { + QueuedMeshUpdate *q = *i; + if(must_be_urgent && m_urgents.count(q->p) == 0) + continue; + m_queue.erase(i); + m_urgents.erase(q->p); + return q; + } + return NULL; } /* @@ -178,8 +191,12 @@ void * MeshUpdateThread::Thread() ScopeProfiler sp(g_profiler, "Client: Mesh making"); - scene::SMesh *mesh_new = NULL; - mesh_new = makeMapBlockMesh(q->data, m_gamedef); + MapBlockMesh *mesh_new = new MapBlockMesh(q->data); + if(mesh_new->getMesh()->getMeshBufferCount() == 0) + { + delete mesh_new; + mesh_new = NULL; + } MeshUpdateResult r; r.p = q->p; @@ -227,14 +244,19 @@ Client::Client( m_inventory_updated(false), m_inventory_from_server(NULL), m_inventory_from_server_age(0.0), - m_time_of_day(0), + m_animation_time(0), + m_crack_level(-1), + m_crack_pos(0,0,0), m_map_seed(0), m_password(password), m_access_denied(false), m_texture_receive_progress(0), m_textures_received(false), m_itemdef_received(false), - m_nodedef_received(false) + m_nodedef_received(false), + m_time_of_day_set(false), + m_last_time_of_day_f(-1), + m_time_of_day_update_timer(0) { m_packetcounter_timer = 0.0; //m_delete_unused_sectors_timer = 0.0; @@ -309,6 +331,12 @@ void Client::step(float dtime) else m_ignore_damage_timer = 0.0; + m_animation_time += dtime; + if(m_animation_time > 60.0) + m_animation_time -= 60.0; + + m_time_of_day_update_timer += dtime; + //infostream<<"Client steps "<replaceMesh(r.mesh); + //JMutexAutoLock lock(block->mesh_mutex); + + // Delete the old mesh + if(block->mesh != NULL) + { + // TODO: Remove hardware buffers of meshbuffers of block->mesh + delete block->mesh; + block->mesh = NULL; + } + + // Replace with the new mesh + block->mesh = r.mesh; } if(r.ack_block_to_server) { @@ -868,9 +907,6 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) //TimeTaker t1("TOCLIENT_REMOVENODE"); - // This will clear the cracking animation after digging - ((ClientMap&)m_env.getMap()).clearTempMod(p); - removeNode(p); } else if(command == TOCLIENT_ADDNODE) @@ -960,13 +996,6 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) m_con.Send(PEER_ID_SERVER, 1, reply, true); #endif - /* - Update Mesh of this block and blocks at x-, y- and z-. - Environment should not be locked as it interlocks with the - main thread, from which is will want to retrieve textures. - */ - - //m_env.getClientMap().updateMeshes(block->getPos(), getDayNightRatio()); /* Add it to mesh update queue and set it to be acknowledged after update. */ @@ -1019,22 +1048,37 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) u16 time_of_day = readU16(&data[2]); time_of_day = time_of_day % 24000; //infostream<<"Client: time_of_day="< modified_blocks; @@ -1853,44 +1905,15 @@ void Client::addNode(v3s16 p, MapNode n) catch(InvalidPositionException &e) {} - //TimeTaker timer2("Client::addNode(): updateMeshes"); - for(core::map::Iterator i = modified_blocks.getIterator(); i.atEnd() == false; i++) { v3s16 p = i.getNode()->getKey(); - //m_env.getClientMap().updateMeshes(p, m_env.getDayNightRatio()); addUpdateMeshTaskWithEdge(p); } } -void Client::updateCamera(v3f pos, v3f dir, f32 fov) -{ - m_env.getClientMap().updateCamera(pos, dir, fov); -} - -void Client::renderPostFx() -{ - m_env.getClientMap().renderPostFx(); -} - -MapNode Client::getNode(v3s16 p) -{ - //JMutexAutoLock envlock(m_env_mutex); //bulk comment-out - return m_env.getMap().getNode(p); -} - -NodeMetadata* Client::getNodeMetadata(v3s16 p) -{ - return m_env.getMap().getNodeMetadata(p); -} - -LocalPlayer* Client::getLocalPlayer() -{ - return m_env.getLocalPlayer(); -} - void Client::setPlayerControl(PlayerControl &control) { //JMutexAutoLock envlock(m_env_mutex); //bulk comment-out @@ -2026,58 +2049,97 @@ void Client::printDebugInfo(std::ostream &os) //<<", m_opt_not_found_history.size()="< Client::getConnectedPlayerNames() { - //JMutexAutoLock envlock(m_env_mutex); //bulk comment-out - return m_env.getDayNightRatio(); + core::list players = m_env.getPlayers(true); + core::list playerNames; + for(core::list::Iterator + i = players.begin(); + i != players.end(); i++) + { + Player *player = *i; + playerNames.push_back(narrow_to_wide(player->getName())); + } + return playerNames; } -u16 Client::getHP() +float Client::getAnimationTime() { - Player *player = m_env.getLocalPlayer(); - assert(player != NULL); - return player->hp; + return m_animation_time; } -void Client::setTempMod(v3s16 p, NodeMod mod) +int Client::getCrackLevel() { - //JMutexAutoLock envlock(m_env_mutex); //bulk comment-out - assert(m_env.getMap().mapType() == MAPTYPE_CLIENT); + return m_crack_level; +} + +void Client::setCrack(int level, v3s16 pos) +{ + int old_crack_level = m_crack_level; + v3s16 old_crack_pos = m_crack_pos; - core::map affected_blocks; - ((ClientMap&)m_env.getMap()).setTempMod(p, mod, - &affected_blocks); + m_crack_level = level; + m_crack_pos = pos; - for(core::map::Iterator - i = affected_blocks.getIterator(); - i.atEnd() == false; i++) + if(old_crack_level >= 0 && (level < 0 || pos != old_crack_pos)) + { + // remove old crack + addUpdateMeshTaskForNode(old_crack_pos, false, true); + } + if(level >= 0 && (old_crack_level < 0 || pos != old_crack_pos)) { - i.getNode()->getValue()->updateMesh(m_env.getDayNightRatio()); + // add new crack + addUpdateMeshTaskForNode(pos, false, true); } } -void Client::clearTempMod(v3s16 p) +u16 Client::getHP() { - //JMutexAutoLock envlock(m_env_mutex); //bulk comment-out - assert(m_env.getMap().mapType() == MAPTYPE_CLIENT); + Player *player = m_env.getLocalPlayer(); + assert(player != NULL); + return player->hp; +} + +bool Client::getChatMessage(std::wstring &message) +{ + if(m_chat_queue.size() == 0) + return false; + message = m_chat_queue.pop_front(); + return true; +} - core::map affected_blocks; - ((ClientMap&)m_env.getMap()).clearTempMod(p, - &affected_blocks); +void Client::typeChatMessage(const std::wstring &message) +{ + // Discard empty line + if(message == L"") + return; - for(core::map::Iterator - i = affected_blocks.getIterator(); - i.atEnd() == false; i++) + // Send to others + sendChatMessage(message); + + // Show locally + if (message[0] == L'/') { - i.getNode()->getValue()->updateMesh(m_env.getDayNightRatio()); + m_chat_queue.push_back( + (std::wstring)L"issued command: "+message); + } + else + { + LocalPlayer *player = m_env.getLocalPlayer(); + assert(player != NULL); + std::wstring name = narrow_to_wide(player->getName()); + m_chat_queue.push_back( + (std::wstring)L"<"+name+L"> "+message); } } -void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server) +void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server, bool urgent) { /*infostream<<"Client::addUpdateMeshTask(): " <<"("<fill(getDayNightRatio(), b); + data->fill(b); + data->setCrack(m_crack_level, m_crack_pos); + data->setSmoothLighting(g_settings->getBool("smooth_lighting")); } // Debug wait //while(m_mesh_update_thread.m_queue_in.size() > 0) sleep_ms(10); // Add task to queue - m_mesh_update_thread.m_queue_in.addBlock(p, data, ack_to_server); + m_mesh_update_thread.m_queue_in.addBlock(p, data, ack_to_server, urgent); /*infostream<<"Mesh update input queue size is " <replaceMesh(mesh_new); - delete data; - } -#endif - - /* - Mark mesh as non-expired at this point so that it can already - be marked as expired again if the data changes - */ - b->setMeshExpired(false); } -void Client::addUpdateMeshTaskWithEdge(v3s16 blockpos, bool ack_to_server) +void Client::addUpdateMeshTaskWithEdge(v3s16 blockpos, bool ack_to_server, bool urgent) { /*{ v3s16 p = blockpos; @@ -2138,25 +2184,66 @@ void Client::addUpdateMeshTaskWithEdge(v3s16 blockpos, bool ack_to_server) try{ v3s16 p = blockpos + v3s16(0,0,0); //MapBlock *b = m_env.getMap().getBlockNoCreate(p); - addUpdateMeshTask(p, ack_to_server); + addUpdateMeshTask(p, ack_to_server, urgent); } catch(InvalidPositionException &e){} // Leading edge try{ v3s16 p = blockpos + v3s16(-1,0,0); - addUpdateMeshTask(p); + addUpdateMeshTask(p, false, urgent); } catch(InvalidPositionException &e){} try{ v3s16 p = blockpos + v3s16(0,-1,0); - addUpdateMeshTask(p); + addUpdateMeshTask(p, false, urgent); } catch(InvalidPositionException &e){} try{ v3s16 p = blockpos + v3s16(0,0,-1); - addUpdateMeshTask(p); + addUpdateMeshTask(p, false, urgent); + } + catch(InvalidPositionException &e){} +} + +void Client::addUpdateMeshTaskForNode(v3s16 nodepos, bool ack_to_server, bool urgent) +{ + { + v3s16 p = nodepos; + infostream<<"Client::addUpdateMeshTaskForNode(): " + <<"("<