Skip to content

A way to run the "update" stage potentially many times per render? #3600

@rodya-mirov

Description

@rodya-mirov

What problem does this solve or what need does it fill?

I'm writing a game which is turn-based, with one player and (potentially many) NPC "players." In terms of control flow, think Civilization (but simpler), so a player's turn actions may impact what the next player does. But, in Civ, an NPC civilization will often take a full second to take their turn; while in my game a turn will usually take much less than a millisecond. So I'd like to be able to process as many as possible per tick and give control back to the player as quickly as possible so they experience smooth gameplay in the "normal" case.

What solution would you like?

The most obvious solution is to somehow run a stage (or system set) "as many times as possible" in the tick, then just render whatever's there. There may be better solutions; I'm open to ideas.

What alternative(s) have you considered?

Nothing great.

Most obviously I tried a proper turn-based system -- the entity whose turn it is can take an action (or not), then a bunch of followup systems run, then it passes control to the next person at the end. I don't see a way to make that not be the entire update stage, so this is the whole stage, and so if you have (e.g.) 1 player and 59 NPCs then the player can take exactly 1 action per second, which doesn't feel great. At 500 NPCs it would be completely unplayable, so it starts to inform game design in a bad way.

I've also tried writing the code in a way that handles everybody's turn in one tick, but when I have NPCs in a loop, the nice separation of concerns ECS provides go out the window -- I really need [NPC 1]'s actions to be fully resolved before NPC 2 even considers their choices. So I can't launch an event "NPC 1 chooses this" and have a bunch of followup systems run afterward, before "NPC 2 chooses this" occurs.

I've also tried just not caring about where (e.g.) NPC 1's actions may invalidate NPC 2's actions, but this is starting to drive my game design ("oh, this is going to make bugs, let's do something else") in a way that I don't like.

Additional context

Nothing obvious comes to mind

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-ExamplesAn addition or correction to our examplesC-UsabilityA targeted quality-of-life change that makes Bevy easier to use

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions