engine: use designated initializers where possible

This commit is contained in:
Alibek Omarov
2026-05-20 12:44:26 -04:00
committed by a1batross
parent c5a8160c32
commit 64be4251c8
15 changed files with 143 additions and 133 deletions

View File

@@ -487,8 +487,6 @@ CL_PlaybackEvent
void GAME_EXPORT CL_PlaybackEvent( int flags, const edict_t *pInvoker, word eventindex, float delay, float *origin,
float *angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2 )
{
event_args_t args;
if( FBitSet( flags, FEV_SERVER ))
return;
@@ -510,20 +508,20 @@ void GAME_EXPORT CL_PlaybackEvent( int flags, const edict_t *pInvoker, word even
ClearBits( flags, FEV_NOTHOST|FEV_HOSTONLY|FEV_GLOBAL );
if( delay < 0.0f ) delay = 0.0f; // fixup negative delays
memset( &args, 0, sizeof( args ));
VectorCopy( origin, args.origin );
VectorCopy( angles, args.angles );
VectorCopy( cl.simvel, args.velocity );
args.entindex = cl.playernum + 1;
args.ducking = ( cl.local.usehull == 1 );
args.fparam1 = fparam1;
args.fparam2 = fparam2;
args.iparam1 = iparam1;
args.iparam2 = iparam2;
args.bparam1 = bparam1;
args.bparam2 = bparam2;
event_args_t args =
{
.origin = Vec3( origin ),
.angles = Vec3( angles ),
.velocity = Vec3( cl.simvel ),
.entindex = cl.playernum + 1,
.ducking = ( cl.local.usehull == 1 ),
.fparam1 = fparam1,
.fparam2 = fparam2,
.iparam1 = iparam1,
.iparam2 = iparam2,
.bparam1 = bparam1,
.bparam2 = bparam2,
};
CL_QueueEvent( flags, eventindex, delay, &args );
}

View File

@@ -604,17 +604,16 @@ tell the client.dll about player origin, angles, fov, etc
*/
static void CL_UpdateClientData( void )
{
client_data_t cdat;
if( cls.state != ca_active )
return;
memset( &cdat, 0, sizeof( cdat ) );
VectorCopy( cl.viewangles, cdat.viewangles );
VectorCopy( clgame.entities[cl.viewentity].origin, cdat.origin );
cdat.iWeaponBits = cl.local.weapons;
cdat.fov = cl.local.scr_fov;
client_data_t cdat =
{
.viewangles = Vec3( cl.viewangles ),
.origin = Vec3( clgame.entities[cl.viewentity].origin ),
.iWeaponBits = cl.local.weapons,
.fov = cl.local.scr_fov,
};
if( clgame.dllFuncs.pfnUpdateClientData( &cdat, cl.time ))
{

View File

@@ -395,9 +395,7 @@ static void SteamBroker_UpdateConnecting( void )
FD_ZERO( &writefds );
FD_SET( broker.socket, &writefds );
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 0;
struct timeval tv = { 0 };
#if XASH_WIN32
int select_result = select( 0, NULL, &writefds, NULL, &tv );

View File

@@ -1185,10 +1185,12 @@ qboolean Voice_Init( const char *pszCodecName, int quality, qboolean preinit )
voice_audio_info_t Voice_GetAudioInfo( void )
{
voice_audio_info_t info;
voice_audio_info_t info =
{
.width = voice.width,
.samplerate = voice.samplerate,
.frame_size = voice.frame_size,
};
info.width = voice.width;
info.samplerate = voice.samplerate;
info.frame_size = voice.frame_size;
return info;
}

View File

@@ -399,7 +399,6 @@ static int HTTP_FileDecompress( httpfile_t *file )
GZFLG_FCOMMENT = BIT( 4 )
};
z_stream decompress_stream;
char name[MAX_SYSPATH];
g_fsapi.Seek( file->file, 0, SEEK_END );
@@ -475,11 +474,15 @@ static int HTTP_FileDecompress( httpfile_t *file )
HTTP_DownloadPath( name, sizeof( name ), file->path, false );
memset( &decompress_stream, 0, sizeof( decompress_stream ));
decompress_stream.total_in = decompress_stream.avail_in = compressed_len;
decompress_stream.next_in = data_in;
decompress_stream.total_out = decompress_stream.avail_out = decompressed_len;
decompress_stream.next_out = data_out;
z_stream decompress_stream =
{
.total_in = compressed_len,
.avail_in = compressed_len,
.next_in = data_in,
.total_out = decompressed_len,
.avail_out = decompressed_len,
.next_out = data_out,
};
g_fsapi.Seek( file->file, deflate_pos, SEEK_SET );
g_fsapi.Read( file->file, data_in, compressed_len );

View File

@@ -355,7 +355,6 @@ qboolean Image_SaveBMP( const char *name, rgbdata_t *pix )
rgba_t rgrgbPalette[256];
byte *pb;
int pixel_size;
bmp_t hdr;
if( FS_FileExists( name, false ) && !Image_CheckFlag( IL_ALLOW_OVERWRITE ) )
return false; // already existed
@@ -394,22 +393,20 @@ qboolean Image_SaveBMP( const char *name, rgbdata_t *pix )
dword cbPalBytes = ( pixel_size == 1 ) ? 256 * sizeof( rgba_t ) : 0;
// Bogus file header check
hdr.id[0] = 'B';
hdr.id[1] = 'M';
hdr.fileSize = sizeof( hdr ) + cbBmpBits + cbPalBytes;
hdr.reserved0 = 0;
hdr.bitmapDataOffset = sizeof( hdr ) + cbPalBytes;
hdr.bitmapHeaderSize = BI_SIZE;
hdr.width = biTrueWidth;
hdr.height = pix->height;
hdr.planes = 1;
hdr.bitsPerPixel = pixel_size * 8;
hdr.compression = BI_RGB;
hdr.bitmapDataSize = cbBmpBits;
hdr.hRes = 0;
hdr.vRes = 0;
hdr.colors = ( pixel_size == 1 ) ? 256 : 0;
hdr.importantColors = 0;
bmp_t hdr =
{
.id = { 'B', 'M' },
.fileSize = sizeof( hdr ) + cbBmpBits + cbPalBytes,
.bitmapDataOffset = sizeof( hdr ) + cbPalBytes,
.bitmapHeaderSize = BI_SIZE,
.width = biTrueWidth,
.height = pix->height,
.planes = 1,
.bitsPerPixel = pixel_size * 8,
.compression = BI_RGB,
.bitmapDataSize = cbBmpBits,
.colors = ( pixel_size == 1 ) ? 256 : 0,
};
le_struct_swap( bmp_swap, &hdr );
FS_Write( pfile, &hdr, sizeof( bmp_t ));

View File

@@ -734,7 +734,11 @@ qboolean Image_SaveWAD( const char *name, rgbdata_t *pix )
byte *mip1_data = NULL, *mip2_data = NULL, *mip3_data = NULL;
byte grad_palette[256 * 3];
file_t *f;
dwadinfo_t header;
dwadinfo_t header =
{
.ident = IDWAD3HEADER,
.numlumps = 1,
};
mip_t miptex;
long infotableofs;
dlumpinfo_t lump;
@@ -775,10 +779,6 @@ qboolean Image_SaveWAD( const char *name, rgbdata_t *pix )
if( !f )
goto cleanup;
memset( &header, 0, sizeof( header ));
header.ident = IDWAD3HEADER;
header.numlumps = 1;
le_struct_swap( dwadinfo_swap, &header );
FS_Write( f, &header, sizeof( header ));
le_struct_swap( mip_swap, &miptex );

View File

@@ -257,7 +257,6 @@ NET_GetHostByName
static qboolean NET_GetHostByName( const char *hostname, int family, struct sockaddr_storage *addr )
{
struct addrinfo *ai = NULL, *cur;
struct addrinfo hints;
qboolean ret = false;
#if XASH_NO_IPV6_RESOLVE
@@ -265,8 +264,10 @@ static qboolean NET_GetHostByName( const char *hostname, int family, struct sock
return false;
#endif
memset( &hints, 0, sizeof( hints ));
hints.ai_family = family;
struct addrinfo hints =
{
.ai_family = family,
};
if( !getaddrinfo( hostname, NULL, &hints, &ai ))
{

View File

@@ -303,11 +303,11 @@ loc0:
int PM_TestLineExt( playermove_t *pmove, physent_t *ents, int numents, const vec3_t start, const vec3_t end, int flags )
{
linetrace_t trace;
trace.contents = CONTENTS_EMPTY;
trace.fraction = 1.0f;
trace.surface = NULL;
linetrace_t trace =
{
.contents = CONTENTS_EMPTY,
.fraction = 1.0f,
};
for( int i = 0; i < numents; i++ )
{
@@ -346,10 +346,11 @@ int PM_TestLineExt( playermove_t *pmove, physent_t *ents, int numents, const vec
VectorSubtract( end, pe->origin, end_l );
}
linetrace_t trace_bbox;
trace_bbox.contents = CONTENTS_EMPTY;
trace_bbox.fraction = 1.0f;
trace_bbox.surface = NULL;
linetrace_t trace_bbox =
{
.contents = CONTENTS_EMPTY,
.fraction = 1.0f,
};
PM_TestLine_r( pe->model, &pe->model->nodes[hull->firstclipnode], 0.0f, 1.0f, start_l, end_l, &trace_bbox );

View File

@@ -100,13 +100,15 @@ qboolean SNDDMA_Init( void )
return false;
}
SDL_AudioSpec desired, obtained;
memset( &desired, 0, sizeof( desired ) );
desired.freq = SOUND_DMA_SPEED;
desired.format = AUDIO_S16SYS;
desired.samples = 1024;
desired.channels = 2;
desired.callback = SDL_SoundCallback;
SDL_AudioSpec obtained;
SDL_AudioSpec desired =
{
.freq = SOUND_DMA_SPEED,
.format = AUDIO_S16SYS,
.samples = 1024,
.channels = 2,
.callback = SDL_SoundCallback,
};
sdl_dev = SDL_OpenAudioDevice( NULL, 0, &desired, &obtained, 0 );

View File

@@ -74,7 +74,7 @@ Returns false if nothing is found.
*/
qboolean SNDDMA_Init( void )
{
SDL_AudioSpec desired, obtained;
SDL_AudioSpec obtained;
int samplecount;
// Modders often tend to use proprietary crappy solutions
@@ -117,12 +117,14 @@ qboolean SNDDMA_Init( void )
return false;
}
memset( &desired, 0, sizeof( desired ) );
desired.freq = SOUND_DMA_SPEED;
desired.format = AUDIO_S16SYS;
desired.samples = 1024;
desired.channels = 2;
desired.callback = SDL_SoundCallback;
SDL_AudioSpec desired =
{
.freq = SOUND_DMA_SPEED,
.format = AUDIO_S16SYS,
.samples = 1024,
.channels = 2,
.callback = SDL_SoundCallback,
};
sdl_dev = SDL_OpenAudioDevice( NULL, 0, &desired, &obtained, 0 );

View File

@@ -193,11 +193,12 @@ void SW_UnlockBuffer( void )
{
if( sw.renderer )
{
SDL_Rect src, dst;
src.x = src.y = 0;
src.w = sw.width;
src.h = sw.height;
dst = src;
SDL_Rect src =
{
.w = sw.width,
.h = sw.height,
};
SDL_Rect dst = src;
SDL_UnlockTexture(sw.tex);
SDL_SetTextureBlendMode(sw.tex, SDL_BLENDMODE_NONE);
@@ -213,11 +214,12 @@ void SW_UnlockBuffer( void )
// blit if blitting surface availiable
if( sw.surf )
{
SDL_Rect src, dst;
src.x = src.y = 0;
src.w = sw.width;
src.h = sw.height;
dst = src;
SDL_Rect src =
{
.w = sw.width,
.h = sw.height,
};
SDL_Rect dst = src;
SDL_UnlockSurface( sw.surf );
SDL_BlitSurface( sw.surf, &src, sw.win, &dst );
return;

View File

@@ -164,9 +164,6 @@ static void Wcon_SetInputText( const char *inputText )
static void Wcon_Clear_f( void )
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
SMALL_RECT scrollRect;
COORD scrollTarget;
CHAR_INFO fill;
if( host.type != HOST_DEDICATED )
return;
@@ -176,14 +173,20 @@ static void Wcon_Clear_f( void )
return;
}
scrollRect.Left = 0;
scrollRect.Top = 0;
scrollRect.Right = csbi.dwSize.X;
scrollRect.Bottom = csbi.dwSize.Y;
scrollTarget.X = 0;
scrollTarget.Y = (SHORT)(0 - csbi.dwSize.Y);
fill.Char.UnicodeChar = TEXT(' ');
fill.Attributes = csbi.wAttributes;
SMALL_RECT scrollRect =
{
.Right = csbi.dwSize.X,
.Bottom = csbi.dwSize.Y,
};
COORD scrollTarget =
{
.Y = (SHORT)(0 - csbi.dwSize.Y),
};
CHAR_INFO fill =
{
.Char.UnicodeChar = TEXT(' '),
.Attributes = csbi.wAttributes,
};
ScrollConsoleScreenBuffer( s_wcd.hOutput, &scrollRect, NULL, scrollTarget, &fill );
csbi.dwCursorPosition.X = 0;
@@ -379,11 +382,9 @@ static void Wcon_EventCharacter(char c)
static void Wcon_UpdateStatusLine( void )
{
COORD coord;
COORD coord = { 0 };
DWORD dwWritten;
coord.X = 0;
coord.Y = 0;
WORD wAttrib = g_color_table[5] | FOREGROUND_INTENSITY | BACKGROUND_INTENSITY;
FillConsoleOutputCharacter( s_wcd.hOutput, ' ', 80, coord, &dwWritten );

View File

@@ -2659,16 +2659,17 @@ static qboolean SV_EntFire_f( sv_client_t *cl )
{
string keyname;
string value;
KeyValueData pkvd;
if( Cmd_Argc() != 5 )
return false;
pkvd.szClassName = (char*)SV_GetString( ent->v.classname );
Q_strncpy( keyname, Cmd_Argv( 3 ), sizeof( keyname ));
Q_strncpy( value, Cmd_Argv( 4 ), sizeof( value ));
pkvd.szKeyName = keyname;
pkvd.szValue = value;
pkvd.fHandled = false;
KeyValueData pkvd =
{
.szClassName = (char*)SV_GetString( ent->v.classname ),
.szKeyName = keyname,
.szValue = value,
};
svgame.dllFuncs.pfnKeyValue( ent, &pkvd );
if( pkvd.fHandled )
@@ -2951,7 +2952,6 @@ static qboolean SV_EntCreate_f( sv_client_t *cl )
{
string keyname;
string value;
KeyValueData pkvd;
// allow split keyvalues to prespawn and postspawn
if( !Q_strcmp( Cmd_Argv( i ), "|" ) )
@@ -2959,10 +2959,12 @@ static qboolean SV_EntCreate_f( sv_client_t *cl )
Q_strncpy( keyname, Cmd_Argv( i++ ), sizeof( keyname ));
Q_strncpy( value, Cmd_Argv( i ), sizeof( value ));
pkvd.fHandled = false;
pkvd.szClassName = (char*)SV_GetString( ent->v.classname );
pkvd.szKeyName = keyname;
pkvd.szValue = value;
KeyValueData pkvd =
{
.szClassName = (char*)SV_GetString( ent->v.classname ),
.szKeyName = keyname,
.szValue = value,
};
svgame.dllFuncs.pfnKeyValue( ent, &pkvd );
if( pkvd.fHandled )
@@ -3018,14 +3020,15 @@ static qboolean SV_EntCreate_f( sv_client_t *cl )
{
string keyname;
string value;
KeyValueData pkvd;
Q_strncpy( keyname, Cmd_Argv( i++ ), sizeof( keyname ));
Q_strncpy( value, Cmd_Argv( i ), sizeof( value ));
pkvd.fHandled = false;
pkvd.szClassName = (char*)SV_GetString( ent->v.classname );
pkvd.szKeyName = keyname;
pkvd.szValue = value;
KeyValueData pkvd =
{
.szClassName = (char*)SV_GetString( ent->v.classname ),
.szKeyName = keyname,
.szValue = value,
};
svgame.dllFuncs.pfnKeyValue( ent, &pkvd );
if( pkvd.fHandled )

View File

@@ -3804,7 +3804,6 @@ pfnRunPlayerMove
static void GAME_EXPORT pfnRunPlayerMove( edict_t *pClient, const float *viewangles, float fmove, float smove, float upmove, word buttons, byte impulse, byte msec )
{
sv_client_t *cl, *oldcl;
usercmd_t cmd;
uint seed;
if(( cl = SV_ClientFromEdict( pClient, true )) == NULL )
@@ -3818,14 +3817,16 @@ static void GAME_EXPORT pfnRunPlayerMove( edict_t *pClient, const float *viewang
sv.current_client = SV_ClientFromEdict( pClient, true );
sv.current_client->timebase = (sv.time + sv.frametime) - ((double)msec / 1000.0);
memset( &cmd, 0, sizeof( cmd ));
VectorCopy( viewangles, cmd.viewangles );
cmd.forwardmove = fmove;
cmd.sidemove = smove;
cmd.upmove = upmove;
cmd.buttons = buttons;
cmd.impulse = impulse;
cmd.msec = msec;
usercmd_t cmd =
{
.viewangles = Vec3( viewangles ),
.forwardmove = fmove,
.sidemove = smove,
.upmove = upmove,
.buttons = buttons,
.impulse = impulse,
.msec = msec,
};
seed = COM_RandomLong( 0, 0x7fffffff ); // full range