Ejemplo n.º 1
0
        private void _generateTerrain()
        {
            try
            {
                IGenerator generator = null;

                switch (_configurationManager.Algorithm)
                {
                case GeneratorAlgorithm.PerlinNoise:
                    generator = new PerlinNoiseGenerator(GraphicsDevice, Graphics, _configurationManager.Parameters);
                    break;

                case GeneratorAlgorithm.Hill:
                    generator = new HillAlgorithmGenerator(GraphicsDevice, Graphics, _configurationManager.Parameters);
                    break;

                case GeneratorAlgorithm.Random:
                    generator = new RandomGenerator(GraphicsDevice, Graphics, _configurationManager.Parameters);
                    break;

                case GeneratorAlgorithm.Rectangle:
                    generator = new RectangleGenerator(GraphicsDevice, Graphics, _configurationManager.Parameters);
                    break;

                case GeneratorAlgorithm.Voronoi:
                    generator = new VoronoiGenerator(GraphicsDevice, Graphics, _configurationManager.Parameters);
                    break;

                case GeneratorAlgorithm.SimplexNoise:
                    generator = new SimplexNoise(GraphicsDevice, Graphics, _configurationManager.Parameters);
                    break;

                case GeneratorAlgorithm.DiamondSquare:
                    generator = new DiamondSquareGenerator(GraphicsDevice, Graphics, _configurationManager.Parameters);
                    break;

                case GeneratorAlgorithm.RandomWalk:
                    generator = new RandomWalkGenerator(GraphicsDevice, Graphics, _configurationManager.Parameters);
                    break;

                case GeneratorAlgorithm.DrunkardWalk:
                    generator = new DrunkardWalk(GraphicsDevice, Graphics, _configurationManager.Parameters);
                    break;

                default:
                    throw new NotImplementedException("Unknown algorithm");
                }
                if (generator == null)
                {
                    throw new NullReferenceException("Generator cannot be null");
                }

                var timeStart = System.DateTime.Now;
                Scene.AddObjectToRender(generator.Generate());
                Logger.Log.Info("Generated time = " + (DateTime.Now - timeStart).TotalMilliseconds + " ms for " + _configurationManager.Algorithm.ToString());
            }
            catch (Exception e)
            {
                Logger.Log.Error(e);
                throw;
            }
        }