Category Archives: XNA

I suppose it’s inevitable..

I would like to preface this post with the following disclaimer; I am not on the XNA team, nor have I been on the XNA team in almost two years. Do not mistake anything below for an “insider scoop” of anything because I do not know what their current plans are, nor do I know what their future plans are. Everything below relates to XNA version 1.0, and there are still folks who worked on later versions over in that organization. With that out of the way, I shall continue!

Shawn Hargreaves announced the other day he was leaving to move over to the Windows Phone team after six years working on XNA. I’m sure this isn’t a surprise to anyone who keeps even a rudimentary pulse on the XNA scene is subscribed to Shawn’s blog and has read it. However, for me it was a little bit bittersweet.

As the title of this post implies, I suppose it is inevitable. After all, as Shawn points out, he was working on XNA for over six years, and that’s a very long time to be doing one thing. However, with Shawn’s departure, from my recollection everyone that busted their asses to get the first version of XNA out the door has moved on from that team (not entirely true; there is still one person left in that organization who was there at the start of the XNA project, but he’s been on a different role now for quite a while).

The team that started XNA wasn’t very large to begin with, and we weren’t all “publicly popular” (such as Shawn, Kluch and myself), but the small group of us that were there from the start had a huge unknown challenge in front of us, not even sure if it would really work. We had a completely unrealistic release schedule (you want us done before the end of this year? right), were writing everything from scratch, and we had exactly zero customers.

I’m extremely proud of what we accomplished with that first release, and it was probably one of my favorite times at Microsoft. We almost felt like a bit of a startup within the company, and we were successful beyond our original ideas. By version two we had the concept of an “App Store” before Apple did (not to take anything away from Apple, there store is obviously more successful than XBLIG), and people were making money.

As often happens though, time goes on, new people are hired, other people leave. Inevitable. While I was there, we always prided ourselves on our ability to make good hires, so I’m sure the people that remain are top-notch, but it is still somewhat sad for me to look back and realize that everyone that made version one of XNA what it was has now moved on to other adventures in their career. I will always look back at those times fondly. Working with that group of people was a pleasure.

As for what line of code of mine that is executed the most, I can’t say actually since I had a hand in almost ever piece of the xna runtime. It’s impossible to run an XNA game without using some of my code, even now with me gone for a few years. In the runtime itself, it’s probably the graphics device creation still (even though that was changed in v4).. By now it could be the predicated tiling work or even the intro “XBLIG screen” that you see before every game. We should have collected metrics on this kind of stuff!

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:

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.

Dean’s opened his new site

My coworker Dean has opened up his new website now, you can go check it out!

My new project!

After I left the XNA team last year, two of the most popular questions I was ask was why I left and what I was going to do next. It was hard to really formulate a good response to either given the general culture of secrecy that seems to always be around. However, now is the time to lay it all out on the line!

First, why did I leave to begin with? Philosophical differences I suppose you could call them. I was pushing very hard to get a LISP and COBOL version of the project out, and they didn’t think it would have a large enough audience. I still can’t believe they were so naive, but c’est la vie.

When I left I had a multitude of opportunities available to me, each of which were very compelling. Right when word got out I was leaving, I was contacted by the good folks at a new team that was forming. They had discovered that certain images in certain sequences could actually change the chemistry in the brain and give the user experiencing them a completely new outlook on life. The government wanted to get involved though, and I’ve worked with the government before. The technology was exciting, but not enough to work with them again.

Yet another group offered me a new job which sounded at first glance to be quite boring. Have you seen those big number signs where they’re constantly increasing with witty phrases such as “Your share of the national debt is <blah>”? Did you know that Microsoft wrote that software? I was offered the chance to be the guy who watches the numbers scroll by and make sure they stay accurate. Sure, it sounds boring, but you get to travel the world and see lots of numbers, how bad could have it been? Everyone loves numbers!

However, the job I finally took was over in Microsoft Game Studios working on an amazing new title. I probably shouldn’t be telling anyone this, but I’ve been holding it in so long, I just can’t wait anymore. What’s the worst they could do? I’m proud to announce our new game Kinectodeck. Everyone has seen how amazing it can be when you’re the controller, but we wanted to see how amazing it could be if you were actually in the game!  We use an amazing set of new technlogies to transform your living room into the actual game playing field. There are eight different Kinect sensors spread throughout the room along with sixteen mini-projectors which bring the game world directly there! It is a completely new innovative experience, where the possibilities are really limitless.  One of our recent test subjects was sent on an safari adventure where they were out riding a tiger through a lake:

We have a few bugs we still need to work out though. For example, due to our desire to have maximum realism, we may have went a little overboard. Shortly after the picture above was taken, the tiger ate our poor test subject. It’s ok though, she signed the release form. Minor setbacks, something you would expect from such an ambitious project. Major innovation doesn’t happen by being safe!  We’re moving quite fast though, and an expected release date should be just about a year from now, and I can’t tell you how excited I am.

You may be wondering how you write the games though? Why XNA of course!  You will of course need an AppHub membership to get the toolset. I’m also happy to announce that the toolset will be available for download (in a very early alpha form) next week! Stay tuned for more information, this is an exciting time in our industry and I am ecstatic to be a part of it.

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!