Writing games and writing platforms..

Much like my love of fiction books, I have been a gamer for basically as long as I’ve been able to be. I have no idea where it started, but the first time I really I remember playing games was at a pizza place back in Saint Louis called Pantera’s. I played all kinds of games back there, although I remember wasting way too many quarters in Rastan. Before that there was Spy Hunter and if we go back far enough, even Pole Position. I’m sure there was probably others before that, but we’re edging back to the limits of my memory, I’m not *that* old after all.

At the time I was playing these though, it hadn’t yet occurred to me that there were people who actually created these wonderful things. Sure, it seems obvious in retrospect, but at the time I was a young kid, I probably would have believed that unicorns and fairies made the games I loved. I knew there was some kind of a computer in there, and that’s what I wanted, but we were quite poor at the time and couldn’t afford one.

Luckily, my mother saved up for a year and she was quite excited to finally give me a computer for Christmas one year, and boy was I excited to get it. It was an amazing piece of hardware called the TRS-80 (that has a nickname now of “trash 80”, but I didn’t care, it was a real computer). Looking back at that now, it’s kind of funny, the very first thing it said when you turned it on was Microsoft (MS did the BASIC for the system). Who would have thought that 15 years later I would actually be *working* at Microsoft, the computer had given me an inspiration I didn’t even realize.

The system came with the BASIC mentioned above and it was fascinating to me. I could type things and stuff would happen. I devoured the few “tutorials” in the book that came with the system and was anxious to find anything more I could. I started out probably the way many kids back then did, by copying huge chunks of text out of a magazine, not necessarily understanding what was going on, but being amazed by the results. Well, after running it the first time, realizing it was broken and then spending hours painstakingly trying to find the single spot I had messed up typing.

With that I knew what I wanted to do when I grew up. I would write games, and despite not even being a teenager yet, I was going to write the best game the world had ever seen. It was here that I learned a very powerful lesson; that being that writing a game was hard. I wasn’t even remotely qualified to do this.

I spent the next several years learning how to be a developer in general, always thinking of games in the background, but learning the basics. I learned new languages, being fascinated by the power of Pascal before migrating to C, and then discovering Visual Basic and realizing that as a development language, this was the beginning of a boon to developers everywhere. It had a low barrier to entry and could explode at any time.

Now, I still wanted to be a game developer, and I still didn’t think I was qualified to be one, so it was then that I decided what better way to become qualified than by opening up game development to the masses and help *everyone* become qualified. By now, I was already working at Microsoft and migrated over to the DirectX team and began a project that intended to bring the power of DirectX to Visual Basic. I’ve told this story many times, so I’m sure everyone knows by now that DirectX for Visual Basic turned into DirectX.NET which turned into Managed DirectX which turned into XNA. By the time I looked up I realized that I had been writing platforms for an entire decade, and still not writing games.

That’s when I switched. I moved over to Microsoft Studios (then Microsoft Games Studios) and started making games. So here we are now, a year and a half later. What have I discovered?

Despite both of them being writing code, and actually, even somewhat related code, the two activities are so very far apart. There are so many things you need to take care of for a platform (such as robust parameter validation) that you simply don’t need to worry about in a game. On the flip side, writing games has extra constraints you just don’t see on the platform side such as game designers. Ok, sure, you could argue that program managers help define the “mechanics” of APIs much like a game designer helps define the “mechanics” of the game, but once the program manager has defined the mechanics, she is done. The game designer must also make those mechanics fun.

There’s so much more creativity required when writing games as well. Sure, there is some creativity in designing API’s and functionality and feature set on a platform, but it’s not nearly the same magnitude. Actually, I suppose that isn’t fair, there is a lot of creativity in developing a platform, just not the type of creativity that excites me the way writing a game does; coming up with narrative, etc.

It’s also taught me that despite spending a decade making game development easier to do, I still have so much to learn. I would feel comfortable developing a platform completely on my own (hell, I have done it before), while I’m not sure I could say the same thing about writing a game. The work game designers do (and the way in which they think about things) is a skill I need to learn, and I’m thankful I have the opportunity to learn from a group of people who are amazing at what they do. Some of my coworkers have done design work on some of my favorite games of all time such as Command and Conquer; Gears of War; Alan Wake; Dungeon Siege; the list goes on and on.

