From 0ed6300efb2d4bbfb44aabb75e622dff17909cf5 Mon Sep 17 00:00:00 2001 From: Ian Date: Sat, 18 Nov 2023 09:01:49 -0500 Subject: [PATCH] NX/VITA: Micro-optimizations --- source/cmd.c | 4 ++-- source/common.c | 4 ++-- source/console.c | 2 +- source/cvar.c | 2 +- source/gl_texmgr.c | 2 +- source/host_cmd.c | 8 ++++---- source/mathlib.c | 27 +++++++++++++++++++++------ source/menu.c | 4 ++-- source/net_dgrm.c | 6 +++--- source/net_loop.c | 4 ++-- source/pr_cmds.c | 4 +++- source/snd_dma.c | 2 +- source/sv_main.c | 2 +- 13 files changed, 44 insertions(+), 27 deletions(-) diff --git a/source/cmd.c b/source/cmd.c index 783475f..a4f2c4f 100644 --- a/source/cmd.c +++ b/source/cmd.c @@ -684,7 +684,7 @@ void Cmd_AddCommand (const char *cmd_name, xcommand_t function) // fail if the command already exists for (cmd=cmd_functions ; cmd ; cmd=cmd->next) { - if (!Q_strcmp (cmd_name, cmd->name)) + if (!strcmp (cmd_name, cmd->name)) { Con_Printf ("Cmd_AddCommand: %s already defined\n", cmd_name); return; @@ -727,7 +727,7 @@ qboolean Cmd_Exists (const char *cmd_name) for (cmd=cmd_functions ; cmd ; cmd=cmd->next) { - if (!Q_strcmp (cmd_name,cmd->name)) + if (!strcmp (cmd_name,cmd->name)) return true; } diff --git a/source/common.c b/source/common.c index 6df6d4d..94d2d02 100644 --- a/source/common.c +++ b/source/common.c @@ -1244,7 +1244,7 @@ int COM_CheckParm (const char *parm) { if (!com_argv[i]) continue; // NEXTSTEP sometimes clears appkit vars. - if (!Q_strcmp (parm,com_argv[i])) + if (!strcmp (parm,com_argv[i])) return i; } @@ -1303,7 +1303,7 @@ void COM_InitArgv (int argc, char **argv) for (com_argc = 0; (com_argc < MAX_NUM_ARGVS) && (com_argc < argc); com_argc++) { largv[com_argc] = argv[com_argc]; - if (!Q_strcmp ("-safe", argv[com_argc])) + if (!strcmp ("-safe", argv[com_argc])) safemode = 1; } diff --git a/source/console.c b/source/console.c index 591ec7c..656540e 100644 --- a/source/console.c +++ b/source/console.c @@ -1030,7 +1030,7 @@ void Con_TabComplete (void) match = keydown[K_SHIFT] ? t->prev->name : t->name; do { - if (!Q_strcmp(t->name, partial)) + if (!strcmp(t->name, partial)) { match = keydown[K_SHIFT] ? t->prev->name : t->next->name; break; diff --git a/source/cvar.c b/source/cvar.c index aaa8089..9fb4b7c 100644 --- a/source/cvar.c +++ b/source/cvar.c @@ -251,7 +251,7 @@ cvar_t *Cvar_FindVar (const char *var_name) for (var = cvar_vars ; var ; var = var->next) { - if (!Q_strcmp(var_name, var->name)) + if (!strcmp(var_name, var->name)) return var; } diff --git a/source/gl_texmgr.c b/source/gl_texmgr.c index 050901d..e630911 100644 --- a/source/gl_texmgr.c +++ b/source/gl_texmgr.c @@ -138,7 +138,7 @@ static void TexMgr_TextureMode_f (cvar_t *var) for (i = 0; i < NUM_GLMODES; i++) { - if (!Q_strcmp (glmodes[i].name, gl_texturemode.string)) + if (!strcmp (glmodes[i].name, gl_texturemode.string)) { if (glmode_idx != i) { diff --git a/source/host_cmd.c b/source/host_cmd.c index 94c6b2e..0953f80 100644 --- a/source/host_cmd.c +++ b/source/host_cmd.c @@ -67,7 +67,7 @@ void FileList_Add (const char *name, filelist_item_t **list) // ignore duplicate for (item = *list; item; item = item->next) { - if (!Q_strcmp (name, item->name)) + if (!strcmp (name, item->name)) return; } @@ -1286,7 +1286,7 @@ void Host_Name_f (void) if (cmd_source == src_command) { - if (Q_strcmp(cl_name.string, newName) == 0) + if (strcmp(cl_name.string, newName) == 0) return; Cvar_Set ("_cl_name", newName); if (cls.state == ca_connected) @@ -1296,7 +1296,7 @@ void Host_Name_f (void) if (host_client->name[0] && strcmp(host_client->name, "unconnected") ) { - if (Q_strcmp(host_client->name, newName) != 0) + if (strcmp(host_client->name, newName) != 0) Con_Printf ("%s renamed to %s\n", host_client->name, newName); } Q_strcpy (host_client->name, newName); @@ -1778,7 +1778,7 @@ void Host_Kick_f (void) save = host_client; - if (Cmd_Argc() > 2 && Q_strcmp(Cmd_Argv(1), "#") == 0) + if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0) { i = Q_atof(Cmd_Argv(2)) - 1; if (i < 0 || i >= svs.maxclients) diff --git a/source/mathlib.c b/source/mathlib.c index 7928baa..300e526 100644 --- a/source/mathlib.c +++ b/source/mathlib.c @@ -32,6 +32,23 @@ float _mathlib_temp_float1, _mathlib_temp_float2, _mathlib_temp_float3; //#define DEG2RAD( a ) ( a * M_PI ) / 180.0F #define DEG2RAD( a ) ( (a) * M_PI_DIV_180 ) //johnfitz +float rsqrt( float number ) +{ + int i; + float x, y; + + if( number == 0.0f ) + return 0.0f; + + x = number * 0.5f; + i = *(int *)&number; // evil floating point bit level hacking + i = 0x5f3759df - (i >> 1); // what the fuck? + y = *(float *)&i; + y = y * (1.5f - (x * y * y)); // first iteration + + return y; +} + void SinCos( float radians, float *sine, float *cosine ) { *sine = sin(radians); @@ -335,20 +352,18 @@ vec_t Length(vec3_t v) float VectorNormalize (vec3_t v) { - float length, ilength; + float ilength; - length = sqrt(DotProduct(v,v)); + ilength = rsqrt(DotProduct(v,v)); - if (length) + if (ilength) { - ilength = 1/length; v[0] *= ilength; v[1] *= ilength; v[2] *= ilength; } - return length; - + return ilength; } void VectorInverse (vec3_t v) diff --git a/source/menu.c b/source/menu.c index ea95449..458ad35 100644 --- a/source/menu.c +++ b/source/menu.c @@ -2055,9 +2055,9 @@ forward: goto forward; // setup_cursor == 4 (OK) - if (Q_strcmp(cl_name.string, setup_myname) != 0) + if (strcmp(cl_name.string, setup_myname) != 0) Cbuf_AddText ( va ("name \"%s\"\n", setup_myname) ); - if (Q_strcmp(hostname.string, setup_hostname) != 0) + if (strcmp(hostname.string, setup_hostname) != 0) Cvar_Set("hostname", setup_hostname); if (setup_top != setup_oldtop || setup_bottom != setup_oldbottom) Cbuf_AddText( va ("color %i %i\n", setup_top, setup_bottom) ); diff --git a/source/net_dgrm.c b/source/net_dgrm.c index 93287bb..c448814 100644 --- a/source/net_dgrm.c +++ b/source/net_dgrm.c @@ -458,7 +458,7 @@ static void NET_Stats_f (void) Con_Printf("shortPacketCount = %i\n", shortPacketCount); Con_Printf("droppedDatagrams = %i\n", droppedDatagrams); } - else if (Q_strcmp(Cmd_Argv(1), "*") == 0) + else if (strcmp(Cmd_Argv(1), "*") == 0) { for (s = net_activeSockets; s; s = s->next) PrintStats(s); @@ -891,7 +891,7 @@ static qsocket_t *_Datagram_CheckNewConnections (void) command = MSG_ReadByte(); if (command == CCREQ_SERVER_INFO) { - if (Q_strcmp(MSG_ReadString(), "QUAKE") != 0) + if (strcmp(MSG_ReadString(), "QUAKE") != 0) return NULL; SZ_Clear(&net_message); @@ -980,7 +980,7 @@ static qsocket_t *_Datagram_CheckNewConnections (void) if (command != CCREQ_CONNECT) return NULL; - if (Q_strcmp(MSG_ReadString(), "QUAKE") != 0) + if (strcmp(MSG_ReadString(), "QUAKE") != 0) return NULL; if (MSG_ReadByte() != NET_PROTOCOL_VERSION) diff --git a/source/net_loop.c b/source/net_loop.c index 8cb22db..bcd385d 100644 --- a/source/net_loop.c +++ b/source/net_loop.c @@ -54,7 +54,7 @@ void Loop_SearchForHosts (qboolean xmit) return; hostCacheCount = 1; - if (Q_strcmp(hostname.string, "UNNAMED") == 0) + if (strcmp(hostname.string, "UNNAMED") == 0) Q_strcpy(hostcache[0].name, "local"); else Q_strcpy(hostcache[0].name, hostname.string); @@ -68,7 +68,7 @@ void Loop_SearchForHosts (qboolean xmit) qsocket_t *Loop_Connect (const char *host) { - if (Q_strcmp(host,"local") != 0) + if (strcmp(host,"local") != 0) return NULL; localconnectpending = true; diff --git a/source/pr_cmds.c b/source/pr_cmds.c index 903dfaa..604dbb1 100644 --- a/source/pr_cmds.c +++ b/source/pr_cmds.c @@ -1158,6 +1158,7 @@ static void PF_findradius (void) org = G_VECTOR(OFS_PARM0); rad = G_FLOAT(OFS_PARM1); + rad *= rad; ent = NEXT_EDICT(sv.edicts); for (i = 1; i < sv.num_edicts; i++, ent = NEXT_EDICT(ent)) @@ -1168,7 +1169,8 @@ static void PF_findradius (void) continue; for (j = 0; j < 3; j++) eorg[j] = org[j] - (ent->v.origin[j] + (ent->v.mins[j] + ent->v.maxs[j]) * 0.5); - if (VectorLength(eorg) > rad) + + if (DotProduct(eorg, eorg) > rad) continue; ent->v.chain = EDICT_TO_PROG(chain); diff --git a/source/snd_dma.c b/source/snd_dma.c index ac912c9..0d2f1b7 100644 --- a/source/snd_dma.c +++ b/source/snd_dma.c @@ -278,7 +278,7 @@ static sfx_t *S_FindName (const char *name) // see if already loaded for (i = 0; i < num_sfx; i++) { - if (!Q_strcmp(known_sfx[i].name, name)) + if (!strcmp(known_sfx[i].name, name)) { return &known_sfx[i]; } diff --git a/source/sv_main.c b/source/sv_main.c index 5148e9f..09f98ae 100644 --- a/source/sv_main.c +++ b/source/sv_main.c @@ -1004,7 +1004,7 @@ qboolean SV_SendClientDatagram (client_t *client) msg.cursize = 0; //johnfitz -- if client is nonlocal, use smaller max size so packets aren't fragmented - if (Q_strcmp(NET_QSocketGetAddressString(client->netconnection), "LOCAL") != 0) + if (strcmp(NET_QSocketGetAddressString(client->netconnection), "LOCAL") != 0) msg.maxsize = DATAGRAM_MTU; //johnfitz