Skip to content

Commit

Permalink
Partially encapsulate fld
Browse files Browse the repository at this point in the history
  • Loading branch information
ifreund committed Feb 10, 2020
1 parent dcd1728 commit 1bb530e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ) {
Expand Down
12 changes: 6 additions & 6 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
}

/*
Expand All @@ -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,
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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<size_t>( p.x / SEEX + ( (
Expand Down Expand Up @@ -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<size_t>( p.x / SEEX + ( (
Expand Down
2 changes: 1 addition & 1 deletion src/map_field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>( locx ), static_cast<int>( locy ) } );
for( auto it = curfield.begin(); it != curfield.end(); ) {
// Iterating through all field effects in the submap's field.
field_entry &cur = it->second;
Expand Down
14 changes: 11 additions & 3 deletions src/submap.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ class submap : public maptile_soa<SEEX, SEEY> // 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;
Expand Down Expand Up @@ -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++;
}
Expand Down

0 comments on commit 1bb530e

Please sign in to comment.