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

vehicle: improve performance by removing has_part( "ROTOR" ) calls #44941

Merged
merged 1 commit into from Oct 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/vehicle.cpp
Expand Up @@ -4235,8 +4235,8 @@ bool vehicle::has_sufficient_rotorlift() const

bool vehicle::is_rotorcraft() const
{
return ( has_part( "ROTOR" ) || has_part( "ROTOR_SIMPLE" ) ) && has_sufficient_rotorlift() &&
player_in_control( get_player_character() );
return !rotors.empty() && player_in_control( get_player_character() ) &&
has_sufficient_rotorlift();
}

bool vehicle::is_flyable() const
Expand All @@ -4256,7 +4256,7 @@ int vehicle::get_z_change() const

bool vehicle::would_prevent_flyable( const vpart_info &vpinfo ) const
{
return is_flyable() && has_part( "ROTOR" ) && !vpinfo.has_flag( "SIMPLE_PART" );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should still check for the string ROTOR flag, this message shouldn't be triggering when it's a SIMPLE_ROTOR. The other change below this is potentially the same deal (though that could probably check !rotors.empty() then has_part( ROTOR ) for performance).

return flyable && !rotors.empty() && !vpinfo.has_flag( "SIMPLE_PART" );
}

bool vehicle::is_flying_in_air() const
Expand Down Expand Up @@ -6684,7 +6684,7 @@ int vehicle::damage_direct( int p, int dmg, damage_type type )
dmg -= std::min<int>( dmg, part_info( p ).damage_reduction[ static_cast<int>( type ) ] );
int dres = dmg - parts[p].hp();
if( mod_hp( parts[ p ], 0 - dmg, type ) ) {
if( is_flyable() && has_part( "ROTOR" ) && !parts[p].has_flag( VPFLAG_SIMPLE_PART ) ) {
if( is_flyable() && !rotors.empty() && !parts[p].has_flag( VPFLAG_SIMPLE_PART ) ) {
// If we break a part, we can no longer fly the vehicle.
set_flyable( false );
}
Expand Down