本文整理汇总了C++中bf_read::ReadOneBit方法的典型用法代码示例。如果您正苦于以下问题:C++ bf_read::ReadOneBit方法的具体用法?C++ bf_read::ReadOneBit怎么用?C++ bf_read::ReadOneBit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bf_read
的用法示例。
在下文中一共展示了bf_read::ReadOneBit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: __MsgFunc_BuildMenuUpdate
//--------------------------------------------------------------
// TGB: usermessage for updating the buildmenu
//--------------------------------------------------------------
void __MsgFunc_BuildMenuUpdate( bf_read &msg )
{
//DevMsg("Received BuildMenuUpdate on client\n");
if (gBuildMenu == NULL)
{
gBuildMenu = dynamic_cast<CBuildMenu *>(gViewPortInterface->FindPanelByName(PANEL_BUILD));
if(gBuildMenu == NULL)
return;
}
//read spawn entindex
int spawnidx = msg.ReadShort();
//read whether this is an opener msg or update msg
bool force_open = (msg.ReadOneBit() == 1);
//read queue from usermessage
int queue[BM_QUEUE_SIZE];
for (int i=0; i < BM_QUEUE_SIZE; i++)
{
//every type was increased by 1 so that type_invalid could be 0 (byte is unsigned)
queue[i] = (msg.ReadByte() - 1);
}
if (force_open)
{
//if we weren't visible, this is also an opening message
gViewPortInterface->ShowPanel(gBuildMenu, true);
}
gBuildMenu->SetCurrentSpawn(spawnidx);
gBuildMenu->UpdateQueue(queue);
}
示例2: MsgFunc_ASWOrderStopItemFX
void CASW_Hud_Squad_Hotbar::MsgFunc_ASWOrderStopItemFX( bf_read &msg )
{
int iMarine = msg.ReadShort();
C_ASW_Marine *pMarine = dynamic_cast<C_ASW_Marine*>(ClientEntityList().GetEnt(iMarine)); // turn iMarine ent index into the marine
if ( !pMarine )
return;
bool bShouldDelay = msg.ReadOneBit() ? true : false;
bool bFailed = msg.ReadOneBit() ? true : false;
// loops through to see if we already have an order effect for this marine
if ( bFailed )
StopItemFX( pMarine, gpGlobals->curtime + 2.0f, true );
else if ( bShouldDelay )
StopItemFX( pMarine, gpGlobals->curtime + 2.0f );
else
StopItemFX( pMarine );
}
示例3: ParseUpdate
//-----------------------------------------------------------------------------
// Purpose: Parse string update
//-----------------------------------------------------------------------------
void CNetworkStringTable::ParseUpdate( bf_read &buf, int entries )
{
int lastEntry = -1;
CUtlVector< StringHistoryEntry > history;
for (int i=0; i<entries; i++)
{
int entryIndex = lastEntry + 1;
if ( !buf.ReadOneBit() )
{
entryIndex = buf.ReadUBitLong( GetEntryBits() );
}
lastEntry = entryIndex;
if ( entryIndex < 0 || entryIndex >= GetMaxStrings() )
{
Host_Error( "Server sent bogus string index %i for table %s\n", entryIndex, GetTableName() );
}
const char *pEntry = NULL;
char entry[ 1024 ];
char substr[ 1024 ];
if ( buf.ReadOneBit() )
{
bool substringcheck = buf.ReadOneBit() ? true : false;
if ( substringcheck )
{
int index = buf.ReadUBitLong( 5 );
int bytestocopy = buf.ReadUBitLong( SUBSTRING_BITS );
Q_strncpy( entry, history[ index ].string, bytestocopy + 1 );
buf.ReadString( substr, sizeof(substr) );
Q_strncat( entry, substr, sizeof(entry), COPY_ALL_CHARACTERS );
}
else
{
buf.ReadString( entry, sizeof( entry ) );
}
pEntry = entry;
}
// Read in the user data.
unsigned char tempbuf[ CNetworkStringTableItem::MAX_USERDATA_SIZE ];
memset( tempbuf, 0, sizeof( tempbuf ) );
const void *pUserData = NULL;
int nBytes = 0;
if ( buf.ReadOneBit() )
{
if ( IsUserDataFixedSize() )
{
// Don't need to read length, it's fixed length and the length was networked down already.
nBytes = GetUserDataSize();
Assert( nBytes > 0 );
tempbuf[nBytes-1] = 0; // be safe, clear last byte
buf.ReadBits( tempbuf, GetUserDataSizeBits() );
}
else
{
nBytes = buf.ReadUBitLong( CNetworkStringTableItem::MAX_USERDATA_BITS );
ErrorIfNot( nBytes <= sizeof( tempbuf ),
("CNetworkStringTableClient::ParseUpdate: message too large (%d bytes).", nBytes)
);
buf.ReadBytes( tempbuf, nBytes );
}
pUserData = tempbuf;
}
// Check if we are updating an old entry or adding a new one
if ( entryIndex < GetNumStrings() )
{
SetStringUserData( entryIndex, nBytes, pUserData );
#ifdef _DEBUG
if ( pEntry )
{
Assert( !Q_strcmp( pEntry, GetString( entryIndex ) ) ); // make sure string didn't change
}
#endif
pEntry = GetString( entryIndex ); // string didn't change
}
else
{
// Grow the table (entryindex must be the next empty slot)
Assert( (entryIndex == GetNumStrings()) && (pEntry != NULL) );
if ( pEntry == NULL )
{
Msg("CNetworkStringTable::ParseUpdate: NULL pEntry, table %s, index %i\n", GetTableName(), entryIndex );
pEntry = "";// avoid crash because of NULL strings
}
//.........这里部分代码省略.........
示例4: HandleMessage
bool HandleMessage(bf_read &msg, int type)
{
if (type == 0) // nop
{
// printf("NOP\n");
return true;
}
if (type == 1) // disconnect
{
char dcreason[1024];
msg.ReadString(dcreason, sizeof(dcreason));
printf("Disconnected: %s\n", dcreason);
printf("Reconnecting in 5000 ms ...");
_sleep(5000);
NET_Reconnect();
return true;
}
if (type == 2)//net_File
{
long transferid = msg.ReadUBitLong(32);
char filename[255];
msg.ReadString(filename, sizeof(filename));
bool requested = (bool)(msg.ReadOneBit()==1);
if (requested)
printf("net_File: Server requested file: %s::%i\n", filename, transferid);
else
printf("net_File: Server is not sending file: %s::%i\n", filename, transferid);
return true;
}
if (type == 3)//net_Tick
{
net_tick = msg.ReadLong();
net_hostframetime = msg.ReadUBitLong(16);
net_hostframedeviation = msg.ReadUBitLong(16);
//printf("Tick: %i - hostframetime: %i ( deviation: %i )\n", net_tick, net_hostframedeviation, net_hostframedeviation);
return true;
}
if (type == 4)//net_StringCmd
{
char cmd[1024];
msg.ReadString(cmd, sizeof(cmd));
printf("net_StringCmd: %s\n", cmd);
return true;
}
if (type == 5)//net_SetConVar
{
int count = msg.ReadByte();
char cmdname[255];
char cmdval[255];
printf("net_SetConVar: %i\n", count);
for (int i = 0; i < count; i++)
{
msg.ReadString(cmdname, sizeof(cmdname));
msg.ReadString(cmdval, sizeof(cmdval));
printf("%s to: %s\n", cmdname, cmdval);
}
printf("net_SetConVar_end, left: %i\n", msg.GetNumBytesLeft());
return true;
}
if (type == 6)// net_SignonState
{
int state = msg.ReadByte();
long aservercount = msg.ReadLong();
printf("Received net_SignOnState: %i, count: %i\n", state, bconnectstep);
if (netchan->m_iSignOnState == state)
{
printf("Ignored signonstate!\n");
return true;
}
netchan->m_iServerCount = aservercount;
netchan->m_iSignOnState = state;
printf("KK __ %i\n", state);
if (state == 3)
{
senddata.WriteUBitLong(8, 6);
senddata.WriteLong(netchan->m_iServerCount);
senddata.WriteLong(518790445);//clc_ClientInfo crc
senddata.WriteOneBit(1);//ishltv
//.........这里部分代码省略.........