Make all names in game interface const where possible

This commit is contained in:
Denis Pauk 2023-09-22 00:58:40 +03:00
parent 2274e86481
commit ff70128bb9
14 changed files with 87 additions and 121 deletions

View file

@ -912,7 +912,7 @@ SizeHUDString(char *string, int *w, int *h)
}
void
DrawHUDStringScaled(char *string, int x, int y, int centerwidth, int xor, float factor)
DrawHUDStringScaled(const char *string, int x, int y, int centerwidth, int xor, float factor)
{
int margin;
char line[1024];
@ -1060,7 +1060,7 @@ SCR_ExecuteLayoutString(char *s)
{
int x, y;
int value;
char *token;
const char *token;
int width;
int index;
clientinfo_t *ci;

View file

@ -83,7 +83,7 @@ Cbuf_Init(void)
* Adds command text at the end of the buffer
*/
void
Cbuf_AddText(char *text)
Cbuf_AddText(const char *text)
{
int l;
@ -532,7 +532,8 @@ Cmd_MacroExpandString(char *text)
char *scan;
static char expanded[MAX_STRING_CHARS];
char temporary[MAX_STRING_CHARS];
char *token, *start;
const char *token;
char *start;
inquote = false;
scan = text;

View file

@ -1980,7 +1980,7 @@ CM_LoadMap(char *name, qboolean clientload, unsigned *checksum)
}
cmodel_t *
CM_InlineModel(char *name)
CM_InlineModel(const char *name)
{
int num;

View file

@ -98,8 +98,8 @@ typedef struct sizebuf_s
void SZ_Init(sizebuf_t *buf, byte *data, int length);
void SZ_Clear(sizebuf_t *buf);
void *SZ_GetSpace(sizebuf_t *buf, int length);
void SZ_Write(sizebuf_t *buf, void *data, int length);
void SZ_Print(sizebuf_t *buf, char *data); /* strcats onto the sizebuf */
void SZ_Write(sizebuf_t *buf, const void *data, int length);
void SZ_Print(sizebuf_t *buf, const char *data); /* strcats onto the sizebuf */
/* ================================================================== */
@ -111,7 +111,7 @@ void MSG_WriteByte(sizebuf_t *sb, int c);
void MSG_WriteShort(sizebuf_t *sb, int c);
void MSG_WriteLong(sizebuf_t *sb, int c);
void MSG_WriteFloat(sizebuf_t *sb, float f);
void MSG_WriteString(sizebuf_t *sb, char *s);
void MSG_WriteString(sizebuf_t *sb, const char *s);
void MSG_WriteCoord(sizebuf_t *sb, float f);
void MSG_WritePos(sizebuf_t *sb, vec3_t pos);
void MSG_WriteAngle(sizebuf_t *sb, float f);
@ -337,7 +337,7 @@ void Cbuf_Init(void);
/* allocates an initial text buffer that will grow as needed */
void Cbuf_AddText(char *text);
void Cbuf_AddText(const char *text);
/* as new commands are generated from the console or keybindings, */
/* the text is added to the end of the command buffer. */
@ -616,7 +616,7 @@ qboolean Netchan_CanReliable(netchan_t *chan);
#include "files.h"
cmodel_t *CM_LoadMap(char *name, qboolean clientload, unsigned *checksum);
cmodel_t *CM_InlineModel(char *name); /* *1, *2, etc */
cmodel_t *CM_InlineModel(const char *name); /* *1, *2, etc */
int CM_NumClusters(void);
int CM_NumInlineModels(void);

View file

@ -311,7 +311,7 @@ void COM_FileBase(char *in, char *out);
void COM_FilePath(const char *in, char *out);
void COM_DefaultExtension(char *path, const char *extension);
char *COM_Parse(char **data_p);
const char *COM_Parse(char **data_p);
/* data is an in/out parm, returns a parsed out token */
void Com_sprintf(char *dest, int size, char *fmt, ...);
@ -360,9 +360,9 @@ char *va(const char *format, ...) PRINTF_ATTR(1, 2);
#define MAX_INFO_STRING 512
char *Info_ValueForKey(char *s, char *key);
void Info_RemoveKey(char *s, char *key);
void Info_SetValueForKey(char *s, char *key, char *value);
qboolean Info_Validate(char *s);
void Info_RemoveKey(char *s, const char *key);
void Info_SetValueForKey(char *s, const char *key, const char *value);
qboolean Info_Validate(const char *s);
/* ============================================= */

View file

@ -247,7 +247,7 @@ MSG_WriteFloat(sizebuf_t *sb, float f)
}
void
MSG_WriteString(sizebuf_t *sb, char *s)
MSG_WriteString(sizebuf_t *sb, const char *s)
{
if (!s)
{

View file

@ -910,7 +910,7 @@ char com_token[MAX_TOKEN_CHARS];
/*
* Parse a token out of a string
*/
char *
const char *
COM_Parse(char **data_p)
{
int c;
@ -1264,7 +1264,7 @@ Info_ValueForKey(char *s, char *key)
}
void
Info_RemoveKey(char *s, char *key)
Info_RemoveKey(char *s, const char *key)
{
char *start;
char pkey[512];
@ -1327,7 +1327,7 @@ Info_RemoveKey(char *s, char *key)
* because they can mess up the server's parsing
*/
qboolean
Info_Validate(char *s)
Info_Validate(const char *s)
{
if (strstr(s, "\""))
{
@ -1343,7 +1343,7 @@ Info_Validate(char *s)
}
void
Info_SetValueForKey(char *s, char *key, char *value)
Info_SetValueForKey(char *s, const char *key, const char *value)
{
char newi[MAX_INFO_STRING], *v;
int c;

View file

@ -71,14 +71,14 @@ SZ_GetSpace(sizebuf_t *buf, int length)
}
void
SZ_Write(sizebuf_t *buf, void *data, int length)
SZ_Write(sizebuf_t *buf, const void *data, int length)
{
if(length > 0)
memcpy(SZ_GetSpace(buf, length), data, length);
}
void
SZ_Print(sizebuf_t *buf, char *data)
SZ_Print(sizebuf_t *buf, const char *data)
{
int len;

View file

@ -103,41 +103,6 @@ ShutdownGame(void)
gi.FreeTags(TAG_GAME);
}
/*
* convert function declarations to correct one
* (warning like from incompatible pointer type)
* little bit better than cast function before set
*/
static void
ReadLevel_f(char *filename)
{
ReadLevel(filename);
}
static void
WriteLevel_f(char *filename)
{
WriteLevel(filename);
}
static void
ReadGame_f(char *filename)
{
ReadGame(filename);
}
static void
WriteGame_f(char *filename, qboolean autosave)
{
WriteGame(filename, autosave);
}
static void
SpawnEntities_f(char *mapname, char *entities, char *spawnpoint)
{
SpawnEntities(mapname, entities, spawnpoint);
}
/*
* Returns a pointer to the structure
* with all entry points and global
@ -151,12 +116,12 @@ GetGameAPI(game_import_t *import)
globals.apiversion = GAME_API_VERSION;
globals.Init = InitGame;
globals.Shutdown = ShutdownGame;
globals.SpawnEntities = SpawnEntities_f;
globals.SpawnEntities = SpawnEntities;
globals.WriteGame = WriteGame_f;
globals.ReadGame = ReadGame_f;
globals.WriteLevel = WriteLevel_f;
globals.ReadLevel = ReadLevel_f;
globals.WriteGame = WriteGame;
globals.ReadGame = ReadGame;
globals.WriteLevel = WriteLevel;
globals.ReadLevel = ReadLevel;
globals.ClientThink = ClientThink;
globals.ClientConnect = ClientConnect;

View file

@ -118,17 +118,17 @@ typedef struct
and misc data like the sky definition and cdtrack.
All of the current configstrings are sent to clients when
they connect, and changes are sent to all connected clients. */
void (*configstring)(int num, char *string);
void (*configstring)(int num, const char *string);
YQ2_ATTR_NORETURN_FUNCPTR void (*error)(const char *fmt, ...);
/* the *index functions create configstrings
and some internal server state */
int (*modelindex)(char *name);
int (*soundindex)(char *name);
int (*imageindex)(char *name);
int (*modelindex)(const char *name);
int (*soundindex)(const char *name);
int (*imageindex)(const char *name);
void (*setmodel)(edict_t *ent, char *name);
void (*setmodel)(edict_t *ent, const char *name);
/* collision detection */
trace_t (*trace)(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end,
@ -156,7 +156,7 @@ typedef struct
void (*WriteShort)(int c);
void (*WriteLong)(int c);
void (*WriteFloat)(float f);
void (*WriteString)(char *s);
void (*WriteString)(const char *s);
void (*WritePosition)(vec3_t pos); /* some fractional bits */
void (*WriteDir)(vec3_t pos); /* single byte encoded, very coarse */
void (*WriteAngle)(float f);
@ -178,7 +178,7 @@ typedef struct
/* add commands to the server console as if
they were typed in for map changing, etc */
void (*AddCommandString)(char *text);
void (*AddCommandString)(const char *text);
void (*DebugGraph)(float value, int color);
} game_import_t;
@ -195,20 +195,20 @@ typedef struct
void (*Shutdown)(void);
/* each new level entered will cause a call to SpawnEntities */
void (*SpawnEntities)(char *mapname, char *entstring, char *spawnpoint);
void (*SpawnEntities)(const char *mapname, char *entstring, const char *spawnpoint);
/* Read/Write Game is for storing persistant cross level information
about the world state and the clients.
WriteGame is called every time a level is exited.
ReadGame is called on a loadgame. */
void (*WriteGame)(char *filename, qboolean autosave);
void (*ReadGame)(char *filename);
void (*WriteGame)(const char *filename, qboolean autosave);
void (*ReadGame)(const char *filename);
/* ReadLevel is called after the default
map information has been loaded with
SpawnEntities */
void (*WriteLevel)(char *filename);
void (*ReadLevel)(char *filename);
void (*WriteLevel)(const char *filename);
void (*ReadLevel)(const char *filename);
qboolean (*ClientConnect)(edict_t *ent, char *userinfo);
void (*ClientBegin)(edict_t *ent);

View file

@ -43,9 +43,9 @@ extern mmoveList_t * GetMmoveByAddress ( mmove_t * adr ) ;
extern byte * FindFunctionByName ( char * name ) ;
extern functionList_t * GetFunctionByAddress ( byte * adr ) ;
extern void InitGame ( void ) ;
extern void Info_SetValueForKey ( char * s , char * key , char * value ) ;
extern qboolean Info_Validate ( char * s ) ;
extern void Info_RemoveKey ( char * s , char * key ) ;
extern void Info_SetValueForKey ( char * s , const char * key , const char * value ) ;
extern qboolean Info_Validate ( const char * s ) ;
extern void Info_RemoveKey ( char * s , const char * key ) ;
extern char * Info_ValueForKey ( char * s , char * key ) ;
extern int Q_strlcat ( char * dst , const char * src , int size ) ;
extern int Q_strlcpy ( char * dst , const char * src , int size ) ;
@ -55,7 +55,7 @@ extern int Q_strcasecmp ( const char * s1 , const char * s2 ) ;
extern int Q_strncasecmp ( const char * s1 , const char * s2 , int n ) ;
extern int Q_stricmp ( const char * s1 , const char * s2 ) ;
extern void Com_PageInMemory ( byte * buffer , int size ) ;
extern char * COM_Parse ( char * * data_p ) ;
extern const char * COM_Parse ( char * * data_p ) ;
extern char * va ( const char * format , ... ) ;
extern void Swap_Init ( void ) ;
extern float FloatNoSwap ( float f ) ;

View file

@ -89,7 +89,7 @@ typedef struct
typedef enum
{
cs_free, /* can be reused for a new connection */
cs_zombie, /* client has been disconnected, but don't reuse
cs_zombie, /* client has been disconnected, but don't reuse
connection for a couple seconds */
cs_connected, /* has been assigned to a client_t, but not in game yet */
cs_spawned /* client is fully in game */
@ -127,7 +127,7 @@ typedef struct client_s
edict_t *edict; /* EDICT_NUM(clientnum+1) */
char name[32]; /* extracted from userinfo, high bits masked */
/* The datagram is written to by sound calls, prints,
/* The datagram is written to by sound calls, prints,
temp ents, etc. It can be harmlessly overflowed. */
sizebuf_t datagram;
byte datagram_buf[MAX_MSGLEN];
@ -200,9 +200,9 @@ extern edict_t *sv_player;
void SV_FinalMessage(char *message, qboolean reconnect);
void SV_DropClient(client_t *drop);
int SV_ModelIndex(char *name);
int SV_SoundIndex(char *name);
int SV_ImageIndex(char *name);
int SV_ModelIndex(const char *name);
int SV_SoundIndex(const char *name);
int SV_ImageIndex(const char *name);
void SV_WriteClientdataToMessage(client_t *client, sizebuf_t *msg);
@ -273,7 +273,7 @@ void SV_LinkEdict(edict_t *ent);
/* Needs to be called any time an entity changes origin, mins, maxs,
or solid. Automatically unlinks if needed. sets ent->v.absmin and
ent->v.absmax sets ent->leafnums[] for pvs determination even if
ent->v.absmax sets ent->leafnums[] for pvs determination even if
the entity is not solid */
int SV_AreaEdicts(vec3_t mins, vec3_t maxs, edict_t **list,
int maxcount, int areatype);

View file

@ -25,17 +25,17 @@
*/
#include "header/server.h"
#ifndef DEDICATED_ONLY
void SCR_DebugGraph(float value, int color);
#endif
game_export_t *ge;
/*
* Sends the contents of the mutlicast buffer to a single client
*/
void
static void
PF_Unicast(edict_t *ent, qboolean reliable)
{
int p;
@ -71,7 +71,7 @@ PF_Unicast(edict_t *ent, qboolean reliable)
/*
* Debug print to server console
*/
void
static void
PF_dprintf(const char *fmt, ...)
{
char msg[1024];
@ -87,7 +87,7 @@ PF_dprintf(const char *fmt, ...)
/*
* Print to a single client
*/
void
static void
PF_cprintf(edict_t *ent, int level, const char *fmt, ...)
{
char msg[1024];
@ -123,7 +123,7 @@ PF_cprintf(edict_t *ent, int level, const char *fmt, ...)
/*
* centerprint to a single client
*/
void
static void
PF_centerprintf(edict_t *ent, const char *fmt, ...)
{
char msg[1024];
@ -149,7 +149,7 @@ PF_centerprintf(edict_t *ent, const char *fmt, ...)
/*
* Abort the server with a game error
*/
YQ2_ATTR_NORETURN_FUNCPTR void
YQ2_ATTR_NORETURN_FUNCPTR static void
PF_error(const char *fmt, ...)
{
char msg[1024];
@ -165,8 +165,8 @@ PF_error(const char *fmt, ...)
/*
* Also sets mins and maxs for inline bmodels
*/
void
PF_setmodel(edict_t *ent, char *name)
static void
PF_setmodel(edict_t *ent, const char *name)
{
int i;
cmodel_t *mod;
@ -191,8 +191,8 @@ PF_setmodel(edict_t *ent, char *name)
}
}
void
PF_Configstring(int index, char *val)
static void
PF_Configstring(int index, const char *val)
{
if ((index < 0) || (index >= MAX_CONFIGSTRINGS))
{
@ -219,64 +219,64 @@ PF_Configstring(int index, char *val)
}
}
void
static void
PF_WriteChar(int c)
{
MSG_WriteChar(&sv.multicast, c);
MSG_WriteChar(&sv.multicast, c);
}
void
static void
PF_WriteByte(int c)
{
MSG_WriteByte(&sv.multicast, c);
MSG_WriteByte(&sv.multicast, c);
}
void
static void
PF_WriteShort(int c)
{
MSG_WriteShort(&sv.multicast, c);
MSG_WriteShort(&sv.multicast, c);
}
void
static void
PF_WriteLong(int c)
{
MSG_WriteLong(&sv.multicast, c);
MSG_WriteLong(&sv.multicast, c);
}
void
static void
PF_WriteFloat(float f)
{
MSG_WriteFloat(&sv.multicast, f);
MSG_WriteFloat(&sv.multicast, f);
}
void
PF_WriteString(char *s)
static void
PF_WriteString(const char *s)
{
MSG_WriteString(&sv.multicast, s);
MSG_WriteString(&sv.multicast, s);
}
void
static void
PF_WritePos(vec3_t pos)
{
MSG_WritePos(&sv.multicast, pos);
MSG_WritePos(&sv.multicast, pos);
}
void
static void
PF_WriteDir(vec3_t dir)
{
MSG_WriteDir(&sv.multicast, dir);
MSG_WriteDir(&sv.multicast, dir);
}
void
static void
PF_WriteAngle(float f)
{
MSG_WriteAngle(&sv.multicast, f);
MSG_WriteAngle(&sv.multicast, f);
}
/*
* Also checks portalareas so that doors block sight
*/
qboolean
static qboolean
PF_inPVS(vec3_t p1, vec3_t p2)
{
int leafnum;
@ -312,7 +312,7 @@ PF_inPVS(vec3_t p1, vec3_t p2)
/*
* Also checks portalareas so that doors block sound
*/
qboolean
static qboolean
PF_inPHS(vec3_t p1, vec3_t p2)
{
int leafnum;
@ -345,7 +345,7 @@ PF_inPHS(vec3_t p1, vec3_t p2)
return true;
}
void
static void
PF_StartSound(edict_t *entity, int channel, int sound_num,
float volume, float attenuation, float timeofs)
{

View file

@ -33,8 +33,8 @@
server_static_t svs; /* persistant server info */
server_t sv; /* local server */
int
SV_FindIndex(char *name, int start, int max, qboolean create)
static int
SV_FindIndex(const char *name, int start, int max, qboolean create)
{
int i;
@ -76,19 +76,19 @@ SV_FindIndex(char *name, int start, int max, qboolean create)
}
int
SV_ModelIndex(char *name)
SV_ModelIndex(const char *name)
{
return SV_FindIndex(name, CS_MODELS, MAX_MODELS, true);
}
int
SV_SoundIndex(char *name)
SV_SoundIndex(const char *name)
{
return SV_FindIndex(name, CS_SOUNDS, MAX_SOUNDS, true);
}
int
SV_ImageIndex(char *name)
SV_ImageIndex(const char *name)
{
return SV_FindIndex(name, CS_IMAGES, MAX_IMAGES, true);
}