Saturday, February 16, 2008

SQuba Car??

Bond...James Bond.

It's awesome yet crazy. The new submarine car is out. A car that drives on land and underwater.

Just make sure you are wearing your freshly tailored scuba suit before you decide to take a nice midday dive. :)

WHERE'S MY TELEPORTER???

Texture Cache

I created a texture caching system that separates the region definitions from the requesting a region. Below is a code snippet of it in action.

XmlDocument xml = new XmlDocument();
xml .Load("textures.xml");
TextureCache tc = new TextureCache<Texture>(xml, new CustomTextureBuilder());

The TextureCache object takes in XML and a TextureBuilder to load the textures appropriate to the application. The XML defines the regions within a texture. The TextureBuilder is an application specific object that performs the conversion of the XML data into the right Texture format. For example, in my Pong remake I am using XNA so my TextureBuilder converts the XML data into a Texture2D object wrapper.

The XML file is pretty straight forward, see snippet below. Each texture node has a collection of region nodes that define a portion of the texture that can be used in rendering. Each region is given a name that is used as a key in the texture cache.

<textures>
<texture name="textureName">
<region name="regionName" x="0" y="0" width="64" height="64" />
</texture>
<texture ...>...</texture>
</textures>

The power behind this interface is it's retrieval mechanism. Basically you ask for what you want.

Texture t = textureCache["textureName"];
TextureRegion tr = t.GetTextureRegion("regionName");

You just ask the texture cache for a texture, then ask the texture for the region you would like to render. It's that simple. Another powerful piece is the system relies on Generics so each application can have the texture cache provide application specific textures.

In the future I am looking to build a UI to create the XML definition file to simplify that process. Will keep you posted on the results of that endeavor.

Stay easy.