From: terencehill Date: Tue, 23 Jul 2024 23:32:57 +0000 (+0200) Subject: A few minor optimizations: X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=a4b0a2d6a9fb14c23c117232f28f303180728790;p=xonotic%2Fxonotic-data.pk3dir.git A few minor optimizations: * Optimize swapwords and consequently shufflewords (which is called by g_maplist_shuffle) a little bit * Avoid setting filename when not needed in Map_Check (called many times when the map vote starts) * Save a few normalize calls in findtrajectorywithleading (called when bots use weapons like mortar and electro that fire projectiles with gravity) findtrajectorywithleading patch probably causes a hash change due to extremely small aim direction changes (always < 0.0005) that at some point change the course of the bot match --- diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 590ab8175..81bb63ba4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -36,7 +36,7 @@ test_compilation_units: test_sv_game: stage: test script: - - export EXPECT=0406faebe1f4903266061f43557d0b1b + - export EXPECT=14b3e3e34253d4b41325080e77317d58 - qcsrc/tools/sv_game-hashtest.sh - exit $? diff --git a/qcsrc/lib/string.qh b/qcsrc/lib/string.qh index 743f4310b..f3fbc6bc2 100644 --- a/qcsrc/lib/string.qh +++ b/qcsrc/lib/string.qh @@ -297,10 +297,9 @@ string substring_range(string s, float b, float e) ERASEABLE string swapwords(string str, float i, float j) { - float n; string s1, s2, s3, s4, s5; float si, ei, sj, ej, s0, en; - n = tokenizebyseparator(str, " "); // must match g_maplist processing in ShuffleMaplist and "shuffle" + int n = tokenizebyseparator(str, " "); // must match g_maplist processing in ShuffleMaplist and "shuffle" si = argv_start_index(i); sj = argv_start_index(j); ei = argv_end_index(i); @@ -308,9 +307,9 @@ string swapwords(string str, float i, float j) s0 = argv_start_index(0); en = argv_end_index(n - 1); s1 = substring_range(str, s0, si); - s2 = substring_range(str, si, ei); + s2 = argv(i); s3 = substring_range(str, ei, sj); - s4 = substring_range(str, sj, ej); + s4 = argv(j); s5 = substring_range(str, ej, en); return strcat(s1, s4, s3, s2, s5); } diff --git a/qcsrc/server/bot/default/aim.qc b/qcsrc/server/bot/default/aim.qc index c058c06f5..40a61fb40 100644 --- a/qcsrc/server/bot/default/aim.qc +++ b/qcsrc/server/bot/default/aim.qc @@ -33,7 +33,8 @@ float findtrajectorywithleading(vector org, vector m1, vector m2, entity targ, f tracebox(o, targ.mins, targ.maxs, v, false, targ); v = trace_endpos; end = v + (targ.mins + targ.maxs) * 0.5; - if ((vlen(end - org) / shotspeed + 0.2) > maxtime) + float shotdistance = max(0.001, vlen(end - org)); + if ((shotdistance / shotspeed + 0.2) > maxtime) { // out of range targ.solid = savesolid; @@ -51,11 +52,13 @@ float findtrajectorywithleading(vector org, vector m1, vector m2, entity targ, f setorigin(tracetossfaketarget, v); c = 0; - dir = normalize(end - org); + dir = (end - org) / shotdistance; // same as dir = normalize(end - org); but cheaper + vector test_dir = dir; + vector test_dir_normalized = dir; while (c < 10) // 10 traces { setorigin(tracetossent, org); // reset - tracetossent.velocity = findtrajectory_velocity = normalize(dir) * shotspeed + shotspeedupward * '0 0 1'; + tracetossent.velocity = findtrajectory_velocity = test_dir_normalized * shotspeed + shotspeedupward * '0 0 1'; tracetoss(tracetossent, ignore); // love builtin functions... if (trace_ent == tracetossfaketarget) // done { @@ -71,7 +74,8 @@ float findtrajectorywithleading(vector org, vector m1, vector m2, entity targ, f return true; } - dir.z = dir.z + 0.1; // aim up a little more + test_dir.z += 0.1; // aim up a little more + test_dir_normalized = normalize(test_dir); c = c + 1; } targ.solid = savesolid; @@ -85,7 +89,7 @@ float findtrajectorywithleading(vector org, vector m1, vector m2, entity targ, f setorigin(tracetossfaketarget, v); // leave a valid one even if it won't reach - findtrajectory_velocity = normalize(end - org) * shotspeed + shotspeedupward * '0 0 1'; + findtrajectory_velocity = dir * shotspeed + shotspeedupward * '0 0 1'; return false; } diff --git a/qcsrc/server/intermission.qc b/qcsrc/server/intermission.qc index 713a72052..9749a95d2 100644 --- a/qcsrc/server/intermission.qc +++ b/qcsrc/server/intermission.qc @@ -116,15 +116,12 @@ bool Map_IsRecent(string m) bool Map_Check(int position, float pass) { - string filename; - string map_next; - map_next = argv(position); + string map_next = argv(position); if(pass <= 1) { if(Map_IsRecent(map_next)) return false; } - filename = Map_Filename(position); if(MapInfo_CheckMap(map_next)) { if(pass == 2) @@ -137,7 +134,10 @@ bool Map_Check(int position, float pass) return false; } else + { + string filename = Map_Filename(position); LOG_DEBUG( "Couldn't select '", filename, "'..." ); + } return false; }