That isn’t to say that I worked with less amazing people before (I’m sure everyone knows who Shawn is, which would disprove that), it’s just a different type of awesome. Developing a platform, the cool things we normally get to see could best be described as tech demos, and while they’re amazing in their own right, you normally have to wait for your customers to write something awesome to fully realize your initial vision.

If there was one thing I missed about being on the platform team it was the intimate knowledge of what was coming next. I just don’t have that anymore, and it is frustrating. I wish someone would say something about XNA and Windows 8 just like everyone else does. However, for where I was in my career and my life, making the transition to making games was definitely the right move for me. I can flex my creative juices and expand in the areas I am weak in.

It’s nice to realize that your dream job at eleven can still be your dream job at thirty six.

Garbage detector from my Gamefest Slides

One of the last things in my slides for Gamefest was a simple little object I had written to help us detect when our code was allocating memory we weren’t expecting. Due to the size limitations of slides I had attempted to to shorten the object to the minimalist version, and in doing so lost a few things. Here is the object I used in its entirety:

Not very much different than what’s in the slides, but a few subtle differences. The most important being whether or not ‘true’ or “false” is passed in during the two calls to GetTotalMemory. What does this code actually do though?

I wrote it basically to allow myself to “wrap” a section of code and measure any allocations from it. At the constructor of the helper object I measure the total memory in use and store how much allocation (in bytes) I expect the code block to take. Then at the end I measure the memory once more and if more memory was allocated than I was expecting I break into the debugger.

A few things to note. First, when you pass in ‘true’ to GetTotalMemory a full collection will occur, so if you are doing this often you will dramatically slow down your application.

Second, you’ll notice that the slides pass in ‘true’ in both spots which is probably not the behavior you want (you’ll notice in the code above that ‘false’ is passed at the end in the second constructor). If you pass in true in both spots, you will only catch allocations that were not garbage because any garbage would have been collected due to the ‘true’ being passed in!

Now, there are times when you do want to know this, so having the option is certainly fine, but the majority of time you want to know about allocations that create garbage, in which case you need to pass in false to the second call.

Another point I brought up during the talk that isn’t obvious is that this code completely ignores other threads. Which means if you have another thread allocating memory in between the two calls, you will get “false positives” that can prove difficult to track down. When I used this method I kept the code I wrapped in this object small to help eliminate them.

To see an example of using this helper in code see below:

Some thoughts on Azure…

With all of the spare time that I don’t seem to have, i’ve been working with Azure a bit for a personal project that I’m not going to go into much detail about (yet). Well actually, I suppose that isn’t fair. Initially I started simply using the hosting I have on this site to do some simple stuff before I quickly got annoyed with it. I didn’t need a web host, I needed some real cloud computing. I briefly looked at Google’s App Engine and Amazon’s AWS before figuring since I work at Microsoft I should probably just dive in with Azure, so that’s what I did!

Once I got over the initial system shock of “what on earth is all of this stuff” and followed through a few examples, I was actually pretty pleased at how simple getting something up and running was. I had downloaded and tried the Azure SDK quite a while back in beta (before we announced it) and it was hard to use, the docs were non-existent, and no samples existed at all. I was completely lost and gave up on it until recently. While I can’t speak for the SDKs for Google or Amazon, the Azure SDK has improved leaps and bounds now and it finally started making sense!

It took me basically a week to write the underlying infrastructure for what my side project wanted when I was using this hosting environment, and a large portion of that was trying to remember SQL, and writing stored procs. I made the equivalent Azure worker role in about a day and didn’t have to write a single SQL statement (unless you count some LINQ in my role, which I don’t) or stored procedure! I also didn’t have to worry about transactions or any of that painful stuff!

