petla wysylajaca informacje o graczach
Ostatnio zmodyfikowano 2014-05-27 18:20
Psiryj Temat założony przez niniejszego użytkownika |
petla wysylajaca informacje o graczach » 2014-05-27 18:20:23 siemka, pisze sobie gre mmorpg i natrafilem na problem z wysylaniem informacji o graczach do pozostalych klientow, otoz, gdy polaczy sie 2 graczy wszystko jest oki, ale gorka sie zaczyna gdy wejdzie trzecia lub wiecej osob, mianowicie przy 3 dolaczonym graczu otrzymuje on pakiety o graczach na mapie kilka razy, to samo gdy wejdzie 4 lub wiecej, lecz liczba kopii pakietow rosnie, mysle ze nie ma sensu wrzucac calego kodu, wiec pozwolcie ze umieszcze metode odpowiadajaca za wysylanie owych informacji void Server::SendMapInfo() { for( std::list < Client *>::iterator it = clients.begin(); it != clients.end(); ++it ) { Client & client = ** it; if( inGameClients.size() > 1 ) { for( std::list < Client *>::iterator itt = inGameClients.begin(); itt != inGameClients.end(); ++itt ) { Client & temp = ** itt; if( temp.ClientID != client.ClientID && client.inGame == true && temp.inGame == true ) { if( client.Char.X / maps[ client.Char.MapID ]->tilesize - 8 <= temp.Char.X / maps[ client.Char.MapID ]->tilesize && client.Char.X / maps[ client.Char.MapID ]->tilesize + 8 >= temp.Char.X / maps[ client.Char.MapID ]->tilesize && client.Char.Y / maps[ client.Char.MapID ]->tilesize - 8 <= temp.Char.Y / maps[ client.Char.MapID ]->tilesize && client.Char.Y / maps[ client.Char.MapID ]->tilesize + 8 >= temp.Char.Y / maps[ client.Char.MapID ]->tilesize ) { client.family = Packet::PACKET_WORLD; client.action = Packet::PACKET_REQUEST; client.send << client.family << client.action << temp.Char.Name << temp.ClientID << temp.Char.X << temp.Char.Y; client.Send(); std::string str; str = std::to_string( temp.ClientID ); str += " "; str += temp.Char.Name; str += " "; str += std::to_string( temp.Char.X ); str += " "; str += std::to_string( temp.Char.Y ); client.SMsg( str.c_str() ); } } } } } } |
|
« 1 » |