void ResourceManager::decodeResource( ResourceLoadOptions& options ) { Task* task = Allocate(GetResourcesAllocator(), Task); ResourceLoadOptions* taskOptions = Allocate(GetResourcesAllocator(), ResourceLoadOptions); *taskOptions = options; task->callback.Bind(ResourceTaskRun); task->userdata = taskOptions; numResourcesQueuedLoad.increment(); #ifdef ENABLE_THREADED_LOADING if( taskPool && asynchronousLoading && options.asynchronousLoad ) { taskPool->add(task, options.isHighPriority); return; } #endif task->run(); sendPendingEvents(); }
ResourceManager::ResourceManager() : taskPool(nullptr) , archive(nullptr) , handleManager(nullptr) , numResourcesQueuedLoad(0) , asynchronousLoading(true) { handleManager = HandleCreateManager( GetResourcesAllocator() ); if( !gs_ResourcesManager ) gs_ResourcesManager = this; if( !gs_ResourceHandleManager ) gs_ResourceHandleManager = handleManager; ReflectionHandleContext context; context.type = ReflectionGetType(Resource); context.handles = gs_ResourceHandleManager; context.serialize = ResourceHandleSerialize; context.deserialize = ResourceHandleFind; ReflectionHandleContextMap contextMap; ReflectionSetHandleContext(&contextMap, context); resourceFinishLoadMutex = Allocate(GetResourcesAllocator(), Mutex); resourceFinishLoad = Allocate(GetResourcesAllocator(), Condition); }
void EditorFrame::createEngine() { engine = AllocateThis(Engine); engine->init(); // Setup the input manager. input = AllocateThis(InputManager); input->createDefaultDevices(); engine->setInputManager(input); // Mount the default assets path. ResourceManager* res = engine->getResourceManager(); // Get the mount paths from the editor preferences. archive = ArchiveCreateVirtual( GetResourcesAllocator() ); ArchiveMountDirectories(archive, MediaFolder, GetResourcesAllocator()); res->setArchive(archive); }
void ResourceManager::setupResourceLoaders(Class* klass) { for( size_t i = 0; i < klass->childs.size(); i++ ) { Class* child = klass->childs[i]; if( !child->childs.empty() ) setupResourceLoaders(child); if( ClassIsAbstract(child ) ) continue; auto loader = (ResourceLoader*) ClassCreateInstance( child, GetResourcesAllocator()); registerLoader( loader ); } }
Resource* ResourceManager::prepareResource( ResourceLoadOptions& options ) { const Path& path = options.name; Stream* stream = archive->openFile(path, GetResourcesAllocator()); if( !stream ) { LogWarn("Resource was not found: '%s'", path.c_str()); return nullptr; } const Path& file = PathGetFile(path); // Get the available resource loader and prepare the resource. ResourceLoader* loader = findLoader( PathGetFileExtension(file) ); if( !loader ) { LogWarn("No resource loader found for resource '%s'", file.c_str()); return nullptr; } options.stream = stream; Resource* resource = loader->prepare(options); if( !resource ) { LogError("Error preparing resource: '%s'", path.c_str()); return nullptr; } resource->setStatus( ResourceStatus::Loading ); resource->setPath( file ); options.resource = resource; return resource; }