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

[CR] [WIP] Optimize generic activities using stages #33864

Closed

Conversation

ipcyborg
Copy link
Contributor

@ipcyborg ipcyborg commented Sep 7, 2019

Summary

SUMMARY: Infrastructure "Optimize generic activities using stages"

Purpose of change

Avoid the possible coordinates looping in generic activities by using stages.
Optimize activity performance.

Describe the solution

Activity stages (stored in activity.index)

  1. Initial stage: determine and remember all possible location for this activity.
  2. Think stage: think about what to do first: choose a source location to move.
  3. Move stage: go to the chosen location.
  4. Do stage: do specific activity there, then think what to do next (go to 2).

The location coordinates are processed only once to avoid loops.
Probably it can also be done using some kind of coordinate markings: skipping and then returning to the skipped coordinate?

Not finished yet.

Describe alternatives you've considered

Leave as it is.

Additional context

Changes were rebased from PR #33710, excluding activity_on_turn_move_loot changes (will be done in separate PR).

Add `mental_map` to `player_activity` (saving is not required, used in `fetch_activity`).
@ZhilkinSerg ZhilkinSerg added [C++] Changes (can be) made in C++. Previously named `Code` [JSON] Changes (can be) made in JSON Mechanics: Character / Player Character / Player mechanics labels Sep 7, 2019
@ipcyborg
Copy link
Contributor Author

Still can't make it work.
The main issue is moving stage: now it is done using set_destination.
I may be incorrect, but I see that moving behaves differently for Player and for NPC:

  • Player moves using simulated key-presses (see get_next_auto_move_direction).
  • NPC moves using get_auto_move_route.

Moving can be done only outside of the activity. See game::process_activity:

while( u.moves > 0 && u.activity ) {
        u.activity.do_turn( u );
    }

So if the current activity has not spend all moving points (moves) -> infinite loop.
And if it has -> no moving points for the actual moving (later, in handle_action).

So for now I don't know how to include moving into the activity stages. And moving outside of the activity (while leaving player activity set to null) leads to some strange behavior on resuming activity from backlog. May be I'm just using the backlog incorrectly and it is not meant to process sub-activities and resume the main activity again.

For now I see one solution: unify moving process (for Player and NPC) and make it a separate activity. Then fix the backlog resuming process.

Any advice?

@ipcyborg ipcyborg changed the title [WIP] Optimize generic activities using stages [CR] [WIP] Optimize generic activities using stages Sep 14, 2019
@ghost
Copy link

ghost commented Sep 17, 2019

Would recommend you come to the developer discord to talk about this in more detail, if this is possible for you.

Its tricky to understand what the problem is, and what you are aiming to do.

https://discord.gg/jFEc7Yp

@ipcyborg
Copy link
Contributor Author

Closed based on the discord discussion results:
It was recommend to keep the structure of the generic activity function, while try to find a way to neaten up the logic and the code.

Separate PR is required.

@ipcyborg ipcyborg closed this Sep 18, 2019
@ipcyborg ipcyborg deleted the fix-29573-auto-sort-loop-v3 branch October 17, 2019 14:41
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` [JSON] Changes (can be) made in JSON Mechanics: Character / Player Character / Player mechanics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants