Thursday, October 30, 2008

IS 3.0 DAY!

"Are we there, mom?". Apparently we are, according to this post.

Although the Creators' site is down and no official word has been posted on the XNA Team's blog, if you cannot wait then you can follow the direct link published on the above-mentioned post to get the download of XNA GS 3.0 Release version.

Enjoy!

Wednesday, October 29, 2008

DBP 2008 WINNERS ANNOUNCED!

The winners of this year's Dream.Build.Play competition have been announced today.

In order:

  1. Carneyvale Showtime,
  2. Battle Tennis,
  3. Weapon of Choice, and
  4. HurricaneX 2.

Congrats to the winning teams!!!

Wednesday, October 15, 2008

CONTENT MANAGERS 101

If you have been using XNA GS for some time now, then you will know by heart the benefits of the content pipeline. If not, just to mention a few, here is a brief list for you to check before reading on this post:

  • Improves the process of importing assets to your own XNA games,
  • Faster loading times for pre-built assets (in binary format), and
  • Easy to extend for importing custom content to our XNA-based creations.

Ok, let us go on, now.

I. THE BASICS

On the process of creating your game, having built all your assets at compile time with GS you will have to use a Content Manager to load them at runtime. Fortunately, as you all may know by now, XNA already provides one for you. What is more, the game project template defines a reference and creates and instance of it on the game class.

This CM will take care of both, the loading and unloading process of pre-built assets. This means that behind the scenes, not only will it handle the instantiation of the assets being loaded but also, when properly requested, it will dispose for you the ones that can be disposed.

For loading, you will have to use a sentence like "this.Content.Load<...>(...);" or "this.Game.Content.Load<...>(...);" and the usual place to put them is inside the overriden LoadContent method of your game class and or drawable game components.

And for unloading, all you have to do is call your CM's Unload() method. Again, being a usual place to include this sentence inside the overriden UnloadContent method of your game class and or drawable game component.

II. BEHIND THE SCENES

Now, If you have been reading carefully you will notice that you can load assets individually but there is no way to unload them individually. At first you may think that this is an unpleasant restriction, but as you may conclude after reading this post -or at least, as I expect you will, this is not. In fact, it helps you manage your assets on a very tidy manner.

Generally, for the sake of performance, efficient memory allocation and best user experience, you design your game so that all the needed assets are loaded at "one time", say, at the begining of each level. So, even if you load the assets individually, that behavior from the perspective of "one-shared time bucket" -to call it some way- shows that you programmed the logic of your game to treat all these loaded assets as a cluster.

The above-mentioned rationale can be then extended to the process of unloading assets. There is no need to assume a priori that each asset will be unloaded individually at different times during gameplay. And therefore, they will be treated as a cluster, in this case during the respective level, and unloaded altogether, again, in "one-shared time bucket", when requested.

You may wonder: "Ok, but what if I want to dispose certain assets during runtime and, at the same time, to keep others in memory?". The answer to that is quite simple actually: just create more than one content manager.

We will get back to this topic in a moment, but first let us consider another important aspect of the Content Manager.

III. THINGS NOT TO DO

Avoid to manually dispose your assets!!! The CM does not like that you handle the destruction of assets by using sentences like "this.myAsset.Dispose();". In fact, the CM does NOT monitor if you do, and thus, it could and will get confused when that happens.

Let us see an example. Say you have a Screen1 and Screen2 classes and:

  1. Both share the game's CM,
  2. Both load the same pre-built texture on their respective local Texture2D fields,
  3. Screen1 is created and shown first, and
  4. Screen2 is only created and shown after Screen1 is manually disposed.

If Screen1 manually disposes the texture (either using the Dispose Pattern or by calling Dispose within the UnloadContent method) without calling "this.Game.Content.Unload();" first, when Screen2 tries to draw the texture on screen you will get an exception stating that the texture has being disposed, even if Screen2 loaded that texture. As I told you before, the CM gets confused with situations like this.


Therefore, avoid these implementations:


protected override void
Dispose(bool disposing)
{
if (disposing)
{
if (this._myTexture != null)
{
this._myTexture.Dispose();
this._myTexture = null;
}
}

base.Dispose(disposing);
}


... and ...


protected override void
UnloadContent()
{
if (this._myTexture != null)
{
this._myTexture.Dispose();
this._myTexture = null;
}

base.UnloadContent();
}


Being the proper way to unload assets:


protected override void
UnloadContent()
{
this.Game.Content.Unload(); // Or the CM you use.

base.UnloadContent();
}


Please notice that this is also allowed by the CM:


protected override void
Dispose(bool disposing)
{
base.Dispose(disposing);

if (disposing)
{
if (this._myTexture != null)
{
this._myTexture.Dispose();
this._myTexture = null;
}
}
}

protected override void UnloadContent()
{
this.Game.Content.Unload(); // Or the CM you use.

base.UnloadContent();
}


Comply with the above, and you will do good.

IV. THINGS TO DO

Getting back to the question of how to unload assets at different times at runtime, there is one practice that will help us understand why it is sound and thus, advisable, to have more than one CM in our XNA-based games.

When you create a program you declare global variables and local variables. This common practice incorporated to our daily programming tasks is the key that will then leads us to think of global and local assets.

You may consider an asset "global" if its lifetime lasts across all the game, or at least, most of it. In this sense, assets should be deem as "local" instead if it is expected and intended to unload them once a stage in the game has finished but the game has not and will not, at least for a while more.

