本文整理汇总了C++中raknet::BitStream::WriteBits方法的典型用法代码示例。如果您正苦于以下问题:C++ BitStream::WriteBits方法的具体用法?C++ BitStream::WriteBits怎么用?C++ BitStream::WriteBits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类raknet::BitStream
的用法示例。
在下文中一共展示了BitStream::WriteBits方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EncodeClassName
void EncodeClassName( char *name, char *identifier )
{
RakNet::BitStream bitStream;
int index = 0;
unsigned char byte;
while ( index < MAXIMUM_CLASS_IDENTIFIER_LENGTH - 1 )
{
if ( name[ index ] == 0 )
break;
// This should generate a unique identifier for any realistic class name that is 5/8th the length of the actual name and weakly encrypts and compresses it
if ( name[ index ] >= 'a' && name[ index ] <= 'z' )
byte = name[ index ] - 'a';
else if ( name[ index ] >= 'A' && name[ index ] <= 'Z' )
byte = name[ index ] - 'A';
else if ( name[ index ] >= '0' && name[ index ] <= '9' )
byte = name[ index ] - '0';
else
byte = name[ index ] << 3;
bitStream.WriteBits( ( unsigned char* ) & byte, 5 );
index++;
}
#ifdef _DEBUG
memset( identifier, 0, MAXIMUM_CLASS_IDENTIFIER_LENGTH );
#endif
identifier[ 0 ] = ( char ) ( bitStream.GetNumberOfBytesUsed() );
memcpy( identifier + 1, bitStream.GetData(), bitStream.GetNumberOfBytesUsed() );
}
示例2: initialSync
void Server::initialSync(const RakNet::SystemAddress &sa,running_machine *machine)
{
unsigned char checksum = 0;
waitingForClientCatchup=true;
machine->osd().pauseAudio(true);
int syncBytes;
{
RakNet::BitStream uncompressedStream;
uncompressedStream.Write(startupTime);
uncompressedStream.Write(globalCurtime);
if(getSecondsBetweenSync())
{
while(memoryBlocksLocked)
{
;
}
memoryBlocksLocked=true;
cout << "IN CRITICAL SECTION\n";
cout << "SERVER: Sending initial snapshot\n";
int numBlocks = int(blocks.size());
cout << "NUMBLOCKS: " << numBlocks << endl;
uncompressedStream.Write(numBlocks);
// NOTE: The server must send stale data to the client for the first time
// So that future syncs will be accurate
for(int blockIndex=0; blockIndex<int(initialBlocks.size()); blockIndex++)
{
//cout << "BLOCK SIZE FOR INDEX " << blockIndex << ": " << staleBlocks[blockIndex].size << endl;
uncompressedStream.Write(initialBlocks[blockIndex].size);
cout << "BLOCK " << blockIndex << ": ";
for(int a=0; a<staleBlocks[blockIndex].size; a++)
{
checksum = checksum ^ staleBlocks[blockIndex].data[a];
//cout << int(staleBlocks[blockIndex].data[a]) << ' ';
unsigned char value = initialBlocks[blockIndex].data[a] ^ staleBlocks[blockIndex].data[a];
uncompressedStream.WriteBits(&value,8);
}
cout << int(checksum) << endl;
}
}
for(
map<int,vector< string > >::iterator it = peerInputs.begin();
it != peerInputs.end();
it++
)
{
uncompressedStream.Write(it->first);
uncompressedStream.Write(int(oldPeerInputs[it->first].size()) + int(it->second.size()));
for(int a=0; a<(int)it->second.size(); a++)
{
uncompressedStream.Write(int(it->second[a].length()));
uncompressedStream.WriteBits((const unsigned char*)it->second[a].c_str(),it->second[a].length()*8);
for(int b=0;b<it->second[a].length();b++)
{
checksum = checksum ^ it->second[a][b];
}
}
for(int a=0; a<int(oldPeerInputs[it->first].size()); a++)
{
uncompressedStream.Write(int(oldPeerInputs[it->first][a].length()));
uncompressedStream.WriteBits((const unsigned char*)oldPeerInputs[it->first][a].c_str(),oldPeerInputs[it->first][a].length()*8);
for(int b=0;b<oldPeerInputs[it->first][a].length();b++)
{
checksum = checksum ^ oldPeerInputs[it->first][a][b];
}
}
}
uncompressedStream.Write(int(-1));
uncompressedStream.Write(checksum);
cout << "CHECKSUM: " << int(checksum) << endl;
if(uncompressedBufferSize<uncompressedStream.GetNumberOfBytesUsed()+sizeof(int))
{
uncompressedBufferSize = uncompressedStream.GetNumberOfBytesUsed()+sizeof(int);
free(uncompressedBuffer);
uncompressedBuffer = (unsigned char*)malloc(uncompressedBufferSize);
if(!uncompressedBuffer)
{
cout << __FILE__ << ":" << __LINE__ << " OUT OF MEMORY\n";
exit(1);
}
}
syncBytes = uncompressedStream.GetNumberOfBytesUsed();
memcpy(uncompressedBuffer,uncompressedStream.GetData(),uncompressedStream.GetNumberOfBytesUsed());
int uncompressedStateSize = (int)uncompressedStream.GetNumberOfBytesUsed();
printf("INITIAL UNCOMPRESSED STATE SIZE: %d\n",uncompressedStateSize);
}
cout << "PUTTING NVRAM AT LOCATION " << syncBytes << endl;
//.........这里部分代码省略.........