From dbd7d0a193ee3ee0d1da6731e51f116e3d970f18 Mon Sep 17 00:00:00 2001 From: Ian Date: Wed, 18 Oct 2023 13:52:57 -0400 Subject: [PATCH] Avoid using strcmp every frame --- source/cmd.c | 2 +- source/common.c | 17 ----------------- source/common.h | 1 - source/cvar.c | 2 +- source/gl_draw.c | 18 +++++++++--------- source/gl_model.c | 16 +++++++++++++--- source/gl_model.h | 3 +++ source/gl_rmisc.c | 4 ++-- source/gl_rsurf.c | 27 ++++++--------------------- source/net_comx.c | 26 +++++++++++++------------- source/snd_mem.c | 4 ++-- 11 files changed, 50 insertions(+), 70 deletions(-) diff --git a/source/cmd.c b/source/cmd.c index e16053d..87734d9 100644 --- a/source/cmd.c +++ b/source/cmd.c @@ -597,7 +597,7 @@ char *Cmd_CompleteCommand (char *partial) // check functions for (cmd=cmd_functions ; cmd ; cmd=cmd->next) - if (!Q_strncmp (partial,cmd->name, len)) + if (!strncmp (partial,cmd->name, len)) return cmd->name; return NULL; diff --git a/source/common.c b/source/common.c index 09b6567..e84f0b4 100644 --- a/source/common.c +++ b/source/common.c @@ -250,23 +250,6 @@ void Q_strcat (char *dest, char *src) Q_strcpy (dest, src); } -int Q_strncmp (char *s1, char *s2, int count) -{ - while (1) - { - if (!count--) - return 0; - if (*s1 != *s2) - return -1; // strings not equal - if (!*s1) - return 0; // strings are equal - s1++; - s2++; - } - - return -1; -} - int Q_strncasecmp (char *s1, char *s2, int n) { int c1, c2; diff --git a/source/common.h b/source/common.h index 37fe517..19ea06a 100644 --- a/source/common.h +++ b/source/common.h @@ -150,7 +150,6 @@ void Q_strncpy (char *dest, char *src, int count); int Q_strlen (char *str); char *Q_strrchr (char *s, char c); void Q_strcat (char *dest, char *src); -int Q_strncmp (char *s1, char *s2, int count); int Q_strcasecmp (char *s1, char *s2); int Q_strncasecmp (char *s1, char *s2, int n); int Q_atoi (char *str); diff --git a/source/cvar.c b/source/cvar.c index 4c9f5c1..9ae3bd3 100644 --- a/source/cvar.c +++ b/source/cvar.c @@ -89,7 +89,7 @@ char *Cvar_CompleteVariable (char *partial) // check functions for (cvar=cvar_vars ; cvar ; cvar=cvar->next) - if (!Q_strncmp (partial,cvar->name, len)) + if (!strncmp (partial,cvar->name, len)) return cvar->name; return NULL; diff --git a/source/gl_draw.c b/source/gl_draw.c index 668a2e1..20b0552 100644 --- a/source/gl_draw.c +++ b/source/gl_draw.c @@ -381,10 +381,10 @@ void Draw_Init (void) Cvar_RegisterVariable (&gl_max_size); Cvar_RegisterVariable (&gl_picmip); - // 3dfx can only handle 256 wide textures - if (!Q_strncasecmp ((char *)gl_renderer, "3dfx",4) || - strstr((char *)gl_renderer, "Glide")) + if (!new3ds_flag) { + Cvar_SetValue("gl_picmip", 1); Cvar_Set ("gl_max_size", "256"); + } Cmd_AddCommand ("gl_texturemode", &Draw_TextureMode_f); @@ -1143,27 +1143,27 @@ void Draw_Crosshair (void) x_value = (vid.width - 3)/2 - crosshair_offset_step; y_value = (vid.height - 1)/2; - Draw_FillByColor(x_value, y_value, 3, 1, 255, (int)col, (int)col, crosshair_opacity); + Draw_FillByColor(x_value, y_value, 3, 1, 255, (int)col, (int)col, (int)crosshair_opacity); x_value = (vid.width - 3)/2 + crosshair_offset_step; y_value = (vid.height - 1)/2; - Draw_FillByColor(x_value, y_value, 3, 1, 255, (int)col, (int)col, crosshair_opacity); + Draw_FillByColor(x_value, y_value, 3, 1, 255, (int)col, (int)col, (int)crosshair_opacity); x_value = (vid.width - 1)/2; y_value = (vid.height - 3)/2 - crosshair_offset_step; - Draw_FillByColor(x_value, y_value, 1, 3, 255, (int)col, (int)col, crosshair_opacity); + Draw_FillByColor(x_value, y_value, 1, 3, 255, (int)col, (int)col, (int)crosshair_opacity); x_value = (vid.width - 1)/2; y_value = (vid.height - 3)/2 + crosshair_offset_step; - Draw_FillByColor(x_value, y_value, 1, 3, 255, (int)col, (int)col, crosshair_opacity); + Draw_FillByColor(x_value, y_value, 1, 3, 255, (int)col, (int)col, (int)crosshair_opacity); } // Area of Effect (o) else if (crosshair.value == 2) { - Draw_CharacterRGBA((vid.width)/2-4, (vid.height)/2, 'O', 255, col, col, crosshair_opacity, 1); + Draw_CharacterRGBA((vid.width)/2-4, (vid.height)/2, 'O', 255, (int)col, (int)col, (int)crosshair_opacity, 1); } // Dot crosshair (.) else if (crosshair.value == 3) { - Draw_CharacterRGBA((vid.width - 8)/2, (vid.height - 8)/2, '.', 255, col, col, crosshair_opacity, 1); + Draw_CharacterRGBA((vid.width - 8)/2, (vid.height - 8)/2, '.', 255, (int)col, (int)col, (int)crosshair_opacity, 1); } // Grenade crosshair else if (crosshair.value == 4) { diff --git a/source/gl_model.c b/source/gl_model.c index e224ea2..680c39a 100644 --- a/source/gl_model.c +++ b/source/gl_model.c @@ -395,7 +395,7 @@ void Mod_LoadTextures (lump_t *l) memcpy ( tx+1, mt+1, pixels); - if (loadmodel->bspversion != HL_BSPVERSION && !Q_strncmp(mt->name,"sky",3)) + if (loadmodel->bspversion != HL_BSPVERSION && !strncmp(mt->name,"sky",3)) { R_InitSky (tx); } @@ -889,7 +889,7 @@ void Mod_LoadFaces (lump_t *l) // set the drawing flags flag - if (!Q_strncmp(out->texinfo->texture->name,"sky",3)) // sky + if (!strncmp(out->texinfo->texture->name,"sky",3)) // sky { out->flags |= (SURF_DRAWSKY | SURF_DRAWTILED); #ifndef QUAKE2 @@ -897,8 +897,18 @@ void Mod_LoadFaces (lump_t *l) #endif continue; } + + if (!strncmp(out->texinfo->texture->name,"nodraw",6) || !strncmp(out->texinfo->texture->name,"NODRAW",6)) { + out->flags |= TEXFLAG_NODRAW; + continue; + } + + if (strstr(fa->texinfo->texture->name,"light")) { + out->flags |= TEXFLAG_LIGHT; + continue; + } - if (!Q_strncmp(out->texinfo->texture->name,"*",1)) // turbulent + if (!strncmp(out->texinfo->texture->name,"*",1)) // turbulent { out->flags |= (SURF_DRAWTURB | SURF_DRAWTILED); for (i=0 ; i<2 ; i++) diff --git a/source/gl_model.h b/source/gl_model.h index 439376c..919f6a2 100644 --- a/source/gl_model.h +++ b/source/gl_model.h @@ -106,6 +106,9 @@ typedef struct texture_s #define SURF_DRAWBACKGROUND 0x40 #define SURF_UNDERWATER 0x80 +#define TEXFLAG_NODRAW 256 +#define TEXFLAG_LIGHT 512 + // !!! if this is changed, it must be changed in asm_draw.h too !!! typedef struct { diff --git a/source/gl_rmisc.c b/source/gl_rmisc.c index 077ac47..75dcbf7 100644 --- a/source/gl_rmisc.c +++ b/source/gl_rmisc.c @@ -468,9 +468,9 @@ void R_NewMap (void) { if (!cl.worldmodel->textures[i]) continue; - if (!Q_strncmp(cl.worldmodel->textures[i]->name,"sky",3) ) + if (!strncmp(cl.worldmodel->textures[i]->name,"sky",3) ) skytexturenum = i; - if (!Q_strncmp(cl.worldmodel->textures[i]->name,"window02_1",10) ) + if (!strncmp(cl.worldmodel->textures[i]->name,"window02_1",10) ) mirrortexturenum = i; cl.worldmodel->textures[i]->texturechain = NULL; } diff --git a/source/gl_rsurf.c b/source/gl_rsurf.c index 239e1d9..6dd57a1 100644 --- a/source/gl_rsurf.c +++ b/source/gl_rsurf.c @@ -788,33 +788,18 @@ void R_RenderBrushPoly (msurface_t *fa) EmitWaterPolys (fa); return; } - //Diabolickal start - if(!Q_strncmp(fa->texinfo->texture->name,"nodraw",6) || !Q_strncmp(fa->texinfo->texture->name,"NODRAW",6)) //Diabolickal nodraw support + + if (fa->flags & TEXFLAG_NODRAW) return; - // if (!strncmp(fa->texinfo->texture->name,"{",1)) //Diabolickal Alpha pixel support - // { - // glEnable(GL_ALPHA_TEST); - // glEnable(GL_BLEND); - // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - // } - if (strstr(fa->texinfo->texture->name,"light")) // Any texture with light in the name ignore lightmaps - { - DrawGLPoly (fa->polys); + else if (fa->flags & TEXFLAG_LIGHT) { + DrawGLPoly(fa->polys); return; - } - //Diabolickal end + } + if (fa->flags & SURF_UNDERWATER) DrawGLWaterPoly (fa->polys); else DrawGLPoly (fa->polys); - - //Diabolickal start - // if (!strncmp(fa->texinfo->texture->name,"{",1)) //Diabolickal Alpha pixel support - // { - // glDisable(GL_ALPHA_TEST); - // glDisable(GL_BLEND); - // } - //Diabolickal end // add the poly to the proper lightmap chain diff --git a/source/net_comx.c b/source/net_comx.c index 2115a14..ef91c91 100644 --- a/source/net_comx.c +++ b/source/net_comx.c @@ -607,9 +607,9 @@ static void Modem_Init(ComPort *p) response = Modem_Response(p); if (!response) continue; - if (Q_strncmp(response, "OK", 2) == 0) + if (strncmp(response, "OK", 2) == 0) break; - if (Q_strncmp(response, "ERROR", 5) == 0) + if (strncmp(response, "ERROR", 5) == 0) { p->enabled = false; goto failed; @@ -632,9 +632,9 @@ static void Modem_Init(ComPort *p) response = Modem_Response(p); if (!response) continue; - if (Q_strncmp(response, "OK", 2) == 0) + if (strncmp(response, "OK", 2) == 0) break; - if (Q_strncmp(response, "ERROR", 5) == 0) + if (strncmp(response, "ERROR", 5) == 0) { p->enabled = false; goto failed; @@ -819,7 +819,7 @@ int TTY_Connect(int handle, char *host) response = Modem_Response(p); if (!response) continue; - if (Q_strncmp(response, "CONNECT", 7) == 0) + if (strncmp(response, "CONNECT", 7) == 0) { disable(); p->modemRang = true; @@ -832,17 +832,17 @@ int TTY_Connect(int handle, char *host) m_return_onerror = false; return 0; } - if (Q_strncmp(response, "NO CARRIER", 10) == 0) + if (strncmp(response, "NO CARRIER", 10) == 0) break; - if (Q_strncmp(response, "NO DIALTONE", 11) == 0) + if (strncmp(response, "NO DIALTONE", 11) == 0) break; - if (Q_strncmp(response, "NO DIAL TONE", 12) == 0) + if (strncmp(response, "NO DIAL TONE", 12) == 0) break; - if (Q_strncmp(response, "NO ANSWER", 9) == 0) + if (strncmp(response, "NO ANSWER", 9) == 0) break; - if (Q_strncmp(response, "BUSY", 4) == 0) + if (strncmp(response, "BUSY", 4) == 0) break; - if (Q_strncmp(response, "ERROR", 5) == 0) + if (strncmp(response, "ERROR", 5) == 0) break; } key_dest = save_key_dest; @@ -887,7 +887,7 @@ qboolean TTY_CheckForConnection(int handle) if (!Modem_Response(p)) return false; - if (Q_strncmp(p->buffer, "RING", 4) == 0) + if (strncmp(p->buffer, "RING", 4) == 0) { Modem_Command (p, "ATA"); p->modemRang = true; @@ -907,7 +907,7 @@ qboolean TTY_CheckForConnection(int handle) if (!Modem_Response(p)) return false; - if (Q_strncmp (p->buffer, "CONNECT", 7) != 0) + if (strncmp (p->buffer, "CONNECT", 7) != 0) return false; disable(); diff --git a/source/snd_mem.c b/source/snd_mem.c index b471a66..0ee8177 100644 --- a/source/snd_mem.c +++ b/source/snd_mem.c @@ -211,7 +211,7 @@ void FindNextChunk(char *name) // Sys_Error ("FindNextChunk: %i length is past the 1 meg sanity limit", iff_chunk_len); data_p -= 8; last_chunk = data_p + 8 + ( (iff_chunk_len + 1) & ~1 ); - if (!Q_strncmp(data_p, name, 4)) + if (!strncmp(data_p, name, 4)) return; } } @@ -261,7 +261,7 @@ wavinfo_t GetWavinfo (char *name, byte *wav, int wavlength) // find "RIFF" chunk FindChunk("RIFF"); - if (!(data_p && !Q_strncmp(data_p+8, "WAVE", 4))) + if (!(data_p && !strncmp(data_p+8, "WAVE", 4))) { Con_Printf("Missing RIFF/WAVE chunks\n"); return info;