https://github.com/raxod502/TerrariaClone/blob/master/src/Do...
which is fortunately only used in a comment here: https://github.com/raxod502/TerrariaClone/blob/9ea04b15add48...
https://github.com/raxod502/TerrariaClone/blob/master/src/Do...
which is fortunately only used in a comment here: https://github.com/raxod502/TerrariaClone/blob/9ea04b15add48...
It's actually a method to convert from the index of an inventory hotkey slot into the keystroke used to access it -- there were ten hotkey slots, which were numbered 1–9 and 0 at the end.
But I like all the other interesting interpretations here :P (They all assume way more knowledge than I had at the time.)
There's an example on SO, I got similar results just now when I replicated it:
https://stackoverflow.com/questions/15596318/is-it-better-to...
It doesn't matter on my machine whether the divisor is 10 or 42 (as in the example), the branching is way faster. Now, maybe if the branching were not in a loop and hence not so easily predicted, it wouldn't make a difference. But if this code is not being used in a loop, optimization may be premature anyway (as indicated in my original comment).
Probably f() has something to do inside the main game loop and gets called on a bunch of objects every frame. I haven't looked at the code enough to know if that's a bottleneck.
And the branch instruction is free??
Yeah, no, that's not free.
I can confirm that the actual reason is that at the time I thought typing "print" instead of "System.out.println" was a great idea.