Archive for June, 2008

Adapting one Content Pipeline to Another

A question recently came up in the XNA Forums.  The poster wanted to maintain his own asset pipeline, but still wanted to use the content manager infrastructure.

Regardless of the discussion on whether it makes sense to reproduce the functionality that the XNA Team has built for us, he may have had perfectly valid reasons.  For example, his team/studio might have a database-based content management system.

Thankfully, because of the fantastic design of the content pipeline, this is actually quite simple :-)

Taking a page from the computer scientists:
http://en.wikipedia.org/wiki/Adapter_pattern

In computer programming, the adapter design pattern (often referred to as the wrapper pattern or simply a wrapper) ‘adapts’ one interface for a class into one that a client expects. An adapter allows classes to work together that normally could not because of incompatible interfaces by wrapping its own interface around that of an already existing class. The adapter is also responsible for handling any logic necessary to transform data into a form that is useful for the consumer. For instance, if multiple boolean values are stored as a single integer but your consumer requires a ‘true’/'false’, the adapter would be responsible for extracting the appropriate values from the integer value.

Using this pattern, it becomes obvious that the content Importer can serve as the adapter.  Let’s use a somewhat trivial example to illustrate.

Adapter PipelineLet’s say for a second that our original forum poster has a fairly complex Mesh generation system that stores meta-data in a database.  This data must then be run through some sort of process to generate Mesh information for runtime.

Now, in this model, all artists only interface with the Custom Asset Manager.  They may not even know anything about XNA game studio … let alone some content pipeline.  But that’s ok … because as described above, all we need is an adapter to import data from the custom asset manager into XNA Game Studio.

This content pipeline importer can be linked to a custom extension,  let’s say, .db.  The .db file can be nothing more than a text file with a database connection string.  Once the importer reads the text file, it can create whatever NodeContent or MeshContent it needs from the data in the database … or maybe even custom types that suit the data.

The great thing about this approach is that it allows his studio to continue using whatever asset pipeline works for them.  But they still get access to the great features of the XNA Content Pipeline.

Comments

Socially Aware XBox Live Games

What if a network session was more than simply a temporary connection to exchange interactions between two or more geographically distributed participants?

What if every encounter meant that the value of your local “installation” grew by just a little bit?

These are some of the questions I’ve been asking myself recently after reading an article (which I can’t find again for the life of me) that was talking about how the XBox’s networking features are so easy to use, that even the most low budget of titles can offer multiplayer.

With barrier to entry being so low, one must begin to question whether maintaining the status quo is the best use of resources.  Most people, when they think of multiplayer, immediately think of the multiplayer arena.  And you can see why … it’s an obvious way of limiting the size of the “world” that the player interacts with (thus limiting computing requirements).  It also lets the game designer avoid other issues such as balancing because you only have to contend with the few players that are in the arena.

Take a few minutes and download the Battlestar Galactica game on XBox Live Arcade to see this pattern in action.

This prototypical game design pattern is so played out that I am instantly turned off when I’m confronted with it.  What is it about online networked play that instantly drives developers to create competitive matches that pit you against other players.

Why aren’t there more co-op games?  one of the things I most enjoyed when I was growing up was playing two player games that I could play at the same time with my brother (Contra, Chip n’ Dale, Double Dragon).  It was so much more fun than playing against him.

But even if developers were to make this shift in thinking and produce more co-op modes … I don’t think that’s going far enough.

Spore is an upcoming game from visionary designer Will Wright.  It includes a feature that I think perfectly showcases the concept I’m trying to convey here.  When you create a creature in the game, it will be uploaded to a central server, and automatically distributed to other spore gamers over the internet.

Aside from the various accolades that you can surely find of the game from the various review sites; the reason I find this so fascinating is the idea that just by playing the game the value of your game increases.  It does this by gathering content from other players of the game.  Conversely, by merely playing the game, you are increasing the value for other players.

Although you may initially think that something like this is not feasible using the XBox Live APIs that shipped with XNA Game Studio, I beg to differ.  Although it wouldn’t be centralized, I can easily see how a feature like this could be implemented.

  1. First and foremost, your game/toy would have to allow you to “create” something.  This could be a creature, a vehicle, a song.  The possibilities here are really only limited by your imagination and creativity as a game designer.
  2. Your game could look for a random network session and join it.
  3. Once connected, your game would exchange whatever it is that your players create.  Again, this could be creatures, weapons, vehicles, whatever makes sense for your title.
  4. This content could be written to the player’s local data storage along with meta-data such as author, date, etc.
  5. History/Playbook keeps track of players that you’ve shared with … this can be used to alert the player of repeat encounters, or even to avoid excessive bandwidth if we recently exchanged content already.

This kind of social/decentralized interaction is one that I don’t believe has been explored to the fullest extent.  Imagine a game that uses genetic algorithms, or neural nets to evolve local AI elements.  The player could train and these agents to their local preferences, and then breed them with other player’s agents that exibit beneficial qualities :-)

Comments (2)

Why all the XACT hate?

