]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
micro-optimization chore: in for-loops change all post-{in,de}crements to pre-{in...
authorDr. Jaska <drjaska83@gmail.com>
Fri, 15 Mar 2024 22:39:19 +0000 (22:39 +0000)
committerDr. Jaska <drjaska83@gmail.com>
Fri, 15 Mar 2024 22:39:19 +0000 (22:39 +0000)
22 files changed:
qcsrc/client/main.qc
qcsrc/common/minigames/cl_minigames.qc
qcsrc/common/minigames/minigame/nmm.qc
qcsrc/common/minigames/minigame/pong.qc
qcsrc/common/mutators/mutator/nades/nades.qc
qcsrc/common/mutators/mutator/nades/nades.qh
qcsrc/common/mutators/mutator/sandbox/sv_sandbox.qc
qcsrc/common/notifications/all.qc
qcsrc/common/physics/movetypes/movetypes.qc
qcsrc/common/physics/movetypes/toss.qc
qcsrc/common/playerstats.qc
qcsrc/common/util.qc
qcsrc/common/weapons/weapon/vaporizer.qc
qcsrc/ecs/systems/physics.qc
qcsrc/lib/json.qc
qcsrc/lib/string.qh
qcsrc/menu/xonotic/maplist.qc
qcsrc/menu/xonotic/weaponarenacheckbox.qc
qcsrc/server/bot/default/waypoints.qc
qcsrc/server/items/items.qc
qcsrc/server/weapons/accuracy.qc
qcsrc/server/world.qc

index e30f9bbcb21d481cbbfe9cb156bf8332f1a3b3cf..90917341a29a67bbc69e9f0cc74a05328015cd0c 100644 (file)
@@ -1381,7 +1381,7 @@ string translate_weaponarena(string s)
 
        int n = tokenizebyseparator(s, " & ");
        string wpn_list = "";
-       for (int i = 0; i < n; i++)
+       for (int i = 0; i < n; ++i)
        {
                Weapon wep = Weapon_from_name(argv(i));
                if (wep == WEP_Null)
index eaf8e0d65b7ae01c523ca23acd587fda0b311280..df6f77a4fa1be1d798c6960028814b22cd3640bf 100644 (file)
@@ -262,7 +262,7 @@ string minigame_getWrappedLine(float w, vector theFontSize, textLengthUpToWidth_
                take_until = strlen(s);
 
        int skip = 0;
-       for ( int i = 0; i < take_until; i++ )
+       for ( int i = 0; i < take_until; ++i )
                if ( substring(s,i,1) == "\n" )
                {
                        take_until = i;
@@ -364,7 +364,7 @@ void minigame_cmd_workaround(float dummy, string...cmdargc)
        string cmd;
        cmd = "cmd minigame ";
        float i;
-       for ( i = 0; i < cmdargc; i++ )
+       for ( i = 0; i < cmdargc; ++i )
                cmd = strcat(cmd,...(i,string));
        localcmd(strcat(cmd,"\n"));
 }
index b550f79a35d21de9efba4723986397f46d18ded5..a54df3b74db3382d467ac5cf5cfbbf78aa40126e 100644 (file)
@@ -101,10 +101,10 @@ void nmm_spawn_tile_square( entity minig, int offset, int skip )
 {
        int letter = offset;
        int number = offset;
-       for ( int i = 0; i < 3; i++ )
+       for ( int i = 0; i < 3; ++i )
        {
                number = offset;
-               for ( int j = 0; j < 3; j++ )
+               for ( int j = 0; j < 3; ++j )
                {
                        if ( i != 1 || j != 1 )
                                nmm_spawn_tile(strzone(minigame_tile_buildname(letter,number)),minig, skip+1);
@@ -175,7 +175,7 @@ bool nmm_tile_canmove(entity tile)
 bool nmm_in_mill_string(entity tile, string s)
 {
        int argc = tokenize(s);
-       for ( int i = 0; i < argc; i++ )
+       for ( int i = 0; i < argc; ++i )
        {
                entity e = nmm_find_tile(tile.owner,argv(i));
                if ( !e || !e.nmm_tile_piece || e.nmm_tile_piece.team != tile.nmm_tile_piece.team )
@@ -223,7 +223,7 @@ int nmm_server_event(entity minigame, string event, ...)
                minigame.minigame_flags = NMM_TURN_PLACE|NMM_TURN_TEAM1;
                nmm_init_tiles(minigame);
                entity e;
-               for ( int i = 0; i < 7; i++ )
+               for ( int i = 0; i < 7; ++i )
                {
                        e = msle_spawn(minigame,new(minigame_board_piece));
                        e.team = 1;
index 4acad766cb4e5336a9f06fbbd7e9da5f4e786090..17c92d8d6ad9672dc75043be01c061dbb77bd4ab 100644 (file)
@@ -162,7 +162,7 @@ void pong_ball_think(entity this)
        this.SendFlags |= MINIG_SF_UPDATE;
 
        int i;
-       for ( i = 1; i <= PONG_MAX_PLAYERS; i++ )
+       for ( i = 1; i <= PONG_MAX_PLAYERS; ++i )
                if ( pong_paddle_hit(this, i) )
                {
                        pong_paddle_bounce(this,i);
@@ -357,7 +357,7 @@ int pong_server_event(entity minigame, string event, ...)
 
                        entity player = ...(0,entity);
                        int i;
-                       for ( i = 0; i < PONG_MAX_PLAYERS; i++ )
+                       for ( i = 0; i < PONG_MAX_PLAYERS; ++i )
                        {
                                if ( minigame.pong_paddles[i] == NULL )
                                {
@@ -374,7 +374,7 @@ int pong_server_event(entity minigame, string event, ...)
                        entity paddle;
                        entity ai;
                        int i;
-                       for ( i = 0; i < PONG_MAX_PLAYERS; i++ )
+                       for ( i = 0; i < PONG_MAX_PLAYERS; ++i )
                        {
                                paddle = minigame.pong_paddles[i];
                                if ( paddle != NULL && paddle.realowner == player )
@@ -403,7 +403,7 @@ int pong_server_event(entity minigame, string event, ...)
                                                minigame.SendFlags |= MINIG_SF_UPDATE;
 
                                                entity ball;
-                                               for ( int j = 0; j < autocvar_sv_minigames_pong_ball_number; j++ )
+                                               for ( int j = 0; j < autocvar_sv_minigames_pong_ball_number; ++j )
                                                {
                                                        ball = msle_spawn(minigame,new(pong_ball));
                                                        ball.pong_length = autocvar_sv_minigames_pong_ball_radius;
@@ -447,8 +447,8 @@ int pong_server_event(entity minigame, string event, ...)
                                        // potentially compiler bug
                                        int j;
                                        if ( minigame.minigame_flags & PONG_STATUS_WAIT )
-                                               for ( j = 0; j < PONG_MAX_PLAYERS; j++ )
-                                               //for ( int j = 0; j < PONG_MAX_PLAYERS; j++ )
+                                               for ( j = 0; j < PONG_MAX_PLAYERS; ++j )
+                                               //for ( int j = 0; j < PONG_MAX_PLAYERS; ++j )
                                                {
                                                        if ( minigame.pong_paddles[j] == NULL )
                                                        {
@@ -466,7 +466,7 @@ int pong_server_event(entity minigame, string event, ...)
                                        if ( minigame.minigame_flags & PONG_STATUS_WAIT )
                                        {
                                                entity paddle;
-                                               for ( int j = PONG_MAX_PLAYERS-1; j >= 0; j-- )
+                                               for ( int j = PONG_MAX_PLAYERS-1; j >= 0; --j )
                                                {
                                                        paddle = minigame.pong_paddles[j];
                                                        if ( paddle != NULL &&
index 3f9e54cdbd97b40d9c153198c9eeccad918ab9e1..e32cd20d8ab87eeb54f7fd1fff678886a9b6682b 100644 (file)
@@ -24,7 +24,7 @@ entity Nade_TrailEffect(int proj, int nade_team)
     }
 
     FOREACH(Nades, true, {
-        for (int j = 0; j < 2; j++)
+        for (int j = 0; j < 2; ++j)
         {
             if (it.m_projectile[j] == proj)
             {
@@ -390,7 +390,7 @@ void napalm_fountain_think(entity this)
 
 void nade_napalm_boom(entity this)
 {
-       for (int c = 0; c < autocvar_g_nades_napalm_ball_count; c++)
+       for (int c = 0; c < autocvar_g_nades_napalm_ball_count; ++c)
                nade_napalm_ball(this);
 
        entity fountain = new(nade_napalm_fountain);
index 7888da7d1bf718e750a5b99bea732405b7dbfe92..9c8aeedec86f9449dc5e3d80616ed177207fd970 100644 (file)
@@ -136,7 +136,7 @@ REGISTRY_DEFINE_GET(Nades, NADE_TYPE_Null)
 Nade Nade_FromProjectile(int proj)
 {
     FOREACH(Nades, true, {
-        for (int j = 0; j < 2; j++)
+        for (int j = 0; j < 2; ++j)
         {
             if (it.m_projectile[j] == proj) return it;
         }
index a31eee2ba49db3dba85272725628fddf4317f344..a387af90f1d58f2d6b098a279603e7e9c2e6c279 100644 (file)
@@ -437,7 +437,7 @@ void sandbox_Database_Load()
                        if(e.material)
                        {
                                // since objects are being loaded for the first time, precache material sounds for each
-                               for (i = 1; i <= 5; i++) // 5 sounds in total
+                               for (i = 1; i <= 5; ++i) // 5 sounds in total
                                        precache_sound(strcat("object/impact_", e.material, "_", ftos(i), ".wav"));
                        }
                }
@@ -714,7 +714,7 @@ MUTATOR_HOOKFUNCTION(sandbox, SV_ParseClientCommand)
                                                        strfree(e.material);
                                                        if(argv(3))
                                                        {
-                                                               for (j = 1; j <= 5; j++) // precache material sounds, 5 in total
+                                                               for (j = 1; j <= 5; ++j) // precache material sounds, 5 in total
                                                                        precache_sound(strcat("object/impact_", argv(3), "_", ftos(j), ".wav"));
                                                                e.material = strzone(argv(3));
                                                        }
index 58910887e914a87c70393d5e0e043d6403495acb..dd200973bc007804c28258c12343b02130d6ec55 100644 (file)
@@ -1181,7 +1181,7 @@ void Local_Notification_centerprint_Add(
 }
 
 void Local_Notification_Queue_Run(MSG net_type, entity notif)
-{              
+{
        switch (net_type)
        {
                case MSG_ANNCE:
@@ -1193,7 +1193,7 @@ void Local_Notification_Queue_Run(MSG net_type, entity notif)
 }
 
 void Local_Notification_Queue_Add(MSG net_type, entity notif, float queue_time)
-{      
+{
        // Guess length if required
        if(queue_time == 0)
                queue_time = soundlength(AnnouncerFilename(notif.nent_snd));
@@ -1205,11 +1205,11 @@ void Local_Notification_Queue_Add(MSG net_type, entity notif, float queue_time)
        } else {
                // Put in queue
                if(notif_queue_length >= NOTIF_QUEUE_MAX) return;
-       
+
                notif_queue_type[notif_queue_length] = net_type;
                notif_queue_entity[notif_queue_length] = notif;
                notif_queue_time[notif_queue_length] = notif_queue_next_time;
-               
+
                notif_queue_next_time += queue_time;
                ++notif_queue_length;
        }
@@ -1224,7 +1224,7 @@ void Local_Notification_Queue_Process()
 
        // Shift queue to the left
        --notif_queue_length;
-       for (int j = 0; j < notif_queue_length; j++) {
+       for (int j = 0; j < notif_queue_length; ++j) {
                notif_queue_type[j] = notif_queue_type[j+1];
                notif_queue_entity[j] = notif_queue_entity[j+1];
                notif_queue_time[j] = notif_queue_time[j+1];
index 73ceb57b0621f85ce638add082b9ffb0b268a58f..2c54617ef208c689b60f07b7cc7f2438d0618f7d 100644 (file)
@@ -20,7 +20,7 @@ bool _Movetype_NudgeOutOfSolid_PivotIsKnownGood(entity this, vector pivot) // SV
 {
        vector stuckorigin = this.origin;
        vector goodmins = pivot, goodmaxs = pivot;
-       for(int bump = 0; bump < 6; bump++)
+       for(int bump = 0; bump < 6; ++bump)
        {
                int coord = 2 - (bump >> 1);
                int dir = (bump & 1);
@@ -150,7 +150,7 @@ int _Movetype_FlyMove(entity this, float dt, bool applygravity, bool applystepno
 
        original_velocity = primal_velocity = this.velocity;
 
-       for(int bumpcount = 0;bumpcount < MAX_CLIP_PLANES;bumpcount++)
+       for(int bumpcount = 0;bumpcount < MAX_CLIP_PLANES; ++bumpcount)
        {
                if(this.velocity == '0 0 0')
                        break;
@@ -265,11 +265,11 @@ int _Movetype_FlyMove(entity this, float dt, bool applygravity, bool applystepno
                // modify original_velocity so it parallels all of the clip planes
                vector new_velocity = '0 0 0';
                int plane;
-               for (plane = 0;plane < numplanes;plane++)
+               for (plane = 0;plane < numplanes; ++plane)
                {
                        int newplane;
                        new_velocity = _Movetype_ClipVelocity(original_velocity, planes[plane], 1);
-                       for (newplane = 0;newplane < numplanes;newplane++)
+                       for (newplane = 0;newplane < numplanes; ++newplane)
                        {
                                if(newplane != plane)
                                {
index 5c254811d181c2cac9f5a5496490ae442241d403..caf1fda477b8521b155194e507a3c6f56e5c1f4d 100644 (file)
@@ -48,7 +48,7 @@ void _Movetype_Physics_Toss(entity this, float dt)  // SV_Physics_Toss
        this.angles = this.angles + this.avelocity * dt;
 
        float movetime = dt;
-       for (int bump = 0; bump < MAX_CLIP_PLANES && movetime > 0; bump++)
+       for (int bump = 0; bump < MAX_CLIP_PLANES && movetime > 0; ++bump)
        {
                if(this.velocity == '0 0 0')
                        break;
index 9744eda19231c450315c6984af9a690bdae6b36f..c2adabb1b601c415710a4768bbead49959c32934 100644 (file)
@@ -47,7 +47,7 @@ void PlayerStats_GameReport_Reset_All()
        if(PS_GR_OUT_DB < 0)
                return;
 
-       for (int i = 0; i < 16; i++)
+       for (int i = 0; i < 16; ++i)
                if (teamscorekeepers[i])
                        PlayerStats_GameReport_AddTeam(i + 1);
        FOREACH_CLIENT(true, {
index 1bb77a1f5af176cb800e0894dace887c0b6ba49c..d9a098691b11e3133493bcbf73fd696fc119b839 100644 (file)
@@ -239,7 +239,7 @@ string build_mutator_list(string s)
                n = tokenizebyseparator(s, ", ");
        }
        string s2 = "";
-       for (string arg = ""; i < n; i++)
+       for (string arg = ""; i < n; ++i)
        {
                if (i >= 0) arg = argv(i);
                // cond is the condition for showing the mutator enabled in the menu
index 9ca0b3192d71f5394879ed6c0e64f7eb38953eb1..4066efc4e00d0d346bc662f2088829ec7228972c 100644 (file)
@@ -201,7 +201,7 @@ void W_RocketMinsta_Attack(entity actor, .entity weaponentity, int mode)
        // uses electro effects
        W_MuzzleFlash(WEP_ELECTRO, actor, weaponentity, w_shotorg, w_shotdir);
 
-       for (int counter = 0; counter < total; counter++)
+       for (int counter = 0; counter < total; ++counter)
        {
                proj = new(plasma_prim);
                proj.owner = proj.realowner = actor;
index c7fc88dc93593159e524a4e9920b32481362fdf2..a68faea4465c23bdd1601fccfd37e9c185d31c76 100644 (file)
@@ -437,7 +437,7 @@ void sys_phys_simulate_simple(entity this, float dt)
 
        this.angles += dt * this.avelocity;
        float movetime = dt;
-       for (int i = 0; i < MAX_CLIP_PLANES && movetime > 0; i++) {
+       for (int i = 0; i < MAX_CLIP_PLANES && movetime > 0; ++i) {
                vector push = vel * movetime;
                vector p0 = pos;
                vector p1 = p0 + push;
index b477fe15e59124924662e4c463030ff7016ca94e..c75dc8eece2bb3f7f030df5786052c7fb163b48e 100644 (file)
@@ -76,7 +76,7 @@ bool _json_parse_array() {
     int len = bufstr_add(_json_buffer, "0", 0);
     if (len) bufstr_set(_json_buffer, len - 1, strcat(bufstr_get(_json_buffer, len - 1), ".length"));
     bool required = false;
-    for (int n = 0; ; n++) {
+    for (int n = 0; ; ++n) {
         string key = ftos(n);
         key = _json_ns ? strcat(_json_ns, ".", key) : key;
         int it = bufstr_add(_json_buffer, key, 0);
index 72673b2354517e28c5abd96c1cc1eb8f160b5b70..743f4310bac53d214f7f808372fcd369a4971d8b 100644 (file)
@@ -570,7 +570,7 @@ vector checkColorCode(string theText, int text_len, int pos, bool check_at_the_e
        int ofs = cc_len;
        if (!check_at_the_end)
                ofs--;
-       for (; ofs >= 1; ofs--)
+       for (; ofs >= 1; --ofs)
        {
                if (!(pos >= ofs && text_len >= pos + (cc_len - ofs)))
                        continue;
index 81bf34e5226a3d3737939bc9a5e3e50232353227..89748e85c3647dda4ac36afc3c06e08e83f3a166 100644 (file)
@@ -234,7 +234,7 @@ void MapList_Add_Shown(entity btn, entity me)
 {
        float i, n;
        n = strlen(me.g_maplistCache);
-       for (i = 0 ; i < n; i++)
+       for (i = 0 ; i < n; ++i)
        {
                if (!me.g_maplistCacheQuery(me, i))
                        me.g_maplistCacheToggle(me, i);
@@ -246,7 +246,7 @@ void MapList_Remove_Shown(entity btn, entity me)
 {
        float i, n;
        n = strlen(me.g_maplistCache);
-       for (i = 0 ; i < n; i++)
+       for (i = 0 ; i < n; ++i)
        {
                if (me.g_maplistCacheQuery(me, i))
                        me.g_maplistCacheToggle(me, i);
index 695b2d7873144974af98443e14ca3f36dd680141..69839ec6073e780d5a4ecb8261f7c9bdd4992d2f 100644 (file)
@@ -22,7 +22,7 @@ void XonoticWeaponarenaCheckBox_setChecked(entity me, float foo)
 void XonoticWeaponarenaCheckBox_loadCvars(entity me)
 {
        int n = tokenize_console(cvar_string("menu_weaponarena"));
-       for (int i = 0; i < n; i++)
+       for (int i = 0; i < n; ++i)
        {
                if(argv(i) == me.netname)
                {
index 0d2ed77acfaf5ec76485cfc1b0e15e3946336802..2a557c5f05f2ad6e1aa17a19625b0225244e6e29 100644 (file)
@@ -170,7 +170,7 @@ void waypoint_getSymmetricalOrigin_cmd(entity caller, bool save, int arg_idx)
 {
        vector org = '0 0 0';
        int ctf_flags = 0;
-       for (int i = 0; i < 6; i++)
+       for (int i = 0; i < 6; ++i)
        {
                if (argv(arg_idx + i) != "")
                        ctf_flags++;
@@ -190,7 +190,7 @@ void waypoint_getSymmetricalOrigin_cmd(entity caller, bool save, int arg_idx)
        else
        {
                vector v1, v2, v3, v4, v5, v6;
-               for (int i = 1; i <= ctf_flags; i++)
+               for (int i = 1; i <= ctf_flags; ++i)
                {
                        if (i == 1) { v1 = stov(argv(arg_idx++)); org = v1 / ctf_flags; }
                        else if (i == 2) { v2 = stov(argv(arg_idx++)); org += v2 / ctf_flags; }
index 820f88ebfe6ee258efc592252ab4480b337d9203..b0b68fd920791b06b850cc3dabef1f047d78e844 100644 (file)
@@ -1275,7 +1275,7 @@ void setItemGroup(entity this)
 
 void setItemGroupCount()
 {
-       for (int k = 1; k <= group_count; k++)
+       for (int k = 1; k <= group_count; ++k)
        {
                int count = 0;
                IL_EACH(g_items, IS_SMALL(it.itemdef) && it.item_group == k, { count++; });
index 150d480ec1e79c2e6496b684d2ca4e7926a4769a..a09719f25416fad9b62461f913660bf626112ff2 100644 (file)
@@ -60,7 +60,7 @@ void accuracy_reset(entity e)
        entity a = CS(e).accuracy;
        if (!a) return;
 
-       for (int i = 0; i < REGISTRY_MAX(Weapons); i++)
+       for (int i = 0; i < REGISTRY_MAX(Weapons); ++i)
        {
                a.accuracy_frags[i] = 0;
                a.accuracy_hit[i] = 0;
index 926349a575665fb8d9c85499557d6be318487a61..90ddd1a9902f4d5a95b65ef640d04ae98244a622 100644 (file)
@@ -2433,7 +2433,7 @@ void RunThink(entity this, float dt)
 
        float oldtime = time; // do we need to save this?
 
-       for (int iterations = 0; iterations < 128 && !wasfreed(this); iterations++)
+       for (int iterations = 0; iterations < 128 && !wasfreed(this); ++iterations)
        {
                time = max(oldtime, this.nextthink);
                this.nextthink = 0;