class EE::System::ResourceLoader

Overview

A simple resource loader that can load a batch of resources synchronously or asynchronously. More…

#include <resourceloader.hpp>

class ResourceLoader {
public:
    // typedefs

    typedef std::function<void(ResourceLoader*)> ResLoadCallback;
    typedef std::function<void()> ObjectLoaderTask;

    // construction

    ResourceLoader(const Uint32& MaxThreads = THREADS_AUTO);
    virtual ~ResourceLoader();

    // methods

    void add(const ObjectLoaderTask& objectLoaderTask);
    void load(const ResLoadCallback& callback);
    void load();
    virtual bool isLoaded();
    virtual bool isLoading();
    bool isThreaded() const;
    void setThreaded(const bool& setThreaded);
    bool clear();
    Float getProgress();
    Uint32 getCount() const;
};

Detailed Documentation

A simple resource loader that can load a batch of resources synchronously or asynchronously.

Construction

ResourceLoader(const Uint32& MaxThreads = THREADS_AUTO)

Parameters:

MaxThreads

Set the maximun simultaneous threads to load resources, THREADS_AUTO will use the cpu number of cores.

Methods

void add(const ObjectLoaderTask& objectLoaderTask)

Adds a resource to load. Must be called before the loading starts. Once an object loader is added to the resource loader, the instance of that object will be managed and released by the loader. *.

Parameters:

objectLoaderTask

The function callback of the load process

void load(const ResLoadCallback& callback)

Starts loading the resources.

Parameters:

callback

A callback that is called when the resources finished loading.

void load()

Starts loading the resources.

virtual bool isLoaded()

Returns:

If the resources were loaded.

virtual bool isLoading()

Returns:

If the resources are still loading.

bool isThreaded() const

Returns:

If the resource loader is asynchronous

void setThreaded(const bool& setThreaded)

Sets if the resource loader is asynchronous. This must be called before the load starts.

bool clear()

Clears the resources added to load that werent loaded, and delete the instances of the loaders.

Float getProgress()

Returns:

The aproximate percent of progress ( between 0 and 100 )

Uint32 getCount() const

Returns:

The number of resources added to load.