XNA has been out for a few years now, and I still don’t understand why people seem to dislike XACT so much.  After I started working on some of the audio for an upcoming presentation, I was reminded just how powerful of a tool it is.  I mean, I guess I understand the allure of the super simple audio model offered in XNA 3.0.  For simple projects it’s definitely a lower barrier to entry. 

But here’s one problem I see with it … I can almost guarantee that very few people will use XACT once 3.0 is released.  Considering that I do not see very much community involvement from the XACT team, or any individuals (where are the xact tutorials, where is the xact team blog?), I fear that an atrophying user-base will kill the project for future releases.

Much of the feedback I see about XACT seem to mimic a lot of the negative feedback of the content pipeline.  Thankfully, the XNA team hasn’t given in and allowed runtime loading of content files.  The second they enable that is the second that 99% of people move their projects to import/loading everything at runtime (and thus, introducing longer load times into their games).  By limiting that choice, I believe they’ve done the community a favor because at this point, lots of people are very familiar with building custom content pipeline extensions.

so I guess what I’m trying to say is, if you’re an XNA developer … fire up XACT, and give it some love :-)

ps. I suppose this would be an ironic time to announce that once I upgrade Scurvy.Media to 3.0, I’m going to experiment with automatically importing the video’s audio stream using the new SoundEffect/Song APIs :-P

Comments off

XNA Presentation

I’ve mentioned this already to a few close friends, but figured I’d post it here for posterity. I will be giving the presentation at the August ONETUG meeting. The topic?

Software development is about constantly learning, and developing your skills. Each new technique, or novel solution to a problem improves your overall effectiveness and value as a software developer/engineer.

XNA Game Studio can help you experience those new techniques and solutions by exposing you to a different world of software engineering problems. If you embrace game development as a hobby, you *will* become a better programmer, and this session will show you how.

I’ve already got the presentation in development … pretty excited to finally be talking to the locals about some of the stuff that has had so much of my focus for the past year or two :-)

Comments off

XBox and the Case of the Mysterious Color order

I’ve been meaning to blog about how I finally got the lastest build of Scurvy.Media out the door. Those of you keeping track at home will remember that, though the previous build shipped with XBox platform support, the colors of the videos were unfortunately very “off”.

After a large amount of experimentation, and tons of help from the guys over on the #Xna IRC channel, we were finally able to figure out the problem. To explain the solution, I must first explain a tiny bit about the architecture of the Scurvy.Media content pipeline.

  1. Decode each frame of the video as individual textures. The pipeline currently only supports AVI video using the AVIFile library from CodeProject.
  2. Write the contents of each frame sequentially into one large .XNB file through the content writer.
  3. At runtime, open a stream (and keep it open), and read each texture one at a time in a separate thread.
  4. use .SetData to set the contents of a texture based on whatever the current Frame is.� Technically speaking, there are two textures at play for the purpose of double buffering … but that’s largely irrelevant to the topic at hand :-)

So the confusing part was that the code ran perfectly on windows, but on XBox the colors were all messed up.

Now that I’ve explained the architecture, I’ll explain the solution to one of the issues.� Mainly, it’s the fact that the color order on the xbox platform is *different* than it is on windows.� Why that is I don’t know, I wasn’t able to find very many sources of information on this, but c’est la vie :-)

XBox:

  • RGBA

Windows:

  • BGRA

To get around this problem, I simply had to transpose the color channels as I imported the video when compiling for the xbox platform.

byte[] xpix = new byte[pix.Length];
for (int i = 0; i < pix.Length; i += 4)
{

��� int first = i, second = i + 1, third = i + 2, fourth = i + 3;
��� xpix[first] = pix[third]; //x=red
��� xpix[second] = pix[second]; //x=green
��� xpix[third] = pix[first];//x=blue
��� xpix[fourth] = pix[fourth];//x=alpha�
}

b.SetPixelData(xpix);

the code snippet above takes a byte array that uses four bytes per channel.� And it just puts it into a copy of the byte array.� Technically, I could have used the same array and just rearranged the byte values as I go … but perhaps that’s an improvement for another day.

But Avast! There still be problems on the high waters!

After making that change, the colors were still not right.� What we eventually realized is that I was writing byte data directly from windows (who’s x86 architecture is little-endian), to be read from the xbox (who’s powerpc architecture is big-endian).

Sooooo … the answer was this:

byte[] xpix = new byte[pix.Length];
for (int i = 0; i < pix.Length; i += 2)
{

��� int first = i, second = i + 1;
��� xpix[first] = pix[second];
��� xpix[second] = pix[first];
}

output.Write(xpix.Length);
output.Write(xpix);

Right before writing the byte array to disk … I flip every other byte.� Once I did that, the video was alight with correct coloration :-)

Again, a huge thanks to the guys on the #xna IRC channel.� This wouldn’t have been possible without them.

Comments off

I’m @ ]InBetween[, where are you?

Writing this from the Orange County Convention Center’s “OpenSpace”.  hanging out with the rest of the central florida .NET Geeks:

http://www.devfish.net/articles/inbetween/

You should at least try to make it before the end of the day so you can get a badge and make it into the after-party at Destiny Nightclub :-)

Comments off