swarm-game / swarm

Resource gathering + programming game
Other
838 stars 52 forks source link

Pause the game on objective completion #2073

Closed xsebek closed 2 months ago

xsebek commented 3 months ago

Is your feature request related to a problem? Please describe.

When an objective is completed, the game can keep running until the modal is shown.

In an extreme case, --scenario Tutorials/move --autoplay finishes the tutorial before the next modal pops up.

Describe the solution you'd like

Pause the game after objective completion and do not run further ticks.

byorgey commented 3 months ago

Do objective modals pop up at all with --autoplay?

xsebek commented 3 months ago

Yes, they do. I do not think that is wrong, since you might want to know how the solution is progressing.

byorgey commented 3 months ago

Hmm, when I run --scenario Tutorials/farming --autoplay I do not get any goal modals popping up, and that one takes long enough that I do not think it is because of a race condition.

xsebek commented 3 months ago

I do get the goal modal at start and after it farms 256 lambdas:

Screenshot 2024-07-22 at 17 12 17
byorgey commented 3 months ago

Ah! I get goal modals only when --cheat is enabled. Without --cheat there are no goal modals.

xsebek commented 3 months ago

Cheat does too many things. I can't even find the code that uses checks cheat for this option among the myriad cheat uses.

The only thing I found is: https://github.com/swarm-game/swarm/blob/7dcc3f58f93c5e243b29fa530069896a15bd99ea/src/swarm-tui/Swarm/TUI/Model/Goal.hs#L120-L123

xsebek commented 3 months ago

@byorgey I remembered a quick way to test if this is --autoplay specific:

cabal run swarm -- --scenario Tutorials/move --run <(yq '.solution' scenarios/Tutorials/move.yaml)

The game becomes unresponsive while it tries to catch up and then shows the goal modal after completion.

So, to answer your question in https://github.com/swarm-game/swarm/pull/2080#issuecomment-2256785179:

For example, the game may run for several ticks during a single frame, but if an objective is completed during one of those ticks, the game needs to immediately auto-pause without waiting for the UI to tell it that it should do so, which could come several ticks late. (Actually I am unsure whether the game currently does this correctly or not.)

It does not. 😅

xsebek commented 3 months ago

In #2094 I moved the --cheat behaviour to --debug=autoplay_goals.

That does not solve this Issue though - game should switch to AutoPause upon objective completion, unless the player does not want to interact with the game. Personally I would prefer a separate flag for no goal dialogs.