Skip to main content

Resource - (Game Resource Management)

Resource - (Game Development Resource Management)



#include “dlist.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
46
template< class Asset > class ResMgr;

template< class Asset > class Resource
{
    friend res::ResMgr< Asset >;
    
public:
    
    Asset * object;
    
    void SetLoaded(bool value)
    {
        isloaded = value;
    }
    
    bool GetLoaded() const
    {
        return isloaded;
    }
    
    ds::astring const& GetName() const
    {
        return isloaded;
    }
    
    int GetReferenceCount() const
    {
        return reference_counter;
    }
    
private:
    
    Resource(ds::astring const& name)
    :   object(nullptr)
    ,   reference_counter(0)
    ,   name(name)
    ,   isloaded(false) {}
    
    ~Resource(){}
    
private:
    
    int reference_counter;
    ds::astring name;
    bool isloaded;
};

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 a manager.

@Note  Asset is a template type.

Example: of a resource asset: Resource, Mesh being the Asset template type.


int reference_counter;

reference_counter is used to keep track of how many pointers is pointing to this specific resource asset. many duplicate of the same object will be use, and if an object is deleted will it is being used you will have a big big problem (your app will crash or freeze). To prevent this from happening, a reference_counter is used. When is drops to zero deletion is good to go.


ds::astring name;

name is used to bind the asset to a name so that it can be queried for when a retrieval is requested. Thus, each resource must have a unique name so that the correct asset can be fetch when queried.


bool isolated;

name is used to mark a resource as loaded.


Resource member function details.



void SetLoaded(bool value)

This function is use set the member value isloaded to the param value.
  • @param  (bool value) is the value to set isloaded to true or false.


bool GetLoaded()

This function is return true or false.

      ds::astring const& GetName()

      This function return the name of the resource.


          Comments

          Popular posts from this blog

          Resource Manager - (Game Resource Management)

          Resource Manager - (Game Development Resource Management)


          #include "ResLoader.cpp"


          Definition: MANAGER:

          classManager{public:virtualvoidDestroy()=0;virtual~Manager(){}public:ds::astringname;};
          Manager member variables:
          ds::astring name;
          nameis the name of the  resource manager.

          Definition: RESOURCE-MANAGER:
          template<classAsset>classResourceManager:publicManager{typedefbool(*DeleteAssetFuncPtr)(Asset*asset);DeleteAssetFuncPtrDeleteAssetFunc;public:typedefds::dlist<ResourceLoader<Asset>*>ResourceLoaders;typedefstd::map<ds::astring,ResourceLoaders*>ResourceLoaderMap;typedefds::dlist<Resource<Asset>*>AssetList;typedefstd::map<ds::astring,AssetList*>AssetMap;public:voidAddLoader(ResourceLoader<Asset>*resource_loader);ResourceLoader<Asset>*GetLoader(ds::astringconst&file_ext);AssetList*GetResourceList(ds::astringconst&name);Asset*A

          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.
          Introduction
          What is a Game Resource Manager? A game resource manager manages ob…