Terrarium.Game.GameEngine.CalculateWorldSize C# (CSharp) Метод

CalculateWorldSize() приватный Метод

This routine attempts to figure out how fast the machine is by running some standardized tests to test code execution speed. It then uses this information to determine how big the Terrarium world should be on this machine to maintain a decent frame rate. It also determines how big of a time slice we should give each animal.
private CalculateWorldSize ( ) : void
Результат void
        private void CalculateWorldSize()
        {
            const int Modifier = 40;

            // We need to get all the objects loaded and initialized.
            OrganismQuanta.TestAnimal(10);

            // Run tests
            OrganismQuanta.Clear();
            OrganismQuanta.TestAnimal(100);

            Trace.WriteLine(String.Format("Total {0}, Last {1}, Best {2}, Worst {3}, Average {4}",
                                          new Object[]
                                              {
                                                  OrganismQuanta.totalQuanta*Modifier,
                                                  OrganismQuanta.lastQuanta*Modifier,
                                                  OrganismQuanta.bestQuanta*Modifier,
                                                  OrganismQuanta.worstQuanta*Modifier,
                                                  (OrganismQuanta.totalQuanta*Modifier/OrganismQuanta.samples)
                                              }
                                ));

            // Figure out how much of a time slice to give each animal
            _organismQuanta = (int) (OrganismQuanta.totalQuanta/OrganismQuanta.samples);
            if (_organismQuanta < 500)
            {
                _organismQuanta *= Modifier;
            }
            Debug.Assert(_organismQuanta < EngineSettings.OrganismSchedulingMaximumOvertime,
                         "The computer is too slow to run Terrarium or obtained bad results from OrganismQuanta");

            estimateNumberOfAnimalsToSupport();
            computeWorldHeight();

            // We only need to normalize to GridCellHeight and GridCellWidth.  The
            // game view may add some extra pixels on the bottom and right of the
            // screen for tiling purposes, but this never hurts the game.  In this
            // way we don't need to know the size of the world tiles in the game
            // engine.
            if (_worldWidth%EngineSettings.GridCellWidth != 0)
            {
                _worldWidth += EngineSettings.GridCellWidth - (_worldWidth%EngineSettings.GridCellWidth);
            }

            if (_worldHeight%EngineSettings.GridCellHeight != 0)
            {
                _worldHeight += EngineSettings.GridCellHeight - (_worldHeight%EngineSettings.GridCellHeight);
            }

            // Worldheight and Height must be evenly divisible by our grid cells
            Debug.Assert(WorldHeight%EngineSettings.GridCellHeight == 0 &&
                         WorldWidth%EngineSettings.GridCellWidth == 0);

            // if we actually calculate it, tell the engine not to redo it since it only needs to be done once
            // if this gets changed because we load a file, we'll do it again
            _reloadSettings = false;
        }