diff --git a/src/map.cpp b/src/map.cpp index 3ed741cfb49b3..76760fb5b6057 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -7332,44 +7332,29 @@ bool tinymap::inbounds( const tripoint &p ) const // set up a map just long enough scribble on it // this tinymap should never, ever get saved -bool tinymap::fake_load( const furn_id &fur_type, const ter_id &ter_type, const trap_id &trap_type, - int fake_map_z ) +fake_map::fake_map( const furn_id &fur_type, const ter_id &ter_type, const trap_id &trap_type, + const int fake_map_z ) { const tripoint tripoint_below_zero( 0, 0, fake_map_z ); - bool do_terset = true; set_abs_sub( tripoint_below_zero ); for( int gridx = 0; gridx < my_MAPSIZE; gridx++ ) { for( int gridy = 0; gridy < my_MAPSIZE; gridy++ ) { - const tripoint gridp( gridx, gridy, fake_map_z ); - submap *tmpsub = MAPBUFFER.lookup_submap( gridp ); - if( tmpsub == nullptr ) { - generate_uniform( gridp, ter_type ); - do_terset = false; - tmpsub = MAPBUFFER.lookup_submap( gridp ); - if( tmpsub == nullptr ) { - dbg( D_ERROR ) << "failed to generate a fake submap at 0,0,-9 "; - debugmsg( "failed to generate a fake submap at 0,0,-9" ); - return false; - } - } - const size_t gridn = get_nonant( gridp ); + std::unique_ptr sm = std::make_unique(); - setsubmap( gridn, tmpsub ); - } - } + std::uninitialized_fill_n( &sm->ter[0][0], SEEX * SEEY, ter_type ); + std::uninitialized_fill_n( &sm->frn[0][0], SEEX * SEEY, fur_type ); + std::uninitialized_fill_n( &sm->trp[0][0], SEEX * SEEY, trap_type ); + + setsubmap( get_nonant( { gridx, gridy, fake_map_z } ), sm.get() ); - for( const tripoint &pos : points_in_rectangle( tripoint_below_zero, - tripoint( MAPSIZE * SEEX, MAPSIZE * SEEY, fake_map_z ) ) ) { - if( do_terset ) { - ter_set( pos, ter_type ); + temp_submaps_.emplace_back( std::move( sm ) ); } - furn_set( pos, fur_type ); - trap_set( pos, trap_type ); } - return true; } +fake_map::~fake_map() = default; + void map::set_graffiti( const tripoint &p, const std::string &contents ) { if( !inbounds( p ) ) { diff --git a/src/map.h b/src/map.h index 65a89eb8d3c65..ba5ab3e96b3f9 100644 --- a/src/map.h +++ b/src/map.h @@ -1834,8 +1834,15 @@ class tinymap : public map public: tinymap( int mapsize = 2, bool zlevels = false ); bool inbounds( const tripoint &p ) const override; - bool fake_load( const furn_id &fur_type, const ter_id &ter_type, const trap_id &trap_type, - int fake_map_z ); }; +class fake_map : public tinymap +{ + private: + std::vector> temp_submaps_; + public: + fake_map( const furn_id &fur_type, const ter_id &ter_type, const trap_id &trap_type, + int fake_map_z ); + ~fake_map(); +}; #endif diff --git a/src/mapgen.cpp b/src/mapgen.cpp index eb641e5de8e18..4eb206c519909 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -7272,8 +7272,6 @@ std::pair, std::map> get_changed_ids_from_up const std::string &update_mapgen_id ) { const int fake_map_z = -9; - const tripoint tripoint_below_zero( 0, 0, fake_map_z ); - const tripoint tripoint_fake_map_edge( 23, 23, fake_map_z ); std::map terrains; std::map furnitures; @@ -7284,10 +7282,8 @@ std::pair, std::map> get_changed_ids_from_up return std::make_pair( terrains, furnitures ); } - tinymap fake_map; - if( !fake_map.fake_load( f_null, t_dirt, tr_null, fake_map_z ) ) { - return std::make_pair( terrains, furnitures ); - } + ::fake_map fake_map( f_null, t_dirt, tr_null, fake_map_z ); + oter_id any = oter_id( "field" ); // just need a variable here, it doesn't need to be valid const regional_settings dummy_settings; @@ -7296,20 +7292,13 @@ std::pair, std::map> get_changed_ids_from_up any, any, 0, dummy_settings, fake_map, any, 0.0f, calendar::turn, nullptr ); if( update_function->second[0]->update_map( fake_md ) ) { - for( const tripoint &pos : fake_map.points_in_rectangle( tripoint_below_zero, - tripoint_fake_map_edge ) ) { + for( const tripoint &pos : fake_map.points_on_zlevel( fake_map_z ) ) { ter_id ter_at_pos = fake_map.ter( pos ); if( ter_at_pos != t_dirt ) { - if( terrains.find( ter_at_pos ) == terrains.end() ) { - terrains[ter_at_pos] = 0; - } terrains[ter_at_pos] += 1; } if( fake_map.has_furn( pos ) ) { furn_id furn_at_pos = fake_map.furn( pos ); - if( furnitures.find( furn_at_pos ) == furnitures.end() ) { - furnitures[furn_at_pos] = 0; - } furnitures[furn_at_pos] += 1; } }