From 082e97891fc4171f57698174b91b8d4070089dc2 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 10 Feb 2020 02:18:04 +0100 Subject: [PATCH 1/8] Encapsulate ter --- src/lightmap.cpp | 4 ++-- src/map.cpp | 16 +++++++--------- src/submap.h | 5 +++++ src/vehicle.cpp | 4 ++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/lightmap.cpp b/src/lightmap.cpp index 5b4c5c43d4bdc..331ff52ed28eb 100644 --- a/src/lightmap.cpp +++ b/src/lightmap.cpp @@ -106,7 +106,7 @@ bool map::build_transparency_cache( const int zlev ) continue; } - if( !( cur_submap->ter[sx][sy].obj().transparent && + if( !( cur_submap->get_ter( { sx, sy } ).obj().transparent && cur_submap->frn[sx][sy].obj().transparent ) ) { value = LIGHT_TRANSPARENCY_SOLID; zero_value = LIGHT_TRANSPARENCY_SOLID; @@ -322,7 +322,7 @@ void map::generate_lightmap( const int zlev ) add_light_from_items( p, items.begin(), items.end() ); } - const ter_id terrain = cur_submap->ter[sx][sy]; + const ter_id terrain = cur_submap->get_ter( { sx, sy } ); if( terrain->light_emitted > 0 ) { add_light_source( p, terrain->light_emitted ); } diff --git a/src/map.cpp b/src/map.cpp index 4e318104fa85d..c5a41389a62f2 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -6554,12 +6554,11 @@ static void generate_uniform( const tripoint &p, const ter_id &terrain_type ) dbg( D_INFO ) << "generate_uniform p: " << p << " terrain_type: " << terrain_type.id().str(); - constexpr size_t block_size = SEEX * SEEY; for( int xd = 0; xd <= 1; xd++ ) { for( int yd = 0; yd <= 1; yd++ ) { submap *sm = new submap(); sm->is_uniform = true; - std::uninitialized_fill_n( &sm->ter[0][0], block_size, terrain_type ); + sm->set_all_ter( terrain_type ); sm->last_touched = calendar::turn; MAPBUFFER.add_submap( p + point( xd, yd ), sm ); } @@ -7095,21 +7094,21 @@ void map::add_roofs( const tripoint &grid ) for( int x = 0; x < SEEX; x++ ) { for( int y = 0; y < SEEY; y++ ) { - const ter_id ter_here = sub_here->ter[x][y]; + const ter_id ter_here = sub_here->get_ter( { x, y } ); if( ter_here != t_open_air ) { continue; } if( !check_roof ) { // Make sure we don't have open air at lowest z-level - sub_here->ter[x][y] = t_rock_floor; + sub_here->set_ter( { x, y }, t_rock_floor ); continue; } - const ter_t &ter_below = sub_below->ter[x][y].obj(); + const ter_t &ter_below = sub_below->get_ter( { x, y } ).obj(); if( ter_below.roof ) { // TODO: Make roof variable a ter_id to speed this up - sub_here->ter[x][y] = ter_below.roof.id(); + sub_here->set_ter( { x, y }, ter_below.roof.id() ); } } } @@ -7395,7 +7394,7 @@ fake_map::fake_map( const furn_id &fur_type, const ter_id &ter_type, const trap_ for( int gridy = 0; gridy < my_MAPSIZE; gridy++ ) { std::unique_ptr sm = std::make_unique(); - std::uninitialized_fill_n( &sm->ter[0][0], SEEX * SEEY, ter_type ); + sm->set_all_ter( 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 ); @@ -7857,12 +7856,11 @@ void map::draw_fill_background( const ter_id &type ) set_pathfinding_cache_dirty( abs_sub.z ); // Fill each submap rather than each tile - constexpr size_t block_size = SEEX * SEEY; for( int gridx = 0; gridx < my_MAPSIZE; gridx++ ) { for( int gridy = 0; gridy < my_MAPSIZE; gridy++ ) { auto sm = get_submap_at_grid( {gridx, gridy} ); sm->is_uniform = true; - std::uninitialized_fill_n( &sm->ter[0][0], block_size, type ); + sm->set_all_ter( type ); } } } diff --git a/src/submap.h b/src/submap.h index 0a04a39228a24..9c47f3934a0ff 100644 --- a/src/submap.h +++ b/src/submap.h @@ -91,6 +91,11 @@ class submap : public maptile_soa // TODO: Use private inheritanc ter[p.x][p.y] = terr; } + void set_all_ter( const ter_id &terr ) { + constexpr size_t block_size = SEEX * SEEY; + std::uninitialized_fill_n( &ter[0][0], block_size, terr ); + } + int get_radiation( const point &p ) const { return rad[p.x][p.y]; } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index e3af48e641080..9a50c88b276e8 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -6203,7 +6203,7 @@ static bool is_sm_tile_over_water( const tripoint &real_global_pos ) return false; } - return ( sm->ter[px][py].obj().has_flag( TFLAG_CURRENT ) || + return ( sm->get_ter( { px, py } ).obj().has_flag( TFLAG_CURRENT ) || sm->get_furn( { px, py } ).obj().has_flag( TFLAG_CURRENT ) ); } @@ -6224,7 +6224,7 @@ static bool is_sm_tile_outside( const tripoint &real_global_pos ) return false; } - return !( sm->ter[px][py].obj().has_flag( TFLAG_INDOORS ) || + return !( sm->get_ter( { px, py } ).obj().has_flag( TFLAG_INDOORS ) || sm->get_furn( { px, py } ).obj().has_flag( TFLAG_INDOORS ) ); } From 98ac91f437ee8a6973152180aa9c9aad03bd809c Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 10 Feb 2020 02:25:25 +0100 Subject: [PATCH 2/8] Encapsulate frn --- src/lightmap.cpp | 4 ++-- src/map.cpp | 2 +- src/submap.h | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lightmap.cpp b/src/lightmap.cpp index 331ff52ed28eb..32959b21f15e0 100644 --- a/src/lightmap.cpp +++ b/src/lightmap.cpp @@ -107,7 +107,7 @@ bool map::build_transparency_cache( const int zlev ) } if( !( cur_submap->get_ter( { sx, sy } ).obj().transparent && - cur_submap->frn[sx][sy].obj().transparent ) ) { + cur_submap->get_furn( {sx, sy } ).obj().transparent ) ) { value = LIGHT_TRANSPARENCY_SOLID; zero_value = LIGHT_TRANSPARENCY_SOLID; continue; @@ -326,7 +326,7 @@ void map::generate_lightmap( const int zlev ) if( terrain->light_emitted > 0 ) { add_light_source( p, terrain->light_emitted ); } - const furn_id furniture = cur_submap->frn[sx][sy]; + const furn_id furniture = cur_submap->get_furn( {sx, sy } ); if( furniture->light_emitted > 0 ) { add_light_source( p, furniture->light_emitted ); } diff --git a/src/map.cpp b/src/map.cpp index c5a41389a62f2..c022561cfad59 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -7395,7 +7395,7 @@ fake_map::fake_map( const furn_id &fur_type, const ter_id &ter_type, const trap_ std::unique_ptr sm = std::make_unique(); sm->set_all_ter( ter_type ); - std::uninitialized_fill_n( &sm->frn[0][0], SEEX * SEEY, fur_type ); + sm->set_all_furn( fur_type ); std::uninitialized_fill_n( &sm->trp[0][0], SEEX * SEEY, trap_type ); setsubmap( get_nonant( { gridx, gridy, fake_map_z } ), sm.get() ); diff --git a/src/submap.h b/src/submap.h index 9c47f3934a0ff..0ca6dba7bdf7d 100644 --- a/src/submap.h +++ b/src/submap.h @@ -82,6 +82,11 @@ class submap : public maptile_soa // TODO: Use private inheritanc frn[p.x][p.y] = furn; } + void set_all_furn( const furn_id &furn ) { + constexpr size_t block_size = SEEX * SEEY; + std::uninitialized_fill_n( &frn[0][0], block_size, furn ); + } + ter_id get_ter( const point &p ) const { return ter[p.x][p.y]; } From 2f3e33d718af647b5f0c75ba441b039320771536 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 10 Feb 2020 02:42:23 +0100 Subject: [PATCH 3/8] Encapsulate lum --- src/lightmap.cpp | 2 +- src/map.cpp | 2 +- src/submap.h | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lightmap.cpp b/src/lightmap.cpp index 32959b21f15e0..cfb868e350d88 100644 --- a/src/lightmap.cpp +++ b/src/lightmap.cpp @@ -317,7 +317,7 @@ void map::generate_lightmap( const int zlev ) } } - if( cur_submap->lum[sx][sy] && has_items( p ) ) { + if( cur_submap->get_lum( { sx, sy } ) && has_items( p ) ) { auto items = i_at( p ); add_light_from_items( p, items.begin(), items.end() ); } diff --git a/src/map.cpp b/src/map.cpp index c022561cfad59..8d53a52a2e0c2 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -3942,7 +3942,7 @@ void map::i_clear( const tripoint &p ) submaps_with_active_items.erase( tripoint( abs_sub.x + p.x / SEEX, abs_sub.y + p.y / SEEY, p.z ) ); } - current_submap->lum[l.x][l.y] = 0; + current_submap->set_lum( l, 0 ); current_submap->itm[l.x][l.y].clear(); } diff --git a/src/submap.h b/src/submap.h index 0ca6dba7bdf7d..1b4b515ce2461 100644 --- a/src/submap.h +++ b/src/submap.h @@ -110,6 +110,15 @@ class submap : public maptile_soa // TODO: Use private inheritanc rad[p.x][p.y] = radiation; } + uint8_t get_lum( const point &p ) const { + return lum[p.x][p.y]; + } + + void set_lum( const point &p, uint8_t luminance ) { + is_uniform = false; + lum[p.x][p.y] = luminance; + } + void update_lum_add( const point &p, const item &i ) { is_uniform = false; if( i.is_emissive() && lum[p.x][p.y] < 255 ) { From dcd172891261635d2820538182204552103ed813 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 10 Feb 2020 11:47:14 +0100 Subject: [PATCH 4/8] Partially encapsulate itm --- src/map.cpp | 16 ++++++++-------- src/submap.h | 12 ++++++++++-- src/visitable.cpp | 6 +++--- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/map.cpp b/src/map.cpp index 8d53a52a2e0c2..c9b9d06fbce3f 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -3901,7 +3901,7 @@ map_stack map::i_at( const tripoint &p ) point l; submap *const current_submap = get_submap_at( p, l ); - return map_stack{ ¤t_submap->itm[l.x][l.y], p, this }; + return map_stack{ ¤t_submap->get_items( l ), p, this }; } map_stack::iterator map::i_rem( const tripoint &p, map_stack::const_iterator it ) @@ -3917,7 +3917,7 @@ map_stack::iterator map::i_rem( const tripoint &p, map_stack::const_iterator it current_submap->update_lum_rem( l, *it ); - return current_submap->itm[l.x][l.y].erase( it ); + return current_submap->get_items( l ).erase( it ); } void map::i_rem( const tripoint &p, item *it ) @@ -3934,7 +3934,7 @@ void map::i_clear( const tripoint &p ) point l; submap *const current_submap = get_submap_at( p, l ); - for( item &it : current_submap->itm[l.x][l.y] ) { + for( item &it : current_submap->get_items( l ) ) { // remove from the active items cache (if it isn't there does nothing) current_submap->active_items.remove( &it ); } @@ -3943,7 +3943,7 @@ void map::i_clear( const tripoint &p ) } current_submap->set_lum( l, 0 ); - current_submap->itm[l.x][l.y].clear(); + current_submap->get_items( l ).clear(); } item &map::spawn_an_item( const tripoint &p, item new_item, @@ -4171,7 +4171,7 @@ item &map::add_item( const tripoint &p, item new_item ) current_submap->is_uniform = false; current_submap->update_lum_add( l, new_item ); - const map_stack::iterator new_pos = current_submap->itm[l.x][l.y].insert( new_item ); + const map_stack::iterator new_pos = current_submap->get_items( l ).insert( new_item ); if( new_item.needs_processing() ) { if( current_submap->active_items.empty() ) { submaps_with_active_items.insert( tripoint( abs_sub.x + p.x / SEEX, abs_sub.y + p.y / SEEY, p.z ) ); @@ -4233,7 +4233,7 @@ void map::make_active( item_location &loc ) } point l; submap *const current_submap = get_submap_at( loc.position(), l ); - cata::colony &item_stack = current_submap->itm[l.x][l.y]; + cata::colony &item_stack = current_submap->get_items( l ); cata::colony::iterator iter = item_stack.get_iterator_from_pointer( target ); if( current_submap->active_items.empty() ) { @@ -4600,7 +4600,7 @@ bool map::has_items( const tripoint &p ) const point l; submap *const current_submap = get_submap_at( p, l ); - return !current_submap->itm[l.x][l.y].empty(); + return !current_submap->get_items( l ).empty(); } template @@ -7035,7 +7035,7 @@ void map::actualize( const tripoint &grid ) } // plants contain a seed item which must not be removed under any circumstances if( !furn.has_flag( "DONT_REMOVE_ROTTEN" ) ) { - remove_rotten_items( tmpsub->itm[x][y], pnt ); + remove_rotten_items( tmpsub->get_items( { x, y } ), pnt ); } const auto trap_here = tmpsub->get_trap( p ); diff --git a/src/submap.h b/src/submap.h index 1b4b515ce2461..369c2f2b4d412 100644 --- a/src/submap.h +++ b/src/submap.h @@ -149,6 +149,14 @@ class submap : public maptile_soa // TODO: Use private inheritanc } } + cata::colony &get_items( const point &p ) { + return itm[p.x][p.y]; + } + + const cata::colony &get_items( const point &p ) const { + return itm[p.x][p.y]; + } + struct cosmetic_t { point pos; std::string type; @@ -314,12 +322,12 @@ struct maptile { // For map::draw_maptile size_t get_item_count() const { - return sm->itm[x][y].size(); + return sm->get_items( pos() ).size(); } // Assumes there is at least one item const item &get_uppermost_item() const { - return *std::prev( sm->itm[x][y].cend() ); + return *std::prev( sm->get_items( pos() ).cend() ); } }; diff --git a/src/visitable.cpp b/src/visitable.cpp index 607c2589c9dc9..501faf2754cda 100644 --- a/src/visitable.cpp +++ b/src/visitable.cpp @@ -657,9 +657,9 @@ std::list visitable::remove_items_with( const // fetch the appropriate item stack point offset; submap *sub = g->m.get_submap_at( *cur, offset ); + cata::colony &stack = sub->get_items( offset ); - for( auto iter = sub->itm[ offset.x ][ offset.y ].begin(); - iter != sub->itm[ offset.x ][ offset.y ].end(); ) { + for( auto iter = stack.begin(); iter != stack.end(); ) { if( filter( *iter ) ) { // remove from the active items cache (if it isn't there does nothing) sub->active_items.remove( &*iter ); @@ -669,7 +669,7 @@ std::list visitable::remove_items_with( const // finally remove the item res.push_back( *iter ); - iter = sub->itm[ offset.x ][ offset.y ].erase( iter ); + iter = stack.erase( iter ); if( --count == 0 ) { return res; From 1bb530ef979ae05448e7fb6d1bccd93627504593 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 10 Feb 2020 15:45:40 +0100 Subject: [PATCH 5/8] Partially encapsulate fld --- src/lightmap.cpp | 4 ++-- src/map.cpp | 12 ++++++------ src/map_field.cpp | 2 +- src/submap.h | 14 +++++++++++--- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/lightmap.cpp b/src/lightmap.cpp index cfb868e350d88..35621adb8e9d7 100644 --- a/src/lightmap.cpp +++ b/src/lightmap.cpp @@ -126,7 +126,7 @@ bool map::build_transparency_cache( const int zlev ) zero_value = value; continue; } - for( const auto &fld : cur_submap->fld[sx][sy] ) { + for( const auto &fld : cur_submap->get_field( { sx, sy } ) ) { const field_entry &cur = fld.second; if( cur.is_transparent() ) { continue; @@ -331,7 +331,7 @@ void map::generate_lightmap( const int zlev ) add_light_source( p, furniture->light_emitted ); } - for( auto &fld : cur_submap->fld[sx][sy] ) { + for( auto &fld : cur_submap->get_field( { sx, sy } ) ) { const field_entry *cur = &fld.second; const int light_emitted = cur->light_emitted(); if( light_emitted > 0 ) { diff --git a/src/map.cpp b/src/map.cpp index c9b9d06fbce3f..a3aec2162a282 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -2521,7 +2521,7 @@ void map::decay_fields_and_scent( const time_duration &amount ) const int x = sx + smx * SEEX; const int y = sy + smy * SEEY; - field &fields = cur_submap->fld[sx][sy]; + field &fields = cur_submap->get_field( { sx, sy} ); if( !outside_cache[x][y] ) { to_proc -= fields.field_count(); continue; @@ -5118,7 +5118,7 @@ const field &map::field_at( const tripoint &p ) const point l; submap *const current_submap = get_submap_at( p, l ); - return current_submap->fld[l.x][l.y]; + return current_submap->get_field( l ); } /* @@ -5134,7 +5134,7 @@ field &map::field_at( const tripoint &p ) point l; submap *const current_submap = get_submap_at( p, l ); - return current_submap->fld[l.x][l.y]; + return current_submap->get_field( l ); } time_duration map::mod_field_age( const tripoint &p, const field_type_id &type, @@ -5202,7 +5202,7 @@ field_entry *map::get_field( const tripoint &p, const field_type_id &type ) point l; submap *const current_submap = get_submap_at( p, l ); - return current_submap->fld[l.x][l.y].find_field( type ); + return current_submap->get_field( l ).find_field( type ); } bool map::dangerous_field_at( const tripoint &p ) @@ -5239,7 +5239,7 @@ bool map::add_field( const tripoint &p, const field_type_id &type, int intensity submap *const current_submap = get_submap_at( p, l ); current_submap->is_uniform = false; - if( current_submap->fld[l.x][l.y].add_field( type, intensity, age ) ) { + if( current_submap->get_field( l ).add_field( type, intensity, age ) ) { //Only adding it to the count if it doesn't exist. if( !current_submap->field_count++ ) { get_cache( p.z ).field_cache.set( static_cast( p.x / SEEX + ( ( @@ -5276,7 +5276,7 @@ void map::remove_field( const tripoint &p, const field_type_id &field_to_remove point l; submap *const current_submap = get_submap_at( p, l ); - if( current_submap->fld[l.x][l.y].remove_field( field_to_remove ) ) { + if( current_submap->get_field( l ).remove_field( field_to_remove ) ) { // Only adjust the count if the field actually existed. if( !--current_submap->field_count ) { get_cache( p.z ).field_cache.set( static_cast( p.x / SEEX + ( ( diff --git a/src/map_field.cpp b/src/map_field.cpp index 1cd4247eb2e15..a7c5529b087cb 100644 --- a/src/map_field.cpp +++ b/src/map_field.cpp @@ -383,7 +383,7 @@ bool map::process_fields_in_submap( submap *const current_submap, const tripoint &p = thep; // Get a reference to the field variable from the submap; // contains all the pointers to the real field effects. - field &curfield = current_submap->fld[locx][locy]; + field &curfield = current_submap->get_field( { static_cast( locx ), static_cast( locy ) } ); for( auto it = curfield.begin(); it != curfield.end(); ) { // Iterating through all field effects in the submap's field. field_entry &cur = it->second; diff --git a/src/submap.h b/src/submap.h index 369c2f2b4d412..6ccb9ab875f80 100644 --- a/src/submap.h +++ b/src/submap.h @@ -157,6 +157,14 @@ class submap : public maptile_soa // TODO: Use private inheritanc return itm[p.x][p.y]; } + field &get_field( const point &p ) { + return fld[p.x][p.y]; + } + + const field &get_field( const point &p ) const { + return fld[p.x][p.y]; + } + struct cosmetic_t { point pos; std::string type; @@ -283,16 +291,16 @@ struct maptile { } const field &get_field() const { - return sm->fld[x][y]; + return sm->get_field( pos() ); } field_entry *find_field( const field_type_id &field_to_find ) { - return sm->fld[x][y].find_field( field_to_find ); + return sm->get_field( pos() ).find_field( field_to_find ); } bool add_field( const field_type_id &field_to_add, const int new_intensity, const time_duration &new_age ) { - const bool ret = sm->fld[x][y].add_field( field_to_add, new_intensity, new_age ); + const bool ret = sm->get_field( pos() ).add_field( field_to_add, new_intensity, new_age ); if( ret ) { sm->field_count++; } From d93f2631688bf4950dfc5b57a9d7159b8f3bbcef Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 10 Feb 2020 16:41:16 +0100 Subject: [PATCH 6/8] Encapsulate trp --- src/map.cpp | 2 +- src/submap.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/map.cpp b/src/map.cpp index a3aec2162a282..4164e0d4caeb4 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -7396,7 +7396,7 @@ fake_map::fake_map( const furn_id &fur_type, const ter_id &ter_type, const trap_ sm->set_all_ter( ter_type ); sm->set_all_furn( fur_type ); - std::uninitialized_fill_n( &sm->trp[0][0], SEEX * SEEY, trap_type ); + sm->set_all_traps( trap_type ); setsubmap( get_nonant( { gridx, gridy, fake_map_z } ), sm.get() ); diff --git a/src/submap.h b/src/submap.h index 6ccb9ab875f80..03dbbef4bcf40 100644 --- a/src/submap.h +++ b/src/submap.h @@ -73,6 +73,11 @@ class submap : public maptile_soa // TODO: Use private inheritanc trp[p.x][p.y] = trap; } + void set_all_traps( const trap_id &trap ) { + constexpr size_t block_size = SEEX * SEEY; + std::uninitialized_fill_n( &trp[0][0], block_size, trap ); + } + furn_id get_furn( const point &p ) const { return frn[p.x][p.y]; } From a0f97cdb86d0133d9805f0e51ec510a171860bcf Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 10 Feb 2020 17:27:22 +0100 Subject: [PATCH 7/8] Make submap privately inherit from maptile_soa There are still two loose ends on proper encapsulation here. Namely, the non-const get_field() and get_items(). These need to be replaced with either the necessary setters or by moving necessary code to submap. --- src/submap.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/submap.h b/src/submap.h index 03dbbef4bcf40..17d96bd997d52 100644 --- a/src/submap.h +++ b/src/submap.h @@ -59,7 +59,7 @@ struct maptile_soa { void swap_soa_tile( const point &p, maptile_soa<1, 1> &other ); }; -class submap : public maptile_soa // TODO: Use private inheritance. +class submap : maptile_soa { public: submap(); @@ -154,6 +154,7 @@ class submap : public maptile_soa // TODO: Use private inheritanc } } + // TODO: Replace this as it essentially makes itm public cata::colony &get_items( const point &p ) { return itm[p.x][p.y]; } @@ -162,6 +163,7 @@ class submap : public maptile_soa // TODO: Use private inheritanc return itm[p.x][p.y]; } + // TODO: Replace this as it essentially makes fld public field &get_field( const point &p ) { return fld[p.x][p.y]; } From bb27d5ac69548070ca1db8924cf6537b252597d9 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 10 Feb 2020 21:06:25 +0100 Subject: [PATCH 8/8] Use static constexpr in class --- src/submap.cpp | 2 -- src/submap.h | 11 +++++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/submap.cpp b/src/submap.cpp index a58b4626103de..55c6c0b7c0954 100644 --- a/src/submap.cpp +++ b/src/submap.cpp @@ -35,8 +35,6 @@ void maptile_soa::swap_soa_tile( const point &p, maptile_soa<1, 1> &othe submap::submap() { - constexpr size_t elements = SEEX * SEEY; - std::uninitialized_fill_n( &ter[0][0], elements, t_null ); std::uninitialized_fill_n( &frn[0][0], elements, f_null ); std::uninitialized_fill_n( &lum[0][0], elements, 0 ); diff --git a/src/submap.h b/src/submap.h index 17d96bd997d52..8913ced9cc40d 100644 --- a/src/submap.h +++ b/src/submap.h @@ -74,8 +74,7 @@ class submap : maptile_soa } void set_all_traps( const trap_id &trap ) { - constexpr size_t block_size = SEEX * SEEY; - std::uninitialized_fill_n( &trp[0][0], block_size, trap ); + std::uninitialized_fill_n( &trp[0][0], elements, trap ); } furn_id get_furn( const point &p ) const { @@ -88,8 +87,7 @@ class submap : maptile_soa } void set_all_furn( const furn_id &furn ) { - constexpr size_t block_size = SEEX * SEEY; - std::uninitialized_fill_n( &frn[0][0], block_size, furn ); + std::uninitialized_fill_n( &frn[0][0], elements, furn ); } ter_id get_ter( const point &p ) const { @@ -102,8 +100,7 @@ class submap : maptile_soa } void set_all_ter( const ter_id &terr ) { - constexpr size_t block_size = SEEX * SEEY; - std::uninitialized_fill_n( &ter[0][0], block_size, terr ); + std::uninitialized_fill_n( &ter[0][0], elements, terr ); } int get_radiation( const point &p ) const { @@ -251,6 +248,8 @@ class submap : maptile_soa int temperature = 0; void update_legacy_computer(); + + static constexpr size_t elements = SEEX * SEEY; }; /**