From 06670a436c2ddcd17ebeadd07528689963f2a983 Mon Sep 17 00:00:00 2001 From: codeflorist Date: Thu, 30 Mar 2023 12:21:43 +0200 Subject: [PATCH] fix some type errors for c++ compilation --- Quake/cvar.c | 2 +- Quake/gl_rmisc.c | 2 +- Quake/gl_shaders.c | 2 +- Quake/gl_sky.c | 2 +- Quake/gl_texmgr.c | 8 ++++---- Quake/host_cmd.c | 16 ++++++++-------- Quake/menu.c | 8 ++++---- Quake/net_main.c | 2 +- Quake/pr_cmds.c | 18 +++++++++--------- Quake/pr_edict.c | 8 ++++---- Quake/r_world.c | 12 ++++++------ Quake/server.h | 31 +++++++++++++++++-------------- Quake/sv_main.c | 2 +- Quake/sys_sdl_win.c | 6 +++--- Quake/world.c | 2 +- 15 files changed, 62 insertions(+), 59 deletions(-) diff --git a/Quake/cvar.c b/Quake/cvar.c index c815ce5e9..c556c89bf 100644 --- a/Quake/cvar.c +++ b/Quake/cvar.c @@ -585,7 +585,7 @@ cvar_t *Cvar_Create (const char *name, const char *value) if (Cmd_Exists (name)) return NULL; //error! panic! oh noes! - newvar = Z_Malloc(sizeof(cvar_t) + strlen(name)+1); + newvar = (cvar_t*) Z_Malloc(sizeof(cvar_t) + strlen(name)+1); newvar->name = (char*)(newvar+1); strcpy((char*)(newvar+1), name); newvar->flags = CVAR_USERDEFINED; diff --git a/Quake/gl_rmisc.c b/Quake/gl_rmisc.c index 4c3407d6f..c148a06f0 100644 --- a/Quake/gl_rmisc.c +++ b/Quake/gl_rmisc.c @@ -746,7 +746,7 @@ static void GL_AllocFrameResources (frameres_bits_t bits) if (gl_buffer_storage_able) { GL_BufferStorageFunc (GL_ARRAY_BUFFER, frameres_host_buffer_size, NULL, flags); - frame->host_ptr = GL_MapBufferRangeFunc (GL_ARRAY_BUFFER, 0, frameres_host_buffer_size, flags); + frame->host_ptr = (GLubyte *) GL_MapBufferRangeFunc (GL_ARRAY_BUFFER, 0, frameres_host_buffer_size, flags); if (!frame->host_ptr) Sys_Error ("GL_AllocFrameResources: MapBufferRange failed on %" SDL_PRIu64 " bytes", (uint64_t)frameres_host_buffer_size); } diff --git a/Quake/gl_shaders.c b/Quake/gl_shaders.c index 25cb9f43a..344bdc8e7 100644 --- a/Quake/gl_shaders.c +++ b/Quake/gl_shaders.c @@ -211,7 +211,7 @@ static GLuint GL_CreateProgramFromSources (int count, const GLchar **sources, co q_vsnprintf (eval, sizeof (eval), name, argptr); macros[0] = 0; - pipe = strchr (name, '|'); + pipe = (char*) strchr (name, '|'); if (pipe) // parse symbol list and generate #defines { char *dst = macros; diff --git a/Quake/gl_sky.c b/Quake/gl_sky.c index 121b11c6d..c856bba6f 100644 --- a/Quake/gl_sky.c +++ b/Quake/gl_sky.c @@ -428,7 +428,7 @@ void Sky_LoadSkyBox (const char *name) const int cubemap_order[6] = {3, 1, 4, 5, 0, 2}; // ft/bk/up/dn/rt/lf size_t numfacebytes = samesize * samesize * 4; - newsky.cubemap_pixels = malloc (numfacebytes * 6); + newsky.cubemap_pixels = (byte *) malloc (numfacebytes * 6); if (!newsky.cubemap_pixels) { Con_Warning ("Sky_LoadSkyBox: out of memory on %" SDL_PRIu64 " bytes\n", (uint64_t) numfacebytes); diff --git a/Quake/gl_texmgr.c b/Quake/gl_texmgr.c index 0f272a437..b1cce34e1 100644 --- a/Quake/gl_texmgr.c +++ b/Quake/gl_texmgr.c @@ -288,8 +288,8 @@ TexMgr_SoftEmu_f -- called when r_softemu changes */ static void TexMgr_SoftEmu_f (cvar_t *var) { - softemu = (int)r_softemu.value; - softemu = CLAMP (0, (int)softemu, SOFTEMU_NUMMODES - 1); + softemu = (softemu_t)r_softemu.value; + softemu = (softemu_t)CLAMP (0, softemu, SOFTEMU_NUMMODES - 1); } /* @@ -2046,8 +2046,8 @@ void GLPalette_UpdateLookupTable (void) } else { - metric = (int)r_softemu_metric.value; - metric = CLAMP (0, (int)metric, SOFTEMU_METRIC_COUNT - 1); + metric = (softemu_metric_t)r_softemu_metric.value; + metric = (softemu_metric_t)CLAMP (0, (int)metric, SOFTEMU_METRIC_COUNT - 1); } SDL_assert ((unsigned)metric < SOFTEMU_METRIC_COUNT); diff --git a/Quake/host_cmd.c b/Quake/host_cmd.c index 01b01d816..6a4f258f9 100644 --- a/Quake/host_cmd.c +++ b/Quake/host_cmd.c @@ -177,7 +177,7 @@ static void FileList_Print (filelist_item_t *list, const char *types[2], const c filelist_item_t *item; const char *desc; char buf[256], buf2[256]; - char padchar = '.' | 0x80; + char padchar = '.' | (char)0x80; size_t ofsdesc = list == extralevels ? maxlevelnamelen + 2 : 0; if (substr && *substr) @@ -252,7 +252,7 @@ static maptype_t ExtraMaps_Categorize (const char *name, const searchpath_t *sou break; case 'e': if (name[1] >= '1' && name[1] <= '4') - return MAPTYPE_ID_EP1_LEVEL + (name[1] - '1'); + return (maptype_t)(MAPTYPE_ID_EP1_LEVEL + (name[1] - '1')); if (!strcmp (name + 1, "nd")) return MAPTYPE_ID_END; break; @@ -282,12 +282,12 @@ static maptype_t ExtraMaps_Categorize (const char *name, const searchpath_t *sou base = *source->filename ? MAPTYPE_CUSTOM_MOD_START : MAPTYPE_MOD_START; if (is_start) - return base + MAPTYPE_CUSTOM_MOD_START; + return (maptype_t)(base + MAPTYPE_CUSTOM_MOD_START); if (is_end) - return base + MAPTYPE_CUSTOM_MOD_END; + return (maptype_t)(base + MAPTYPE_CUSTOM_MOD_END); if (is_dm) - return base + MAPTYPE_CUSTOM_MOD_DM; - return base + MAPTYPE_CUSTOM_MOD_LEVEL; + return (maptype_t)(base + MAPTYPE_CUSTOM_MOD_DM); + return (maptype_t)(base + MAPTYPE_CUSTOM_MOD_LEVEL); } typedef struct levelinfo_s @@ -314,7 +314,7 @@ ExtraMaps_GetType maptype_t ExtraMaps_GetType (const filelist_item_t *item) { const levelinfo_t *info = ExtraMaps_GetInfo (item); - return SDL_AtomicGet ((SDL_atomic_t *) &info->type); + return (maptype_t)SDL_AtomicGet ((SDL_atomic_t *) &info->type); } /* @@ -3009,7 +3009,7 @@ static void Host_Spawn_f (void) MSG_WriteByte (&host_client->message, svc_signonnum); MSG_WriteByte (&host_client->message, 3); - host_client->sendsignon = true; + host_client->sendsignon = PRESPAWN_FLUSH; } /* diff --git a/Quake/menu.c b/Quake/menu.c index 53d2a1869..ed9a3669f 100644 --- a/Quake/menu.c +++ b/Quake/menu.c @@ -1674,7 +1674,7 @@ static void M_Maps_Init (void) if (type >= MAPTYPE_BMODEL) continue; if (prev_type != -1 && prev_type != type) - M_Maps_AddSeparator (prev_type, type); + M_Maps_AddSeparator ((maptype_t)prev_type, (maptype_t)type); prev_type = type; map.name = item->name; @@ -1683,7 +1683,7 @@ static void M_Maps_Init (void) map.mapidx = mapsmenu.mapcount++; if (map.active && active == -1) active = VEC_SIZE (mapsmenu.items); - if ((map.active && !cls.demoplayback) || (mapsmenu.list.cursor == -1 && ExtraMaps_IsStart (type))) + if ((map.active && !cls.demoplayback) || (mapsmenu.list.cursor == -1 && ExtraMaps_IsStart ((maptype_t)type))) mapsmenu.list.cursor = VEC_SIZE (mapsmenu.items); VEC_PUSH (mapsmenu.items, map); mapsmenu.list.numitems++; @@ -2650,7 +2650,7 @@ chooses next window mode in order, then updates vid_fullscreen and vid_borderles static void VID_Menu_ChooseNextDisplayMode (int dir) { windowmode_t mode = VID_Menu_GetDisplayMode (); - mode = (mode + DISPLAYMODE_COUNT - dir) % DISPLAYMODE_COUNT; + mode = (windowmode_t)((mode + DISPLAYMODE_COUNT - dir) % DISPLAYMODE_COUNT); VID_Menu_SetDisplayMode (mode); } @@ -3209,7 +3209,7 @@ void M_AdjustSliders (int dir) Cvar_SetValueQuick (&crosshair, ((int) q_max (crosshair.value, 0.f) + 3 + dir) % 3); break; case OPT_UIMOUSE: // UI mouse support - M_Options_SetUIMouse ((M_Options_GetUIMouse () + UI_MOUSE_NUMSETTINGS + dir) % UI_MOUSE_NUMSETTINGS); + M_Options_SetUIMouse ((uimouse_t)((M_Options_GetUIMouse () + UI_MOUSE_NUMSETTINGS + dir) % UI_MOUSE_NUMSETTINGS)); break; case OPT_GAMMA: // gamma f = vid_gamma.value - dir * 0.05; diff --git a/Quake/net_main.c b/Quake/net_main.c index 4c7184b14..85568dc6c 100644 --- a/Quake/net_main.c +++ b/Quake/net_main.c @@ -860,7 +860,7 @@ void NET_Shutdown (void) // for (net_driverlevel = 0; net_driverlevel < net_numdrivers; net_driverlevel++) { - if (net_drivers[net_driverlevel].initialized == true) + if (net_drivers[net_driverlevel].initialized == (qboolean)true) { net_drivers[net_driverlevel].Shutdown (); net_drivers[net_driverlevel].initialized = false; diff --git a/Quake/pr_cmds.c b/Quake/pr_cmds.c index a896e9271..972152904 100644 --- a/Quake/pr_cmds.c +++ b/Quake/pr_cmds.c @@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "q_ctype.h" +#include "server.h" #define STRINGTEMP_BUFFERS 1024 #define STRINGTEMP_LENGTH 1024 @@ -2056,8 +2057,7 @@ static void PF_cl_playerkey_f(void) PF_cl_playerkey_internal(playernum, keyname, true); } - -static struct +static struct qcpics_t { char name[MAX_QPATH]; unsigned int flags; @@ -2104,7 +2104,7 @@ static qpic_t *DrawQC_CachePic(const char *picname, unsigned int flags) if (i+1 > maxqcpics) { maxqcpics = i + 32; - qcpics = realloc(qcpics, maxqcpics * sizeof(*qcpics)); + qcpics = (struct qcpics_t*)realloc(qcpics, maxqcpics * sizeof(*qcpics)); } strcpy(qcpics[i].name, picname); @@ -2540,13 +2540,13 @@ static void PF_strzone(void) } len++; /*for the null*/ - buf = Z_Malloc(len); + buf = (char*)Z_Malloc(len); G_INT(OFS_RETURN) = PR_SetEngineString(buf); id = -1-G_INT(OFS_RETURN); if (id >= qcvm->knownzonesize) { qcvm->knownzonesize = (id+32)&~7; - qcvm->knownzone = Z_Realloc(qcvm->knownzone, (qcvm->knownzonesize+7)>>3); + qcvm->knownzone = (unsigned char *)Z_Realloc(qcvm->knownzone, (qcvm->knownzonesize+7)>>3); } qcvm->knownzone[id>>3] |= 1u<<(id&7); @@ -3237,7 +3237,7 @@ static void PF_tokenizebyseparator(void) if (found) { tlen = qctoken[qctoken_count].end - qctoken[qctoken_count].start; - qctoken[qctoken_count].token = malloc(tlen + 1); + qctoken[qctoken_count].token = (char*)malloc(tlen + 1); memcpy(qctoken[qctoken_count].token, start + qctoken[qctoken_count].start, tlen); qctoken[qctoken_count].token[tlen] = 0; @@ -3401,7 +3401,7 @@ static void PF_cl_registercommand(void) Cmd_AddCommand(cmdname, NULL); } -static struct svcustomstat_s *PR_CustomStat(int idx, int type) +static svcustomstat_t *PR_CustomStat(int idx, int type) { size_t i; if (idx < 0 || idx >= MAX_CL_STATS) @@ -3428,14 +3428,14 @@ static struct svcustomstat_s *PR_CustomStat(int idx, int type) sv.customstats[i].type = type; sv.customstats[i].fld = 0; sv.customstats[i].ptr = NULL; - return &sv.customstats[i]; + return (svcustomstat_t*) & sv.customstats[i]; } static void PF_clientstat(void) { int idx = G_FLOAT(OFS_PARM0); int type = G_FLOAT(OFS_PARM1); int fldofs = G_INT(OFS_PARM2); - struct svcustomstat_s *stat = PR_CustomStat(idx, type); + svcustomstat_t *stat = PR_CustomStat(idx, type); if (!stat) return; stat->fld = fldofs; diff --git a/Quake/pr_edict.c b/Quake/pr_edict.c index 350fc4e71..f319bf815 100644 --- a/Quake/pr_edict.c +++ b/Quake/pr_edict.c @@ -985,14 +985,14 @@ static void ED_RezoneString (string_t *ref, const char *str) // Con_Warning("ED_RezoneString: string wasn't strzoned\n"); //warnings would trigger from the default cvar value that autocvars are initialised with } - buf = Z_Malloc(len); + buf = (char *)Z_Malloc(len); memcpy(buf, str, len); id = -1-(*ref = PR_SetEngineString(buf)); //make sure its flagged as zoned so we can clean up properly after. if (id >= qcvm->knownzonesize) { qcvm->knownzonesize = (id+32)&~7; - qcvm->knownzone = Z_Realloc(qcvm->knownzone, (qcvm->knownzonesize+7)>>3); + qcvm->knownzone = (unsigned char *)Z_Realloc(qcvm->knownzone, (qcvm->knownzonesize+7)>>3); } qcvm->knownzone[id>>3] |= 1u<<(id&7); } @@ -1378,7 +1378,7 @@ static func_t PR_FindExtFunction(const char *entryname) return 0; } -static void *PR_FindExtGlobal(int type, const char *name) +static float *PR_FindExtGlobal(int type, const char *name) { ddef_t *def = ED_FindGlobal(name); if (def && (def->type&~DEF_SAVEGLOBAL) == type && def->ofs < qcvm->progs->numglobals) @@ -1529,7 +1529,7 @@ static void PR_MergeEngineFieldDefs (void) if (maxdefs != qcvm->progs->numfielddefs) { //we now know how many entries we need to add... ddef_t *olddefs = qcvm->fielddefs; - qcvm->fielddefs = malloc(maxdefs * sizeof(*qcvm->fielddefs)); + qcvm->fielddefs = (ddef_t *)malloc(maxdefs * sizeof(*qcvm->fielddefs)); memcpy(qcvm->fielddefs, olddefs, qcvm->progs->numfielddefs*sizeof(*qcvm->fielddefs)); if (olddefs != (ddef_t *)((byte *)qcvm->progs + qcvm->progs->ofs_fielddefs)) free(olddefs); diff --git a/Quake/r_world.c b/Quake/r_world.c index b04f417d8..e4f29c3df 100644 --- a/Quake/r_world.c +++ b/Quake/r_world.c @@ -379,32 +379,32 @@ static void R_DrawBrushModels_Real (entity_t **ents, int count, brushpass_t pass { default: case BP_SOLID: - texbegin = 0; + texbegin = (textype_t)0; texend = TEXTYPE_CUTOUT; program = glprogs.world[oit][q_max(0, (int)softemu - 1)][WORLDSHADER_SOLID]; break; case BP_ALPHATEST: texbegin = TEXTYPE_CUTOUT; - texend = TEXTYPE_CUTOUT + 1; + texend = (textype_t)(TEXTYPE_CUTOUT + 1); program = glprogs.world[oit][q_max(0, (int)softemu - 1)][WORLDSHADER_ALPHATEST]; break; case BP_SKYLAYERS: texbegin = TEXTYPE_SKY; - texend = TEXTYPE_SKY + 1; + texend = (textype_t)(TEXTYPE_SKY + 1); program = glprogs.skylayers[softemu == SOFTEMU_COARSE]; break; case BP_SKYCUBEMAP: texbegin = TEXTYPE_SKY; - texend = TEXTYPE_SKY + 1; + texend = (textype_t)(TEXTYPE_SKY + 1); program = glprogs.skycubemap[Sky_IsAnimated ()][softemu == SOFTEMU_COARSE]; break; case BP_SKYSTENCIL: texbegin = TEXTYPE_SKY; - texend = TEXTYPE_SKY + 1; + texend = (textype_t)(TEXTYPE_SKY + 1); program = glprogs.skystencil; break; case BP_SHOWTRIS: - texbegin = 0; + texbegin = (textype_t)0; texend = TEXTYPE_COUNT; program = glprogs.world[0][0][0]; break; diff --git a/Quake/server.h b/Quake/server.h index 4c8ebc1f0..1bee21512 100644 --- a/Quake/server.h +++ b/Quake/server.h @@ -34,6 +34,14 @@ typedef struct qboolean changelevel_issued; // cleared when at SV_SpawnServer } server_static_t; +typedef struct +{ + int idx; + int type; + int fld; + eval_t* ptr; +} svcustomstat_t; + //============================================================================= #define MAX_SIGNON_BUFFERS 256 @@ -75,13 +83,7 @@ typedef struct unsigned protocol; //johnfitz unsigned protocolflags; - struct svcustomstat_s - { - int idx; - int type; - int fld; - eval_t *ptr; - } customstats[MAX_CL_STATS*2]; //strings or numeric... + svcustomstat_t customstats[MAX_CL_STATS*2]; //strings or numeric... size_t numcustomstats; char lastsave[MAX_OSPATH]; @@ -103,18 +105,19 @@ typedef struct #define NUM_PING_TIMES 16 +typedef enum { + PRESPAWN_DONE, + PRESPAWN_FLUSH = 1, + PRESPAWN_SIGNONBUFS, + PRESPAWN_SIGNONMSG, +} sendsignon_t; + typedef struct client_s { qboolean active; // false = client is free qboolean spawned; // false = don't send datagrams qboolean dropasap; // has been told to go to another level - enum - { - PRESPAWN_DONE, - PRESPAWN_FLUSH=1, - PRESPAWN_SIGNONBUFS, - PRESPAWN_SIGNONMSG, - } sendsignon; // only valid before spawned + sendsignon_t sendsignon; // only valid before spawned int signonidx; double last_message; // reliable messages must be sent diff --git a/Quake/sv_main.c b/Quake/sv_main.c index bdd0c5a46..e4d03ec9a 100644 --- a/Quake/sv_main.c +++ b/Quake/sv_main.c @@ -456,7 +456,7 @@ void SV_SendServerinfo (client_t *client) MSG_WriteByte (&client->message, svc_signonnum); MSG_WriteByte (&client->message, 1); - client->sendsignon = true; + client->sendsignon = PRESPAWN_FLUSH; client->spawned = false; // need prespawn, spawn, etc } diff --git a/Quake/sys_sdl_win.c b/Quake/sys_sdl_win.c index ffd436ad5..d2a0427b3 100644 --- a/Quake/sys_sdl_win.c +++ b/Quake/sys_sdl_win.c @@ -381,7 +381,7 @@ static qboolean Sys_GetKnownFolder (const KNOWNFOLDERID *base, const char *subdi if (FAILED (hr)) return false; - hr = SHGetKnownFolderPath (base, 0, NULL, &wpath); + hr = SHGetKnownFolderPath ((REFKNOWNFOLDERID)base, 0, NULL, &wpath); if (FAILED (hr)) { CoUninitialize (); @@ -568,9 +568,9 @@ typedef struct winfindfile_s { static void Sys_FillFindData (winfindfile_t *find) { WideStringToUTF8 (find->data.cFileName, find->base.name, countof (find->base.name)); - find->base.attribs = 0; + find->base.attribs = (fileattribs_t)0; if (find->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - find->base.attribs |= FA_DIRECTORY; + find->base.attribs = (fileattribs_t)(find->base.attribs | FA_DIRECTORY); } findfile_t *Sys_FindFirst (const char *dir, const char *ext) diff --git a/Quake/world.c b/Quake/world.c index ff886bbbd..d577d2ed5 100644 --- a/Quake/world.c +++ b/Quake/world.c @@ -340,7 +340,7 @@ void SV_TouchLinks (edict_t *ent) int old_self, old_other; int i, listcount; - list = alloca (qcvm->num_edicts*sizeof(edict_t *)); + list = (edict_t **)(alloca (qcvm->num_edicts*sizeof(edict_t *))); listcount = 0; SV_AreaTriggerEdicts (ent, sv_areanodes, list, &listcount, qcvm->num_edicts);