From 0b4f424f414380b7a46270e1389e8aa0524d8fba Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sat, 24 Aug 2019 19:07:38 +0200 Subject: Inventory: Send dirty lists where appropriate (#8742) This change reduces the amount of sent data towards clients. Inventory lists that are already known to the player are skipped, saving quite some data over time. Raises protocol version to 38 to ensure correct backwards-compatible code. --- src/client/client.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'src/client/client.cpp') diff --git a/src/client/client.cpp b/src/client/client.cpp index e78b9bb8a..4c5485325 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -557,8 +557,8 @@ void Client::step(float dtime) if (count_after != count_before) { // Do this every seconds after TOCLIENT_INVENTORY // Reset the locally changed inventory to the authoritative inventory - m_env.getLocalPlayer()->inventory = *m_inventory_from_server; - m_inventory_updated = true; + player->inventory = *m_inventory_from_server; + m_update_wielded_item = true; } } @@ -1331,28 +1331,30 @@ void Client::setPlayerControl(PlayerControl &control) void Client::setPlayerItem(u16 item) { m_env.getLocalPlayer()->setWieldIndex(item); - m_inventory_updated = true; + m_update_wielded_item = true; NetworkPacket pkt(TOSERVER_PLAYERITEM, 2); pkt << item; Send(&pkt); } -// Returns true if the inventory of the local player has been -// updated from the server. If it is true, it is set to false. -bool Client::getLocalInventoryUpdated() +// Returns true once after the inventory of the local player +// has been updated from the server. +bool Client::updateWieldedItem() { - bool updated = m_inventory_updated; - m_inventory_updated = false; - return updated; -} + if (!m_update_wielded_item) + return false; + + m_update_wielded_item = false; -// Copies the inventory of the local player to parameter -void Client::getLocalInventory(Inventory &dst) -{ LocalPlayer *player = m_env.getLocalPlayer(); assert(player); - dst = player->inventory; + if (auto *list = player->inventory.getList("main")) + list->setModified(false); + if (auto *list = player->inventory.getList("hand")) + list->setModified(false); + + return true; } Inventory* Client::getInventory(const InventoryLocation &loc) -- cgit v1.2.3