Terrarium.Game.GameEngine.estimateNumberOfAnimalsToSupport C# (CSharp) Method

estimateNumberOfAnimalsToSupport() private static method

This is where we attempt to estimate how many animals we can support on this machine. We assume we want 20 frames a second and we do two engine ticks per second which means we have 500 msec per engine tick. We budget our paint time 200 mSec, and that leaves 300 mSec for all engine processing. We assume we'll allocate 4/5 of our available engine processing time to running animals, and 1/5 to plants. organismQuanta is how many microseconds each animal will get, so we have to divide by 1000 to get milliseconds. We assume that we can use all engine processing time for running animals although this isn't strictly true since we need to run the engine code too. It's OK, because animals can't use all their allocated time every tick -- they'll eventually get killed. Thus, we use the time they don't use for the engine processing. It's all basically an estimate, that we've tuned and works pretty well.
private static estimateNumberOfAnimalsToSupport ( ) : void
return void
        private static void estimateNumberOfAnimalsToSupport()
        {
            float baseTime = (300/5)/((_organismQuanta)/((float) 1000));
            _maxAnimals = (int) (baseTime*4);
            _maxAnimals = (int) (_maxAnimals*(GameConfig.CpuThrottle/(double) 100));
            _maxPlants = _maxAnimals;
        }