当前位置: 首页>>代码示例>>C++>>正文


C++ NetBitStreamInterface::WriteBits方法代码示例

本文整理汇总了C++中NetBitStreamInterface::WriteBits方法的典型用法代码示例。如果您正苦于以下问题:C++ NetBitStreamInterface::WriteBits方法的具体用法?C++ NetBitStreamInterface::WriteBits怎么用?C++ NetBitStreamInterface::WriteBits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NetBitStreamInterface的用法示例。


在下文中一共展示了NetBitStreamInterface::WriteBits方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Write

bool CVehicleInOutPacket::Write ( NetBitStreamInterface& BitStream ) const
{
    if ( m_pSourceElement && m_ID != INVALID_ELEMENT_ID )
    {
        ElementID ID = m_pSourceElement->GetID ();
        BitStream.Write ( ID );

        BitStream.Write ( m_ID );
        BitStream.WriteBits ( &m_ucSeat, 3 );
        BitStream.WriteBits ( &m_ucAction, 4 );

        if ( m_ucAction == CGame::VEHICLE_REQUEST_IN_CONFIRMED || m_ucAction == CGame::VEHICLE_REQUEST_JACK_CONFIRMED )
        {
            BitStream.WriteBits ( &m_ucDoor, 3 );
        }
        // If the action id is VEHICLE_NOTIFY_JACK_RETURN, send the in/out player chars aswell
        if ( m_ucAction == CGame::VEHICLE_NOTIFY_JACK_RETURN )
        {
            BitStream.Write ( m_PlayerIn );
            BitStream.Write ( m_PlayerOut );
        }

        if ( m_ucAction == 9 /*VEHICLE_ATTEMPT_FAILED*/ )
        {
            BitStream.Write ( m_ucFailReason );
            if ( m_ucFailReason == 5 /*FAIL_DISTANCE*/ && m_pCorrectVector )
            {
                SPositionSync pos ( false );
                pos.data.vecPosition = *m_pCorrectVector;
                BitStream.Write ( &pos );
            }
        }

        if ( m_ucAction == CGame::VEHICLE_NOTIFY_IN_ABORT_RETURN )
        {
            BitStream.WriteBits ( &m_ucDoor, 3 );
            SDoorOpenRatioSync door;
            door.data.fRatio = m_fDoorAngle;
            BitStream.Write ( &door );
        }

        if ( m_ucAction == CGame::VEHICLE_REQUEST_OUT_CONFIRMED )
        {
            if ( m_ucDoor < 4 )
                BitStream.WriteBits ( &m_ucDoor, 2 );
        }

        return true;
    }

    return false;
}
开发者ID:EagleShen,项目名称:MTA,代码行数:52,代码来源:CVehicleInOutPacket.cpp

示例2: Write

//
// Should do the same this as what CPedTaskPacket::Write() does
//
bool CSimPedTaskPacket::Write ( NetBitStreamInterface& BitStream ) const
{
    // Write the source player id
    BitStream.Write ( m_PlayerID );

    // Write packet data
    BitStream.WriteBits( m_Cache.DataBuffer, m_Cache.uiNumBitsInPacketBody );
    return true;
}
开发者ID:AdiBoy,项目名称:mtasa-blue,代码行数:12,代码来源:CSimPedTaskPacket.cpp

示例3: SendCancelNotification

///////////////////////////////////////////////////////////////
//
// CLatentSendQueue::SendCancelNotification
//
// Tell remote an in-progress transfer is cancelled
//
///////////////////////////////////////////////////////////////
void CLatentSendQueue::SendCancelNotification ( SSendItem& activeTx )
{
    assert ( activeTx.bSendStarted && !activeTx.bSendFinishing );
    NetBitStreamInterface* pBitStream = DoAllocateNetBitStream ( m_RemoteId, m_usBitStreamVersion );
    pBitStream->WriteBits ( &activeTx.uiId, 15 );
    pBitStream->WriteBit ( 1 );
    pBitStream->Write ( (uchar)FLAG_CANCEL );
    DoSendPacket ( PACKET_ID_LATENT_TRANSFER, m_RemoteId, pBitStream, PACKET_PRIORITY_LOW, PACKET_RELIABILITY_RELIABLE_ORDERED, PACKET_ORDERING_DATA_TRANSFER );
    DoDeallocateNetBitStream ( pBitStream );
}
开发者ID:0x688,项目名称:gtasa_crashfix,代码行数:17,代码来源:CLatentSendQueue.cpp

示例4: OnReceive