Thus, when creating your game, use:
1) A Content Manager for "global" assets: the one instantiated by default within the Game class (which you can access using the Content property), and
2) One (or more) Content Manager(s) for "local" assets: say one content manager per level, per screen, or per whatever category that fits your game's design.

Again, group your assets in clusters based on lifetime, and you will know which one is global and which ones are locals. If all your screens will use one spritefont in common, then there is no reason to load and unload it for every screen; just load it once and hold it in the collection of global assets. If a ship model will be used in only one level, handle it locally to that level.

As you can see, using more than one Content Manager is a sound practice: easier to apply, easier to debug, easier to mantain and easier to extend.

Sometimes there is no need to have more than one CM for all the game, depending on the game of course, but still it is a good practice to know and get accustomed to, since in the end it helps us manage our assets at runtime in a more tidy and convenient manner.

So, my recommendation is: get used to it. The sooner, the better.

V. CONCLUSION

The Content Pipeline is a great tool to import assets to our XNA-based games which is complemented with the proper manager to handle that content at runtime: the ContentManager class.

By using instances of this class wise and properly, we could get (more) efficience in the fields of implementation, debugging, mantainability and extensibility.

In order to achieve this goal certain practices must be applied:

  1. Use one instance of the ContentManager class for global assets,
  2. Use at least one instance of the ContentManager class for local assets, and
  3. Do not manually dispose assets; instead, call the Unload() method of the CM.

I hope you find this post useful. Comments and suggestions are welcome.

Cheers!
~Pete

Tuesday, October 14, 2008

IT'S OFFICIAL!

We have an official release date!

The XNA Team has announced that the final version of XNA GS 3 will be out this October, 30th. Read the announcement here.

The wait is almost over.

Cheers!
~Pete

ZIGGYWARE'S CONTEST UPDATE

Head over Ziggyware's XNA Article Contest site since new prizes have been announced today!

Wireless headset, extra wireless controller, Milkshape 3D licenses ... read it from the source page.

~Pete

Sunday, October 12, 2008

NEW XNA ARTICLE CONTEST AT ZIGGYWARE

Ok, guys. Ziggy's raising the bar of prizes.

The new "Ziggyware Fall 2008 XNA Article Contest" gives away an XBox 360 Elite for the first price!!! And, as it also comes with a one-year suscription to the XNA Creators Club, the winner will have no excuses to produce a game with XNA GS for the 360 platform.

Simply put: Amazing!

Now, what do you have to submit? As usual, write and submit an XNA related tutorial for XNA developers. No ideas? Don't worry. There's plenty of examples to read on.

So, go ahead: read the rules, make your questions on the forums, put together your ideas, write them down, submit your article and that's it! You could become an "Elite" member of the 360 community at the end of the contest.

Happy writing!
~Pete

Thursday, October 02, 2008

XNA GS CONNECT UPDATE

In preparation to the extreme makeover that the 360's Dashboard will experience later this year, Michael Klucher has announced a new version of XNA Game Studio Connect.

This version will allow us to also run XNA Framework 3.0 games. So, this is a perfect time to start porting our projects to XNA 3.0, don't you think?

Head over Michael's site to know how to get the upgrade, which is a manual process.

'till next time,
~Pete

UNOFFICIAL SAMPLES FOR XNA 3 BETA

Hey folks!

Since the moment the CTP was out I spent some time to update all the samples available on the creators site to that early version of XNA 3.0, for my-own use.

Then, when the beta was published, and taking into account that maybe we will see no big changes to it until the final release, I decided to recreate them -complying with the license terms and conditions- so that I can publish them on the Web for those who eventually need them.

One important note: these files are NOT official so use them at your own risk!!! Otherwise, you can wait till 3.0 final gets released and thus, for the official education files.

The only changes in the code that you will see are those related to the 2D projects that used the WrapAngle method (created in the same class that used it). Instead, MathHelper.WrapAngle(...) is now in place. And ... yes! I almost forgot: each zip file contains a Windows-only project.

Well, here they go (hold on to something):

First Wave:

Second Wave:

Yes! Third Wave:
I think ... This Is The Fourth Wave (?)
Ok. Who Am I? And Why Am I Typing This?
No, Seriously ... (Why The Heck Am I Doing This?)
Phewww! At last, I finished ... man, I stopped counting after the first 20 links.

Well, I'm done, so in case you're using XNA 3.0 beta, I hope you find them useful.

Cheers!
~Pete

BLOGGING AGAIN!

Wow! It's been a while since my last post here. The reason: getting my life back to normal after my visit to Seattle/Vancouver.

A lot has happened since my last post. I'm still creating my own engine with XNA 3.0 (the latter is now out in beta), I submitted my demo game for the DBP compo, and we witnessed how a "ninja cat" approaches.

About my entry, well, it was created in 10 days ... the last 10 days before the submission deadline! I'm proud of the result but not proud at all about the code ... that implementation goes against of all my believes and practices in software design. But, it had to be done on time no matter what if I wanted to enter the compo. Why did I start so late? Well, that's a loooong story (maybe I'll blog about it some other time).

Man! There's a lot of great entries this year that really show off the power of XNA. If you want to take a look at them just go to http://video.msn.com/ and search for videos tagged, say, DBP? ... or "Dream Build Play", thanks Lawrence ;)

My favorites are ... well, I'll let you know after the results are in :-D

Ok, I think that's it for now but stay tuned since more is comming next!