void OsmAnd::ObfAddressSectionReader_P::readBuildingsFromStreet( const ObfReader_P& reader, const std::shared_ptr<const Model::Street>& street, QList< std::shared_ptr<const Model::Building> >* resultOut, std::function<bool (const std::shared_ptr<const OsmAnd::Model::Building>&)> visitor, const IQueryController* const controller) { auto cis = reader._codedInputStream.get(); for(;;) { if (controller && controller->isAborted()) return; auto tag = cis->ReadTag(); switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: return; case OBF::StreetIndex::kIntersectionsFieldNumber: { gpb::uint32 length; cis->ReadVarint32(&length); cis->Skip(length); } break; case OBF::StreetIndex::kBuildingsFieldNumber: { auto offset = cis->CurrentPosition(); gpb::uint32 length; cis->ReadVarint32(&length); auto oldLimit = cis->PushLimit(length); std::shared_ptr<Model::Building> building(new Model::Building()); building->_offset = offset; readBuilding(reader, street, building); cis->PopLimit(oldLimit); if (!visitor || visitor(building)) { if (resultOut) resultOut->push_back(qMove(building)); } } break; default: ObfReaderUtilities::skipUnknownField(cis, tag); break; } } }
std::vector<JsonNode> CTownHandler::loadLegacyData(size_t dataSize) { std::vector<JsonNode> dest(dataSize); factions.resize(dataSize); auto getBuild = [&](size_t town, size_t building) -> JsonNode & { return dest[town]["town"]["buildings"][EBuildingType::names[building]]; }; CLegacyConfigParser parser("DATA/BUILDING.TXT"); parser.endLine(); // header parser.endLine(); //Unique buildings for (size_t town=0; town<dataSize; town++) { parser.endLine(); //header parser.endLine(); int buildID = 17; do { getBuild(town, buildID) = readBuilding(parser); buildID++; } while (!parser.isNextEntryEmpty()); } // Common buildings parser.endLine(); // header parser.endLine(); parser.endLine(); int buildID = 0; do { JsonNode building = readBuilding(parser); for (size_t town=0; town<dataSize; town++) getBuild(town, buildID) = building; buildID++; } while (!parser.isNextEntryEmpty()); parser.endLine(); //header parser.endLine(); //Dwellings for (size_t town=0; town<dataSize; town++) { parser.endLine(); //header parser.endLine(); for (size_t i=0; i<14; i++) { getBuild(town, 30+i) = readBuilding(parser); } } { CLegacyConfigParser parser("DATA/BLDGNEUT.TXT"); for(int building=0; building<15; building++) { std::string name = parser.readString(); std::string descr = parser.readString(); parser.endLine(); for(int j=0; j<dataSize; j++) { getBuild(j, building)["name"].String() = name; getBuild(j, building)["description"].String() = descr; } } parser.endLine(); // silo parser.endLine(); // blacksmith //unused entries parser.endLine(); // moat //shipyard with the ship std::string name = parser.readString(); std::string descr = parser.readString(); parser.endLine(); for(int town=0; town<dataSize; town++) { getBuild(town, 20)["name"].String() = name; getBuild(town, 20)["description"].String() = descr; } //blacksmith for(int town=0; town<dataSize; town++) { getBuild(town, 16)["name"].String() = parser.readString(); getBuild(town, 16)["description"].String() = parser.readString(); parser.endLine(); } } { CLegacyConfigParser parser("DATA/BLDGSPEC.TXT"); for(int town=0; town<dataSize; town++) { for(int build=0; build<9; build++) { getBuild(town, 17 + build)["name"].String() = parser.readString(); getBuild(town, 17 + build)["description"].String() = parser.readString(); parser.endLine(); } getBuild(town, 26)["name"].String() = parser.readString(); // Grail getBuild(town, 26)["description"].String() = parser.readString(); parser.endLine(); getBuild(town, 15)["name"].String() = parser.readString(); // Resource silo getBuild(town, 15)["description"].String() = parser.readString(); parser.endLine(); } } { CLegacyConfigParser parser("DATA/DWELLING.TXT"); for(int town=0; town<dataSize; town++) { for(int build=0; build<14; build++) { getBuild(town, 30 + build)["name"].String() = parser.readString(); getBuild(town, 30 + build)["description"].String() = parser.readString(); parser.endLine(); } } } { CLegacyConfigParser typeParser("DATA/TOWNTYPE.TXT"); CLegacyConfigParser nameParser("DATA/TOWNNAME.TXT"); size_t townID=0; do { dest[townID]["name"].String() = typeParser.readString(); for (int i=0; i<NAMES_PER_TOWN; i++) { JsonNode name; name.String() = nameParser.readString(); dest[townID]["town"]["names"].Vector().push_back(name); nameParser.endLine(); } townID++; } while (typeParser.endLine()); } return dest; }
void CTownHandler::loadLegacyData(JsonNode & dest) { CLegacyConfigParser parser("DATA/BUILDING.TXT"); dest.Vector().resize(GameConstants::F_NUMBER); parser.endLine(); // header parser.endLine(); //Unique buildings for (size_t town=0; town<GameConstants::F_NUMBER; town++) { JsonVector & buildList = dest.Vector()[town]["buildings"].Vector(); buildList.resize( 30 ); //prepare vector for first set of buildings parser.endLine(); //header parser.endLine(); int buildID = 17; do { buildList[buildID] = readBuilding(parser); buildID++; } while (!parser.isNextEntryEmpty()); } // Common buildings parser.endLine(); // header parser.endLine(); parser.endLine(); int buildID = 0; do { JsonNode building = readBuilding(parser); for (size_t town=0; town<GameConstants::F_NUMBER; town++) dest.Vector()[town]["buildings"].Vector()[buildID] = building; buildID++; } while (!parser.isNextEntryEmpty()); parser.endLine(); //header parser.endLine(); //Dwellings for (size_t town=0; town<GameConstants::F_NUMBER; town++) { parser.endLine(); //header parser.endLine(); do { dest.Vector()[town]["buildings"].Vector().push_back(readBuilding(parser)); } while (!parser.isNextEntryEmpty()); } { CLegacyConfigParser parser("DATA/BLDGNEUT.TXT"); for(int building=0; building<15; building++) { std::string name = parser.readString(); std::string descr = parser.readString(); parser.endLine(); for(int j=0; j<GameConstants::F_NUMBER; j++) { JsonVector & buildings = dest.Vector()[j]["buildings"].Vector(); buildings[building]["name"].String() = name; buildings[building]["description"].String() = descr; } } parser.endLine(); // silo parser.endLine(); // blacksmith //unused entries parser.endLine(); // moat //shipyard with the ship std::string name = parser.readString(); std::string descr = parser.readString(); parser.endLine(); for(int town=0; town<GameConstants::F_NUMBER; town++) { JsonVector & buildings = dest.Vector()[town]["buildings"].Vector(); buildings[20]["name"].String() = name; buildings[20]["description"].String() = descr; } //blacksmith for(int town=0; town<GameConstants::F_NUMBER; town++) { JsonVector & buildings = dest.Vector()[town]["buildings"].Vector(); buildings[16]["name"].String() = parser.readString(); buildings[16]["description"].String() = parser.readString(); parser.endLine(); } } { CLegacyConfigParser parser("DATA/BLDGSPEC.TXT"); for(int town=0; town<GameConstants::F_NUMBER; town++) { JsonVector & buildings = dest.Vector()[town]["buildings"].Vector(); for(int build=0; build<9; build++) { buildings[17+build]["name"].String() = parser.readString(); buildings[17+build]["description"].String() = parser.readString(); parser.endLine(); } buildings[26]["name"].String() = parser.readString(); // Grail buildings[26]["description"].String() = parser.readString(); parser.endLine(); buildings[15]["name"].String() = parser.readString(); // Resource silo buildings[15]["description"].String() = parser.readString(); parser.endLine(); } } { CLegacyConfigParser parser("DATA/DWELLING.TXT"); for(int town=0; town<GameConstants::F_NUMBER; town++) { JsonVector & buildings = dest.Vector()[town]["buildings"].Vector(); for(int build=0; build<14; build++) { buildings[30+build]["name"].String() = parser.readString(); buildings[30+build]["description"].String() = parser.readString(); parser.endLine(); } } } { CLegacyConfigParser typeParser("DATA/TOWNTYPE.TXT"); CLegacyConfigParser nameParser("DATA/TOWNNAME.TXT"); size_t townID=0; do { JsonNode & town = dest.Vector()[townID]; town["name"].String() = typeParser.readString(); for (int i=0; i<GameConstants::NAMES_PER_TOWN; i++) { JsonNode name; name.String() = nameParser.readString(); town["names"].Vector().push_back(name); nameParser.endLine(); } townID++; } while (typeParser.endLine()); } }