ResultCode CreateExtSaveData(MediaType media_type, u32 high, u32 low, VAddr icon_buffer, u32 icon_size, const FileSys::ArchiveFormatInfo& format_info) { // Construct the binary path to the archive first FileSys::Path path = FileSys::ConstructExtDataBinaryPath(static_cast<u32>(media_type), high, low); auto archive = id_code_map.find(media_type == MediaType::NAND ? ArchiveIdCode::SharedExtSaveData : ArchiveIdCode::ExtSaveData); if (archive == id_code_map.end()) { return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the right error } auto ext_savedata = static_cast<FileSys::ArchiveFactory_ExtSaveData*>(archive->second.get()); ResultCode result = ext_savedata->Format(path, format_info); if (result.IsError()) return result; if (!Memory::IsValidVirtualAddress(icon_buffer)) return ResultCode(-1); // TODO(Subv): Find the right error code std::vector<u8> smdh_icon(icon_size); Memory::ReadBlock(icon_buffer, smdh_icon.data(), smdh_icon.size()); ext_savedata->WriteIcon(path, smdh_icon.data(), smdh_icon.size()); return RESULT_SUCCESS; }
inline void Restaurant::FillInPredictivesNonGraphical( const std::vector<double>& parent_predictives, int type, int depth, const HPYParameter& hpy_parameter, std::vector<double>& predictives) const { for (size_t i = 0; i < parent_predictives.size(); ++i) { predictives[i] = parent_predictives[i]; } for (auto floor_it = floor2c_t_.begin(); floor_it != floor2c_t_.end(); ++floor_it) { auto floor_id = (*floor_it).first; auto& c_t = (*floor_it).second; tmp_c_[floor_id] = c_t.first; predictives[floor_id] *= (hpy_parameter.concentration(depth, floor_id) + hpy_parameter.discount(depth, floor_id) * c_t.second) / (c_t.first + hpy_parameter.concentration(depth, floor_id)); } auto type_it = type2internal_.find(type); if (type_it == type2internal_.end()) return; auto& sections = (*type_it).second.sections_; auto section_it = sections.begin(); for (; section_it != sections.end(); ++section_it) { auto floor_id = (*section_it).first; auto& section = (*section_it).second; auto cw = section.customers; auto tw = section.tables; predictives[floor_id] += (cw - hpy_parameter.discount(depth, floor_id) * tw) / (tmp_c_[floor_id] + hpy_parameter.concentration(depth, floor_id)); } }
/* * Retrieve a material by tag */ boost::optional<std::size_t> get_material_by_tag(const std::string &tag) noexcept { boost::optional<std::size_t> result; auto finder = material_defs_idx.find(tag); if (finder != material_defs_idx.end()) { result = finder->second; } return result; }
ResultVal<FileSys::ArchiveFormatInfo> GetArchiveFormatInfo(ArchiveIdCode id_code, FileSys::Path& archive_path) { auto archive = id_code_map.find(id_code); if (archive == id_code_map.end()) { return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the right error } return archive->second->GetFormatInfo(archive_path); }
ResultCode FormatArchive(ArchiveIdCode id_code, const FileSys::ArchiveFormatInfo& format_info, const FileSys::Path& path) { auto archive_itr = id_code_map.find(id_code); if (archive_itr == id_code_map.end()) { return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the right error } return archive_itr->second->Format(path, format_info); }
ResultVal<std::unique_ptr<FileSys::FileSystemBackend>> OpenFileSystem(Type type, FileSys::Path& path) { LOG_TRACE(Service_FS, "Opening FileSystem with type=%d", type); auto itr = filesystem_map.find(type); if (itr == filesystem_map.end()) { // TODO(bunnei): Find a better error code for this return ResultCode(-1); } return itr->second->Open(path); }
double Restaurant::predictive_probability(topic_t floor_id, int type, double parent_probability, double discount, double concentration) const { int cw = 0; int tw = 0; int c = 0; int t = 0; auto section_it = type2internal_.find(type); if (section_it != type2internal_.end()) { cw = (*section_it).second.customers(floor_id); tw = (*section_it).second.tables(floor_id); } auto floor_it = floor2c_t_.find(floor_id); if (floor_it != floor2c_t_.end()) { c = (*floor_it).second.first; t = (*floor_it).second.second; } return ComputePYPPredictive(cw, tw, c, t, parent_probability, discount, concentration); }
std::pair<double,double> FermiTable::calcAverageAtomicProperties (const boost::container::flat_map<string,double>& tracers) const { double total = 0; double aa = 0; double zz = 0; for(std::map<string,std::pair<double,double> >::const_iterator it= atomic_properties_.begin(); it!=atomic_properties_.end();++it){ assert(tracers.count(it->first)==1); const double mass_frac = tracers.find(it->first)->second; const double A = it->second.first; const double Z = it->second.second; total += mass_frac; aa += mass_frac/A; zz += mass_frac*Z/A; } return std::pair<double,double>(total/aa,zz/aa); }
ResultVal<ArchiveHandle> OpenArchive(ArchiveIdCode id_code, FileSys::Path& archive_path) { LOG_TRACE(Service_FS, "Opening archive with id code 0x%08X", id_code); auto itr = id_code_map.find(id_code); if (itr == id_code_map.end()) { // TODO: Verify error against hardware return ResultCode(ErrorDescription::NotFound, ErrorModule::FS, ErrorSummary::NotFound, ErrorLevel::Permanent); } CASCADE_RESULT(std::unique_ptr<ArchiveBackend> res, itr->second->Open(archive_path)); // This should never even happen in the first place with 64-bit handles, while (handle_map.count(next_handle) != 0) { ++next_handle; } handle_map.emplace(next_handle, std::move(res)); return MakeResult<ArchiveHandle>(next_handle++); }
bool is_better_armor(const std::string &item_tag, boost::container::flat_map<item_location_t, float> &ac_by_loc) { auto finder = get_clothing_by_tag(item_tag); if (!finder) return false; const float item_ac = finder->armor_class; item_location_t loc = INVENTORY; if (finder->slot == "head") loc = HEAD; if (finder->slot == "torso") loc = TORSO; if (finder->slot == "legs") loc = LEGS; if (finder->slot == "shoes") loc = FEET; auto tester = ac_by_loc.find(loc); if (tester == ac_by_loc.end()) { return true; } else { if (item_ac > tester->second) return true; } return false; }
void workflow_system::update(const double duration_ms) { if (dirty) { automatic_reactions.clear(); // Enumerate buildings and see which ones have reactions. each<position_t, building_t>([this] (entity_t &e, position_t &pos, building_t &b) { if (b.complete) { auto finder = reaction_building_defs.find(b.tag); if (finder != reaction_building_defs.end()) { for (const std::string &reaction_name : finder->second) { auto reactor = reaction_defs.find(reaction_name); if (reactor != reaction_defs.end()) { // Automatic reactions are added to the auto reactor list if (reactor->second.automatic) { auto automatic_finder = automatic_reactions.find(e.id); if (automatic_finder == automatic_reactions.end()) { automatic_reactions[e.id] = std::vector<std::string>{ reaction_name }; } else { automatic_finder->second.push_back(reaction_name); } } } } } } }); // Erase all completed jobs designations->build_orders.erase( std::remove_if(designations->build_orders.begin(), designations->build_orders.end(), [] (auto order_pair) { return order_pair.first == 0; }), designations->build_orders.end()); // Not dirty anymore! dirty = false; } }
/* * Linter for materials, used in raw loader. */ void sanity_check_materials() noexcept { for (const auto &mat : material_defs) { if (mat.tag.empty()) std::cout << "WARNING: Empty material tag\n"; if (mat.name.empty()) std::cout << "WARNING: Empty material name, tag: " << mat.tag << "\n"; /*if (!mat.mines_to_tag.empty()) { auto finder = item_defs.find(mat.mines_to_tag); if (finder == item_defs.end()) std::cout << "WARNING: Unknown mining result " << mat.mines_to_tag << ", tag: " << mat.tag << "\n"; } if (!mat.mines_to_tag_second.empty()) { auto finder = item_defs.find(mat.mines_to_tag_second); if (finder == item_defs.end()) std::cout << "WARNING: Unknown mining result " << mat.mines_to_tag_second << ", tag: " << mat.tag << "\n"; }*/ if (!mat.ore_materials.empty()) { for (const std::string &metal : mat.ore_materials) { auto finder = material_defs_idx.find(metal); if (finder == material_defs_idx.end()) { std::cout << "WARNING: Substance " << mat.tag << " produces a non-existent ore: " << metal << "\n"; } } } } }
void Restaurant::FillInPredictives(const std::vector<double>& parent_predictives, int type, const LambdaManagerInterface& lmanager, int depth, const HPYParameter& hpy_parameter, std::vector<double>& predictives) const { auto floor_it = floor2c_t_.begin(); auto type_it = type2internal_.find(type); predictives[0] = parent_predictives[0]; if (floor2c_t_.empty()) { for (size_t i = 1; i < predictives.size(); ++i) { double lambda = lmanager.lambda(i, depth); predictives[i] = lambda * parent_predictives[i] + (1 - lambda) * predictives[0]; } return; } if ((*floor_it).first == 0) { auto& c_t = (*floor_it).second; predictives[0] *= (hpy_parameter.concentration(depth, 0) + hpy_parameter.discount(depth, 0) * c_t.second) / (c_t.first + hpy_parameter.concentration(depth, 0)); if (type_it != type2internal_.end()) { auto& sections = (*type_it).second.sections_; if (!sections.empty()) { auto section_begin = sections.begin(); if ((*section_begin).first == 0) { int cw = (*section_begin).second.customers; int tw = (*section_begin).second.tables; predictives[0] += (cw - hpy_parameter.discount(depth, 0) * tw) / (c_t.first + hpy_parameter.concentration(depth, 0)); } } } } for (size_t i = 1; i < predictives.size(); ++i) { double lambda = lmanager.lambda(i, depth); predictives[i] = lambda * parent_predictives[i] + (1 - lambda) * predictives[0]; } if ((*floor_it).first == 0) { ++floor_it; } for (; floor_it != floor2c_t_.end(); ++floor_it) { auto floor_id = (*floor_it).first; auto& c_t = (*floor_it).second; tmp_c_[floor_id] = c_t.first; predictives[floor_id] *= (hpy_parameter.concentration(depth, floor_id) + hpy_parameter.discount(depth, floor_id) * c_t.second) / (c_t.first + hpy_parameter.concentration(depth, floor_id)); } if (type_it == type2internal_.end()) return; auto& sections = (*type_it).second.sections_; auto section_it = sections.begin(); if (section_it != sections.end() && (*section_it).first == 0) { ++section_it; } for (; section_it != sections.end(); ++section_it) { auto floor_id = (*section_it).first; auto& section = (*section_it).second; int cw = section.customers; int tw = section.tables; predictives[floor_id] += (cw - hpy_parameter.discount(depth, floor_id) * tw) / (tmp_c_[floor_id] + hpy_parameter.concentration(depth, floor_id)); } }