Blog

By DigitalRune Team on Saturday, February 19, 2011

In all XNA games you have to create your own Game class that derives from the Game base class. Here is a pattern in which we use the service provider pattern to create a clear structure for our game class.

In many XNA games and samples the Game class does a lot of stuff and is maybe the most complex class of the application. This makes the source code difficult to understand and hard to re-use. We suggest two things to improve this:

  • Use separate managers for the game’s sub-systems (e.g. graphics, physics, UI, …) and make these sub-systems accessible using the service provider pattern.
  • Separate game-specific game logic and drawing from the Game class.

By DigitalRune Team on Tuesday, February 15, 2011

We have discussed the Service Provider pattern in the last blog post and in this post we will show how to implement a service provider, how the DigitalRune libraries support this pattern, and how to use it in an XNA game.

A Simple Implementation

Implementing a basic service provider with a Dictionary is simple:

By DigitalRune Team on Saturday, February 12, 2011

The service provider pattern is one of my favorite patterns: It creates clean, slick code when used right - but when used in the wrong places it creates libraries that are hard to use, difficult to understand and a nightmare to maintain. In this blog post we examine the service provider pattern, related concepts, like global variables, services, managers, service providers, contexts and how they can be used in games.