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


C++ OutputMemoryBitStream::GetBufferPtr方法代码示例

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


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

示例1: Finish

void NetworkServer::Finish(int player)
{
	OutputMemoryBitStream ombs;
	ombs.Write(PacketType::PT_FINISH, 3);
	//Escribimos en nuestro OMBS las posiciones absolutas de los jugadores.
 	ombs.Write(player, 2);
	sendToAllChar(ombs.GetBufferPtr());

	for (int i = 0; i < 4; i++)
	{
		playerList[i].position = 0;
	}
}
开发者ID:DagorladFinite,项目名称:Steeplechase,代码行数:13,代码来源:NetworkServer.cpp

示例2: ComputeGlobalCRC

uint32_t NetworkManager::ComputeGlobalCRC()
{
	//save into bit stream to reduce CRC calls
	OutputMemoryBitStream crcStream;

	uint32_t crc = static_cast<uint32_t>( crc32( 0, Z_NULL, 0 ) );

	for ( auto& iter : mNetworkIdToGameObjectMap )
	{
		iter.second->WriteForCRC( crcStream );
	}

	crc = static_cast<uint32_t>( crc32( crc, reinterpret_cast<const Bytef*>(crcStream.GetBufferPtr()), crcStream.GetByteLength() ) );
	return crc;
}
开发者ID:caldera,项目名称:MultiplayerBook,代码行数:15,代码来源:NetworkManager.cpp

示例3: OutputMemoryBitStream

// Test if you can write to the buffer stream
TEST( OutputMemoryBitStream, WritePrimatives )
{
    OutputMemoryBitStream x = OutputMemoryBitStream();

    x.Write( 12 ); // write 4 bytes equal to 12
    x.Write( 2 );  // write 4 bytes equal to 2
    x.Write( -2 ); // write 4 bytes equal to -2
    x.Write( 0 );  // write 4 bytes equal to 0

    const char* buffer = x.GetBufferPtr();

    // Check if each value was written to the stream
    EXPECT_EQ( int( *buffer ), 12 );
    buffer = buffer + 4;
    EXPECT_EQ( int( *buffer ), 2 );
    buffer = buffer + 4;
    EXPECT_EQ( int( *buffer ), -2 );
    buffer = buffer + 4;
    EXPECT_EQ( int( *buffer ), 0 );
}
开发者ID:etinlb,项目名称:networkplayground,代码行数:21,代码来源:OutputMemoryBitStream_test.cpp

示例4: Dispatch

void NetworkServer::Dispatch(){

	clock_t time = clock();
	if (time > dispatchTime + 125)
	{
		OutputMemoryBitStream ombs;
		ombs.Write(PacketType::PT_AUTHOR, 3);
		for (size_t i = 0; i < 4; i++)
		{
			//Escribimos en nuestro OMBS las posiciones absolutas de los jugadores.
			ombs.Write(playerList[i].position, 10);

		}

		ombs.Write(cheaterAlarm, 1);
		sendToAllChar(ombs.GetBufferPtr());

		cheaterAlarm = 0;
		dispatchTime = time;
	}


}
开发者ID:DagorladFinite,项目名称:Steeplechase,代码行数:23,代码来源:NetworkServer.cpp

示例5: processMessageBit

bool NetworkServer::processMessageBit(char* _message,int _size, SocketAddress _saClient)
{


	InputMemoryBitStream imbs(_message, _size * 8);
	PacketType pt = PacketType::PT_EMPTY;
	imbs.Read(&pt, 3);
	int player = 0;

	for (int i = 0; i < 4; i++)
	{
		if (playerList[i].GetSocketAddress() == _saClient)
		{
			player = i;
		}
	}

	if (pt == PacketType::PT_HELLO) {

		std::cout << "Hola!";
		std::string nick;
		imbs.ReadString(&nick);
		playerList[playerlibre].SetNick(nick);
		playerList[playerlibre].SetAddress(_saClient);
		playerList[playerlibre].connected = true;
		for (int i = 0; i < 4; i++)
		{
			if (playerList[i].GetSocketAddress() == _saClient)
			{
				player = i;
			}
		}
		OutputMemoryBitStream ombs;
		ombs.Write(PacketType::PT_WELCOME, 3);
		ombs.Write(player, 2);
		udpSocket.SendTo(ombs.GetBufferPtr(), 1300, playerList[playerlibre].GetSocketAddress());
		playerlibre++;
	}

	if (pt == PacketType::PT_MOVE) {


		newInfo = true;
		//std::cout << "Me ha llegado una petición de movimiento."<< std::endl;;
		int toMove = 0;

		//Incremento de posición
		imbs.Read(&toMove, 2);

		//Revisamos el número de pulsaciones
		//El record Guinness de pulsaciones en 5 segundos nos permite calcular el número de pulsaciones cada 100ms
		//Este número de pulsaciones es aproximadamente 1,5 - 2,25 pulsaciones/100ms
		//De esto extraemos que el número de veces que podamos ver un 3 es INFINITAMENTE PEQUEÑO
		//Si detectamos más de un cierto número, devolvemos al jugador al inicio
		//No rest for the wicked

		if (toMove == 3) {

			playerList[player].antiCheatCount++;

		}

		//Posición de seguridad enviada por el cliente.
		//Se establece aquí para evitar el impacto de la perdida de paquetes.
		imbs.Read(&playerList[player].position, 10);

		
		
		playerList[player].position = playerList[player].position + (3 * toMove);
		//std::cout << "El jugador se ha movido a la posición: " << playerList[player].position << std::endl;
		
		if (playerList[player].position >= 637)
		{
			Finish(player);
			std::cout << "Victoria del jugador: " << player << std::endl;
		}

	}

	return false;
}
开发者ID:DagorladFinite,项目名称:Steeplechase,代码行数:81,代码来源:NetworkServer.cpp


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