A better RPG data system for mass entities
I was reading through fluent python today, and I was looking at the chapter involving sets. For those not in the know, sets are a programming data structure (and mathematical topic, you might’ve heard of 'set theory') and they’re used when you want to quickly find if something EXISTS in a certain category. It’s like searching up if a user has an account, vs pulling up their account and returning an error (the former is faster than the latter).
I was thinking, because I’ve been working on a rogue-like recently, and one of the things that’s on my mind is the quick iteration over multiple entities. I want to create a game with 10,000 characters (representing a country), and have each of them with their own goals and personalities. Of course, a complete simulation done turn-by-turn is going to be computationally expensive. I want to find a way to do it quicker.
One of the key fields in the game is the "temporary emotion" struct - which has an array of tags (happy, fearful, jealous, etc. etc.). So, when we iterate over each character, we’d use an if statement to see what tags are present - then apply behavior.
Instead - we can utilize data oriented design and set-based design. So, we’d iterate through an array of happy[Character], sad[Character] instead of doing the tags (I hope that makes sense). We can do simple existence checks to see if the character is in that specific personality array, and if they are, we perform the behavior and adjust the goals. No if statements.
Just a thought.