Wednesday, August 30, 2006

Faster Build Times - Reducing Header Dependencies

Long compile times are a pain in the neck. They waste time, cause frustration, interrupt your ‘flow’ etc. They do cause a lot of programmers to learn how to juggle, which is a slight positive, but lets proceed with the assumption that long compile times are bad.

As I’ve already mentioned in the past, a lot of compilation time goes into parsing headers. Using pre-compiled headers is a good way to reduce them, but there are a couple of other ways.

You can wrap your header with the following kind of pre-processor directives:

#ifndef _MYFILENAME_H_

#define _MYFILENAME_H_

… normal header contents go here …

#endif // _MYFILENAME_H_

So what does this do? Well the defined value “_MYFILENAME_H_” is arbitrary, it’s just some unique value, the filename with some underscores is commonly used. The first time this is encountered, the parser will process the contents of the header, but also define the property. If the header gets included again (for the current cpp file it’s compiling) the value will already be defined and the contents of the header will be skipped. This is a time saving, and also avoids cyclic loops of headers.

But wait! For that trick to work, the parser still has to read the header to get to the point where the #endif is, so it still has to read the whole file.

Microsoft have an answer for this. You can put:

#pragma once

at the top of your file, and the parser will only include the file once. The parser knows that if it encounters this pragma for a second time for one cpp file, it can just stop there. This is good, but it only works on the Microsoft compiler, and so might not meet your needs. Also even though we’re preventing repeated parsing of the same file, we could still be including a lot of files.

The best thing is for us to reduce the amount of headers getting included. Most people know this, but it’s still a very common problem. A header can need to include another header for several reasons, including:

  • So a class/struct from another file can be embedded in a class.
  • So that functions defined in the header can ‘use’ another data types' functions and data.
  • So pointers to other classes/structs can be used in structures and function prototypes.

The last bullet point here is interesting. The header that’s doing the including is not needing to know the size of the other structure, or call functions related to it. In this case, we can just make a forward declaration instead of including the other header. So to embed a pointer to the class 'Foo', instead of:

#include “foo.h”

we can just say:

class Foo;

This tells the compiler “there’s a class called Foo, and all you need to know right now is that it exists and I’m going to be dealing with pointers to it”. You’ll then likely need to put the #include into one or more cpp files where the pointer gets used. This can seem like a pointless exercise at first, but it reduces the overall amount of headers which need including, by breaking the chains of headers which rely on other headers.

You can also think about the other cases – do I need to implement this function in the header, or can it be moved to the cpp, allowing me to remove the include.

If you want faster build times, turn on build timing so you can see how long your compiles take. In .NET, go to “Tools->Options->Projects and Solutions->VC++ Project Settings->Build Timing” and turn it on. Then turn on “Project->Properties->C/C++->Advanced->Show Includes” to show a list of all the included files when you compile. Then look at the build output and find header include chains you think you can break up.

It can be tricky to reduce header dependencies, it requires many large rebuilds of your project. But assuming you can find some optimisations, you get paid back in shorter compile times and the benefits they bring.

Friday, August 25, 2006

Getting a games programming job - Tip 7 - Practice Answering Interview Questions

During a phone interview, programming test, and interview, the chances are that you’re going to get asked a load of questions. Many of the questions you’ll be asked are general programming questions, perhaps dressed up with a game related theme. Doing a quick search for “programming interview questions yields a bunch sites which round up the types of questions you get asked.

Reading and answering a few questions probably isn’t going to suddenly make the interview process a cakewalk, but it can show you some areas to practice and can give you an idea of the type of questions you’re going to be asked. Beyond standard interview questions, in a games interview you’ll likely also get asked questions about 3D math, and lower level operations like memory allocation, pointers, bitwise operations, and hardware and operating system concepts.

