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; }
void index_resources(ResourceSet &rs) { uint16_t index(1); ResourceSet::iterator it(rs.begin()); for (; it!=rs.end(); ++it) { it->second = index++; } }
bool Res::canAfford(const ResourceSet &res, const ResourceSet &price) { assert(res.size() == price.size() && price.size() == GameConstants::RESOURCE_QUANTITY); for(int i = 0; i < GameConstants::RESOURCE_QUANTITY; i++) if(price[i] > res[i]) return false; return true; }
void write_resource_data(ostream &out, ResourceIndex &index , const ResourceSet &rs) { uint32_t offset(0); ResourceSet::const_iterator it(rs.begin()); for (; it!=rs.end(); ++it) { index.push_back(ResourceInfo(offset, it->first->type)); offset += it->first->write(out); } }
void measure_jumps(ResourceSet &rs) { ResourceSet::iterator it(rs.begin()); for (; it!=rs.end(); ++it) { if (it->first->type == RESOURCE_FUNCTION) { AsmFunc *func = dynamic_cast< AsmFunc * >(it->first); measure_function_jumps(*func); } } }
void print_resources(const ResourceSet &rs) { cout << "collected " << rs.size() << " resources\n"; ResourceSet::const_iterator it(rs.begin()); for (; it!=rs.end(); ++it) { cout << it->second << "\t"; it->first->pretty(cout); cout << endl; } }
void generate_code(ResourceSet &rs) { ResourceSet::iterator it(rs.begin()); AsmFunc *func; for (; it!=rs.end(); ++it) { if (it->first->type != RESOURCE_FUNCTION) { // no code to generate for non-functions continue; } func = static_cast< AsmFunc * >(it->first); if (!func->stmts) { continue; } generate_codeblock(*func, *func->stmts); } measure_jumps(rs); }
ResourceTableHeader write_resource_table(ostream &out, const ResourceSet &rs) { ResourceIndex index; uint32_t pre_data(out.tellp()); write_resource_data(out, index, rs); uint32_t post_data(out.tellp()); write_resource_index(out, index); ResourceTableHeader tbl_header; tbl_header.data_size = post_data - pre_data; tbl_header.resource_count = rs.size(); return tbl_header; }
bool Action::can_do_event(Graph *g, ResourceSet amount) { // check all required resources are available for (auto &a : amount.get_amounts()) { // if the amount is not enough if (!g->get_resource(a.first)->allow_negative() && a.second < -pre_effect.get_delta(a.first)) { return false; } } return true; }
void JabberBotSession::SetAvailable(const std::string *from) { // Split the string into username/resource std::string account_id, resource; split_identifier(from, account_id, resource); UserStatusType::iterator i = m_userStatuses.find(account_id); if (i == m_userStatuses.end()) { // Not found, need to add the user ResourceSet value; if ("" != resource) { value.insert(resource); } m_userStatuses.insert(UserStatusType::value_type(account_id, value)); } else { if ("" != resource) { i->second.insert(resource); } } std::ostringstream message; message << "Account " << account_id << " has become available at resource " << resource << std::endl; syslog(LOG_INFO, message.str().c_str()); }
void ResourceManager::loadResources( const ResourceList& rResources, const SimpleResourceCallback& rCallbackSlot ) { // Convert to set to remove duplicates. ResourceSet resources = ResourceInfo::toResourceSet( rResources ); if( resources.empty() ) { // If there are no resources to be loaded, call the slot and return immediately. rCallbackSlot(); return; } ResourceManager::ResourcesLoader* resourceLoader = ResourceManager::ResourcesLoader::create( rCallbackSlot ); unsigned short loaded = 0; for( ResourceSet::const_iterator i = resources.begin(); i != resources.end(); ++i ) { // Add resources to resource loader. Ogre::ResourcePtr resource = ResourceManager::getResource( *i, true ); if( resource.isNull() ) { DIVERSIA_EXCEPT( Exception::ERR_FILE_NOT_FOUND, "Cannot load resource " + (*i).mFile.string() + ", file does not exist.", "ResourceManager::loadResource" ); } if( resource->isLoaded() ) loaded++; else resourceLoader->addResource( resource ); } // All resources are already loaded. if( loaded == resources.size() ) { rCallbackSlot(); delete resourceLoader; return; } for( ResourceSet::const_iterator j = resources.begin(); j != resources.end(); ++j ) { // Load all resources and callback to the resource loader. If all resources are loaded // the rCallbackSlot will be called and the resource loader will be destroyed. ResourceManager::loadResource( *j, sigc::mem_fun( resourceLoader, &ResourceManager::ResourcesLoader::loadingComplete ) ); } }
void fieldset_stmt::collect_resources(ResourceSet &rs) { rs.collect(field_name); }
bool collect_modsym(ResourceSet &rs, AsmModSym &modsym) { rs.import(modsym.module); rs.collect(modsym.symbol); return rs.collect(modsym); }
bool collect_string(ResourceSet &rs, AsmString &str) { return rs.collect(str); }
bool collect_resource(ResourceSet &rs, AsmResource &res) { return rs.collect(res); }
void Action::apply_end_effect(ResourceSet &r) { for (auto &e : post_effect.get_deltas()) { r.adjust_amount(e.first, e.second); } }