void BackgroundLoader::FinishBackgroundLoading(BackgroundLoadItem& item) { Resource* resource = item.resource_; bool success = resource->GetAsyncLoadState() == ASYNC_SUCCESS; // If BeginLoad() phase was successful, call EndLoad() and get the final success/failure result if (success) { #ifdef URHO3D_PROFILING String profileBlockName("Finish" + resource->GetTypeName()); Profiler* profiler = owner_->GetSubsystem<Profiler>(); if (profiler) profiler->BeginBlock(profileBlockName.CString()); #endif LOGDEBUG("Finishing background loaded resource " + resource->GetName()); success = resource->EndLoad(); #ifdef URHO3D_PROFILING if (profiler) profiler->EndBlock(); #endif } resource->SetAsyncLoadState(ASYNC_DONE); if (!success && item.sendEventOnFailure_) { using namespace LoadFailed; VariantMap& eventData = owner_->GetEventDataMap(); eventData[P_RESOURCENAME] = resource->GetName(); owner_->SendEvent(E_LOADFAILED, eventData); } // Send event, either success or failure { using namespace ResourceBackgroundLoaded; VariantMap& eventData = owner_->GetEventDataMap(); eventData[P_RESOURCENAME] = resource->GetName(); eventData[P_SUCCESS] = success; eventData[P_RESOURCE] = resource; owner_->SendEvent(E_RESOURCEBACKGROUNDLOADED, eventData); } // Store to the cache; use same mechanism as for manual resources if (success || owner_->GetReturnFailedResources()) owner_->AddManualResource(resource); }
void BackgroundLoader::FinishBackgroundLoading(BackgroundLoadItem& item) { Resource* resource = item.resource_; bool success = resource->GetAsyncLoadState() == ASYNC_SUCCESS; // If BeginLoad() phase was successful, call EndLoad() and get the final success/failure result if (success) { URHO3D_PROFILE(ea::string("Finish" + resource->GetTypeName()).c_str()); URHO3D_LOGDEBUG("Finishing background loaded resource " + resource->GetName()); success = resource->EndLoad(); } resource->SetAsyncLoadState(ASYNC_DONE); if (!success && item.sendEventOnFailure_) { using namespace LoadFailed; VariantMap& eventData = owner_->GetEventDataMap(); eventData[P_RESOURCENAME] = resource->GetName(); owner_->SendEvent(E_LOADFAILED, eventData); } // Store to the cache just before sending the event; use same mechanism as for manual resources if (success || owner_->GetReturnFailedResources()) owner_->AddManualResource(resource); // Send event, either success or failure { using namespace ResourceBackgroundLoaded; VariantMap& eventData = owner_->GetEventDataMap(); eventData[P_RESOURCENAME] = resource->GetName(); eventData[P_SUCCESS] = success; eventData[P_RESOURCE] = resource; owner_->SendEvent(E_RESOURCEBACKGROUNDLOADED, eventData); } }