CResource* CResourceManager::Load(CString strAbsPath, CString strResourceName) { for(auto pResource : m_resources) { if(pResource->GetName() == strResourceName) { if(pResource->HasChanged()) { pResource->Stop(); RemoveResource(pResource); delete pResource; break; } else return pResource; } } CResource* loadResource = new CResource(strAbsPath, strResourceName); if(!loadResource->IsLoaded()) { CLogFile::Printf("Loading of resource '%s' failed\n", strResourceName.Get()); SAFE_DELETE(loadResource); } else { CLogFile::Printf("Resource loaded (%s)", strResourceName.Get()); loadResource->SetCreateVMCallback(m_fnCreateVM); AddResource(loadResource); return loadResource; } return 0; }
void cSoundResourceManagerBase::NotifyResourceParentChanged(vResource<ALuint> *res) { if(!res) return; RemoveResource(res->GetStorageIndex()); }
void cSoundResourceManagerBase::Release() { // Remove all resources // Note: if there are any valid resource proxies, they'll crash when their associated resource is dereferenced using cSoundBuffer::Get() while(GetResourcesCount()) RemoveResource(GetResourcesCount() - 1); }
void cVideoManager::Destroy(iResourceBase* apResource) { if(apResource) { RemoveResource(apResource); hplDelete(apResource); } }
void cImageEntityManager::Destroy(iResourceBase* apResource) { apResource->DecUserCount(); if(apResource->HasUsers()==false){ RemoveResource(apResource); hplDelete(apResource); } }
void cTextureManager::DeleteResource(unsigned int storage_index) { if(storage_index < 0 || storage_index >= GetResourcesCount()) return; vTextureResource *res = m_Resources[storage_index]; RemoveResource(storage_index); ReleaseResource(res); }
void cImageManager::Destroy(iResourceBase* apResource) { //Lower the user num for the the resource. If it is 0 then lower the //user num for the TextureFrame and delete the resource. If the Texture //frame reaches 0 it is deleted as well. cResourceImage *pImage = static_cast<cResourceImage*>(apResource); cFrameTexture *pFrame = pImage->GetFrameTexture(); cFrameBitmap *pBmpFrame = pImage->GetFrameBitmap(); //pImage->GetFrameBitmap()->FlushToTexture(); Not needed? //Log("Users Before: %d\n",pImage->GetUserCount()); //Log("Framepics Before: %d\n",pFrame->GetPicCount()); pImage->DecUserCount();//dec frame count as well.. is that ok? //Log("---\n"); //Log("Destroyed Image: '%s' Users: %d\n",pImage->GetName().c_str(),pImage->GetUserCount()); //Log("Frame %d has left Pics: %d\n",pFrame,pFrame->GetPicCount()); if(pImage->HasUsers()==false) { pFrame->DecPicCount(); // Doing it here now instead. pBmpFrame->DecPicCount(); RemoveResource(apResource); hplDelete(apResource); //Log("deleting image and dec fram to %d images!\n",pFrame->GetPicCount()); } if(pFrame->IsEmpty()) { //Log(" Deleting frame..."); //Delete the bitmap frame that has this this frame. for(tFrameBitmapListIt it=mlstBitmapFrames.begin();it!=mlstBitmapFrames.end();++it) { cFrameBitmap *pBmpFrame = *it; if(pBmpFrame->GetFrameTexture() == pFrame) { //Log("and bitmap..."); hplDelete(pBmpFrame); mlstBitmapFrames.erase(it); break; } } //delete from list m_mapTextureFrames.erase(pFrame->GetHandle()); hplDelete(pFrame); //Log(" Deleted frame!\n"); } //Log("---\n"); }
void cFontManager::Destroy(iResourceBase *a_pResource) { a_pResource->DecUserCount(); if (a_pResource->HasUsers()==false) { RemoveResource(a_pResource); efeDelete(a_pResource); } }
void cSoundSourceManager::ReleaseResource(cSoundSource *res) { if(!res) return; vSoundSourceResource *base = res->GetRawResource(); // Check if its claimed if(base && base->GetParent() == this) RemoveResource(base->GetStorageIndex()); }
ShaderPtr ShaderLoader::Load(const Path & vertex_file_name, const Path & fragment_file_name, bool replaceCached) { Path resourceName = vertex_file_name.filename().generic_string() + fragment_file_name.filename().generic_string(); Resource<Shader> existingResource = this->GetResource(resourceName); if (existingResource.resource && !replaceCached) { GetContext().GetLogger()->log(LOG_LOG, "Shader returned from cache."); return existingResource.resource; } FilePtr vertexFile = GetContext().GetFileSystem()->OpenRead(vertex_file_name); FilePtr fragmentFile = GetContext().GetFileSystem()->OpenRead(fragment_file_name); if (!vertexFile->IsOpen() || !fragmentFile->IsOpen()) { return ShaderPtr(); } GetContext().GetLogger()->log(LOG_LOG, "Shader resource name: %s", resourceName.generic_string().c_str()); ByteBufferPtr vertexBuffer = vertexFile->ReadText(); ByteBufferPtr fragmentBuffer = fragmentFile->ReadText(); Shader * shader = new Shader(resourceName.generic_string(), (char*)vertexBuffer->data(), (char*)fragmentBuffer->data(), ""); shader->Compile(); if (shader->IsCompiledAndLinked()) { if (existingResource.resource) { RemoveResource(existingResource.path); GetContext().GetLogger()->log(LOG_LOG, "Removed cached shader: '%s'.", resourceName.c_str()); } GetContext().GetLogger()->log(LOG_LOG, "Shader loaded: '%s'.", resourceName.c_str()); Resource<Shader> res(ShaderPtr(shader), resourceName); this->AddResource(res); return res.resource; } else { delete shader; if (existingResource.resource) GetContext().GetLogger()->log(LOG_ERROR, "Shader failed to load: '%s', using cached version.", resourceName.generic_string().c_str()); else GetContext().GetLogger()->log(LOG_ERROR, "Shader failed to load: '%s'.", resourceName.generic_string().c_str()); return existingResource.resource; } }
void cSoundManager::DestroyAll() { tResourceHandleMapIt it = m_mapHandleResources.begin(); while(it != m_mapHandleResources.end()) { iResourceBase *pData = it->second; RemoveResource(pData); efeDelete(pData); it = m_mapHandleResources.begin(); } }
void cSoundManager::Destroy(iResourceBase *a_pResource) { if (a_pResource->HasUsers()) { a_pResource->DecUserCount(); iSoundData *pData = static_cast<iSoundData*>(a_pResource); if (pData->IsStream() && pData->HasUsers() == false) { RemoveResource(pData); efeDelete(pData); } } }
//! Returns false, if item is NULL or memory is insufficient, true otherwise. bool ResourcesContainer::AddResource(ResourceItem *item, int32 index, bool replace) { bool result = false; if (item) { // replace an item with the same type and id if (replace) delete RemoveResource(IndexOf(item->Type(), item->ID())); int32 count = CountResources(); if (index < 0 || index > count) index = count; result = fResources.AddItem(item, count); SetModified(true); } return result; }
static PyObject *ResObj_RemoveResource(ResourceObject *_self, PyObject *_args) { PyObject *_res = NULL; #ifndef RemoveResource PyMac_PRECHECK(RemoveResource); #endif if (!PyArg_ParseTuple(_args, "")) return NULL; RemoveResource(_self->ob_itself); { OSErr _err = ResError(); if (_err != noErr) return PyMac_Error(_err); } Py_INCREF(Py_None); _res = Py_None; return _res; }
// adds 1 resource to the currently cached resource list for a type // if a resource with the id passed already exists then it overwrites it void CResContainerDirCache::AddResource( ResType inResType, TResId inResId, const TResName inResName) { RemoveResource(inResType,inResId); Try_ { SResContents cur={0,NULL}; CResHash::iterator it=mResContentsHash.find(inResType); CNewHandleStream stream; int ok; if (it!=mResContentsHash.end()) { cur=(*it).second; mResContentsHash.erase(it); } if (cur.contents==NULL) { cur.contents=::NewHandle(0); ThrowIfMemFull_(cur.contents); } stream.SetDisposeHandleFlag(false); stream.SetDataHandle(cur.contents); cur.count++; stream.SetMarker(0,streamFrom_End); stream << inResId; stream << inResName; mResContentsHash.insert(CResHash::value_type(inResType,cur)); } Catch_(err) { throw; } catch(...)
//_______________________________________________________________________________ OSErr WriteRsrc (Handle rsrc, ResType type, short ID, short resFile) { OSErr err; Handle h; short saved; saved = CurResFile(); UseResFile( resFile); if ((err= ResError())!=noErr) return err; h= GetResource (type, ID); if (h) RemoveResource (h); HLock (rsrc); AddResource( rsrc, type, ID, "\p"); err= ResError(); if( err== noErr) { UpdateResFile( resFile); err= ResError(); } HUnlock( rsrc); UseResFile( saved); return err; }
void CXTPCalendarResourcesManager::RemoveAll() { int i, nDPCount = GetDataProvidersCount(); for (i = 0; i < nDPCount; i++) { CXTPCalendarData* pData = GetDataProvider(i); _SaveCloseDPifNeed(pData); } //------------------------------------ for (i = nDPCount - 1; i >= 0; i--) { RemoveDataProvider(i); } //------------------------------------ int nRCCount = GetResourcesCount(); for (i = nRCCount - 1; i >= 0; i--) { RemoveResource(i); } }
OSErr CreateToolNameRes(StringPtr toolName) { short ref; FSSpec prefs; OSErr error; Handle theStrings; // build the 'STR ' resource error = FindPrefs(&prefs); if (error == noErr) { ref = FSpOpenResFile(&prefs, fsRdWrPerm); if (ref != -1) { theStrings = Get1Resource('STR ',kToolNameRes); if (theStrings != nil) { RemoveResource(theStrings); error = ResError(); } error = PtrToHand(toolName, &theStrings, toolName[0] + 1); AddResource(theStrings, 'STR ', kToolNameRes, "\ptoolName"); error = ResError(); ChangedResource(theStrings); error = ResError(); WriteResource(theStrings); error = ResError(); //ReleaseResource(theStrings); // Release the resource from memory. //error = ResError(); UpdateResFile(ref); // No screwing around; write that resource! error = ResError(); FlushVol(nil, prefs.vRefNum); CloseResFile(ref); } else {
i32 IResourceManager::DestroyResource( const ResourceHandle& Handle, const GroupHandle& GroupHandle ) { if( RemoveResource( Handle, GroupHandle ).IsValid() ) return XST_OK; return XST_FAIL; }
void CTriggerManager::ReleaseTrigger(const std::string& _trigger) { RemoveResource( _trigger ); }
int DoHostListDialog() { short itemHit,okay=FALSE,keepGoing=TRUE; DialogPtr dlog=NIL; GrafPtr oldPort; ModalFilterUPP MyFilterUPP; GetPort(&oldPort); /* On PowerPC, need a RoutineDescriptor from heap; on 68K, no allocation */ MyFilterUPP = NewModalFilterProc(MyFilterHD); if (MyFilterUPP == NIL) goto cleanUp; /* Build dialog window and install its item values */ OpenPrefsFile(); dlog = OpenThisDialog(); if (dlog == NIL) goto cleanUp; /* Entertain filtered user events until dialog is dismissed */ while (keepGoing) { ModalDialog(MyFilterUPP,&itemHit); keepGoing = DoDialogItem(dlog,itemHit); } /* * Do final processing of item values, such as exporting them to caller. * DoDialogItem() has already called AnyBadValues(). */ if (itemHit == OK_ITEM) { Point theCell; short dataLen; OSErr anErr; Handle aHand; // get the current selection and store it in a global which can be accessed // from the application theCell.h = 0; theCell.v = list4.currentRow; dataLen = 255; LGetCell(&gSavedSelection[1], &dataLen, theCell, list4.hndl); gSavedSelection[0] = dataLen; // we save the current selection for the next time we use this transport // remove the current resource aHand = Get1Resource('mw2H', 1000); if (aHand != nil) { RemoveResource(aHand); DisposeHandle(aHand); aHand = nil; } // create a handle and add this resource to the resource file anErr = PtrToHand(&gSavedSelection[0], &aHand, gSavedSelection[0] + 1); // name and length byte if ( (anErr == noErr) && (aHand != nil) ) { AddResource(aHand, 'mw2H', 1000, "\pDefault Host"); WriteResource(aHand); }
// レンダーターゲット削除 void CGraphicsDeviceDX9::RemoveRenderTarget(CRenderTargetDX9* p) { m_ResetRT = RemoveResource(p, m_ResetRT); }
ResourcePtr IResourceManager::RemoveResource(xst_castring& strName) { ResourceHandle Handle = XSE_HASH( strName ); return RemoveResource( Handle ); }
// インデックスバッファ削除 void CGraphicsDeviceDX9::RemoveIndexBuffer(CIndexBufferDX9* p) { m_ResetIB = RemoveResource(p, m_ResetIB); }
// 頂点バッファ削除 void CGraphicsDeviceDX9::RemoveVertexBuffer(CVertexBufferDX9* p) { m_ResetVB = RemoveResource(p, m_ResetVB); }
ResourcePtr IResourceManager::RemoveResource( xst_castring& strName, xst_castring& strGroup ) { ResourceHandle Handle = XSE_HASH( strName ); GroupHandle GrHandle = XSE_HASH( strGroup ); return RemoveResource( Handle, GrHandle ); }
i32 IResourceManager::DestroyResource(ResourceWeakPtr pRes) { if( RemoveResource( pRes ).IsValid() ) return XST_OK; return XST_FAIL; }
i32 IResourceManager::DestroyResource( xst_castring& strName, xst_castring& strGroup ) { if( RemoveResource( strName, strGroup ).IsValid() ) return XST_OK; return XST_FAIL; }
void cTextureManager::NotifyResourceParentChanged(vResource<SDL_Surface*> *res) { int index = FindResource(res); if(index >= 0) RemoveResource(index); }
// テクスチャ削除 void CGraphicsDeviceDX9::RemoveTexture(CTextureDX9* p) { m_ResetTexture = RemoveResource(p, m_ResetTexture); }