#include <msp/strings/format.h>
#include <msp/time/utils.h>
#include "resourcemanager.h"
+#include "resources.h"
#include "resourcewatcher.h"
using namespace std;
namespace Msp {
namespace GL {
+resource_load_error::resource_load_error(const string &name, const string &err):
+ runtime_error(format("%s: %s", name, err))
+{ }
+
resource_load_error::resource_load_error(const string &name, const exception &exc):
runtime_error(format("%s: %s: %s", name, Debug::demangle(typeid(exc).name()), exc.what()))
{ }
if(async_loads)
{
managed.state = ManagedResource::LOAD_QUEUED;
- queue.push_back(&managed);
+ LoadQueue::iterator i;
+ for(i=queue.begin(); (i!=queue.end() && (*i)->load_priority>=managed.load_priority); ++i) ;
+ queue.insert(i, &managed);
}
else
{
}
}
-bool ResourceManager::is_resource_loaded(const Resource &r)
+bool ResourceManager::is_resource_loaded(const Resource &r) const
{
ManagedResource *managed = reinterpret_cast<ManagedResource *>(r.get_manager_data());
return managed ? managed->state==ManagedResource::LOADED : false;
void ResourceManager::resource_used(const Resource &r)
{
ManagedResource *managed = reinterpret_cast<ManagedResource *>(r.get_manager_data());
+ if(!managed)
+ return;
if(managed->state==ManagedResource::NOT_LOADED && policy!=LOAD_MANUALLY)
load_resource(*managed->resource);
ResourceManager::ManagedResource::ManagedResource(Resource &r):
resource(&r),
+ load_priority(r.get_load_priority()),
io(0),
loader(0),
state(NOT_LOADED),
void ResourceManager::ManagedResource::start_loading()
{
io = location.collection->open_raw(location.name);
- loader = resource->load(*io);
+ if(!io)
+ throw resource_load_error(location.name, "open failed");
+
+ const Resources *res = dynamic_cast<Resources *>(location.collection);
+ loader = resource->load(*io, res);
if(!loader)
{
delete io;