Stack Based ECS


When analyzing which entities and components I would need to implement the game, something very quickly became apparent: I’d need some kind of state machine to keep track of what can happen when.

Now, in ECS there are multiple ways to achieve this, but I ended up with what I call “Stack-based ECS”:

Stack-Based ECS

  • There is a stack of states
  • States have a start and end function
  • States have a list of systems
  • The systems of the stack are executed from bottom to top
  • States can be pushed and popped off the stack
  • States can be paused (systems don’t run)

To explain how it works I’ll use an example from the game:

First, the game is in the “Match” state, which is where a game of Access Battlers happens:

Initially, we are in the setup phase, where the AI starts placing cards:

The stack:

  • AI Setup [AI Setup system]
  • Setup [Setup system]
  • Match [Render system, Music system, Match system]

After the AI finishes, the AI state is popped off, and it’s the players turn:

  • Player Setup [Player Setup]
  • Setup [Setup system]
  • Match [Render system, Music system, Match system]

When the player is done, the Match system pops the Setup state, and moves on to the next.

Wrapping Up

It’s midnight, my goal was to get good regular sleep so I’ve certainly failed at that. But I’d really like to keep these blog posts up, so there you have it!

Get TIC-80: Access Battlers

Leave a comment

Log in with itch.io to leave a comment.