Gamedev in Lisp. Part 1: ECS and Metalinguistic Abstraction
awkravchuk.itch.io
awkravchuk.itch.io
Components were just a key in my game state hash map, which used immutable data, so if something said it only read (but didn't write) a component, but it was lying, there would be no bug - the core is responsible for actual updates returned from systems, not the systems themselves.
But then... where do you stick "globals"? Sometimes systems need access to common non-component data. You could hack it and stick it in components, which felt weird.
So I kinda changed my design. Now, at the core, I have systems. And systems declare what keys in game state it needs, similar to how they did with components. But it doesn't have to be only for components. It can be any key or "key path" (nested maps). And systems are automatically ran concurrently based upon this.
I happen to arrange entity data as components, because that increases the concurrency of the systems. But it doesn't have to. Sometimes I split things up for the sake of concurrency.
This is also really easy to test. You just have functions that take data spitting out data.
Common Lisp is probably my favorite language so I bookmarked this to use when I get home from traveling.
What did you do for Nintendo and Disney?
Because doing VR in theate 90s sounds super interesting!
One thing I've always wondered about ecs is if you just focused on the array and looping part and instead ignored the component part. Seems a lot simpler over all amd is probably faster too because you're not doing a bunch of branches on components.
If your entities are more heterogenous or don't need to be running all the time the benefit for gameplay code disappears quite quickly. In particular the acronym conception of ECS architecture isn't the most performant way of organizing things. Which is why you end up with concepts like archetypes to base memory organization around.
Nothing wrong if you're writing a general-purpose engine around ECS as an organizational principle but for game makers you still need to think about memory access patterns and how to organize around that.
If you're just trying to make a game then make the game and organize the game data around it's unique access patterns. If that's just a flat array of tagged unions then who cares.
- commercial games getting too big for any one single person to keep track of all those widgets getting developed in parallel
- engines being developed as standalone generic projects to be used in many, many games that need solid abstractions
- enough RAM to justify the overhead (whole megabytes! Scandalous!)
...then ECS starts making a lot of sense. That was in the late 90s/early 00s, and these days the (performance) overhead is negligible even for indie game dev. The only potential downside is the cognitive overhead, but that very much depends on what you're doing.
Historic reminder: Forth was making games using DSLs long ago. In the days of Kilo-byte memory spaces, it was a strategic advantage, IF you created a good DSL.
I prefer testing and so typically avoid singletons, but I do acknowledge the pros of thinking of games as a series of “managers” telling things how to behave. Enough to appreciate that thinking of a game as centralized set of manager systems is kinda the basis of ECS.
Throwing this out there in case anyone in this community has interesting thoughts on the subject!
Games generally are inherently a complex system all interacting with a global state.
So whether you’re making a singleton class, a regular global variable, or averting your gaze while passing a massive state variable to every single function, you can’t escape it.
Entirely unrelated to the post? Entirely? The post talks:
"To write Common Lisp code with comfort and still have the ability to interact with REPL, you can choose your favorite IDE"
And then it goes on to provide some recommendations for major editors out there. So the GP is at least a little related to the post?
I did not get the impression of any flame war in the GP. As a Emacs user myself I am well aware that everyone does not like to use Emacs. Many like Vim. I don't see the problem with recommending a Vim setup for Lisp. We need more recommendations like that for different editors to make Lisp programming more attractive to people of all types of technical background.