Skip to content

Commit

Permalink
Partially encapsulate itm
Browse files Browse the repository at this point in the history
  • Loading branch information
ifreund committed Feb 10, 2020
1 parent 2f3e33d commit dcd1728
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
16 changes: 8 additions & 8 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{ &current_submap->itm[l.x][l.y], p, this };
return map_stack{ &current_submap->get_items( l ), p, this };
}

map_stack::iterator map::i_rem( const tripoint &p, map_stack::const_iterator it )
Expand All @@ -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 )
Expand All @@ -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 );
}
Expand All @@ -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,
Expand Down Expand Up @@ -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 ) );
Expand Down Expand Up @@ -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> &item_stack = current_submap->itm[l.x][l.y];
cata::colony<item> &item_stack = current_submap->get_items( l );
cata::colony<item>::iterator iter = item_stack.get_iterator_from_pointer( target );

if( current_submap->active_items.empty() ) {
Expand Down Expand Up @@ -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 <typename Stack>
Expand Down Expand Up @@ -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 );
Expand Down
12 changes: 10 additions & 2 deletions src/submap.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ class submap : public maptile_soa<SEEX, SEEY> // TODO: Use private inheritanc
}
}

cata::colony<item> &get_items( const point &p ) {
return itm[p.x][p.y];
}

const cata::colony<item> &get_items( const point &p ) const {
return itm[p.x][p.y];
}

struct cosmetic_t {
point pos;
std::string type;
Expand Down Expand Up @@ -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() );
}
};

Expand Down
6 changes: 3 additions & 3 deletions src/visitable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,9 +657,9 @@ std::list<item> visitable<map_cursor>::remove_items_with( const
// fetch the appropriate item stack
point offset;
submap *sub = g->m.get_submap_at( *cur, offset );
cata::colony<item> &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 );
Expand All @@ -669,7 +669,7 @@ std::list<item> visitable<map_cursor>::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;
Expand Down

0 comments on commit dcd1728

Please sign in to comment.