本文整理汇总了C++中raknet::BitStream::GetNumberOfBitsUsed方法的典型用法代码示例。如果您正苦于以下问题:C++ BitStream::GetNumberOfBitsUsed方法的具体用法?C++ BitStream::GetNumberOfBitsUsed怎么用?C++ BitStream::GetNumberOfBitsUsed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类raknet::BitStream
的用法示例。
在下文中一共展示了BitStream::GetNumberOfBitsUsed方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Destruct
void ReplicaManager::Destruct(Replica *replica, PlayerID playerId, bool broadcast)
{
assert(replica);
bool objectExists;
unsigned replicatedObjectsIndex;
replicatedObjectsIndex = replicatedObjects.GetIndexFromKey(replica, &objectExists);
if (objectExists==false)
return;
// For each existing participant, send a packet telling them of this object destruction
RakNet::BitStream outBitstream;
unsigned i,tempIndex;
bool replicaReferenced;
ParticipantStruct *participantStruct;
replicaReferenced=false;
for (i=0; i < participantList.Size(); i++)
{
participantStruct=participantList[i];
if ((broadcast==true && playerId!=participantStruct->playerId) ||
(broadcast==false && playerId==participantStruct->playerId))
{
// Send the destruction packet immediately
if (replica->GetNetworkID()!=UNASSIGNED_NETWORK_ID && (replicatedObjects[replicatedObjectsIndex].allowedInterfaces & REPLICA_SEND_DESTRUCTION))
{
outBitstream.Reset();
outBitstream.Write((unsigned char)ID_REPLICA_MANAGER_DESTRUCTION);
outBitstream.Write(replica->GetNetworkID());
replica->SendDestruction(&outBitstream, participantStruct->playerId);
if (outBitstream.GetNumberOfBitsUsed()>0)
{
rakPeer->Send(&outBitstream, HIGH_PRIORITY, RELIABLE_ORDERED, sendChannel, participantStruct->playerId, false);
}
}
// Remove any pending commands that reference this object, for this player
tempIndex = participantStruct->commandList.GetIndexFromKey(replica, &objectExists);
if (objectExists)
participantStruct->commandList.RemoveAtIndex(tempIndex);
// Remove any remote object state tracking for this object, for this player
tempIndex = participantStruct->remoteObjectList.GetIndexFromKey(replica, &objectExists);
if (objectExists)
participantStruct->remoteObjectList.RemoveAtIndex(tempIndex);
}
else if (replicaReferenced==false)
{
// See if any commands or objects reference replica
if (participantStruct->commandList.HasData(replica))
replicaReferenced=true;
else if (participantStruct->remoteObjectList.HasData(replica))
replicaReferenced=true;
}
}
// Remove replica from the list if no commands and no remote objects reference it
if (replicaReferenced==false)
replicatedObjects.RemoveAtIndex(replicatedObjectsIndex);
}
示例2: EncodeString
void StringCompressor::EncodeString( const char *input, int maxCharsToWrite, RakNet::BitStream *output, int languageID )
{
HuffmanEncodingTree *huffmanEncodingTree;
if (huffmanEncodingTrees.Has(languageID)==false)
return;
huffmanEncodingTree=huffmanEncodingTrees.Get(languageID);
if ( input == 0 )
{
output->WriteCompressed( (unsigned short) 0 );
return;
}
RakNet::BitStream encodedBitStream;
unsigned short stringBitLength;
int charsToWrite;
if ( maxCharsToWrite<=0 || ( int ) strlen( input ) < maxCharsToWrite )
charsToWrite = ( int ) strlen( input );
else
charsToWrite = maxCharsToWrite - 1;
huffmanEncodingTree->EncodeArray( ( unsigned char* ) input, charsToWrite, &encodedBitStream );
stringBitLength = ( unsigned short ) encodedBitStream.GetNumberOfBitsUsed();
output->WriteCompressed( stringBitLength );
output->WriteBits( encodedBitStream.GetData(), stringBitLength );
}