本文整理汇总了C++中SPtr::allowAsyncLoading方法的典型用法代码示例。如果您正苦于以下问题:C++ SPtr::allowAsyncLoading方法的具体用法?C++ SPtr::allowAsyncLoading怎么用?C++ SPtr::allowAsyncLoading使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPtr
的用法示例。
在下文中一共展示了SPtr::allowAsyncLoading方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadInternal
//.........这里部分代码省略.........
}
}
}
else if (loadDependencies && savedResourceData != nullptr) // Queue dependencies in case they aren't already loaded
{
const Vector<String>& dependencies = savedResourceData->getDependencies();
if (!dependencies.empty())
{
{
Lock lock(mInProgressResourcesMutex);
ResourceLoadData* loadData = nullptr;
auto iterFind = mInProgressResources.find(UUID);
if (iterFind == mInProgressResources.end()) // Fully loaded
{
loadData = bs_new<ResourceLoadData>(outputResource.getWeak(), 0);
loadData->resData = outputResource.getWeak();
loadData->remainingDependencies = 0;
loadData->notifyImmediately = synchronous; // Make resource listener trigger before exit if loading synchronously
mInProgressResources[UUID] = loadData;
}
else
{
loadData = iterFind->second;
}
// Register dependencies and count them so we know when the resource is fully loaded
for (auto& dependency : dependencies)
{
if (dependency != UUID)
{
bool registerDependency = true;
auto iterFind2 = mDependantLoads.find(dependency);
if (iterFind2 != mDependantLoads.end())
{
Vector<ResourceLoadData*>& dependantData = iterFind2->second;
auto iterFind3 = std::find_if(dependantData.begin(), dependantData.end(),
[&](ResourceLoadData* x)
{
return x->resData.resource.getUUID() == outputResource.getUUID();
});
registerDependency = iterFind3 == dependantData.end();
}
if (registerDependency)
{
mDependantLoads[dependency].push_back(loadData);
loadData->remainingDependencies++;
loadData->dependencies.push_back(_getResourceHandle(dependency));
}
}
}
}
for (auto& dependency : dependencies)
loadFromUUID(dependency, !synchronous, true, false);
}
}
// Actually start the file read operation if not already loaded or in progress
if (!alreadyLoading && !filePath.isEmpty())
{
// Synchronous or the resource doesn't support async, read the file immediately
if (synchronous || !savedResourceData->allowAsyncLoading())
{
loadCallback(filePath, outputResource);
}
else // Asynchronous, read the file on a worker thread
{
String fileName = filePath.getFilename();
String taskName = "Resource load: " + fileName;
SPtr<Task> task = Task::create(taskName, std::bind(&Resources::loadCallback, this, filePath, outputResource));
TaskScheduler::instance().addTask(task);
}
}
else // File already loaded or in progress
{
// Complete the load unless its in progress in which case we wait for its worker thread to complete it.
// In case file is already loaded this will only decrement dependency count in case this resource is a dependency.
if (!loadInProgress)
loadComplete(outputResource);
else
{
// In case loading finished in the meantime we cannot be sure at what point ::loadComplete was triggered,
// so trigger it manually so that the dependency count is properly decremented in case this resource
// is a dependency.
Lock lock(mLoadedResourceMutex);
auto iterFind = mLoadedResources.find(UUID);
if (iterFind != mLoadedResources.end())
loadComplete(outputResource);
}
}
return outputResource;
}