本文整理汇总了C++中NetBitStreamInterface::AlignWriteToByteBoundary方法的典型用法代码示例。如果您正苦于以下问题:C++ NetBitStreamInterface::AlignWriteToByteBoundary方法的具体用法?C++ NetBitStreamInterface::AlignWriteToByteBoundary怎么用?C++ NetBitStreamInterface::AlignWriteToByteBoundary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetBitStreamInterface
的用法示例。
在下文中一共展示了NetBitStreamInterface::AlignWriteToByteBoundary方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WriteToBitStream
//.........这里部分代码省略.........
else if (dataType == DATA_TYPE_FLOAT)
{
bitStream.WriteBit(true);
bitStream.WriteBit(false);
bitStream.Write(fNumber);
}
else
{
bitStream.WriteBit(true);
bitStream.WriteBit(true);
bitStream.Write(dNumber);
}
break;
}
// String argument
case LUA_TSTRING:
{
// Grab the string and its length. Is it short enough to be sendable?
const char* szTemp = m_strString.c_str();
size_t sizeTemp = m_strString.length();
unsigned short usLength = static_cast<unsigned short>(sizeTemp);
if (sizeTemp == usLength)
{
// This is a string argument
type.data.ucType = LUA_TSTRING;
bitStream.Write(&type);
// Write its length
bitStream.WriteCompressed(usLength);
// Write the content too if it's not empty
if (usLength > 0)
{
bitStream.Write(szTemp, usLength);
}
}
else
{
// This is a long string argument
type.data.ucType = LUA_TSTRING_LONG;
bitStream.Write(&type);
// Write its length
uint uiLength = sizeTemp;
bitStream.WriteCompressed(uiLength);
// Write the content too if it's not empty
if (uiLength > 0)
{
bitStream.AlignWriteToByteBoundary();
bitStream.Write(szTemp, uiLength);
}
}
break;
}
// Element argument
case LUA_TLIGHTUSERDATA:
case LUA_TUSERDATA:
{
// Grab the element from this userdata pointer. Valid and has a synced element ID?
CElement* pElement = GetElement();
if (pElement && pElement->GetID() != INVALID_ELEMENT_ID)
{
// Write its ID
type.data.ucType = LUA_TUSERDATA;
bitStream.Write(&type);
bitStream.Write(pElement->GetID());
}
else
{
// Jax: this just spams the script debugger, it's not really neccesary
// LogUnableToPacketize ( "Couldn't packetize argument list, invalid element specified." );
// Write a nil though so other side won't get out of sync
type.data.ucType = LUA_TNIL;
bitStream.Write(&type);
return false;
}
break;
}
// Unpacketizable type.
default:
{
// Unpacketizable
LogUnableToPacketize("Couldn't packetize argument list, unknown type specified.");
// Write a nil though so other side won't get out of sync
type.data.ucType = LUA_TNIL;
bitStream.Write(&type);
return false;
}
}
// Success
return true;
}
示例2: 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 );
}
}
示例3: WriteToBitStream
//.........这里部分代码省略.........
{
bitStream.WriteBit ( true );
bitStream.WriteBit ( true );
bitStream.Write ( dNumber );
}
}
break;
}
// String argument
case LUA_TSTRING:
{
// Grab the string and its length. Is it short enough to be sendable?
const char* szTemp = m_strString.c_str ();
size_t sizeTemp = m_strString.length ();
unsigned short usLength = static_cast < unsigned short > ( sizeTemp );
if ( sizeTemp == usLength )
{
// This is a string argument
type.data.ucType = LUA_TSTRING;
bitStream.Write ( &type );
// Write its length
bitStream.WriteCompressed ( usLength );
// Write the content too if it's not empty
if ( usLength > 0 )
{
bitStream.Write ( szTemp, usLength );
}
}
else
{
// This is a long string argument
type.data.ucType = LUA_TSTRING_LONG;
bitStream.Write ( &type );
// Write its length
uint uiLength = sizeTemp;
bitStream.WriteCompressed ( uiLength );
// Write the content too if it's not empty
if ( uiLength > 0 )
{
bitStream.AlignWriteToByteBoundary ();
bitStream.Write ( szTemp, uiLength );
}
}
break;
}
// Element packet
case LUA_TLIGHTUSERDATA:
case LUA_TUSERDATA:
{
// Got a valid element to send?
CClientEntity* pElement = GetElement ();
if ( pElement )
{
// Clientside element?
if ( !pElement->IsLocalEntity () )
{
type.data.ucType = LUA_TLIGHTUSERDATA;
bitStream.Write ( &type );
bitStream.Write ( pElement->GetID () );
}
else
{
// Write a nil though so other side won't get out of sync
type.data.ucType = LUA_TNIL;
bitStream.Write ( &type );
return false;
}
}
else
{
// Write a nil though so other side won't get out of sync
type.data.ucType = LUA_TNIL;
bitStream.Write ( &type );
return false;
}
break;
}
// Unpacketizable type.
default:
{
// Unpacketizable
LogUnableToPacketize ( "Couldn't packetize argument list, unknown type specified." );
// Write a nil though so other side won't get out of sync
type.data.ucType = LUA_TNIL;
bitStream.Write ( &type );
return false;
}
}
// Success
return true;
}
示例4: WriteToBitStream
//.........这里部分代码省略.........
}
break;
}
// String argument
case LUA_TSTRING:
{
// Grab the string and its length. Is it short enough to be sendable?
const char* szTemp = m_strString.c_str ();
size_t sizeTemp = m_strString.length ();
unsigned short usLength = static_cast < unsigned short > ( sizeTemp );
if ( sizeTemp == usLength )
{
// This is a string argument
type.data.ucType = LUA_TSTRING;
bitStream.Write ( &type );
// Write its length
bitStream.WriteCompressed ( usLength );
// Write the content too if it's not empty
if ( usLength > 0 )
{
bitStream.Write ( szTemp, usLength );
}
}
else
if ( sizeTemp > 65535 && bitStream.Version () >= 0x027 && g_pGame->CalculateMinClientRequirement () >= LONG_STRING_MIN_VERSION )
{
// This is a long string argument
type.data.ucType = LUA_TSTRING_LONG;
bitStream.Write ( &type );
// Write its length
uint uiLength = sizeTemp;
bitStream.WriteCompressed ( uiLength );
// Write the content too if it's not empty
if ( uiLength > 0 )
{
bitStream.AlignWriteToByteBoundary ();
bitStream.Write ( szTemp, uiLength );
}
}
else
{
// Too long string
LogUnableToPacketize ( "Couldn't packetize argument list. Invalid string specified, limit is 65535 characters."
" To use longer strings, set script <min_mta_version> to " LONG_STRING_MIN_VERSION " or higher." );
// Write a nil though so other side won't get out of sync
type.data.ucType = LUA_TNIL;
bitStream.Write ( &type );
return false;
}
break;
}
// Element argument
case LUA_TLIGHTUSERDATA:
{
// Grab the element from this userdata pointer. Valid and has a synced element ID?
CElement* pElement = GetElement ();
if ( pElement && pElement->GetID () != INVALID_ELEMENT_ID )
{
// Write its ID
type.data.ucType = LUA_TLIGHTUSERDATA;
bitStream.Write ( &type );
bitStream.Write ( pElement->GetID () );
}
else
{
// Jax: this just spams the script debugger, it's not really neccesary
// LogUnableToPacketize ( "Couldn't packetize argument list, invalid element specified." );
// Write a nil though so other side won't get out of sync
type.data.ucType = LUA_TNIL;
bitStream.Write ( &type );
return false;
}
break;
}
// Unpacketizable type.
default:
{
// Unpacketizable
LogUnableToPacketize ( "Couldn't packetize argument list, unknown type specified." );
// Write a nil though so other side won't get out of sync
type.data.ucType = LUA_TNIL;
bitStream.Write ( &type );
return false;
}
}
// Success
return true;
}