Skip to content

Commit

Permalink
Merge pull request #51193 from ZhilkinSerg/perf-terrain-bitset-flags
Browse files Browse the repository at this point in the history
Use ter_bitflags instead of flag strings
  • Loading branch information
kevingranade authored Aug 29, 2021
2 parents ba0c50d + ab2e056 commit 83b4e06
Show file tree
Hide file tree
Showing 40 changed files with 238 additions and 250 deletions.
9 changes: 3 additions & 6 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ static const quality_id qual_BUTCHER( "BUTCHER" );
static const quality_id qual_CUT_FINE( "CUT_FINE" );

static const std::string flag_CONSOLE( "CONSOLE" );
static const std::string flag_GOES_DOWN( "GOES_DOWN" );
static const std::string flag_GOES_UP( "GOES_UP" );
static const std::string flag_SWIMMABLE( "SWIMMABLE" );

static void parse_keymap( std::istream &keymap_txt, std::map<char, action_id> &kmap,
std::set<action_id> &unbound_keymap );
Expand Down Expand Up @@ -624,7 +621,7 @@ bool can_move_vertical_at( const tripoint &p, int movez )
Character &player_character = get_player_character();
map &here = get_map();
// TODO: unify this with game::move_vertical
if( here.has_flag( flag_SWIMMABLE, p ) && here.has_flag( TFLAG_DEEP_WATER, p ) ) {
if( here.has_flag( TFLAG_SWIMMABLE, p ) && here.has_flag( TFLAG_DEEP_WATER, p ) ) {
if( movez == -1 ) {
return !player_character.is_underwater() && !player_character.worn_with_flag( flag_FLOTATION );
} else {
Expand All @@ -634,9 +631,9 @@ bool can_move_vertical_at( const tripoint &p, int movez )
}

if( movez == -1 ) {
return here.has_flag( flag_GOES_DOWN, p );
return here.has_flag( TFLAG_GOES_DOWN, p );
} else {
return here.has_flag( flag_GOES_UP, p );
return here.has_flag( TFLAG_GOES_UP, p );
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ static const trait_id trait_STOCKY_TROGLO( "STOCKY_TROGLO" );
static const std::string flag_AUTODOC( "AUTODOC" );
static const std::string flag_AUTODOC_COUCH( "AUTODOC_COUCH" );
static const std::string flag_PLANTABLE( "PLANTABLE" );
static const std::string flag_SUPPORTS_ROOF( "SUPPORTS_ROOF" );

using namespace activity_handlers;

Expand Down Expand Up @@ -1782,7 +1781,7 @@ void activity_handlers::pickaxe_finish( player_activity *act, Character *you )
act->set_to_null();
if( you->is_avatar() ) {
const int helpersize = get_player_character().get_num_crafting_helpers( 3 );
if( here.is_bashable( pos ) && here.has_flag( flag_SUPPORTS_ROOF, pos ) &&
if( here.is_bashable( pos ) && here.has_flag( TFLAG_SUPPORTS_ROOF, pos ) &&
here.ter( pos ) != t_tree ) {
// Tunneling through solid rock is sweaty, backbreaking work
// Betcha wish you'd opted for the J-Hammer
Expand Down
4 changes: 2 additions & 2 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ static activity_reason_info can_do_activity_there( const activity_id &act, Chara
return activity_reason_info::fail( do_activity_reason::NO_ZONE );
}
if( act == ACT_MULTIPLE_MINE ) {
if( !here.has_flag( "MINEABLE", src_loc ) ) {
if( !here.has_flag( TFLAG_MINEABLE, src_loc ) ) {
return activity_reason_info::fail( do_activity_reason::NO_ZONE );
}
std::vector<item *> mining_inv = you.items_with( [&you]( const item & itm ) {
Expand Down Expand Up @@ -2174,7 +2174,7 @@ static bool mine_activity( Character &you, const tripoint &src_loc )
} );
map &here = get_map();
if( mining_inv.empty() || you.is_mounted() || you.is_underwater() || here.veh_at( src_loc ) ||
!here.has_flag( "MINEABLE", src_loc ) || you.has_effect( effect_incorporeal ) ) {
!here.has_flag( TFLAG_MINEABLE, src_loc ) || you.has_effect( effect_incorporeal ) ) {
return false;
}
item *chosen_item = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1784,7 +1784,7 @@ void avatar::try_to_sleep( const time_duration &dur )
}
} else if( has_trait( trait_M_SKIN3 ) ) {
fungaloid_cosplay = true;
if( here.has_flag_ter_or_furn( "FUNGUS", pos() ) ) {
if( here.has_flag_ter_or_furn( TFLAG_FUNGUS, pos() ) ) {
add_msg_if_player( m_good,
_( "Our fibers meld with the ground beneath us. The gills on our neck begin to seed the air with spores as our awareness fades." ) );
}
Expand Down Expand Up @@ -1831,7 +1831,7 @@ void avatar::try_to_sleep( const time_duration &dur )
add_msg_if_player( m_good,
_( "You lay beneath the waves' embrace, gazing up through the water's surface…" ) );
watersleep = true;
} else if( here.has_flag_ter( "SWIMMABLE", pos() ) ) {
} else if( here.has_flag_ter( TFLAG_SWIMMABLE, pos() ) ) {
add_msg_if_player( m_good, _( "You settle into the water and begin to drowse…" ) );
watersleep = true;
}
Expand Down
7 changes: 3 additions & 4 deletions src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ static const trait_id trait_RUMINANT( "RUMINANT" );
static const trait_id trait_SHELL2( "SHELL2" );

static const std::string flag_RAMP_END( "RAMP_END" );
static const std::string flag_SWIMMABLE( "SWIMMABLE" );

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

Expand Down Expand Up @@ -402,9 +401,9 @@ bool avatar_action::move( avatar &you, map &m, const tripoint &d )
return false;
}
}
bool toSwimmable = m.has_flag( flag_SWIMMABLE, dest_loc );
bool toSwimmable = m.has_flag( TFLAG_SWIMMABLE, dest_loc );
bool toDeepWater = m.has_flag( TFLAG_DEEP_WATER, dest_loc );
bool fromSwimmable = m.has_flag( flag_SWIMMABLE, you.pos() );
bool fromSwimmable = m.has_flag( TFLAG_SWIMMABLE, you.pos() );
bool fromDeepWater = m.has_flag( TFLAG_DEEP_WATER, you.pos() );
bool fromBoat = veh0 != nullptr && veh0->is_in_water( fromDeepWater );
bool toBoat = veh1 != nullptr && veh1->is_in_water( toDeepWater );
Expand Down Expand Up @@ -573,7 +572,7 @@ bool avatar_action::ramp_move( avatar &you, map &m, const tripoint &dest_loc )

void avatar_action::swim( map &m, avatar &you, const tripoint &p )
{
if( !m.has_flag( flag_SWIMMABLE, p ) ) {
if( !m.has_flag( TFLAG_SWIMMABLE, p ) ) {
dbg( D_ERROR ) << "game:plswim: Tried to swim in "
<< m.tername( p ) << "!";
debugmsg( "Tried to swim in %s!", m.tername( p ) );
Expand Down
4 changes: 1 addition & 3 deletions src/ballistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ static const efftype_id effect_bounced( "bounced" );

static const json_character_flag json_flag_HARDTOHIT( "HARDTOHIT" );

static const std::string flag_LIQUID( "LIQUID" );

static void drop_or_embed_projectile( const dealt_projectile_attack &attack )
{
const auto &proj = attack.proj;
Expand Down Expand Up @@ -143,7 +141,7 @@ static void drop_or_embed_projectile( const dealt_projectile_attack &attack )
}

if( effects.count( "HEAVY_HIT" ) ) {
if( here.has_flag( flag_LIQUID, pt ) ) {
if( here.has_flag( TFLAG_LIQUID, pt ) ) {
sounds::sound( pt, 10, sounds::sound_t::combat, _( "splash!" ), false, "bullet_hit", "hit_water" );
} else {
sounds::sound( pt, 8, sounds::sound_t::combat, _( "thud." ), false, "bullet_hit", "hit_wall" );
Expand Down
4 changes: 1 addition & 3 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ static const json_character_flag json_flag_BIONIC_NPC_USABLE( "BIONIC_NPC_USABLE
static const json_character_flag json_flag_BIONIC_WEAPON( "BIONIC_WEAPON" );
static const json_character_flag json_flag_BIONIC_TOGGLED( "BIONIC_TOGGLED" );

static const std::string flag_SEALED( "SEALED" );

struct Character::auto_toggle_bionic_result {
bool can_burn_fuel = false;
bool has_burnable_fuel = false;
Expand Down Expand Up @@ -945,7 +943,7 @@ bool Character::activate_bionic( int b, bool eff_only, bool *close_bionics_ui )
std::vector<std::pair<item, tripoint>> affected;
const units::mass weight_cap = weight_capacity();
for( const tripoint &p : here.points_in_radius( pos(), 10 ) ) {
if( p == pos() || !here.has_items( p ) || here.has_flag( flag_SEALED, p ) ) {
if( p == pos() || !here.has_items( p ) || here.has_flag( TFLAG_SEALED, p ) ) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3909,7 +3909,7 @@ void cata_tiles::get_tile_values_with_ter( const tripoint &p, const int t, const
if( val == 0 ) {
for( int i = 0; i < 4; ++i ) {
const tripoint &pt = p + four_adjacent_offsets[i];
if( here.has_flag( "WALL", pt ) || here.has_flag( "WINDOW", pt ) ||
if( here.has_flag( TFLAG_WALL, pt ) || here.has_flag( "WINDOW", pt ) ||
here.has_flag( "DOOR", pt ) ) {
val += 1 << i;
}
Expand Down
20 changes: 10 additions & 10 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5116,7 +5116,7 @@ bool Character::in_climate_control()
return true;
}
map &here = get_map();
if( has_trait( trait_M_SKIN3 ) && here.has_flag_ter_or_furn( "FUNGUS", pos() ) &&
if( has_trait( trait_M_SKIN3 ) && here.has_flag_ter_or_furn( TFLAG_FUNGUS, pos() ) &&
in_sleep_state() ) {
return true;
}
Expand Down Expand Up @@ -5857,7 +5857,7 @@ bool Character::is_deaf() const
{
return get_effect_int( effect_deaf ) > 2 || worn_with_flag( flag_DEAF ) ||
has_flag( json_flag_DEAF ) ||
( has_trait( trait_M_SKIN3 ) && get_map().has_flag_ter_or_furn( "FUNGUS", pos() )
( has_trait( trait_M_SKIN3 ) && get_map().has_flag_ter_or_furn( TFLAG_FUNGUS, pos() )
&& in_sleep_state() );
}

Expand Down Expand Up @@ -7675,8 +7675,8 @@ Character::comfort_response_t Character::base_comfort_value( const tripoint &p )
}
}
}
if( ( fungaloid_cosplay && here.has_flag_ter_or_furn( "FUNGUS", pos() ) ) ||
( watersleep && here.has_flag_ter( "SWIMMABLE", pos() ) ) ) {
if( ( fungaloid_cosplay && here.has_flag_ter_or_furn( TFLAG_FUNGUS, pos() ) ) ||
( watersleep && here.has_flag_ter( TFLAG_SWIMMABLE, pos() ) ) ) {
comfort += static_cast<int>( comfort_level::very_comfortable );
}
} else if( plantsleep ) {
Expand Down Expand Up @@ -12666,7 +12666,7 @@ int Character::run_cost( int base_cost, bool diag ) const
map &here = get_map();
// The "FLAT" tag includes soft surfaces, so not a good fit.
const bool on_road = flatground && here.has_flag( STATIC( "ROAD" ), pos() );
const bool on_fungus = here.has_flag_ter_or_furn( STATIC( "FUNGUS" ), pos() );
const bool on_fungus = here.has_flag_ter_or_furn( TFLAG_FUNGUS, pos() );

if( !is_mounted() ) {
if( movecost > 105 ) {
Expand Down Expand Up @@ -12741,7 +12741,7 @@ int Character::run_cost( int base_cost, bool diag ) const
movecost += 8;
}

if( has_trait( trait_ROOTS3 ) && here.has_flag( STATIC( "DIGGABLE" ), pos() ) ) {
if( has_trait( trait_ROOTS3 ) && here.has_flag( TFLAG_DIGGABLE, pos() ) ) {
movecost += 10 * footwear_factor();
}

Expand Down Expand Up @@ -12864,7 +12864,7 @@ std::vector<Creature *> Character::get_targetable_creatures( const int range, bo
for( const tripoint &point : path ) {
if( here.impassable( point ) &&
!( weapon.has_flag( flag_SPEAR ) && // Fences etc. Spears can stab through those
here.has_flag( STATIC( "THIN_OBSTACLE" ),
here.has_flag( TFLAG_THIN_OBSTACLE,
point ) ) ) { //this mirrors melee.cpp function reach_attack
can_see = false;
break;
Expand Down Expand Up @@ -13291,7 +13291,7 @@ int Character::sleep_spot( const tripoint &p ) const

sleepy = enchantment_cache->modify_value( enchant_vals::mod::SLEEPY, sleepy );

if( watersleep && get_map().has_flag_ter( "SWIMMABLE", pos() ) ) {
if( watersleep && get_map().has_flag_ter( TFLAG_SWIMMABLE, pos() ) ) {
sleepy += 10; //comfy water!
}

Expand Down Expand Up @@ -14818,7 +14818,7 @@ void Character::knock_back_to( const tripoint &to )

map &here = get_map();
// If we're still in the function at this point, we're actually moving a tile!
if( here.has_flag( "LIQUID", to ) && here.has_flag( TFLAG_DEEP_WATER, to ) ) {
if( here.has_flag( TFLAG_LIQUID, to ) && here.has_flag( TFLAG_DEEP_WATER, to ) ) {
if( !is_npc() ) {
avatar_action::swim( here, get_avatar(), to );
}
Expand Down Expand Up @@ -15678,7 +15678,7 @@ void Character::pause()
body_part_hand_r
}
}, true );
} else if( here.has_flag( "SWIMMABLE", pos() ) ) {
} else if( here.has_flag( TFLAG_SWIMMABLE, pos() ) ) {
drench( 80, { { body_part_foot_l, body_part_foot_r, body_part_leg_l, body_part_leg_r } },
false );
}
Expand Down
11 changes: 4 additions & 7 deletions src/construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ static const trait_id trait_PAINRESIST_TROGLO( "PAINRESIST_TROGLO" );
static const trait_id trait_SPIRITUAL( "SPIRITUAL" );
static const trait_id trait_STOCKY_TROGLO( "STOCKY_TROGLO" );

static const std::string flag_FLAT( "FLAT" );
static const std::string flag_INITIAL_PART( "INITIAL_PART" );
static const std::string flag_SUPPORTS_ROOF( "SUPPORTS_ROOF" );
static const std::string flag_NO_FLOOR( "NO_FLOOR" );

static bool finalized = false;

Expand Down Expand Up @@ -1114,7 +1111,7 @@ bool construct::check_empty( const tripoint &p )
map &here = get_map();
// @TODO should check for *visible* traps only. But calling code must
// first know how to handle constructing on top of an invisible trap!
return ( here.has_flag( flag_FLAT, p ) && !here.has_furn( p ) &&
return ( here.has_flag( TFLAG_FLAT, p ) && !here.has_furn( p ) &&
g->is_empty( p ) && here.tr_at( p ).is_null() &&
here.i_at( p ).empty() && !here.veh_at( p ) );
}
Expand All @@ -1138,7 +1135,7 @@ bool construct::check_support( const tripoint &p )
}
int num_supports = 0;
for( const tripoint &nb : get_orthogonal_neighbors( p ) ) {
if( here.has_flag( flag_SUPPORTS_ROOF, nb ) ) {
if( here.has_flag( TFLAG_SUPPORTS_ROOF, nb ) ) {
num_supports++;
}
}
Expand All @@ -1147,7 +1144,7 @@ bool construct::check_support( const tripoint &p )

bool construct::check_stable( const tripoint &p )
{
return get_map().has_flag( flag_SUPPORTS_ROOF, p + tripoint_below );
return get_map().has_flag( TFLAG_SUPPORTS_ROOF, p + tripoint_below );
}

bool construct::check_empty_stable( const tripoint &p )
Expand All @@ -1157,7 +1154,7 @@ bool construct::check_empty_stable( const tripoint &p )

bool construct::check_nofloor_above( const tripoint &p )
{
return get_map().has_flag( flag_NO_FLOOR, p + tripoint_above );
return get_map().has_flag( TFLAG_NO_FLOOR, p + tripoint_above );
}

bool construct::check_deconstruct( const tripoint &p )
Expand Down
4 changes: 2 additions & 2 deletions src/do_turn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ void update_stair_monsters()

avatar &u = get_avatar();
for( const tripoint &dest : m.points_on_zlevel( u.posz() ) ) {
if( ( from_below && m.has_flag( "GOES_DOWN", dest ) ) ||
( !from_below && m.has_flag( "GOES_UP", dest ) ) ) {
if( ( from_below && m.has_flag( TFLAG_GOES_DOWN, dest ) ) ||
( !from_below && m.has_flag( TFLAG_GOES_UP, dest ) ) ) {
stairx.push_back( dest.x );
stairy.push_back( dest.y );
stairdist.push_back( rl_dist( dest, u.pos() ) );
Expand Down
2 changes: 0 additions & 2 deletions src/flag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ const flag_id flag_TACK( "TACK" );
const flag_id flag_TANGLE( "TANGLE" );
const flag_id flag_TARDIS( "TARDIS" );
const flag_id flag_THERMOMETER( "THERMOMETER" );
const flag_id flag_THIN_OBSTACLE( "THIN_OBSTACLE" );
const flag_id flag_TIE_UP( "TIE_UP" );
const flag_id flag_TINDER( "TINDER" );
const flag_id flag_TOBACCO( "TOBACCO" );
Expand All @@ -287,7 +286,6 @@ const flag_id flag_TOW_CABLE( "TOW_CABLE" );
const flag_id flag_TRADER_AVOID( "TRADER_AVOID" );
const flag_id flag_TRADER_KEEP( "TRADER_KEEP" );
const flag_id flag_TRADER_KEEP_EQUIPPED( "TRADER_KEEP_EQUIPPED" );
const flag_id flag_TRANSPARENT( "TRANSPARENT" );
const flag_id flag_TWO_WAY_RADIO( "TWO_WAY_RADIO" );
const flag_id flag_UNARMED_WEAPON( "UNARMED_WEAPON" );
const flag_id flag_UNBREAKABLE_MELEE( "UNBREAKABLE_MELEE" );
Expand Down
1 change: 0 additions & 1 deletion src/flag.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ extern const flag_id flag_TOW_CABLE;
extern const flag_id flag_TRADER_AVOID;
extern const flag_id flag_TRADER_KEEP;
extern const flag_id flag_TRADER_KEEP_EQUIPPED;
extern const flag_id flag_TRANSPARENT;
extern const flag_id flag_TWO_WAY_RADIO;
extern const flag_id flag_UNARMED_WEAPON;
extern const flag_id flag_UNBREAKABLE_MELEE;
Expand Down
13 changes: 4 additions & 9 deletions src/fungal_effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,11 @@ static const species_id species_FUNGUS( "FUNGUS" );
static const trait_id trait_TAIL_CATTLE( "TAIL_CATTLE" );
static const trait_id trait_THRESH_MYCUS( "THRESH_MYCUS" );

static const std::string flag_DIGGABLE( "DIGGABLE" );
static const std::string flag_FLAMMABLE( "FLAMMABLE" );
static const std::string flag_FLAT( "FLAT" );
static const std::string flag_FLOWER( "FLOWER" );
static const std::string flag_ORGANIC( "ORGANIC" );
static const std::string flag_PLANT( "PLANT" );
static const std::string flag_SHRUB( "SHRUB" );
static const std::string flag_THIN_OBSTACLE( "THIN_OBSTACLE" );
static const std::string flag_TREE( "TREE" );
static const std::string flag_WALL( "WALL" );
static const std::string flag_YOUNG( "YOUNG" );

void fungal_effects::fungalize( const tripoint &p, Creature *origin, double spore_chance )
Expand Down Expand Up @@ -142,12 +137,12 @@ void fungal_effects::spread_fungus_one_tile( const tripoint &p, const int growth
map &here = get_map();
bool converted = false;
// Terrain conversion
if( here.has_flag_ter( flag_DIGGABLE, p ) ) {
if( here.has_flag_ter( TFLAG_DIGGABLE, p ) ) {
if( x_in_y( growth * 10, 100 ) ) {
here.ter_set( p, t_fungus );
converted = true;
}
} else if( here.has_flag( flag_FLAT, p ) ) {
} else if( here.has_flag( TFLAG_FLAT, p ) ) {
if( here.has_flag( TFLAG_INDOORS, p ) ) {
if( x_in_y( growth * 10, 500 ) ) {
here.ter_set( p, t_fungus_floor_in );
Expand All @@ -172,7 +167,7 @@ void fungal_effects::spread_fungus_one_tile( const tripoint &p, const int growth
here.ter_set( p, t_marloss );
converted = true;
}
} else if( here.has_flag( flag_THIN_OBSTACLE, p ) ) {
} else if( here.has_flag( TFLAG_THIN_OBSTACLE, p ) ) {
if( x_in_y( growth * 10, 150 ) ) {
here.ter_set( p, t_fungus_mound );
converted = true;
Expand Down Expand Up @@ -209,7 +204,7 @@ void fungal_effects::spread_fungus_one_tile( const tripoint &p, const int growth
}
converted = true;
}
} else if( here.has_flag( flag_WALL, p ) && here.has_flag( flag_FLAMMABLE, p ) ) {
} else if( here.has_flag( TFLAG_WALL, p ) && here.has_flag( TFLAG_FLAMMABLE, p ) ) {
if( x_in_y( growth * 10, 5000 ) ) {
here.ter_set( p, t_fungus_wall );
converted = true;
Expand Down
Loading

0 comments on commit 83b4e06

Please sign in to comment.