Adapting one Content Pipeline to Another

By on 6/30/2008

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.

See more in the archives