May 222011
 

When a data-, entity- or datalist resource requires another resource that has not yet been loaded the resource manager will load the required resource automatically. For this to work a resource that is required by another resource is referenced by it’s ID in the requesting resource by placing it into XML tags that end with an uppercase string ID. Because of this the name of property XML tags inside data resource files may only end with ID to mark a property that contains an ID to a referenced resource.

Sounds confusing enough? OK! What it all means is that if you write an XML tag with an uppercase ‘ID’ at the end of it’s name, that tag is recognized as containing a string which is an ID which references to another resource.

If the referenced resource is a text- or datalist resource the referring ID needs to be made up of two parts: first the ID of the text resource or the datalist resource and second the ID of the actual string as defined in the text resource file or the ID of the item in the datalist. These two parts need to be divided by a slash character ‘/’. To better understand this have a look at the structure of this example “infantry unit” entity definition:

<?xml version="1.0" encoding="UTF-8"?>
<data>
    <entity id="unitInfantry">
        <components>
            <component classID="tbsUnitPropertiesComponent">
                <nameID>textUnits/nameInfantryUnit</nameID>
                <descriptionID>textUnits/descInfantryUnit</descriptionID>
                <movementTypeID>movementTypes/movementTypeInfantry</movementTypeID>
                <price>1000</price>
            </component>
        </components>
    </entity>
</data>

… the component properties nameID and descriptionID are referencing to an ID of a text string nameInfantryUnit and descInfantryUnit which are both located in the text resource with ID textUnits. The movementTypeID property contains a referenced ID to a lookup-table datalist item with ID movementTypeInfantry in the datalist resource with ID movementTypes.

If a resource is already loaded and is then requested by a referencing resource, the resource is not loaded again but it’s refCount is increased.

May 222011
 

tetragon uses a resource index file named resources.xml that sits inside the resource folder and that contains information about where the engine can find which resources. It is loaded and parsed during the application init phase and all it’s entries are then mapped in the ResourceIndex, a class that acts as a central directory for all resources that are available to the application.

The resource index file defines the following asset types:

  • Resource packages: These are the packed resource archives, only used when tetragon is built/published as an AIR application. By default only one resource package is defined but the engine provides the option to use more than one.
  • Data files: These are the ‘physical’ XML files in which data-, datalist- or entity resources are found. A data file can contain more than one data/datalist/entity resource so every one of these resources needs to refer the data file in which it can be found.
  • Media files: These are binary content files like images, audio files, SWF files, 3D geometry files etc. or virtually any other binary file type that is not a data file. These files are referenced directly by their file path.
  • Data resources: Data resources define custom data type objects for use with the engine. Any custom data type requires it’s own dedicated parser. Data resources are grouped by their type and mapped with a referencing ID to the data files in that the data resource can be found. If all data resources of a group are inside the same data file, the ID for the data file can also be specified per group instead per resource.
  • Datalist resources: Datalists define custom data in the form of specified list structures. Like data resources they are grouped by their data type and require a reference to the data file in that they can be found.
  • Entity resources: Entities are objects that are used with tetragon’s entity-component system. These are essentially empty objects that are only defined by the components that are part of them. Therefore entity resource data follows a pre-defined XML structure and unlike data resources or datalist resources they don’t require a custom parser. In the resource index file entity resources are defined just like data resources, grouped by their type and with a reference to the data file they are found in.
  • XML resources: Not to be confused with data-, datalist- or entity resources which are also defined as XML, XML resources are an optional type of resource as they are XML files that the engine should not parse. Instead the data of XML resources is provided to the engine as raw XML data.
  • Text resources: These are XML files that contain all the text content of the application. A text resource can consist of several text resource files, each with the same text data defined in a different language and then referenced with a language ID, for example en, de or jp etc.

NOTE: When the application is published for AIR the resource index file is being packed and named resources.rif.

To get an idea about how the resource index file relates to the resource package and it’s contents check the following example diagram:

tetragon Resource Index File Diagram

May 222011
 

In the tetragon engine resource files are categorized into several resource families. These families are:

  • media – These are binary resource files. Basically every kind of assets file that is not XML-based, e.g. graphic files, audio files, binary files, 3D object files, SWF files, Shader files, etc.
  • data – Data files are XML files that can contain any kind of custom data for use as data objects inside the engine. Every custom data format requires it’s own data parser so that the data from the XML file can successfully be transfered into data objects. These parsers should implement the IDataParser interface and may extend the DataParser class.
  • entities – Entities are data objects that are utilized by tetragon’s Entity Component architecture. Entity data files are XML files that follow a certain structure so that they can be parsed in the same way by the engine. Entities are essentially abstract data objects that are made up of (and defined by) one or more entity components.
  • lists – Data lists are objects that can store a list of properties and optionally a collection of datasets which in turn act as containers for a set of properties. Lists are typically used for such things like lookup tables whose contents are essentially static. They are defined in XML files with a certain structure.
  • text – Text resources are XML files that follow a certain structure and only contain text data mapped by ID. They are used to separate text content from other data and the engine can process several text resource files that share the same ID but have different, localized text content.
  • settings – Settings are XML files that contain global setting parameters for the application. They are read by the engine during application init and follow a certain structure.
  • xml – XML resource files are an optional resource family that is used for XML files which should not be parsed into any data objects. Instead their data is provided to the engine as unprocessed, unparsed XML data.
May 222011
 

The asset files that tetragon can load and process are generally called resources. These files can be graphic files, audio files, any other binary files, data files etc. They are either loaded from external single files, an external packed resource archive (also called “pak”) or files that are embedded within the application’s binary (SWF) by using the Flex compiler [Embed] meta tag.

When publishing an AIR application tetragon’s build procedure packs all resource files into a single, packed resource archive (by default called resources.pak). The files in this archive are then later read by the engine via random access which means that the engine only needs to read the required chunk from the resource pack instead of having to read the whole archive into memory first every time it needs a resource file from the pack.

The resource pack is a standard zip file that can be opened and inspected with any tool that can manage zip files. However tetragon resource packs only support Deflate and Store compression methods.

Since the AS3 API for utilizing random access is only available for AIR applications tetragon’s build procedure does not pack the resources into a resource archive when deploying for web-based Flash content. Instead it leaves them as they are – as single, uncompressed files – so that they can be quickly loaded from a web server.