当前位置: 首页>>代码示例>>C++>>正文


C++ NetClient::checkOtherPlayer方法代码示例

本文整理汇总了C++中NetClient::checkOtherPlayer方法的典型用法代码示例。如果您正苦于以下问题:C++ NetClient::checkOtherPlayer方法的具体用法?C++ NetClient::checkOtherPlayer怎么用?C++ NetClient::checkOtherPlayer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NetClient的用法示例。


在下文中一共展示了NetClient::checkOtherPlayer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: receiver

int NetClient::receiver (void* instance){ /** CRITICA **/
	NetClient* pNetClient = (NetClient *) instance;

	UDPpacket* in_packet;
	TiXmlDocument* xmlcontainer = new TiXmlDocument();
	TiXmlElement* net_msg;
	string msg_type;
	int msg_id;
	string plyName;
	char* data = NULL;


	in_packet = SDLNet_AllocPacket(NetControl::M_PACKET_SIZE);

	while (!pNetClient->m_stopClient){
		pNetClient->m_threadReceiverReady = true;
		while(!SDLNet_UDP_Recv(pNetClient->m_sock, in_packet)){
			pNetClient->checkServerTimeout();
			
			if (pNetClient->m_stopClient)
				break;
			
			SDL_Delay(NetControl::M_RECEIVER_DELAY); //  RECEIVER_DELAY/1000 seconds
		}

		if (pNetClient->m_stopClient)
			break;
			
			pNetClient->m_lastServerMsg = SDL_GetTicks();
	
		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 );
		}
	
//.........这里部分代码省略.........
开发者ID:indigente,项目名称:libinge,代码行数:101,代码来源:NetClient.cpp


注:本文中的NetClient::checkOtherPlayer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。