One thing that I guess makes me naive is that I was surprised at the potential cost for even the simplest of things! For example, a “small core” on Azure costs $0.12 per CPU hour (and CPU hour is measured by the amount of time the application is deployed). This means for a single core, for an average month you’re looking at $0.12 * 30 days * 24 hours = ~$86. Worse, it’s recommended you run at least two instances, and you have to if you want the “guaranteed” 99.99% uptime. Since each instance is another core, basically double that cost so $172 per month to run your application in the cloud. You can get 3+ years of web hosting for less than that.  That’s just the CPU cost though, you end up paying for storage as well!

At first, storage “sounds” pretty cheap. You pay $0.01 per 10,000 transactions which sounds super cheap, but that adds up as well. In most of the samples for Azure you’ll notice that in the run method it will essentially check for messages in a never-ending loop to see if there is work to do, and will normally check these messages about once every five seconds. The act of checking to see if a message exists is a storage transaction though! Checking every five seconds is 12 times per minute or 720 per hour or 17,280 per day or 518,400 per month or an extra 51.84 pennies per month. Ok, so that isn’t all that expensive I guess. It does start to add up though, and there is an extra $0.15 per gigabyte of data you’re storing.. So a million transactions a month storing 2gigs of data is an extra $1.30, not terrible.

Now, I’m sure that large companies needing cloud computing find these prices to be quite acceptable (the Azure prices seem to be similar to the prices offered by Google and Amazon), and I actually don’t mind them too much, but they do seem to be a decent chunk of change for a developer just starting out. I guess I was just expecting prices to be similar to hosting prices so was surprised by the costs I saw.

I’m no where near an expert on the subject yet, but so far working with Azure and “in the cloud” has been a pleasure. Now if I could just get off my lazy butt and finish this thing…

Game development is still hard…

It’s hard to believe that over ten years ago I joined the DirectX team with a goal of making game development easier. Back then, being a game developer was a relatively “exclusive” club. The barrier to entry for developers who wanted to make games was very high in all aspects.

