| 807 | } |
| 808 | |
| 809 | void WorldStorage::syncSector(Sector const& sector) { |
| 810 | if (!m_tileArray->sectorValid(sector)) |
| 811 | return; |
| 812 | |
| 813 | auto entityFactory = Root::singleton().entityFactory(); |
| 814 | auto& metadata = m_sectorMetadata[sector]; |
| 815 | |
| 816 | // Only sync the levels that we know are loaded. It is possible that this |
| 817 | // sector is at load level < Entities but has zombie entities in it, but |
| 818 | // storing those without unloading them will lead to duplication. Zombie |
| 819 | // entities will be unloaded in update eventually anyway. |
| 820 | |
| 821 | if (metadata.loadLevel >= SectorLoadLevel::Entities) { |
| 822 | EntitySectorStore sectorStore; |
| 823 | UniqueIndexStore storedUniques; |
| 824 | for (auto const& entity : m_entityMap->entityQuery(RectF(m_tileArray->sectorRegion(sector)))) { |
| 825 | if (!belongsInSector(sector, entity->position())) |
| 826 | continue; |
| 827 | |
| 828 | if (m_generatorFacade->entityPersistent(this, entity)) { |
| 829 | if (auto uniqueId = entity->uniqueId()) |
| 830 | storedUniques.add(*uniqueId, {sector, entity->position()}); |
| 831 | sectorStore.append(entityFactory->storeVersionedEntity(entity)); |
| 832 | } |
| 833 | } |
| 834 | m_db.insert(entitySectorKey(sector), writeEntitySector(sectorStore)); |
| 835 | updateSectorUniques(sector, storedUniques); |
| 836 | } |
| 837 | |
| 838 | if (metadata.loadLevel >= SectorLoadLevel::Tiles) { |
| 839 | TileSectorStore sectorStore; |
| 840 | sectorStore.tiles = m_tileArray->copySector(sector); |
| 841 | sectorStore.generationLevel = metadata.generationLevel; |
| 842 | m_db.insert(tileSectorKey(sector), writeTileSector(sectorStore)); |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | List<WorldStorage::Sector> WorldStorage::adjacentSectors(Sector const& sector) const { |
| 847 | auto tiles = m_tileArray->sectorRegion(sector); |
nothing calls this directly
no test coverage detected