From 78fbf61f365c13194c8a3346b779c1a9b02cbdce Mon Sep 17 00:00:00 2001 From: BevapDin Date: Tue, 31 Dec 2019 01:31:08 +0100 Subject: [PATCH 1/3] Remove pointless check before adding to values of map. If the key does not exist in the map, it is added its value is automatically initialized anyway. --- src/mapgen.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/mapgen.cpp b/src/mapgen.cpp index eb641e5de8e18..accc8dd96b2d8 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -7300,16 +7300,10 @@ std::pair, std::map> get_changed_ids_from_up tripoint_fake_map_edge ) ) { 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; } } From 45e8aadec312732f9cc6e26979de53ca68f21e5f Mon Sep 17 00:00:00 2001 From: BevapDin Date: Tue, 31 Dec 2019 01:32:08 +0100 Subject: [PATCH 2/3] Iterate via map::points_on_zlevel Much simpler and does not need magic values. fixup iterationg --- src/mapgen.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/mapgen.cpp b/src/mapgen.cpp index accc8dd96b2d8..179ba8ed95cfb 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; @@ -7296,8 +7294,7 @@ 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 ) { terrains[ter_at_pos] += 1; From 61dcc4d0d0595f06c7c9f35cb589c49c48f33139 Mon Sep 17 00:00:00 2001 From: BevapDin Date: Tue, 31 Dec 2019 01:33:42 +0100 Subject: [PATCH 3/3] Convert functionality of tinymap::fake_load into its own class. The class takes care of storing the temporary submaps (and deleting them) and it will also not save them into the global mapbuffer. --- src/map.cpp | 37 +++++++++++-------------------------- src/map.h | 11 +++++++++-- src/mapgen.cpp | 6 ++---- 3 files changed, 22 insertions(+), 32 deletions(-) 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 179ba8ed95cfb..4eb206c519909 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -7282,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;