forked from Mirrorlandia_minetest/minetest
Server::AsyncRunStep: buffered_messages now uses std::vector instead of std::list. * sendRemoveNode and sendAddNodes are also converted as a side effect
This commit is contained in:
parent
36e8ba9ce2
commit
82482ecd9d
105
src/server.cpp
105
src/server.cpp
@ -788,25 +788,22 @@ void Server::AsyncRunStep(bool initial_step)
|
|||||||
|
|
||||||
// Key = object id
|
// Key = object id
|
||||||
// Value = data sent by object
|
// Value = data sent by object
|
||||||
std::map<u16, std::list<ActiveObjectMessage>* > buffered_messages;
|
std::map<u16, std::vector<ActiveObjectMessage>* > buffered_messages;
|
||||||
|
|
||||||
// Get active object messages from environment
|
// Get active object messages from environment
|
||||||
for(;;)
|
for(;;) {
|
||||||
{
|
|
||||||
ActiveObjectMessage aom = m_env->getActiveObjectMessage();
|
ActiveObjectMessage aom = m_env->getActiveObjectMessage();
|
||||||
if (aom.id == 0)
|
if (aom.id == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
std::list<ActiveObjectMessage>* message_list = NULL;
|
std::vector<ActiveObjectMessage>* message_list = NULL;
|
||||||
std::map<u16, std::list<ActiveObjectMessage>* >::iterator n;
|
std::map<u16, std::vector<ActiveObjectMessage>* >::iterator n;
|
||||||
n = buffered_messages.find(aom.id);
|
n = buffered_messages.find(aom.id);
|
||||||
if(n == buffered_messages.end())
|
if (n == buffered_messages.end()) {
|
||||||
{
|
message_list = new std::vector<ActiveObjectMessage>;
|
||||||
message_list = new std::list<ActiveObjectMessage>;
|
|
||||||
buffered_messages[aom.id] = message_list;
|
buffered_messages[aom.id] = message_list;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
message_list = n->second;
|
message_list = n->second;
|
||||||
}
|
}
|
||||||
message_list->push_back(aom);
|
message_list->push_back(aom);
|
||||||
@ -817,26 +814,24 @@ void Server::AsyncRunStep(bool initial_step)
|
|||||||
// Route data to every client
|
// Route data to every client
|
||||||
for (std::map<u16, RemoteClient*>::iterator
|
for (std::map<u16, RemoteClient*>::iterator
|
||||||
i = clients.begin();
|
i = clients.begin();
|
||||||
i != clients.end(); ++i)
|
i != clients.end(); ++i) {
|
||||||
{
|
|
||||||
RemoteClient *client = i->second;
|
RemoteClient *client = i->second;
|
||||||
std::string reliable_data;
|
std::string reliable_data;
|
||||||
std::string unreliable_data;
|
std::string unreliable_data;
|
||||||
// Go through all objects in message buffer
|
// Go through all objects in message buffer
|
||||||
for(std::map<u16, std::list<ActiveObjectMessage>* >::iterator
|
for (std::map<u16, std::vector<ActiveObjectMessage>* >::iterator
|
||||||
j = buffered_messages.begin();
|
j = buffered_messages.begin();
|
||||||
j != buffered_messages.end(); ++j)
|
j != buffered_messages.end(); ++j) {
|
||||||
{
|
|
||||||
// If object is not known by client, skip it
|
// If object is not known by client, skip it
|
||||||
u16 id = j->first;
|
u16 id = j->first;
|
||||||
if (client->m_known_objects.find(id) == client->m_known_objects.end())
|
if (client->m_known_objects.find(id) == client->m_known_objects.end())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Get message list of object
|
// Get message list of object
|
||||||
std::list<ActiveObjectMessage>* list = j->second;
|
std::vector<ActiveObjectMessage>* list = j->second;
|
||||||
// Go through every message
|
// Go through every message
|
||||||
for(std::list<ActiveObjectMessage>::iterator
|
for (std::vector<ActiveObjectMessage>::iterator
|
||||||
k = list->begin(); k != list->end(); ++k)
|
k = list->begin(); k != list->end(); ++k) {
|
||||||
{
|
|
||||||
// Compose the full new data with header
|
// Compose the full new data with header
|
||||||
ActiveObjectMessage aom = *k;
|
ActiveObjectMessage aom = *k;
|
||||||
std::string new_data;
|
std::string new_data;
|
||||||
@ -876,10 +871,9 @@ void Server::AsyncRunStep(bool initial_step)
|
|||||||
m_clients.Unlock();
|
m_clients.Unlock();
|
||||||
|
|
||||||
// Clear buffered_messages
|
// Clear buffered_messages
|
||||||
for(std::map<u16, std::list<ActiveObjectMessage>* >::iterator
|
for(std::map<u16, std::vector<ActiveObjectMessage>* >::iterator
|
||||||
i = buffered_messages.begin();
|
i = buffered_messages.begin();
|
||||||
i != buffered_messages.end(); ++i)
|
i != buffered_messages.end(); ++i) {
|
||||||
{
|
|
||||||
delete i->second;
|
delete i->second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -912,77 +906,60 @@ void Server::AsyncRunStep(bool initial_step)
|
|||||||
// Players far away from the change are stored here.
|
// Players far away from the change are stored here.
|
||||||
// Instead of sending the changes, MapBlocks are set not sent
|
// Instead of sending the changes, MapBlocks are set not sent
|
||||||
// for them.
|
// for them.
|
||||||
std::list<u16> far_players;
|
std::vector<u16> far_players;
|
||||||
|
|
||||||
if(event->type == MEET_ADDNODE || event->type == MEET_SWAPNODE)
|
switch (event->type) {
|
||||||
{
|
case MEET_ADDNODE:
|
||||||
//infostream<<"Server: MEET_ADDNODE"<<std::endl;
|
case MEET_SWAPNODE:
|
||||||
prof.add("MEET_ADDNODE", 1);
|
prof.add("MEET_ADDNODE", 1);
|
||||||
if(disable_single_change_sending)
|
|
||||||
sendAddNode(event->p, event->n, event->already_known_by_peer,
|
sendAddNode(event->p, event->n, event->already_known_by_peer,
|
||||||
&far_players, 5, event->type == MEET_ADDNODE);
|
&far_players, disable_single_change_sending ? 5 : 30,
|
||||||
else
|
event->type == MEET_ADDNODE);
|
||||||
sendAddNode(event->p, event->n, event->already_known_by_peer,
|
break;
|
||||||
&far_players, 30, event->type == MEET_ADDNODE);
|
case MEET_REMOVENODE:
|
||||||
}
|
|
||||||
else if(event->type == MEET_REMOVENODE)
|
|
||||||
{
|
|
||||||
//infostream<<"Server: MEET_REMOVENODE"<<std::endl;
|
|
||||||
prof.add("MEET_REMOVENODE", 1);
|
prof.add("MEET_REMOVENODE", 1);
|
||||||
if(disable_single_change_sending)
|
|
||||||
sendRemoveNode(event->p, event->already_known_by_peer,
|
sendRemoveNode(event->p, event->already_known_by_peer,
|
||||||
&far_players, 5);
|
&far_players, disable_single_change_sending ? 5 : 30);
|
||||||
else
|
break;
|
||||||
sendRemoveNode(event->p, event->already_known_by_peer,
|
case MEET_BLOCK_NODE_METADATA_CHANGED:
|
||||||
&far_players, 30);
|
|
||||||
}
|
|
||||||
else if(event->type == MEET_BLOCK_NODE_METADATA_CHANGED)
|
|
||||||
{
|
|
||||||
infostream << "Server: MEET_BLOCK_NODE_METADATA_CHANGED" << std::endl;
|
infostream << "Server: MEET_BLOCK_NODE_METADATA_CHANGED" << std::endl;
|
||||||
prof.add("MEET_BLOCK_NODE_METADATA_CHANGED", 1);
|
prof.add("MEET_BLOCK_NODE_METADATA_CHANGED", 1);
|
||||||
setBlockNotSent(event->p);
|
setBlockNotSent(event->p);
|
||||||
}
|
break;
|
||||||
else if(event->type == MEET_OTHER)
|
case MEET_OTHER:
|
||||||
{
|
|
||||||
infostream << "Server: MEET_OTHER" << std::endl;
|
infostream << "Server: MEET_OTHER" << std::endl;
|
||||||
prof.add("MEET_OTHER", 1);
|
prof.add("MEET_OTHER", 1);
|
||||||
for(std::set<v3s16>::iterator
|
for(std::set<v3s16>::iterator
|
||||||
i = event->modified_blocks.begin();
|
i = event->modified_blocks.begin();
|
||||||
i != event->modified_blocks.end(); ++i)
|
i != event->modified_blocks.end(); ++i) {
|
||||||
{
|
|
||||||
setBlockNotSent(*i);
|
setBlockNotSent(*i);
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
else
|
default:
|
||||||
{
|
|
||||||
prof.add("unknown", 1);
|
prof.add("unknown", 1);
|
||||||
infostream << "WARNING: Server: Unknown MapEditEvent "
|
infostream << "WARNING: Server: Unknown MapEditEvent "
|
||||||
<< ((u32)event->type) << std::endl;
|
<< ((u32)event->type) << std::endl;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Set blocks not sent to far players
|
Set blocks not sent to far players
|
||||||
*/
|
*/
|
||||||
if(!far_players.empty())
|
if(!far_players.empty()) {
|
||||||
{
|
|
||||||
// Convert list format to that wanted by SetBlocksNotSent
|
// Convert list format to that wanted by SetBlocksNotSent
|
||||||
std::map<v3s16, MapBlock*> modified_blocks2;
|
std::map<v3s16, MapBlock*> modified_blocks2;
|
||||||
for(std::set<v3s16>::iterator
|
for(std::set<v3s16>::iterator
|
||||||
i = event->modified_blocks.begin();
|
i = event->modified_blocks.begin();
|
||||||
i != event->modified_blocks.end(); ++i)
|
i != event->modified_blocks.end(); ++i) {
|
||||||
{
|
|
||||||
modified_blocks2[*i] =
|
modified_blocks2[*i] =
|
||||||
m_env->getMap().getBlockNoCreateNoEx(*i);
|
m_env->getMap().getBlockNoCreateNoEx(*i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set blocks not sent
|
// Set blocks not sent
|
||||||
for(std::list<u16>::iterator
|
for(std::vector<u16>::iterator
|
||||||
i = far_players.begin();
|
i = far_players.begin();
|
||||||
i != far_players.end(); ++i)
|
i != far_players.end(); ++i) {
|
||||||
{
|
if(RemoteClient *client = getClient(*i))
|
||||||
u16 peer_id = *i;
|
|
||||||
RemoteClient *client = getClient(peer_id);
|
|
||||||
if(client==NULL)
|
|
||||||
continue;
|
|
||||||
client->SetBlocksNotSent(modified_blocks2);
|
client->SetBlocksNotSent(modified_blocks2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2018,7 +1995,7 @@ void Server::stopSound(s32 handle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Server::sendRemoveNode(v3s16 p, u16 ignore_id,
|
void Server::sendRemoveNode(v3s16 p, u16 ignore_id,
|
||||||
std::list<u16> *far_players, float far_d_nodes)
|
std::vector<u16> *far_players, float far_d_nodes)
|
||||||
{
|
{
|
||||||
float maxd = far_d_nodes*BS;
|
float maxd = far_d_nodes*BS;
|
||||||
v3f p_f = intToFloat(p, BS);
|
v3f p_f = intToFloat(p, BS);
|
||||||
@ -2049,7 +2026,7 @@ void Server::sendRemoveNode(v3s16 p, u16 ignore_id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Server::sendAddNode(v3s16 p, MapNode n, u16 ignore_id,
|
void Server::sendAddNode(v3s16 p, MapNode n, u16 ignore_id,
|
||||||
std::list<u16> *far_players, float far_d_nodes,
|
std::vector<u16> *far_players, float far_d_nodes,
|
||||||
bool remove_metadata)
|
bool remove_metadata)
|
||||||
{
|
{
|
||||||
float maxd = far_d_nodes*BS;
|
float maxd = far_d_nodes*BS;
|
||||||
|
@ -422,9 +422,9 @@ private:
|
|||||||
*/
|
*/
|
||||||
// Envlock and conlock should be locked when calling these
|
// Envlock and conlock should be locked when calling these
|
||||||
void sendRemoveNode(v3s16 p, u16 ignore_id=0,
|
void sendRemoveNode(v3s16 p, u16 ignore_id=0,
|
||||||
std::list<u16> *far_players=NULL, float far_d_nodes=100);
|
std::vector<u16> *far_players=NULL, float far_d_nodes=100);
|
||||||
void sendAddNode(v3s16 p, MapNode n, u16 ignore_id=0,
|
void sendAddNode(v3s16 p, MapNode n, u16 ignore_id=0,
|
||||||
std::list<u16> *far_players=NULL, float far_d_nodes=100,
|
std::vector<u16> *far_players=NULL, float far_d_nodes=100,
|
||||||
bool remove_metadata=true);
|
bool remove_metadata=true);
|
||||||
void setBlockNotSent(v3s16 p);
|
void setBlockNotSent(v3s16 p);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user