Skip to content

Commit

Permalink
speed up fields processing by replacing inline ids with global consts
Browse files Browse the repository at this point in the history
(this is correct because of CleverRaven#44261)
partially reverts da3a1fe
  • Loading branch information
Aivean committed Sep 29, 2020
1 parent ac84e5c commit eae3296
Show file tree
Hide file tree
Showing 40 changed files with 406 additions and 306 deletions.
2 changes: 1 addition & 1 deletion src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2462,7 +2462,7 @@ void activity_handlers::oxytorch_finish( player_activity *act, player *p )
here.furn_set( pos, f_safe_o );
// 50% of starting a fire.
if( here.flammable_items_at( pos ) && rng( 1, 100 ) < 50 ) {
here.add_field( pos, field_type_id( "fd_fire" ), 1, 10_minutes );
here.add_field( pos, fd_fire, 1, 10_minutes );
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1914,7 +1914,7 @@ void activity_on_turn_move_loot( player_activity &act, player &p )
// (to prevent taking out wood off the lit brazier)
// and inaccessible furniture, like filled charcoal kiln
if( mgr.has( zone_type_LOOT_IGNORE, src ) ||
here.get_field( src_loc, field_type_id( "fd_fire" ) ) != nullptr ||
here.get_field( src_loc, fd_fire ) != nullptr ||
!here.can_put_items_ter_furn( src_loc ) ) {
continue;
}
Expand Down Expand Up @@ -2777,7 +2777,7 @@ static cata::optional<tripoint> find_best_fire( const std::vector<tripoint> &fro
time_duration best_fire_age = 1_days;
map &here = get_map();
for( const tripoint &pt : from ) {
field_entry *fire = here.get_field( pt, field_type_id( "fd_fire" ) );
field_entry *fire = here.get_field( pt, fd_fire );
if( fire == nullptr || fire->get_field_intensity() > 1 ||
!here.clear_path( center, pt, PICKUP_RANGE, 1, 100 ) ) {
continue;
Expand Down Expand Up @@ -2939,7 +2939,7 @@ void try_fuel_fire( player_activity &act, player &p, const bool starting_fire )
// Special case: fire containers allow burning logs, so use them as fuel if fire is contained
bool contained = here.has_flag_furn( TFLAG_FIRE_CONTAINER, *best_fire );
fire_data fd( 1, contained );
time_duration fire_age = here.get_field_age( *best_fire, field_type_id( "fd_fire" ) );
time_duration fire_age = here.get_field_age( *best_fire, fd_fire );

// Maybe TODO: - refueling in the rain could use more fuel
// First, simulate expected burn per turn, to see if we need more fuel
Expand Down
4 changes: 2 additions & 2 deletions src/ammo_effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct ammo_effect {
void check() const;

public:
field_type_id aoe_field_type = fd_null;
field_type_id aoe_field_type = fd_null.id_or( INVALID_FIELD_TYPE_ID );
/** used during JSON loading only */
std::string aoe_field_type_name = "fd_null";
int aoe_intensity_min = 0;
Expand All @@ -38,7 +38,7 @@ struct ammo_effect {
bool do_emp_blast = false;
bool foamcrete_build = false;

field_type_id trail_field_type = fd_null;
field_type_id trail_field_type = fd_null.id_or( INVALID_FIELD_TYPE_ID );
/** used during JSON loading only */
std::string trail_field_type_name = "fd_null";
int trail_intensity_min = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ bool Character::activate_bionic( int b, bool eff_only, bool *close_bionics_ui )
const cata::optional<tripoint> pnt = choose_adjacent( _( "Start a fire where?" ) );
if( pnt && here.is_flammable( *pnt ) ) {
add_msg_activate();
here.add_field( *pnt, field_type_id( "fd_fire" ), 1 );
here.add_field( *pnt, fd_fire, 1 );
mod_moves( -100 );
} else {
refund_power();
Expand Down
2 changes: 1 addition & 1 deletion src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2601,7 +2601,7 @@ bool cata_tiles::draw_field_or_item( const tripoint &p, const lit_level ll, int
auto field_at = [&]( const tripoint & q, const bool invis ) -> field_type_id {
const auto it = field_override.find( q );
return it != field_override.end() ? it->second :
( !fld_overridden || !invis ) ? here.field_at( q ).displayed_field_type() : field_type_id( "fd_null" );
( !fld_overridden || !invis ) ? here.field_at( q ).displayed_field_type() : fd_null;
};
// for rotation information
const int neighborhood[4] = {
Expand Down
18 changes: 9 additions & 9 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,22 +508,22 @@ void Character::randomize_blood()
field_type_id Character::bloodType() const
{
if( has_trait( trait_ACIDBLOOD ) ) {
return field_type_id( "fd_acid" );
return fd_acid;
}
if( has_trait( trait_THRESH_PLANT ) ) {
return field_type_id( "fd_blood_veggy" );
return fd_blood_veggy;
}
if( has_trait( trait_THRESH_INSECT ) || has_trait( trait_THRESH_SPIDER ) ) {
return field_type_id( "fd_blood_insect" );
return fd_blood_insect;
}
if( has_trait( trait_THRESH_CEPHALOPOD ) ) {
return field_type_id( "fd_blood_invertebrate" );
return fd_blood_invertebrate;
}
return field_type_id( "fd_blood" );
return fd_blood;
}
field_type_id Character::gibType() const
{
return field_type_id( "fd_gibs_flesh" );
return fd_gibs_flesh;
}

bool Character::in_species( const species_id &spec ) const
Expand Down Expand Up @@ -6637,7 +6637,7 @@ Character::comfort_response_t Character::base_comfort_value( const tripoint &p )
const ter_id ter_at_pos = tile.get_ter();
const furn_id furn_at_pos = tile.get_furn();

int web = here.get_field_intensity( p, field_type_id( "fd_web" ) );
int web = here.get_field_intensity( p, fd_web );

// Some mutants have different comfort needs
if( !plantsleep && !webforce ) {
Expand Down Expand Up @@ -8846,7 +8846,7 @@ void Character::vomit()

if( stomach.contains() != 0_ml ) {
stomach.empty();
get_map().add_field( adjacent_tile(), field_type_id( "fd_bile" ), 1 );
get_map().add_field( adjacent_tile(), fd_bile, 1 );
add_msg_player_or_npc( m_bad, _( "You throw up heavily!" ), _( "<npcname> throws up heavily!" ) );
}

Expand Down Expand Up @@ -9961,7 +9961,7 @@ void Character::blossoms()
sounds::sound( pos(), 10, sounds::sound_t::combat, _( "Pouf!" ), false, "misc", "puff" );
map &here = get_map();
for( const tripoint &tmp : here.points_in_radius( pos(), 2 ) ) {
here.add_field( tmp, field_type_id( "fd_fungal_haze" ), rng( 1, 2 ) );
here.add_field( tmp, fd_fungal_haze, rng( 1, 2 ) );
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/computer_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ void computer_session::action_irradiator()
"alarm" );
here.i_rem( dest, it );
here.make_rubble( dest );
here.propagate_field( dest, field_type_id( "fd_nuke_gas" ), 100, 3 );
here.propagate_field( dest, fd_nuke_gas, 100, 3 );
here.translate_radius( t_water_pool, t_sewage, 8.0, dest, true );
here.adjust_radiation( dest, rng( 50, 500 ) );
for( const tripoint &radorigin : here.points_in_radius( dest, 5 ) ) {
Expand Down Expand Up @@ -1260,13 +1260,13 @@ void computer_session::action_deactivate_shock_vent()
bool has_generator = false;
map &here = get_map();
for( const tripoint &dest : here.points_in_radius( player_character.pos(), 10 ) ) {
if( here.get_field( dest, field_type_id( "fd_shock_vent" ) ) != nullptr ) {
if( here.get_field( dest, fd_shock_vent ) != nullptr ) {
has_vent = true;
}
if( here.ter( dest ) == t_plut_generator ) {
has_generator = true;
}
here.remove_field( dest, field_type_id( "fd_shock_vent" ) );
here.remove_field( dest, fd_shock_vent );
}
print_line( _( "Initiating POWER-DIAG ver.2.34…" ) );
if( has_vent ) {
Expand Down
2 changes: 1 addition & 1 deletion src/emit.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class emit

private:
emit_id id_;
field_type_id field_ = fd_null;
field_type_id field_ = fd_null.id_or( INVALID_FIELD_TYPE_ID );
int intensity_ = 1;
int qty_ = 1;
int chance_ = 100;
Expand Down
14 changes: 7 additions & 7 deletions src/explosion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ static void do_blast( const tripoint &p, const float power,
intensity++;
}

here.add_field( pt, field_type_id( "fd_fire" ), intensity );
here.add_field( pt, fd_fire, intensity );
}

if( const optional_vpart_position vp = here.veh_at( pt ) ) {
Expand Down Expand Up @@ -804,24 +804,24 @@ void resonance_cascade( const tripoint &p )
case 5:
for( int k = i - 1; k <= i + 1; k++ ) {
for( int l = j - 1; l <= j + 1; l++ ) {
field_type_id type = field_type_id( "fd_null" );
field_type_id type = fd_null;
switch( rng( 1, 7 ) ) {
case 1:
type = field_type_id( "fd_blood" );
type = fd_blood;
break;
case 2:
type = field_type_id( "fd_bile" );
type = fd_bile;
break;
case 3:
case 4:
type = field_type_id( "fd_slime" );
type = fd_slime;
break;
case 5:
type = field_type_id( "fd_fire" );
type = fd_fire;
break;
case 6:
case 7:
type = field_type_id( "fd_nuke_gas" );
type = fd_nuke_gas;
break;
}
if( !one_in( 3 ) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ time_duration field_entry::set_field_age( const time_duration &new_age )
}

field::field()
: _displayed_field_type( fd_null )
: _displayed_field_type( fd_null.id_or( INVALID_FIELD_TYPE_ID ) )
{
}

Expand Down
3 changes: 2 additions & 1 deletion src/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
class field_entry
{
public:
field_entry() : type( fd_null ), intensity( 1 ), age( 0_turns ), is_alive( false ) { }
field_entry() : type( fd_null.id_or( INVALID_FIELD_TYPE_ID ) ), intensity( 1 ), age( 0_turns ),
is_alive( false ) { }
field_entry( const field_type_id &t, const int i, const time_duration &a ) : type( t ),
intensity( i ), age( a ), is_alive( true ) { }

Expand Down
57 changes: 54 additions & 3 deletions src/field_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,53 @@
#include "json.h"
#include "string_id.h"

field_type_id fd_null;
const field_type_str_id fd_null = field_type_str_id::NULL_ID();
const field_type_str_id fd_fire( "fd_fire" );
const field_type_str_id fd_blood( "fd_blood" );
const field_type_str_id fd_bile( "fd_bile" );
const field_type_str_id fd_extinguisher( "fd_extinguisher" );
const field_type_str_id fd_gibs_flesh( "fd_gibs_flesh" );
const field_type_str_id fd_gibs_veggy( "fd_gibs_veggy" );
const field_type_str_id fd_web( "fd_web" );
const field_type_str_id fd_slime( "fd_slime" );
const field_type_str_id fd_acid( "fd_acid" );
const field_type_str_id fd_sap( "fd_sap" );
const field_type_str_id fd_sludge( "fd_sludge" );
const field_type_str_id fd_smoke( "fd_smoke" );
const field_type_str_id fd_toxic_gas( "fd_toxic_gas" );
const field_type_str_id fd_tear_gas( "fd_tear_gas" );
const field_type_str_id fd_nuke_gas( "fd_nuke_gas" );
const field_type_str_id fd_gas_vent( "fd_gas_vent" );
const field_type_str_id fd_fire_vent( "fd_fire_vent" );
const field_type_str_id fd_flame_burst( "fd_flame_burst" );
const field_type_str_id fd_electricity( "fd_electricity" );
const field_type_str_id fd_fatigue( "fd_fatigue" );
const field_type_str_id fd_push_items( "fd_push_items" );
const field_type_str_id fd_shock_vent( "fd_shock_vent" );
const field_type_str_id fd_acid_vent( "fd_acid_vent" );
const field_type_str_id fd_plasma( "fd_plasma" );
const field_type_str_id fd_laser( "fd_laser" );
const field_type_str_id fd_dazzling( "fd_dazzling" );
const field_type_str_id fd_blood_veggy( "fd_blood_veggy" );
const field_type_str_id fd_blood_insect( "fd_blood_insect" );
const field_type_str_id fd_blood_invertebrate( "fd_blood_invertebrate" );
const field_type_str_id fd_gibs_insect( "fd_gibs_insect" );
const field_type_str_id fd_gibs_invertebrate( "fd_gibs_invertebrate" );
const field_type_str_id fd_bees( "fd_bees" );
const field_type_str_id fd_incendiary( "fd_incendiary" );
const field_type_str_id fd_relax_gas( "fd_relax_gas" );
const field_type_str_id fd_fungal_haze( "fd_fungal_haze" );
const field_type_str_id fd_cold_air2( "fd_cold_air2" );
const field_type_str_id fd_cold_air3( "fd_cold_air3" );
const field_type_str_id fd_cold_air4( "fd_cold_air4" );
const field_type_str_id fd_hot_air1( "fd_hot_air1" );
const field_type_str_id fd_hot_air2( "fd_hot_air2" );
const field_type_str_id fd_hot_air3( "fd_hot_air3" );
const field_type_str_id fd_hot_air4( "fd_hot_air4" );
const field_type_str_id fd_fungicidal_gas( "fd_fungicidal_gas" );
const field_type_str_id fd_insecticidal_gas( "fd_insecticidal_gas" );
const field_type_str_id fd_smoke_vent( "fd_smoke_vent" );
const field_type_str_id fd_tindalos_rift( "fd_tindalos_rift" );

namespace io
{
Expand Down Expand Up @@ -101,11 +147,17 @@ const field_type &string_id<field_type>::obj() const
return all_field_types.obj( *this );
}

template<>
int_id<field_type> string_id<field_type>::id_or( const int_id<field_type> &fallback ) const
{
return all_field_types.convert( *this, fallback, false );
}

/** @relates string_id */
template<>
int_id<field_type> string_id<field_type>::id() const
{
return all_field_types.convert( *this, fd_null );
return all_field_types.convert( *this, fd_null.id_or( int_id<field_type>() ) );
}

/** @relates int_id */
Expand Down Expand Up @@ -272,7 +324,6 @@ void field_type::finalize()
debugmsg( "Invalid mtype_id %s in immune_mtypes for field %s.", m_id.c_str(), id.c_str() );
}
}
fd_null = field_type_id( "fd_null" );
}

void field_type::check() const
Expand Down
49 changes: 48 additions & 1 deletion src/field_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,54 @@ struct field_intensity_level {
std::vector<field_effect> field_effects;
};

extern field_type_id fd_null;
const field_type_id INVALID_FIELD_TYPE_ID = field_type_id( -1 );
extern const field_type_str_id fd_null;
extern const field_type_str_id fd_fire;
extern const field_type_str_id fd_blood;
extern const field_type_str_id fd_bile;
extern const field_type_str_id fd_extinguisher;
extern const field_type_str_id fd_gibs_flesh;
extern const field_type_str_id fd_gibs_veggy;
extern const field_type_str_id fd_web;
extern const field_type_str_id fd_slime;
extern const field_type_str_id fd_acid;
extern const field_type_str_id fd_sap;
extern const field_type_str_id fd_sludge;
extern const field_type_str_id fd_smoke;
extern const field_type_str_id fd_toxic_gas;
extern const field_type_str_id fd_tear_gas;
extern const field_type_str_id fd_nuke_gas;
extern const field_type_str_id fd_gas_vent;
extern const field_type_str_id fd_fire_vent;
extern const field_type_str_id fd_flame_burst;
extern const field_type_str_id fd_electricity;
extern const field_type_str_id fd_fatigue;
extern const field_type_str_id fd_push_items;
extern const field_type_str_id fd_shock_vent;
extern const field_type_str_id fd_acid_vent;
extern const field_type_str_id fd_plasma;
extern const field_type_str_id fd_laser;
extern const field_type_str_id fd_dazzling;
extern const field_type_str_id fd_blood_veggy;
extern const field_type_str_id fd_blood_insect;
extern const field_type_str_id fd_blood_invertebrate;
extern const field_type_str_id fd_gibs_insect;
extern const field_type_str_id fd_gibs_invertebrate;
extern const field_type_str_id fd_bees;
extern const field_type_str_id fd_incendiary;
extern const field_type_str_id fd_relax_gas;
extern const field_type_str_id fd_fungal_haze;
extern const field_type_str_id fd_cold_air2;
extern const field_type_str_id fd_cold_air3;
extern const field_type_str_id fd_cold_air4;
extern const field_type_str_id fd_hot_air1;
extern const field_type_str_id fd_hot_air2;
extern const field_type_str_id fd_hot_air3;
extern const field_type_str_id fd_hot_air4;
extern const field_type_str_id fd_fungicidal_gas;
extern const field_type_str_id fd_insecticidal_gas;
extern const field_type_str_id fd_smoke_vent;
extern const field_type_str_id fd_tindalos_rift;

struct field_type {
public:
Expand Down
4 changes: 2 additions & 2 deletions src/fungal_effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void fungal_effects::spread_fungus_one_tile( const tripoint &p, const int growth
}
} else if( m.has_flag( flag_YOUNG, p ) ) {
if( x_in_y( growth * 10, 500 ) ) {
if( m.get_field_intensity( p, field_type_id( "fd_fungal_haze" ) ) != 0 ) {
if( m.get_field_intensity( p, fd_fungal_haze ) != 0 ) {
if( x_in_y( growth * 10, 800 ) ) { // young trees are vulnerable
m.ter_set( p, t_fungus );
if( gm.place_critter_at( mon_fungal_blossom, p ) ) {
Expand All @@ -199,7 +199,7 @@ void fungal_effects::spread_fungus_one_tile( const tripoint &p, const int growth
}
} else if( m.has_flag( flag_TREE, p ) ) {
if( one_in( 10 ) ) {
if( m.get_field_intensity( p, field_type_id( "fd_fungal_haze" ) ) != 0 ) {
if( m.get_field_intensity( p, fd_fungal_haze ) != 0 ) {
if( x_in_y( growth * 10, 100 ) ) {
m.ter_set( p, t_fungus );
if( gm.place_critter_at( mon_fungal_blossom, p ) ) {
Expand Down
Loading

0 comments on commit eae3296

Please sign in to comment.