本文整理汇总了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;
}
}
示例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;
}
示例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 );
}
示例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;
}
}
示例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;
}