engine: client: refactor variable declarations

This commit is contained in:
Alibek Omarov
2026-05-20 17:26:14 +05:00
committed by a1batross
parent d49178d5b6
commit e8845fc404
52 changed files with 987 additions and 1670 deletions

View File

@@ -60,33 +60,34 @@ CL_ParseSoundPacket
*/
static void CL_ParseSoundPacket( sizebuf_t *msg, qboolean restore )
{
vec3_t pos;
int chan, sound;
float volume, attn;
int flags, pitch, entnum, wordIndex = 0;
int wordIndex = 0;
sound_t handle = 0;
double samplePos = 0, forcedEnd = 0;
flags = MSG_ReadUBitLong( msg, MAX_SND_FLAGS_BITS );
sound = MSG_ReadUBitLong( msg, MAX_SOUND_BITS );
chan = MSG_ReadUBitLong( msg, MAX_SND_CHAN_BITS );
int flags = MSG_ReadUBitLong( msg, MAX_SND_FLAGS_BITS );
int sound = MSG_ReadUBitLong( msg, MAX_SOUND_BITS );
int chan = MSG_ReadUBitLong( msg, MAX_SND_CHAN_BITS );
float volume;
if( FBitSet( flags, SND_VOLUME ))
volume = (float)MSG_ReadByte( msg ) / 255.0f;
else volume = VOL_NORM;
float attn;
if( FBitSet( flags, SND_ATTENUATION ))
attn = (float)MSG_ReadByte( msg ) / 64.0f;
else attn = ATTN_NONE;
int pitch;
if( FBitSet( flags, SND_PITCH ))
pitch = MSG_ReadByte( msg );
else pitch = PITCH_NORM;
// entity reletive
entnum = MSG_ReadUBitLong( msg, MAX_ENTITY_BITS );
int entnum = MSG_ReadUBitLong( msg, MAX_ENTITY_BITS );
// positioned in space
vec3_t pos;
MSG_ReadVec3Coord( msg, pos );
if( FBitSet( flags, SND_SENTENCE ))
@@ -129,8 +130,6 @@ CL_ParseServerTime
*/
void CL_ParseServerTime( sizebuf_t *msg, connprotocol_t proto )
{
double dt;
cl.mtime[1] = cl.mtime[0];
cl.mtime[0] = MSG_ReadFloat( msg );
@@ -140,7 +139,7 @@ void CL_ParseServerTime( sizebuf_t *msg, connprotocol_t proto )
if( cl.maxclients == 1 )
cl.time = cl.mtime[0];
dt = cl.time - cl.mtime[0];
double dt = cl.time - cl.mtime[0];
if( fabs( dt ) > cl_clockreset.value ) // 0.1 by default
{
@@ -212,29 +211,26 @@ CL_ParseParticles
*/
static void CL_ParseParticles( sizebuf_t *msg, connprotocol_t proto )
{
vec3_t org, dir;
int i, count, color;
float life;
vec3_t org, dir;
MSG_ReadVec3Coord( msg, org );
for( i = 0; i < 3; i++ )
for( int i = 0; i < 3; i++ )
dir[i] = MSG_ReadChar( msg ) * 0.0625f;
count = MSG_ReadByte( msg );
color = MSG_ReadByte( msg );
int count = MSG_ReadByte( msg );
int color = MSG_ReadByte( msg );
if( count == 255 )
count = 1024;
float life;
if( proto == PROTO_GOLDSRC )
life = 0.0f;
else life = MSG_ReadByte( msg ) * 0.125f;
if( life != 0.0f && count == 1 )
{
particle_t *p;
p = R_AllocParticle( NULL );
particle_t *p = R_AllocParticle( NULL );
if( !p ) return;
p->die += life;
@@ -256,10 +252,8 @@ static client entity
*/
static void CL_ParseStaticEntity( sizebuf_t *msg )
{
int i;
const entity_state_t from = { 0 };
entity_state_t to;
cl_entity_t *ent;
if( !clgame.static_entities )
clgame.static_entities = Mem_Calloc( clgame.mempool, sizeof( cl_entity_t ) * MAX_STATIC_ENTITIES );
@@ -267,14 +261,14 @@ static void CL_ParseStaticEntity( sizebuf_t *msg )
MSG_ReadUBitLong( msg, MAX_ENTITY_BITS );
MSG_ReadDeltaEntity( msg, &from, &to, 0, DELTA_STATIC, cl.mtime[0] );
i = clgame.numStatics;
int i = clgame.numStatics;
if( i >= MAX_STATIC_ENTITIES )
{
Con_Printf( S_ERROR "MAX_STATIC_ENTITIES limit exceeded!\n" );
return;
}
ent = &clgame.static_entities[i];
cl_entity_t *ent = &clgame.static_entities[i];
clgame.numStatics++;
// all states are same
@@ -315,7 +309,7 @@ Set new weapon animation
*/
void GAME_EXPORT CL_WeaponAnim( int iAnim, int body )
{
cl_entity_t *view = &clgame.viewent;
cl_entity_t *view = &clgame.viewent;
cl.local.weaponstarttime = 0.0f;
cl.local.weaponsequence = iAnim;
@@ -339,20 +333,18 @@ CL_ParseStaticDecal
*/
void CL_ParseStaticDecal( sizebuf_t *msg )
{
vec3_t origin;
int decalIndex, entityIndex, modelIndex;
float scale;
int flags;
vec3_t origin;
MSG_ReadVec3Coord( msg, origin );
decalIndex = MSG_ReadWord( msg );
entityIndex = MSG_ReadShort( msg );
int decalIndex = MSG_ReadWord( msg );
int entityIndex = MSG_ReadShort( msg );
int modelIndex;
if( entityIndex > 0 )
modelIndex = MSG_ReadWord( msg );
else modelIndex = 0;
flags = MSG_ReadByte( msg );
scale = (float)MSG_ReadWord( msg ) / 4096.0f;
int flags = MSG_ReadByte( msg );
float scale = (float)MSG_ReadWord( msg ) / 4096.0f;
CL_FireCustomDecal( CL_DecalIndex( decalIndex ), entityIndex, modelIndex, origin, flags, scale );
}
@@ -381,11 +373,9 @@ CL_RequestMissingResources
*/
qboolean CL_RequestMissingResources( void )
{
resource_t *p;
if( !cls.dl.doneregistering && ( cls.dl.custom || cls.state == ca_validate ))
{
p = cl.resourcesneeded.pNext;
resource_t *p = cl.resourcesneeded.pNext;
if( p == &cl.resourcesneeded )
{
@@ -404,17 +394,16 @@ qboolean CL_RequestMissingResources( void )
void CL_BatchResourceRequest( qboolean initialize )
{
byte data[MAX_INIT_MSG];
resource_t *p, *n;
sizebuf_t msg;
qboolean done_downloading = true;
byte data[MAX_INIT_MSG];
sizebuf_t msg;
qboolean done_downloading = true;
MSG_Init( &msg, "Resource Batch", data, sizeof( data ));
// client resources is not precached by server
if( initialize ) CL_AddClientResources();
for( p = cl.resourcesneeded.pNext; p && p != &cl.resourcesneeded; p = n )
for( resource_t *p = cl.resourcesneeded.pNext, *n; p && p != &cl.resourcesneeded; p = n )
{
n = p->pNext;
@@ -491,10 +480,9 @@ void CL_BatchResourceRequest( qboolean initialize )
int CL_EstimateNeededResources( void )
{
resource_t *p;
int nTotalSize = 0;
int nTotalSize = 0;
for( p = cl.resourcesneeded.pNext; p != &cl.resourcesneeded; p = p->pNext )
for( resource_t *p = cl.resourcesneeded.pNext; p != &cl.resourcesneeded; p = p->pNext )
{
switch( p->type )
{
@@ -570,9 +558,7 @@ static void CL_StartResourceDownloading( const char *pszMessage, qboolean bCusto
static customization_t *CL_PlayerHasCustomization( int nPlayerNum, resourcetype_t type )
{
customization_t *pList;
for( pList = cl.players[nPlayerNum].customdata.pNext; pList; pList = pList->pNext )
for( customization_t *pList = cl.players[nPlayerNum].customdata.pNext; pList; pList = pList->pNext )
{
if( pList->resource.type == type )
return pList;
@@ -582,10 +568,8 @@ static customization_t *CL_PlayerHasCustomization( int nPlayerNum, resourcetype_
static void CL_RemoveCustomization( int nPlayerNum, customization_t *pRemove )
{
customization_t *pList;
customization_t *pNext;
for( pList = cl.players[nPlayerNum].customdata.pNext; pList; pList = pNext )
customization_t *pNext;
for( customization_t *pList = cl.players[nPlayerNum].customdata.pNext; pList; pList = pNext )
{
pNext = pList->pNext;
@@ -619,17 +603,11 @@ CL_ParseCustomization
*/
static void CL_ParseCustomization( sizebuf_t *msg )
{
customization_t *pExistingCustomization;
customization_t *pList;
qboolean bFound;
resource_t *pRes;
int i;
i = MSG_ReadByte( msg );
int i = MSG_ReadByte( msg );
if( i >= MAX_CLIENTS )
Host_Error( "Bogus player index during customization parsing.\n" );
pRes = Mem_Calloc( cls.mempool, sizeof( resource_t ));
resource_t *pRes = Mem_Calloc( cls.mempool, sizeof( resource_t ));
pRes->type = MSG_ReadByte( msg );
Q_strncpy( pRes->szFileName, MSG_ReadString( msg ), sizeof( pRes->szFileName ));
@@ -656,13 +634,13 @@ static void CL_ParseCustomization( sizebuf_t *msg )
return;
}
pExistingCustomization = CL_PlayerHasCustomization( i, pRes->type );
customization_t *pExistingCustomization = CL_PlayerHasCustomization( i, pRes->type );
if( pExistingCustomization )
CL_RemoveCustomization( i, pExistingCustomization );
bFound = false;
for( pList = cl.players[pRes->playernum].customdata.pNext; pList; pList = pList->pNext )
qboolean bFound = false;
for( customization_t *pList = cl.players[pRes->playernum].customdata.pNext; pList; pList = pList->pNext )
{
if( !memcmp( pList->resource.rgucMD5_hash, pRes->rgucMD5_hash, 16 ))
{
@@ -673,11 +651,11 @@ static void CL_ParseCustomization( sizebuf_t *msg )
if( HPAK_GetDataPointer( hpk_custom_file.string, pRes, NULL, NULL ))
{
qboolean bError = false;
qboolean bError = false;
if( !bFound )
{
pList = &cl.players[pRes->playernum].customdata;
customization_t *pList = &cl.players[pRes->playernum].customdata;
if( !COM_CreateCustomization( pList, pRes, pRes->playernum, FCUST_FROMHPAK, NULL, NULL ))
bError = true;
@@ -707,15 +685,14 @@ CL_ParseResourceRequest
*/
void CL_SendResourceList( const resource_t *list, int count )
{
byte buffer[MAX_INIT_MSG];
sizebuf_t sbuf;
int i;
byte buffer[MAX_INIT_MSG];
sizebuf_t sbuf;
MSG_Init( &sbuf, "ResourceBlock", buffer, sizeof( buffer ));
MSG_BeginClientCmd( &sbuf, clc_resourcelist );
MSG_WriteShort( &sbuf, count );
for( i = 0; i < count; i++ )
for( int i = 0; i < count; i++ )
{
MSG_WriteString( &sbuf, list[i].szFileName );
MSG_WriteByte( &sbuf, list[i].type );
@@ -733,10 +710,8 @@ void CL_SendResourceList( const resource_t *list, int count )
static void CL_ParseResourceRequest( sizebuf_t *msg )
{
int arg, nStartIndex;
arg = MSG_ReadLong( msg );
nStartIndex = MSG_ReadLong( msg );
int arg = MSG_ReadLong( msg );
int nStartIndex = MSG_ReadLong( msg );
if( cl.servercount != arg )
return;
@@ -756,16 +731,12 @@ loading custom decal for self
*/
static void CL_CreateCustomizationList( void )
{
resource_t *pResource;
player_info_t *pPlayer;
int i;
pPlayer = &cl.players[cl.playernum];
player_info_t *pPlayer = &cl.players[cl.playernum];
pPlayer->customdata.pNext = NULL;
for( i = 0; i < cl.num_resources; i++ )
for( int i = 0; i < cl.num_resources; i++ )
{
pResource = &cl.resourcelist[i];
resource_t *pResource = &cl.resourcelist[i];
if( !COM_CreateCustomization( &pPlayer->customdata, pResource, cl.playernum, 0, NULL, NULL ))
Con_Printf( "problem with client customization %s, ignoring...", pResource->szFileName );
@@ -1247,12 +1218,10 @@ CL_ParseLightStyle
*/
static void CL_ParseLightStyle( sizebuf_t *msg, connprotocol_t proto )
{
int style;
const char *s;
float f = cl.mtime[0];
float f = cl.mtime[0];
style = MSG_ReadByte( msg );
s = MSG_ReadString( msg );
int style = MSG_ReadByte( msg );
const char *s = MSG_ReadString( msg );
if( proto != PROTO_GOLDSRC && proto != PROTO_QUAKE )
f = MSG_ReadFloat( msg );
@@ -1280,10 +1249,7 @@ add the view angle yaw
*/
static void CL_ParseAddAngle( sizebuf_t *msg )
{
pred_viewangle_t *a;
float delta_yaw;
delta_yaw = MSG_ReadBitAngle( msg, 16 );
float delta_yaw = MSG_ReadBitAngle( msg, 16 );
#if 0
cl.viewangles[YAW] += delta_yaw;
return;
@@ -1293,7 +1259,7 @@ static void CL_ParseAddAngle( sizebuf_t *msg )
// select entry into circular buffer
cl.angle_position = (cl.angle_position + 1) & ANGLE_MASK;
a = &cl.predicted_angle[cl.angle_position];
pred_viewangle_t *a = &cl.predicted_angle[cl.angle_position];
// record update
a->starttime = cl.mtime[0];
@@ -1323,20 +1289,18 @@ reading decals, etc.
*/
static void CL_ParseRestore( sizebuf_t *msg )
{
string filename;
int i, mapCount;
char *pMapName;
string filename;
// mapname.HL2
Q_strncpy( filename, MSG_ReadString( msg ), sizeof( filename ));
mapCount = MSG_ReadByte( msg );
int mapCount = MSG_ReadByte( msg );
// g-cont. acutally in Xash3D this does nothing.
// decals already restored on a server, and correctly transferred through levels
// but i'm leave this message for backward compatibility
for( i = 0; i < mapCount; i++ )
for( int i = 0; i < mapCount; i++ )
{
pMapName = MSG_ReadString( msg );
char *pMapName = MSG_ReadString( msg );
Con_Printf( "Loading decals from %s\n", pMapName );
}
}
@@ -1350,10 +1314,9 @@ register new user message or update existing
*/
static void CL_RegisterUserMessage( sizebuf_t *msg, connprotocol_t proto )
{
char *pszName;
char szName[17];
int size;
int svc_num = MSG_ReadByte( msg );
int size;
if( proto == PROTO_GOLDSRC )
{
@@ -1368,6 +1331,7 @@ static void CL_RegisterUserMessage( sizebuf_t *msg, connprotocol_t proto )
size = -1;
}
char *pszName;
if( proto == PROTO_GOLDSRC )
{
MSG_ReadBytes( msg, szName, sizeof( szName ) - 1 );
@@ -1388,9 +1352,8 @@ collect userinfo from all players
*/
static void CL_UpdateUserinfo( sizebuf_t *msg, connprotocol_t proto )
{
int slot, id;
qboolean active;
player_info_t *player;
int slot, id;
qboolean active;
if( proto == PROTO_GOLDSRC )
{
@@ -1408,7 +1371,7 @@ static void CL_UpdateUserinfo( sizebuf_t *msg, connprotocol_t proto )
if( slot >= MAX_CLIENTS )
Host_Error( "%s: svc_updateuserinfo >= MAX_CLIENTS\n", __func__ );
player = &cl.players[slot];
player_info_t *player = &cl.players[slot];
if( active )
{
@@ -1449,9 +1412,7 @@ downloading and precache resource in-game
*/
void CL_ParseResource( sizebuf_t *msg )
{
resource_t *pResource;
pResource = Mem_Calloc( cls.mempool, sizeof( resource_t ));
resource_t *pResource = Mem_Calloc( cls.mempool, sizeof( resource_t ));
pResource->type = MSG_ReadUBitLong( msg, 4 );
Q_strncpy( pResource->szFileName, MSG_ReadString( msg ), sizeof( pResource->szFileName ));
@@ -1511,13 +1472,10 @@ void CL_UpdateUserPings( sizebuf_t *msg )
// because pings message always ends by null bit
while( 1 )
{
int slot;
player_info_t *player;
if( !MSG_ReadOneBit( msg ))
break; // end of message
slot = MSG_ReadUBitLong( msg, MAX_CLIENT_BITS );
int slot = MSG_ReadUBitLong( msg, MAX_CLIENT_BITS );
if( unlikely( slot >= MAX_CLIENTS ))
{
@@ -1525,7 +1483,7 @@ void CL_UpdateUserPings( sizebuf_t *msg )
return;
}
player = &cl.players[slot];
player_info_t *player = &cl.players[slot];
player->ping = MSG_ReadUBitLong( msg, 12 );
player->packet_loss = MSG_ReadUBitLong( msg, 7 );
}
@@ -1550,18 +1508,14 @@ static const char *CL_CheckTypeToString( int check_type )
static void CL_SendConsistencyInfo( sizebuf_t *msg, connprotocol_t proto )
{
qboolean user_changed_diskfile;
vec3_t mins, maxs;
string filename;
byte md5[16] = { 0 };
int pos;
byte md5[16] = { 0 };
if( !cl.need_force_consistency_response )
return;
cl.need_force_consistency_response = false;
MSG_BeginClientCmd( msg, clc_fileconsistency );
pos = MSG_GetNumBytesWritten( msg );
int pos = MSG_GetNumBytesWritten( msg );
if( proto == PROTO_GOLDSRC )
{
MSG_WriteShort( msg, 0 );
@@ -1573,9 +1527,11 @@ static void CL_SendConsistencyInfo( sizebuf_t *msg, connprotocol_t proto )
for( int i = 0; i < cl.num_consistency; i++ )
{
qboolean have_file = true;
qboolean user_changed_diskfile = false;
vec3_t mins, maxs;
string filename;
consistency_t *pc = &cl.consistency_list[i];
user_changed_diskfile = false;
MSG_WriteOneBit( msg, 1 );
MSG_WriteUBitLong( msg, pc->orig_index, MAX_MODEL_BITS );
@@ -1654,10 +1610,9 @@ static void CL_SendConsistencyInfo( sizebuf_t *msg, connprotocol_t proto )
if( proto == PROTO_GOLDSRC )
{
int len;
MSG_EndBitWriting( msg );
len = MSG_GetNumBytesWritten( msg ) - pos - 2;
int len = MSG_GetNumBytesWritten( msg ) - pos - 2;
*(short *)&msg->pData[pos] = len;
COM_Munge( &msg->pData[pos + 2], len, cl.servercount );
@@ -1673,11 +1628,10 @@ static void CL_StartDark( void )
{
if( v_dark.value )
{
screenfade_t *sf = &clgame.fade;
float fadetime = 5.0f;
client_textmessage_t *title;
screenfade_t *sf = &clgame.fade;
float fadetime = 5.0f;
title = CL_TextMessageGet( "GAMETITLE" );
client_textmessage_t *title = CL_TextMessageGet( "GAMETITLE" );
if( Host_IsQuakeCompatible( ))
fadetime = 1.0f;
@@ -1789,20 +1743,12 @@ void CL_RegisterResources( sizebuf_t *msg, connprotocol_t proto )
static void CL_ParseConsistencyInfo( sizebuf_t *msg, connprotocol_t proto )
{
int lastcheck;
int delta;
int i;
int isdelta;
resource_t *pResource;
resource_t *skip_crc_change;
int skip;
consistency_t *pc;
byte nullbuffer[32];
byte nullbuffer[32];
memset( nullbuffer, 0, 32 );
cl.need_force_consistency_response = MSG_ReadOneBit( msg );
pResource = cl.resourcesneeded.pNext;
resource_t *pResource = cl.resourcesneeded.pNext;
if( !cl.need_force_consistency_response )
return;
@@ -1816,19 +1762,20 @@ static void CL_ParseConsistencyInfo( sizebuf_t *msg, connprotocol_t proto )
if( cl_trace_consistency.value )
Con_Printf( "Server wants consistency of the following resources:\n" );
skip_crc_change = NULL;
lastcheck = 0;
resource_t *skip_crc_change = NULL;
int lastcheck = 0;
while( MSG_ReadOneBit( msg ))
{
isdelta = MSG_ReadOneBit( msg );
int isdelta = MSG_ReadOneBit( msg );
int delta;
if( isdelta ) delta = MSG_ReadUBitLong( msg, 5 ) + lastcheck;
else delta = MSG_ReadUBitLong( msg, proto == PROTO_GOLDSRC ? MAX_GOLDSRC_MODEL_BITS : MAX_MODEL_BITS );
skip = delta - lastcheck;
int skip = delta - lastcheck;
for( i = 0; i < skip; i++ )
for( int i = 0; i < skip; i++ )
{
if( pResource != skip_crc_change && Q_strstr( pResource->szFileName, "models/" ))
Mod_NeedCRC( pResource->szFileName, false );
@@ -1844,7 +1791,7 @@ static void CL_ParseConsistencyInfo( sizebuf_t *msg, connprotocol_t proto )
if( cl.num_consistency >= MAX_MODELS )
Host_Error( "%s: MAX_MODELS limit exceeded (%d)\n", __func__, MAX_MODELS );
pc = &cl.consistency_list[cl.num_consistency];
consistency_t *pc = &cl.consistency_list[cl.num_consistency];
cl.num_consistency++;
memset( pc, 0, sizeof( *pc ));
@@ -1876,14 +1823,11 @@ CL_ParseResourceList
*/
void CL_ParseResourceList( sizebuf_t *msg, connprotocol_t proto )
{
resource_t *pResource;
int i, total;
int total = MSG_ReadUBitLong( msg, proto == PROTO_GOLDSRC ? MAX_GOLDSRC_RESOURCE_BITS : MAX_RESOURCE_BITS );
total = MSG_ReadUBitLong( msg, proto == PROTO_GOLDSRC ? MAX_GOLDSRC_RESOURCE_BITS : MAX_RESOURCE_BITS );
for( i = 0; i < total; i++ )
for( int i = 0; i < total; i++ )
{
pResource = Mem_Calloc( cls.mempool, sizeof( resource_t ));
resource_t *pResource = Mem_Calloc( cls.mempool, sizeof( resource_t ));
pResource->type = MSG_ReadUBitLong( msg, 4 );
Q_strncpy( pResource->szFileName, MSG_ReadString( msg ), sizeof( pResource->szFileName ));
@@ -2080,14 +2024,12 @@ Set screen fade
*/
static void CL_ParseScreenFade( sizebuf_t *msg )
{
float duration, holdTime;
screenfade_t *sf = &clgame.fade;
float flScale;
screenfade_t *sf = &clgame.fade;
duration = (float)MSG_ReadWord( msg );
holdTime = (float)MSG_ReadWord( msg );
float duration = (float)MSG_ReadWord( msg );
float holdTime = (float)MSG_ReadWord( msg );
sf->fadeFlags = MSG_ReadShort( msg );
flScale = FBitSet( sf->fadeFlags, FFADE_LONGFADE ) ? (1.0f / 256.0f) : (1.0f / 4096.0f);
float flScale = FBitSet( sf->fadeFlags, FFADE_LONGFADE ) ? (1.0f / 256.0f) : (1.0f / 4096.0f);
sf->fader = MSG_ReadByte( msg );
sf->fadeg = MSG_ReadByte( msg );
@@ -2196,9 +2138,6 @@ Exec map/class specific configs
*/
static void CL_ParseExec( sizebuf_t *msg )
{
qboolean is_class;
int class_idx;
string mapname;
const char *class_cfgs[] = {
"",
"exec scout.cfg\n",
@@ -2214,17 +2153,18 @@ static void CL_ParseExec( sizebuf_t *msg )
"exec civilian.cfg\n"
};
is_class = MSG_ReadByte( msg );
qboolean is_class = MSG_ReadByte( msg );
if( is_class )
{
class_idx = MSG_ReadByte( msg );
int class_idx = MSG_ReadByte( msg );
if( class_idx >= 0 && class_idx <= 11 && !Q_stricmp( GI->gamefolder, "tfc" ) )
Cbuf_AddText( class_cfgs[class_idx] );
}
else if( !Q_stricmp( GI->gamefolder, "tfc" ) )
{
string mapname;
Cbuf_AddText( "exec mapdefault.cfg\n" );
COM_FileBase( clgame.mapname, mapname, sizeof( mapname ));
@@ -2378,17 +2318,15 @@ show display finale or cutscene message
*/
static void CL_ParseFinaleCutscene( sizebuf_t *msg, int level )
{
static int msgindex = 0;
client_textmessage_t *text;
int channel;
static int msgindex = 0;
cl.intermission = level;
channel = msgindex;
int channel = msgindex;
msgindex = (msgindex + 1) & (MAX_TEXTCHANNELS - 1);
// grab message channel
text = &cl_textmessage[channel];
client_textmessage_t *text = &cl_textmessage[channel];
// NOTE: svc_finale and svc_cutscene has a
// predefined settings like Quake-style
@@ -2600,9 +2538,9 @@ dispatch messages
*/
void CL_ParseServerMessage( sizebuf_t *msg )
{
size_t bufStart, playerbytes;
int cmd;
int old_background;
size_t bufStart, playerbytes;
int cmd;
int old_background;
// parse the message
while( 1 )

View File

@@ -285,19 +285,17 @@ static void CL_CopyPacketEntity( frame_t *frame, int num, const entity_state_t *
static int CL_ParsePacketEntitiesGS( sizebuf_t *msg, qboolean delta )
{
frame_t *frame, *oldframe;
int oldindex, oldnum, numbase = 0;
entity_state_t *oldent;
int count;
frame_t *oldframe;
int numbase = 0;
int playerbytes = 0;
// save first uncompressed packet as timestamp
if( cls.changelevel && !delta && cls.demorecording )
CL_WriteDemoJumpTime();
count = MSG_ReadWord( msg );
int count = MSG_ReadWord( msg );
frame = &cl.frames[cl.parsecountmod];
frame_t *frame = &cl.frames[cl.parsecountmod];
memset( frame->flags, 0, sizeof( frame->flags ));
frame->first_entity = cls.next_client_entities;
frame->num_entities = 0;
@@ -326,9 +324,9 @@ static int CL_ParsePacketEntitiesGS( sizebuf_t *msg, qboolean delta )
MSG_StartBitWriting( msg );
oldent = NULL;
oldindex = 0;
oldnum = CL_UpdateOldEntNum( oldindex, oldframe, &oldent );
entity_state_t *oldent = NULL;
int oldindex = 0;
int oldnum = CL_UpdateOldEntNum( oldindex, oldframe, &oldent );
// read it all but ignore it
while( 1 )
@@ -415,10 +413,9 @@ static int CL_ParsePacketEntitiesGS( sizebuf_t *msg, qboolean delta )
static float MSG_ReadGSBitCoord( sizebuf_t *sb )
{
float value = 0;
int ival, fval;
ival = MSG_ReadOneBit( sb );
fval = MSG_ReadOneBit( sb );
int ival = MSG_ReadOneBit( sb );
int fval = MSG_ReadOneBit( sb );
if( ival || fval )
{
@@ -439,13 +436,11 @@ static float MSG_ReadGSBitCoord( sizebuf_t *sb )
static void MSG_ReadGSBitVec3Coord( sizebuf_t *sb, vec3_t fa )
{
qboolean x, y, z;
VectorClear( fa );
x = MSG_ReadOneBit( sb );
y = MSG_ReadOneBit( sb );
z = MSG_ReadOneBit( sb );
qboolean x = MSG_ReadOneBit( sb );
qboolean y = MSG_ReadOneBit( sb );
qboolean z = MSG_ReadOneBit( sb );
if( x )
fa[0] = MSG_ReadGSBitCoord( sb );
if( y )
@@ -456,31 +451,32 @@ static void MSG_ReadGSBitVec3Coord( sizebuf_t *sb, vec3_t fa )
static void CL_ParseSoundPacketGS( sizebuf_t *msg )
{
vec3_t pos;
int chan, sound;
float volume, attn;
int flags, pitch, entnum;
sound_t handle = 0;
MSG_StartBitWriting( msg );
flags = MSG_ReadUBitLong( msg, 9 );
int flags = MSG_ReadUBitLong( msg, 9 );
float volume;
if( FBitSet( flags, SND_VOLUME ))
volume = (float)MSG_ReadByte( msg ) / 255.0f;
else volume = VOL_NORM;
float attn;
if( FBitSet( flags, SND_ATTENUATION ))
attn = (float)MSG_ReadByte( msg ) / 64.0f;
else attn = ATTN_NONE;
chan = MSG_ReadUBitLong( msg, 3 );
entnum = MSG_ReadUBitLong( msg, MAX_GOLDSRC_ENTITY_BITS );
int chan = MSG_ReadUBitLong( msg, 3 );
int entnum = MSG_ReadUBitLong( msg, MAX_GOLDSRC_ENTITY_BITS );
int sound;
if( FBitSet( flags, SND_GOLDSRC_LARGE_INDEX ))
sound = MSG_ReadWord( msg );
else sound = MSG_ReadByte( msg );
vec3_t pos;
MSG_ReadGSBitVec3Coord( msg, pos );
int pitch;
if( FBitSet( flags, SND_PITCH ))
pitch = MSG_ReadByte( msg );
else pitch = PITCH_NORM;
@@ -514,17 +510,15 @@ static void CL_ParseSoundPacketGS( sizebuf_t *msg )
static void CL_ParseSpawnStaticSound( sizebuf_t *msg )
{
vec3_t pos;
int sound, entnum, pitch, flags;
float volume, attn;
sound_t handle = 0;
MSG_ReadVec3Coord( msg, pos );
sound = MSG_ReadShort( msg );
volume = MSG_ReadByte( msg ) * ( 1.0f / 255.0f );
attn = MSG_ReadByte( msg ) * ( 1.0f / 64.0f );
entnum = MSG_ReadShort( msg );
pitch = MSG_ReadByte( msg );
flags = MSG_ReadByte( msg );
int sound = MSG_ReadShort( msg );
float volume = MSG_ReadByte( msg ) * ( 1.0f / 255.0f );
float attn = MSG_ReadByte( msg ) * ( 1.0f / 64.0f );
int entnum = MSG_ReadShort( msg );
int pitch = MSG_ReadByte( msg );
int flags = MSG_ReadByte( msg );
if( FBitSet( flags, SND_SENTENCE ))
{

View File

@@ -80,14 +80,13 @@ we don't want interpolate this
*/
static qboolean CL_QuakeEntityTeleported( cl_entity_t *ent, entity_state_t *newstate )
{
float len, maxlen;
vec3_t delta;
vec3_t delta;
VectorSubtract( newstate->origin, ent->prevstate.origin, delta );
// compute potential max movement in units per frame and compare with entity movement
maxlen = ( clgame.movevars.maxvelocity * ( 1.0f / GAME_FPS ));
len = VectorLength( delta );
float maxlen = ( clgame.movevars.maxvelocity * ( 1.0f / GAME_FPS ));
float len = VectorLength( delta );
return (len > maxlen);
}
@@ -139,33 +138,30 @@ CL_ParseQuakeSound
*/
static void CL_ParseQuakeSound( sizebuf_t *msg )
{
int channel, sound;
int flags, entnum;
float volume, attn;
sound_t handle;
vec3_t pos;
flags = MSG_ReadByte( msg );
int flags = MSG_ReadByte( msg );
float volume;
if( FBitSet( flags, SND_VOLUME ))
volume = (float)MSG_ReadByte( msg ) / 255.0f;
else volume = VOL_NORM;
float attn;
if( FBitSet( flags, SND_ATTENUATION ))
attn = (float)MSG_ReadByte( msg ) / 64.0f;
else attn = ATTN_NONE;
channel = MSG_ReadWord( msg );
sound = MSG_ReadByte( msg ); // Quake1 have max 255 precached sounds. erm
int channel = MSG_ReadWord( msg );
int sound = MSG_ReadByte( msg ); // Quake1 have max 255 precached sounds. erm
// positioned in space
vec3_t pos;
MSG_ReadVec3Coord( msg, pos );
entnum = channel >> 3; // entity reletive
int entnum = channel >> 3; // entity reletive
channel &= 7;
// see precached sound
handle = cl.sound_index[sound];
sound_t handle = cl.sound_index[sound];
if( !cl.audio_prepped )
return; // too early
@@ -181,11 +177,6 @@ CL_ParseQuakeServerInfo
*/
static void CL_ParseQuakeServerInfo( sizebuf_t *msg )
{
resource_t *pResource;
const char *pResName;
int gametype;
int i;
Con_Reportf( "Serverdata packet received.\n" );
cls.timestart = Platform_DoubleTime();
@@ -198,7 +189,7 @@ static void CL_ParseQuakeServerInfo( sizebuf_t *msg )
cls.state = ca_connected;
// parse protocol version number
i = MSG_ReadLong( msg );
int i = MSG_ReadLong( msg );
if( i != PROTOCOL_VERSION_QUAKE )
{
@@ -208,7 +199,7 @@ static void CL_ParseQuakeServerInfo( sizebuf_t *msg )
}
cl.maxclients = MSG_ReadByte( msg );
gametype = MSG_ReadByte( msg );
int gametype = MSG_ReadByte( msg );
clgame.maxEntities = GI->max_edicts;
clgame.maxEntities = bound( 600, clgame.maxEntities, MAX_EDICTS );
clgame.maxModels = MAX_MODELS;
@@ -264,12 +255,12 @@ static void CL_ParseQuakeServerInfo( sizebuf_t *msg )
// Quake just have a large packet of initialization data
for( i = 1; i < MAX_MODELS; i++ )
{
pResName = MSG_ReadString( msg );
const char *pResName = MSG_ReadString( msg );
if( COM_StringEmptyOrNULL( pResName ))
break; // end of list
pResource = Mem_Calloc( cls.mempool, sizeof( resource_t ));
resource_t *pResource = Mem_Calloc( cls.mempool, sizeof( resource_t ));
pResource->type = t_model;
Q_strncpy( pResource->szFileName, pResName, sizeof( pResource->szFileName ));
@@ -282,12 +273,12 @@ static void CL_ParseQuakeServerInfo( sizebuf_t *msg )
for( i = 1; i < MAX_SOUNDS; i++ )
{
pResName = MSG_ReadString( msg );
const char *pResName = MSG_ReadString( msg );
if( COM_StringEmptyOrNULL( pResName ))
break; // end of list
pResource = Mem_Calloc( cls.mempool, sizeof( resource_t ));
resource_t *pResource = Mem_Calloc( cls.mempool, sizeof( resource_t ));
pResource->type = t_sound;
Q_strncpy( pResource->szFileName, pResName, sizeof( pResource->szFileName ));
@@ -340,15 +331,12 @@ CL_ParseQuakeClientData
*/
static void CL_ParseQuakeClientData( sizebuf_t *msg )
{
int i, bits = MSG_ReadWord( msg );
frame_t *frame;
int bits = MSG_ReadWord( msg );
// this is the frame update that this message corresponds to
i = cls.netchan.incoming_sequence;
cl.parsecount = i; // ack'd incoming messages.
cl.parsecount = cls.netchan.incoming_sequence; // ack'd incoming messages.
cl.parsecountmod = cl.parsecount & CL_UPDATE_MASK; // index into window.
frame = &cl.frames[cl.parsecountmod]; // frame at index.
frame_t *frame = &cl.frames[cl.parsecountmod]; // frame at index.
frame->time = cl.mtime[0]; // mark network received time
frame->receivedtime = host.realtime; // time now that we are parsing.
memset( &frame->graphdata, 0, sizeof( netbandwidthgraph_t ));
@@ -365,7 +353,7 @@ static void CL_ParseQuakeClientData( sizebuf_t *msg )
cl.local.idealpitch = MSG_ReadChar( msg );
else cl.local.idealpitch = 0;
for( i = 0; i < 3; i++ )
for( int i = 0; i < 3; i++ )
{
if( FBitSet( bits, SU_PUNCH1 << i ))
frame->clientdata.punchangle[i] = (float)MSG_ReadChar( msg );
@@ -568,15 +556,14 @@ CL_ParseQuakeParticles
*/
static void CL_ParseQuakeParticle( sizebuf_t *msg )
{
int count, color;
vec3_t org, dir;
vec3_t org, dir;
MSG_ReadVec3Coord( msg, org );
dir[0] = MSG_ReadChar( msg ) * 0.0625f;
dir[1] = MSG_ReadChar( msg ) * 0.0625f;
dir[2] = MSG_ReadChar( msg ) * 0.0625f;
count = MSG_ReadByte( msg );
color = MSG_ReadByte( msg );
int count = MSG_ReadByte( msg );
int color = MSG_ReadByte( msg );
if( count == 255 ) count = 1024;
R_RunParticleEffect( org, dir, color, count );
@@ -590,14 +577,12 @@ CL_ParseQuakeStaticSound
*/
static void CL_ParseQuakeStaticSound( sizebuf_t *msg )
{
int sound_num;
float vol, attn;
vec3_t org;
vec3_t org;
MSG_ReadVec3Coord( msg, org );
sound_num = MSG_ReadByte( msg );
vol = (float)MSG_ReadByte( msg ) / 255.0f;
attn = (float)MSG_ReadByte( msg ) / 64.0f;
int sound_num = MSG_ReadByte( msg );
float vol = (float)MSG_ReadByte( msg ) / 255.0f;
float attn = (float)MSG_ReadByte( msg ) / 64.0f;
S_StartSound( org, 0, CHAN_STATIC, cl.sound_index[sound_num], vol, attn, PITCH_NORM, 0 );
}
@@ -628,8 +613,6 @@ CL_ParseStaticEntity
static void CL_ParseQuakeStaticEntity( sizebuf_t *msg )
{
entity_state_t state = { 0 };
cl_entity_t *ent;
int i;
if( !clgame.static_entities )
clgame.static_entities = Mem_Calloc( clgame.mempool, sizeof( cl_entity_t ) * MAX_STATIC_ENTITIES );
@@ -645,14 +628,14 @@ static void CL_ParseQuakeStaticEntity( sizebuf_t *msg )
state.origin[2] = MSG_ReadCoord( msg );
state.angles[2] = MSG_ReadAngle( msg );
i = clgame.numStatics;
int i = clgame.numStatics;
if( i >= MAX_STATIC_ENTITIES )
{
Con_Printf( S_ERROR "%s: static entities limit exceeded!\n", __func__ );
return;
}
ent = &clgame.static_entities[i];
cl_entity_t *ent = &clgame.static_entities[i];
clgame.numStatics++;
ent->index = 0; // ???
@@ -692,16 +675,13 @@ CL_ParseQuakeBaseline
*/
static void CL_ParseQuakeBaseline( sizebuf_t *msg )
{
entity_state_t state;
cl_entity_t *ent;
int newnum;
newnum = MSG_ReadWord( msg ); // entnum
int newnum = MSG_ReadWord( msg ); // entnum
if( newnum >= clgame.maxEntities )
Host_Error( "%s: no free edicts\n", __func__ );
// parse baseline
entity_state_t state;
memset( &state, 0, sizeof( state ));
state.modelindex = MSG_ReadByte( msg );
state.frame = MSG_ReadByte( msg );
@@ -714,7 +694,7 @@ static void CL_ParseQuakeBaseline( sizebuf_t *msg )
state.origin[2] = MSG_ReadCoord( msg );
state.angles[2] = MSG_ReadAngle( msg );
ent = CL_EDICT_NUM( newnum );
cl_entity_t *ent = CL_EDICT_NUM( newnum );
ent->index = newnum;
ent->player = CL_IsPlayerIndex( newnum );
ent->prevstate = ent->baseline = state;