Skip to content

Commit

Permalink
Remove Queue class which uses std::list and use native std::queue
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzhul authored and Zeno- committed Mar 5, 2015
1 parent 9e67579 commit b214cde
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 139 deletions.
23 changes: 13 additions & 10 deletions src/client.cpp
Expand Up @@ -512,7 +512,7 @@ void Client::step(float dtime)
ClientEvent event;
event.type = CE_PLAYER_DAMAGE;
event.player_damage.amount = damage;
m_client_event_queue.push_back(event);
m_client_event_queue.push(event);
}
}
else if(event.type == CEE_PLAYER_BREATH) {
Expand Down Expand Up @@ -1429,7 +1429,8 @@ bool Client::getChatMessage(std::wstring &message)
{
if(m_chat_queue.size() == 0)
return false;
message = m_chat_queue.pop_front();
message = m_chat_queue.front();
m_chat_queue.pop();
return true;
}

Expand All @@ -1445,14 +1446,14 @@ void Client::typeChatMessage(const std::wstring &message)
// Show locally
if (message[0] == L'/')
{
m_chat_queue.push_back((std::wstring)L"issued command: " + message);
m_chat_queue.push((std::wstring)L"issued command: " + message);
}
else
{
LocalPlayer *player = m_env.getLocalPlayer();
assert(player != NULL);
std::wstring name = narrow_to_wide(player->getName());
m_chat_queue.push_back((std::wstring)L"<" + name + L"> " + message);
m_chat_queue.push((std::wstring)L"<" + name + L"> " + message);
}
}

Expand Down Expand Up @@ -1545,13 +1546,15 @@ void Client::addUpdateMeshTaskForNode(v3s16 nodepos, bool ack_to_server, bool ur

ClientEvent Client::getClientEvent()
{
if(m_client_event_queue.size() == 0)
{
ClientEvent event;
ClientEvent event;
if(m_client_event_queue.size() == 0) {
event.type = CE_NONE;
return event;
}
return m_client_event_queue.pop_front();
else {
event = m_client_event_queue.front();
m_client_event_queue.pop();
}
return event;
}

float Client::mediaReceiveProgress()
Expand Down Expand Up @@ -1669,7 +1672,7 @@ void Client::makeScreenshot(IrrlichtDevice *device)
} else {
sstr << "Failed to save screenshot '" << filename << "'";
}
m_chat_queue.push_back(narrow_to_wide(sstr.str()));
m_chat_queue.push(narrow_to_wide(sstr.str()));
infostream << sstr.str() << std::endl;
image->drop();
}
Expand Down
4 changes: 2 additions & 2 deletions src/client.h
Expand Up @@ -578,13 +578,13 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
// 0 <= m_daynight_i < DAYNIGHT_CACHE_COUNT
//s32 m_daynight_i;
//u32 m_daynight_ratio;
Queue<std::wstring> m_chat_queue;
std::queue<std::wstring> m_chat_queue;
// The seed returned by the server in TOCLIENT_INIT is stored here
u64 m_map_seed;
std::string m_password;
bool m_access_denied;
std::wstring m_access_denied_reason;
Queue<ClientEvent> m_client_event_queue;
std::queue<ClientEvent> m_client_event_queue;
bool m_itemdef_received;
bool m_nodedef_received;
ClientMediaDownloader *m_media_downloader;
Expand Down
36 changes: 18 additions & 18 deletions src/content_sao.cpp
Expand Up @@ -91,7 +91,7 @@ class TestSAO : public ServerActiveObject
data += itos(m_base_position.Z);

ActiveObjectMessage aom(getId(), false, data);
m_messages_out.push_back(aom);
m_messages_out.push(aom);
}
}

Expand Down Expand Up @@ -233,7 +233,7 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
std::string str = getPropertyPacket();
// create message and add to list
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push_back(aom);
m_messages_out.push(aom);
}

// If attached, check that our parent is still there. If it isn't, detach.
Expand Down Expand Up @@ -320,15 +320,15 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
m_armor_groups);
// create message and add to list
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push_back(aom);
m_messages_out.push(aom);
}

if(m_animation_sent == false){
m_animation_sent = true;
std::string str = gob_cmd_update_animation(m_animation_range, m_animation_speed, m_animation_blend);
// create message and add to list
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push_back(aom);
m_messages_out.push(aom);
}

if(m_bone_position_sent == false){
Expand All @@ -337,7 +337,7 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
std::string str = gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y);
// create message and add to list
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push_back(aom);
m_messages_out.push(aom);
}
}

Expand All @@ -346,7 +346,7 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
std::string str = gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation);
// create message and add to list
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push_back(aom);
m_messages_out.push(aom);
}
}

Expand Down Expand Up @@ -461,7 +461,7 @@ int LuaEntitySAO::punch(v3f dir,
std::string str = gob_cmd_punched(result.damage, getHP());
// create message and add to list
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push_back(aom);
m_messages_out.push(aom);
}

