I’m halfway through the code changes to faction cultural attributes and it is a huge mess…

Just to give an idea of what I’m dealing with, right now, whenever a faction culture is updated, the code will go trough all of the cultural attributes and search for the equivalent attributes in the faction’s core group culture. This requires doing multiple hashtable searches (specifically in the case of c#, dictionary queries). These searches are supposed to be quick, but in practice, each query has a small overhead that rapidly accumulates (we are talking about 500 queries per frame in some instances). The same issue happens when the simulation tries to update a polity’s culture, which requires looking through every member faction’s culture for equivalent properties.

What I’m trying to do is to get rid of all those queries by directly storing on each faction’s attribute references to its equivalent core group and polity attributes. The problem is that I have to make sure those references are set up correctly and kept up to date at all times. However, there are many operations that frequently screw-up with those references (core group migrations, tribe splits/merges, etc). This is the headache-inducing part of the problem and the one that it’s taking longer to work out.

Hopefully I can get done with this by next week. But there’s a big chance this modification will break a lot of things and take even longer to get it to work. I really hope I get to reduce CPU usage by another 5% at least. But if it doesn’t… it’ll be a learning experience.