Exemplo n.º 1
0
        public static bool FloodFillAndAddCells(RegionMaker __instance, IntVec3 root)
        {
            Region newReg = __instance.newReg;
            Map    map    = __instance.map;

            __instance.newRegCells = new List <IntVec3>();
            if (newReg.type.IsOneCellRegion())
            {
                if (!RegionAndRoomUpdater_Patch.cellsWithNewRegions.Contains(root))
                {
                    RegionAndRoomUpdater_Patch.cellsWithNewRegions.Add(root);
                    __instance.AddCell(root);
                }

                return(false);
            }

            map.floodFiller.FloodFill(root, x => newReg.extentsLimit.Contains(x) && x.GetExpectedRegionType(map) == newReg.type, delegate(IntVec3 x)
            {
                if (!RegionAndRoomUpdater_Patch.cellsWithNewRegions.Contains(x))
                {
                    RegionAndRoomUpdater_Patch.cellsWithNewRegions.Add(x);
                    __instance.AddCell(x);
                }
            });
            return(false);
        }
Exemplo n.º 2
0
    void UpdateRegionPositions(WorldMap map)
    {
        if (!GameSettings.Instance.rendering.drawDistantTerrain)
        {
            return;
        }

        foreach (var item in DetailRegions)
        {
            RegionMaker region = item.Value;
            region.SetPosition(map);
        }
    }
Exemplo n.º 3
0
 void GenerateRegionMeshes()
 {
     foreach (WorldMap map in regionMaps.world_maps)
     {
         DFCoord2d pos = new DFCoord2d(map.map_x, map.map_y);
         if (DetailRegions.ContainsKey(pos))
         {
             //Debug.Log("Region exists: " + pos.x + ", " + pos.y);
             continue;
         }
         RegionMaker region = Instantiate <RegionMaker>(regionPrefab);
         region.CopyFromRemote(map, DFConnection.Instance.NetMapInfo);
         region.name             = region.worldNameEnglish;
         region.transform.parent = transform;
         DetailRegions[pos]      = region;
     }
 }
Exemplo n.º 4
0
        public static bool CreateLinks(RegionMaker __instance)
        {
            HashSet <IntVec3>[] linksProcessedAt = __instance.linksProcessedAt;
            List <IntVec3>      newRegCells      = __instance.newRegCells;

            for (int i = 0; i < linksProcessedAt.Length; i++)
            {
                linksProcessedAt[i] = new HashSet <IntVec3>();
            }

            for (int j = 0; j < newRegCells.Count; j++)
            {
                IntVec3 c = newRegCells[j];
                __instance.SweepInTwoDirectionsAndTryToCreateLink(Rot4.North, c);
                __instance.SweepInTwoDirectionsAndTryToCreateLink(Rot4.South, c);
                __instance.SweepInTwoDirectionsAndTryToCreateLink(Rot4.East, c);
                __instance.SweepInTwoDirectionsAndTryToCreateLink(Rot4.West, c);
            }
            return(false);
        }
Exemplo n.º 5
0
    void GenerateRegionMeshes()
    {
        if (!GameSettings.Instance.rendering.drawDistantTerrain)
        {
            return;
        }

        foreach (WorldMap map in regionMaps.world_maps)
        {
            DFCoord2d pos = new DFCoord2d(map.map_x, map.map_y);
            if (DetailRegions.ContainsKey(pos))
            {
                continue;
            }
            RegionMaker region = Instantiate <RegionMaker>(regionPrefab);
            region.CopyFromRemote(map, worldMap);
            region.name             = region.worldNameEnglish;
            region.transform.parent = transform;
            DetailRegions[pos]      = region;
        }
    }
