cocks gun, blows brains out
(Yes I know the evil goto supposedly has its time and place, blah blah blah)
cocks gun, blows brains out
(Yes I know the evil goto supposedly has its time and place, blah blah blah)
Goto is just fine if it is used responsibly.
[1]: http://sourceforge.net/p/jediacademy/code/ci/4bebb8ec23200ee...
People start with a clean model of how the player should move, using minimal physics, then add layer upon layer of special case code for various environmental / state / networking edge-cases.
I've heard looking at the first person movement code for Valve's games will make you wish for your own death, but stripping out the weird stuff which looks ideologically wrong just makes the game play worse.
The nesting is too deep imho, but apart from that it looks ok. This looks more like a design problem, because there are lots of special cases, but the code style is ok.
That function is almost 1500 lines long, full of complex nested if conditions and commented out blocks. I understand how code (especially game character control code) grows to become like that, and I've probably been guilty of some similar horrors myself, but the most I can do with such code style is excuse it.
I know that object-oriented best practice would suggest a lot of different classes and using dynamic dispatch for switching. That might even be faster. However, I dislike the fact that this scatters the logic across hundreds of files.
The best solution would be to simplify the logic, but this is also the most costly/time consuming variant.
For example, codemp/game/g_saga.c uses goto just fine. Three "goto failure" jump to the end of the function to handle the error case differently than a normal return. Not a very good example for proper goto use, but ok.
In contrast, codemp/cgame/cg_players.c should be refactored. It seems to be model loading code. If the loading fails, some gotos jump to the start of the function and using a flag variable a default model "kyle" is used instead of the arguments. If the default model is broken, this becomes an infinite loop. My style suggestion:
if (loadModel(foo)) return;
if (loadModel(default)) return;
assert (false && "fallback/default model broken");