Skip to content

Commit

Permalink
Rebuild active_item cache after refresh (#60952)
Browse files Browse the repository at this point in the history
  • Loading branch information
robob27 authored Sep 13, 2022
1 parent 564b786 commit 6e4d1f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3473,9 +3473,6 @@ void vehicle::deserialize( const JsonObject &data )
auto it = vp.part().items.begin();
auto end = vp.part().items.end();
for( ; it != end; ++it ) {
if( it->needs_processing() ) {
active_items.add( *it, vp.mount() );
}
// remove after 0.F
if( savegame_loading_version < 33 ) {
migrate_item_charges( *it );
Expand Down
15 changes: 15 additions & 0 deletions src/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5778,6 +5778,20 @@ void vehicle::enable_refresh()
refresh();
}

void vehicle::refresh_active_item_cache()
{
// Need to manually backfill the active item cache since the part loader can't call its vehicle.
for( const vpart_reference &vp : get_any_parts( VPFLAG_CARGO ) ) {
auto it = vp.part().items.begin();
auto end = vp.part().items.end();
for( ; it != end; ++it ) {
if( it->needs_processing() ) {
active_items.add( *it, vp.mount() );
}
}
}
}

/**
* Refreshes all caches and refinds all parts. Used after the vehicle has had a part added or removed.
* Makes indices of different part types so they're easy to find. Also calculates power drain.
Expand Down Expand Up @@ -6064,6 +6078,7 @@ void vehicle::refresh( const bool remove_fakes )
zones_dirty = true;
invalidate_mass();
occupied_cache_pos = { -1, -1, -1 };
refresh_active_item_cache();
}

vpart_edge_info vehicle::get_edge_info( const point &mount ) const
Expand Down
3 changes: 3 additions & 0 deletions src/vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,9 @@ class vehicle
//Refresh all caches and re-locate all parts
void refresh( bool remove_fakes = true );

// Refresh active_item cache for vehicle parts
void refresh_active_item_cache();

/**
* Set stat for part constrained by range [0,durability]
* @note does not invoke base @ref item::on_damage callback
Expand Down

0 comments on commit 6e4d1f4

Please sign in to comment.