void BackgroundLoader::ThreadFunction() { while (shouldRun_) { backgroundLoadMutex_.Acquire(); // Search for a queued resource that has not been loaded yet HashMap<Pair<StringHash, StringHash>, BackgroundLoadItem>::Iterator i = backgroundLoadQueue_.Begin(); while (i != backgroundLoadQueue_.End()) { if (i->second_.resource_->GetAsyncLoadState() == ASYNC_QUEUED) break; else ++i; } if (i == backgroundLoadQueue_.End()) { // No resources to load found backgroundLoadMutex_.Release(); Time::Sleep(5); } else { BackgroundLoadItem& item = i->second_; Resource* resource = item.resource_; // We can be sure that the item is not removed from the queue as long as it is in the // "queued" or "loading" state backgroundLoadMutex_.Release(); bool success = false; SharedPtr<File> file = owner_->GetFile(resource->GetName(), item.sendEventOnFailure_); if (file) { resource->SetAsyncLoadState(ASYNC_LOADING); success = resource->BeginLoad(*file); } // Process dependencies now // Need to lock the queue again when manipulating other entries Pair<StringHash, StringHash> key = MakePair(resource->GetType(), resource->GetNameHash()); backgroundLoadMutex_.Acquire(); if (item.dependents_.Size()) { for (HashSet<Pair<StringHash, StringHash> >::Iterator i = item.dependents_.Begin(); i != item.dependents_.End(); ++i) { HashMap<Pair<StringHash, StringHash>, BackgroundLoadItem>::Iterator j = backgroundLoadQueue_.Find(*i); if (j != backgroundLoadQueue_.End()) j->second_.dependencies_.Erase(key); } item.dependents_.Clear(); } resource->SetAsyncLoadState(success ? ASYNC_SUCCESS : ASYNC_FAIL); backgroundLoadMutex_.Release(); } } }
void C_SoundPlayer::SetBuffer(Resource res) { ReleaseBuffer(); if(res.IsValid() && res->GetType()&RES_TYPE_SOUND) { buff = *(CAST_RES(ALuint*, res)); }
void ComponentParticleSystem::SetTexture(UID uid) { Resource* res = App->resources->Get(uid); if (res != nullptr && res->GetType() == Resource::texture) { if(res->LoadToMemory() == true) { texture_info.texture = uid; } } }
void C_SoundPlayer::SetBuffer(Resource buff) { ReleaseBuffer(); if(buff.IsValid() && buff->GetType()&RES_TYPE_SOUND) { #ifdef USE_DIRECTSOUND8 if(buff.GetPtr<SoundResource>()->GetSoundDevice()==0) return; if(buff.GetPtr<SoundResource>()->GetSoundDevice()->GetDevice()==0) return; #endif buff.GetPtr<SoundResource>()->GetSoundDevice()->GetDevice()->DuplicateSoundBuffer(CAST_RES(LPDIRECTSOUNDBUFFER, buff), &dsb); releasebuff = true; } }
/** * @brief * Copy constructor */ Resource::Resource(const Resource &cSource) : m_pRenderer(&cSource.GetRenderer()), m_nType(cSource.GetType()) { // No implementation because the copy constructor is never used }