- DEMOCRACY 3 CRASHES ON NEW GAME MANUAL
- DEMOCRACY 3 CRASHES ON NEW GAME CODE
- DEMOCRACY 3 CRASHES ON NEW GAME FREE
Its fast enough for most cases, but its WAY slower than just accessing the value of a floating point number thats already in RAM, and cached happily in the equation processor itself. I was still storing variables as ‘0’ instead of just 0. But one thing I had not done is store the atof() outcomes. I parse them equation on startup, and stick the various values into buckets, so I am not wasting time each turn.
DEMOCRACY 3 CRASHES ON NEW GAME MANUAL
I actually did know to look into this, and I do not do manual text parsing of the equation each time. This is the key to a roughly 33% speedup of the whole processing in the game. That * is going to remain * and that 0 and 0.22 will remain fixed too. I do not know what the current value of x or GDP is, so I will need to grab their pointers and query them when I process the equation, but the rest of that stuff is static.
Looking back at the equation above (OilPrice,0+(0.22*x)*GDP) there is obviously some stuff in there which is volatile.
DEMOCRACY 3 CRASHES ON NEW GAME CODE
But the fastest code is code that never runs.’.Īll those calls to atof are absolute nonsense. No way are you are going to be able to make that code faster’, to which I reply ‘dude, obviously not. Now, you may think ‘dude, atof is pretty standard. This is a HUGE chunk of the whole equation processing code. Thats a low level c runtime function, not one of mine, and it seems to be slowing down everything. Lots of stuff goes on, but what I immediately noticed was all this atof stuff. This is showing the code inside that 30-turn pre-game processing called PreCalcCoreSimulation.
Its not recognizing my ultra-amazing new chip, so only doing usermode sampling, but nonetheless it draws pretty flame charts like this: Before I optimised
DEMOCRACY 3 CRASHES ON NEW GAME FREE
I just installed a new version of the free vtune profiler from intel. Thus, if the equation processor is slow, its all slow. The Equation processor runs each turn, on every neural effect, and there are LOTS of them. They contain basically the names of a host and a target (resolved to actual C++ pointers to objects), and an equation explaining the connection, and some other housekeeping stuff.Īt the heart of it all, is an equation processor which lets you write this:Īnd actually turn it into a value for that effect, given the current situation. Those connections to neurons should probably be called dendrites or whatever, but I call them SIM_NeuralEffect. You can run through the inputs and outputs, process the values and get a current value for a neuron at any time, which is done for every one of them, every turn.Īlso… when we start a new game, I need ‘historical’ data for each value, so the game pre-processes the whole simulation about 30 times before you start to give us meaningful background data, and to ensure the current simulation sits as a reasonable equilibrium. Without going into tons of details, every object in the game (policy, dilemma option, voter, voter group, situation…) is modeled as a neuron, which is basically just a named object connected by a ton of inputs and outputs to other neurons. It kind of makes me look a bit like an idiot to admit this is a big speedup (I should have known), but anyway, knowledge sharing (especially on optimization) is always good.įundamentally, the code in Democracy 4 is structured like a neural network. I just made a major speedup to the loading/next turn/new game code in Democracy 4, and thought I may as well share the gains with readers of this blog :D.