Using CoreResMgr and ResMgr and ResLoader - (Game Resource Management)

Using CoreResMgr and ResMgr and ResLoader

Implementing ResLoader. All that is needed to be done is inherit ResLoader and override the load method.

#include "ResourceManager"

class FontResLoader :public kege::res::ResLoader< gfx::FontSheet >
{
public:
    
    gfx::FontSheet * Load(const LoaderContext& info, kege::ds::astring const& filename);
    FontResLoader();
};

Overriding the load method is don't like so.


gfx::FontSheet * FontResLoader::Load(const LoaderContext&amp; context, kege::ds::astring const&amp; filename)
{
    // use the resumer member var pointer to create the new a font resource asset
    gfx::FontSheet * font = resmgr-&gt;Create(context.name);
    if ( !font ) return font;

    // since my font class has a load function to i use it to load the filename
    if( !font-&gt;Load(filename.c_str()) )
    {
        resmgr-&gt;Delete(context.name);
        return nullptr;
    }
    // then i use the context data to set the font name
    font-&gt;SetName(context.name);
    font-&gt;SetSID(context.name);
    return font;
}

FontResLoader::FontResLoader()
:   res::ResLoader&lt; gfx::FontSheet &gt;("font")
{}
creating a resource.
CoreResMgr  cormgr;
ResMgr<Font> * resmgr  = cormgr.CreateResMgr< Font >(new res::FontResLoader);
loading a resource.
resmgr->Load(nullptr, "~/font/monaco.font");
what would happen if we load the same font more than once? 
  1. Would a new font get loaded with the same name.
  2. Will the font that already exist get return.
resmgr->Load(nullptr, "~/font/monaco.font");
resmgr->Load(nullptr, "~/font/monaco.font");

answer. 
  1. the font that already exist will get returned. objects should not be loaded if it was already loaded before. this is what a resource manager suppose to do.
retrieving a resource.
Font * font = resmgr->Get(nullptr, "monaco.font");
deleting a resource.
resmgr->Delete("monaco.font");
THE END

Comments