Live data from Hacker News

Jedi Knight 2 And 3 Source Code Released

rockpapershotgun.com

1–10 of 31 posts

Re: Jedi Knight 2 And 3 Source Code Released

#3
post #2

Searching 1897 files for "goto " ... 603 matches across 121 files cocks gun, blows brains out (Yes I know the evil goto supposedly has its time and place, blah blah blah)

What's the most popular "proper" use of goto in the code? The implementations of finite state machines?

Re: Jedi Knight 2 And 3 Source Code Released

#5
post #2

Searching 1897 files for "goto " ... 603 matches across 121 files cocks gun, blows brains out (Yes I know the evil goto supposedly has its time and place, blah blah blah)

If you are going to write functions like this [1], gotos are not your worst problem. :)

[1]: http://sourceforge.net/p/jediacademy/code/ci/4bebb8ec23200ee...

Re: Jedi Knight 2 And 3 Source Code Released

#6
post #3
post #2

Searching 1897 files for "goto " ... 603 matches across 121 files cocks gun, blows brains out (Yes I know the evil goto supposedly has its time and place, blah blah blah)

What's the most popular "proper" use of goto in the code? The implementations of finite state machines?

I would guess error handing (freeing memory, closing fd's). A goto lets you avoid deeply nested if statements.

Re: Jedi Knight 2 And 3 Source Code Released

#7
post #5
post #2

Searching 1897 files for "goto " ... 603 matches across 121 files cocks gun, blows brains out (Yes I know the evil goto supposedly has its time and place, blah blah blah)

If you are going to write functions like this [1], gotos are not your worst problem. :) [1]: http://sourceforge.net/p/jediacademy/code/ci/4bebb8ec23200ee...

I was also surprised to see these huge functions with multiple nested layers. Is it common for game development? Or it was just a quick hack on top of Quake engine?

Re: Jedi Knight 2 And 3 Source Code Released

#8
post #2

Searching 1897 files for "goto " ... 603 matches across 121 files cocks gun, blows brains out (Yes I know the evil goto supposedly has its time and place, blah blah blah)

Skimming through the academy source, some are fine, some are not.

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");

Re: Jedi Knight 2 And 3 Source Code Released

#9
post #5
post #2

Searching 1897 files for "goto " ... 603 matches across 121 files cocks gun, blows brains out (Yes I know the evil goto supposedly has its time and place, blah blah blah)

If you are going to write functions like this [1], gotos are not your worst problem. :) [1]: http://sourceforge.net/p/jediacademy/code/ci/4bebb8ec23200ee...

What exactly is wrong about that?

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.

Re: Jedi Knight 2 And 3 Source Code Released

#10
post #2

Searching 1897 files for "goto " ... 603 matches across 121 files cocks gun, blows brains out (Yes I know the evil goto supposedly has its time and place, blah blah blah)

Use of "structured gotos" for error handling is perfectly reasonable. Internal returns are far, far worse sources of error (mostly resource leaks, in my experience). Having functions with single exit points and avoiding contortions that involve extra control variables is better than the mindless avoidance of 'goto'.

Goto is just fine if it is used responsibly.

Post reply on HN