Exemplo n.º 6
0
    void GenerateMesh()
    {
        if (width == 1 && height == 1)
        {
            return;
        }
        int            length    = width * height * 4;
        List <Vector3> vertices  = new List <Vector3>(length);
        List <Color>   colors    = new List <Color>(length);
        List <Vector2> uvs       = new List <Vector2>(length);
        List <Vector2> uv2s      = new List <Vector2>(length);
        List <int>     triangles = new List <int>(length);

        List <Vector3> waterVerts = new List <Vector3>();
        List <Vector2> waterUvs   = new List <Vector2>();
        List <int>     waterTris  = new List <int>();

        foreach (MeshFilter mf in terrainChunks)
        {
            if (mf.mesh != null)
            {
                mf.mesh.Clear();
            }
        }
        foreach (MeshFilter mf in waterChunks)
        {
            if (mf.mesh != null)
            {
                mf.mesh.Clear();
            }
        }

        int chunkIndex      = 0;
        int waterChunkIndex = 0;

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                if (DetailRegions.ContainsKey(new DFCoord2d(x, y)))
                {
                    continue;
                }

                //If the vertex lists are already full, make a chunk with what we have, and keep going
                if (vertices.Count >= (65535 - 20))
                {
                    if (terrainChunks.Count <= chunkIndex)
                    {
                        terrainChunks.Add(Instantiate <MeshFilter>(terrainPrefab));
                        terrainChunks[chunkIndex].transform.parent = transform;
                        terrainChunks[chunkIndex].gameObject.name  = "TerrainChunk" + chunkIndex;
                    }
                    MeshFilter mf = terrainChunks[chunkIndex];

                    if (mf.mesh == null)
                    {
                        mf.mesh = new Mesh();
                    }

                    Mesh terrainMesh = mf.mesh;

                    terrainMesh.vertices  = vertices.ToArray();
                    terrainMesh.colors    = colors.ToArray();
                    terrainMesh.uv        = uvs.ToArray();
                    terrainMesh.uv2       = uv2s.ToArray();
                    terrainMesh.triangles = triangles.ToArray();

                    terrainMesh.RecalculateNormals();
                    terrainMesh.RecalculateTangents();

                    mf.mesh = terrainMesh;

                    vertices.Clear();
                    colors.Clear();
                    uvs.Clear();
                    uv2s.Clear();
                    triangles.Clear();
                    chunkIndex++;
                }

                //If the vertex lists are already full, make a chunk with what we have, and keep going
                if (waterVerts.Count >= (65535 - 20))
                {
                    if (waterChunks.Count <= waterChunkIndex)
                    {
                        waterChunks.Add(Instantiate <MeshFilter>(waterPrefab));
                        waterChunks[waterChunkIndex].transform.parent = transform;
                        waterChunks[waterChunkIndex].gameObject.name  = "WaterChunk" + waterChunkIndex;
                    }
                    MeshFilter mf = waterChunks[waterChunkIndex];

                    if (mf.mesh == null)
                    {
                        mf.mesh = new Mesh();
                    }

                    Mesh waterMesh = mf.mesh;

                    waterMesh.vertices  = waterVerts.ToArray();
                    waterMesh.uv        = waterUvs.ToArray();
                    waterMesh.triangles = waterTris.ToArray();

                    waterMesh.RecalculateNormals();
                    waterMesh.RecalculateTangents();

                    mf.mesh = waterMesh;

                    waterVerts.Clear();
                    waterUvs.Clear();
                    waterTris.Clear();
                    waterChunkIndex++;
                }



                Vector2 biome = new Vector2(rainfall[x, y], 100 - drainage[x, y]) / 100;

                Vector3 vert1 = (new Vector3(x * 48 * 16 * GameMap.tileWidth, elevation[x, y] * GameMap.tileHeight, -y * 48 * 16 * GameMap.tileWidth) + offset) * scale;
                Vector3 vert2 = (new Vector3((x + 1) * 48 * 16 * GameMap.tileWidth, elevation[x, y] * GameMap.tileHeight, -(y + 1) * 48 * 16 * GameMap.tileWidth) + offset) * scale;


                RegionMaker.AddHorizontalQuad(vert1, vert2, biome, Color.white, vertices, colors, uvs, uv2s, triangles);

                if (elevation[x, y] < water_elevation[x, y])
                {
                    vert1 = (new Vector3(x * 48 * 16 * GameMap.tileWidth, water_elevation[x, y] * GameMap.tileHeight, -y * 48 * 16 * GameMap.tileWidth) + offset) * scale;
                    vert2 = (new Vector3((x + 1) * 48 * 16 * GameMap.tileWidth, water_elevation[x, y] * GameMap.tileHeight, -(y + 1) * 48 * 16 * GameMap.tileWidth) + offset) * scale;

                    RegionMaker.AddHorizontalQuad(vert1, vert2, biome, Color.white, waterVerts, null, waterUvs, null, waterTris);
                }

                int north = 0;
                if (y > 0 && !DetailRegions.ContainsKey(new DFCoord2d(x, y - 1)))
                {
                    north = elevation[x, y - 1];
                }
                if (north < elevation[x, y])
                {
                    vert1 = (new Vector3(x * 48 * 16 * GameMap.tileWidth, elevation[x, y] * GameMap.tileHeight, -y * 48 * 16 * GameMap.tileWidth) + offset) * scale;
                    vert2 = (new Vector3((x + 1) * 48 * 16 * GameMap.tileWidth, north * GameMap.tileHeight, -y * 48 * 16 * GameMap.tileWidth) + offset) * scale;

                    RegionMaker.AddVerticalQuad(vert1, vert2, biome, Color.white, vertices, colors, uvs, uv2s, triangles);
                }

                int south = 0;
                if (y < height - 1 && !DetailRegions.ContainsKey(new DFCoord2d(x, y + 1)))
                {
                    south = elevation[x, y + 1];
                }
                if (south < elevation[x, y])
                {
                    vert1 = (new Vector3((x + 1) * 48 * 16 * GameMap.tileWidth, elevation[x, y] * GameMap.tileHeight, -(y + 1) * 48 * 16 * GameMap.tileWidth) + offset) * scale;
                    vert2 = (new Vector3(x * 48 * 16 * GameMap.tileWidth, south * GameMap.tileHeight, -(y + 1) * 48 * 16 * GameMap.tileWidth) + offset) * scale;

                    RegionMaker.AddVerticalQuad(vert1, vert2, biome, Color.white, vertices, colors, uvs, uv2s, triangles);
                }

                int east = 0;
                if (x < width - 1 && !DetailRegions.ContainsKey(new DFCoord2d(x + 1, y)))
                {
                    east = elevation[x + 1, y];
                }
                if (east < elevation[x, y])
                {
                    vert1 = (new Vector3((x + 1) * 48 * 16 * GameMap.tileWidth, elevation[x, y] * GameMap.tileHeight, -y * 48 * 16 * GameMap.tileWidth) + offset) * scale;
                    vert2 = (new Vector3((x + 1) * 48 * 16 * GameMap.tileWidth, east * GameMap.tileHeight, -(y + 1) * 48 * 16 * GameMap.tileWidth) + offset) * scale;

                    RegionMaker.AddVerticalQuad(vert1, vert2, biome, Color.white, vertices, colors, uvs, uv2s, triangles);
                }
                int west = 0;
                if (x > 0 && !DetailRegions.ContainsKey(new DFCoord2d(x - 1, y)))
                {
                    west = elevation[x - 1, y];
                }
                if (west < elevation[x, y])
                {
                    vert1 = (new Vector3(x * 48 * 16 * GameMap.tileWidth, elevation[x, y] * GameMap.tileHeight, -(y + 1) * 48 * 16 * GameMap.tileWidth) + offset) * scale;
                    vert2 = (new Vector3(x * 48 * 16 * GameMap.tileWidth, west * GameMap.tileHeight, -y * 48 * 16 * GameMap.tileWidth) + offset) * scale;

                    RegionMaker.AddVerticalQuad(vert1, vert2, biome, Color.white, vertices, colors, uvs, uv2s, triangles);
                }
            }
        }
        {
            if (terrainChunks.Count <= chunkIndex)
            {
                terrainChunks.Add(Instantiate <MeshFilter>(terrainPrefab));
                terrainChunks[chunkIndex].transform.parent = transform;
                terrainChunks[chunkIndex].gameObject.name  = "TerrainChunk" + chunkIndex;
            }
            MeshFilter mf = terrainChunks[chunkIndex];

            if (mf.mesh == null)
            {
                mf.mesh = new Mesh();
            }

            Mesh terrainMesh = mf.mesh;

            terrainMesh.vertices  = vertices.ToArray();
            terrainMesh.colors    = colors.ToArray();
            terrainMesh.uv        = uvs.ToArray();
            terrainMesh.uv2       = uv2s.ToArray();
            terrainMesh.triangles = triangles.ToArray();

            terrainMesh.RecalculateNormals();
            terrainMesh.RecalculateTangents();

            mf.mesh = terrainMesh;
        }

        {
            if (waterChunks.Count <= waterChunkIndex)
            {
                waterChunks.Add(Instantiate <MeshFilter>(waterPrefab));
                waterChunks[waterChunkIndex].transform.parent = transform;
                waterChunks[waterChunkIndex].gameObject.name  = "WaterChunk" + waterChunkIndex;
            }
            MeshFilter mf = waterChunks[waterChunkIndex];

            if (mf.mesh == null)
            {
                mf.mesh = new Mesh();
            }

            Mesh waterMesh = mf.mesh;

            waterMesh.vertices  = waterVerts.ToArray();
            waterMesh.uv        = waterUvs.ToArray();
            waterMesh.triangles = waterTris.ToArray();

            waterMesh.RecalculateNormals();
            waterMesh.RecalculateTangents();

            mf.mesh = waterMesh;

            waterVerts.Clear();
            waterUvs.Clear();
            waterTris.Clear();
            waterChunkIndex++;
        }
    }