One more thing. It's easy to read a question, read the answer, and fool yourself into thinking you'd be great at answering. Put a bit more effort into it, write your answer out, talk out loud as if you were talking to an interviewer. You might find that the answer is harder to write down than you think, or that you've forgotten your impressive vocabulary of cromulent words. Another good idea is to code it up and make it work - if you've not written a linked list class in a while, an interview is a pretty rough place to re-learn it. This is why I recommend working on demos, and keeping on coding while you go through the interview process.

Thursday, August 17, 2006

Getting a games programming job - Tip 6 - Submitting Your Resume

The first stage in your application process is sending in your resume and cover letter. Here are a few of my tips, mainly aimed at people new to the industry:

  • It doesn’t hurt to personalize your application by mentioning the name of the company, and saying why you’d like to work with them in particular. If I read ‘I liked playing ‘The Incredibles’ and would like to work on similar titles’ then that makes the person stand out. It shows they’ve researched the company, and are particularly interested in it. It’s the difference between getting junk mail that says Dear Sir, and Dear .
  • If you’ve been doing little demo projects like I suggest, mention it, and give a link to your web page. Being able to quickly show someone what you can do can make a massive difference.
  • I like it when the application includes a cover letter, and perhaps a note about hobbies/interests. It gives a chance for me to see the applicant as a person, and not just a completed University course. Expressing why you want to work in games, and the fact that you’re crazy about playing the Sax lets your personality show, and makes you memorable. You become ‘that Sax guy’. It also shows your communication skills. The ability to communicate well is important in almost any job.
  • Be honest about your abilities. If you get an interview, and people find that you’ve been exaggerating in some area, then it casts doubt on everything you’ve put. Don’t undersell yourself either, as you might not get called.
  • If you’re proud of your GPA, don’t forget to put it.
  • Format what you’re sending nicely. Check the spelling and grammar.
  • If you’re coming from an educational establishment, then they likely have a group who will check your resume for you. Make sure you use this. If you don’t have this kind of service available, then find one or two people who can proof read it for you.
  • It’s best to apply directly to the company instead of using a recruiter. Using a recruiter would be free to you, but would usually cost the company several thousand dollars to hire you. You’re saving the company money by applying directly. Another thing is that sometimes your resume gets mangled down to a badly formatted txt file, which can give a bad impression.
  • At some companies, the online job application database, or centralized corporate HR department can be a bit of a quagmire that applications get stuck in. Whenever possible I try and avoid this route by contacting the studio directly, or finding a contact there through a friend of a friend.
  • While you’re going through the interview process, keep on coding for fun. It’ll keep your skills nice and sharp, and you also wont have much time for your own coding once you get a job.
Hopefully, with your resume in good order, you'll soon be contacted and then move onto the next stage. As it's videogames, you have to complete three stages and then you face a big angry boss.

Oh come on, that was a good one...

Monday, August 14, 2006

Homebrew Xbox 360

In the news today.

"Microsoft Corp. on Monday will announce the availability of software tools aimed at encouraging independent and hobbyist video game makers to create titles for its new Xbox 360 console."

"A test version of the tool kit will be out by Aug. 30. The final product will be available this holiday season for an annual subscription of $99 per year for Xbox 360 game development. The software will be free to people making games to run on Windows."

I think this is great news. It really opens the door to people wanting to get into the industry, to creative new game ideas, indie developers, all sorts...

Saturday, August 12, 2006

Blog Update - August 2006

I thought that today would be a good day to post an update about the blog.

As you’ve hopefully noticed, I’ve been tweaking the layout. There’s a beautiful picture of me, less ads, and generally a cleaner look. Thanks to Scott Chiu for helping to squeeze the DVD tray into my mouth.

I use Google Analytics and AdSense to track some stats on the site. For the month of July the site averaged 27 hits per day. I can also tell that 75% of hits are ‘returning visitors’, and traffic spikes at around 50 each time a post is made. I like this, as it hopefully means people are getting something out of the site.

Some might wonder how much money AdSense is making. Well I’m proud to say that in the first three months I’ve managed to rack up a whopping $3.88. I hope all this money doesn’t corrupt me and send me down a path of ruin. :)

