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

Allow for specialization of activity parameters #37450

Merged
merged 4 commits into from
Apr 4, 2020

Conversation

ifreund
Copy link
Contributor

@ifreund ifreund commented Jan 27, 2020

Summary

SUMMARY: Infrastructure "Allow for specialization of activity parameters"

Purpose of change

Currently player activities can only store state during execution by using one of
the already available members of player_activity or creating a new one if the
desired type is not already available.

Describe the solution

This commit introduces the activity_actor abstract class and the
infrastructure needed to integrate with the current player_activity system.

This commit also migrates ACT_MOVE_ITEMS to use this new actor system
as and example and a test of the new system.

The activity actor system allows for each actor to declare its own
state variables allowing specialization for the type of activity being
preformed and much more readable code

The migration of activities to this new system can be done in an
incremental way until all activities have been migrated to the actor
system at which point the legacy infrastructure can be removed.

Describe alternatives you've considered

Alternatives to this approach include creating more generic parameter types
in player_actvity, perhaps using cata_varaint. However, such an approach
is still limited in the specialization available compared to this system.

Testing

Hauling and moving items with the advanced inventory are still fully functional.
Autosaves during hauling can be reloaded without errors and result in resumption
of the activity.

Additional context

I'm not entirely happy with how the deserialization of activity actors is handled
in the code. If anyone has suggestions on that front or on the system in general
I'd love to hear them.

@ifreund ifreund added [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Mechanics: Character / Player Character / Player mechanics labels Jan 27, 2020
@ifreund
Copy link
Contributor Author

ifreund commented Jan 27, 2020

Just realized that I've forgotten to handle save migration for in progress legacy activities, So I'm marking this as WIP for now.

@ifreund ifreund changed the title Allow for specialization of activity parameters [WIP] Allow for specialization of activity parameters Jan 27, 2020
@ifreund
Copy link
Contributor Author

ifreund commented Jan 28, 2020

Migration is now handled through a new ACT_MIGRATION_CANCEL activity which
clears the backlog, resets the state of the avatar or npc, and sets
itself to null the first time its do_turn is called.

This may result in inconvenience when a save is migrated, but should avoid
any lasting negative effects on the save.

This also avoids the tedious and error-prone task of writing custom
migration code for each activity migrated to the activity_actor system.

@ifreund ifreund changed the title [WIP] Allow for specialization of activity parameters Allow for specialization of activity parameters Jan 28, 2020
@snipercup
Copy link
Contributor

snipercup commented Jan 28, 2020

While testing, my game freezes when I try to move all in advanced inventory using the default key ,

I cannot reproduce it when compiling from master, only from this branch. Can you reproduce?

@ifreund
Copy link
Contributor Author

ifreund commented Jan 28, 2020

@snipercup thanks, I forgot to migrate the move all function. Should be fixed now.

@snipercup
Copy link
Contributor

Can confirm, the bug I reported is no longer there.

@snipercup
Copy link
Contributor

I continued playing for a while but didnt find any bugs related to this pr.

if( filtered_any_bucket ) {
add_msg( m_info, _( "Skipping filled buckets to avoid spilling their contents." ) );
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This currently adds a lot of code duplication in the advanced inventory, but that will be remedied when I migrate ACT_PICKUP and ACT_WEAR to use the actor system.

Copy link
Contributor

@jbytheway jbytheway left a comment

Choose a reason for hiding this comment

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

I've not tested in-game, but the code looks reasonable to me.

class player_activity
{
private:
activity_id type;
cata::clone_ptr<activity_actor> actor;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does player_activity need to be copyable? Could this just be a unique_ptr?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It may not be strictly necessary, but it seemed easier than tracking down all the places we are currently doing copy construction and copy assignment to add an std::move() thanks to the cata::clone_ptr type you added. I guess I didn't think about it too deeply but don't see a big drawback in keeping it copyable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, if it's already being copied sometimes then that's probably fine.

This commit introduces the activity_actor abstract class and the
infrastructure needed to integrate with the current player_activity system.

This commit also migrates ACT_MOVE_ITEMS to use this new actor system
as and example and a test of the new system.

The activity actor system allows for each actor to declare its own
state variables which is an improvement over the status quo of each
activity making do with the preselected state variables available in
player_activity.

The migration of activities to this new system can be done in an
incremental way until all activities have been migrate to the actor
system, at which point the legacy infrastructure can be removed.
Migration is handled through a new ACT_MIGRATION_CANCEL activity which
clears the backlog, resets the state of the avatar or npc, and sets
itself to null the first time its do_turn is called.

This may result in inconvience when a save is migrated, but should avoid
any lasting negative effects on the save.

This also avoids the tedious and error-prone task of writing custom
migration code for each activity migrated to the activity_actor system.
@ifreund
Copy link
Contributor Author

ifreund commented Apr 3, 2020

rebased to resolve conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Mechanics: Character / Player Character / Player mechanics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants