Skip to content

Latest commit

 

History

History
109 lines (86 loc) · 3.46 KB

AssetManager.md

File metadata and controls

109 lines (86 loc) · 3.46 KB

The Tornado Asset Manager

The asset manager takes care of loading all the assets of the demo, including allocating memory and calling the unpacking routines.

It can load any type of file, but it is most convenient when used with TNDO files.

Loading assets

Assets can only be loaded during the initialisation phase, when Amiga OS is still running. Let's see an example:

This is what the Asset struct looks like:

typedef struct {
  uint8_t *Name;
  uint32_t Flags;
  void *Data;
  uint32_t Size;
} TornadoAsset;

You only need to provide the asset name, that is the file path, and the flags. The two commonly used flags are:

  • ASSETS_IN_REUSABLE_MEM: Load assets in the scratch pad, so they can be further processed during initialisation.
  • NO_Z_DECOMPRESS : Do not decompress assets on load.

First we declare the asset list. These are all the files we want to load.

static TornadoAsset assetList[] = {
    {
        .Name = (uint8_t *)"data/zoom.tndo", // Roundrobin 1
    },
    {
        .Name = (uint8_t *)"data/zoom2.tndo", // Roundrobin 2
    },
    {
        .Name = (uint8_t *)"data/zoom_frame0.tndo", // Frame 0
    },
    {
        .Name = (uint8_t *)"data/zoom.pal", // Palette
    },
};

And now during the effect initialisation we use the asset manager to load them.

  effect->numAssets = sizeof(assetList) / sizeof(TornadoAsset);
  effect->Assets = (TornadoAsset *)assetList;
  if (!loadAssets(assetList, effect->numAssets, tornadoOptions, 0)) {
    tndo_memory_shutdown(tornadoOptions);
    if (tornadoOptions & LOGGING) {
      printf("failed!\n");
    }
    exit(1);
  }

After this the Data and Size fields for every asset now contain the payload and its size respectively.

The TNDO file format

The TNDO file format is generated by some of the tools, in particular tndo_compress. It contains a header with file metadata, including what type of data and some type-specific fields for things like audio or graphics data.

You can examine the header of a TNDO file with the tndo_info tool:

mmendez$ tndo_info data/zoom.tndo 
File name: data/zoom.tndo
File type: Generic.
Compression: TNDO LZSS.
Compressed size: 504929 bytes
Uncompressed size: 1048576 bytes

mmendez$ tndo_info data/brut_zoom.tndo 
File name: data/brut_zoom.tndo
File type: Audio.
Compression: Audio CAPS.
Compressed size: 0 bytes
Uncompressed size: 0 bytes
Sample rate: 11025
Bit depth: 8
Number of channels: 2

The TNDO container

Another feature built into the Tornado asset manager is the data container. During development you will use individual asset files, like this:

mmendez$ ls -la data/
total 4600
drwxr-xr-x   8 mmendez  staff     256  2 Jun 14:09 .
drwxr-xr-x  12 mmendez  staff     384  2 Jun 14:09 ..
-rw-r--r--   1 mmendez  staff  966447  2 Jun 14:09 brut_zoom.mp3
-rw-r--r--   1 mmendez  staff  358200  2 Jun 14:09 brut_zoom.tndo
-rw-r--r--   1 mmendez  staff     200  2 Jun 14:09 zoom.pal
-rw-r--r--   1 mmendez  staff  505001  2 Jun 14:09 zoom.tndo
-rw-r--r--   1 mmendez  staff  495611  2 Jun 14:09 zoom2.tndo
-rw-r--r--   1 mmendez  staff   19106  2 Jun 14:09 zoom_frame0.tndo

Once your demo is ready for release you can assemble a container file with all the assets and configure the asset manager to read the data from there. Please refer to the Getting Ready For Release section for more information on how to use this feature.