1
0
mirror of https://github.com/minetest/minetest.git synced 2025-07-01 07:30:23 +02:00

Don't send an InventoryAction at each setInventoryModified, we only need one SendInventory per inventory modification

This commit is contained in:
Loic Blot
2015-03-24 09:36:54 +01:00
parent 732d7b9a7c
commit fb801eaae2
5 changed files with 15 additions and 10 deletions

View File

@ -455,9 +455,9 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
} }
} }
mgr->setInventoryModified(from_inv); mgr->setInventoryModified(from_inv, false);
if(inv_from != inv_to) if(inv_from != inv_to)
mgr->setInventoryModified(to_inv); mgr->setInventoryModified(to_inv, false);
} }
void IMoveAction::clientApply(InventoryManager *mgr, IGameDef *gamedef) void IMoveAction::clientApply(InventoryManager *mgr, IGameDef *gamedef)
@ -597,7 +597,7 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
if(item2.count != actually_dropped_count) if(item2.count != actually_dropped_count)
errorstream<<"Could not take dropped count of items"<<std::endl; errorstream<<"Could not take dropped count of items"<<std::endl;
mgr->setInventoryModified(from_inv); mgr->setInventoryModified(from_inv, false);
} }
} }

View File

@ -112,7 +112,7 @@ public:
// Get an inventory (server and client) // Get an inventory (server and client)
virtual Inventory* getInventory(const InventoryLocation &loc){return NULL;} virtual Inventory* getInventory(const InventoryLocation &loc){return NULL;}
// Set modified (will be saved and sent over network; only on server) // Set modified (will be saved and sent over network; only on server)
virtual void setInventoryModified(const InventoryLocation &loc){} virtual void setInventoryModified(const InventoryLocation &loc, bool playerSend = true){}
// Send inventory action to server (only on client) // Send inventory action to server (only on client)
virtual void inventoryAction(InventoryAction *a){} virtual void inventoryAction(InventoryAction *a){}
}; };

View File

@ -952,8 +952,8 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt)
ma->from_inv.applyCurrentPlayer(player->getName()); ma->from_inv.applyCurrentPlayer(player->getName());
ma->to_inv.applyCurrentPlayer(player->getName()); ma->to_inv.applyCurrentPlayer(player->getName());
setInventoryModified(ma->from_inv); setInventoryModified(ma->from_inv, false);
setInventoryModified(ma->to_inv); setInventoryModified(ma->to_inv, false);
bool from_inv_is_current_player = bool from_inv_is_current_player =
(ma->from_inv.type == InventoryLocation::PLAYER) && (ma->from_inv.type == InventoryLocation::PLAYER) &&
@ -1006,7 +1006,7 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt)
da->from_inv.applyCurrentPlayer(player->getName()); da->from_inv.applyCurrentPlayer(player->getName());
setInventoryModified(da->from_inv); setInventoryModified(da->from_inv, false);
/* /*
Disable dropping items out of craftpreview Disable dropping items out of craftpreview
@ -1033,7 +1033,7 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt)
ca->craft_inv.applyCurrentPlayer(player->getName()); ca->craft_inv.applyCurrentPlayer(player->getName());
setInventoryModified(ca->craft_inv); setInventoryModified(ca->craft_inv, false);
//bool craft_inv_is_current_player = //bool craft_inv_is_current_player =
// (ca->craft_inv.type == InventoryLocation::PLAYER) && // (ca->craft_inv.type == InventoryLocation::PLAYER) &&
@ -1052,6 +1052,8 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt)
a->apply(this, playersao, this); a->apply(this, playersao, this);
// Eat the action // Eat the action
delete a; delete a;
SendInventory(playersao);
} }
void Server::handleCommand_ChatMessage(NetworkPacket* pkt) void Server::handleCommand_ChatMessage(NetworkPacket* pkt)

View File

@ -1290,13 +1290,16 @@ Inventory* Server::getInventory(const InventoryLocation &loc)
} }
return NULL; return NULL;
} }
void Server::setInventoryModified(const InventoryLocation &loc) void Server::setInventoryModified(const InventoryLocation &loc, bool playerSend)
{ {
switch(loc.type){ switch(loc.type){
case InventoryLocation::UNDEFINED: case InventoryLocation::UNDEFINED:
break; break;
case InventoryLocation::PLAYER: case InventoryLocation::PLAYER:
{ {
if (!playerSend)
return;
Player *player = m_env->getPlayer(loc.name.c_str()); Player *player = m_env->getPlayer(loc.name.c_str());
if(!player) if(!player)
return; return;

View File

@ -237,7 +237,7 @@ public:
Shall be called with the environment and the connection locked. Shall be called with the environment and the connection locked.
*/ */
Inventory* getInventory(const InventoryLocation &loc); Inventory* getInventory(const InventoryLocation &loc);
void setInventoryModified(const InventoryLocation &loc); void setInventoryModified(const InventoryLocation &loc, bool playerSend = true);
// Connection must be locked when called // Connection must be locked when called
std::wstring getStatusString(); std::wstring getStatusString();