ResourceSet ResourceInfo::toResourceSet( const ResourceList& rResourceList ) { ResourceSet set; std::insert_iterator<ResourceSet> ii( set, set.begin() ); std::copy( rResourceList.begin(), rResourceList.end(), ii ); return set; }
bool CSVResourceReportElement::generate() { generateHeader(); generateTableHeader(); ResourceList filteredResourceList; if (!filterResourceList(filteredResourceList, 0, hideResource, rollUpResource)) return false; sortResourceList(filteredResourceList); maxDepthResourceList = filteredResourceList.maxDepth(); maxDepthTaskList = 0; int rNo = 1; for (ResourceListIterator rli(filteredResourceList); *rli != 0; ++rli, ++rNo) { TableLineInfo tli1; tli1.ca1 = tli1.resource = *rli; for (uint sc = 0; sc < scenarios.count(); ++sc) { tli1.row = sc; tli1.sc = scenarios[sc]; tli1.idxNo = rNo; generateLine(&tli1, sc == 0 ? 4 : 5); } } generateFooter(); return true; }
// Publish all ResourceList's that have changes. void ResourceListSet::publish() { Os::Logger::instance().log(FAC_RLS, PRI_DEBUG, "ResourceListSet::publish this = %p", this); // Serialize access to the ResourceListSet. OsLock lock(mSemaphore); // If publishing has been suspended, do nothing -- // publish() will be called again after publishing is resumed. if (!publishingSuspended()) { // Iterate through the resource lists. UtlSListIterator resourceListItor(mResourceLists); ResourceList* resourceList; while ((resourceList = dynamic_cast <ResourceList*> (resourceListItor()))) { resourceList->publishIfNecessary(); } // Purge dialogs with terminated state and terminated resource // instances, now that we have published the fact that they've // terminated (and their termination reasons). getResourceCache().purgeTerminated(); } }
void SurveyTool::StartUsing(PlayerObject* player) { Message* message; ResourceCategory* mainCat = gResourceManager->getResourceCategoryById(getInternalAttribute<uint32>("survey_tool_resource_category")); ResourceList resourceList; mainCat->getResources(resourceList,true); gMessageFactory->StartMessage(); gMessageFactory->addUint32(opResourceListForSurveyMessage); gMessageFactory->addUint32(resourceList.size()); ResourceList::iterator resourceIt = resourceList.begin(); while(resourceIt != resourceList.end()) { Resource* tmpResource = (*resourceIt); gMessageFactory->addString(tmpResource->getName()); gMessageFactory->addUint64(tmpResource->getId()); gMessageFactory->addString((tmpResource->getType())->getDescriptor()); ++resourceIt; } gMessageFactory->addString(mainCat->getName()); gMessageFactory->addUint64(mId); message = gMessageFactory->EndMessage(); (player->getClient())->SendChannelA(message, player->getAccountId(),CR_Client,4); }
ResourceList ResourceInfo::toResourceList( const std::set<ResourceInfo>& rResourceList ) { ResourceList list; std::insert_iterator<ResourceList> ii( list, list.begin() ); std::copy( rResourceList.begin(), rResourceList.end(), ii ); return list; }
void ResourceListSet::deleteResourceAt(const char* user, size_t at) { Os::Logger::instance().log(FAC_RLS, PRI_DEBUG, "ResourceListSet::deleteResourceAt this = %p, user = '******', at = %d", this, user, (int) at); // Serialize access to the ResourceListSet. OsLock lock(mSemaphore); ResourceList* resourceList = findResourceList(user); if (resourceList) { bool resource_deleted = resourceList->deleteResourceAt(at); if (resource_deleted) { // Delay to allow the consequent processing to catch up. OsTask::delay(getResourceListServer()->getChangeDelay()); } Os::Logger::instance().log(FAC_RLS, PRI_DEBUG, "ResourceListSet::deleteResourceAt done"); } else { Os::Logger::instance().log(FAC_RLS, PRI_DEBUG, "ResourceListSet::deleteResourceAt ResourceList '%s' not found", user); } }
bool TjPrintTaskReport::generate() { /* Get complete task list, filter and sort it. Then determine the maximum * tree level. */ TaskList filteredTaskList; if (!reportElement->filterTaskList(filteredTaskList, 0, reportElement->getHideTask(), reportElement->getRollUpTask())) return false; maxDepthTaskList = filteredTaskList.maxDepth(); (static_cast<const QtTaskReportElement*>(reportElement))-> sortTaskList(filteredTaskList); if (filteredTaskList.isEmpty()) return true; /* Same for resource list. Just that we don't have to sort it. It needs to * be regenerated per task later on. */ ResourceList filteredResourceList; if (!reportElement->filterResourceList(filteredResourceList, 0, reportElement->getHideResource(), reportElement->getRollUpResource())) return false; maxDepthResourceList = filteredResourceList.maxDepth(); generateTableHeader(); int index = 1; for (TaskListIterator tli(filteredTaskList); *tli; ++tli) { TjReportRow* row = new TjReportRow(getNumberOfColumns(), index++); row->setCoreAttributes(*tli, 0); rows.push_back(row); generateTaskListRow(row, *tli); if (!reportElement->filterResourceList (filteredResourceList, *tli, reportElement->getHideResource(), reportElement->getRollUpResource())) return false; reportElement->sortResourceList(filteredResourceList); for (ResourceListIterator rli(filteredResourceList); *rli; ++rli) { row = new TjReportRow(getNumberOfColumns(), index++); row->setCoreAttributes(*tli, *rli); rows.push_back(row); generateResourceListRow(row, *rli, *tli); } } layoutPages(); return true; }
//------------------------------------------------------------------------------------------------- void sdResourceSystem::GarbageCollect() { sdRequestInfoListItr itr = m_kCachedList.begin(); sdRequestInfoListItr itr_end = m_kCachedList.end(); for (; itr != itr_end; ++itr) { sdRequestInfo& kRequestInfo = *itr; RaiseEvent(kRequestInfo.m_spResource); } m_kCachedList.clear(); itr = m_kRequestList.begin(); itr_end = m_kRequestList.end(); for (; itr != itr_end;) { sdRequestInfo& kRequestInfo = *itr; if (kRequestInfo.m_eRequest == sdRequestInfo::E_REQ_LOAD && kRequestInfo.m_spResource->Cached()) { RaiseEvent(kRequestInfo.m_spResource); itr = m_kRequestList.erase(itr); } else { ++itr; } } m_kRequestList.clear(); ResourceGroupVecItr itr_res_gp = m_kResourceGroupVec.begin(); ResourceGroupVecItr itr_res_gp_end = m_kResourceGroupVec.end(); for (; itr_res_gp != itr_res_gp_end; ++itr_res_gp) { sdResourceGroup* pkResourceGroup = *itr_res_gp; if (!pkResourceGroup) continue; ResourceList kResourceList; pkResourceGroup->GarbageCollect(kResourceList); ResourceListItr itr_res_list = kResourceList.begin(); ResourceListItr itr_res_list_end = kResourceList.end(); for (; itr_res_list != itr_res_list_end; ++itr_res_list) { // 后台线程清除资源 //RequestFree(*itr_res_list); // 主线程清除资源 sdResourcePtr pkResource = *itr_res_list; pkResource->FreeResource(false); pkResource = 0; } } }
void SpriteModel::addSprites( quint8 resourceType, ResourceList& resources ) { if( resourceType != m_resourceType ) return; emit addedSprites( resourceType, resources.size() ); beginInsertRows( QModelIndex(), m_resourceList.size(), m_resourceList.size() + resources.size() ); m_resourceList += resources; endInsertRows(); }
void Turret::GetPrefetchResourceList(const char* pszObjectName, IObjectResourceGatherer* pInterface, ResourceList& Resources ) { // get the turret record char szTurretType[MAX_PATH]; pInterface->GetPropString(pszObjectName, "TurretType", szTurretType, LTARRAYSIZE(szTurretType), NULL); if (!LTStrEmpty(szTurretType)) { HRECORD hTurretRecord = g_pWeaponDB->GetTurretRecord(szTurretType); // get the base model and material HATTRIBUTE hBaseModelAttribute = g_pLTDatabase->GetAttribute(hTurretRecord, WDB_TURRET_sBaseModel); const char* pszBaseModel = g_pLTDatabase->GetString(hBaseModelAttribute, 0, NULL); if (pszBaseModel) { Resources.push_back(pszBaseModel); } HATTRIBUTE hBaseMaterialAttribute = g_pLTDatabase->GetAttribute(hTurretRecord, WDB_TURRET_sBaseMaterial); const char* pszBaseMaterial = g_pLTDatabase->GetString(hBaseMaterialAttribute, 0, NULL); if (pszBaseMaterial) { Resources.push_back(pszBaseMaterial); } // get the client FX resources GetClientFXResources(Resources, hTurretRecord, WDB_TURRET_sLoopFX); GetClientFXResources(Resources, hTurretRecord, WDB_TURRET_sDamageFX); HATTRIBUTE hDamageStateStruct = g_pLTDatabase->GetAttribute(hTurretRecord, WDB_TURRET_DamageState); uint32 nNumberOfDamageStates = g_pLTDatabase->GetNumValues(hDamageStateStruct); for (uint32 nDamageStateIndex = 0; nDamageStateIndex < nNumberOfDamageStates; ++nDamageStateIndex) { HATTRIBUTE hClientFX = CGameDatabaseReader::GetStructAttribute(hDamageStateStruct, nDamageStateIndex, WDB_TURRET_fxClientFX); const char* pszClientFX = g_pLTDatabase->GetString(hClientFX, 0, NULL); GetClientFXResources(Resources, pszClientFX); } // get the weapon record HATTRIBUTE hTurretWeaponLink = g_pLTDatabase->GetAttribute(hTurretRecord, WDB_TURRET_rWeapon); HRECORD hTurretWeapon = g_pLTDatabase->GetRecordLink(hTurretWeaponLink, 0, NULL); if (hTurretWeapon) { // get the default attribute HATTRIBUTE hDefaultAttribute = g_pLTDatabase->GetAttribute(hTurretWeapon, "Default"); HRECORD hDefaultRecord = g_pLTDatabase->GetRecordLink(hDefaultAttribute, 0, NULL); // get everything under here GetRecordResources(Resources, hDefaultRecord, true); } } }
ResourceList Scheduler::allocate(Job &j, size_t max_res, size_t min_res) { ResourceList allocatedResources; if (resPool->size() >= min_res) { while (max_res-- > 0 && resPool->size() > 0) { allocatedResources.push_back(*resPool->wait_pop_back()); } // LOGF(debug, "Allocated %1% resources to %2% ") % allocatedResources.size() % j; } return allocatedResources; }
ResourceList ResourceManager::list() { ResourceList resourceList; Ogre::StringVectorPtr resources = mRGM.findResourceNames( mGroup, "*" ); for( Ogre::StringVector::const_iterator i = resources->begin(); i != resources->end(); ++i ) { resourceList.push_back( Path( *i ) ); } return resourceList; }
void Resource::flush() { ResourceList* list = ResourceImpl::deletes_; if (list != nil) { boolean previous = ResourceImpl::deferred_; ResourceImpl::deferred_ = false; for (ListItr(ResourceList) i(*list); i.more(); i.next()) { Resource* r = i.cur(); delete r; } list->remove_all(); ResourceImpl::deferred_ = previous; } }
QByteArray QResourceInfo::data() const { if(container || related.isEmpty()) return QByteArray(); if(!hasData) { hasData = true; QString path = searchFile; if(path.startsWith(QLatin1Char(':'))) path = path.mid(1); mData = related.at(0).data(path); } return mData; }
void ResourceHandler::addForeignResources( quint8 resourceType, ResourceList& resources ) { ResourceList *foreignList; switch( resourceType ) { case RESOURCE_TYPE_SPRITE: foreignList = &m_foreignSprites; break; case RESOURCE_TYPE_PICTURE: foreignList = &m_foreignPictures; break; } foreignList->append( resources ); }
SharedResource ResourceHandler::addResource( quint32 resourceType, SharedResource& resource ) { ResourceList *foreignResources; switch( resourceType ) { case RESOURCE_TYPE_SPRITE: foreignResources = &m_foreignSprites; break; case RESOURCE_TYPE_PICTURE: foreignResources = &m_foreignPictures; break; } foreignResources->push_back( resource ); return resource; }
SharedResource ResourceHandler::addResource( quint8 resourceType, quint32 identifier, quint16 frame, QFile *file ) { ResourceList *foreignResources; switch( resourceType ) { case RESOURCE_TYPE_SPRITE: foreignResources = &m_foreignSprites; break; case RESOURCE_TYPE_PICTURE: foreignResources = &m_foreignPictures; break; } SharedResource reference(new TibiaResource( resourceType, identifier, frame, file)); foreignResources->push_back(reference); return reference; }
// Get a list of the user-parts of all resource lists. void ResourceListSet::getAllResourceLists(UtlSList& list) { Os::Logger::instance().log(FAC_RLS, PRI_DEBUG, "ResourceListSet::getAllResourceLists this = %p", this); // Serialize access to the ResourceListSet. OsLock lock(mSemaphore); // Iterate through the resource lists. UtlSListIterator resourceListItor(mResourceLists); ResourceList* resourceList; while ((resourceList = dynamic_cast <ResourceList*> (resourceListItor()))) { list.append(new UtlString(*resourceList->getUserPart())); } }
bool PictureFile::createNew( void ) { if( !m_loaded ) { m_count = 1; TibiaSprite picture; picture.id = 1; picture.setDummy( false ); SharedResource newResource = g_resourceHandler.createLocalResource( RESOURCE_TYPE_PICTURE, 0, picture ); ResourceList resources; resources.push_back( newResource ); g_resourceHandler.addLocalResources( RESOURCE_TYPE_PICTURE, 0, resources ); m_loaded = true; return true; } return false; }
ResourceList Session::getResourcesUsed( bool reset ) { ScopedLock<ReentrantMutex> sl( session_mtx ); ResourceList list; list.reserve( resources_used.size() ); for( ResourceList::const_iterator i = resources_used.begin(); i != resources_used.end(); i++ ) { list.push_back( i->get() ); } if ( reset ) resources_used.clear(); return list; }
bool QResourceInfo::loadResource(const QString &path) { ensureInitialized(); const ResourceList *list = resourceList(); for(int i = 0; i < list->size(); ++i) { QResource res = list->at(i); if(res.exists(path)) { if(related.isEmpty()) container = res.isContainer(path); else if(res.isContainer(path) != container) qWarning("Resource [%s] has both data and children!", file.toLatin1().constData()); related.append(res); } } return !related.isEmpty(); }
inline void clear() { searchFile.clear(); file.clear(); hasData = hasChildren = 0; container = 0; related.clear(); initialized = 0; }
// Search for a resource list with a given name (user-part). ResourceList* ResourceListSet::findResourceList(const char* user) { ResourceList* ret = 0; // Iterate through the resource lists. UtlSListIterator resourceListItor(mResourceLists); ResourceList* resourceList; while (!ret && (resourceList = dynamic_cast <ResourceList*> (resourceListItor()))) { if (resourceList->getUserPart()->compareTo(user) == 0) { ret = resourceList; } } return ret; }
// Create and add a resource list. bool ResourceListSet::addResourceList(const char* user, const char* userCons, const char* nameXml) { Os::Logger::instance().log(FAC_RLS, PRI_DEBUG, "ResourceListSet::addResourceList this = %p, user = '******', userCons = '%s', nameXml = '%s'", this, user, userCons, nameXml); // Serialize access to the ResourceListSet. OsLock lock(mSemaphore); // Check to see if there is already a list with this name. bool ret = !findResourceList(user); if (ret) { // Create the resource list. ResourceList* resourceList = new ResourceList(this, user, userCons); // Update the version number for consolidated events if it is too // small for an existing subscription to this URI. int v = getResourceListServer()->getSubscriptionMgr(). getNextAllowedVersion(*resourceList->getResourceListUriCons()); if (v > mVersion) { mVersion = v; } // Add the resource list to the set. mResourceLists.append(resourceList); Os::Logger::instance().log(FAC_RLS, PRI_DEBUG, "ResourceListSet::addResourceList added ResourceList, mVersion = %d", mVersion); } else { Os::Logger::instance().log(FAC_RLS, PRI_DEBUG, "ResourceListSet::addResourceList ResourceList '%s' already exists", user); } return ret; }
void Terrain::load() { // Load terrain resources. ResourceList resourceList; // Heightmap resourceList.push_back( ResourceInfo( mHeightmapFile ) ); // Textures for( LayerInstances::iterator i = mLayerInstances.begin(); i != mLayerInstances.end(); ++i ) { for( std::vector<Path>::iterator j = (*i).mTextureFiles.begin(); j != (*i).mTextureFiles.end(); ++j ) { resourceList.push_back( ResourceInfo( *j ) ); } } mResourceManager.loadResources( resourceList, sigc::mem_fun( this, &Terrain::resourcesLoaded ) ); }
//! Create and add a resource to the resource list. bool ResourceListSet::addResource(const char* user, const char* uri, const char* nameXml, const char* display_name, ssize_t no_check_start, ssize_t no_check_end) { Os::Logger::instance().log(FAC_RLS, PRI_DEBUG, "ResourceListSet::addResource this = %p, user = '******', uri = '%s', nameXml = '%s', display_name = '%s', no_check_start = %d, no_check_end = %d", this, user, uri, nameXml, display_name, (int) no_check_start, (int) no_check_end); // Serialize access to the ResourceListSet. OsLock lock(mSemaphore); bool resource_added = false; ResourceList* resourceList = findResourceList(user); if (resourceList) { bool resource_cached_created; resourceList->addResource(uri, nameXml, display_name, resource_added, resource_cached_created, no_check_start, no_check_end); if (resource_cached_created) { // Delay to allow the consequent processing to catch up. OsTask::delay(getResourceListServer()->getChangeDelay()); } Os::Logger::instance().log(FAC_RLS, PRI_DEBUG, "ResourceListSet::addResource resource added"); } else { Os::Logger::instance().log(FAC_RLS, PRI_DEBUG, "ResourceListSet::addResource ResourceList '%s' not found", user); } return resource_added; }
// Dump the object's internal state. void ResourceListSet::dumpState() { // Serialize access to the ResourceListSet. OsLock lock(mSemaphore); // indented 2 Os::Logger::instance().log(FAC_RLS, PRI_INFO, "\t ResourceListSet %p mSuspendPublishingCount = %d", this, mSuspendPublishingCount); UtlSListIterator i(mResourceLists); ResourceList* rl; while ((rl = dynamic_cast <ResourceList*> (i()))) { rl->dumpState(); } mResourceCache.dumpState(); }
// Delete a resource list. void ResourceListSet::deleteResourceList(const char* user) { Os::Logger::instance().log(FAC_RLS, PRI_DEBUG, "ResourceListSet::deleteResourceList this = %p, user = '******'", this, user); // Gradually remove elements from the ResourceList and delete them. ResourceList* rl; int changeDelay = getResourceListServer()->getChangeDelay(); do { // Set to true if a ResourceCached was deleted and so we need to delay. bool resource_deleted = false; { // Serialize access to the ResourceListSet. OsLock lock(mSemaphore); // Get pointer to the ResourceList. rl = findResourceList(user); // If it exists, shrink it. if (rl) { bool list_empty; rl->shrink(list_empty, resource_deleted); if (list_empty) { // The ResourceList is empty, and so can be removed and deleted. mResourceLists.removeReference(rl); delete rl; // Exit the loop now. rl = NULL; } } } if (resource_deleted) { // Delay to allow the consequent processing to catch up. OsTask::delay(changeDelay); } } while (rl && !gShutdownFlag); }
// Get the information from resource in a resource list specified // by its position in the list. void ResourceListSet::getResourceInfoAt(const char* user, size_t at, UtlString& uri, UtlString& nameXml, UtlString& display_name) { // Serialize access to the ResourceListSet. OsLock lock(mSemaphore); ResourceList* resourceList = findResourceList(user); if (resourceList) { resourceList->getResourceInfoAt(at, uri, nameXml, display_name); } else { Os::Logger::instance().log(FAC_RLS, PRI_DEBUG, "ResourceListSet::getResourceInfoAt ResourceList '%s' not found", user); } }
// Delete all resource lists. void ResourceListSet::deleteAllResourceLists(bool abortOnShutdown) { Os::Logger::instance().log(FAC_RLS, PRI_DEBUG, "ResourceListSet::deleteAllResourceLists " "this = %p, abortOnShutdown = %d", this, abortOnShutdown); // Gradually remove elements from the ResourceLists and delete them. ResourceList* rl; int changeDelay = getResourceListServer()->getChangeDelay(); do { // Set to true if a ResourceCached was deleted and so we need to delay. bool resource_deleted = false; { // Serialize access to the ResourceListSet. OsLock lock(mSemaphore); // Get pointer to the first ResourceList. rl = dynamic_cast <ResourceList*> (mResourceLists.first()); // If one exists, shrink it. if (rl) { bool list_empty; rl->shrink(list_empty, resource_deleted); if (list_empty) { // The ResourceList is empty, and so can be removed and deleted. mResourceLists.removeReference(rl); delete rl; } } } if (resource_deleted) { // Delay to allow the consequent processing to catch up. OsTask::delay(changeDelay); } } while (rl && !gShutdownFlag); }