本文整理汇总了C++中NetBitStreamInterface::WriteCompressed方法的典型用法代码示例。如果您正苦于以下问题:C++ NetBitStreamInterface::WriteCompressed方法的具体用法?C++ NetBitStreamInterface::WriteCompressed怎么用?C++ NetBitStreamInterface::WriteCompressed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetBitStreamInterface
的用法示例。
在下文中一共展示了NetBitStreamInterface::WriteCompressed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Write
bool CLuaEventPacket::Write(NetBitStreamInterface& BitStream) const
{
unsigned short usNameLength = static_cast<unsigned short>(m_strName.length());
BitStream.WriteCompressed(usNameLength);
BitStream.WriteStringCharacters(m_strName, usNameLength);
BitStream.Write(m_ElementID);
m_pArguments->WriteToBitStream(BitStream);
return true;
}
示例2: WriteToBitStream
bool CLuaArguments::WriteToBitStream(NetBitStreamInterface& bitStream, CFastHashMap<CLuaArguments*, unsigned long>* pKnownTables) const
{
bool bKnownTablesCreated = false;
if (!pKnownTables)
{
pKnownTables = new CFastHashMap<CLuaArguments*, unsigned long>();
bKnownTablesCreated = true;
}
bool bSuccess = true;
pKnownTables->insert(make_pair((CLuaArguments*)this, pKnownTables->size()));
#if MTA_DM_VERSION >= 0x150
bitStream.WriteCompressed(static_cast<unsigned int>(m_Arguments.size()));
#else
if (ExtractVersionStringBuildNumber(g_pGame->GetPlayerManager()->GetLowestConnectedPlayerVersion()) < ExtractVersionStringBuildNumber("1.4.0-9.06858") &&
MTASA_VERSION_TYPE != VERSION_TYPE_CUSTOM)
bitStream.WriteCompressed(static_cast<unsigned short>(m_Arguments.size()));
else
{
// Send 0xFFFF to indicate that we're using the new version | TODO: Remove this in 1.5
bitStream.WriteCompressed(static_cast<unsigned short>(0xFFFF));
bitStream.WriteCompressed(static_cast<unsigned int>(m_Arguments.size()));
}
#endif
vector<CLuaArgument*>::const_iterator iter = m_Arguments.begin();
for (; iter != m_Arguments.end(); ++iter)
{
CLuaArgument* pArgument = *iter;
if (!pArgument->WriteToBitStream(bitStream, pKnownTables))
{
bSuccess = false;
}
}
if (bKnownTablesCreated)
delete pKnownTables;
return bSuccess;
}
示例3: Write
bool CPlayerJoinCompletePacket::Write ( NetBitStreamInterface& BitStream ) const
{
BitStream.Write ( m_PlayerID );
BitStream.Write ( m_ucNumberOfPlayers );
BitStream.Write ( m_RootElementID );
// Transmit server requirement for the client to check settings
BitStream.Write ( m_iEnableClientChecks );
// Transmit whether or not the Voice is enabled
BitStream.WriteBit ( m_bVoiceEnabled );
// Transmit the sample rate for voice
SIntegerSync < unsigned char, 2 > sampleRate ( m_ucSampleRate );
BitStream.Write ( &sampleRate );
// Transmit the quality for voice
SIntegerSync < unsigned char, 4 > voiceQuality ( m_ucQuality );
BitStream.Write ( &voiceQuality );
// Transmit the max bitrate for voice
BitStream.WriteCompressed ( m_uiBitrate );
// Tellclient about maybe throttling back http client requests
BitStream.Write ( m_iHTTPMaxConnectionsPerClient );
BitStream.Write ( static_cast < unsigned char > ( m_ucHTTPDownloadType ) );
switch ( m_ucHTTPDownloadType )
{
case HTTP_DOWNLOAD_ENABLED_PORT:
{
BitStream.Write ( m_usHTTPDownloadPort );
}
break;
case HTTP_DOWNLOAD_ENABLED_URL:
{
// Internal http server port
if ( BitStream.Version() >= 0x48 )
BitStream.Write( m_usHTTPDownloadPort );
// External http server URL
BitStream.WriteString ( m_strHTTPDownloadURL );
}
break;
default:
break;
}
return true;
}
示例4: Write
bool CServerTextItemPacket::Write ( NetBitStreamInterface &BitStream ) const
{
BitStream.WriteCompressed ( m_ulUniqueId );
// Write the flag byte
BitStream.WriteBit ( m_bDeletable );
// Not deleting this?
if ( !m_bDeletable )
{
BitStream.Write ( m_fX );
BitStream.Write ( m_fY );
BitStream.Write ( m_fScale );
BitStream.Write ( m_red );
BitStream.Write ( m_green );
BitStream.Write ( m_blue );
BitStream.Write ( m_alpha );
BitStream.Write ( m_ucFormat );
// Grab the text length
size_t sizeText = strlen ( m_szText );
if ( sizeText > 1024 )
{
sizeText = 1024;
}
// Write the text
BitStream.WriteCompressed ( static_cast < unsigned short > ( sizeText ) );
if ( sizeText )
{
BitStream.Write ( m_szText, sizeText );
}
}
return true;
}
示例5: Write
bool CPlayerStatsPacket::Write ( NetBitStreamInterface& BitStream ) const
{
// Write the source player.
if ( m_pSourceElement )
{
ElementID ID = m_pSourceElement->GetID ();
BitStream.WriteCompressed ( ID );
// Write the stats
unsigned short usNumStats = static_cast < unsigned short >( m_List.size () );
BitStream.WriteCompressed ( usNumStats );
vector < sPlayerStat* > ::const_iterator iter = m_List.begin ();
for ( ; iter != m_List.end () ; iter++ )
{
BitStream.Write ( (*iter)->id );
BitStream.Write ( (*iter)->value );
}
return true;
}
return false;
}
示例6: WriteToBitStream
bool CLuaArguments::WriteToBitStream(NetBitStreamInterface& bitStream, CFastHashMap<CLuaArguments*, unsigned long>* pKnownTables) const
{
bool bKnownTablesCreated = false;
if (!pKnownTables)
{
pKnownTables = new CFastHashMap<CLuaArguments*, unsigned long>();
bKnownTablesCreated = true;
}
bool bSuccess = true;
pKnownTables->insert(make_pair((CLuaArguments*)this, pKnownTables->size()));
#if MTA_DM_VERSION >= 0x150
bitStream.WriteCompressed(static_cast<unsigned int>(m_Arguments.size()));
#else
if (bitStream.Version() < 0x05B)
bitStream.WriteCompressed(static_cast<unsigned short>(m_Arguments.size()));
else
bitStream.WriteCompressed(static_cast<unsigned int>(m_Arguments.size()));
#endif
vector<CLuaArgument*>::const_iterator iter = m_Arguments.begin();
for (; iter != m_Arguments.end(); iter++)
{
CLuaArgument* pArgument = *iter;
if (!pArgument->WriteToBitStream(bitStream, pKnownTables))
{
bSuccess = false;
}
}
if (bKnownTablesCreated)
delete pKnownTables;
return bSuccess;
}
示例7: Write
bool CExplosionSyncPacket::Write(NetBitStreamInterface& BitStream) const
{
// Write the source player and latency if any. Otherwize 0
if (m_pSourceElement)
{
BitStream.WriteBit(true);
ElementID ID = m_pSourceElement->GetID();
BitStream.Write(ID);
unsigned short usLatency = static_cast<CPlayer*>(m_pSourceElement)->GetPing();
BitStream.WriteCompressed(usLatency);
}
else
{
BitStream.WriteBit(false);
}
if (m_OriginID != INVALID_ELEMENT_ID)
{
BitStream.WriteBit(true);
BitStream.Write(m_OriginID);
}
else
BitStream.WriteBit(false);
// Write position and type
SPositionSync position(false);
position.data.vecPosition = m_vecPosition;
BitStream.Write(&position);
SExplosionTypeSync explosionType;
explosionType.data.uiType = m_ucType;
BitStream.Write(&explosionType);
return true;
}
示例8: Write
bool CVehiclePuresyncPacket::Write ( NetBitStreamInterface& BitStream ) const
{
// Got a player to send?
if ( m_pSourceElement )
{
CPlayer * pSourcePlayer = static_cast < CPlayer * > ( m_pSourceElement );
// Player is in a vehicle and is the driver?
CVehicle* pVehicle = pSourcePlayer->GetOccupiedVehicle ();
if ( pVehicle )
{
// Player ID
ElementID PlayerID = pSourcePlayer->GetID ();
BitStream.Write ( PlayerID );
// Write the time context of that player
BitStream.Write ( pSourcePlayer->GetSyncTimeContext () );
// Write his ping divided with 2 plus a small number so the client can find out when this packet was sent
unsigned short usLatency = pSourcePlayer->GetPing ();
BitStream.WriteCompressed ( usLatency );
// Write the keysync data
CControllerState ControllerState = pSourcePlayer->GetPad ()->GetCurrentControllerState ();
WriteFullKeysync ( ControllerState, BitStream );
// Write the vehicle matrix only if he's the driver
CVector vecTemp;
unsigned int uiSeat = pSourcePlayer->GetOccupiedVehicleSeat ();
if ( uiSeat == 0 )
{
// Vehicle position
SPositionSync position ( false );
position.data.vecPosition = pVehicle->GetPosition ();
BitStream.Write ( &position );
// Vehicle rotation
SRotationDegreesSync rotation;
pVehicle->GetRotationDegrees ( rotation.data.vecRotation );
BitStream.Write ( &rotation );
// Move speed vector
SVelocitySync velocity;
velocity.data.vecVelocity = pVehicle->GetVelocity ();
BitStream.Write ( &velocity );
// Turn speed vector
SVelocitySync turnSpeed;
turnSpeed.data.vecVelocity = pVehicle->GetTurnSpeed ();
BitStream.Write ( &turnSpeed );
// Health
SVehicleHealthSync health;
health.data.fValue = pVehicle->GetHealth ();
BitStream.Write ( &health );
}
// Player health and armor
SPlayerHealthSync health;
health.data.fValue = pSourcePlayer->GetHealth ();
BitStream.Write ( &health );
SPlayerArmorSync armor;
armor.data.fValue = pSourcePlayer->GetArmor ();
BitStream.Write ( &armor );
// Weapon
unsigned char ucWeaponType = pSourcePlayer->GetWeaponType ();
// Flags
SVehiclePuresyncFlags flags;
flags.data.bIsWearingGoggles = pSourcePlayer->IsWearingGoggles ();
flags.data.bIsDoingGangDriveby = pSourcePlayer->IsDoingGangDriveby ();
flags.data.bIsSirenOrAlarmActive = pVehicle->IsSirenActive ();
flags.data.bIsSmokeTrailEnabled = pVehicle->IsSmokeTrailEnabled ();
flags.data.bIsLandingGearDown = pVehicle->IsLandingGearDown ();
flags.data.bIsOnGround = pVehicle->IsOnGround ();
flags.data.bIsInWater = pVehicle->IsInWater ();
flags.data.bIsDerailed = pVehicle->IsDerailed ();
flags.data.bIsAircraft = ( pVehicle->GetVehicleType () == VEHICLE_PLANE ||
pVehicle->GetVehicleType () == VEHICLE_HELI );
flags.data.bHasAWeapon = ( ucWeaponType != 0 );
flags.data.bIsHeliSearchLightVisible = pVehicle->IsHeliSearchLightVisible ();
BitStream.Write ( &flags );
// Write the weapon stuff
if ( flags.data.bHasAWeapon )
{
// Write the weapon slot
SWeaponSlotSync slot;
slot.data.uiSlot = pSourcePlayer->GetWeaponSlot ();
BitStream.Write ( &slot );
if ( flags.data.bIsDoingGangDriveby && CWeaponNames::DoesSlotHaveAmmo ( slot.data.uiSlot ) )
{
// Write the ammo states
SWeaponAmmoSync ammo ( ucWeaponType, false, true );
ammo.data.usAmmoInClip = pSourcePlayer->GetWeaponAmmoInClip ();
BitStream.Write ( &ammo );
//.........这里部分代码省略.........
示例9: Write
bool CMapInfoPacket::Write ( NetBitStreamInterface& BitStream ) const
{
// Write the map weather
BitStream.Write ( m_ucWeather );
BitStream.Write ( m_ucWeatherBlendingTo );
BitStream.Write ( m_ucBlendedWeatherHour );
BitStream.WriteBit ( m_bHasSkyGradient );
if ( m_bHasSkyGradient )
{
BitStream.Write ( m_ucSkyGradientTR );
BitStream.Write ( m_ucSkyGradientTG );
BitStream.Write ( m_ucSkyGradientTB );
BitStream.Write ( m_ucSkyGradientBR );
BitStream.Write ( m_ucSkyGradientBG );
BitStream.Write ( m_ucSkyGradientBB );
}
// Write heat haze
BitStream.WriteBit ( m_bHasHeatHaze );
if ( m_bHasHeatHaze )
{
SHeatHazeSync heatHaze ( m_HeatHazeSettings );
BitStream.Write ( &heatHaze );
}
// Write the map hour
BitStream.Write ( m_ucClockHour );
BitStream.Write ( m_ucClockMin );
BitStream.WriteCompressed ( m_ulMinuteDuration );
// Write the map flags
SMapInfoFlagsSync flags;
flags.data.bShowNametags = m_bShowNametags;
flags.data.bShowRadar = m_bShowRadar;
flags.data.bCloudsEnabled = m_bCloudsEnabled;
BitStream.Write ( &flags );
// Write any other world conditions
BitStream.Write ( m_fGravity );
if ( m_fGameSpeed == 1.0f )
BitStream.WriteBit ( true );
else
{
BitStream.WriteBit ( false );
BitStream.Write ( m_fGameSpeed );
}
BitStream.Write ( m_fWaveHeight );
// Write world water level
BitStream.Write ( m_WorldWaterLevelInfo.fSeaLevel );
BitStream.WriteBit ( m_WorldWaterLevelInfo.bNonSeaLevelSet );
if ( m_WorldWaterLevelInfo.bNonSeaLevelSet )
BitStream.Write ( m_WorldWaterLevelInfo.fNonSeaLevel );
BitStream.WriteCompressed ( m_usFPSLimit );
// Write the garage states
for ( unsigned char i = 0 ; i < MAX_GARAGES ; i++ )
{
BitStream.WriteBit( static_cast < unsigned char > ( m_pbGarageStates[i] ) );
}
// Write the fun bugs state
SFunBugsStateSync funBugs;
funBugs.data.bQuickReload = g_pGame->IsGlitchEnabled ( CGame::GLITCH_QUICKRELOAD );
funBugs.data.bFastFire = g_pGame->IsGlitchEnabled ( CGame::GLITCH_FASTFIRE );
funBugs.data.bFastMove = g_pGame->IsGlitchEnabled ( CGame::GLITCH_FASTMOVE );
funBugs.data.bCrouchBug = g_pGame->IsGlitchEnabled ( CGame::GLITCH_CROUCHBUG );
funBugs.data.bCloseRangeDamage = g_pGame->IsGlitchEnabled ( CGame::GLITCH_CLOSEDAMAGE );
BitStream.Write ( &funBugs );
BitStream.Write ( m_fJetpackMaxHeight );
BitStream.WriteBit ( m_bOverrideWaterColor );
if ( m_bOverrideWaterColor )
{
BitStream.Write ( m_ucWaterRed );
BitStream.Write ( m_ucWaterGreen );
BitStream.Write ( m_ucWaterBlue );
BitStream.Write ( m_ucWaterAlpha );
}
// Interior sounds
BitStream.WriteBit ( m_bInteriorSoundsEnabled );
// Rain level
BitStream.WriteBit ( m_bOverrideRainLevel );
if ( m_bOverrideRainLevel )
{
BitStream.Write ( m_fRainLevel );
}
// Sun size
BitStream.WriteBit ( m_bOverrideSunSize );
if ( m_bOverrideSunSize )
{
BitStream.Write ( m_fSunSize );
}
//.........这里部分代码省略.........
示例10: Write
//.........这里部分代码省略.........
BitStream.WriteBit ( pPlayer->IsNametagColorOverridden () );
BitStream.WriteBit ( pPlayer->IsHeadless() );
BitStream.WriteBit ( pPlayer->IsFrozen() );
// Nametag stuff
unsigned char ucNametagTextLength = 0;
char* szNametagText = pPlayer->GetNametagText ();
if ( szNametagText )
ucNametagTextLength = static_cast < unsigned char > ( strlen ( szNametagText ) );
BitStream.Write ( ucNametagTextLength );
if ( ucNametagTextLength > 0 )
BitStream.Write ( szNametagText, ucNametagTextLength );
// Write nametag color if it's overridden
if ( pPlayer->IsNametagColorOverridden () )
{
unsigned char ucR, ucG, ucB;
pPlayer->GetNametagColor ( ucR, ucG, ucB );
BitStream.Write ( ucR );
BitStream.Write ( ucG );
BitStream.Write ( ucB );
}
// Move anim
if ( BitStream.Version() > 0x4B )
{
uchar ucMoveAnim = pPlayer->GetMoveAnim();
BitStream.Write ( ucMoveAnim );
}
// Always send extra info (Was: "Write spawn info if he's spawned")
if ( true )
{
// Player model ID
BitStream.WriteCompressed ( pPlayer->GetModel () );
// Team id
CTeam* pTeam = pPlayer->GetTeam ();
if ( pTeam )
{
BitStream.WriteBit ( true );
BitStream.Write ( pTeam->GetID () );
}
else
BitStream.WriteBit ( false );
if ( bInVehicle )
{
// Grab the occupied vehicle
CVehicle* pVehicle = pPlayer->GetOccupiedVehicle ();
// Vehicle ID and seat
BitStream.Write ( pVehicle->GetID () );
SOccupiedSeatSync seat;
seat.data.ucSeat = pPlayer->GetOccupiedVehicleSeat ();
BitStream.Write ( &seat );
}
else
{
// Player position
SPositionSync position ( false );
position.data.vecPosition = pPlayer->GetPosition ();
BitStream.Write ( &position );
// Player rotation
SPedRotationSync rotation;
rotation.data.fRotation = pPlayer->GetRotation ();
BitStream.Write ( &rotation );
}
BitStream.WriteCompressed ( pPlayer->GetDimension () );
BitStream.Write ( pPlayer->GetFightingStyle () );
SEntityAlphaSync alpha;
alpha.data.ucAlpha = pPlayer->GetAlpha ();
BitStream.Write ( &alpha );
BitStream.Write ( pPlayer->GetInterior () );
// Write the weapons of the player weapon slots
for ( unsigned int i = 0; i < 16; ++i )
{
CWeapon* pWeapon = pPlayer->GetWeapon ( i );
if ( pWeapon && pWeapon->ucType != 0 )
{
BitStream.WriteBit ( true );
SWeaponTypeSync weaponType;
weaponType.data.ucWeaponType = pWeapon->ucType;
BitStream.Write ( &weaponType );
}
else
BitStream.WriteBit ( false );
}
}
}
return true;
}
示例11: Write
bool CEntityAddPacket::Write ( NetBitStreamInterface& BitStream ) const
{
SPositionSync position ( false );
// Check that we have any entities
if ( m_Entities.size () > 0 )
{
// Write the number of entities
unsigned int NumElements = m_Entities.size ();
BitStream.WriteCompressed ( NumElements );
// For each entity ...
CVector vecTemp;
vector < CElement* > ::const_iterator iter = m_Entities.begin ();
for ( ; iter != m_Entities.end (); iter++ )
{
// Entity id
CElement* pElement = *iter;
BitStream.Write ( pElement->GetID () );
// Entity type id
unsigned char ucEntityTypeID = static_cast < unsigned char > ( pElement->GetType () );
BitStream.Write ( ucEntityTypeID );
// Entity parent
CElement* pParent = pElement->GetParentEntity ();
ElementID ParentID = INVALID_ELEMENT_ID;
if ( pParent )
ParentID = pParent->GetID ();
BitStream.Write ( ParentID );
// Entity interior
BitStream.Write ( pElement->GetInterior () );
// Entity dimension
BitStream.WriteCompressed ( pElement->GetDimension () );
// Entity attached to
CElement* pElementAttachedTo = pElement->GetAttachedToElement ();
if ( pElementAttachedTo )
{
BitStream.WriteBit ( true );
BitStream.Write ( pElementAttachedTo->GetID () );
// Attached position and rotation
SPositionSync attachedPosition ( false );
SRotationDegreesSync attachedRotation ( false );
pElement->GetAttachedOffsets ( attachedPosition.data.vecPosition,
attachedRotation.data.vecRotation );
BitStream.Write ( &attachedPosition );
BitStream.Write ( &attachedRotation );
}
else
BitStream.WriteBit ( false );
// Entity collisions enabled
bool bCollisionsEnabled = true;
switch ( pElement->GetType() )
{
case CElement::VEHICLE:
{
CVehicle* pVehicle = static_cast < CVehicle* > ( pElement );
bCollisionsEnabled = pVehicle->GetCollisionEnabled ( );
break;
}
case CElement::OBJECT:
{
CObject* pObject = static_cast < CObject* > ( pElement );
bCollisionsEnabled = pObject->GetCollisionEnabled ( );
break;
}
case CElement::PED:
case CElement::PLAYER:
{
CPed* pPed = static_cast < CPed* > ( pElement );
bCollisionsEnabled = pPed->GetCollisionEnabled ( );
break;
}
}
BitStream.WriteBit ( bCollisionsEnabled );
// Write custom data
CCustomData* pCustomData = pElement->GetCustomDataPointer ();
assert ( pCustomData );
BitStream.WriteCompressed ( pCustomData->CountOnlySynchronized () );
map < string, SCustomData > :: const_iterator iter = pCustomData->IterBegin ();
for ( ; iter != pCustomData->IterEnd (); iter++ )
{
const char* szName = iter->first.c_str ();
const CLuaArgument* pArgument = &iter->second.Variable;
bool bSynchronized = iter->second.bSynchronized;
if ( bSynchronized )
{
unsigned char ucNameLength = static_cast < unsigned char > ( strlen ( szName ) );
BitStream.Write ( ucNameLength );
BitStream.Write ( szName, ucNameLength );
pArgument->WriteToBitStream ( BitStream );
//.........这里部分代码省略.........
示例12: Write
bool CMapInfoPacket::Write ( NetBitStreamInterface& BitStream ) const
{
// Write the map weather
BitStream.Write ( m_ucWeather );
BitStream.Write ( m_ucWeatherBlendingTo );
BitStream.Write ( m_ucBlendedWeatherHour );
BitStream.WriteBit ( m_bHasSkyGradient );
if ( m_bHasSkyGradient )
{
BitStream.Write ( m_ucSkyGradientTR );
BitStream.Write ( m_ucSkyGradientTG );
BitStream.Write ( m_ucSkyGradientTB );
BitStream.Write ( m_ucSkyGradientBR );
BitStream.Write ( m_ucSkyGradientBG );
BitStream.Write ( m_ucSkyGradientBB );
}
// Write heat haze
BitStream.WriteBit ( m_bHasHeatHaze );
if ( m_bHasHeatHaze )
{
SHeatHazeSync heatHaze ( m_HeatHazeSettings );
BitStream.Write ( &heatHaze );
}
// Write the map hour
BitStream.Write ( m_ucClockHour );
BitStream.Write ( m_ucClockMin );
BitStream.WriteCompressed ( m_ulMinuteDuration );
// Write the map flags
SMapInfoFlagsSync flags;
flags.data.bShowNametags = m_bShowNametags;
flags.data.bShowRadar = m_bShowRadar;
flags.data.bCloudsEnabled = m_bCloudsEnabled;
BitStream.Write ( &flags );
// Write any other world conditions
BitStream.Write ( m_fGravity );
if ( m_fGameSpeed == 1.0f )
BitStream.WriteBit ( true );
else
{
BitStream.WriteBit ( false );
BitStream.Write ( m_fGameSpeed );
}
BitStream.Write ( m_fWaveHeight );
// Write world water level
BitStream.Write ( m_WorldWaterLevelInfo.fSeaLevel );
BitStream.WriteBit ( m_WorldWaterLevelInfo.bNonSeaLevelSet );
if ( m_WorldWaterLevelInfo.bNonSeaLevelSet )
BitStream.Write ( m_WorldWaterLevelInfo.fNonSeaLevel );
BitStream.WriteCompressed ( m_usFPSLimit );
// Write the garage states
for ( unsigned char i = 0 ; i < MAX_GARAGES ; i++ )
{
const SGarageStates& garageStates = *m_pGarageStates;
BitStream.WriteBit( garageStates[i] );
}
// Write the fun bugs state
SFunBugsStateSync funBugs;
funBugs.data.bQuickReload = g_pGame->IsGlitchEnabled ( CGame::GLITCH_QUICKRELOAD );
funBugs.data.bFastFire = g_pGame->IsGlitchEnabled ( CGame::GLITCH_FASTFIRE );
funBugs.data.bFastMove = g_pGame->IsGlitchEnabled ( CGame::GLITCH_FASTMOVE );
funBugs.data.bCrouchBug = g_pGame->IsGlitchEnabled ( CGame::GLITCH_CROUCHBUG );
funBugs.data.bCloseRangeDamage = g_pGame->IsGlitchEnabled ( CGame::GLITCH_CLOSEDAMAGE );
funBugs.data2.bHitAnim = g_pGame->IsGlitchEnabled ( CGame::GLITCH_HITANIM );
funBugs.data3.bFastSprint = g_pGame->IsGlitchEnabled ( CGame::GLITCH_FASTSPRINT );
BitStream.Write ( &funBugs );
BitStream.Write ( m_fJetpackMaxHeight );
BitStream.WriteBit ( m_bOverrideWaterColor );
if ( m_bOverrideWaterColor )
{
BitStream.Write ( m_ucWaterRed );
BitStream.Write ( m_ucWaterGreen );
BitStream.Write ( m_ucWaterBlue );
BitStream.Write ( m_ucWaterAlpha );
}
// Interior sounds
BitStream.WriteBit ( m_bInteriorSoundsEnabled );
// Rain level
BitStream.WriteBit ( m_bOverrideRainLevel );
if ( m_bOverrideRainLevel )
{
BitStream.Write ( m_fRainLevel );
}
// Moon size
if ( BitStream.Version () >= 0x40 )
{
BitStream.WriteBit ( m_bOverrideMoonSize );
//.........这里部分代码省略.........
示例13: WriteToBitStream
bool CLuaArgument::WriteToBitStream ( NetBitStreamInterface& bitStream, std::map < CLuaArguments*, unsigned long > * pKnownTables ) const
{
SLuaTypeSync type;
switch ( GetType () )
{
// Nil type
case LUA_TNIL:
{
type.data.ucType = LUA_TNIL;
bitStream.Write ( &type );
break;
}
// Boolean type
case LUA_TBOOLEAN:
{
type.data.ucType = LUA_TBOOLEAN;
bitStream.Write ( &type );
// Write the boolean to it
bitStream.WriteBit ( GetBoolean () );
break;
}
// Table argument
case LUA_TTABLE:
{
if ( pKnownTables && pKnownTables->find ( m_pTableData ) != pKnownTables->end () )
{
// Self-referencing table
type.data.ucType = LUA_TTABLEREF;
bitStream.Write ( &type );
bitStream.WriteCompressed ( pKnownTables->find ( m_pTableData )->second );
}
else
{
type.data.ucType = LUA_TTABLE;
bitStream.Write ( &type );
// Write the subtable to the bitstream
m_pTableData->WriteToBitStream ( bitStream, pKnownTables );
}
break;
}
// Number argument?
case LUA_TNUMBER:
{
type.data.ucType = LUA_TNUMBER;
bitStream.Write ( &type );
float fNumber = static_cast < float > ( GetNumber () );
long lNumber = static_cast < long > ( fNumber );
float fNumberInteger = static_cast < float > ( lNumber );
// Check if the number is an integer and can fit a long datatype
if ( fabs ( fNumber ) > fabs ( fNumberInteger + 1 ) ||
fabs ( fNumber - fNumberInteger ) >= FLOAT_EPSILON )
{
bitStream.WriteBit ( true );
bitStream.Write ( fNumber );
}
else
{
bitStream.WriteBit ( false );
bitStream.WriteCompressed ( lNumber );
}
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 = strlen ( szTemp );
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 ( const_cast < char* > ( szTemp ), usLength );
}
}
else
{
// Too long string
LogUnableToPacketize ( "Couldn't packetize argument list. Invalid string specified, limit is 65535 characters." );
// Write a nil though so other side won't get out of sync
type.data.ucType = LUA_TNIL;
bitStream.Write ( &type );
//.........这里部分代码省略.........
示例14: WriteToBitStream
bool CLuaArgument::WriteToBitStream ( NetBitStreamInterface& bitStream, CFastHashMap < CLuaArguments*, unsigned long > * pKnownTables ) const
{
SLuaTypeSync type;
switch ( GetType () )
{
// Nil type
case LUA_TNIL:
{
type.data.ucType = LUA_TNIL;
bitStream.Write ( &type );
break;
}
// Boolean type
case LUA_TBOOLEAN:
{
type.data.ucType = LUA_TBOOLEAN;
bitStream.Write ( &type );
// Write the boolean to it
bitStream.WriteBit ( GetBoolean () );
break;
}
// Table argument
case LUA_TTABLE:
{
ulong* pTableId;
if ( pKnownTables && ( pTableId = MapFind ( *pKnownTables, m_pTableData ) ) )
{
// Self-referencing table
type.data.ucType = LUA_TTABLEREF;
bitStream.Write ( &type );
bitStream.WriteCompressed ( *pTableId );
}
else
{
type.data.ucType = LUA_TTABLE;
bitStream.Write ( &type );
// Write the subtable to the bitstream
m_pTableData->WriteToBitStream ( bitStream, pKnownTables );
}
break;
}
// Number argument?
case LUA_TNUMBER:
{
type.data.ucType = LUA_TNUMBER;
bitStream.Write ( &type );
if ( bitStream.Version() < 0x59 )
{
// Old way
int iNumber;
if ( !ShouldUseInt( GetNumber(), &iNumber ) )
{
bitStream.WriteBit ( true );
bitStream.Write ( static_cast < float > ( GetNumber() ) );
}
else
{
bitStream.WriteBit ( false );
bitStream.WriteCompressed ( iNumber );
}
}
else
{
// New way - Maybe use double to better preserve > 32bit numbers
int iNumber;
float fNumber;
double dNumber;
EDataType dataType = GetDataTypeToUse( GetNumber(), &iNumber, &fNumber, &dNumber );
if ( dataType == DATA_TYPE_INT )
{
bitStream.WriteBit ( false );
bitStream.WriteCompressed ( iNumber );
}
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:
{
//.........这里部分代码省略.........
示例15: Write
bool CLightsyncPacket::Write ( NetBitStreamInterface& BitStream ) const
{
bool bSyncPosition;
if ( Count() == 0 )
return false;
for ( std::vector<CPlayer *>::const_iterator iter = m_players.begin ();
iter != m_players.end();
++iter )
{
CPlayer* pPlayer = *iter;
CPlayer::SLightweightSyncData& data = pPlayer->GetLightweightSyncData ();
CVehicle* pVehicle = pPlayer->GetOccupiedVehicle ();
// Find the difference between now and the time the position last changed for the player
long long llTicksDifference = GetTickCount64_ ( ) - pPlayer->GetPositionLastChanged ( );
// Right we need to sync the position if there is no vehicle or he's in a vehicle and the difference between setPosition is less than or equal to the slow sync rate
// i.e. make sure his position has been updated more than 0.001f in the last 1500ms plus a small margin for error (probably not needed).
// This will ensure we only send positions when the position has changed.
bSyncPosition = ( !pVehicle || pPlayer->GetOccupiedVehicleSeat () == 0 ) && llTicksDifference <= SLOW_SYNCRATE + 100;
BitStream.Write ( pPlayer->GetID () );
BitStream.Write ( (unsigned char)pPlayer->GetSyncTimeContext () );
unsigned short usLatency = pPlayer->GetPing ();
BitStream.WriteCompressed ( usLatency );
BitStream.WriteBit ( data.health.bSync );
if ( data.health.bSync )
{
SPlayerHealthSync health;
health.data.fValue = pPlayer->GetHealth ();
BitStream.Write ( &health );
SPlayerArmorSync armor;
armor.data.fValue = pPlayer->GetArmor ();
BitStream.Write ( &armor );
}
BitStream.WriteBit ( bSyncPosition );
if ( bSyncPosition )
{
SLowPrecisionPositionSync pos;
pos.data.vecPosition = pPlayer->GetPosition ();
BitStream.Write ( &pos );
bool bSyncVehicleHealth = data.vehicleHealth.bSync && pVehicle;
BitStream.WriteBit ( bSyncVehicleHealth );
if ( bSyncVehicleHealth )
{
SLowPrecisionVehicleHealthSync health;
health.data.fValue = pVehicle->GetHealth ();
BitStream.Write ( &health );
}
}
}
return true;
}