Coding 2020-07-06

By Max Woerner Chase

I started trying to rewrite Dennis's ECS implementation using attrs and pyrsistent in a new monorepo.

I feel like it might be helpful to explain what all that means and why I'm doing it.

Dennis is what I called my project to rework the implementation of the roguelike from TStand90's roguelike tutorials in line with my own preferences. It leans a lot on some features of Coconut, which I'll probably end up replacing with attrs somehow. It's called Dennis because it's an adventure game, kind of, and the implementation is in Coconut, which is a reference to Monty Python and the Holy Grail.

Part of the rework involved redoing the implementation of the ECS, or entity component system. The idea of an entity component system is that, instead of creating a distinct class for each "kind of thing" (something like PositionedFactionBasedSizedMonsterWithAI), there's just one "kind of thing" called an entity, which can have "components" associated with it (which, in the example given, would be something like "Position", "Faction", "Size", "Statblock", "AI"). Dennis represents entities as a simple opaque identifier (using a system that can be simplified in the current rewrite), and component instances are stored in mappings from those identifiers.

In Dennis, the master data structure for the ECS is mutable, and the implementation makes heavy use of Coconut's "data" classes. In the current rewrite, the data structures are all immutable thanks to pyrsistent, and the "frozen" feature from attrs.

The rewrite is taking place in a new version control repository that will contain the source for multiple Python packages, which will be developed in tandem. The basic idea is that, where Dennis had a single ECS module, I'm now trying to put that into an ECS package, which should hopefully be easier to reuse in other applications. Just add a package to the monorepo that defines an entry point for execution, and I can have it pick and choose from the packages in the monorepo. Part of what I plan to do is rewrite Dennis into the monorepo, so I can better reuse the work I already did.

Anyway, that's a bunch of explaining I just did. I should get to bed ASAP, again.

Good night.