void ResourceManager::LoadResource( const std::string & resource )
{
	if( ResourceIsLoaded( resource ) )
		return;

	ResourceFactory * rf = ResourceFactory::Instance( );
	m_Resources[resource] = rf->LoadResource( resource );
}
Exemplo n.º 2
0
// loading/unloading
// ----------------------------------------------------------------------------------------------
// Loads a file and turns it into a runtime resource
bool ResourceManager::LoadResource(Resource * res,  const WCHAR* filename)
{
    bool ok = false;
    // try to create resource
    if (!FileUtils::Exists(filename))
    {
        Logger::Log(OutputMessageType::Error, L"Failed to load file, '%ls' -- does not exist\n", filename);
        return false;
    }

    PerfTimer timer;
    timer.Start();

    // get factory associated with 'filename'
    ResourceFactory * factory = GetFactory(filename);
    if (!factory)
    {
        return false;
    }


    ok = factory->LoadResource(res, filename);
    if (ok)
    {
        res->SetReady();
        timer.Stop();
        Logger::Log(OutputMessageType::Debug, L"%d ms Loaded %ls\n", timer.ElapsedMilliseconds(), FileUtils::Name(filename));
    }
    else
    {
        timer.Stop();
        Logger::Log(OutputMessageType::Error, L"%d ms failed to load %ls\n", timer.ElapsedMilliseconds(), filename);
    }

    return ok;
}