Skip to content

Commit

Permalink
Encapsulate ter
Browse files Browse the repository at this point in the history
  • Loading branch information
ifreund committed Feb 10, 2020
1 parent 2073ce1 commit 082e978
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ bool map::build_transparency_cache( const int zlev )
continue;
}

if( !( cur_submap->ter[sx][sy].obj().transparent &&
if( !( cur_submap->get_ter( { sx, sy } ).obj().transparent &&
cur_submap->frn[sx][sy].obj().transparent ) ) {
value = LIGHT_TRANSPARENCY_SOLID;
zero_value = LIGHT_TRANSPARENCY_SOLID;
Expand Down Expand Up @@ -322,7 +322,7 @@ void map::generate_lightmap( const int zlev )
add_light_from_items( p, items.begin(), items.end() );
}

const ter_id terrain = cur_submap->ter[sx][sy];
const ter_id terrain = cur_submap->get_ter( { sx, sy } );
if( terrain->light_emitted > 0 ) {
add_light_source( p, terrain->light_emitted );
}
Expand Down
16 changes: 7 additions & 9 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6554,12 +6554,11 @@ static void generate_uniform( const tripoint &p, const ter_id &terrain_type )
dbg( D_INFO ) << "generate_uniform p: " << p
<< " terrain_type: " << terrain_type.id().str();

constexpr size_t block_size = SEEX * SEEY;
for( int xd = 0; xd <= 1; xd++ ) {
for( int yd = 0; yd <= 1; yd++ ) {
submap *sm = new submap();
sm->is_uniform = true;
std::uninitialized_fill_n( &sm->ter[0][0], block_size, terrain_type );
sm->set_all_ter( terrain_type );
sm->last_touched = calendar::turn;
MAPBUFFER.add_submap( p + point( xd, yd ), sm );
}
Expand Down Expand Up @@ -7095,21 +7094,21 @@ void map::add_roofs( const tripoint &grid )

for( int x = 0; x < SEEX; x++ ) {
for( int y = 0; y < SEEY; y++ ) {
const ter_id ter_here = sub_here->ter[x][y];
const ter_id ter_here = sub_here->get_ter( { x, y } );
if( ter_here != t_open_air ) {
continue;
}

if( !check_roof ) {
// Make sure we don't have open air at lowest z-level
sub_here->ter[x][y] = t_rock_floor;
sub_here->set_ter( { x, y }, t_rock_floor );
continue;
}

const ter_t &ter_below = sub_below->ter[x][y].obj();
const ter_t &ter_below = sub_below->get_ter( { x, y } ).obj();
if( ter_below.roof ) {
// TODO: Make roof variable a ter_id to speed this up
sub_here->ter[x][y] = ter_below.roof.id();
sub_here->set_ter( { x, y }, ter_below.roof.id() );
}
}
}
Expand Down Expand Up @@ -7395,7 +7394,7 @@ fake_map::fake_map( const furn_id &fur_type, const ter_id &ter_type, const trap_
for( int gridy = 0; gridy < my_MAPSIZE; gridy++ ) {
std::unique_ptr<submap> sm = std::make_unique<submap>();

std::uninitialized_fill_n( &sm->ter[0][0], SEEX * SEEY, ter_type );
sm->set_all_ter( 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 );

Expand Down Expand Up @@ -7857,12 +7856,11 @@ void map::draw_fill_background( const ter_id &type )
set_pathfinding_cache_dirty( abs_sub.z );

// Fill each submap rather than each tile
constexpr size_t block_size = SEEX * SEEY;
for( int gridx = 0; gridx < my_MAPSIZE; gridx++ ) {
for( int gridy = 0; gridy < my_MAPSIZE; gridy++ ) {
auto sm = get_submap_at_grid( {gridx, gridy} );
sm->is_uniform = true;
std::uninitialized_fill_n( &sm->ter[0][0], block_size, type );
sm->set_all_ter( type );
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/submap.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ class submap : public maptile_soa<SEEX, SEEY> // TODO: Use private inheritanc
ter[p.x][p.y] = terr;
}

void set_all_ter( const ter_id &terr ) {
constexpr size_t block_size = SEEX * SEEY;
std::uninitialized_fill_n( &ter[0][0], block_size, terr );
}

int get_radiation( const point &p ) const {
return rad[p.x][p.y];
}
Expand Down
4 changes: 2 additions & 2 deletions src/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6203,7 +6203,7 @@ static bool is_sm_tile_over_water( const tripoint &real_global_pos )
return false;
}

return ( sm->ter[px][py].obj().has_flag( TFLAG_CURRENT ) ||
return ( sm->get_ter( { px, py } ).obj().has_flag( TFLAG_CURRENT ) ||
sm->get_furn( { px, py } ).obj().has_flag( TFLAG_CURRENT ) );
}

Expand All @@ -6224,7 +6224,7 @@ static bool is_sm_tile_outside( const tripoint &real_global_pos )
return false;
}

return !( sm->ter[px][py].obj().has_flag( TFLAG_INDOORS ) ||
return !( sm->get_ter( { px, py } ).obj().has_flag( TFLAG_INDOORS ) ||
sm->get_furn( { px, py } ).obj().has_flag( TFLAG_INDOORS ) );
}

Expand Down

0 comments on commit 082e978

Please sign in to comment.