Resource Management - TeamLe-Shop/cayv-rpg GitHub Wiki

Goals

  • To allow flexibility in the types of resources and how they are handled
  • To automate memory management when dealing with numerous/large resources
  • To organise resources so they can be distributed and categorised for user customisation

Concepts

The humble Resource

A Resource is a base from which all actual resource types are derived. All resources must be "loaded" in some fashion, and have some accessible data. Different resource types may be loaded in different ways and may have several functions for their usage. Most resources will be loaded from a file, hence we will introduce the idea of a resource Bundle.

Bundles

A Bundle is practically a list of resources. Bundles are how resources will be distributed (e.g. a custom sprite replacement pack). They will also feature functions to locate individual resources in a bundle. For convenience in referencing, every resource will be given a reference name and a corresponding path. Their type will also be known. All this information will be contained in a manifest. Example:

// name path type [any extra parameters]
footstep: snd/footstep.wav sound
fields: music/autismofields.xm xmsong
tiles: spritesheets/tiles.png sheet sheetdata/tiles.txt

Bundles themselves will also have names, as well as priorities. Priorities will allow additional bundles to override the game's base bundle.

As for the format of Bundles, an archived tarball is a good candidate. Reasons for this are as follows:

  • Tar archives (compressed with gzip or bzip2) have available libraries for dealing with them. (e.g. libarchive)
  • A single file will be easier to transfer from server to client

Retrieving resources

Resources will obviously be in a file. Resources that are needed will be read into memory and dealt with accordingly (e.g. creating a Mix_Chunk* from some sound resource). Bundles hold all of their resources. A resource Manager will be used to introduce new Bundles and sift through them for the correct resource. Consider this hypothetical call:

SoundResource* s = manager.get("sound", "footstep");

This would instruct the manager to find the resource of type "sound" and name "footstep". If there are multiple occurences in different packages, the package with the higher priority is taken. If there are multiple occurrences with the same priority, the first one the manager comes across is taken.