Skip to content

Commit

Permalink
Convert functionality of tinymap::fake_load into its own class.
Browse files Browse the repository at this point in the history
The class takes care of storing the temporary submaps (and deleting them) and it will also not save them into the global mapbuffer.
  • Loading branch information
BevapDin committed Dec 31, 2019
1 parent 45e8aad commit 61dcc4d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 32 deletions.
37 changes: 11 additions & 26 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<submap> sm = std::make_unique<submap>();

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 ) ) {
Expand Down
11 changes: 9 additions & 2 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::unique_ptr<submap>> 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
6 changes: 2 additions & 4 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7282,10 +7282,8 @@ std::pair<std::map<ter_id, int>, std::map<furn_id, int>> 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;
Expand Down

0 comments on commit 61dcc4d

Please sign in to comment.