Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move colony to cata namespace and add documentation #31659

Merged
merged 2 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
293 changes: 273 additions & 20 deletions src/colony.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/item_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ item_stack::iterator item_stack::get_iterator_from_index( size_t idx )
return items->get_iterator_from_index( idx );
}

size_t item_stack::get_index_from_iterator( const const_iterator &it )
size_t item_stack::get_index_from_iterator( const item_stack::const_iterator &it )
{
return items->get_index_from_iterator( it );
}
Expand Down
14 changes: 7 additions & 7 deletions src/item_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
// A wrapper class to bundle up the references needed for a caller to safely manipulate
// items and obtain information about items at a particular map x/y location.
// Note this does not expose the container itself,
// which means you cannot call e.g. colony::erase() directly.
// which means you cannot call e.g. cata::colony::erase() directly.

// Pure virtual base class for a collection of items with origin information.
// Only a subset of the functionality is callable without casting to the specific
// subclass, e.g. not begin()/end() or range loops.
class item_stack
{
protected:
colony<item> *items;
cata::colony<item> *items;

public:
using iterator = colony<item>::iterator;
using const_iterator = colony<item>::const_iterator;
using reverse_iterator = colony<item>::reverse_iterator;
using const_reverse_iterator = colony<item>::const_reverse_iterator;
using iterator = cata::colony<item>::iterator;
using const_iterator = cata::colony<item>::const_iterator;
using reverse_iterator = cata::colony<item>::reverse_iterator;
using const_reverse_iterator = cata::colony<item>::const_reverse_iterator;

item_stack( colony<item> *items ) : items( items ) { }
item_stack( cata::colony<item> *items ) : items( items ) { }

size_t size() const;
bool empty() const;
Expand Down
4 changes: 2 additions & 2 deletions src/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ class JsonIn
// special case for colony as it uses `insert()` instead of `push_back()`
// and therefore doesn't fit with vector/deque/list
template <typename T>
bool read( colony<T> &v ) {
bool read( cata::colony<T> &v ) {
if( !test_array() ) {
return false;
}
Expand Down Expand Up @@ -590,7 +590,7 @@ class JsonOut

// special case for colony, since it doesn't fit in other categories
template <typename T>
void write( const colony<T> &container ) {
void write( const cata::colony<T> &container ) {
write_as_array( container );
}

Expand Down
10 changes: 5 additions & 5 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ const efftype_id effect_stunned( "stunned" );

#define dbg(x) DebugLog((x),D_MAP) << __FILE__ << ":" << __LINE__ << ": "

static colony<item> nulitems; // Returned when &i_at() is asked for an OOB value
static field nulfield; // Returned when &field_at() is asked for an OOB value
static level_cache nullcache; // Dummy cache for z-levels outside bounds
static cata::colony<item> nulitems; // Returned when &i_at() is asked for an OOB value
static field nulfield; // Returned when &field_at() is asked for an OOB value
static level_cache nullcache; // Dummy cache for z-levels outside bounds

// Map stack methods.
map_stack::iterator map_stack::erase( map_stack::const_iterator it )
Expand Down Expand Up @@ -4438,8 +4438,8 @@ void map::make_active( item_location &loc )
}
point l;
submap *const current_submap = get_submap_at( loc.position(), l );
colony<item> &item_stack = current_submap->itm[l.x][l.y];
colony<item>::iterator iter = item_stack.get_iterator_from_pointer( target );
cata::colony<item> &item_stack = current_submap->itm[l.x][l.y];
cata::colony<item>::iterator iter = item_stack.get_iterator_from_pointer( target );

if( current_submap->active_items.empty() ) {
submaps_with_active_items.insert( abs_sub + tripoint( loc.position().x / SEEX,
Expand Down
2 changes: 1 addition & 1 deletion src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class map_stack : public item_stack
tripoint location;
map *myorigin;
public:
map_stack( colony<item> *newstack, tripoint newloc, map *neworigin ) :
map_stack( cata::colony<item> *newstack, tripoint newloc, map *neworigin ) :
item_stack( newstack ), location( newloc ), myorigin( neworigin ) {}
void insert( const item &newitem ) override;
iterator erase( const_iterator it ) override;
Expand Down
2 changes: 1 addition & 1 deletion src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3493,7 +3493,7 @@ void submap::load( JsonIn &jsin, const std::string &member_name, bool rubpow_upd
return VisitResponse::NEXT;
} );

const colony<item>::iterator it = itm[p.x][p.y].insert( tmp );
const cata::colony<item>::iterator it = itm[p.x][p.y].insert( tmp );
if( tmp.needs_processing() ) {
active_items.add( it, p );
}
Expand Down
14 changes: 7 additions & 7 deletions src/submap.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ struct spawn_point {

template<int sx, int sy>
struct maptile_soa {
ter_id ter[sx][sy]; // Terrain on each square
furn_id frn[sx][sy]; // Furniture on each square
std::uint8_t lum[sx][sy]; // Number of items emitting light on each square
colony<item> itm[sx][sy]; // Items on each square
field fld[sx][sy]; // Field on each square
trap_id trp[sx][sy]; // Trap on each square
int rad[sx][sy]; // Irradiation of each square
ter_id ter[sx][sy]; // Terrain on each square
furn_id frn[sx][sy]; // Furniture on each square
std::uint8_t lum[sx][sy]; // Number of items emitting light on each square
cata::colony<item> itm[sx][sy]; // Items on each square
field fld[sx][sy]; // Field on each square
trap_id trp[sx][sy]; // Trap on each square
int rad[sx][sy]; // Irradiation of each square

void swap_soa_tile( const point &p1, const point &p2 );
void swap_soa_tile( const point &p, maptile_soa<1, 1> &other );
Expand Down
6 changes: 3 additions & 3 deletions src/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4445,8 +4445,8 @@ cata::optional<vehicle_stack::iterator> vehicle::add_item( int part, const item

bool vehicle::remove_item( int part, item *it )
{
const colony<item> &veh_items = parts[part].items;
const colony<item>::const_iterator iter = veh_items.get_iterator_from_pointer( it );
const cata::colony<item> &veh_items = parts[part].items;
const cata::colony<item>::const_iterator iter = veh_items.get_iterator_from_pointer( it );
if( iter == veh_items.end() ) {
return false;
}
Expand All @@ -4456,7 +4456,7 @@ bool vehicle::remove_item( int part, item *it )

vehicle_stack::iterator vehicle::remove_item( int part, vehicle_stack::const_iterator it )
{
colony<item> &veh_items = parts[part].items;
cata::colony<item> &veh_items = parts[part].items;

if( active_items.has( it, parts[part].mount ) ) {
active_items.remove( it, parts[part].mount );
Expand Down
4 changes: 2 additions & 2 deletions src/vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class vehicle_stack : public item_stack
vehicle *myorigin;
int part_num;
public:
vehicle_stack( colony<item> *newstack, point newloc, vehicle *neworigin, int part ) :
vehicle_stack( cata::colony<item> *newstack, point newloc, vehicle *neworigin, int part ) :
item_stack( newstack ), location( newloc ), myorigin( neworigin ), part_num( part ) {}
iterator erase( const_iterator it ) override;
void insert( const item &newitem ) override;
Expand Down Expand Up @@ -383,7 +383,7 @@ struct vehicle_part {
mutable const vpart_info *info_cache = nullptr;

item base;
colony<item> items; // inventory
cata::colony<item> items; // inventory

/** Preferred ammo type when multiple are available */
itype_id ammo_pref = "null";
Expand Down
Loading