if(getHP() == 0)
Expand Down Expand Up @@ -610,7 +610,7 @@ void LuaEntitySAO::setTextureMod(const std::string &mod)
std::string str = gob_cmd_set_texture_mod(mod);
// create message and add to list
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push_back(aom);
m_messages_out.push(aom);
}

void LuaEntitySAO::setSprite(v2s16 p, int num_frames, float framelength,
Expand All @@ -624,7 +624,7 @@ void LuaEntitySAO::setSprite(v2s16 p, int num_frames, float framelength,
);
// create message and add to list
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push_back(aom);
m_messages_out.push(aom);
}

std::string LuaEntitySAO::getName()
Expand Down Expand Up @@ -664,7 +664,7 @@ void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
);
// create message and add to list
ActiveObjectMessage aom(getId(), false, str);
m_messages_out.push_back(aom);
m_messages_out.push(aom);
}

bool LuaEntitySAO::getCollisionBox(aabb3f *toset) {
Expand Down Expand Up @@ -856,7 +856,7 @@ void PlayerSAO::step(float dtime, bool send_recommended)
std::string str = getPropertyPacket();
// create message and add to list
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push_back(aom);
m_messages_out.push(aom);
}

// If attached, check that our parent is still there. If it isn't, detach.
Expand Down Expand Up @@ -919,7 +919,7 @@ void PlayerSAO::step(float dtime, bool send_recommended)
);
// create message and add to list
ActiveObjectMessage aom(getId(), false, str);
m_messages_out.push_back(aom);
m_messages_out.push(aom);
}

if(m_armor_groups_sent == false) {
Expand All @@ -928,7 +928,7 @@ void PlayerSAO::step(float dtime, bool send_recommended)
m_armor_groups);
// create message and add to list
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push_back(aom);
m_messages_out.push(aom);
}

if(m_physics_override_sent == false){
Expand All @@ -938,15 +938,15 @@ void PlayerSAO::step(float dtime, bool send_recommended)
m_physics_override_sneak, m_physics_override_sneak_glitch);
// create message and add to list
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push_back(aom);
m_messages_out.push(aom);
}

if(m_animation_sent == false){
m_animation_sent = true;
std::string str = gob_cmd_update_animation(m_animation_range, m_animation_speed, m_animation_blend);
// create message and add to list
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push_back(aom);
m_messages_out.push(aom);
}

if(m_bone_position_sent == false){
Expand All @@ -955,7 +955,7 @@ void PlayerSAO::step(float dtime, bool send_recommended)
std::string str = gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y);
// create message and add to list
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push_back(aom);
m_messages_out.push(aom);
}
}

Expand All @@ -964,7 +964,7 @@ void PlayerSAO::step(float dtime, bool send_recommended)
std::string str = gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation);
// create message and add to list
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push_back(aom);
m_messages_out.push(aom);
}
}

