Skip to main content

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.


Popular posts from this blog

Resource Manager - (Game Resource Management)

Resource Manager - (Game Development Resource Management)

#include "ResLoader.cpp"

Definition: MANAGER:

Manager member variables:
ds::astring name;
nameis the name of the  resource manager.


Game Resource Management

Game Resource Manager
Requirements Sound understanding C++, pointer, and template.basic understanding of std::vector and std::map. 
Depending on your level of programming in C++ this tutorial maybe easy or hard to comprehend. I will try to explain things in a way that is simple to understand. Note that the resource manager here uses C++ template. If you don’t know what a template is in C++, it is highly recommend that you review and understand it before you read this article. This is a general-purpose resource manager; C++ templates will allow us to use the same class to create many different resource-manager to manage different objects of different type. The core resource manager will be used to create manage resource managers automatically, and manage them. 

@Noteds::dlist is my own custom linked list. std::vector can be used instead.  @Note ds::astring is my own custom string. std::string can be used instead.
What is a Game Resource Manager? A game resource manager manages ob…

Resource - (Game Resource Management)

Resource - (Game Development Resource Management)

#include “dlist.hpp” #include “charstr.hpp”

Definition: RESOURCE:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46template<classAsset>classResMgr;template<classAsset>classResource{friendres::ResMgr<Asset>;public:Asset*object;voidSetLoaded(boolvalue){isloaded=value;}boolGetLoaded()const{returnisloaded;}ds::astringconst&GetName()const{returnisloaded;}intGetReferenceCount()const{returnreference_counter;}private:Resource(ds::astringconst&name):object(nullptr),reference_counter(0),name(name),isloaded(false){}~Resource(){}private:intreference_counter;ds::astringname;boolisloaded;};
Resource member variables details.
Asset* object;
is the asset that is to be manages. Asset is made to be a pointer to allow the adding of an asset to the manager. With out the uses of a pointer the asset will have to be copied each time an asset is added to…