Show HN: 3D shooter in your terminal using raycasting in Awk
github.com
github.com
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 did a "two-up" printout of source code: two pages of code per page of paper in landscape mode. It used a nice font and drew graphic boxes around the pages. I was in the habit of using separator lines like this in my code:
//-------------------------------------
So the program found these and changed them to graphic line separators. It also avoided splitting a function onto two pages if it could - it would leave whitespace at the bottom of a page instead, filled in with a faint dot pattern.
Somewhere I have a printout I made with this program; I was hoping to find it and scan it in to show what it looked like. I know it's here somewhere, but in the meantime the source code will have to do:
https://github.com/geary/awk/blob/master/LJPII.AWK
Of course, these days I hardly ever print out any code. But back then we printed everything.
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 library's a bit mad in places (gsub, sigh). But it's expressive and concise and still readable, and meets its core competency of doing easy text processing beautifully.
The most recent thing I wrote in it was this:
https://github.com/EtchedPixels/FUZIX/blob/master/Applicatio...
That's a C file which is also an executable shell script which contains an embedded awk script. The whole thing's a Forth interpreter. Running the file uses the awk script to compile a Forth subset into bytecode and patch the source file with the new bytecode, which allows me to keep the whole thing in a single source file. It's not what I'd call good awk, but it's incredibly effective awk...
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
)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!
As for fforth.... your signoff at the end of the comments sums it up much better than anything I could say.
# No evil was harmed in the making of this file. Probably.
This thing is absolutely awesome... a self-modifying tri-language source file, implementing Forth in just 22KB (or 34KB on x64). Very nice.Now to go read the, um,
panic: unrecognised word: help
...documentation? :PIt actually happens that I've recently become really interested in Forth implementations and systems, so discovering this is especially cool... and on that note, what sources would you recommend I study to get an overview of Forth history and development? I've read enough historical anecdotes to understand there are conflicting opinions (as always), but nothing thus far has shown the evolution of the language itself, how ANS became a thing, and so forth.
PS. clang-3.7 -Os is the winner on i386, gcc-5.3 -Os on x64. tcc-0.9.26, interestingly, comes second on both (26KB and 36KB respectively). (Using Slackware-current.)
PPS. Your site's About section might want to know the Antix website seems to have been taken over by a spam system.
Anyways, I was talking about how this thing totally misappropriated awk, not awk itself.
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.
This is your father's awk. An elegant weapon for a more... civilized age. :-)
There is a bit of cheating going on here though. Awk doesn't support true multidimensional arrays. They are depending on a Gawk extension for that bit of functionality.
I'm reminded of an administration tool I wrote using AWK and ANSI command sequences. It was the most powerful programming language available on the machines available to me for that project. It worked great, but in the end meant that I had to fly back out to that site every time it needed maintenance or new features as nobody else there knew AWK.
I also hesitate to say that the site in question deserved to pay for the tickets, since AWK is reasonably easy to learn, even in the case of 4- or 5-digit-SLOC applications.
But if AWK was the most capable system available, that's saying a bit... :p
The site in question was isolated from the Internet for security reasons. This was ~1994 and I would have had to submit significant paperwork to get permission to use one of the phone lines for a modem.
As I remember it, the site had a hodgepodge of SCO Unix, SunOS, IRIX, and Linux systems. SCO Unix was the least equipped of them. Configuration management had them all stuck at an old version. Perl wasn't even installed on all of the systems. I remember feeling that AWK was a good choice because, being interpreted, it allowed for fast development. Another obvious option would have been C with X for the GUI, but that would have taken much longer to implement.
Good way to put it, and point conceded (and filed away for future reference in my own life).
> The site in question was isolated from the Internet for security reasons. This was ~1994 and I would have had to submit significant paperwork to get permission to use one of the phone lines for a modem.
I figured as much. Usually flying someone out only happens when the core infrastructure is out (and the tiny DSL emergency modem failed as well), when something's being so annoying/intermittent it has to be poked onsite, or when something's airgapped.
> As I remember it, the site had a hodgepodge of SCO Unix, SunOS, IRIX, and Linux systems. SCO Unix was the least equipped of them. Configuration management had them all stuck at an old version. Perl wasn't even installed on all of the systems.
Ouch, wow. (I'm not sure whether to be more impressed that Linux made an appearance at all only 3 years after entering existence, or that it was apparently stable enough at that point to not be laughed out of the building.)
> I remember feeling that AWK was a good choice because, being interpreted, it allowed for fast development.
A problem that's still a toss-up for many people :) hah. I'm not even sure what to use half the time...
> Another obvious option would have been C with X for the GUI, but that would have taken much longer to implement.
Ah, the joys of Xlib. I've poked it briefly but not too much, although I can resonate with the "much longer to implement" part... heh
I was young and so was Linux. I was the only available Linux guy at that time in that organization. The site was running some experiments for military training simulators, so it wasn't uncommon to use technology that wasn't yet mainstream. If I remember correctly, it was just being used to translate some data from one system and inject it into another.
It's old and C++ but explains raycasting very well.
And there is also a similar project in just 265 JS lines: http://www.playfuljs.com/a-first-person-engine-in-265-lines/
Anyway, really cool project. Good work!
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
And yet, I can't get him to sit down and put any time into programming on a computer. Sigh.
"If I had to choose a word to describe our centering forces in language design, I’d say Kernighan emphasized ease of learning; Weiberger, soundness of implementation; and I, utility. I think AWK has all three of these properties."
As for the PRs, apparently I've slept through all the action =) I'll get back to them as soon as I can.
It's sad that languages rise and fall by the feature base present in their standard libraries.
Ill never forget the day I realized its true power was in shortness of code. I took a one page perl script I couldnt get to work and turned it into a one line awk script that worked.
PS: You need gawk to run this.