Live data from Hacker News

Show HN: 3D shooter in your terminal using raycasting in Awk

github.com

41–50 of 57 posts

Re: Show HN: 3D shooter in your terminal using raycasting in Awk

#41
post #26

Earlier quoted context omitted.

Well, there were those bored days with a TI-83... shudders at TI-BASIC

My son spends a ton of his class time programming games into his TI-83. He even built his own Final Fantasy type game (when he really should have been doing classwork). He built a battle system, and even a merchant/vendor for buying upgrades. I had a lot of fun playing his game, and offered him some ideas for improvement (which, again, were made during class time). And yet, I can't get him to sit down and put any tim…

TI-BASIC is a blessing and a curse. You can get the most non-technical people to write code in it, but if you've had experience in a REAL language, you can't bring yourself to.

Re: Show HN: 3D shooter in your terminal using raycasting in Awk

#45

Earlier quoted context omitted.

Ah but awk is great! It's parsimony when processing structured text files is hard to beat. Such a pity the next step on from it is perl. Perl is snot certainly.

No, the next step from awk is ruby :-D. Anyways, I was talking about how this thing totally misappropriated awk, not awk itself.

In all seriousness, Ruby is Awk's grandchild borne of a virtuous union between Perl and Python.

After looking at the code I'd agree that it's not really idiomatic Awk. But come on, snot? I would've said a humble yet more dignified medium, such as match-sticks.

Re: Show HN: 3D shooter in your terminal using raycasting in Awk

#46

Earlier quoted context omitted.

No, the next step from awk is ruby :-D. Anyways, I was talking about how this thing totally misappropriated awk, not awk itself.

In all seriousness, Ruby is Awk's grandchild borne of a virtuous union between Perl and Python. After looking at the code I'd agree that it's not really idiomatic Awk. But come on, snot? I would've said a humble yet more dignified medium, such as match-sticks.

But I'd say that ideologically, ruby is far closer to awk than perl is. And yeah, matchsticks would have been better. I do actually LIKE awk, and will defend it from anybody who says that it is useless or badly designed.

This is your father's awk. An elegant weapon for a more... civilized age. :-)

Re: Show HN: 3D shooter in your terminal using raycasting in Awk

#47

Earlier quoted context omitted.

I used to write a fair amount of AWK code back in the day. It was great for one-liners, but I wrote some more elaborate programs in it too. I treated it seriously, like a real programming language, and it served me well. My favorite AWK program was probably my LaserJet II code listing program from 1991. I wrote this out of frustration with the terrible default listings I got when I printed source code. The AWK code d…

Years ago I wrote a compiler (for bytecode) in awk. Ummm... http://cowlark.com/mercat , although you'll need to wade through zip files to get at the source. It was 1.6kloc for a fully typed algolish language producing stack-based bytecode. awk's a lovely little language, and deserves to be better known than it is. Its two big failings are local variable syntax and absence of structured types... and the standard libra…

That is brilliant!

So the embedded FORTH compiler written in AWK reads the FORTH code in a comment like this:

  //@C SPACES
  // \ n --
  //   BEGIN
  //     DUP 0>
  //   WHILE
  //     SPACE 1-
  //   REPEAT
  //   DROP
and compiles it into C code like this (reformatted here to help illustrate):

  COM(
      spaces_word, codeword, "SPACES", &space_word,
          (void*)&dup_word, (void*)&more0_word,
      (void*)&branch0_word, (void*)(&spaces_word.payload[0] + 8),
          (void*)&space_word, (void*)&sub_one_word,
      (void*)&branch_word, (void*)(&spaces_word.payload[0] + 0),
      (void*)&drop_word,
      (void*)&exit_word
  )

Re: Show HN: 3D shooter in your terminal using raycasting in Awk

#48
post #28

Needs bash and gawk, bash you can avoid by changing cmd = "bash -c 'read -n 1 input; echo $input'" to cmd = "saved=$(stty -g); stty raw; var=$(dd bs=1 count=1 2>/dev/null); stty \"$saved\"; echo \"$var\"" all credit to izabera from #bash on freenode

Finally merged that.

Re: Show HN: 3D shooter in your terminal using raycasting in Awk

#49

Earlier quoted context omitted.

Years ago I wrote a compiler (for bytecode) in awk. Ummm... http://cowlark.com/mercat , although you'll need to wade through zip files to get at the source. It was 1.6kloc for a fully typed algolish language producing stack-based bytecode. awk's a lovely little language, and deserves to be better known than it is. Its two big failings are local variable syntax and absence of structured types... and the standard libra…

That is brilliant! So the embedded FORTH compiler written in AWK reads the FORTH code in a comment like this: //@C SPACES // \ n -- // BEGIN // DUP 0> // WHILE // SPACE 1- // REPEAT // DROP and compiles it into C code like this (reformatted here to help illustrate): COM( spaces_word, codeword, "SPACES", &space_word, (void*)&dup_word, (void*)&more0_word, (void*)&branch0_word, (void*)(&spaces_word.payload[0] + 8), (voi…

Yup! COM() is a varargs macro that actually assembles the data in memory --- the actual word layout is not the traditional one Forth uses (to make it C friendly). But the end result is a linked list of Forth words in exactly the same format that user words have, which the user dictionary extends.

It all means that the C source can just be compiled in a single step --- gcc -o fforth fforth.c --- without needing a precompilation stage, which makes it vastly easier to manage.

It's even portable!

Re: Show HN: 3D shooter in your terminal using raycasting in Awk

#50

I was wondering how you'd read a key in raw mode in awk. The answer, I found with a mix of horror and admiration is 3 forks. Two stty and one bash (presuming read and echo are builtins)

Now it's been updated to use dd, and can run with /bin/sh.

It's sad that languages rise and fall by the feature base present in their standard libraries.

Post reply on HN