//.........这里部分代码省略.........
        {
            bIsHead = true;
            pBitStream->Read ( usCategory );
            pBitStream->Read ( uiFinalSize );
            pBitStream->Read ( uiRate );
            if ( pBitStream->Version () >= 0x31 )
                pBitStream->Read ( usResourceNetId );
        }
        else
        if ( ucSpecialFlag == FLAG_TAIL )
        {
            bIsTail = true;
        }
        else
        if ( ucSpecialFlag == FLAG_CANCEL )
        {
            bIsCancel = true;
        }
        else
        {
            return OnReceiveError ( "Invalid special type" );
        }
    }

    pBitStream->AlignReadToByteBoundary ();
    ushort usSizeSent = 0;
    pBitStream->Read ( usSizeSent );

    //
    // Process header
    //
    if ( bIsHead )
    {
        // If head, check no previous transfer
        if ( activeRx.bReceiveStarted )
            return OnReceiveError ( "bIsHead && activeRx.bReceiveActive" );
        if ( uiFinalSize > 100 * 1024 * 1024 )
            return OnReceiveError ( "uiFinalSize too large" );

        activeRx.usId = usId;
        activeRx.bReceiveStarted = true;
        activeRx.usCategory = usCategory;
        activeRx.uiRate = uiRate;
        activeRx.usResourceNetId = usResourceNetId;
        activeRx.buffer.SetSize ( uiFinalSize );
        activeRx.uiWritePosition = 0;
    }

    if ( activeRx.usId != usId )
        return OnReceiveError ( "usId wrong" );

    if ( bIsCancel )
    {
        // Reset for next receive
        activeRx = SReceiveItem ();
        return;
    }


    //
    // Read body
    //
    if ( activeRx.uiWritePosition + usSizeSent > activeRx.buffer.GetSize () )
        return OnReceiveError ( "Buffer would overflow" );

    if ( bIsTail && activeRx.uiWritePosition + usSizeSent != activeRx.buffer.GetSize () )
        return OnReceiveError ( "Buffer size wrong" );

    pBitStream->Read ( activeRx.buffer.GetData () + activeRx.uiWritePosition, usSizeSent );
    activeRx.uiWritePosition += usSizeSent;


    //
    // Process tail
    //
    if ( bIsTail )
    {
        if ( activeRx.usCategory == CATEGORY_PACKET )
        {
            // Recreate the packet data
            NetBitStreamInterface* pBitStream = DoAllocateNetBitStream ( m_RemoteId, m_usBitStreamVersion );
            uchar ucPacketId = 0;
            uint uiBitStreamBitsUsed = 0;

            CBufferReadStream stream ( activeRx.buffer );
            stream.Read ( ucPacketId );
            stream.Read ( uiBitStreamBitsUsed );
            uint uiBitStreamBytesUsed = ( uiBitStreamBitsUsed + 7 ) >> 3;

            if ( uiBitStreamBytesUsed != activeRx.buffer.GetSize () - 5 )
                return OnReceiveError ( "Buffer size mismatch" );

            pBitStream->WriteBits ( activeRx.buffer.GetData () + 5, uiBitStreamBitsUsed );
            pBitStream->ResetReadPointer ();

            DoStaticProcessPacket ( ucPacketId, m_RemoteId, pBitStream, activeRx.usResourceNetId );
            DoDeallocateNetBitStream ( pBitStream );
        }
        else
        {
开发者ID:AdiBoy,项目名称:mtasa-blue,代码行数:101,代码来源:CLatentReceiver.cpp

示例5: Write


//.........这里部分代码省略.........
                    }

                    break;
                }

                case CElement::VEHICLE:
                {
                    CVehicle* pVehicle = static_cast < CVehicle* > ( pElement );

                    // Write the vehicle position and rotation
                    position.data.vecPosition = pVehicle->GetPosition ();
                    SRotationDegreesSync rotationDegrees ( false );
                    pVehicle->GetRotationDegrees ( rotationDegrees.data.vecRotation );

                    // Write it
                    BitStream.Write ( &position );
                    BitStream.Write ( &rotationDegrees );

                    // Vehicle id as a char
                    // I'm assuming the "-400" is for adjustment so that all car values can
                    // fit into a char?  Why doesn't someone document this?
                    //
                    // --slush
                    BitStream.Write ( static_cast < unsigned char > ( pVehicle->GetModel () - 400 ) );

                    // Health
                    SVehicleHealthSync health;
                    health.data.fValue = pVehicle->GetHealth ();
                    BitStream.Write ( &health );

                    // Color
                    CVehicleColor& vehColor = pVehicle->GetColor ();
                    uchar ucNumColors = vehColor.GetNumColorsUsed () - 1;
                    BitStream.WriteBits ( &ucNumColors, 2 );
                    for ( uint i = 0 ; i <= ucNumColors ; i++ )
                    {
                        SColor RGBColor = vehColor.GetRGBColor ( i );
                        BitStream.Write ( RGBColor.R );
                        BitStream.Write ( RGBColor.G );
                        BitStream.Write ( RGBColor.B );
                    }

                    // Paintjob
                    SPaintjobSync paintjob;
                    paintjob.data.ucPaintjob = pVehicle->GetPaintjob ();
                    BitStream.Write ( &paintjob );

                    // Write the damage model
                    SVehicleDamageSync damage ( true, true, true, true, false );
                    memcpy ( damage.data.ucDoorStates,  pVehicle->m_ucDoorStates,  MAX_DOORS );
                    memcpy ( damage.data.ucWheelStates, pVehicle->m_ucWheelStates, MAX_WHEELS );
                    memcpy ( damage.data.ucPanelStates, pVehicle->m_ucPanelStates, MAX_PANELS );
                    memcpy ( damage.data.ucLightStates, pVehicle->m_ucLightStates, MAX_LIGHTS );
                    BitStream.Write ( &damage );

                    // If the vehicle has a turret, send its position too
                    unsigned short usModel = pVehicle->GetModel ();
                    if ( CVehicleManager::HasTurret ( usModel ) )
                    {
                        SVehicleTurretSync specific;
                        specific.data.fTurretX = pVehicle->GetTurretPositionX ();
                        specific.data.fTurretY = pVehicle->GetTurretPositionY ();
                        BitStream.Write ( &specific );
                    }

                    // If the vehicle has an adjustable property send its value
开发者ID:qaisjp,项目名称:green-candy,代码行数:67,代码来源:CEntityAddPacket.cpp

示例6: DoPulse

///////////////////////////////////////////////////////////////
//
// CLatentSendQueue::DoPulse
//
// Send next part of the active transfer
//
///////////////////////////////////////////////////////////////
void CLatentSendQueue::DoPulse ( int iTimeMsBetweenCalls )
{
    if ( m_TxQueue.empty () )
    {
        m_iBytesOwing = 0;
        return;
    }

    // Check if previous tx has completed
    if ( m_TxQueue.front ().uiReadPosition == m_TxQueue.front ().bufferRef->GetSize () && m_TxQueue.front ().bSendFinishing )
    {
        m_TxQueue.pop_front ();
        PostQueueRemove ();
        if ( m_TxQueue.empty () )
        {
            m_iBytesOwing = 0;
            return;
        }
    }

    m_uiCurrentRate = Max < uint > ( MIN_SEND_RATE, m_uiCurrentRate );

    // How many bytes to send this pulse
    int iBytesToSendThisPulse = iTimeMsBetweenCalls * m_uiCurrentRate / 1000;

    // Add bytes owing from last pulse
    iBytesToSendThisPulse += m_iBytesOwing;

    // Calc packet size depending on rate
    uint uiMaxPacketSize = Lerp ( MIN_PACKET_SIZE, UnlerpClamped ( MIN_PACKET_SIZE * 10, m_uiCurrentRate, MAX_PACKET_SIZE * 15 ), MAX_PACKET_SIZE );

    // Calc how many packets to do this pulse
    uint uiNumPackets = iBytesToSendThisPulse / uiMaxPacketSize;

    // Update carry over
    m_iBytesOwing = iBytesToSendThisPulse % uiMaxPacketSize;

    // Process item at front of queue
    SSendItem& activeTx = m_TxQueue.front ();
    for ( uint i = 0 ; i < uiNumPackets && !activeTx.bSendFinishing ; i++ )
    {
        // Send next part of data    
        NetBitStreamInterface* pBitStream = DoAllocateNetBitStream ( m_RemoteId, m_usBitStreamVersion );
        pBitStream->WriteBits ( &activeTx.uiId, 15 );

        // Next bit indicates if it has a special flag
        if ( activeTx.uiReadPosition == 0 )
        {
            // Head
            pBitStream->WriteBit ( 1 );
            pBitStream->Write ( (uchar)FLAG_HEAD );
            pBitStream->Write ( activeTx.usCategory );
            pBitStream->Write ( activeTx.bufferRef->GetSize () );
            pBitStream->Write ( activeTx.uiRate );
            if ( pBitStream->Version () >= 0x31 )
                pBitStream->Write ( activeTx.usResourceNetId );
            activeTx.bSendStarted = true;
        }
        else
        if ( activeTx.bufferRef->GetSize () == activeTx.uiReadPosition )
        {
            // Tail
            pBitStream->WriteBit ( 1 );
            pBitStream->Write ( (uchar)FLAG_TAIL );
            activeTx.bSendFinishing = true;
        }
        else
        {
            // Body
            pBitStream->WriteBit ( 0 );
        }

        // Align to next boundary
        pBitStream->AlignWriteToByteBoundary ();
        uint uiMaxDataSize = Max < int > ( 10, uiMaxPacketSize - pBitStream->GetNumberOfBytesUsed () );

        // Calc how much data to send
        uint uiDataOffset = activeTx.uiReadPosition;
        uint uiSizeToSend = Min ( uiMaxDataSize, activeTx.bufferRef->GetSize () - activeTx.uiReadPosition );
        activeTx.uiReadPosition += uiSizeToSend;

        pBitStream->Write ( (ushort)uiSizeToSend );
        pBitStream->Write ( activeTx.bufferRef->GetData () + uiDataOffset, uiSizeToSend );

        // Send
        DoSendPacket ( PACKET_ID_LATENT_TRANSFER, m_RemoteId, pBitStream, PACKET_PRIORITY_LOW, PACKET_RELIABILITY_RELIABLE_ORDERED, PACKET_ORDERING_DATA_TRANSFER );
        DoDeallocateNetBitStream ( pBitStream );
    }
}
开发者ID:0x688,项目名称:gtasa_crashfix,代码行数:96,代码来源:CLatentSendQueue.cpp


注:本文中的NetBitStreamInterface::WriteBits方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。