Exemplo n.º 7
0
    void GenerateMesh()
    {
        if (width == 1 && height == 1)
        {
            return;
        }
        int            length    = width * height * 4;
        List <Vector3> vertices  = new List <Vector3>(length);
        List <Color>   colors    = new List <Color>(length);
        List <Vector2> uvs       = new List <Vector2>(length);
        List <Vector2> uv2s      = new List <Vector2>(length);
        List <Vector2> uv3s      = new List <Vector2>(length);
        List <int>     triangles = new List <int>(length);

        List <Vector3> waterVerts = new List <Vector3>();
        List <Vector2> waterUvs   = new List <Vector2>();
        List <int>     waterTris  = new List <int>();

        foreach (MeshFilter mf in terrainChunks)
        {
            if (mf.mesh != null)
            {
                mf.mesh.Clear();
            }
        }
        foreach (MeshFilter mf in waterChunks)
        {
            if (mf.mesh != null)
            {
                mf.mesh.Clear();
            }
        }

        chunkIndex      = 0;
        waterChunkIndex = 0;
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                if (DetailRegions.ContainsKey(new DFCoord2d(x, y)))
                {
                    continue;
                }


                //If the vertex lists are already full, make a chunk with what we have, and keep going
                if (vertices.Count >= (65535 - 20))
                {
                    FinalizeGeometryChunk(vertices, colors, uvs, uv2s, uv3s, triangles);
                }

                //If the vertex lists are already full, make a chunk with what we have, and keep going
                if (waterVerts.Count >= (65535 - 20))
                {
                    FinalizeWaterGeometryChunk(waterVerts, waterUvs, waterTris);
                }


                MapDataStore.Tile fakeTile = new MapDataStore.Tile(null, new DFCoord(0, 0, 0));

                fakeTile.material = regionTiles[x, y].surface_material;

                ColorContent colorContent;
                ContentLoader.Instance.ColorConfiguration.GetValue(fakeTile, MeshLayer.StaticMaterial, out colorContent);
                Color terrainColor = colorContent.color;

                Color plantColor   = Color.black;
                float grassPercent = Mathf.Pow(regionTiles[x, y].vegetation / 100.0f, 0.25F);
                float treePercent  = Mathf.Pow(regionTiles[x, y].vegetation / 100.0f, 0.5F);

                foreach (var item in regionTiles[x, y].plant_materials)
                {
                    fakeTile.material = item;
                    ContentLoader.Instance.ColorConfiguration.GetValue(fakeTile, MeshLayer.StaticMaterial, out colorContent);
                    plantColor += colorContent.color;
                }
                if (regionTiles[x, y].plant_materials.Count == 0)
                {
                    grassPercent = 0;
                }
                else
                {
                    plantColor /= regionTiles[x, y].plant_materials.Count;
                }

                Color treeColor = Color.black;
                int   treeCount = 0;
                foreach (var tree in regionTiles[x, y].tree_materials)
                {
                    int plantIndex = tree.mat_index;
                    if (tree.mat_type != 419 ||
                        DFConnection.Instance.NetPlantRawList == null ||
                        DFConnection.Instance.NetPlantRawList.plant_raws.Count <= plantIndex)
                    {
                        continue;
                    }
                    var treeMat = tree;
                    foreach (var growth in DFConnection.Instance.NetPlantRawList.plant_raws[plantIndex].growths)
                    {
                        int currentTicks = TimeHolder.DisplayedTime.CurrentYearTicks;
                        if ((growth.timing_start != -1 && growth.timing_start > currentTicks) || (growth.timing_end != -1 && growth.timing_end < currentTicks))
                        {
                            continue;
                        }
                        treeMat = growth.mat;
                        break;
                    }
                    fakeTile.material = treeMat;
                    if (ContentLoader.Instance.ColorConfiguration.GetValue(fakeTile, MeshLayer.StaticMaterial, out colorContent))
                    {
                        treeColor += colorContent.color;
                        treeCount++;
                    }
                }
                if (treeCount == 0)
                {
                    treePercent = 0;
                }
                else
                {
                    treeColor /= treeCount;
                }



                terrainColor = Color.Lerp(terrainColor, plantColor, grassPercent);
                terrainColor = Color.Lerp(terrainColor, treeColor, treePercent);

                Vector2 biome = new Vector2(regionTiles[x, y].rainfall, 100 - regionTiles[x, y].drainage) / 100;

                Vector3 vert1 = RegionToUnityCoords(x, y, regionTiles[x, y].elevation);
                Vector3 vert2 = RegionToUnityCoords(x + 1, y + 1, regionTiles[x, y].elevation);

                bool snow = regionTiles[x, y].snow > 0;

                RegionMaker.AddHorizontalQuad(vert1, vert2, biome, terrainColor, vertices, colors, uvs, uv2s, uv3s, triangles, snow);

                if (regionTiles[x, y].elevation < regionTiles[x, y].water_elevation)
                {
                    vert1 = RegionToUnityCoords(x, y, regionTiles[x, y].water_elevation);
                    vert2 = RegionToUnityCoords(x + 1, y + 1, regionTiles[x, y].water_elevation);

                    RegionMaker.AddHorizontalQuad(vert1, vert2, biome, terrainColor, waterVerts, null, waterUvs, null, null, waterTris, false);
                }

                int north = 0;
                if (y > 0 && !DetailRegions.ContainsKey(new DFCoord2d(x, y - 1)))
                {
                    north = regionTiles[x, y - 1].elevation;
                }
                if (north < regionTiles[x, y].elevation)
                {
                    vert1 = (new Vector3(x * 48 * 16 * GameMap.tileWidth, regionTiles[x, y].elevation * GameMap.tileHeight, -y * 48 * 16 * GameMap.tileWidth)) * scale;
                    vert2 = (new Vector3((x + 1) * 48 * 16 * GameMap.tileWidth, north * GameMap.tileHeight, -y * 48 * 16 * GameMap.tileWidth)) * scale;

                    RegionMaker.AddVerticalQuad(vert1, vert2, biome, terrainColor, vertices, colors, uvs, uv2s, uv3s, triangles, snow);
                }

                int south = 0;
                if (y < height - 1 && !DetailRegions.ContainsKey(new DFCoord2d(x, y + 1)))
                {
                    south = regionTiles[x, y + 1].elevation;
                }
                if (south < regionTiles[x, y].elevation)
                {
                    vert1 = (new Vector3((x + 1) * 48 * 16 * GameMap.tileWidth, regionTiles[x, y].elevation * GameMap.tileHeight, -(y + 1) * 48 * 16 * GameMap.tileWidth)) * scale;
                    vert2 = (new Vector3(x * 48 * 16 * GameMap.tileWidth, south * GameMap.tileHeight, -(y + 1) * 48 * 16 * GameMap.tileWidth)) * scale;

                    RegionMaker.AddVerticalQuad(vert1, vert2, biome, terrainColor, vertices, colors, uvs, uv2s, uv3s, triangles, snow);
                }

                int east = 0;
                if (x < width - 1 && !DetailRegions.ContainsKey(new DFCoord2d(x + 1, y)))
                {
                    east = regionTiles[x + 1, y].elevation;
                }
                if (east < regionTiles[x, y].elevation)
                {
                    vert1 = (new Vector3((x + 1) * 48 * 16 * GameMap.tileWidth, regionTiles[x, y].elevation * GameMap.tileHeight, -y * 48 * 16 * GameMap.tileWidth)) * scale;
                    vert2 = (new Vector3((x + 1) * 48 * 16 * GameMap.tileWidth, east * GameMap.tileHeight, -(y + 1) * 48 * 16 * GameMap.tileWidth)) * scale;

                    RegionMaker.AddVerticalQuad(vert1, vert2, biome, terrainColor, vertices, colors, uvs, uv2s, uv3s, triangles, snow);
                }
                int west = 0;
                if (x > 0 && !DetailRegions.ContainsKey(new DFCoord2d(x - 1, y)))
                {
                    west = regionTiles[x - 1, y].elevation;
                }
                if (west < regionTiles[x, y].elevation)
                {
                    vert1 = (new Vector3(x * 48 * 16 * GameMap.tileWidth, regionTiles[x, y].elevation * GameMap.tileHeight, -(y + 1) * 48 * 16 * GameMap.tileWidth)) * scale;
                    vert2 = (new Vector3(x * 48 * 16 * GameMap.tileWidth, west * GameMap.tileHeight, -y * 48 * 16 * GameMap.tileWidth)) * scale;

                    RegionMaker.AddVerticalQuad(vert1, vert2, biome, terrainColor, vertices, colors, uvs, uv2s, uv3s, triangles, snow);
                }
            }
        }

        FinalizeGeometryChunk(vertices, colors, uvs, uv2s, uv3s, triangles);

        FinalizeWaterGeometryChunk(waterVerts, waterUvs, waterTris);
    }