本文整理汇总了C++中MSG_ReadBits函数的典型用法代码示例。如果您正苦于以下问题:C++ MSG_ReadBits函数的具体用法?C++ MSG_ReadBits怎么用?C++ MSG_ReadBits使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MSG_ReadBits函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MSG_ReadDeltaFloat
float MSG_ReadDeltaFloat( msg_t *msg, float oldV ) {
if ( MSG_ReadBits( msg, 1 ) ) {
float newV;
*(int *)&newV = MSG_ReadBits( msg, 32 );
return newV;
}
return oldV;
}
示例2: MSG_ReadDeltaFloat
float MSG_ReadDeltaFloat( msg_t *msg, float oldV ) {
if ( MSG_ReadBits( msg, 1 ) ) {
byteAlias_t fi;
fi.i = MSG_ReadBits( msg, 32 );
return fi.f;
}
return oldV;
}
示例3: demoCutParseRMG
void demoCutParseRMG(msg_t *msg, clientConnection_t *clcCut, clientActive_t *clCut) {
int i;
clcCut->rmgHeightMapSize = (unsigned short)MSG_ReadShort(msg);
if (clcCut->rmgHeightMapSize == 0) {
return;
}
z_stream zdata;
int flatDataSize;
unsigned char heightmap1[15000];
// height map
if (MSG_ReadBits(msg, 1)) {
memset(&zdata, 0, sizeof(z_stream));
inflateInit(&zdata/*, Z_SYNC_FLUSH*/);
MSG_ReadData (msg, heightmap1, clcCut->rmgHeightMapSize);
zdata.next_in = heightmap1;
zdata.avail_in = clcCut->rmgHeightMapSize;
zdata.next_out = (unsigned char*)clcCut->rmgHeightMap;
zdata.avail_out = MAX_HEIGHTMAP_SIZE;
inflate(&zdata,Z_SYNC_FLUSH);
clcCut->rmgHeightMapSize = zdata.total_out;
inflateEnd(&zdata);
} else {
MSG_ReadData(msg, (unsigned char*)clcCut->rmgHeightMap, clcCut->rmgHeightMapSize);
}
// Flatten map
flatDataSize = MSG_ReadShort(msg);
if (MSG_ReadBits(msg, 1)) {
// Read the flatten map
memset(&zdata, 0, sizeof(z_stream));
inflateInit(&zdata/*, Z_SYNC_FLUSH*/);
MSG_ReadData ( msg, heightmap1, flatDataSize);
zdata.next_in = heightmap1;
zdata.avail_in = clcCut->rmgHeightMapSize;
zdata.next_out = (unsigned char*)clcCut->rmgFlattenMap;
zdata.avail_out = MAX_HEIGHTMAP_SIZE;
inflate(&zdata, Z_SYNC_FLUSH);
inflateEnd(&zdata);
} else {
MSG_ReadData(msg, (unsigned char*)clcCut->rmgFlattenMap, flatDataSize);
}
// Seed
clcCut->rmgSeed = MSG_ReadLong(msg);
// Automap symbols
clcCut->rmgAutomapSymbolCount = (unsigned short)MSG_ReadShort(msg);
for(i = 0; i < clcCut->rmgAutomapSymbolCount; i++) {
clcCut->rmgAutomapSymbols[i].mType = (int)MSG_ReadByte(msg);
clcCut->rmgAutomapSymbols[i].mSide = (int)MSG_ReadByte(msg);
clcCut->rmgAutomapSymbols[i].mOrigin[0] = (float)MSG_ReadLong(msg);
clcCut->rmgAutomapSymbols[i].mOrigin[1] = (float)MSG_ReadLong(msg);
}
}
示例4: MSG_ReadLong
int MSG_ReadLong( msg_t *msg ) {
int c;
if ( msg->readcount+4 > msg->cursize ) {
c = -1;
} else {
c = MSG_ReadBits( msg, 32 );
}
return c;
}
示例5: MSG_ReadSShort
static int MSG_ReadSShort( msg_t *msg ) {
int c;
if ( msg->readcount+2 > msg->cursize ) {
c = -1;
} else {
c = MSG_ReadBits( msg, -16 );
}
return c;
}
示例6: MSG_ReadByte
// returns -1 if no more characters are available
int MSG_ReadByte( msg_t *msg ) {
int c;
if ( msg->readcount+1 > msg->cursize ) {
c = -1;
} else {
c = (unsigned char)MSG_ReadBits( msg, 8 );
}
return c;
}
示例7: demoCutParseGamestate
qboolean demoCutParseGamestate(msg_t *msg, clientConnection_t *clcCut, clientActive_t *clCut) {
int i;
entityState_t *es;
int newnum;
entityState_t nullstate;
int cmd;
char *s;
clcCut->connectPacketCount = 0;
Com_Memset(clCut, 0, sizeof(*clCut));
clcCut->serverCommandSequence = MSG_ReadLong(msg);
clCut->gameState.dataCount = 1;
while (1) {
cmd = MSG_ReadByte(msg);
if (cmd == svc_EOF) {
break;
}
if (cmd == svc_configstring) {
int len, start;
start = msg->readcount;
i = MSG_ReadShort(msg);
if (i < 0 || i >= MAX_CONFIGSTRINGS) {
Com_Printf("configstring > MAX_CONFIGSTRINGS");
return qfalse;
}
s = MSG_ReadBigString(msg);
len = strlen(s);
if (len + 1 + clCut->gameState.dataCount > MAX_GAMESTATE_CHARS) {
Com_Printf("MAX_GAMESTATE_CHARS exceeded");
return qfalse;
}
// append it to the gameState string buffer
clCut->gameState.stringOffsets[i] = clCut->gameState.dataCount;
Com_Memcpy(clCut->gameState.stringData + clCut->gameState.dataCount, s, len + 1);
clCut->gameState.dataCount += len + 1;
} else if (cmd == svc_baseline) {
newnum = MSG_ReadBits(msg, GENTITYNUM_BITS);
if (newnum < 0 || newnum >= MAX_GENTITIES) {
Com_Printf("Baseline number out of range: %i", newnum);
return qfalse;
}
Com_Memset(&nullstate, 0, sizeof(nullstate));
es = &clCut->entityBaselines[newnum];
MSG_ReadDeltaEntity(msg, &nullstate, es, newnum);
} else {
Com_Printf("demoCutParseGameState: bad command byte");
return qfalse;
}
}
clcCut->clientNum = MSG_ReadLong(msg);
clcCut->checksumFeed = MSG_ReadLong(msg);
// RMG stuff
demoCutParseRMG(msg, clcCut, clCut);
return qtrue;
}
示例8: demoCutParsePacketEntities
void demoCutParsePacketEntities(msg_t *msg, clSnapshot_t *oldSnap, clSnapshot_t *newSnap, clientActive_t *clCut) {
/* The beast that is entity parsing */
int newnum;
entityState_t *oldstate, *newstate;
int oldindex = 0;
int oldnum;
newSnap->parseEntitiesNum = clCut->parseEntitiesNum;
newSnap->numEntities = 0;
newnum = MSG_ReadBits(msg, GENTITYNUM_BITS);
while (1) {
// read the entity index number
if (oldSnap && oldindex < oldSnap->numEntities) {
oldstate = &clCut->parseEntities[(oldSnap->parseEntitiesNum + oldindex) & (MAX_PARSE_ENTITIES-1)];
oldnum = oldstate->number;
} else {
oldstate = 0;
oldnum = 99999;
}
newstate = &clCut->parseEntities[clCut->parseEntitiesNum];
if (!oldstate && (newnum == (MAX_GENTITIES-1))) {
break;
} else if (oldnum < newnum) {
*newstate = *oldstate;
oldindex++;
} else if (oldnum == newnum) {
oldindex++;
MSG_ReadDeltaEntity(msg, oldstate, newstate, newnum);
newnum = MSG_ReadBits(msg, GENTITYNUM_BITS);
} else if (oldnum > newnum) {
MSG_ReadDeltaEntity(msg, &clCut->entityBaselines[newnum], newstate, newnum);
newnum = MSG_ReadBits(msg, GENTITYNUM_BITS);
}
if (newstate->number == MAX_GENTITIES-1)
continue;
clCut->parseEntitiesNum++;
clCut->parseEntitiesNum &= (MAX_PARSE_ENTITIES-1);
newSnap->numEntities++;
}
}
示例9: MSG_ReadField
void MSG_ReadField (msg_t *msg, int *toF, const netField_t *field, int print)
{
int trunc;
if ( field->bits == -1)
{ // a -1 in the bits field means it's a float that's always between -1 and 1
int temp = MSG_ReadBits( msg, -16);
*(float *)toF = (float)temp / 32767;
}
else
if ( field->bits == 0 ) {
// float
if ( MSG_ReadBits( msg, 1 ) == 0 ) {
*(float *)toF = 0.0f;
} else {
if ( MSG_ReadBits( msg, 1 ) == 0 ) {
// integral float
trunc = MSG_ReadBits( msg, FLOAT_INT_BITS );
// bias to allow equal parts positive and negative
trunc -= FLOAT_INT_BIAS;
*(float *)toF = trunc;
if ( print ) {
Com_Printf( "%s:%i ", field->name, trunc );
}
} else {
// full floating point value
*toF = MSG_ReadBits( msg, 32 );
if ( print ) {
Com_Printf( "%s:%f ", field->name, *(float *)toF );
}
}
}
} else {
if ( MSG_ReadBits( msg, 1 ) == 0 ) {
*toF = 0;
} else {
// integer
*toF = MSG_ReadBits( msg, field->bits );
if ( print ) {
Com_Printf( "%s:%i ", field->name, *toF );
}
}
}
}
示例10: MSG_ReadBits
/*
================
rvDebuggerServer::HandleAddBreakpoint
Handle the DBMSG_ADDBREAKPOINT message being sent by the debugger client. This
message is handled by adding a new breakpoint to the breakpoint list with the
data supplied in the message.
================
*/
void rvDebuggerServer::HandleAddBreakpoint ( msg_t* msg )
{
bool onceOnly = false;
long lineNumber;
long id;
char filename[MAX_PATH];
// Read the breakpoint info
onceOnly = MSG_ReadBits ( msg, 1 ) ? true : false;
lineNumber = MSG_ReadLong ( msg );
id = MSG_ReadLong ( msg );
MSG_ReadString ( msg, filename, MAX_PATH );
// Since breakpoints are used by both threads we need to
// protect them with a crit section
EnterCriticalSection ( &mCriticalSection );
mBreakpoints.Append ( new rvDebuggerBreakpoint ( filename, lineNumber, id ) );
LeaveCriticalSection ( &mCriticalSection );
}
示例11: CL_ParseGamestate
/*
==================
CL_ParseGamestate
==================
*/
void CL_ParseGamestate( msg_t *msg ) {
int i;
entityState_t *es;
int newnum;
entityState_t nullstate;
int cmd;
char *s;
char oldGame[MAX_QPATH];
Con_Close();
clc.connectPacketCount = 0;
// wipe local client state
CL_ClearState();
// a gamestate always marks a server command sequence
clc.serverCommandSequence = MSG_ReadLong( msg );
// parse all the configstrings and baselines
cl.gameState.dataCount = 1; // leave a 0 at the beginning for uninitialized configstrings
while ( 1 ) {
cmd = MSG_ReadByte( msg );
if ( cmd == svc_EOF ) {
break;
}
if ( cmd == svc_configstring ) {
int len;
i = MSG_ReadShort( msg );
if ( i < 0 || i >= MAX_CONFIGSTRINGS ) {
Com_Error( ERR_DROP, "configstring > MAX_CONFIGSTRINGS" );
}
s = MSG_ReadBigString( msg );
len = strlen( s );
if ( len + 1 + cl.gameState.dataCount > MAX_GAMESTATE_CHARS ) {
Com_Error( ERR_DROP, "MAX_GAMESTATE_CHARS exceeded" );
}
// append it to the gameState string buffer
cl.gameState.stringOffsets[ i ] = cl.gameState.dataCount;
Com_Memcpy( cl.gameState.stringData + cl.gameState.dataCount, s, len + 1 );
cl.gameState.dataCount += len + 1;
} else if ( cmd == svc_baseline ) {
newnum = MSG_ReadBits( msg, GENTITYNUM_BITS );
if ( newnum < 0 || newnum >= MAX_GENTITIES ) {
Com_Error( ERR_DROP, "Baseline number out of range: %i", newnum );
}
Com_Memset (&nullstate, 0, sizeof(nullstate));
es = &cl.entityBaselines[ newnum ];
MSG_ReadDeltaEntity( msg, &nullstate, es, newnum );
} else {
Com_Error( ERR_DROP, "CL_ParseGamestate: bad command byte" );
}
}
clc.clientNum = MSG_ReadLong(msg);
// read the checksum feed
clc.checksumFeed = MSG_ReadLong( msg );
// save old gamedir
Cvar_VariableStringBuffer("fs_game", oldGame, sizeof(oldGame));
// parse useful values out of CS_SERVERINFO
CL_ParseServerInfo();
// parse serverId and other cvars
CL_SystemInfoChanged();
// stop recording now so the demo won't have an unnecessary level load at the end.
if(cl_autoRecordDemo->integer && clc.demorecording)
CL_StopRecord_f();
// reinitialize the filesystem if the game directory has changed
if(!cl_oldGameSet && (Cvar_Flags("fs_game") & CVAR_MODIFIED))
{
cl_oldGameSet = qtrue;
Q_strncpyz(cl_oldGame, oldGame, sizeof(cl_oldGame));
}
FS_ConditionalRestart(clc.checksumFeed, qfalse);
// This used to call CL_StartHunkUsers, but now we enter the download state before loading the
// cgame
CL_InitDownloads();
// make sure the game starts
Cvar_Set( "cl_paused", "0" );
}
示例12: FS_FOpenFileRead
static demoPlay_t *demoPlayOpen( const char* fileName ) {
demoPlay_t *play;
fileHandle_t fileHandle;
int fileSize, filePos;
int i;
msg_t msg;
fileSize = FS_FOpenFileRead( fileName, &fileHandle, qtrue );
if (fileHandle<=0) {
Com_Printf("Failed to open demo file %s \n", fileName );
return 0;
}
filePos = strlen( demoHeader );
i = FS_Read( &demoBuffer, filePos, fileHandle );
if ( i != filePos || Q_strncmp( demoBuffer, demoHeader, filePos )) {
Com_Printf("demo file %s is wrong version\n", fileName );
FS_FCloseFile( fileHandle );
return 0;
}
play = Z_Malloc( sizeof( demoPlay_t ));
Q_strncpyz( play->fileName, fileName, sizeof( play->fileName ));
play->fileSize = fileSize;
play->frame = &play->storageFrame[0];
play->nextFrame = &play->storageFrame[1];
for (i=0;i<DEMO_PLAY_CMDS;i++)
play->commandStart[i] = i;
play->commandFree = DEMO_PLAY_CMDS;
for ( ; filePos<fileSize; ) {
int blockSize, isFull, serverTime;
FS_Read( &blockSize, 4, fileHandle );
blockSize = LittleLong( blockSize );
if (blockSize > sizeof(demoBuffer)) {
Com_Printf( "Block too large to be read in.\n");
goto errorreturn;
}
if ( blockSize + filePos > fileSize) {
Com_Printf( "Block would read past the end of the file.\n");
goto errorreturn;
}
FS_Read( demoBuffer, blockSize, fileHandle );
MSG_Init( &msg, demoBuffer, sizeof(demoBuffer) );
MSG_BeginReading( &msg );
msg.cursize = blockSize;
isFull = MSG_ReadBits( &msg, 1 );
serverTime = MSG_ReadLong( &msg );
if (!play->startTime)
play->startTime = serverTime;
if (isFull) {
if (play->fileIndexCount < DEMO_MAX_INDEX) {
play->fileIndex[play->fileIndexCount].pos = filePos;
play->fileIndex[play->fileIndexCount].frame = play->totalFrames;
play->fileIndex[play->fileIndexCount].time = serverTime;
play->fileIndexCount++;
}
}
play->endTime = serverTime;
filePos += 4 + blockSize;
play->totalFrames++;
}
play->fileHandle = fileHandle;
demoPlaySetIndex( play, 0 );
play->clientNum = -1;
for( i=0;i<MAX_CLIENTS;i++)
if (play->frame->clientData[i]) {
play->clientNum = i;
break;
}
return play;
errorreturn:
Z_Free( play );
FS_FCloseFile( fileHandle );
return 0;
}
示例13: CL_ParseDemo
//.........这里部分代码省略.........
// other commands
switch (cmd)
{
default:
Com_FuncDrop("Illegible server message %d", cmd);
return;
case svc_nop:
break;
case svc_serverCommand:
MSG_ReadLong(msg);
MSG_ReadString(msg);
break;
case svc_gamestate:
clc.serverCommandSequence = MSG_ReadLong(msg);
cl.gameState.dataCount = 1;
while (qtrue)
{
int cmd2 = MSG_ReadByte(msg);
if (cmd2 == svc_EOF)
{
break;
}
if (cmd2 == svc_configstring)
{
MSG_ReadShort(msg);
MSG_ReadBigString(msg);
}
else if (cmd2 == svc_baseline)
{
entityState_t s1, s2;
memset(&s1, 0, sizeof(s1));
memset(&s2, 0, sizeof(s2));
MSG_ReadBits(msg, GENTITYNUM_BITS);
MSG_ReadDeltaEntity(msg, &s1, &s2, 0);
}
else
{
Com_FuncDrop("bad command byte");
return;
}
}
MSG_ReadLong(msg);
MSG_ReadLong(msg);
break;
case svc_snapshot:
CL_ParseDemoSnapShotSimple(msg);
break;
case svc_download:
MSG_ReadShort(msg);
break;
}
}
if (!cl.snap.valid)
{
Com_FuncPrinf("!cl.snap.valid\n");
continue;
}
if (cl.snap.serverTime < cl.oldFrameServerTime)
{
// ignore snapshots that don't have entities
if (cl.snap.snapFlags & SNAPFLAG_NOT_ACTIVE)
{
示例14: demoFrameUnpack
static void demoFrameUnpack( msg_t *msg, demoFrame_t *oldFrame, demoFrame_t *newFrame ) {
int last;
qboolean isDelta = MSG_ReadBits( msg, 1 ) ? qfalse : qtrue;
if (!isDelta)
oldFrame = 0;
newFrame->serverTime = MSG_ReadLong( msg );
/* Read config strings */
newFrame->string.data[0] = 0;
newFrame->string.used = 1;
last = 0;
/* Extract config strings */
while ( 1 ) {
int i, num = MSG_ReadShort( msg );
if (!isDelta ) {
for (i = last;i<num;i++)
newFrame->string.offsets[i] = 0;
} else {
for (i = last;i<num;i++)
demoFrameAddString( &newFrame->string, i, oldFrame->string.data + oldFrame->string.offsets[i] );
}
if (num < MAX_CONFIGSTRINGS) {
demoFrameAddString( &newFrame->string, num, MSG_ReadBigString( msg ) );
} else {
break;
}
last = num + 1;
}
/* Extract player states */
Com_Memset( newFrame->clientData, 0, sizeof( newFrame->clientData ));
last = MSG_ReadByte( msg );
while (last < MAX_CLIENTS) {
playerState_t *oldPlayer, *newPlayer;
newFrame->clientData[last] = 1;
oldPlayer = isDelta && oldFrame->clientData[last] ? &oldFrame->clients[last] : &demoNullPlayerState;
newPlayer = &newFrame->clients[last];
MSG_ReadDeltaPlayerstate( msg, oldPlayer, newPlayer );
last = MSG_ReadByte( msg );
}
/* Extract entity states */
last = 0;
while ( 1 ) {
int i, num = MSG_ReadBits( msg, GENTITYNUM_BITS );
entityState_t *oldEntity, *newEntity;
if ( isDelta ) {
for (i = last;i<num;i++)
if (oldFrame->entities[i].number == i)
newFrame->entities[i] = oldFrame->entities[i];
else
newFrame->entities[i].number = MAX_GENTITIES - 1;
} else {
for (i = last;i<num;i++)
newFrame->entities[i].number = MAX_GENTITIES - 1;
}
if (num < MAX_GENTITIES - 1) {
if (isDelta) {
oldEntity = &oldFrame->entities[num];
if (oldEntity->number != num)
oldEntity = &demoNullEntityState;
} else {
oldEntity = &demoNullEntityState;
}
newEntity = &newFrame->entities[i];
MSG_ReadDeltaEntity( msg, oldEntity, newEntity, num );
} else
break;
last = num + 1;
}
/* Read the area mask */
newFrame->areaUsed = MSG_ReadByte( msg );
MSG_ReadData( msg, newFrame->areamask, newFrame->areaUsed );
/* Read the command string data */
newFrame->commandUsed = MSG_ReadLong( msg );
MSG_ReadData( msg, newFrame->commandData, newFrame->commandUsed );
}
示例15: MSG_ReadDelta
int MSG_ReadDelta( msg_t *msg, int oldV, int bits ) {
if ( MSG_ReadBits( msg, 1 ) ) {
return MSG_ReadBits( msg, bits );
}
return oldV;
}