Game Engine Black Book

I found Fabien Sanglard’s site awhile ago while searching for information on Doom’s engine. While not extremely exhaustive, each short article on his site gives a nice informative look into several of id’s and other games to see what makes it tick. Well, apparently there was enough demand for him to dive in deeper, because now Fabien has released the Game Engine Black Book for Wolfenstein 3D. Unlike Game Programming Patterns, which I’ve previously posted about, don’t expect to follow along with much or most of this book unless you have some serious graphics and/or assembly language programming under your belt. Wolfenstein 3D was created at a time when there were severe restrictions on what a game could do, especially a 3D game. Through his previous experience and uncanny ability to grasp, learn, and create brilliant new things, John Carmack came up with a fast-performing engine that allowed id to create the most popular shooter of its time, at least until Doom came long.

In the book Fabien first takes a look at the hardware id had to work with at the time, including the Intel i286 and i386 processors, RAM limitations and 2 ways of trying to expand beyond it, video modes, and sound processing. Then a small section covers the asset creation for the game, and the personnel at id who worked on each. Finally Fabien dives into the Wolfenstein 3D source code, and this is definitely the meat of the book. He goes over the general architecture, the 2D and 3D renderers, audio and sound effects, and user input.

This was a fun read, but I’ll say at least 95% of it went over my head. The code in C I could roughly follow, as that’s the language I primarily learned. But there’s a LOT of assembly mixed in, and these days I don’t think even Rasberry Pi programmers deal with it; it’s that low-end (I think BIOS/UEFI and device drivers are the only things that use assembly). I would love to see further books from Fabien. Doom is an obvious choice, but I think something even further along would be great, whether that’s Quake or even Doom 3. I’d just like his analysis on code that I could roughly follow better, whether it’s C or C++.

Game Programming Patterns

I first learned of this book from author Robert Nystrom’s entry on the Uses This website (also featuring the greatest profile photo on that site, maybe ever!). The book can be found on its dedicated website, in a variety of electronic and print versions, as well as being able to read online for free. I must applaud Robert for that latter option, as it’s a great way to know for sure the book covers what you want to learn before buying a paper copy (which for me is still superior for longer reading sessions as well as reference).

Since it’s available to look through online I won’t go through all the chapters or such. I will just say that as a still-novice programmer much of the details went over my head, but I did understand the general concepts Robert was talking about. His hand-drawn diagrams are also perfect and wish all programming books utilized that style!

While you will still need other books to start to learn programming, both in general and for games, I think this book is worth picking up at least at the intermediate level to begin learning about some general concepts as well as learned lessons from others to incorporate into your own work.

Ruby Wizardry

After leaving the lands of Pascual and C, I didn’t fully come back to programming until I learned of the Invent Your Own Computer Game With Python website. I had tried C++ and Java with object-oriented programming methods and I just couldn’t get it. With IYOCGWP it started to click, thanks to the clean design of Python. I had always heard of Ruby on Rails, but not too much of Ruby itself. That changed with a Humble Bundle of programming books; the base level, where you can choose what to pay, included the book Ruby Wizardry. I had heard good things about No Starch Press, and I wanted to give Ruby a try, so I purchased the PDF and began my Ruby journey.

The book starts out very strong. At first I was perplexed, however, why a programming book aimed at kids weighed in at over 350 pages. The beginning chapters are quite engaging, as we’re introduced to the King and two young programming ingenues, Scarlet and Ruben. As more and more things break down in the kingdom, Scarlet and Ruben assist the King to fix the Ruby-powered devices. This is a very engaging and ingenious way to encourage kids (and adults!) to keep reading and exploring the increasingly-intricate concepts and syntax.

Oh boy, the syntax. Evidently Ruby has a number of ways to notate things such as loops and interations, and the author is only too happy to dump all of this on the reader at once. Seriously, in the Staying in the Loop chapter Scarlet shows three different ways to write a loop. The concepts and syntax is just too much to take in at once for a Ruby programmer; I can’t imagine what a kid, let alone an adult beginner programmer period, would think of this. I had to stop reading and take a break to try to digest all of that. In other words, the pacing and complexity ramped up way too much way too fast. This is a critical failure, especially in a book aimed for kids. Why not just stick to one way to notate loops and integrators, and then later on introduce alternate syntax? Is this also a failure of Ruby, by having all of these different ways? Compared to Python, which is just so much simpler and more logical looking at its code and syntax.

One other great fault of Ruby is its software. First, the irb is simply a command line; there’s no text editor, debugger, or anything else. Again, Python includes so much more. Also, on my Ubuntu system, which has Ruby 1.9 instead of 2, I have no idea how to easily install 2 and use that by default. There’s a Ruby2 package in the App Store, but that didn’t change anything. There’s nothing on the Ruby website either. So, at least OS X includes Ruby2, and there’s an easy installer for Windows. For Ubuntu, I guess I would have to upgrade to 15.04 or wait for 15.10, and I have no intention to move to a non-LTS Ubuntu.

I’m currently working on the chapter dealing with arrays and hashes, and it’s still somewhat clicking for me. Of course the kids in the book have dumped a bunch of new syntax, and without any larger or book-long project to implement these items most of it is just flying through my brain and out of it just as quickly.

I’m certainly glad I didn’t pay full price for the PDF or the book, or I would definitely feel it was money wasted. I like the direction the author was trying to take, but ultimately I have to say he failed. Does this permanently turn me off of Ruby? Well, if Python didn’t exist I would certainly still keep at it, but with the clean, simple, one-true-way of Python, I think my limited free time is better spent on that language. There is a python book from No Starch Press that’s in a similar vein to Ruby Wizardry, so I may take a chance, provided I don’t find a better book first.

A Simple Dice Roller Program

Here is a quick dice roller program I whipped up in Python.  To run it, you’ll need to install Python3, which can be downloaded here. Then simply copy and paste this code into a new file and save with the .py file extension.

import random

def diceRoller(numSides, numDie):
#generates random number based on first parameter
    totalResult = 0
    for i in range(numDie):
        rollResult = random.randint(1, numSides)
        totalResult = totalResult + rollResult
    print('The result of the roll is: ', totalResult)

rollAgain = 'yes'

while rollAgain == 'yes' or rollAgain == 'y':

    print('How many sides does this dice have(2-30)?')

    dice = int(input())

    # error checker
    while dice < 2 or dice > 30:
        print('Please type a number between 2 and 30')
        dice = int(input())

    print('How many dice of this type do you need to roll?')

    numDice = int(input())

    diceRoller(dice, numDice)

    print('Do you want to roll again? (yes or no)')
    rollAgain = input()

Update (3/22/2013): Just noticed that the error checking code doesn’t work. I’ll fix it later.

Update (4/5/2013): Error checker fixed.  Helps to use the correct logic (or, not and) 🙂