News for hackers. Stuff that matters.
Re:A Great Old-Timey Game-Programming Hack by Morgawr on Monday December 16, 2013 @08:19AM (#6914507)
This reminded me of a game programming hack I did back in highschool. I had just started a school course on Pascal and decided to code a small game of snake, just for fun. I knew very little about actual programming, I was a real novice. The game was very simple, it was running in a windows console (cmd) without any graphics, the actual assets were ASCII art. The grid of the game was represented with asterisks and the snake was dots with a smiley face (one of those weird ASCII symbols nobody knows why it's there). Every game update I would redraw the whole grid, snake and the comma that was used to output the food.

The problem was that this was terribly slow, it flickered like crazy and it was unplayable. I was very sad because my game was working but unplayable for anybody so I tried to engineer a way to make it stop flickering. The solution came when I found out about a couple of functions in pascal that let you clear a specific character in the console at a specific X,Y coordinate and write another character that that coordinate. What I ended up doing was keep track of all the changes in the game for each frame (snake movements, food position) and just re-draw only the portions of screen that had changed.

This was great, no more flickering and the game was playable. (Nobody really played it because nobody cared but I was really proud of it).

Found out years later that this approach is pretty much what Carmack did in his old games: Adaptive Tile Refresh[1]

[1]https://en.wikipedia.org/wiki/Adaptive_tile_refresh

Re:A Great Old-Timey Game-Programming Hack by acheron on Monday December 16, 2013 @12:17PM (#6916167)
If you're curious why the smiley faces and such were in MS-DOS extended ASCII:

Bill Gates: "... We were also fascinated by dedicated word processors from Wang, because we believed that general-purpose machines could do that just as well. That's why, when it came time to design the keyboard for the IBM PC, we put the funny Wang character set into the machine—you know, smiley faces and boxes and triangles and stuff. We were thinking we'd like to do a clone of Wang word-processing software someday."[1]

[1] https://en.wikipedia.org/wiki/Code_page_437

Re:A Great Old-Timey Game-Programming Hack by Morgawr on Monday December 16, 2013 @01:11PM (#6916569)
That's really interesting! Thanks!
Re:A Great Old-Timey Game-Programming Hack by ketralnis on Monday December 16, 2013 @12:47PM (#6916395)
I made a similar game for a TI calculator where the issue I was having was a lack of memory for the game state. Eventually I found that you could read the graphics memory, so I stopped saving any of the game state at all: I'd tell if there was an obstacle by just reading the graphics memory and seeing if the according pixel was already black. Now system dialogs like the calculator's "reminders" could draw their dialogues to the screen and become obstacles themselves. Now I couldn't tell food from obstacles, so I just got rid of the food idea and now you grow infinitely, and the randomly dropping obstacles XOR their targets to potentially free up walls to pass through.

Like it sounds, the game went through a lot of changes like this in structure through the course of development, where the nature of the game had entirely changed. I had a number of friends with my model of calculator, which was not the more-common TI-86 at my school, so I was the only, err, game in town. Because it was in-effect several games over its lifetime, and different people wanted different versions of it, I learnt a lot about maintainability and version management. "You have the six-month-old version of this with food, and it has a bug that I fixed five months ago in a different game. And the fix doesn't apply here". Or "I solved the slowness you're seeing in this case by removing 3 instructions from inside of this loop here, but that cut the key response time in half, is that alright?"

It was a major learning experience for me. My calculator is long-dead and I don't have a version of the game anymore, but I bet that I could still remember how to make changes to it if I saw the code again.

Re:A Great Old-Timey Game-Programming Hack by a3_nm on Tuesday December 17, 2013 @05:46AM (#6920438)
I remember writing a naive recursive bruteforce Sudoku solver in TI-BASIC on a TI-82-stats in high school. The "recursive" part was non-trivial, because, though a sub could call itself, there were no local variables, only global variables shared between all the subs. Fortunately, there were global lists that you could use, so I ended up using a global list as the stack, along with a global variable to maintain the nesting depth between the recursive instances and serve as some sort of pointer to the current stack position. It worked; it was so slow it took about one second per call, so you could really see it explore the tree, but it usually managed to solve Sudoku grids in a few hours.

I also recall writing minesweeper (this time on a TI voyage 200), also in TI-basic. The main difficulty, of course, was that when you hit an empty square you have to recursively uncover all adjacent empty squares. So I wrote this recursively, but on this TI there were local variables to recursive calls which also meant that the calculator would sometimes run out of memory when doing its recursive calls (at vaguely unpredictable intervals). Fortunately, I discovered that this could be caught with the rudimentary exception-handling mechanism provided, so I would use this to explore not everything but a small radius around the selected position. The puzzling thing, however, was that the radius was uneven, and got smaller and smaller (as if some memory was being leaked by the interpreter), and more surprisingly, in the graphics view that I used, whenever the exception handling would trigger the TI would display a small warning "differentiating an equation may yield a false equation". To this day I have no idea why.

It all sounds silly now but I learnt a lot typing naive code for a slow, buggy, and limited interpreted, on a cramped calculator keyboard, during boring classes. If smartphones had existed back then, I wonder what it would have changed.

Re:A Great Old-Timey Game-Programming Hack by nitrogen on Monday December 16, 2013 @04:54PM (#6918101)
What you describe is also similar to a bitmapped graphics technique called dirty rectangles.
Re:A Great Old-Timey Game-Programming Hack by army on Tuesday December 17, 2013 @12:10PM (#6922199)
It's also a specific instance of a more general technique of incremental computation, which is, if you look at it from the right perspective, a more specific instance of integration: rather than computing a function directly, you're computing the differences and then integrating. So you could almost say that the method dates back to the 18th century: http://en.wikipedia.org/wiki/Euler%27s_method.

It's definitely one of those tricks that comes in handy now and again :).

Re:A Great Old-Timey Game-Programming Hack by bencollier49 on Monday December 16, 2013 @03:21PM (#6917552)
Another way to avoid the flickering was to wait for the screen refresh interrupt before writing to the video buffer, but it did slow things down if you weren't careful.
Re:A Great Old-Timey Game-Programming Hack by ygra on Tuesday December 17, 2013 @03:56AM (#6920176)
The flickering most likely was the result of the most naïve way of redrawing the screen:

    clrscr();
    draw();
This redraws twice, by first clearing and then overwriting again. The flickering should go away completely if you actually redraw the screen, e.g.

    gotoxy(1, 1);
    draw();
At least in the things I wrote in Turbo Pascal back in the day this was enough to fix performance problems from drawing too. gotoxy() calls cost time too and simply writing a large bunch of characters in one go is often fast enough. Of course, writing directly to video memory is by far the fastest approach.

The last time I had fun with this was with FreePascal in my first semester with a friend. We wrote a text-mode UI library for one assignment (it wasn't strictly necessary, but it was a fun learning experience); it had a message loop that handled focus and dispatched input to controls, full-screen "windows", sub-screen dialogs, and buttons, text input boxes, combo boxes, and tabular view. We used gotoxy() and write() calls throughout, which had the benefit that we could test it on my friend's old VT-100 terminal as well (it was slow as hell, though, but you could literally see where to optimize draw calls, similar to using X remotely over a slow network where you can watch it draw each menu half a dozen times), but planned on moving to a more optimized strategy. Alas, we never really had the time for a v2 rewrite so the project just went to die. And by now it's probably of no use to anyone anyway (but it taught me a lot about how windowing systems work or at least can work).

Re:A Great Old-Timey Game-Programming Hack by ajuc on Wednesday December 18, 2013 @02:13AM (#6926286)
I've done similar game, had same problem, then I found out that you could write directly to the text buffer memory in pascal - the address was B800:0001 if I remember correctly? Every even byte was ASCI code, and odd bytes were color numbers. It was fast enough that I could redraw the whole screen each frame no problem (and I could do nice effects like changing the colors of the screen without changing the content).
Re:A Great Old-Timey Game-Programming Hack by acqq on Monday December 16, 2013 @02:17PM (#6917119)
I'm sorry, but believing you did in the highschool what Carmack managed to achieve on the PC in his early games is delusional.

What Carmack achieved (by using the hardware features of the graphic cards of that day) is properly described in the link you give: smooth side scrolling on the PC. The kind of scrolling seen on the consoles of that day, which had a hardware support, or in the famous http://en.wikipedia.org/wiki/Super_Mario_Bros (a copy of which is the unreleased "Dangerous Dave in Copyright Infringement" made by Carmack). That has nothing to do with drawing only the changed characters with simple print at the given screen coordinates, what you did.

To achieve that, it used exactly hardware feature of changing the origin of the area in memory that is going to be picked up by the graphic chip to be presented on the screen. That changing was made in one pixel increments. Without it, no smooth scrolling. Second, he redraw the tiles, he didn't print the characters.

So no, that is absolutely not "pretty much what Carmack did in his old games." What you did at the end was done by absolutely every game at these times (using the commands of cursor movements to position the characters then printing them, in Turbo Pascal using gotoXY from the console library), what you started with (reprinting the whole screen just because) was simply as "pessimized" approach as it can be made at all. You didn't even optimize anything, you did what everybody did, you just started with the "pessimization." I'm old enough to remember. There is also at least somebody here who can provide a link to any computer magazine which printed such games in a few lines of code (at that time sources were made small enough to be printed in the magazines).

For the reference, at least the terminals in 1973 already had "Direct Cursor Addressing" -- the technology behind the gotoxy you used:

http://vt100.net/docs/vt05-rm/chapter3.html#S3.8

(It was already standardized anyway!) That terminal had 1440 characters, all directly addressable, and the maximum communication speed was 2400 bps which gives 300 characters per second or almost 5 seconds to push the whole screen to it. If you moved for example 10 characters, each with a 5 byte sequence, you needed only 50 bytes, so you can change their position 6 times per second. Everybody at that time knew that stuff. It was slow enough to see.

Re:A Great Old-Timey Game-Programming Hack by Morgawr on Monday December 16, 2013 @03:21PM (#6917551)
I'm not sure where all the bitterness comes from but obviously I'm not comparing an amateurish attempt at optimizing a terminal-based snake game written in Pascal to the genius of Carmack, those are two entirely different things.

And yes, I did that while I was in highschool, which is still years after Carmack did his deed. It was around uh... 2005?

I thought I'd just share an interesting "hack" I did when I was a teenager which, to me, felt like a real genius trick to smooth gameplay. Back then my code was literally a lot of messy spaghetti goto hell, so you can understand how much of a novice I was.

I recommend re-reading what I said, I never claimed I "pretty much" did what Carmack did, just that the idea behind incremental upgrades was "pretty much" similar to Carmack's genius. No more, no less.

Re:A Great Old-Timey Game-Programming Hack by acqq on Monday December 16, 2013 @03:29PM (#6917590)
Your words "this approach is pretty much what Carmack did in his old games."

Let me rephrase in less words, it is absolutely not pretty much what Carmack did. You just "rediscovered" cursor positioning feature introduced eons ago on the character-based terminals. Carmack did something else and with the bit-mapped screens using the specifics of the graphics adapters of that time. The tracking you try to refer to he did on the scrollable pixel addresses, you just did simple character prints for $deity sake!

For the explanation of my opinion, see my previous post.

Re:A Great Old-Timey Game-Programming Hack by Morgawr on Monday December 16, 2013 @03:33PM (#6917614)
From wikipedia[1]: "The technique is named for its other aspect, the tracking of moved graphical elements in order to minimize the amount of redrawing required in every frame."

That's all I did, really. Not pretending I did anything more complex than that, I didn't even have access to a framebuffer or anything... Let's say the "principle" was the same, the delivery far from it.

[1]https://en.wikipedia.org/wiki/Adaptive_tile_refresh

Re:A Great Old-Timey Game-Programming Hack by acqq on Monday December 16, 2013 @03:53PM (#6917739)
So according to your logic, as you've read in your school book and then wrote in your notebook a^2 + b^2 = c^2 that is "the same principle" what Einstein did with discovering E = m c ^2 since it has ^2 and the letters. Impressive.

Your school book is the equivalent to the Turbo Pascal on-line help (or TP book if you used TP 3). The similarity of the formulas is the similarity of your implementation and Carmack's "being first." Having your post the top of HN discussion of one real hack makes me deeply sad as it obviously reflects there are some readers who support your view of "the same principle." Or just don't understand, in my view.

Re:A Great Old-Timey Game-Programming Hack by jonesetc on Monday December 16, 2013 @04:27PM (#6917930)
You seriously should to leave the computer, come back tomorrow, and then reread these posts. You are trying to stomp on someone's fond memory of a simple problem that they solved in a way that was novel to them. They clearly don't think that they are deserving of a Turing award, they were just young and felt some pride.
Re:A Great Old-Timey Game-Programming Hack by acqq on Monday December 16, 2013 @04:31PM (#6917957)
Not really arguments. Otherwise, I also do here "the same principle" as Platon and Aristotle as I discuss anything with you. And I'll have the fond memories of this. Don't stomp on them.

My claim is that anybody who thinks moving the text cursor is "the same principle" as Carmack's one pixel at the time smooth scrolling doesn't have elementary understanding of both. And I explained the difference.

I have nothing against morgawr writing about his discovering cursor positioning. I have against supporting him equating this with something completely different. If a five year old goes out of the go cart and says "ma I can ride the plane" nobody cares. If he's 20 something and claims the same after the same "feat" on the pilot forum, some pilot can try to correct him, even if it's the lost time. Even if he also knows that there's the famous "don't argue with .... People might not know the difference."

I still think it was worth writing these comments.

Re:A Great Old-Timey Game-Programming Hack by to3m on Monday December 16, 2013 @06:53PM (#6918745)
Not really. Dirty rects are dirty rects! And anybody familiar with coding for crappy systems that sported hardware scrolling would use the same technique, because your options are limited when the screen moves due to base address changing and yet you want in-memory sprites (i.e., bits copied into screen memory by software or hardware, rather than images drawn automatically at a particular position during the scan) to move independently while drawing nicely on top of the background. And for full-screen scrolling games it is usual for at least the player sprite to stay centred. BBC Micro examples from the 1980s would include JCB Digger, Uridium and Firetrack. I bet Atari ST and Amiga games did the same thing too; the principle extends obviously to multi buffering.

The cunning part of the Carmack games was presumably widening the screen - I don't think I ever saw this done on the BBC. But as a schoolboy in 1989/1990 I'd experimented with reducing the BBC's screen height by one character row (by tweaking R6) to avoid flicker when scrolling vertically. Same principle. It's a fairly obvious thing to do, once you've figured out what's going on.

I think one can come up with better evidence for John Carmack's uniquely amazing skills.

Re:A Great Old-Timey Game-Programming Hack by chipsy on Monday December 16, 2013 @08:20PM (#6919065)
My own understanding was that it was just that particular configuration of the EGA hardware that hadn't been tried before Carmack's implementation.

This is someone who found out from Romero exactly what the Keen games did: http://www.vintage-computer.com/vcforum/showthread.php?30619...

Re:A Great Old-Timey Game-Programming Hack by acqq on Monday December 16, 2013 @07:08PM (#6918829)
You discuss Carmack's pixel scrolling and miss the fact that this guy here who claims he did "the same" just had to draw one character of the snake's head at the new position, overwriting the previous head with the "body" character. And the tail character with the "empty" character unless the snake eats something.

What in the world has that to do with Carmack's algorithm of updating Mario after one pixel hardware scroll (after which he has to redraw the "unmoving" part fully) and adding more background once he spends the hardware moves?

Re:A Great Old-Timey Game-Programming Hack by to3m on Monday December 16, 2013 @07:35PM (#6918930)
Same principle, as I see it, whether it's writing 1 byte, calling gotoxy/putch, or copying a whole bunch of bytes. Dirty rects! The insight is the same: you draw the things that have changed, and leave alone the things that stay the same.
Re:A Great Old-Timey Game-Programming Hack by mattdonnelly on Monday December 16, 2013 @04:18PM (#6917867)
Christ, you sound like such an insufferable prick
Re:A Great Old-Timey Game-Programming Hack by acqq on Monday December 16, 2013 @04:21PM (#6917885)
Is there anything that I wrote that you can show it is not true? I think I've given very specific arguments.
Re:A Great Old-Timey Game-Programming Hack by jonesetc on Monday December 16, 2013 @04:29PM (#6917941)
""" Walter: Am I wrong? The Dude: No you're not wrong. Walter: Am I wrong? The Dude: You're not wrong Walter. You're just an asshole. """
Re:A Great Old-Timey Game-Programming Hack by acheron on Monday December 16, 2013 @07:34PM (#6918924)
I know we try to discourage random quotes and so on here, but that one was pretty much perfect.
Re:A Great Old-Timey Game-Programming Hack by serf on Monday December 16, 2013 @04:55PM (#6918110)
yeah, except he didn't pull a gun on someone, he pointed out that the example was overly flattering for the author. (which it was)
Re:A Great Old-Timey Game-Programming Hack by acqq on Monday December 16, 2013 @05:02PM (#6918148)
Honestly, do you understand the technical aspects discussed here? Can you contribute on that level to the discussion?
Re:A Great Old-Timey Game-Programming Hack by jacalata on Monday December 16, 2013 @05:11PM (#6918203)
Nobody said you were technically wrong. They said you are being an asshole. Do you understand the interpersonal dynamics here? Can you comment on that level?
Re:A Great Old-Timey Game-Programming Hack by acqq on Monday December 16, 2013 @05:28PM (#6918293)
I'm really sad I don't have your e-mail or the possibility to send you personal messages to demonstrate you how hurtful it is when you are being named the names. But I will not fail to your level to do it here in public. And I still don't see that you understood at all the topic which I discussed. Stay classy my friend, I won't answer you here anything more no matter what you write. The same goes to the other name namers.
Re:A Great Old-Timey Game-Programming Hack by jfarmer on Monday December 16, 2013 @10:19PM (#6919391)
Think about all the personal and professional feedback you've received over your entire life. Have you ever been told you're too curt, abrasive, or aggressive? Has anyone told you that what you say is fine, but how you say it alienates or frustrates people? Do you feel like people avoid interacting with you or generally bring up issues (especially personal issues) with other people well before they bring them up with you? Do you feel like you're constantly being misunderstood or that people are taking what you're saying the wrong way? Do you often find yourself rationalizing the impact your words have by telling yourself other people are too sensitive, too stupid, or too deluded to hear what you're saying?

Because right now, that's what's happening. And unless this is a particularly off day, I'd be astonished if you haven't had this reflected to you before by friends, family, and/or co-workers.

You're 100% right on the technical merits. Everybody here understands what you're saying and agrees with you — nobody cares. It seems like you're going out of your way to humiliate the original commenter for no good reason, e.g., by calling him delusional, even after he admitted that he understood what he did in high school in no way rose to the level of what Carmack did.

The OC was describing the sensation vindication and pride he felt when he figured something out on his own and later learned that a more advanced version of same idea already had a name. This is a feeling most programmers can relate to, I think. I only learned what a "trie" was, for example, years after I implemented a shitty version on my own.

Whatever your intentions are, you have to understand the impact your words have. And in this thread, at least, it's not pretty.

Re:A Great Old-Timey Game-Programming Hack by jacalata on Monday December 16, 2013 @06:16PM (#6918535)
The worst thing about this exchange is that you seem to honestly, actually not understand why people are having problems with you. You don't need to respond to this, but if you really totally don't understand why people are reacting badly to you here, it would probably be good for you to try reading some basic interpersonal self-help stuff like "How to Win Friends and Influence People", or to ask someone you know and trust whether they think you have an excessively abrasive/confrontational style.

Or maybe you're just having a bad day, in which case, hope it improves, chill, try not to get caught up in arguments when you're already pissed off (I know I do that and come off as a jerk sometimes).

Re:A Great Old-Timey Game-Programming Hack by nekopa on Monday December 16, 2013 @08:45PM (#6919127)
I haven't, and won't, 'name you names'. You could have given a nice technical explanation of what Carmack did without having to call the person 'delusional', saying they started with 'pessimisation' then further going on to belittle them by saying you'll 'explain with less words'. Even after they go further and say their programming was a goto spaghetti hell made in 2005 as he was learning to program, you keep trying to brow beat him with your decades of knowledge and experience.

Why are you angry at him? I thought the main point of the fine article wasn't just about the technical details, but also the fact that they wouldn't give up. Would you rather that he had seen his flickering game and just say 'Aw screw it, programming is crappy!' and walk away?

Or do you want a signed and printed statement of your 'absolute' rightness, a full retraction from him never to compare himself with Carmack again and pg to come into this thread and strike down his comment from the top and relegate it to the bottom of the page until he spends years learning what people knew 30 years ago?

Most of the people here understood what you were discussing. My first computer was a Sinclair ZX81, and I remember well those magazines you brought up.

But you were really rude the way you were discussing it, and quite frankly, you were calling him names, unless you think that delusional is a nice way to refer to someone.

And yes, my email is in my profile if you do want to email me privately and call me names.

Re:A Great Old-Timey Game-Programming Hack by eruditely on Monday December 16, 2013 @07:21PM (#6918882)
No you definitely are being an asshole, it is you who needs to stay classy, maybe get a fresh nights sleep wake up with some nice coffee and review your statements.
Re:A Great Old-Timey Game-Programming Hack by acqq on Tuesday December 17, 2013 @08:18AM (#6920928)
Expletives say the most about those who use them, not much about anything else.
Re:A Great Old-Timey Game-Programming Hack by guiomie on Tuesday December 17, 2013 @10:14AM (#6921501)
Go to bed dude. No one is on your side here.
Re:A Great Old-Timey Game-Programming Hack by Sssnake on Monday December 16, 2013 @06:53PM (#6918741)
When the entire world thinks you are the asshole, it is worth stopping and considering the possibility that they may be right.
Re:A Great Old-Timey Game-Programming Hack by mattdonnelly on Monday December 16, 2013 @06:54PM (#6918750)
Nothing you said is factually wrong but you're being obnoxiously pedantic and rude. OP was merely commenting on the similarities between his and John Carmack's approach to solving the problem and is in no way deluding himself by comparing the two in terms of complexity. It's absolutely possible to write a naive solution to a small problem and still take a similar approach to a more complex one
Re:A Great Old-Timey Game-Programming Hack by mcgwiz on Tuesday December 17, 2013 @11:33AM (#6921996)
Of course it's not exactly the same. But the approach was similar. They each believed that more could be done to bring their creations closer to perfection if they understood the underlying technologies better. Commenter took that to one level, and Carmack took that to the extreme. But both relied on tech abstractions that effectively had a multiple levels of proficiency.