本文整理汇总了C++中NetClient::answerPing方法的典型用法代码示例。如果您正苦于以下问题:C++ NetClient::answerPing方法的具体用法?C++ NetClient::answerPing怎么用?C++ NetClient::answerPing使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetClient
的用法示例。
在下文中一共展示了NetClient::answerPing方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: receiver
//.........这里部分代码省略.........
data = new char[in_packet->len];
memcpy (data, in_packet->data, in_packet->len);
xmlcontainer->Clear();
xmlcontainer->Parse( data );
net_msg = xmlcontainer->RootElement();
if ( data )
delete [] data;
if( m_pNetClient->handleMessage(net_msg) ) continue;
msg_type = net_msg->Attribute( "TYPE" );
net_msg->QueryIntAttribute( "ID", &msg_id );
if ( net_msg->Attribute( "PLYNAME" ) )
plyName = net_msg->Attribute( "PLYNAME" );
else
plyName = "unnamed";
NetControl::waitForSync();
//SDL_SemWait (NetControl::m_pSemNetAndLocalSync);
SDL_SemWait (pNetClient->m_pSemEntityValues); /** comecando a mexer nas entidades... travar acesso **/
if (msg_type == "ENT"){ //nessa situacao, supoe-se que o cliente ja saiba da existencia
//da origem dessa mensagem, portanto o lugar no vetor ja existe!
EntityFactory* pEntityFactory = EntityFactory::getInstance();
pNetClient->checkOtherPlayer( msg_id , plyName);
IEntity* newEntity = pEntityFactory->loadEntity( net_msg );
int ent_id;
net_msg->QueryIntAttribute( "ENTID", &ent_id );
while (pNetClient->m_vOthersEntities[msg_id].size() <= ent_id){
pNetClient->m_vOthersEntities[msg_id].push_back( NULL );
}
pNetClient->m_vOthersEntities[msg_id][ent_id] = newEntity;
}
if (msg_type == "RMENT"){
EntityFactory* pEntityFactory = EntityFactory::getInstance();
string uniqueId = net_msg->Attribute( "UNIQUEID" );
int entId;
net_msg->Attribute( "ENTID" , &entId );
pNetClient->m_vOthersEntities[msg_id][entId] = NULL;
pEntityFactory->rmEntity( pEntityFactory->getEntity( uniqueId ) );
}
if (msg_type == "LGNGRA"){ //arranja um lugar no vetor de outras entidades para o novo vizinho
pNetClient->checkOtherPlayer( msg_id , plyName );
}
if (msg_type == "BYE"){ //aqui supoe-se que ja exista a posicao msg_id no vector
pNetClient->rmOtherPlayer( msg_id );
}
if (msg_type == "TIMEOUT_BYE"){ //o servidor informou que o cliente (msg_id) desconectou-se por timeout
pNetClient->rmOtherPlayer( msg_id );
}
if (msg_type == "CUS"){ //mensagem personalizada
NetCustomMessage* cus_msg = new NetCustomMessage(net_msg);
//adiconar *net_msg a um vector (ou outro container) para uso futuro pelo usuario
pNetClient->m_qCustomMessageQueue.push( cus_msg );
}
if (msg_type == "SERVER_CLOSED"){
pNetClient->stopEverything();
break;
}
if (msg_type == "SERVER_PING"){
pNetClient->answerPing();
}
SDL_SemPost (pNetClient->m_pSemEntityValues); /** terminou de mexer nas entidades... liberar acesso **/
NetControl::postForSync();
//SDL_SemPost (NetControl::m_pSemNetAndLocalSync);
}
SDLNet_FreePacket( in_packet );
if ( xmlcontainer )
delete ( xmlcontainer );
return 0;
}