本文整理汇总了C++中MSG_WriteBits函数的典型用法代码示例。如果您正苦于以下问题:C++ MSG_WriteBits函数的具体用法?C++ MSG_WriteBits怎么用?C++ MSG_WriteBits使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MSG_WriteBits函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MSG_Init
/*
================
rvDebuggerServer::HandleInspectThreads
Send the list of the current threads in the interpreter back to the debugger client
================
*/
void rvDebuggerServer::HandleInspectThreads ( msg_t* in_msg )
{
msg_t msg;
byte buffer[MAX_MSGLEN];
int i;
// Initialize the message
MSG_Init( &msg, buffer, sizeof( buffer ) );
MSG_WriteShort ( &msg, (int)DBMSG_INSPECTTHREADS );
// Write the number of threads to the message
MSG_WriteShort ( &msg, (int)idThread::GetThreads().Num() );
// Loop through all of the threads and write their name and number to the message
for ( i = 0; i < idThread::GetThreads().Num(); i ++ )
{
idThread* thread = idThread::GetThreads()[i];
MSG_WriteString ( &msg, thread->GetThreadName ( ) );
MSG_WriteLong ( &msg, thread->GetThreadNum ( ) );
MSG_WriteBits ( &msg, (int)(thread == mBreakInterpreter->GetThread ( )), 1 );
MSG_WriteBits ( &msg, (int)thread->IsDoneProcessing(), 1 );
MSG_WriteBits ( &msg, (int)thread->IsWaiting(), 1 );
MSG_WriteBits ( &msg, (int)thread->IsDying(), 1 );
}
// Send off the inspect threads packet to the debugger client
SendPacket ( msg.data, msg.cursize );
}
示例2: MSG_WriteDelta
void MSG_WriteDelta( msg_t *msg, int oldV, int newV, int bits ) {
if ( oldV == newV ) {
MSG_WriteBits( msg, 0, 1 );
return;
}
MSG_WriteBits( msg, 1, 1 );
MSG_WriteBits( msg, newV, bits );
}
示例3: MSG_WriteDeltaFloat
void MSG_WriteDeltaFloat( msg_t *msg, float oldV, float newV ) {
if ( oldV == newV ) {
MSG_WriteBits( msg, 0, 1 );
return;
}
MSG_WriteBits( msg, 1, 1 );
MSG_WriteBits( msg, *(int *)&newV, 32 );
}
示例4: MSG_WriteDeltaFloat
void MSG_WriteDeltaFloat( msg_t *msg, float oldV, float newV ) {
byteAlias_t fi;
if ( oldV == newV ) {
MSG_WriteBits( msg, 0, 1 );
return;
}
fi.f = newV;
MSG_WriteBits( msg, 1, 1 );
MSG_WriteBits( msg, fi.i, 32 );
}
示例5: demoFramePack
static void demoFramePack( msg_t *msg, const demoFrame_t *newFrame, const demoFrame_t *oldFrame ) {
int i;
/* Full or delta frame marker */
MSG_WriteBits( msg, oldFrame ? 0 : 1, 1 );
MSG_WriteLong( msg, newFrame->serverTime );
/* Add the config strings */
for (i = 0;i<MAX_CONFIGSTRINGS;i++) {
const char *oldString = !oldFrame ? "" : &oldFrame->string.data[oldFrame->string.offsets[i]];
const char *newString = newFrame->string.data + newFrame->string.offsets[i];
if (strcmp( oldString, newString)) {
MSG_WriteShort( msg, i );
MSG_WriteBigString( msg, newString );
}
}
MSG_WriteShort( msg, MAX_CONFIGSTRINGS );
/* Add the playerstates */
for (i=0; i<MAX_CLIENTS; i++) {
const playerState_t *oldPlayer, *newPlayer;
if (!newFrame->clientData[i])
continue;
oldPlayer = (!oldFrame || !oldFrame->clientData[i]) ? &demoNullPlayerState : &oldFrame->clients[i];
newPlayer = &newFrame->clients[i];
MSG_WriteByte( msg, i );
MSG_WriteDeltaPlayerstate( msg, oldPlayer, newPlayer );
}
MSG_WriteByte( msg, MAX_CLIENTS );
/* Add the entities */
for (i=0; i<MAX_GENTITIES-1; i++) {
const entityState_t *oldEntity, *newEntity;
newEntity = &newFrame->entities[i];
if (oldFrame) {
oldEntity = &oldFrame->entities[i];
if (oldEntity->number == (MAX_GENTITIES -1))
oldEntity = 0;
} else {
oldEntity = 0;
}
if (newEntity->number != i || newEntity->number >= (MAX_GENTITIES -1)) {
newEntity = 0;
} else {
if (!oldEntity) {
oldEntity = &demoNullEntityState;
}
}
MSG_WriteDeltaEntity( msg, oldEntity, newEntity, qfalse );
}
MSG_WriteBits( msg, (MAX_GENTITIES-1), GENTITYNUM_BITS );
/* Add the area mask */
MSG_WriteByte( msg, newFrame->areaUsed );
MSG_WriteData( msg, newFrame->areamask, newFrame->areaUsed );
/* Add the command string data */
MSG_WriteLong( msg, newFrame->commandUsed );
MSG_WriteData( msg, newFrame->commandData, newFrame->commandUsed );
}
示例6: SV_EmitPacketEntities
/*
=============
SV_EmitPacketEntities
Writes a delta update of an entityState_t list to the message.
=============
*/
static void SV_EmitPacketEntities( clientSnapshot_t *from, clientSnapshot_t *to, msg_t *msg ) {
entityState_t *oldent, *newent;
int oldindex, newindex;
int oldnum, newnum;
int from_num_entities;
// generate the delta update
if ( !from ) {
from_num_entities = 0;
} else {
from_num_entities = from->num_entities;
}
newent = NULL;
oldent = NULL;
newindex = 0;
oldindex = 0;
while ( newindex < to->num_entities || oldindex < from_num_entities ) {
if ( newindex >= to->num_entities ) {
newnum = 9999;
} else {
newent = &svs.snapshotEntities[(to->first_entity+newindex) % svs.numSnapshotEntities];
newnum = newent->number;
}
if ( oldindex >= from_num_entities ) {
oldnum = 9999;
} else {
oldent = &svs.snapshotEntities[(from->first_entity+oldindex) % svs.numSnapshotEntities];
oldnum = oldent->number;
}
if ( newnum == oldnum ) {
// delta update from old position
// because the force parm is qfalse, this will not result
// in any bytes being emited if the entity has not changed at all
MSG_WriteDeltaEntity (msg, oldent, newent, qfalse );
oldindex++;
newindex++;
continue;
}
if ( newnum < oldnum ) {
// this is a new entity, send it from the baseline
MSG_WriteDeltaEntity (msg, &sv.svEntities[newnum].baseline, newent, qtrue );
newindex++;
continue;
}
if ( newnum > oldnum ) {
// the old entity isn't present in the new message
MSG_WriteDeltaEntity (msg, oldent, NULL, qtrue );
oldindex++;
continue;
}
}
MSG_WriteBits( msg, (MAX_GENTITIES-1), GENTITYNUM_BITS ); // end of packetentities
}
示例7: SV_EmitPacketEntities
/*
=============
SV_EmitPacketEntities
Writes a delta update of an entity_state_t list to the message->
=============
*/
void SV_EmitPacketEntities( client_frame_t *from, client_frame_t *to, sizebuf_t *msg )
{
entity_state_t *oldent, *newent;
int oldindex, newindex;
int oldnum, newnum;
int from_num_entities;
MSG_WriteByte( msg, svc_packetentities );
if( !from ) from_num_entities = 0;
else from_num_entities = from->num_entities;
newent = NULL;
oldent = NULL;
newindex = 0;
oldindex = 0;
while( newindex < to->num_entities || oldindex < from_num_entities )
{
if( newindex >= to->num_entities ) newnum = MAX_ENTNUMBER;
else
{
newent = &svs.client_entities[(to->first_entity+newindex)%svs.num_client_entities];
newnum = newent->number;
}
if( oldindex >= from_num_entities ) oldnum = MAX_ENTNUMBER;
else
{
oldent = &svs.client_entities[(from->first_entity+oldindex)%svs.num_client_entities];
oldnum = oldent->number;
}
if( newnum == oldnum )
{
// delta update from old position
// because the force parm is false, this will not result
// in any bytes being emited if the entity has not changed at all
MSG_WriteDeltaEntity( oldent, newent, msg, false, ( newent->number <= sv_maxclients->integer ));
oldindex++;
newindex++;
continue;
}
if( newnum < oldnum )
{
// this is a new entity, send it from the baseline
MSG_WriteDeltaEntity( &svs.baselines[newnum], newent, msg, true, true );
newindex++;
continue;
}
if( newnum > oldnum )
{
// remove from message
MSG_WriteDeltaEntity( oldent, NULL, msg, false, false );
oldindex++;
continue;
}
}
MSG_WriteBits( msg, 0, "svc_packetentities", NET_WORD ); // end of packetentities
}
示例8: MSG_WriteDeltaEntity
void MSG_WriteDeltaEntity( msg_t *msg, struct entityState_s *from, struct entityState_s *to,
qboolean force ) {
int c;
int i;
const netField_t *field;
int *fromF, *toF;
int blah;
bool stuffChanged = false;
const int numFields = sizeof(entityStateFields)/sizeof(entityStateFields[0]);
byte changeVector[(numFields/8) + 1];
// all fields should be 32 bits to avoid any compiler packing issues
// the "number" field is not part of the field list
// if this assert fails, someone added a field to the entityState_t
// struct without updating the message fields
blah = sizeof( *from );
assert( numFields + 1 == blah/4);
c = msg->cursize;
// a NULL to is a delta remove message
if ( to == NULL ) {
if ( from == NULL ) {
return;
}
MSG_WriteBits( msg, from->number, GENTITYNUM_BITS );
MSG_WriteBits( msg, 1, 1 );
return;
}
if ( to->number < 0 || to->number >= MAX_GENTITIES ) {
Com_Error (ERR_FATAL, "MSG_WriteDeltaEntity: Bad entity number: %i", to->number );
}
memset(changeVector, 0, sizeof(changeVector));
// build the change vector as bytes so it is endien independent
for ( i = 0, field = entityStateFields ; i < numFields ; i++, field++ ) {
fromF = (int *)( (byte *)from + field->offset );
toF = (int *)( (byte *)to + field->offset );
if ( *fromF != *toF ) {
changeVector[ i>>3 ] |= 1 << ( i & 7 );
stuffChanged = true;
}
}
示例9: MSG_WriteShort
void MSG_WriteShort( msg_t *sb, int c ) {
#ifdef PARANOID
if (c < ((short)0x8000) || c > (short)0x7fff)
Com_Error (ERR_FATAL, "MSG_WriteShort: range error");
#endif
MSG_WriteBits( sb, c, 16 );
}
示例10: MSG_WriteByte
void MSG_WriteByte( msg_t *sb, int c ) {
#ifdef PARANOID
if (c < 0 || c > 255)
Com_Error (ERR_FATAL, "MSG_WriteByte: range error");
#endif
MSG_WriteBits( sb, c, 8 );
}
示例11: MSG_WriteField
void MSG_WriteField (msg_t *msg, const int *toF, const netField_t *field)
{
int trunc;
float fullFloat;
if ( field->bits == -1)
{ // a -1 in the bits field means it's a float that's always between -1 and 1
int temp = *(float *)toF * 32767;
MSG_WriteBits( msg, temp, -16 );
}
else
if ( field->bits == 0 ) {
// float
fullFloat = *(float *)toF;
trunc = (int)fullFloat;
if (fullFloat == 0.0f) {
MSG_WriteBits( msg, 0, 1 ); //it's a zero
} else {
MSG_WriteBits( msg, 1, 1 ); //not a zero
if ( trunc == fullFloat && trunc + FLOAT_INT_BIAS >= 0 &&
trunc + FLOAT_INT_BIAS < ( 1 << FLOAT_INT_BITS ) ) {
// send as small integer
MSG_WriteBits( msg, 0, 1 );
MSG_WriteBits( msg, trunc + FLOAT_INT_BIAS, FLOAT_INT_BITS );
} else {
// send as full floating point value
MSG_WriteBits( msg, 1, 1 );
MSG_WriteBits( msg, *toF, 32 );
}
}
} else {
if (*toF == 0) {
MSG_WriteBits( msg, 0, 1 ); //it's a zero
} else {
MSG_WriteBits( msg, 1, 1 ); //not a zero
// integer
MSG_WriteBits( msg, *toF, field->bits );
}
}
}
示例12: MSG_Init
/*
================
rvDebuggerClient::SendAddBreakpoint
Send an individual breakpoint over to the debugger server
================
*/
void rvDebuggerClient::SendAddBreakpoint(rvDebuggerBreakpoint &bp, bool onceOnly)
{
msg_t msg;
byte buffer[MAX_MSGLEN];
if (!mConnected) {
return;
}
MSG_Init(&msg, buffer, sizeof(buffer));
MSG_WriteShort(&msg, (int)DBMSG_ADDBREAKPOINT);
MSG_WriteBits(&msg, onceOnly?1:0, 1);
MSG_WriteLong(&msg, (unsigned long) bp.GetLineNumber());
MSG_WriteLong(&msg, bp.GetID());
MSG_WriteString(&msg, bp.GetFilename());
SendPacket(msg.data, msg.cursize);
}
示例13: SV_WriteVoipToClient
/*
==================
SV_WriteVoipToClient
Check to see if there is any VoIP queued for a client, and send if there is.
==================
*/
static void SV_WriteVoipToClient( client_t* cl, msg_s* msg )
{
int totalbytes = 0;
int i;
voipServerPacket_t* packet;
if ( cl->queuedVoipPackets )
{
// Write as many VoIP packets as we reasonably can...
for ( i = 0; i < cl->queuedVoipPackets; i++ )
{
packet = cl->voipPacket[( i + cl->queuedVoipIndex ) % ARRAY_LEN( cl->voipPacket )];
if ( !*cl->downloadName )
{
totalbytes += packet->len;
if ( totalbytes > ( msg->maxsize - msg->cursize ) / 2 )
break;
MSG_WriteByte( msg, svc_voip );
MSG_WriteShort( msg, packet->sender );
MSG_WriteByte( msg, ( byte ) packet->generation );
MSG_WriteLong( msg, packet->sequence );
MSG_WriteByte( msg, packet->frames );
MSG_WriteShort( msg, packet->len );
MSG_WriteBits( msg, packet->flags, VOIP_FLAGCNT );
MSG_WriteData( msg, packet->data, packet->len );
}
free( packet );
}
cl->queuedVoipPackets -= i;
cl->queuedVoipIndex += i;
cl->queuedVoipIndex %= ARRAY_LEN( cl->voipPacket );
}
}
示例14: MSG_WriteBits_api
void EXT_FUNC MSG_WriteBits_api(uint32 data, int numbits) {
MSG_WriteBits(data, numbits);
}
示例15: CL_WritePacket
//.........这里部分代码省略.........
}
#ifdef USE_VOIP
if (clc.voipOutgoingDataSize > 0)
{
if((clc.voipFlags & VOIP_SPATIAL) || Com_IsVoipTarget(clc.voipTargets, sizeof(clc.voipTargets), -1))
{
MSG_WriteByte (&buf, clc_voip);
MSG_WriteByte (&buf, clc.voipOutgoingGeneration);
MSG_WriteLong (&buf, clc.voipOutgoingSequence);
MSG_WriteByte (&buf, clc.voipOutgoingDataFrames);
MSG_WriteData (&buf, clc.voipTargets, sizeof(clc.voipTargets));
MSG_WriteByte(&buf, clc.voipFlags);
MSG_WriteShort (&buf, clc.voipOutgoingDataSize);
MSG_WriteData (&buf, clc.voipOutgoingData, clc.voipOutgoingDataSize);
// If we're recording a demo, we have to fake a server packet with
// this VoIP data so it gets to disk; the server doesn't send it
// back to us, and we might as well eliminate concerns about dropped
// and misordered packets here.
if(clc.demorecording && !clc.demowaiting)
{
const int voipSize = clc.voipOutgoingDataSize;
msg_t fakemsg;
byte fakedata[MAX_MSGLEN];
MSG_Init (&fakemsg, fakedata, sizeof (fakedata));
MSG_Bitstream (&fakemsg);
MSG_WriteLong (&fakemsg, clc.reliableAcknowledge);
MSG_WriteByte (&fakemsg, svc_voip);
MSG_WriteShort (&fakemsg, clc.clientNum);
MSG_WriteByte (&fakemsg, clc.voipOutgoingGeneration);
MSG_WriteLong (&fakemsg, clc.voipOutgoingSequence);
MSG_WriteByte (&fakemsg, clc.voipOutgoingDataFrames);
MSG_WriteShort (&fakemsg, clc.voipOutgoingDataSize );
MSG_WriteBits (&fakemsg, clc.voipFlags, VOIP_FLAGCNT);
MSG_WriteData (&fakemsg, clc.voipOutgoingData, voipSize);
MSG_WriteByte (&fakemsg, svc_EOF);
CL_WriteDemoMessage (&fakemsg, 0);
}
clc.voipOutgoingSequence += clc.voipOutgoingDataFrames;
clc.voipOutgoingDataSize = 0;
clc.voipOutgoingDataFrames = 0;
}
else
{
// We have data, but no targets. Silently discard all data
clc.voipOutgoingDataSize = 0;
clc.voipOutgoingDataFrames = 0;
}
}
#endif
if ( count >= 1 ) {
if ( cl_showSend->integer ) {
Com_Printf( "(%i)", count );
}
// begin a client move command
if ( cl_nodelta->integer || !cl.snap.valid || clc.demowaiting
|| clc.serverMessageSequence != cl.snap.messageNum ) {
MSG_WriteByte (&buf, clc_moveNoDelta);
} else {
MSG_WriteByte (&buf, clc_move);
}
// write the command count
MSG_WriteByte( &buf, count );
// use the checksum feed in the key
key = clc.checksumFeed;
// also use the message acknowledge
key ^= clc.serverMessageSequence;
// also use the last acknowledged server command in the key
key ^= MSG_HashKey(clc.serverCommands[ clc.serverCommandSequence & (MAX_RELIABLE_COMMANDS-1) ], 32);
// write all the commands, including the predicted command
for ( i = 0 ; i < count ; i++ ) {
j = (cl.cmdNumber - count + i + 1) & CMD_MASK;
cmd = &cl.cmds[j];
MSG_WriteDeltaUsercmdKey (&buf, key, oldcmd, cmd);
oldcmd = cmd;
}
}
//
// deliver the message
//
packetNum = clc.netchan.outgoingSequence & PACKET_MASK;
cl.outPackets[ packetNum ].p_realtime = cls.realtime;
cl.outPackets[ packetNum ].p_serverTime = oldcmd->serverTime;
cl.outPackets[ packetNum ].p_cmdNumber = cl.cmdNumber;
clc.lastPacketSentTime = cls.realtime;
if ( cl_showSend->integer ) {
Com_Printf( "%i ", buf.cursize );
}
CL_Netchan_Transmit (&clc.netchan, &buf);
}