1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Dynamic_Add_Media v2 (#11550)

This commit is contained in:
sfan5 2021-09-09 16:51:35 +02:00 committed by GitHub
parent bcb6565483
commit bbfae0cc67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 796 additions and 246 deletions

View file

@ -555,6 +555,29 @@ void Client::step(float dtime)
m_media_downloader = NULL;
}
}
{
// Acknowledge dynamic media downloads to server
std::vector<u32> done;
for (auto it = m_pending_media_downloads.begin();
it != m_pending_media_downloads.end();) {
assert(it->second->isStarted());
it->second->step(this);
if (it->second->isDone()) {
done.emplace_back(it->first);
it = m_pending_media_downloads.erase(it);
} else {
it++;
}
if (done.size() == 255) { // maximum in one packet
sendHaveMedia(done);
done.clear();
}
}
if (!done.empty())
sendHaveMedia(done);
}
/*
If the server didn't update the inventory in a while, revert
@ -770,7 +793,8 @@ void Client::request_media(const std::vector<std::string> &file_requests)
Send(&pkt);
infostream << "Client: Sending media request list to server ("
<< file_requests.size() << " files. packet size)" << std::endl;
<< file_requests.size() << " files, packet size "
<< pkt.getSize() << ")" << std::endl;
}
void Client::initLocalMapSaving(const Address &address,
@ -1295,6 +1319,19 @@ void Client::sendPlayerPos()
Send(&pkt);
}
void Client::sendHaveMedia(const std::vector<u32> &tokens)
{
NetworkPacket pkt(TOSERVER_HAVE_MEDIA, 1 + tokens.size() * 4);
sanity_check(tokens.size() < 256);
pkt << static_cast<u8>(tokens.size());
for (u32 token : tokens)
pkt << token;
Send(&pkt);
}
void Client::removeNode(v3s16 p)
{
std::map<v3s16, MapBlock*> modified_blocks;