// Copyright (C) 2015 Jérôme Leclercq // This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include #include #include #include template void NzResourceManager::Clear() { Type::s_managerMap.clear(); } template NzObjectRef NzResourceManager::Get(const NzString& filePath) { NzObjectRef ref; NzString absolutePath = NzFile::AbsolutePath(filePath); auto it = Type::s_managerMap.find(absolutePath); if (it == Type::s_managerMap.end()) { NzObjectRef resource = Type::New(); if (!resource) { NazaraError("Failed to create resource"); return ref; } if (!resource->LoadFromFile(absolutePath, GetDefaultParameters())) { NazaraError("Failed to load resource from file: " + absolutePath); return ref; } NazaraDebug("Loaded resource from file " + absolutePath); it = Type::s_managerMap.insert(std::make_pair(absolutePath, resource)).first; } return it->second; } template const Parameters& NzResourceManager::GetDefaultParameters() { return Type::s_managerParameters; } template void NzResourceManager::Purge() { auto it = Type::s_managerMap.begin(); while (it != Type::s_managerMap.end()) { const NzObjectRef& ref = it->second; if (ref.GetReferenceCount() == 1) // Sommes-nous les seuls à détenir la ressource ? Type::s_managerMap.erase(it++); // Alors on la supprime else ++it; } } template void NzResourceManager::Register(const NzString& filePath, NzObjectRef resource) { NzString absolutePath = NzFile::AbsolutePath(filePath); Type::s_managerMap[absolutePath] = resource; } template void NzResourceManager::SetDefaultParameters(const Parameters& params) { Type::s_managerParameters = params; } template void NzResourceManager::Unregister(const NzString& filePath) { NzString absolutePath = NzFile::AbsolutePath(filePath); Type::s_managerMap.erase(absolutePath); } template bool NzResourceManager::Initialize() { return true; } template void NzResourceManager::Uninitialize() { Clear(); } #include