本文整理汇总了C++中BitStream::Reset方法的典型用法代码示例。如果您正苦于以下问题:C++ BitStream::Reset方法的具体用法?C++ BitStream::Reset怎么用?C++ BitStream::Reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitStream
的用法示例。
在下文中一共展示了BitStream::Reset方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Disconnect
//--------------------------------------------------------------------------
void ClientAgent::Disconnect()
{
BitStream kStream;
kStream.Reset();
kStream << VeUInt8(ID_CLIENT_FORCE_DISCONNECT);
SendPacket(kStream);
}
示例2: SyncToClient
//--------------------------------------------------------------------------
void EntityS::SyncToClient()
{
if(m_pkAgent)
{
if(m_kSyncDirty.Size())
{
BitStream kStream;
kStream.Reset();
kStream << VeUInt8(ID_CLIENT_ENTITY_UPDATE);
kStream << (const VeChar8*)m_kName;
VE_ASSERT(m_kSyncDirty.Size() <= VE_UINT16_MAX);
kStream << VeUInt16(m_kSyncDirty.Size());
m_kSyncDirty.BeginIterator();
while(!m_kSyncDirty.IsEnd())
{
PropertySValue* pkValue = m_kSyncDirty.GetIterNode()->m_tContent;
m_kSyncDirty.Next();
VE_ASSERT(pkValue);
kStream << pkValue->GetField();
VE_ASSERT(pkValue->GetSize() <= 0xff);
kStream.WriteAlignedBytesSafe((const VeChar8*)pkValue->GetClientData(), pkValue->GetClientSize(), VE_UINT8_MAX);
}
m_kSyncDirty.Clear();
m_pkAgent->SendPacket(kStream);
}
}
}
示例3: S_ReqSyncTime
void TexasPokerHallAgentC::S_ReqSyncTime()
{
BitStream kStream;
kStream.Reset();
kStream << VeUInt8(ID_SERVER_GLOBAL_RPC);
kStream << VeUInt8(SERVER_ReqSyncTime);
SendPacket(kStream);
}
示例4: DestoryFromClient
//--------------------------------------------------------------------------
void EntityS::DestoryFromClient()
{
if(m_pkAgent)
{
BitStream kStream;
kStream.Reset();
kStream << VeUInt8(ID_CLIENT_ENTITY_DESTORY);
kStream << VEString(m_kName);
m_pkAgent->SendPacket(kStream);
}
}
示例5: S_ReqLogin
/// </CODE-GENERATE>{EntitiesClientGetterImpl}
//--------------------------------------------------------------------------
/// <CODE-GENERATE>{GlobalServerFuncSend}
void TexasPokerHallAgentC::S_ReqLogin(const VeChar8* strPlayerUUID, const VeChar8* strChannel, const VeChar8* strDeviceName, const LanguageS& tLanguage, VeUInt8 u8VersionMajor, VeUInt8 u8VersionMinor)
{
BitStream kStream;
kStream.Reset();
kStream << VeUInt8(ID_SERVER_GLOBAL_RPC);
kStream << VeUInt8(SERVER_ReqLogin);
kStream << strPlayerUUID;
kStream << strChannel;
kStream << strDeviceName;
kStream << tLanguage;
kStream << u8VersionMajor;
kStream << u8VersionMinor;
SendPacket(kStream);
}
示例6: SyncAllToClient
//--------------------------------------------------------------------------
void EntityS::SyncAllToClient()
{
if(m_pkAgent)
{
BitStream kStream;
kStream.Reset();
kStream << VeUInt8(ID_CLIENT_ENTITY_UPDATE);
kStream << (const VeChar8*)m_kName;
VE_ASSERT(m_kSyncChildren.Size() <= VE_UINT16_MAX);
kStream << VeUInt16(m_kSyncChildren.Size());
for(VeUInt32 i(0); i < m_kSyncChildren.Size(); ++i)
{
PropertySValue* pkValue = m_kSyncChildren[i];
kStream << pkValue->GetField();
VE_ASSERT(pkValue->GetSize() <= 0xff);
kStream.WriteAlignedBytesSafe((const VeChar8*)pkValue->GetClientData(), pkValue->GetClientSize(), VE_UINT8_MAX);
}
m_pkAgent->SendPacket(kStream);
}
}
示例7: RunTest
//.........这里部分代码省略.........
case ID_CONNECTION_REQUEST_ACCEPTED:
if (isVerbose)
printf("ID_CONNECTION_REQUEST_ACCEPTED\n");
doSend=true;
nextSend=currentTime;
break;
case ID_NO_FREE_INCOMING_CONNECTIONS:
if (isVerbose)
printf("ID_NO_FREE_INCOMING_CONNECTIONS\n");
break;
case ID_DISCONNECTION_NOTIFICATION:
if (isVerbose)
printf("ID_DISCONNECTION_NOTIFICATION\n");
break;
case ID_CONNECTION_LOST:
if (isVerbose)
printf("ID_CONNECTION_LOST\n");
break;
case ID_CONNECTION_ATTEMPT_FAILED:
if (isVerbose)
printf("Connection attempt failed\n");
break;
}
sender->DeallocatePacket(packet);
packet = sender->Receive();
}
while (doSend && currentTime > nextSend)
{
streamNumberSender=0;
// streamNumber = randomMT() % 32;
// Do the send
bitStream.Reset();
bitStream.Write((unsigned char) (ID_USER_PACKET_ENUM+1));
bitStream.Write(packetNumberSender[streamNumberSender]++);
bitStream.Write(streamNumberSender);
bitStream.Write(currentTime);
char *pad;
int padLength = (randomMT() % 5000) + 1;
pad = new char [padLength];
bitStream.Write(pad, padLength);
delete [] pad;
// Send on a random priority with a random stream
// if (sender->Send(&bitStream, HIGH_PRIORITY, (PacketReliability) (RELIABLE + (randomMT() %2)) ,streamNumber, UNASSIGNED_SYSTEM_ADDRESS, true)==false)
if (sender->Send(&bitStream, HIGH_PRIORITY, RELIABLE_ORDERED ,streamNumberSender, UNASSIGNED_SYSTEM_ADDRESS, true)==false)
packetNumberSender[streamNumberSender]--; // Didn't finish connecting yet?
RakNetStatistics *rssSender;
rssSender=sender->GetStatistics(sender->GetSystemAddressFromIndex(0));
if (isVerbose)
printf("Snd: %i.\n", packetNumberSender[streamNumberSender]);
nextSend+=sendInterval;
// Test halting
// if (rand()%20==0)
// nextSend+=1000;
}
packet = receiver->Receive();
while (packet)
{
switch(packet->data[0])
{
case ID_NEW_INCOMING_CONNECTION:
示例8: RunTest
//.........这里部分代码省略.........
TimeMS entryTime=GetTimeMS();//Loop entry time
TimeMS finishTimer=GetTimeMS();
bool initialConnectOver=false;//Our initial connect all has been done.
for (int k=0;k<numPackets||GetTimeMS()-finishTimer<5000;)//Quit after we send 100 messages while connected, if not all connected and not failure, otherwise fail after 20 seconds and exit
{
bool allConnected=true;//Start true, only one failed case makes it all fail
for (int i=0;i<peerNum;i++)//Make sure all peers are connected to eachother
{
if (connectionAmount[i]<peerNum-1)
{
allConnected=false;
}
}
if (GetTimeMS()-entryTime>20000 &&!initialConnectOver &&!allConnected)//failed for 20 seconds
{
if (isVerbose)
DebugTools::ShowError("Failed to connect to all peers after 20 seconds",!noPauses && isVerbose,__LINE__,__FILE__);
return 2;
break;
}
if (allConnected)
{
if(!initialConnectOver)
initialConnectOver=true;
if (k<numPackets)
{
for (int i=0;i<peerNum;i++)//Have all peers send a message to all peers
{
bitStream.Reset();
bitStream.Write((unsigned char) (ID_USER_PACKET_ENUM+1));
bitStream.Write(k);
bitStream.Write(i);
peerList[i]->Send(&bitStream, HIGH_PRIORITY, RELIABLE_ORDERED ,0, UNASSIGNED_SYSTEM_ADDRESS, true);
}
}
k++;
}
if (k>=numPackets-3)//This is our last 3 packets, give it time to send packet and arrive on interface, 2 seconds is more than enough
{
RakSleep(300);
if (k==numPackets)
{
finishTimer=GetTimeMS();
}
}
for (int i=0;i<peerNum;i++)//Receive for all peers
{
if (allConnected)//If all connected try to make the data more visually appealing by bunching it in one receive
{
int waittime=0;
do
{
packet=peerList[i]->Receive();
waittime++;
示例9: OnAutopatcherRequestFiles
void AutoPatcher::OnAutopatcherRequestFiles( Packet *packet )
{
assert( rakPeerInterface || rakClientInterface || rakServerInterface );
BitStream serializedFileDescriptor( ( char* ) packet->data, packet->length, false );
BitStream outputBitStream;
DownloadableFileDescriptor dfd;
unsigned int numberOfFilesRequested;
unsigned index, downloadableFilesIndex;
unsigned char packetID;
// Holds a copy of the pointers. Don't deallocate them!
BasicDataStructures::List<DownloadableFileDescriptor*> sendList;
// Ignore ID_AUTOPATCHER_REQUEST_FILES
serializedFileDescriptor.IgnoreBits( sizeof( unsigned char ) * 8 );
if ( serializedFileDescriptor.ReadCompressed( numberOfFilesRequested ) == false )
{
// Invalid packet format. Should never get this unless it's a bug or someone is hacking
#ifdef _DEBUG
assert( 0 );
#endif
return ;
}
// Go through all the files requested in the packet.
// If we allow download of it, add the descriptor to a send list which we
// serialize and send back to the sender telling them what files they will get.
// This is necessary because it is possible that cheaters will request files
// not in the list or that files will be removed from downloadable status after an initial
// successful request for it
for ( index = 0; index < numberOfFilesRequested; index++ )
{
dfd.Clear();
if ( dfd.DeserializeHeader( &serializedFileDescriptor ) == false )
{
assert( 0 ); // Error in packet header. Should only get this from hackers or bugs
return ;
}
for ( downloadableFilesIndex = 0; downloadableFilesIndex < downloadableFiles.size(); downloadableFilesIndex++ )
{
if ( strcmp( downloadableFiles[ downloadableFilesIndex ] ->filename, dfd.filename ) == 0 )
{
// Record that we are going to send this file to system requesting it
sendList.insert( downloadableFiles[ downloadableFilesIndex ] );
break;
}
}
}
packetID = ID_AUTOPATCHER_SET_DOWNLOAD_LIST;
// Serialize the list of files we will send
outputBitStream.Write( packetID );
outputBitStream.WriteCompressed( sendList.size() );
for ( index = 0; index < sendList.size(); index++ )
sendList[ index ] ->SerializeHeader( &outputBitStream );
// Send the list of files
if ( rakServerInterface )
rakServerInterface->Send( &outputBitStream, MEDIUM_PRIORITY, RELIABLE_ORDERED, orderingStream, packet->playerId, false );
else
if ( rakPeerInterface )
rakPeerInterface->Send( &outputBitStream, MEDIUM_PRIORITY, RELIABLE_ORDERED, orderingStream, packet->playerId, false );
else
rakClientInterface->Send( &outputBitStream, MEDIUM_PRIORITY, RELIABLE_ORDERED, orderingStream );
// The next step is to send the actual files. We already know what files need to be sent -
// The files specified by the descriptors in sendList.
packetID = ID_AUTOPATCHER_WRITE_FILE;
for ( index = 0; index < sendList.size(); index++ )
{
// We used outputBitStream earlier so don't forget to reset it
outputBitStream.Reset();
outputBitStream.Write( packetID );
sendList[ index ] ->SerializeHeader( &outputBitStream );
sendList[ index ] ->SerializeFileData( &outputBitStream );
if ( rakServerInterface )
rakServerInterface->Send( &outputBitStream, LOW_PRIORITY, RELIABLE_ORDERED, orderingStream, packet->playerId, false );
else
if ( rakPeerInterface )
rakPeerInterface->Send( &outputBitStream, LOW_PRIORITY, RELIABLE_ORDERED, orderingStream, packet->playerId, false );
else
rakClientInterface->Send( &outputBitStream, LOW_PRIORITY, RELIABLE_ORDERED, orderingStream );
}
}
示例10: rakVoiceThread
void* rakVoiceThread( void* arguments )
#endif
{
SpeexBits bits;
char output[ 2000 ];
int outputLength;
unsigned char typeID;
PlayerID id;
BitStream b;
int availableChunks;
int MTU;
int numberOfChunksPerSend;
int i;
unsigned long lastSendTime;
CoderStateWithPlayerIDMapStruct *cswpims;
lastSendTime = RakNet::GetTime();
PlayerID target;
RakVoice *rakVoice = ( RakVoice* ) arguments;
numberOfChunksPerSend = rakVoice->blockSize / rakVoice->frame_size;
speex_bits_init( &bits );
MTU = rakVoice->peer->GetMTUSize();
while ( rakVoice->init )
{
if ( rakVoice->writeCursor >= rakVoice->readCursor )
availableChunks = rakVoice->writeCursor - rakVoice->readCursor;
else
availableChunks = RAK_VOICE_INPUT_LIST_BUFFER_SIZE - rakVoice->readCursor + rakVoice->writeCursor;
while ( availableChunks >= numberOfChunksPerSend )
{
// Get a bit of a buffer before we start sending so we don't "grind" the data and get popping as data continually arrives and runs out
if ( RakNet::GetTime() - lastSendTime > 1000 && availableChunks < numberOfChunksPerSend * 3 )
break;
// Grab data at the read cursor and encode it
speex_bits_reset( &bits );
target = rakVoice->targetedSendRecipient[ rakVoice->readCursor ];
cswpims = rakVoice->GetCoderFromPlayerID( rakVoice->sampleRate, target, false );
for ( i = 0; i < numberOfChunksPerSend; i++ )
{
// For each frame, call speex_encode
speex_encode( cswpims->encoderState, rakVoice->inputList[ rakVoice->readCursor ], &bits );
rakVoice->readCursor = ( rakVoice->readCursor + 1 ) % RAK_VOICE_INPUT_LIST_BUFFER_SIZE;
}
availableChunks -= numberOfChunksPerSend;
// Write the encoded bitstream
outputLength = speex_bits_write( ( SpeexBits* ) ( &bits ), output, 2000 );
#ifdef _DEBUG
static bool printOnce = true;
if ( printOnce == true && outputLength > MTU )
{
printf( "Warning - compressed data larger than MTU! This will result in split packets and poor speech.\nYou should use a lower blockSize in the call to Init.\n" );
printOnce = false;
}
else if ( printOnce == true && outputLength < MTU / 4 )
{
printf( "Warning - compressed data smaller than 1/4 the MTU. This is not an efficient use of bandwidth.\nYou might want to use a larger blockSize in the call to Init.\n" );
printOnce = false;
}
#endif
b.Reset();
typeID = ID_VOICE_PACKET;
b.Write( typeID );
b.Write( ( char* ) & target, sizeof( target ) );
b.Write( rakVoice->bps ); // Write how many bits we are encoding the data with
b.Write( rakVoice->sampleRate ); // Write the sampling rate
id = rakVoice->peer->GetInternalID();
b.Write( ( char* ) & id, sizeof( id ) ); // Write who is sending this packet
b.Write( cswpims->nextPacketNumber ); // Write what speech packet number this is, so we can compensate for lost packets
cswpims->nextPacketNumber++;
b.Write( output, outputLength );
/*
//.........这里部分代码省略.........