Beispiel #1
0
        public void Generate()
        {
            using (Instrumenter.Start())
            {
                _missCounter = 0;

                MapGenerationData.Instance = MapGenerationData;

                var seed = MapGenerationData.Instance.Seed.GetHashCode();
                _size = MapGenerationData.Instance.MapSize * MapGenerationData.Instance.ChunkSize;

                _heightMap      = GetHeightMap(seed);
                _temperatureMap = GetTemperatureMap();
                _moistureMap    = GetMoistureMap(seed);

                _cells = GetCells();

                DrawChunks();

                Debug.Log($"Miss: {_missCounter}/{_size * _size}");

                Camera.ConfigureMinMax(0, _size, 0, (int)(_size * 1.5f));
                Camera.MoveToWorldCenter();
            }
        }
        public List <ChunkCell> Resolve()
        {
            using (Instrumenter.Start())
            {
                Reset();
                AddCellToFrontier(_origin);

                while (_searchFrontier.Count > 0)
                {
                    _iterations++;
                    if (_iterations > _maxIterations)
                    {
                        throw new OverflowException($"Search area too large > {_maxIterations} reached!");
                    }

                    var cell = _searchFrontier.Dequeue();
                    if (_search(cell))
                    {
                        _matches.Add(cell);
                        AddNeighboursToSearchFrontier(cell);
                    }
                }
            }

            return(_matches.ToList());
        }
Beispiel #3
0
 public void CreateMesh(ChunkCell[,] cells)
 {
     using (Instrumenter.Start())
     {
         GenerateMesh(cells);
     }
 }
Beispiel #4
0
        public static Texture2D CreateTextureFromColorMap(int width, int height, Color[,] color)
        {
            using (Instrumenter.Start())
            {
                var texture = new Texture2D(width, height)
                {
                    filterMode = FilterMode.Point,
                    wrapMode   = TextureWrapMode.Clamp
                };
                var pixels = new Color[width * height];

                var i = 0;
                for (var y = 0; y < height; y++)
                {
                    for (var x = 0; x < width; x++)
                    {
                        pixels[i] = color[x, y];
                        i++;
                    }
                }
                texture.SetPixels(pixels);
                texture.Apply();
                File.WriteAllBytes($@"C:\ext\tex\{DateTime.Now.Ticks}.png", texture.EncodeToPNG());

                return(texture);
            }
        }
Beispiel #5
0
    public void RegenerateMap()
    {
        using (Instrumenter.Start())
        {
            var mapSize = GetMapSize();
            map = new Cell[mapSize, mapSize];

            var noise = new FastNoiseLite(Guid.NewGuid().GetHashCode());
            noise.SetNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
            noise.SetFrequency(0.01f);
            noise.SetFractalType(FastNoiseLite.FractalType.FBm);

            var height = noise.GetNoiseMap(mapSize);
            for (var x = 0; x < mapSize; x++)
            {
                for (var z = 0; z < mapSize; z++)
                {
                    var cellHeight = height[x, z] * 20f;

                    if (cellHeight <= 0)
                    {
                        cellHeight = 0;
                    }

                    Color color;
                    if (cellHeight > 9)
                    {
                        color = Color.white;
                    }
                    else if (cellHeight > 7)
                    {
                        color = Color.grey;
                    }
                    else if (cellHeight > 5)
                    {
                        color = ColorExtensions.GetColorFromHex("2d6a4f");
                    }
                    else if (cellHeight > 2)
                    {
                        color = ColorExtensions.GetColorFromHex("52b788");
                    }
                    else if (cellHeight > 0)
                    {
                        color = Color.yellow;
                    }
                    else
                    {
                        color = Color.blue;
                    }

                    map[x, z] = new Cell(x, z, cellHeight, color);
                }
            }

            Locate <ChunkManager>().RenderCells(map);
        }
    }
Beispiel #6
0
 public void InitializeServices()
 {
     foreach (var service in _services)
     {
         using (Instrumenter.Start(service.Key))
         {
             service.Value.Initialize();
         }
     }
 }
Beispiel #7
0
 // Start is called before the first frame update
 private void Start()
 {
     using (Instrumenter.Start())
     {
         for (int i = 0; i < Amount; i++)
         {
             var obj = Instantiate(ObjectToSpawn, transform);
             obj.transform.localPosition = new Vector3(Random.Range(1f, 100f), Random.Range(1f, 100f), Random.Range(1f, 100f));
         }
     }
 }
 public void ProcessInitializationQueue()
 {
     while (_initializationQueue.Count > 0)
     {
         var nextItem = _initializationQueue.Dequeue();
         var name     = nextItem.GetType().Name;
         using (Instrumenter.Start(name))
         {
             InitializeService(name, nextItem);
         }
     }
 }
Beispiel #9
0
        public IEnumerator ProcessServiceList()
        {
            foreach (var item in _services)
            {
                using (Instrumenter.Start(item.Key.Name))
                {
                    item.Value.Initialize();
                    _readyServices.Add(item.Key);
                    yield return(null);
                }
            }

            LogServices();
        }
Beispiel #10
0
        public List <IStructure> GetStructuresLinkedTo(IStructure structure)
        {
            var network = new List <IStructure>();

            using (Instrumenter.Start())
            {
                var frontier = new Queue <Coord>();
                frontier.Enqueue(structure.Coord);

                var closed = new List <Coord>();
                while (frontier.Count > 0)
                {
                    var current = frontier.Dequeue();
                    if (closed.Contains(current))
                    {
                        continue;
                    }
                    closed.Add(current);

                    if (TryGetStructureAtCoord(current, out IStructure linkedStructure))
                    {
                        if (!network.Contains(linkedStructure))
                        {
                            network.Add(linkedStructure);
                        }

                        if (linkedStructure.Type == StructureDefinition.StructureType.Road || linkedStructure.Type == StructureDefinition.StructureType.Core)
                        {
                            if (_mapManager.TryGetCellAtCoord(linkedStructure.Coord, out Cell cell))
                            {
                                foreach (var linkedCell in cell.GetCardinalNeighbours())
                                {
                                    if (!closed.Contains(linkedCell.Coord))
                                    {
                                        frontier.Enqueue(linkedCell.Coord);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(network);
        }