示例#1
0
        /// <summary>
        /// Saves all current objects to disk (POSSIBLE REWORK NEEDED)
        /// </summary>
        public void SaveChanges()
        {
            List <ObjectPoint> objectPoints = new List <ObjectPoint>();

            foreach (var chunkPart in DataMap.ChunkParts)
            {
                objectPoints.AddRange(chunkPart.Value.ObjectPoints.Values);
            }

            ObjectMapLoader.SaveObjectMap(this, objectPoints.ToArray(), SaveDataManager.WorldDataPath);
        }
示例#2
0
        public static ObjectPoint[] CreateObjectPoints(int uniformSize, MeshSettings meshSettings, ResourceMapSettings resourceMapSettings, BiomeMap biomeMap, HeightMap heightMap, TerrainChunk terrainChunk)
        {
            string fileName = $"chunkInfo{terrainChunk.Coord.x}{terrainChunk.Coord.y}.dat";

            // Try to load a save file
            if (File.Exists(SaveDataManager.WorldDataPath + fileName))
            {
                return(ObjectMapLoader.LoadObjectMap(terrainChunk, SaveDataManager.WorldDataPath).ObjectPoints);
            }
            else
            {
                //ResourceMap resourceMap = ResourceMapGenerator.GenerateResourceMap(uniformSize, resourceMapSettings, terrainChunk.SampleCenter);

                ResourceMap resourceMap = ResourceMapGenerator.GenerateResourceMap(uniformSize, resourceMapSettings, terrainChunk.SampleCenter, biomeMap, heightMap);

                List <ObjectPoint> tempObjectPoints = new List <ObjectPoint>();

                // Resource points to object points
                foreach (var resourcePoint in resourceMap.resourcePoints)
                {
                    int x = resourcePoint.x;
                    int z = resourcePoint.z;

                    HeightMapLayer layer = heightMap.GetLayer(x + 1, z + 1);

                    // Don't spawn objects on water.
                    if (layer.IsWater)
                    {
                        continue;
                    }

                    float   height   = heightMap.Values[x + 1, z + 1];
                    Vector3 position = new Vector3(terrainChunk.Bounds.center.x, 0f, terrainChunk.Bounds.center.y) + new Vector3((x - (uniformSize - 1) / 2f) * meshSettings.MeshScale, height, (z - (uniformSize - 1) / 2f) * -meshSettings.MeshScale);

                    // Create a seeded System.Random for the rotation based on the position
                    float         a    = position.x + position.y;
                    float         b    = position.z + position.y;
                    System.Random rand = new System.Random((int)(0.5 * (a + b) * (a + b + 1) + b));

                    Quaternion rotation = Quaternion.Euler(new Vector3(0f, rand.Next(0, 360), 0f));

                    int chunkPartSize = uniformSize / meshSettings.ChunkPartSizeRoot + 1;
                    int coordX        = Mathf.FloorToInt(x / chunkPartSize) - 1;
                    int coordZ        = Mathf.FloorToInt(z / chunkPartSize) - 1;

                    Vector2 chunkPartCoords = terrainChunk.Coord * meshSettings.ChunkPartSizeRoot + new Vector2(coordX, -coordZ);

                    tempObjectPoints.Add(new ObjectPoint(position, rotation, resourcePoint.biomeId, resourcePoint.worldResourcePrefabId, chunkPartCoords.x, chunkPartCoords.y));
                }

                return(tempObjectPoints.ToArray());
            }
        }