本文整理汇总了C++中OutputMemoryBitStream类的典型用法代码示例。如果您正苦于以下问题:C++ OutputMemoryBitStream类的具体用法?C++ OutputMemoryBitStream怎么用?C++ OutputMemoryBitStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OutputMemoryBitStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SendInputPacket
void NetworkManagerClient::SendInputPacket()
{
//only send if there's any input to sent!
const MoveList& moveList = InputManager::sInstance->GetMoveList();
if( moveList.HasMoves() )
{
OutputMemoryBitStream inputPacket;
inputPacket.Write( kInputCC );
mDeliveryNotificationManager.WriteState( inputPacket );
//eventually write the 3 latest moves so they have three chances to get through...
int moveCount = moveList.GetMoveCount();
int firstMoveIndex = moveCount - 3;
if( firstMoveIndex < 3 )
{
firstMoveIndex = 0;
}
auto move = moveList.begin() + firstMoveIndex;
//only need two bits to write the move count, because it's 0, 1, 2 or 3
inputPacket.Write( moveCount - firstMoveIndex, 2 );
for( ; firstMoveIndex < moveCount; ++firstMoveIndex, ++move )
{
///would be nice to optimize the time stamp...
move->Write( inputPacket );
}
SendPacket( inputPacket, mServerAddress );
}
}
示例2: TEST
// Testing
TEST( OutputMemoryBitStream, GetBitLength )
{
OutputMemoryBitStream x = OutputMemoryBitStream();
x.Write( 12 );
x.Write( 2 );
x.Write( -2 );
x.Write( 0 );
uint32_t streamSize = x.GetBitLength();
// 4 entries * bytesInInt * 8 bits
uint32_t numOfBitsWritten = 4 * sizeof( uint32_t ) * 8;
EXPECT_EQ( streamSize, numOfBitsWritten );
x.Write( 0 ); // Write 32 more bits
streamSize = x.GetBitLength();
EXPECT_EQ( streamSize, numOfBitsWritten + sizeof( uint32_t ) * 8 );
x.Write( true ); // 2 more bits
x.Write( true );
streamSize = x.GetBitLength();
EXPECT_EQ( streamSize, numOfBitsWritten + sizeof( uint32_t ) * 8 + 2 );
}
示例3: Write
void TurnData::Write( OutputMemoryBitStream& inOutputStream )
{
inOutputStream.Write( mPlayerId );
inOutputStream.Write( mRandomValue );
inOutputStream.Write( mCRC );
mCommandList.Write( inOutputStream );
}
示例4: UpdateDelay
void NetworkManager::UpdateDelay()
{
//first process incoming packets, in case that removes us from delay
NetworkManager::sInstance->ProcessIncomingPackets();
if( mState == NMS_Delay )
{
mDelayHeartbeat -= Timing::sInstance.GetDeltaTime();
if( mDelayHeartbeat <= 0.0f )
{
mDelayHeartbeat = kTimeBetweenDelayHeartbeat;
}
//find out who's missing and send them a heartbeat
unordered_set< uint64_t > playerSet;
for( auto& iter : mPlayerNameMap )
{
playerSet.emplace( iter.first );
}
Int64ToTurnDataMap& turnData = mTurnData[ mTurnNumber + 1 ];
for( auto& iter : turnData )
{
playerSet.erase( iter.first );
}
OutputMemoryBitStream packet;
packet.Write( kDelayCC );
//whoever's left is who's missing
for( auto& iter : playerSet )
{
SendPacket( packet, iter );
}
}
}
示例5: LOG
void NetworkManager::TryStartGame()
{
if ( mState == NMS_Ready && IsMasterPeer() && mPlayerCount == mReadyCount )
{
LOG( "Starting!" );
//let everyone know
OutputMemoryBitStream outPacket;
outPacket.Write( kStartCC );
//select a seed value
uint32_t seed = RandGen::sInstance->GetRandomUInt32( 0, UINT32_MAX );
RandGen::sInstance->Seed( seed );
outPacket.Write( seed );
for ( auto &iter : mPlayerNameMap )
{
if( iter.first != mPlayerId )
{
SendPacket( outPacket, iter.first );
}
}
mTimeToStart = kStartDelay;
mState = NMS_Starting;
}
}
示例6: SendHelloPacket
void NetworkManagerClient::SendHelloPacket()
{
OutputMemoryBitStream helloPacket;
helloPacket.Write( kHelloCC );
helloPacket.Write( mName );
SendPacket( helloPacket, mServerAddress );
}
示例7: Write
void ReplicationManagerServer::Write( OutputMemoryBitStream& inOutputStream )
{
//run through each replication command and do something...
for( auto& pair: mNetworkIdToReplicationCommand )
{
ReplicationCommand& replicationCommand = pair.second;
if( replicationCommand.HasDirtyState() )
{
int networkId = pair.first;
//well, first write the network id...
inOutputStream.Write( networkId );
//only need 2 bits for action...
ReplicationAction action = replicationCommand.GetAction();
inOutputStream.Write( action, 2 );
uint32_t writtenState = 0;
uint32_t dirtyState = replicationCommand.GetDirtyState();
//now do what?
switch( action )
{
case RA_Create:
writtenState = WriteCreateAction( inOutputStream, networkId, dirtyState );
//once the create action is transmitted, future replication
//of this object should be updates instead of creates
replicationCommand.SetAction( RA_Update );
break;
case RA_Update:
writtenState = WriteUpdateAction( inOutputStream, networkId, dirtyState );
break;
case RA_Destroy:
//don't need anything other than state!
writtenState = WriteDestroyAction( inOutputStream, networkId, dirtyState );
//add this to the list of replication commands to remove
mNetworkIdsToRemove.emplace_back( networkId );
break;
}
//let's pretend everything was written- don't make this too hard
replicationCommand.ClearDirtyState( writtenState );
}
}
//remove replication commands for destroyed objects
if( !mNetworkIdsToRemove.empty() )
{
for( auto id : mNetworkIdsToRemove )
{
RemoveFromReplication( id );
}
mNetworkIdsToRemove.clear();
}
}
示例8: SendWelcomePacket
void NetworkManagerServer::SendWelcomePacket( ClientProxyPtr inClientProxy )
{
OutputMemoryBitStream welcomePacket;
welcomePacket.Write( kWelcomeCC );
welcomePacket.Write( inClientProxy->GetPlayerId() );
LOG( "Server Welcoming, new client '%s' as player %d", inClientProxy->GetName().c_str(), inClientProxy->GetPlayerId() );
SendPacket( welcomePacket, inClientProxy->GetSocketAddress() );
}
示例9: WriteLastMoveTimestampIfDirty
void NetworkManagerServer::WriteLastMoveTimestampIfDirty( OutputMemoryBitStream& inOutputStream, ClientProxyPtr inClientProxy )
{
//first, dirty?
bool isTimestampDirty = inClientProxy->IsLastMoveTimestampDirty();
inOutputStream.Write( isTimestampDirty );
if( isTimestampDirty )
{
inOutputStream.Write( inClientProxy->GetUnprocessedMoveList().GetLastMoveTimestamp() );
inClientProxy->SetIsLastMoveTimestampDirty( false );
}
}
示例10:
bool ScoreBoardManager::Entry::Write( OutputMemoryBitStream& inOutputStream ) const
{
bool didSucceed = true;
inOutputStream.Write( mColor );
inOutputStream.Write( mPlayerId );
inOutputStream.Write( mPlayerName );
inOutputStream.Write( mScore );
return didSucceed;
}
示例11: SendReadyPacketsToPeers
void NetworkManager::SendReadyPacketsToPeers()
{
OutputMemoryBitStream outPacket;
outPacket.Write( kReadyCC );
for( auto& iter : mPlayerNameMap )
{
if( iter.first != mPlayerId )
{
SendPacket( outPacket, iter.first );
}
}
}
示例12: Write
void AckRange::Write( OutputMemoryBitStream& inOutputStream ) const
{
inOutputStream.Write( mStart );
bool hasCount = mCount > 1;
inOutputStream.Write( hasCount );
if( hasCount )
{
//most you can ack is 255...
uint32_t countMinusOne = mCount - 1;
uint8_t countToAck = countMinusOne > 255 ? 255 : static_cast< uint8_t >( countMinusOne );
inOutputStream.Write( countToAck );
}
}
示例13: 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;
}
}
示例14: AddWorldStateToPacket
//should we ask the server for this? or run through the world ourselves?
void NetworkManagerServer::AddWorldStateToPacket( OutputMemoryBitStream& inOutputStream )
{
const auto& gameObjects = World::sInstance->GetGameObjects();
//now start writing objects- do we need to remember how many there are? we can check first...
inOutputStream.Write( gameObjects.size() );
for( GameObjectPtr gameObject : gameObjects )
{
inOutputStream.Write( gameObject->GetNetworkId() );
inOutputStream.Write( gameObject->GetClassId() );
gameObject->Write( inOutputStream, 0xffffffff );
}
}
示例15: 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;
}