My first goal was to make the act of writing the code itself to be simpler. DirectX is very powerful, but was quite esoteric if you didn’t use it every day. At the time, it was C/C++ only as well, and while these are great languages the fact was that Visual Basic developers (C# didn’t exist at the time) outnumbered them five to one (at least). Over the next few years many VB (and some C/C++) developers migrated to C#, DXVB became Managed DirectX, which in turn morphed into XNA Game Studio. Through each of these iterations the act of writing the code for a game became easier and easier.

If my only goal was to make writing code easier, then by any measure I can think of I accomplished this goal, but it wasn’t. I wanted to expand beyond the PC as well, I wanted to allow every day folks to write code for their home consoles, and in 2006 (with the first version of XNA Game Studio) that goal was accomplished as well (followed by the ability to publish and make money a year later). People don’t think much about it now, but that was huge back then. Nowadays it seems every device has a public marketplace and an ability for anyone to write apps and make money from them (and you would dismiss them if they didn’t), but it wasn’t the landscape in 2006.

It was all of these “successes” that prompted my exodus away from the XNA team and into a game studio in 2010. I felt I had accomplished all of the goals I had in lowering the barrier to entry for game development and wanted to move on to my passion of actually creating them. The release of Beards and Beaks has given me a bit of time to be introspective somewhat (which isn’t to say I’m not busy, but still).

For all the successes that we’ve had though, the simple fact is that today, halfway through 2011, game development is still hard.  In some ways, I would argue that it is actually even harder today than it was when I started, albeit for completely different reasons.

While we certainly helped remove some of the barriers to entry over the last ten years, we didn’t remove them all, and we’ve actually added a few new ones. For example, it’s still extremely difficult for an up and coming game developer to hook up with an artist, just as it’s hard for that artist looking for things to stick in their portfolio to find a developer. People are still confused about what a good “game idea” is.

Actually, that’s a good enough side track that I need to break off for a moment for a mini-rant. I swear if I hear one more person tell me that they have a great idea for a game, and then begin describe some story I’m going to scream. In the majority of cases, the story is not what is going to make or break your game (and invariably when someone is describing a “game idea” to me in this fasion, they are not in the minority where it matters). You need to know what game mechanic makes your game interesting. Even in story heavy games, the game mechanic is what makes your game most times. If your game idea is essentially “all the game mechanics of Gears of War with a different story”, this isn’t a good idea.

Sorry, with that rant out of the way, I’ll continue. I believe the barrier to entry for a budding game developer is so low now that the real problems are no longer “how do I make games”, but instead “how do I stand out in the crowd”. The barrier is no longer to entry, the barrier is now to recognition. How can your shining gem of a game rise above the cess pool of thousands of terrible games?

If you ask me, this is an even harder problem to solve, and despite rambling on for all this time so far, I’m not about to say some magic incantation that solves it because truthfully, I don’t know how. Sure, I have some ideas which I’ll go into presently, but I have no delusions that they are a sure-fire way to success.

First, as I alluded to above, you need to have a good mechanic (and a fun game). If you’re trying to make a rip-off of Gears of War, well stop it because you’re not helping anyone and just adding to problem. Now, that isn’t to say that taking a formula that works and improving it is a bad thing, but don’t try to copy something whole-sale unless you can do it better. You want to make a game that’s like Gears of War but includes the ability to turn into a dinosaur and eat folks? Awesome! You want to make a copy of Gears of War with a budget of $30 and a diet coke? Get out of here.

When I say taking a copy of a game and making it better, what I really mean (most times) is “polishing” the game. The term is a little weird to begin with, but basically what it means is that the game looks and feels professional. It’s hard to describe, but you can see it when it’s there and will miss it when it’s not.

People think that polish doesn’t matter as much, but in reality it matters probably more than anything. Consumers can tell. Angry Birds is like a printing press that spits out money, but it isn’t an original idea or anything. The exact same game came out years before it, but that game was unpolished and forgotten to the sands of time. Rovio took the basic idea, polished the hell out of it and have made more money than they know what to do with.

Of course, once your amazing game is out, you then need to market yourself. I feel a bit sorry for the single guys (or small teams) in this regard. At Microsoft, we have entire marketting teams, and it’s still a difficult proposition! I hope one day soon to talk more about this and some ideas I have, but right now this post is already way longer than I was intending it to be.

As the title says, game development is still hard.. I suppose I have a lot more work to do..

Beards and Beaks!

If you follow me on twitter or the like, you may have heard by now that my latest Windows Phone game was just recently released called Beards and Beaks! I’m pretty happy with how the game has turned out, and thus far we’ve gotten pretty positive reviews with an average of four stars, and a large amount of the negative reviews were due to the fact that you can spend money beyond the actual cost of the game (which I can understand the reluctance there).

Beards and Beaks
Gameplay shot!

We had a lot of things we wanted to accomplish with this game, and while it isn’t perfect (what game is?) we did get the big ticket items we wanted in there! We wanted to come up with a game mechanic we hadn’t really seen before that worked well on the phone, and we wanted to enable premium downloadable content on the device. Based on the reviews so far, I think it’s safe to say we accomplished the former, and the latter is pretty easily quantifiable, so I feel really good about how the game ended up!

Meteor Power
Using the meteor power

There are also a lot of misconceptions though, or features people are just unaware of! One of the biggest complaints I see in the reviews is that people think that you have to spend actual money to use the mushroom powers, which simply isn’t true! Now granted, you certainly *can* spend money to use these powers more frequently, but your mushroom power bar slowly refills over time. If you played once a day, you would notice that every day you would have a new full mushroom bar!

Beards and Beaks
Attacking the crows base!

We also have quite a few more leaderboards than it seems most people realize. When you click the leaderboards button on the main menu you will see three leaderboards at first, but did you know the list of leaderboards at the bottom is scrollable? There are quite a few different leaderboards you can see if you scroll that list down! That isn’t even the start of it, every single level in the game has two leaderboards as well (best score and best time)! If you click the button next to the score or time on the level information tab, you will be taken to those leaderboards!

We also have quite a few levels. There are thirty in the base game when you first download it (seven in the trial), and another 15 in the first level pack (which is absolutely free)! Which brings the number of levels for free up to 45. There’s also currently another premium map pack available for $1 (another 15, up to 60 levels), and that isn’t the last map pack the game will see!

Anyone who’s seen my gamertag probably realizes that I love Xbox 360 achievements, and if you’re like me, you’ll be happy to know that getting all of the achievements in this game won’t be a lesson in frustration! It’s possible (albeit unlikely) to get every one of them in your first playthrough of all the levels if you know what you’re doing (and get a little lucky)!

I’m also giving a performance talk at Gamefest in Seattle next month in which I go into the nitty gritty details on the performance gotchas we ran into during development of the game, along with how I found them, and what I did to fix them.  The title of the talk is “Performance Patterns and Pitfalls for Windows Phone Games” if you want to find it in the list!

If you are going to be at Gamefest come find me to chat! Maybe by then someone will know what a Bleego is.

Sometimes I don’t understand book reviews..

Not that I have any complaint about them, it’s just odd. For example, my latest book only has a single review, but the review is glowing and the best it could be.  Now, I naturally don’t know how other books are doing, but I am a little obsessive compulsive, so I do watch the average Amazon sales numbers, and compare them to how my book has been doing. Generally, in the category the book is in, we do very well (which is awesome), yet I see other books doing much worse in the average sales with many more reviews and I wonder why? Does their publisher try to prime the channel with reviews? Pay people to give reviews? Maybe those books just give people the overwhelming need to tell others about them, where ours does not?

I also know that our book isn’t perfect, I’ve seen mistakes in there.

I’m curious though, what do you think about the book? Like it? Hate it?

Visual Basic for XNA?

So it seems that it was annouced today that XNA is coming to Visual Basic! I have to admit the announcement caught me a bit by surprise. As one of the people who has had to investigate (at various times) what it would take to make this happen, I have no idea where the team has gotten the time to do this! As the article says though, it was one of the most popular feature requests I can remember though so it’s good that it’s finally happening.

Wish there was more information though. For example, when is it coming? Is it coming on all the platforms, particularly Xbox? The picture in the article implies it will, but that doesn’t necessarily mean anything. I know they said to wait a few months, but given people have been waiting for literally years at all, I wish they would have waited until they could give us all the information rather than teasing it early when they cannot.

Although, I suppose I could be in the minority in thinking that. Some folks just like be teased and waiting a few months.

Loading… I hate loading…

I guess I’m impatient, because there are very few things that annoy me more than loading screens. In a world of instant gratification, waiting for any significant amount of time is unacceptable. Hell, I’ve only just started typing this and I’m already annoyed that I’m not finished yet. Loading just bugs me, and I see it creep a lot on Windows Phone 7 games. Perhaps I should ramble on about that for a while.

The first goal of the game should be to show me something on screen as soon as possible. While you can “somewhat” use the splashscreen.jpg trick to show something quick, in XNA applications, it doesn’t stay on screen long enough and looks awkward (in my opinion).  I personally would rather show my splash screen on the first render.  However, that leads me to another common mistake I see people making, and that’s loading a bunch of content (or all!) in the LoadContent method.  This is certainly a bad idea if you want to show something on screen quickly. This is essentially the order you will see things happen at startup:

  1. Game’s Constructor is called
  2. Initialize is called
  3. LoadContent is called
  4. Update is called
  5. Draw is called
  6. Goto 4.

While there are certainly nuances here, that’s the basic order, and notice that Draw isn’t called until way at the end.  I’ve seen people decide that the best way to fix this would be to draw something in LoadContent, and then they implement that, see that it works and call it a success. If only it were so easy. If your application is starting up once more after being tombstoned, essentially the same sequence of events happens, however there is a caveat this time.  While the “startup sequence” is happening, the phone will be displaying the “Resuming…” screen (my how I dislike that screen), and will not show anything from your application until the “startup sequence” has finished. In this case, the sequence doesn’t finish until *after* LoadContent has finished. So if you showed something on screen early in your LoadContent method, and then loaded a bunch of content, it would work in the initial startup scenario, and potentially fail in the restore from tombstone scenarios.

The easy way to get around these issues is to do all of your content loading (aside from the first thing you want to see on screen, such as a splash screen) on the second update call.  This allows you to show something on screen quickly in both the initial startup and coming back from tombstoning cases, and if you don’t have much content, should be sufficient enough. Your splash screen image will stay static on screen (and your application is essentially non-interactive) while the content is loading. If it takes more than a few seconds to get to this state though (ie, you have too much content), you have more work to do.

The most common thing I see happening here is the game will load only the content needed for the main UI portions, and will force you behind a loading screen after you choose the level or what have you. Again, this works perfectly fine, but we can do so much better! Why can’t you load everything you need while I’m playing around with the UI? For ease of explanation, let’s say that you are making a 2D game, and you have a large list of strings that are all the sprite textures you will need to load. What if you had a class such as this:

So long as you called BackgroundLoad.Go(this); sometime after you started up, your game would dutifully start loading all of your assets behind the scenes in a background thread.  This isn’t a foolproof solution though. For one, you have very little control over background threads on Windows Phone 7. You cannot change priority, and you have no control over how much they will execute (although on average for every 4ms your main thread is executing your background thread will run for 2ms).  In this example, you are also using the graphics device on another thread, which will take out a lock to avoid multiple threads manipulating it at the same time. In the larger scheme of things though, it’s still probably faster in this mechanism than without.

You will notice two potentially useless pieces of code here as well. First, a property to dictate when the loading has been complete, and a second in which the actual asset load is happening within an action rather than directly in code. The property is self explanatory if you think about it, you still need to know when all of your content has been loaded so you can allow the user to start the game! This just gives you easy access to it.  The action delegate is slightly less obvious though.

What should you do when the user has gone through the UI and is ready to play the game but the content isn’t done loading? As was mentioned earlier, you don’t have any control over the background threads execution time, and because it is running half the speed as the main thread, as the code is written now, your loading time could potentially be *increased*! This is most definitely not what we wanted. What you really want is a mechanism where you would load things in the background if the user was still messing around with the UI, but will switch to loading in the foreground if the user was waiting on loading, and that is what the action delegate is for. If you replaced the code in the thread method with the following, you will get this behavior:

Now your code is loading in the background while the user is messing around with the UI and will switch to the foreground once they’re done. In the degenerate case, this is still slightly slower than simply forcing them to wait at a loading screen, but given the degenerate case is almost certain to never happen, a mechanism such as this will (for most intents and purposes) always be faster. It certainly took me long enough to exlain all this, I should have had a loading screen for this post…

As a final caveat, this was an extremely simple example of multithreading. If you do anything more complex and don’t have knowledge of multithreading (or what the ‘lock’ keyword does), you should probably read up a bit on that!

Welcome to the new site!

Well, it’s been a long time since I’ve written a real blog post, and this is the first one on my new site, so what do I want to talk about!? I suppose we should start with why I migrated to a new site to begin with!

There are two major reasons in reality. First, I needed a web host for some experiments I wanted to run, so I figured I may as well just catch up with the times and buy one. I’m only a decade or so late, but better late than never right? Second, I needed to have more freedom in what I wanted to say. Having my blog hosted on MSDN was great and all, but despite the disclaimer up top, the reality is that anything I say there is essentially the same as saying it as Microsoft. While it’s certainly true some folks go wild on their MSDN blogs, I never felt very comfortable in doing so.  Now, I’ll be able to say whatever it is that I’m thinking!

Of course, this also means that my MSDN blog is essentially retired as of now, but given the frequency (or lack thereof) of posts there, it probably isn’t a big deal anyway!

So, what do I want to talk about on this new site? Well, a lot of stuff I used to talk about on the old site, game programming, XNA, Xbox, and Windows Phone! For example, while my latest XNA book is already out (look to the right), should I consider writing a new one? Perhaps I should release a few games on XBLIG or the WP7 marketplace? I’m not entirely sure what I want to do yet, but now i’ll have the chance to do them without having to worry about speaking as anyone but myself, which will be nice.

XNA Game Studio 3.1 Zune HD Extensions

If you were already developing games for your Zune using XNA Game Studio, you’ll be happy to know that moving that game over to the new Zune HD will be remarkably easy.  Today we’ve released the XNA Game Studio 3.1 Zune HD Extensions that will allow you to deploy to your new device and includes a few new API’s as well.

There is also a thread on the XNA Creators Club forums for any questions or discussions.