News for hackers. Stuff that matters.
Re:Source code for Quake 2 rerelease by _flux on Friday August 11, 2023 @05:21AM (#37086700)
Using % vs comparison and reset was probably more efficient with the compilers of the time; might still be.

Also I doubt everyone would agree that the one exit condition is more clear. For example, if I know that if e->inuse is 0 it will continue with the next round. Arguably it's more difficult to understand that from the single combined expression—because it isn't so: if !e->inuse but e == ent->client->chase_target, the original will loop but yours will exit.

Though I'm guessing ent->client->chase_target->inuse is probably never 0.

Re:Source code for Quake 2 rerelease by augustk on Friday August 11, 2023 @05:52AM (#37086869)
> if !e->inuse but e == ent->client->chase_target, the original will loop but yours will exit.

No, the continue statement will jump to the test part also for `do' loops:

"The continue statement is related to break, but less often used; it causes the next iteration of the enclosing for, while, or do loop to begin. In the while and do, this means that the test part is executed immediately"

-- "The C programming language (Second Edition)"

Re:Source code for Quake 2 rerelease by _flux on Friday August 11, 2023 @09:45AM (#37088618)
Well today I have learned something I may have forgotten, thank you :). It seems natural in for and while so it does make sense also the do loops use it.
Re:Source code for Quake 2 rerelease by scott_s on Friday August 11, 2023 @11:11AM (#37089591)
Seconded that the main reason was probably avoiding a mod. But it's not because of the compiler, but the processor. Mod and division instructions are always more expensive than additions and multiplications. If this function was on the hot path (and looking at where it's called, it's at least called once per frame), that may have mattered a lot.
Re:Source code for Quake 2 rerelease by Sharlin on Friday August 11, 2023 @12:41PM (#37090725)
A modern optimizing compiler would quite likely do induction variable elimination/strength reduction and replace the % with increment-and-reset if it deemed it worth it, so it’s also about the compiler.