void mapbuffer::save( bool delete_after_save ) { std::stringstream map_directory; map_directory << world_generator->active_world->world_path << "/maps"; assure_dir_exist( map_directory.str().c_str() ); int num_saved_submaps = 0; int num_total_submaps = submap_list.size(); point map_origin = overmapbuffer::sm_to_omt_copy( g->levx, g->levy ); map_origin.x += g->cur_om->pos().x * OMAPX; map_origin.y += g->cur_om->pos().y * OMAPY; // A set of already-saved submaps, in global overmap coordinates. std::set<tripoint, pointcomp> saved_submaps; std::list<tripoint> submaps_to_delete; for( std::map<tripoint, submap *, pointcomp>::iterator it = submaps.begin(); it != submaps.end(); ++it ) { if (num_total_submaps > 100 && num_saved_submaps % 100 == 0) { popup_nowait(_("Please wait as the map saves [%d/%d]"), num_saved_submaps, num_total_submaps); } // Whatever the coordinates of the current submap are, // we're saving a 2x2 quad of submaps at a time. // Submaps are generated in quads, so we know if we have one member of a quad, // we have the rest of it, if that assumtion is broken we have REAL problems. const tripoint om_addr = overmapbuffer::sm_to_omt_copy( it->first ); if( saved_submaps.count( om_addr ) != 0 ) { // Already handled this one. continue; } saved_submaps.insert( om_addr ); // A segment is a chunk of 32x32 submap quads. // We're breaking them into subdirectories so there aren't too many files per directory. // Might want to make a set for this one too so it's only checked once per save(). std::stringstream segment_path; tripoint segment_addr = overmapbuffer::omt_to_seg_copy( om_addr ); segment_path << map_directory.str() << "/" << segment_addr.x << "." << segment_addr.y << "." << segment_addr.z; assure_dir_exist( segment_path.str().c_str() ); std::stringstream quad_path; quad_path << segment_path.str() << "/" << om_addr.x << "." << om_addr.y << "." << om_addr.z << ".map"; // delete_on_save deletes everything, otherwise delete submaps // outside the current map. save_quad( quad_path.str(), om_addr, submaps_to_delete, delete_after_save || om_addr.z != g->levz || om_addr.x < map_origin.x || om_addr.y < map_origin.y || om_addr.x > map_origin.x + (MAPSIZE / 2) || om_addr.y > map_origin.y + (MAPSIZE / 2) ); num_saved_submaps += 4; } for( std::list<tripoint>::iterator it = submaps_to_delete.begin(); it != submaps_to_delete.end(); ++it ) { remove_submap( *it ); } }
void mapbuffer::save( bool delete_after_save ) { std::stringstream map_directory; map_directory << world_generator->active_world->world_path << "/maps"; assure_dir_exist( map_directory.str().c_str() ); int num_saved_submaps = 0; int num_total_submaps = submaps.size(); const tripoint map_origin = overmapbuffer::sm_to_omt_copy( g->m.get_abs_sub() ); const bool map_has_zlevels = g != nullptr && g->m.has_zlevels(); // A set of already-saved submaps, in global overmap coordinates. std::set<tripoint> saved_submaps; std::list<tripoint> submaps_to_delete; for( auto &elem : submaps ) { if (num_total_submaps > 100 && num_saved_submaps % 100 == 0) { popup_nowait(_("Please wait as the map saves [%d/%d]"), num_saved_submaps, num_total_submaps); } // Whatever the coordinates of the current submap are, // we're saving a 2x2 quad of submaps at a time. // Submaps are generated in quads, so we know if we have one member of a quad, // we have the rest of it, if that assumption is broken we have REAL problems. const tripoint om_addr = overmapbuffer::sm_to_omt_copy( elem.first ); if( saved_submaps.count( om_addr ) != 0 ) { // Already handled this one. continue; } saved_submaps.insert( om_addr ); // A segment is a chunk of 32x32 submap quads. // We're breaking them into subdirectories so there aren't too many files per directory. // Might want to make a set for this one too so it's only checked once per save(). std::stringstream dirname; tripoint segment_addr = overmapbuffer::omt_to_seg_copy( om_addr ); dirname << map_directory.str() << "/" << segment_addr.x << "." << segment_addr.y << "." << segment_addr.z; std::stringstream quad_path; quad_path << dirname.str() << "/" << om_addr.x << "." << om_addr.y << "." << om_addr.z << ".map"; // delete_on_save deletes everything, otherwise delete submaps // outside the current map. const bool zlev_del = !map_has_zlevels && om_addr.z != g->get_levz(); save_quad( dirname.str(), quad_path.str(), om_addr, submaps_to_delete, delete_after_save || zlev_del || om_addr.x < map_origin.x || om_addr.y < map_origin.y || om_addr.x > map_origin.x + (MAPSIZE / 2) || om_addr.y > map_origin.y + (MAPSIZE / 2) ); num_saved_submaps += 4; } for( auto &elem : submaps_to_delete ) { remove_submap( elem ); } }