Loader - (Game Resource Management)

Loader - (Game Development Resource Management)

#include "Resource.hpp"


template< class ResourceObject > class ResMgr;

template< class Asset >  class ResLoader
    friend res::ResMgr< Asset >;
    res::ResMgr< Asset > * resmgr;
    ds::astring ext;
    struct LoaderContext
        typedef ds::dlist< Resource< Asset >* > AssetList;
        AssetList * reslist;
        ds::astring name;
        ds::astring ext;
        const ResInfo* resinfo;
    virtual Asset * Load(const LoaderContext& info, ds::astring const& filename) = 0;
    virtual void DeleteAsset(Asset * asset) = 0;
    ResLoader(ds::astring const& ext)
    :   ext(ext)
    ,   resmgr(nullptr) {}
    virtual ~ ResLoader(){}

Resource Loader member variables details.

res::ResourceManager< Asset > * resmgr;

resmgr is the resource manager that the loader is associated with.

ds::astring ext;

ext is the name of file extension the loader is responsible of loading.

LoaderContext member variables:
  • LoaderContext is a data structure that contains important information passed to the loader via manager so that the loader can load the resource into the correct list.

AssetList * reslist

reslist is the list the asset should be stored in.

ds::astring name

name is the name of the file. The name is parsed from the filename. is purpose is to serve as the name for the loaded resource.

ds::astring ext

ext is the name of the file extension, which is also parsed from the filename.

LoaderContext Member functions:

virtual Asset * Load(const LoaderContext& info, ds::astring const& filename) = 0;

This is the function responsible for loading the resource. This function will obviously need to be override by the objec that implements it.
  • @param (const LoaderContext& context) : contains important information passed to the loader via Manager. 
  • @param (ds::astring const& filename) : is the name of the file to load.