Having AdSense does give me a good way of tracking traffic though, and it’s amusing to see how irrelevant the ads can get. I also had some Amazon ads, and they did quite literally nothing.

Analytics gives a fun graphical display of where in the world people are reading from. A big shout out to the New Zealand, India and Philippines crews. :)

I’m enjoying writing the blog. At first I thought I was going to run out of ideas, but more and more topics keep coming up. That said, I really enjoy getting posts and mail, as it helps me shape what I write about, and it’s nice to make the connection.

Thanks for reading so far!


Thursday, August 10, 2006

Favourite Tools - Inkscape

I recently came across Inkscape. It’s an open source vector graphic editor. An example of vector graphics is windows clip art. The image is stored as lines and colored areas rather than pixels, which means you can zoom in infinitely without pixelation.

I find it absolutely brilliant. It’s very intuitive and easy to use, and comes with interactive tutorials.

A big hurdle for small scale independent coding is that programmers are usually pretty bad at art – hence the commonly used term “Programmer Art”. I find that this program allows me to ‘build’ my art, rather than ‘draw’ it. It allows me to make much better images than I get when I try and use something like Photoshop. You could use it for in game art, website art, icons, all kinds of things.

Now for something really cool. It saves in Scalable Vector Graphics (SVG) format, which is an open source XML format. You could use Inkscape as a level layout tool for a game. For example, red circles are where enemy tanks go, the player starts on the blue circle, walls can be made from lines, etc. You can even import textures into the art, which could be a way of bringing texturing into the world. Using Inkscape in this way could save you months of effort compared with making an editor yourself. You can then use an open source XML parser like Xerces to parse the file. Your whole tool chain is written for you!

Another thing you could use it for is laying out UI screens. Using Inkscape could provide a far better development process than hard coding positions, or hand writing a text file of parameters.

One downside is that it doesn’t support making animated vector graphics. Still though, it’s mighty cool. If you’ve got some free time, I recommend downloading it and having a play.

Saturday, August 05, 2006

Favourite Sites –

I like to use lots of different tools while I’m working. Finding a good tool to help you do a task can reduce a mundane task like renaming 100 files from 30 mind numbing minutes to 5 minutes of feeling smug. Brilliant.

When picking a tool, as well as just generally searching around myself, I usually check the free country as it usually has a good list of programs to try. I usually find it quicker to find a good tool using this site, than searching through other free/shareware directories.

Tuesday, August 01, 2006

Getting a games programming job - Tip 5 - Understanding The Interview Process

To get a games job you’ll go through an interview process. If this is your first proper job, then it’s good to know what to expect. Here’s how an average games company might do things:
  • You submit your resume.
  • If they’re interested in you, someone contacts you to arrange a phone interview.
  • You have a phone interview with someone technical. They probably ask programming and problem solving questions, as well as about the things you’ve listed in your resume.
  • If that goes OK, they might send you a programming test which you do at home and email back to them. This could be 10 questions in which you write a function, or writing just one system.
  • If that goes OK, you’re invited in for an in-house interview. If you’re out of state, then they’ll either fly you in, or perhaps do more phone interviewing first.
  • If the interview goes OK, they check your references.
  • If your references check out they make you a job offer.
  • You choose to accept or reject the offer.
Each company is different. For example, some companies don’t do a programming test, or do the test before the phone interview.

In future posts I’ll spend time talking about the different stages of the interview process. I’ll aim to give some tips which help you know what to expect, keep you calm, and generally improve your chances of landing a job.

MSDN is now free

I just heard that MSDN is now free to download. It was available online before, but if you prefer to have it local and like downloading 1.6GB files, have at it...

MSDN is a huge technical library which covers all the different Microsoft technologies from Visual Basic to SQL server. If you're coding games, the windows and C++ stuff will be occasionally useful, but you can access it all online too.