mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 18:13:46 +01:00
Send Inventory packet on event, don't check it at each AsyncRunStep.
* Call UpdateCrafting into SendInventory because this functions is only called before SendInventory * Use Player* instead of peer_id for UpdateCrafting because SendInventory already has the Player* pointer, then don't loop for searching Player* per peer_id * m_env_mutex don't need to be used with this modification because it's already locked before the calls
This commit is contained in:
parent
038d3a31df
commit
1b2f64473e
@ -717,7 +717,6 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
|
|||||||
m_attachment_sent(false),
|
m_attachment_sent(false),
|
||||||
// public
|
// public
|
||||||
m_moved(false),
|
m_moved(false),
|
||||||
m_inventory_not_sent(false),
|
|
||||||
m_physics_override_speed(1),
|
m_physics_override_speed(1),
|
||||||
m_physics_override_jump(1),
|
m_physics_override_jump(1),
|
||||||
m_physics_override_gravity(1),
|
m_physics_override_gravity(1),
|
||||||
@ -1162,11 +1161,6 @@ InventoryLocation PlayerSAO::getInventoryLocation() const
|
|||||||
return loc;
|
return loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerSAO::setInventoryModified()
|
|
||||||
{
|
|
||||||
m_inventory_not_sent = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string PlayerSAO::getWieldList() const
|
std::string PlayerSAO::getWieldList() const
|
||||||
{
|
{
|
||||||
return "main";
|
return "main";
|
||||||
|
@ -205,7 +205,6 @@ public:
|
|||||||
Inventory* getInventory();
|
Inventory* getInventory();
|
||||||
const Inventory* getInventory() const;
|
const Inventory* getInventory() const;
|
||||||
InventoryLocation getInventoryLocation() const;
|
InventoryLocation getInventoryLocation() const;
|
||||||
void setInventoryModified();
|
|
||||||
std::string getWieldList() const;
|
std::string getWieldList() const;
|
||||||
int getWieldIndex() const;
|
int getWieldIndex() const;
|
||||||
void setWieldIndex(int i);
|
void setWieldIndex(int i);
|
||||||
@ -317,7 +316,6 @@ private:
|
|||||||
public:
|
public:
|
||||||
// Some flags used by Server
|
// Some flags used by Server
|
||||||
bool m_moved;
|
bool m_moved;
|
||||||
bool m_inventory_not_sent;
|
|
||||||
|
|
||||||
float m_physics_override_speed;
|
float m_physics_override_speed;
|
||||||
float m_physics_override_jump;
|
float m_physics_override_jump;
|
||||||
|
@ -1390,7 +1390,9 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
|
|||||||
// Placement was handled in lua
|
// Placement was handled in lua
|
||||||
|
|
||||||
// Apply returned ItemStack
|
// Apply returned ItemStack
|
||||||
playersao->setWieldedItem(item);
|
if (playersao->setWieldedItem(item)) {
|
||||||
|
SendInventory(pkt->getPeerId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If item has node placement prediction, always send the
|
// If item has node placement prediction, always send the
|
||||||
|
@ -355,6 +355,9 @@ int ObjectRef::l_set_wielded_item(lua_State *L)
|
|||||||
// Do it
|
// Do it
|
||||||
ItemStack item = read_item(L, 2, getServer(L));
|
ItemStack item = read_item(L, 2, getServer(L));
|
||||||
bool success = co->setWieldedItem(item);
|
bool success = co->setWieldedItem(item);
|
||||||
|
if (success && co->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
|
||||||
|
getServer(L)->SendInventory(((PlayerSAO*)co)->getPeerID());
|
||||||
|
}
|
||||||
lua_pushboolean(L, success);
|
lua_pushboolean(L, success);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -609,14 +609,6 @@ void Server::AsyncRunStep(bool initial_step)
|
|||||||
SendMovePlayer(*i);
|
SendMovePlayer(*i);
|
||||||
playersao->m_moved = false;
|
playersao->m_moved = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Send player inventories if necessary
|
|
||||||
*/
|
|
||||||
if(playersao->m_inventory_not_sent) {
|
|
||||||
UpdateCrafting(*i);
|
|
||||||
SendInventory(*i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1164,7 +1156,6 @@ PlayerSAO* Server::StageTwoClientInit(u16 peer_id)
|
|||||||
SendPlayerInventoryFormspec(peer_id);
|
SendPlayerInventoryFormspec(peer_id);
|
||||||
|
|
||||||
// Send inventory
|
// Send inventory
|
||||||
UpdateCrafting(peer_id);
|
|
||||||
SendInventory(peer_id);
|
SendInventory(peer_id);
|
||||||
|
|
||||||
// Send HP
|
// Send HP
|
||||||
@ -1385,7 +1376,8 @@ void Server::setInventoryModified(const InventoryLocation &loc)
|
|||||||
PlayerSAO *playersao = player->getPlayerSAO();
|
PlayerSAO *playersao = player->getPlayerSAO();
|
||||||
if(!playersao)
|
if(!playersao)
|
||||||
return;
|
return;
|
||||||
playersao->m_inventory_not_sent = true;
|
|
||||||
|
SendInventory(playersao->getPeerID());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case InventoryLocation::NODEMETA:
|
case InventoryLocation::NODEMETA:
|
||||||
@ -1650,7 +1642,7 @@ void Server::SendInventory(u16 peer_id)
|
|||||||
PlayerSAO *playersao = getPlayerSAO(peer_id);
|
PlayerSAO *playersao = getPlayerSAO(peer_id);
|
||||||
assert(playersao);
|
assert(playersao);
|
||||||
|
|
||||||
playersao->m_inventory_not_sent = false;
|
UpdateCrafting(playersao->getPlayer());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Serialize it
|
Serialize it
|
||||||
@ -2701,13 +2693,10 @@ void Server::DeleteClient(u16 peer_id, ClientDeletionReason reason)
|
|||||||
SendChatMessage(PEER_ID_INEXISTENT,message);
|
SendChatMessage(PEER_ID_INEXISTENT,message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::UpdateCrafting(u16 peer_id)
|
void Server::UpdateCrafting(Player* player)
|
||||||
{
|
{
|
||||||
DSTACK(__FUNCTION_NAME);
|
DSTACK(__FUNCTION_NAME);
|
||||||
|
|
||||||
Player* player = m_env->getPlayer(peer_id);
|
|
||||||
assert(player);
|
|
||||||
|
|
||||||
// Get a preview for crafting
|
// Get a preview for crafting
|
||||||
ItemStack preview;
|
ItemStack preview;
|
||||||
InventoryLocation loc;
|
InventoryLocation loc;
|
||||||
|
@ -375,6 +375,9 @@ public:
|
|||||||
void SendPlayerHPOrDie(u16 peer_id, bool die) { die ? DiePlayer(peer_id) : SendPlayerHP(peer_id); }
|
void SendPlayerHPOrDie(u16 peer_id, bool die) { die ? DiePlayer(peer_id) : SendPlayerHP(peer_id); }
|
||||||
void SendPlayerBreath(u16 peer_id);
|
void SendPlayerBreath(u16 peer_id);
|
||||||
|
|
||||||
|
// Envlock and conlock should be locked when calling these
|
||||||
|
void SendInventory(u16 peer_id);
|
||||||
|
|
||||||
// Bind address
|
// Bind address
|
||||||
Address m_bind_addr;
|
Address m_bind_addr;
|
||||||
|
|
||||||
@ -394,8 +397,7 @@ private:
|
|||||||
/* mark blocks not sent for all clients */
|
/* mark blocks not sent for all clients */
|
||||||
void SetBlocksNotSent(std::map<v3s16, MapBlock *>& block);
|
void SetBlocksNotSent(std::map<v3s16, MapBlock *>& block);
|
||||||
|
|
||||||
// Envlock and conlock should be locked when calling these
|
|
||||||
void SendInventory(u16 peer_id);
|
|
||||||
void SendChatMessage(u16 peer_id, const std::wstring &message);
|
void SendChatMessage(u16 peer_id, const std::wstring &message);
|
||||||
void SendTimeOfDay(u16 peer_id, u16 time, f32 time_speed);
|
void SendTimeOfDay(u16 peer_id, u16 time, f32 time_speed);
|
||||||
void SendPlayerHP(u16 peer_id);
|
void SendPlayerHP(u16 peer_id);
|
||||||
@ -466,7 +468,7 @@ private:
|
|||||||
void DiePlayer(u16 peer_id);
|
void DiePlayer(u16 peer_id);
|
||||||
void RespawnPlayer(u16 peer_id);
|
void RespawnPlayer(u16 peer_id);
|
||||||
void DeleteClient(u16 peer_id, ClientDeletionReason reason);
|
void DeleteClient(u16 peer_id, ClientDeletionReason reason);
|
||||||
void UpdateCrafting(u16 peer_id);
|
void UpdateCrafting(Player *player);
|
||||||
|
|
||||||
// When called, connection mutex should be locked
|
// When called, connection mutex should be locked
|
||||||
RemoteClient* getClient(u16 peer_id,ClientState state_min=CS_Active);
|
RemoteClient* getClient(u16 peer_id,ClientState state_min=CS_Active);
|
||||||
|
@ -90,14 +90,9 @@ ItemStack ServerActiveObject::getWieldedItem() const
|
|||||||
|
|
||||||
bool ServerActiveObject::setWieldedItem(const ItemStack &item)
|
bool ServerActiveObject::setWieldedItem(const ItemStack &item)
|
||||||
{
|
{
|
||||||
Inventory *inv = getInventory();
|
if(Inventory *inv = getInventory()) {
|
||||||
if(inv)
|
if (InventoryList *list = inv->getList(getWieldList())) {
|
||||||
{
|
|
||||||
InventoryList *list = inv->getList(getWieldList());
|
|
||||||
if (list)
|
|
||||||
{
|
|
||||||
list->changeItem(getWieldIndex(), item);
|
list->changeItem(getWieldIndex(), item);
|
||||||
setInventoryModified();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user