Wednesday, March 28, 2007

A general GameScreen implementation, Pt 2

Previously, I posted an implementation of Eli's GameScreen design that I'm using for the games in my book. I've just added two new virtual functions to the GameScreen class - BeginPause and EndPause. I did this to make dealing with audio easier - when a screen is about to lose updates, it should mute it's sounds, and then it can unmute them when updates resume. The change isn't terribly complicated, and it passes the smoke test, so I thought I'd post it for folks to use.

GameScreen1.1.zip

P.S. Last night, someone asked me if I was planning to change this class, and I swore I wasn't. I forgot about this feature. Sorry.

Thursday, March 15, 2007

My Rocinante Sails at Night on Her Final Flight

Today was the last day of my contract with the XNA team (non-employees can only work for one year). I had a blast working with them and hopefully I will do so again. Leaving is pretty bittersweet - I want to keep working there, but now I also get to work on the XNA book full-time and get that out the door. My current plan is to spend a couple months doing that and maybe spend some time on game development once I put the book to bed.

(regarding the title of this post: I've been listening to a lot of Rush lately in anticipation of their next album.)


In other news, there was an XNA user group for Microsoft employees this week. It was a lot of fun meeting folks developing XNA games and there are a couple things I want to share.

Respect Da Normals

One of the guys had a problem - he had game terrain made up of tiles using 3D objects (as opposed to quads) and each row of tiles was unevenly colored. One side of each tile was completely black, making the whole terrain look like a farm with furrowed rows.

Clearly a lighting problem. We suspected that the vertex normals weren't right (he was using vertex lighting) but they were fine in 3DS Max. In 3DS Max, each vertex had 3 normals pointing in the proper directions. But then we re-imported the FBX file, and BAM - the vertex normal was the average of the three distinct normals we had been seeing in 3DS Max. This meant that the vertex normals were pointing away from the light on the far side, so the light color was black, and getting averaged with the vertices on the other side, which were lit normally.

We started playing around with 3DS Max, and sure enough on the Export dialog there was a checkbox that said something that can roughly be translated as "Respect Da Normals". Of course it's unchecked by default. But paying attention to your normals is good advice for any time.

Avoid Solutions that are Too General

We were discussing how you might build a texture manager to load textures on demand and unload them when they're not being used. I suggested a simple COM-like approach - refcount the texture on Load(), and expect a Release() call for the texture to decrement the refcount.

"What happens if they don't call Release?"
"@#$% 'em", I said.
"@#$% 'em?"
"@#$% 'em," I repeated.

My reasoning is that, especially in game programming, there is such a thing as building a too-general solution. If a programmer uses one of your objects for a game and they don't follow the contract you specify, let 'em suffer. They'll pay the price by keeping the texture in memory if they fail to release it. Like the rule against premature optimization ("don't do it"), you should consider a similar rule against building solutions to problems that most game designers should know better than to cause.

Tuesday, March 13, 2007

XNA Creator's Club has a new website

Most of the XNA community is probably aware that the MSDN forums have moved to the new XNA Creator's Club website, http://creators.xna.com/ . But I want to point out that there are also new samples there, especially the Font Sample, which is VERY useful to those of us who sorely missed fonts in 1.0.

Sadly, my contract with the XNA team ends this week, but happily that will give me more time to devote to finishing my book. I can't promise to blog more often, but I can promise to think about blogging more often, and to feel guilty if I don't.