1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-26 18:21:04 +00:00

Remove Queue class which uses std::list and use native std::queue

This commit is contained in:
Loic Blot 2015-03-04 17:48:07 +01:00 committed by Craig Robbins
parent 9e67579315
commit b214cde5b4
11 changed files with 85 additions and 139 deletions

View file

@ -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);
}
}
@ -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();
@ -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);
@ -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(
@ -1193,7 +1191,8 @@ 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)) {
@ -1201,7 +1200,7 @@ void UDPPeer::RunCommandQueues(
<< " 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) {
@ -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;
}
}
@ -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 "
@ -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) {
@ -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;
}
}
@ -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) :

View file

@ -505,10 +505,10 @@ public:
ReliablePacketBuffer outgoing_reliables_sent;
//queued reliable packets
Queue<BufferedPacket> queued_reliables;
std::queue<BufferedPacket> queued_reliables;
//queue commands prior splitting to packets
Queue<ConnectionCommand> queued_commands;
std::queue<ConnectionCommand> queued_commands;
IncomingSplitBuffer incoming_splits;
@ -964,7 +964,7 @@ private:
Connection* m_connection;
unsigned int m_max_packet_size;
float m_timeout;
Queue<OutgoingPacket> m_outgoing_queue;
std::queue<OutgoingPacket> m_outgoing_queue;
JSemaphore m_send_sleep_semaphore;
unsigned int m_iteration_packets_avaialble;

View file

@ -263,7 +263,7 @@ void Client::handleCommand_ChatMessage(NetworkPacket* pkt)
message += (wchar_t)read_wchar;
}
m_chat_queue.push_back(message);
m_chat_queue.push(message);
}
void Client::handleCommand_ActiveObjectRemoveAdd(NetworkPacket* pkt)
@ -380,7 +380,7 @@ void Client::handleCommand_HP(NetworkPacket* pkt)
ClientEvent event;
event.type = CE_PLAYER_DAMAGE;
event.player_damage.amount = oldhp - hp;
m_client_event_queue.push_back(event);
m_client_event_queue.push(event);
}
}
@ -424,7 +424,7 @@ void Client::handleCommand_MovePlayer(NetworkPacket* pkt)
event.type = CE_PLAYER_FORCE_MOVE;
event.player_force_move.pitch = pitch;
event.player_force_move.yaw = yaw;
m_client_event_queue.push_back(event);
m_client_event_queue.push(event);
// Ignore damage for a few seconds, so that the player doesn't
// get damage from falling on ground
@ -450,7 +450,7 @@ void Client::handleCommand_DeathScreen(NetworkPacket* pkt)
event.deathscreen.camera_point_target_x = camera_point_target.X;
event.deathscreen.camera_point_target_y = camera_point_target.Y;
event.deathscreen.camera_point_target_z = camera_point_target.Z;
m_client_event_queue.push_back(event);
m_client_event_queue.push(event);
}
void Client::handleCommand_AnnounceMedia(NetworkPacket* pkt)
@ -735,7 +735,7 @@ void Client::handleCommand_ShowFormSpec(NetworkPacket* pkt)
// adding a std:string to a struct isn't possible
event.show_formspec.formspec = new std::string(formspec);
event.show_formspec.formname = new std::string(formname);
m_client_event_queue.push_back(event);
m_client_event_queue.push(event);
}
void Client::handleCommand_SpawnParticle(NetworkPacket* pkt)
@ -766,7 +766,7 @@ void Client::handleCommand_SpawnParticle(NetworkPacket* pkt)
event.spawn_particle.vertical = vertical;
event.spawn_particle.texture = new std::string(texture);
m_client_event_queue.push_back(event);
m_client_event_queue.push(event);
}
void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt)
@ -818,7 +818,7 @@ void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt)
event.add_particlespawner.texture = new std::string(texture);
event.add_particlespawner.id = id;
m_client_event_queue.push_back(event);
m_client_event_queue.push(event);
}
@ -832,7 +832,7 @@ void Client::handleCommand_DeleteParticleSpawner(NetworkPacket* pkt)
event.type = CE_DELETE_PARTICLESPAWNER;
event.delete_particlespawner.id = (u32) id;
m_client_event_queue.push_back(event);
m_client_event_queue.push(event);
}
void Client::handleCommand_HudAdd(NetworkPacket* pkt)
@ -880,7 +880,7 @@ void Client::handleCommand_HudAdd(NetworkPacket* pkt)
event.hudadd.offset = new v2f(offset);
event.hudadd.world_pos = new v3f(world_pos);
event.hudadd.size = new v2s32(size);
m_client_event_queue.push_back(event);
m_client_event_queue.push(event);
}
void Client::handleCommand_HudRemove(NetworkPacket* pkt)
@ -892,7 +892,7 @@ void Client::handleCommand_HudRemove(NetworkPacket* pkt)
ClientEvent event;
event.type = CE_HUDRM;
event.hudrm.id = id;
m_client_event_queue.push_back(event);
m_client_event_queue.push(event);
}
void Client::handleCommand_HudChange(NetworkPacket* pkt)
@ -928,7 +928,7 @@ void Client::handleCommand_HudChange(NetworkPacket* pkt)
event.hudchange.sdata = new std::string(sdata);
event.hudchange.data = intdata;
event.hudchange.v2s32data = new v2s32(v2s32data);
m_client_event_queue.push_back(event);
m_client_event_queue.push(event);
}
void Client::handleCommand_HudSetFlags(NetworkPacket* pkt)
@ -984,7 +984,7 @@ void Client::handleCommand_HudSetSky(NetworkPacket* pkt)
event.set_sky.bgcolor = bgcolor;
event.set_sky.type = type;
event.set_sky.params = params;
m_client_event_queue.push_back(event);
m_client_event_queue.push(event);
}
void Client::handleCommand_OverrideDayNightRatio(NetworkPacket* pkt)
@ -1000,7 +1000,7 @@ void Client::handleCommand_OverrideDayNightRatio(NetworkPacket* pkt)
event.type = CE_OVERRIDE_DAY_NIGHT_RATIO;
event.override_day_night_ratio.do_override = do_override;
event.override_day_night_ratio.ratio_f = day_night_ratio_f;
m_client_event_queue.push_back(event);
m_client_event_queue.push(event);
}
void Client::handleCommand_LocalPlayerAnimations(NetworkPacket* pkt)