Friday 28 April 2017

Teach Yourself Game Programming in 21 Days - Day 1

Welcome to Teach Yourself Game Programming in 21 Days! You're about to embark upon one of the most exciting and rewarding learning experiences you've ever had. Game programming is, without a doubt, one of the most difficult areas of computing to understand. However, it's also one of the most satisfyingand, with determination and patience, you will conquer it.



So begins this great book. The first chapter talks about video gaming history on home computers, going from those heady days when owning an Atari 800 made you the coolest kid on the block, right up to the cutting edge of the Intel 486. It's fun to look back into the past this way; it's particularly amusing to see the almost breathless way that André explains things that are considered mundane or even trite now, like the way "most PCs today have sound cards" or that games aim to hit "15-30 frames per second".

The book lists the basic genres of games as such:

  • First-Person, Three-Dimensional Walkthroughs like Doom, Blake Stone, etc.
  • Flying, Driving, or Spaceflight Simulations like Microsoft's Flight Simulator, Wing Commander, etc. "These games try to simulate something we can do in reality." I wonder how André would feel about the preponderance of Farming Simulator stuff these days.
  • Sports Games in 2- or 3-D; he doesn't name any here, but he does mention that "the most popular games are football and basketball."
  • Scrolling Adventure Games like Mario Brothers. 'Adventure' games! It still amazes me how much this word has changed in meaning over time.
  • Sideview Combat Games by which he means Street Fighter et al. "The factor that attracts most players to these kinds of games is the ability to project themselves into virtual warriors with super strength and abilities."
  • Role-Playing Fantasy Games in 2- or 3-D, again not naming any, only 'admitting' that he used to play Dungeons and Dragons back in the day.
I guess the largest missing genre here is Puzzle; a segment which has exploded through so-called 'casual gaming', something that would have been difficult to predict back in the 90s. The focus back then was on bigger and better - pushing the boundaries of tech, upgrading your PC every 6 months. The very idea of large parts of the industry jumping onto a low-powered portable machine is kind of weird, but it definitely worked.

Next is a fairly lengthy discussion about the architecture of a video game. It notes that everything happens in a big loop, so it's really important to make that loop run as fast as possible. I remember there being quite a few optimisation tips spread throughout the book, and plenty of advice to make you stay on the path. I think this really stuck with me; even though I mostly write websites and non-critical things these days, I still make notes about what could be improved and like to use profilers to get a feel of how fast my code actually runs.



Game Law: Don't mix game logic and graphics unless absolutely necessary. Try to keep rendering and computation separate.

This separation of concerns is a rather important part of programming in general. The separation of code into individually testable units means that it is possible to reason about their correctness. It also helps guarantee that later changes don't break any old code. This is something I've only really got into recently - although I've known about unit testing for a long time, I had no idea how good the tools for code coverage and static analysis had got. I think it's a fascinating way of learning more.

What Does the PC Offer as a Game Machine?
Today the PC is a formidable computer. You can bank on the following minimum hardware configuration as your base platform:
  • CPU: A 386 with two megabytes of RAM (with 486s being common)
  • Video Card: The VGA card is standard, with many PCs having a Super VGA card
  • Sound Card: A Sound Blaster- or Adlib-compatible sound card
  • Input Devices: All PCs have keyboards; many have mice, and—if the owner is a gamer—you can count on a joystick
What an amazing snapshot! It still blows my mind that these clever 90s programmers managed to wrest so much power out of a general-purpose machine, managing also to create some of the most memorable masterpieces in gaming history. The book also notes that you can also write games with this same level of hardware; this is something that is difficult to achieve today. Most Windows programming requires a powerful computer so you can load memory-hogging beasts like Visual Studio. Game programming with the latest engines is similarly demanding. Still, a commodity PC is enough to write indie games, and there are plenty of those around (lauded ones, too).

There is a worrying requirement in André's list, however. "You need a C compiler. I use Microsoft's C/C++ 7.0; if you have that one, we're completely in sync. Also, it would be to your advantage to have MASM 5.0 or higher." I've used Visual C, but this is older still, and it might be a pain to get hold of. Also, I'm using a 64-bit PC, so there could be further problems there.

The next line offers a potential way out. "If you're a Borland user, you'll have to make slight changes here and there. However, there shouldn't be a problem with code compiling under Borland's products." Ah, Borland (now Embarcadero)! My first experience with C programming was with Borland's venerable Turbo C package, also in the 90s. I also went on to use C++Builder once I got into visual stuff. I might still be able to find a copy of that lying around.



Lastly, there's a section about 'Being Creative'. This largely boils down to watching random fantasy and sci-fi movies for ideas. "If there's one game designer on Earth who hasn't seen all the Star Trek episodes, the Alien movies, and Real Genius a thousand times, I'd be surprised! So go out there and use other people's ideas as the seed of your own new idea." Probably decent advice for a programmer, we tend to be quite boring people.

So, there's no code in this chapter. However, each chapter does end with a list of quiz questions, some answered in the text, others requiring research. I won't bother to answer the questions (one is a bizarrely specific question about Real Genius) but I will attempt to do the exercises. One of them this time is "Play the game DOOM for a couple hours and see what can be done with a PC", so... see you later.

No comments:

Post a Comment