Expand Down Expand Up @@ -1025,7 +1025,7 @@ int PlayerSAO::punch(v3f dir,
std::string str = gob_cmd_punched(0, getHP());
// create message and add to list
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push_back(aom);
m_messages_out.push(aom);
return 0;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/environment.cpp
Expand Up @@ -1239,7 +1239,8 @@ void ServerEnvironment::step(float dtime)
while(!obj->m_messages_out.empty())
{
m_active_object_messages.push_back(
obj->m_messages_out.pop_front());
obj->m_messages_out.front());
obj->m_messages_out.pop();
}
}
}
Expand Down
45 changes: 23 additions & 22 deletions src/network/connection.cpp
Expand Up @@ -1058,22 +1058,19 @@ void UDPPeer::PutReliableSendCommand(ConnectionCommand &c,
if ( channels[c.channelnum].queued_commands.empty() &&
/* don't queue more packets then window size */
(channels[c.channelnum].queued_reliables.size()
< (channels[c.channelnum].getWindowSize()/2)))
{
< (channels[c.channelnum].getWindowSize()/2))) {
LOG(dout_con<<m_connection->getDesc()
<<" processing reliable command for peer id: " << c.peer_id
<<" data size: " << c.data.getSize() << std::endl);
if (!processReliableSendCommand(c,max_packet_size))
{
channels[c.channelnum].queued_commands.push_back(c);
if (!processReliableSendCommand(c,max_packet_size)) {
channels[c.channelnum].queued_commands.push(c);
}
}
else
{
else {
LOG(dout_con<<m_connection->getDesc()
<<" Queueing reliable command for peer id: " << c.peer_id
<<" data size: " << c.data.getSize() <<std::endl);
channels[c.channelnum].queued_commands.push_back(c);
channels[c.channelnum].queued_commands.push(c);
}
}

Expand Down Expand Up @@ -1104,7 +1101,7 @@ bool UDPPeer::processReliableSendCommand(

bool have_sequence_number = true;
bool have_initial_sequence_number = false;
Queue<BufferedPacket> toadd;
std::queue<BufferedPacket> toadd;
volatile u16 initial_sequence_number = 0;

for(std::list<SharedBuffer<u8> >::iterator i = originals.begin();
Expand All @@ -1129,19 +1126,20 @@ bool UDPPeer::processReliableSendCommand(
m_connection->GetProtocolID(), m_connection->GetPeerID(),
c.channelnum);

toadd.push_back(p);
toadd.push(p);
}

if (have_sequence_number) {
volatile u16 pcount = 0;
while(toadd.size() > 0) {
BufferedPacket p = toadd.pop_front();
BufferedPacket p = toadd.front();
toadd.pop();
// LOG(dout_con<<connection->getDesc()
// << " queuing reliable packet for peer_id: " << c.peer_id
// << " channel: " << (c.channelnum&0xFF)
// << " seqnum: " << readU16(&p.data[BASE_HEADER_SIZE+1])
// << std::endl)
channels[c.channelnum].queued_reliables.push_back(p);
channels[c.channelnum].queued_reliables.push(p);
pcount++;
}
assert(channels[c.channelnum].queued_reliables.size() < 0xFFFF);
Expand All @@ -1156,7 +1154,7 @@ bool UDPPeer::processReliableSendCommand(
}
while(toadd.size() > 0) {
/* remove packet */
toadd.pop_front();
toadd.pop();

bool successfully_put_back_sequence_number
= channels[c.channelnum].putBackSequenceNumber(
Expand Down Expand Up @@ -1193,15 +1191,16 @@ void UDPPeer::RunCommandQueues(
(commands_processed < maxcommands))
{
try {
ConnectionCommand c = channels[i].queued_commands.pop_front();
ConnectionCommand c = channels[i].queued_commands.front();
channels[i].queued_commands.pop();
LOG(dout_con<<m_connection->getDesc()
<<" processing queued reliable command "<<std::endl);
if (!processReliableSendCommand(c,max_packet_size)) {
LOG(dout_con<<m_connection->getDesc()
<< " Failed to queue packets for peer_id: " << c.peer_id
<< ", delaying sending of " << c.data.getSize()
<< " bytes" << std::endl);
channels[i].queued_commands.push_front(c);
channels[i].queued_commands.push(c);
}
}
catch (ItemNotFoundException &e) {
Expand Down Expand Up @@ -1550,7 +1549,7 @@ bool ConnectionSendThread::rawSendAsPacket(u16 peer_id, u8 channelnum,
<<" INFO: queueing reliable packet for peer_id: " << peer_id
<<" channel: " << channelnum
<<" seqnum: " << seqnum << std::endl);
channel->queued_reliables.push_back(p);
channel->queued_reliables.push(p);
return false;
}
}
Expand Down Expand Up @@ -1919,7 +1918,8 @@ void ConnectionSendThread::sendPackets(float dtime)
< dynamic_cast<UDPPeer*>(&peer)->channels[i].getWindowSize())&&
(peer->m_increment_packets_remaining > 0))
{
BufferedPacket p = dynamic_cast<UDPPeer*>(&peer)->channels[i].queued_reliables.pop_front();
BufferedPacket p = dynamic_cast<UDPPeer*>(&peer)->channels[i].queued_reliables.front();
dynamic_cast<UDPPeer*>(&peer)->channels[i].queued_reliables.pop();
Channel* channel = &(dynamic_cast<UDPPeer*>(&peer)->channels[i]);
LOG(dout_con<<m_connection->getDesc()
<<" INFO: sending a queued reliable packet "
Expand All @@ -1942,10 +1942,11 @@ void ConnectionSendThread::sendPackets(float dtime)
unsigned int initial_queuesize = m_outgoing_queue.size();
/* send non reliable packets*/
for(unsigned int i=0;i < initial_queuesize;i++) {
OutgoingPacket packet = m_outgoing_queue.pop_front();
OutgoingPacket packet = m_outgoing_queue.front();
m_outgoing_queue.pop();

assert(!packet.reliable &&
"reliable packets are not allowed in outgoing queue!");
if (packet.reliable)
continue;

PeerHelper peer = m_connection->getPeerNoEx(packet.peer_id);
if (!peer) {
Expand All @@ -1972,7 +1973,7 @@ void ConnectionSendThread::sendPackets(float dtime)
peer->m_increment_packets_remaining--;
}
else {
m_outgoing_queue.push_back(packet);
m_outgoing_queue.push(packet);
pending_unreliable[packet.peer_id] = true;
}
}
Expand All @@ -1992,7 +1993,7 @@ void ConnectionSendThread::sendAsPacket(u16 peer_id, u8 channelnum,
SharedBuffer<u8> data, bool ack)
{
OutgoingPacket packet(peer_id, channelnum, data, false, ack);
m_outgoing_queue.push_back(packet);
m_outgoing_queue.push(packet);
}

ConnectionReceiveThread::ConnectionReceiveThread(unsigned int max_packet_size) :
Expand Down

0 comments on commit b214cde

Please sign in to comment.