Skip to content

Commit 7e56637

Browse files
committedMar 3, 2015
Send Breath packet on event, don't check it at each AsyncRunStep
1 parent 64ff966 commit 7e56637

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed
 

Diff for: ‎src/content_sao.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,6 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
718718
// public
719719
m_moved(false),
720720
m_inventory_not_sent(false),
721-
m_breath_not_sent(false),
722721
m_wielded_item_not_sent(false),
723722
m_physics_override_speed(1),
724723
m_physics_override_jump(1),

Diff for: ‎src/content_sao.h

-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ class PlayerSAO : public ServerActiveObject
318318
// Some flags used by Server
319319
bool m_moved;
320320
bool m_inventory_not_sent;
321-
bool m_breath_not_sent;
322321
bool m_wielded_item_not_sent;
323322

324323
float m_physics_override_speed;

Diff for: ‎src/network/packethandlers/server.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ void Server::handleCommand_Breath(NetworkPacket* pkt)
922922
}
923923

924924
playersao->setBreath(breath);
925-
m_script->player_event(playersao,"breath_changed");
925+
SendPlayerBreath(pkt->getPeerId());
926926
}
927927

928928
void Server::handleCommand_Password(NetworkPacket* pkt)

Diff for: ‎src/script/lua_api/l_object.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,11 @@ int ObjectRef::l_set_breath(lua_State *L)
812812
u16 breath = luaL_checknumber(L, 2);
813813
// Do it
814814
co->setBreath(breath);
815-
co->m_breath_not_sent = true;
815+
816+
// If the object is a player sent the breath to client
817+
if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER)
818+
getServer(L)->SendPlayerBreath(((PlayerSAO*)co)->getPeerID());
819+
816820
return 0;
817821
}
818822

Diff for: ‎src/server.cpp

+7-11
Original file line numberDiff line numberDiff line change
@@ -604,20 +604,15 @@ void Server::AsyncRunStep(bool initial_step)
604604
if(playersao == NULL)
605605
continue;
606606

607-
/*
608-
Send player breath if changed
609-
*/
610-
if(playersao->m_breath_not_sent) {
611-
SendPlayerBreath(*i);
612-
}
613607

614-
/*
615-
Send player inventories if necessary
616-
*/
617608
if(playersao->m_moved) {
618609
SendMovePlayer(*i);
619610
playersao->m_moved = false;
620611
}
612+
613+
/*
614+
Send player inventories if necessary
615+
*/
621616
if(playersao->m_inventory_not_sent) {
622617
UpdateCrafting(*i);
623618
SendInventory(*i);
@@ -1892,8 +1887,8 @@ void Server::SendPlayerBreath(u16 peer_id)
18921887
DSTACK(__FUNCTION_NAME);
18931888
PlayerSAO *playersao = getPlayerSAO(peer_id);
18941889
assert(playersao);
1895-
playersao->m_breath_not_sent = false;
1896-
m_script->player_event(playersao,"breath_changed");
1890+
1891+
m_script->player_event(playersao, "breath_changed");
18971892
SendBreath(peer_id, playersao->getBreath());
18981893
}
18991894

@@ -2604,6 +2599,7 @@ void Server::RespawnPlayer(u16 peer_id)
26042599
playersao->setBreath(PLAYER_MAX_BREATH);
26052600

26062601
SendPlayerHP(peer_id);
2602+
SendPlayerBreath(peer_id);
26072603

26082604
bool repositioned = m_script->on_respawnplayer(playersao);
26092605
if(!repositioned){

Diff for: ‎src/server.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ class Server : public con::PeerHandler, public MapEventReceiver,
373373
std::string* vers_string);
374374

375375
void SendPlayerHPOrDie(u16 peer_id, bool die) { die ? DiePlayer(peer_id) : SendPlayerHP(peer_id); }
376+
void SendPlayerBreath(u16 peer_id);
377+
376378
// Bind address
377379
Address m_bind_addr;
378380

@@ -397,7 +399,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
397399
void SendChatMessage(u16 peer_id, const std::wstring &message);
398400
void SendTimeOfDay(u16 peer_id, u16 time, f32 time_speed);
399401
void SendPlayerHP(u16 peer_id);
400-
void SendPlayerBreath(u16 peer_id);
402+
401403
void SendMovePlayer(u16 peer_id);
402404
void SendLocalPlayerAnimations(u16 peer_id, v2s32 animation_frames[4], f32 animation_speed);
403405
void SendEyeOffset(u16 peer_id, v3f first, v3f third);

0 commit comments

Comments
 (0)
Please sign in to comment.