This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
I consider a roguelike to be a complicated-enough genre to warrant the use of the Entity-Component-System (ECS) approach. This means that entities have a composition rather than inheritence see wikipedia.
I've used this pattern successfully when developing basic games like Asteroids, and of course ECS is used extensively in engines like Unity and Unreal, whose games are mostly real-time.
In such real-time games, it's easy to see how ECS entities and their ECS components can be updated via ECS systems. Imagine I have a position component that describes an entity's position in the game world, and a movement system that updates all position components, making entities move around. In a real-time game, you would normally execute the movement system once per frame.
It's easy to see why this scheme breaks down in turn-based games. In the roguelike I'm making, for example, each character has a turn, and during their turn they decide how they will act. Actions such as movement have an energy cost. If two different entities are walking around and have a different energy cost for movement, then each time the slower entity moves, the faster entity may move a variable amount of spaces, depending on the ratio of their costs. This system is described very well in this article, along with some great interactive examples. I believe the same system is used in Angband and Dwarf Fortress.
An ESC System will normally update all entities that match its component definition. This isn't possible in a turn-based game, because you don't want to be updating entities when it isn't their turn yet.
The simplest solution I can see is to loop through all entities (as the game loop), and call whichever systems match their component definition. What this means is that my ECS Systems won't be grouping together like-components. Instead, I will need to actually inspect the entity whose turn it currently is, to find out what components they have that might need updating, and then call the right 'systems' manually, passing through the relevant components. I imagine this may lead to a performance hit, especially if my game allows for many micro-actions to take place (e.g. player moves 1 tile, and many turns go by for other entities doing small things, or for an arrow shooting through the air).
Has anyone used this approach? What other ways are there to use ECS in roguelikes?
Subreddit
Post Details
- Posted
- 7 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/roguelikede...