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

[WIP] Fixed "Auto-sort infinite loop/game hang #29573" (rebased) #33710

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions data/json/player_activities.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,7 @@
"type": "activity_type",
"activity_level": "MODERATE_EXERCISE",
"verb": "sorting out the loot",
"suspendable": false,
"based_on": "neither",
"no_resume": true
"based_on": "neither"
},
{
"id": "ACT_TILL_PLOT",
Expand All @@ -307,18 +305,14 @@
"type": "activity_type",
"activity_level": "MODERATE_EXERCISE",
"verb": "fetching components",
"suspendable": false,
"based_on": "neither",
"no_resume": true
"based_on": "neither"
},
{
"id": "ACT_MULTIPLE_FARM",
"type": "activity_type",
"activity_level": "ACTIVE_EXERCISE",
"verb": "farming",
"suspendable": false,
"based_on": "neither",
"no_resume": true
"based_on": "neither"
},
{
"id": "ACT_PLANT_PLOT",
Expand Down
4 changes: 0 additions & 4 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3101,10 +3101,6 @@ void activity_handlers::churn_finish( player_activity *act, player *p )
// Go back to what we were doing before
// could be player zone activity, or could be NPC multi-farming
act->set_to_null();
if( !p->backlog.empty() ) {
p->activity = p->backlog.front();
p->backlog.pop_front();
}
}

void activity_handlers::build_do_turn( player_activity *act, player *p )
Expand Down
2 changes: 1 addition & 1 deletion src/activity_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ enum do_activity_reason : int {
NEEDS_HARVESTING, // For farming - tile is harvestable now.
NEEDS_PLANTING, // For farming - tile can be planted
NEEDS_TILLING, // For farming - tile can be tilled
NEEDS_FETCHING, // Generic fetching required
BLOCKING_TILE // Something has made it's way onto the tile, so the activity cannot proceed
};

Expand Down Expand Up @@ -76,7 +77,6 @@ int butcher_time_to_cut( const player &u, const item &corpse_item, butcher_type
// activity_item_handling.cpp
void activity_on_turn_drop();
void activity_on_turn_move_items( player_activity &act, player &p );
void activity_on_turn_move_loot( player_activity &act, player &p );
void generic_multi_activity_handler( player_activity &act, player &p );
void activity_on_turn_fetch( player_activity &, player *p );
void activity_on_turn_pickup();
Expand Down
767 changes: 438 additions & 329 deletions src/activity_item_handling.cpp

Large diffs are not rendered by default.

39 changes: 0 additions & 39 deletions src/clzones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1104,45 +1104,6 @@ void zone_manager::rotate_zones( map &target_map, const int turns )
}
}

void zone_manager::start_sort( const std::vector<tripoint> &src_sorted )
{
for( auto &src : src_sorted ) {
num_processed[src] = 0;
}
}

void zone_manager::end_sort()
{
num_processed.clear();
}

bool zone_manager::is_sorting() const
{
return !num_processed.empty();
}

int zone_manager::get_num_processed( const tripoint &src ) const
{
auto it = num_processed.find( src );
if( it != num_processed.end() ) {
return it->second;
}
return 0;
}

void zone_manager::increment_num_processed( const tripoint &src )
{
num_processed[src]++;
}

void zone_manager::decrement_num_processed( const tripoint &src )
{
num_processed[src]--;
if( num_processed[src] < 0 ) {
num_processed[src] = 0;
}
}

std::vector<zone_manager::ref_zone_data> zone_manager::get_zones( const faction_id &fac )
{
auto zones = std::vector<ref_zone_data>();
Expand Down
9 changes: 0 additions & 9 deletions src/clzones.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,6 @@ class zone_manager
std::unordered_set<tripoint> get_vzone_set( const zone_type_id &type,
const faction_id &fac = your_fac ) const;

//Cache number of items already checked on each source tile when sorting
std::unordered_map<tripoint, int> num_processed;

public:
zone_manager();
~zone_manager() = default;
Expand Down Expand Up @@ -407,12 +404,6 @@ class zone_manager
const faction_id &fac = your_fac ) const;
std::unordered_set<tripoint> get_point_set_loot( const tripoint &where, int radius,
bool npc_search, const faction_id &fac = your_fac ) const;
void start_sort( const std::vector<tripoint> &src_sorted );
void end_sort();
bool is_sorting() const;
int get_num_processed( const tripoint &src ) const;
void increment_num_processed( const tripoint &src );
void decrement_num_processed( const tripoint &src );

// 'direct' access to zone_manager::zones, giving direct access was nono
std::vector<ref_zone_data> get_zones( const faction_id &fac = your_fac );
Expand Down
6 changes: 0 additions & 6 deletions src/construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,12 +928,6 @@ void complete_construction( player *p )
// This comes after clearing the activity, in case the function interrupts
// activities
built.post_special( terp );
// npcs will automatically resume backlog, players wont.
if( p->is_player() && !p->backlog.empty() &&
p->backlog.front().id() == activity_id( "ACT_MULTIPLE_CONSTRUCTION" ) ) {
p->backlog.clear();
p->assign_activity( activity_id( "ACT_MULTIPLE_CONSTRUCTION" ) );
}
}

bool construct::check_empty( const tripoint &p )
Expand Down
2 changes: 2 additions & 0 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ void player_activity::serialize( JsonOut &json ) const
json.member( "index", index );
json.member( "position", position );
json.member( "coords", coords );
json.member( "coord_set", coord_set );
json.member( "name", name );
json.member( "targets", targets );
json.member( "placement", placement );
Expand Down Expand Up @@ -281,6 +282,7 @@ void player_activity::deserialize( JsonIn &jsin )
data.read( "index", index );
position = tmppos;
data.read( "coords", coords );
data.read( "coord_set", coord_set );
data.read( "name", name );
data.read( "targets", targets );
data.read( "placement", placement );
Expand Down