Skip to content

Commit

Permalink
Merge pull request #36582 from BevapDin/bpi
Browse files Browse the repository at this point in the history
Fix mysterious creation of submap (0,0,-9).
kevingranade authored Dec 31, 2019
2 parents 93d8a1d + 61dcc4d commit 02408f0
Showing 3 changed files with 23 additions and 42 deletions.
37 changes: 11 additions & 26 deletions src/map.cpp
Original file line number Diff line number Diff line change
@@ -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 ) ) {
11 changes: 9 additions & 2 deletions src/map.h
Original file line number Diff line number Diff line change
@@ -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
17 changes: 3 additions & 14 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
@@ -7272,8 +7272,6 @@ std::pair<std::map<ter_id, int>, std::map<furn_id, int>> get_changed_ids_from_up
const std::string &update_mapgen_id )
{
const int fake_map_z = -9;
const tripoint tripoint_below_zero( 0, 0, fake_map_z );
const tripoint tripoint_fake_map_edge( 23, 23, fake_map_z );

std::map<ter_id, int> terrains;
std::map<furn_id, int> furnitures;
@@ -7284,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;
@@ -7296,20 +7292,13 @@ std::pair<std::map<ter_id, int>, std::map<furn_id, int>> get_changed_ids_from_up
any, any, 0, dummy_settings, fake_map, any, 0.0f, calendar::turn, nullptr );

if( update_function->second[0]->update_map( fake_md ) ) {
for( const tripoint &pos : fake_map.points_in_rectangle( tripoint_below_zero,
tripoint_fake_map_edge ) ) {
for( const tripoint &pos : fake_map.points_on_zlevel( fake_map_z ) ) {
ter_id ter_at_pos = fake_map.ter( pos );
if( ter_at_pos != t_dirt ) {
if( terrains.find( ter_at_pos ) == terrains.end() ) {
terrains[ter_at_pos] = 0;
}
terrains[ter_at_pos] += 1;
}
if( fake_map.has_furn( pos ) ) {
furn_id furn_at_pos = fake_map.furn( pos );
if( furnitures.find( furn_at_pos ) == furnitures.end() ) {
furnitures[furn_at_pos] = 0;
}
furnitures[furn_at_pos] += 1;
}
}

0 comments on commit 02408f0

Please sign in to comment.