Monday, August 2, 2010

Our Development Environment

Start at the Beginning
Table of Contents

CHAPTER I - Getting Started

Modern computers with their modern operating systems (OS, like Windows or Mac OS X) are hugely complex pieces of engineering. In order to even begin to write a C++ DirectX Windows game, you need hundreds of lines of boilerplate code and a deep understanding of dozens of weird technologies. It's not interesting, really, and it's extremely confusing for a beginner.

The advantages are that it's safer - you're unlikely to blow up your computer with the protection Windows provides. You also don't need to worry too much about compatibility - a DirectX game should work on basically any Windows computer, no matter what kind of hardware is inside it.

A mixed blessing is that DirectX and modern graphics cards take care of many of the little details of game programming we used to have to do ourselves. While this is less work, those searching for a deeper understanding of game programming won't really find it. The complex, mysterious machinations of the modern development environment tuck you in and tell you that you'll understand when you're older, basically. While this sort of abstraction is a great thing on the whole, and I have no intention to slight it, I also feel that a deep understanding is crucial to being a truly skilled and capable programmer.

To that end, we're going to travel back in time to around 1992. The 386, running at 33MHz, is becoming the most popular CPU on the market, executing a blistering 11 million instructions per second (MIPS). By comparison, a modern CPU runs at around 3GHz (that's around 100x faster) and executes nearly 150,000 MIPS. Right now we run Windows 7 on our computers - back in 1992, most computers ran DOS, an ultra-minimal, text-only environment. A modern computer might have 4GB of RAM. Back then you were lucky if you had 4MB (around 1000x less). A modern computer has around 1TB of hard disk space. Back then, you might have 100MB - that's 10,000x less! It's on a computer like this that we're going to learn.

Here, we need to do everything ourselves - talk directly to the hardware to make it do our bidding. We'll need to learn the basic math to draw geometric shapes. We'll need to write our own code to unpack images from files. We'll need to carefully feed chunks of sound to the sound card to play music. Only once we get this deep understanding of all the different problems we need to solve in order to make a game can we understand how masterpieces like Doom and Quake were made - and only once we've unpeeled these masterpieces and figured out how people could possibly put them together can we possibly put masterpieces like them together ourselves.

Of course, you probably don't have an old 386 sitting around. Happily we can create a "virtual" 386 using free software, running inside a window on our modern desktops. To do this we'll use Bochs, a free and open source PC emulator, and FreeDOS, a free and open source implementation of DOS. To compile our C code into programs we can run, we'll use DJGPP, a venerable DOS port of the free GCC compiler. This is the same compiler used to build Quake nearly 15 years ago, and it's only gotten better since.

1 comment:

  1. Hi, This is a great article. Loved your efforts on it buddy. Thanks for sharing this with us. MS-500: Microsoft 365 Security Administration

    ReplyDelete