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