Ejemplo n.º 1
0
        public virtual void Print(LayerSubMesh subMesh)
        {
            float averageTileSize = Find.WorldGrid.averageTileSize;

            WorldRendererUtility.PrintQuadTangentialToPlanet(DrawPos, 0.7f * averageTileSize, 0.015f, subMesh, counterClockwise: false, randomizeRotation: true);
        }
Ejemplo n.º 2
0
        public static void PrintQuadTangentialToPlanetWithRodation(Vector3 pos, Vector3 posForTangents, float size, float altOffset, LayerSubMesh subMesh, Vector3 rotVec)
        {
            Vector3 first;
            Vector3 second;

            GetTangentsToPlanetWithRotation(posForTangents, out first, out second, rotVec);
            Vector3 normalized = posForTangents.normalized;
            float   d          = size * 0.5f;
            Vector3 v1         = pos - first * d - second * d + normalized * altOffset;
            Vector3 v2         = pos - first * d + second * d + normalized * altOffset;
            Vector3 v3         = pos + first * d + second * d + normalized * altOffset;
            Vector3 v4         = pos + first * d - second * d + normalized * altOffset;
            int     count      = subMesh.verts.Count;

            subMesh.verts.Add(v1);
            subMesh.verts.Add(v2);
            subMesh.verts.Add(v3);
            subMesh.verts.Add(v4);
            subMesh.tris.Add(count);
            subMesh.tris.Add(count + 1);
            subMesh.tris.Add(count + 2);
            subMesh.tris.Add(count);
            subMesh.tris.Add(count + 2);
            subMesh.tris.Add(count + 3);
        }
Ejemplo n.º 3
0
        public override IEnumerable Regenerate()
        {
            IEnumerator enumerator = base.Regenerate().GetEnumerator();

            try
            {
                if (enumerator.MoveNext())
                {
                    object result = enumerator.Current;
                    yield return(result);

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
            finally
            {
                IDisposable disposable;
                IDisposable disposable2 = disposable = (enumerator as IDisposable);
                if (disposable != null)
                {
                    disposable2.Dispose();
                }
            }
            LayerSubMesh           subMesh       = GetSubMesh(WorldMaterials.Rivers);
            LayerSubMesh           subMeshBorder = GetSubMesh(WorldMaterials.RiversBorder);
            WorldGrid              grid          = Find.WorldGrid;
            List <OutputDirection> outputs       = new List <OutputDirection>();
            List <OutputDirection> outputsBorder = new List <OutputDirection>();

            for (int i = 0; i < grid.TilesCount; i++)
            {
                if (i % 1000 == 0)
                {
                    yield return((object)null);

                    /*Error: Unable to find new state assignment for yield return*/;
                }
                if (subMesh.verts.Count > 60000)
                {
                    subMesh       = GetSubMesh(WorldMaterials.Rivers);
                    subMeshBorder = GetSubMesh(WorldMaterials.RiversBorder);
                }
                Tile tile = grid[i];
                if (tile.potentialRivers != null)
                {
                    outputs.Clear();
                    outputsBorder.Clear();
                    for (int j = 0; j < tile.potentialRivers.Count; j++)
                    {
                        List <OutputDirection> list      = outputs;
                        OutputDirection        item      = default(OutputDirection);
                        Tile.RiverLink         riverLink = tile.potentialRivers[j];
                        item.neighbor = riverLink.neighbor;
                        Tile.RiverLink riverLink2 = tile.potentialRivers[j];
                        item.width = riverLink2.river.widthOnWorld - 0.2f;
                        list.Add(item);
                        List <OutputDirection> list2      = outputsBorder;
                        OutputDirection        item2      = default(OutputDirection);
                        Tile.RiverLink         riverLink3 = tile.potentialRivers[j];
                        item2.neighbor = riverLink3.neighbor;
                        Tile.RiverLink riverLink4 = tile.potentialRivers[j];
                        item2.width = riverLink4.river.widthOnWorld;
                        list2.Add(item2);
                    }
                    GeneratePaths(subMesh, i, outputs, riverColor, allowSmoothTransition: true);
                    GeneratePaths(subMeshBorder, i, outputsBorder, riverColor, allowSmoothTransition: true);
                }
            }
            FinalizeMesh(MeshParts.All);
            yield break;
IL_0335:
            /*Error near IL_0336: Unexpected return in MoveNext()*/;
        }
        public override IEnumerable Regenerate()
        {
            IEnumerator enumerator = base.Regenerate().GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    object result = enumerator.Current;
                    yield return(result);
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
            World          world                 = Find.World;
            WorldGrid      grid                  = world.grid;
            int            tilesCount            = grid.TilesCount;
            List <Tile>    tiles                 = grid.tiles;
            List <int>     tileIDToVerts_offsets = grid.tileIDToVerts_offsets;
            List <Vector3> verts                 = grid.verts;

            this.triangleIndexToTileID.Clear();
            IEnumerator enumerator2 = this.CalculateInterpolatedVerticesParams().GetEnumerator();

            try
            {
                while (enumerator2.MoveNext())
                {
                    object result2 = enumerator2.Current;
                    yield return(result2);
                }
            }
            finally
            {
                IDisposable disposable2;
                if ((disposable2 = (enumerator2 as IDisposable)) != null)
                {
                    disposable2.Dispose();
                }
            }
            int colorsAndUVsIndex = 0;

            for (int i = 0; i < tilesCount; i++)
            {
                Tile         tile  = tiles[i];
                BiomeDef     biome = tile.biome;
                int          j;
                LayerSubMesh subMesh = base.GetSubMesh(biome.DrawMaterial, out j);
                while (j >= this.triangleIndexToTileID.Count)
                {
                    this.triangleIndexToTileID.Add(new List <int>());
                }
                int count = subMesh.verts.Count;
                int num   = 0;
                int num2  = (i + 1 >= tileIDToVerts_offsets.Count) ? verts.Count : tileIDToVerts_offsets[i + 1];
                for (int k = tileIDToVerts_offsets[i]; k < num2; k++)
                {
                    subMesh.verts.Add(verts[k]);
                    subMesh.uvs.Add(this.elevationValues[colorsAndUVsIndex]);
                    colorsAndUVsIndex++;
                    if (k < num2 - 2)
                    {
                        subMesh.tris.Add(count + num + 2);
                        subMesh.tris.Add(count + num + 1);
                        subMesh.tris.Add(count);
                        this.triangleIndexToTileID[j].Add(i);
                    }
                    num++;
                }
            }
            base.FinalizeMesh(MeshParts.All);
            IEnumerator enumerator3 = this.RegenerateMeshColliders().GetEnumerator();

            try
            {
                while (enumerator3.MoveNext())
                {
                    object result3 = enumerator3.Current;
                    yield return(result3);
                }
            }
            finally
            {
                IDisposable disposable3;
                if ((disposable3 = (enumerator3 as IDisposable)) != null)
                {
                    disposable3.Dispose();
                }
            }
            this.elevationValues.Clear();
            this.elevationValues.TrimExcess();
            yield break;
        }
Ejemplo n.º 5
0
 public static void PrintQuadTangentialToPlanet(Vector3 pos, float size, float altOffset, LayerSubMesh subMesh, bool counterClockwise = false, bool randomizeRotation = false, bool printUVs = true)
 {
     PrintQuadTangentialToPlanet(pos, pos, size, altOffset, subMesh, counterClockwise, randomizeRotation, printUVs);
 }
Ejemplo n.º 6
0
        public override IEnumerable Regenerate()
        {
            RoadsOfTheRim.DebugLog("Just regenerated Roads on Water");
            foreach (object item in base.Regenerate())
            {
                yield return(item);
            }
            LayerSubMesh             subMesh       = GetSubMesh(WorldMaterials.Roads);
            WorldGrid                grid          = Find.WorldGrid;
            List <RoadWorldLayerDef> roadLayerDefs = DefDatabase <RoadWorldLayerDef> .AllDefs.OrderBy((RoadWorldLayerDef rwld) => rwld.order).ToList();

            int i = 0;

            while (i < grid.TilesCount)
            {
                if (i % 1000 == 0)
                {
                    yield return(null);
                }
                if (subMesh.verts.Count > 60000)
                {
                    subMesh = GetSubMesh(WorldMaterials.Roads);
                }
                Tile tile = grid[i];
                if (tile.WaterCovered)
                {
                    List <OutputDirection> list = new List <OutputDirection>();
                    if (tile.potentialRoads != null)
                    {
                        RoadsOfTheRim.DebugLog("Road on water on tile " + i);
                        bool allowSmoothTransition = true;
                        for (int j = 0; j < tile.potentialRoads.Count - 1; j++)
                        {
                            if (tile.potentialRoads[j].road.worldTransitionGroup != tile.potentialRoads[j + 1].road.worldTransitionGroup)
                            {
                                allowSmoothTransition = false;
                            }
                        }
                        for (int k = 0; k < roadLayerDefs.Count; k++)
                        {
                            bool flag = false;
                            list.Clear();
                            for (int l = 0; l < tile.potentialRoads.Count; l++)
                            {
                                RoadDef road       = tile.potentialRoads[l].road;
                                float   layerWidth = road.GetLayerWidth(roadLayerDefs[k]);
                                if (layerWidth > 0f)
                                {
                                    flag = true;
                                }
                                list.Add(new OutputDirection
                                {
                                    neighbor            = tile.potentialRoads[l].neighbor,
                                    width               = layerWidth,
                                    distortionFrequency = road.distortionFrequency,
                                    distortionIntensity = road.distortionIntensity
                                });
                            }
                            if (flag)
                            {
                                GeneratePaths(subMesh, i, list, roadLayerDefs[k].color, allowSmoothTransition);
                            }
                        }
                    }
                }
                int num = i + 1;
                i = num;
            }
            FinalizeMesh(MeshParts.All);
        }
        /*
         * public override void DrawLayer()
         * {
         *  if (!this.Visible)
         *  {
         *      return;
         *  }
         *  int count = this.subMeshes.Count;
         *  for (int i = 0; i < count; i++)
         *  {
         *      LayerSubMesh layerSubMesh = this.subMeshes[i];
         *      Vector3 s = new Vector3(.28f, 1f, .28f);
         *      Matrix4x4 matrix = default(Matrix4x4);
         *      matrix.SetTRS(vector, Quaternion.AngleAxis(angle, Vector3.up), s);
         *      if (layerSubMesh.finalized && !layerSubMesh.disabled)
         *      {
         *          Graphics.DrawMesh(layerSubMesh.mesh, Vector3.zero, Quaternion.identity, layerSubMesh.material, 0);
         *      }
         *  }
         * }
         */
        // Token: 0x060047BA RID: 18362 RVA: 0x0021ADFC File Offset: 0x002191FC
        public override void Regenerate()
        {
            LayerSubMesh subMesh = base.GetSubMesh(RRYMatBases.Hive);

            if (subMesh.mesh.vertexCount == 0)
            {
                SectionLayerGeometryMaker_Solid.MakeBaseGeometry(this.section, subMesh, AltitudeLayer.Terrain);
            }
            subMesh.Clear(MeshParts.Colors);
            MapComponent_HiveGrid _AvPHiveCreep = base.Map.GetComponent <MapComponent_HiveGrid>();

            //    Log.Message(string.Format(" 6 {0}", _AvPHiveCreep.DepthGridDirect_Unsafe));
            float[]     depthGridDirect_Unsafe = _AvPHiveCreep.DepthGridDirect_Unsafe;
            CellRect    cellRect    = this.section.CellRect;
            int         num         = base.Map.Size.z - 1;
            int         num2        = base.Map.Size.x - 1;
            bool        flag        = false;
            CellIndices cellIndices = base.Map.cellIndices;

            for (int i = cellRect.minX; i <= cellRect.maxX; i++)
            {
                for (int j = cellRect.minZ; j <= cellRect.maxZ; j++)
                {
                    float num3 = depthGridDirect_Unsafe[cellIndices.CellToIndex(i, j)];
                    int   num4 = cellIndices.CellToIndex(i, j - 1);
                    float num5 = (j <= 0) ? num3 : depthGridDirect_Unsafe[num4];
                    num4 = cellIndices.CellToIndex(i - 1, j - 1);
                    float num6 = (j <= 0 || i <= 0) ? num3 : depthGridDirect_Unsafe[num4];
                    num4 = cellIndices.CellToIndex(i - 1, j);
                    float num7 = (i <= 0) ? num3 : depthGridDirect_Unsafe[num4];
                    num4 = cellIndices.CellToIndex(i - 1, j + 1);
                    float num8 = (j >= num || i <= 0) ? num3 : depthGridDirect_Unsafe[num4];
                    num4 = cellIndices.CellToIndex(i, j + 1);
                    float num9 = (j >= num) ? num3 : depthGridDirect_Unsafe[num4];
                    num4 = cellIndices.CellToIndex(i + 1, j + 1);
                    float num10 = (j >= num || i >= num2) ? num3 : depthGridDirect_Unsafe[num4];
                    num4 = cellIndices.CellToIndex(i + 1, j);
                    float num11 = (i >= num2) ? num3 : depthGridDirect_Unsafe[num4];
                    num4 = cellIndices.CellToIndex(i + 1, j - 1);
                    float num12 = (j <= 0 || i >= num2) ? num3 : depthGridDirect_Unsafe[num4];
                    this.vertDepth[0] = (num5 + num6 + num7 + num3) / 4f;
                    this.vertDepth[1] = (num7 + num3) / 2f;
                    this.vertDepth[2] = (num7 + num8 + num9 + num3) / 4f;
                    this.vertDepth[3] = (num9 + num3) / 2f;
                    this.vertDepth[4] = (num9 + num10 + num11 + num3) / 4f;
                    this.vertDepth[5] = (num11 + num3) / 2f;
                    this.vertDepth[6] = (num11 + num12 + num5 + num3) / 4f;
                    this.vertDepth[7] = (num5 + num3) / 2f;
                    this.vertDepth[8] = num3;
                    for (int k = 0; k < 9; k++)
                    {
                        if (this.vertDepth[k] > 0.01f)
                        {
                            ;
                            flag = true;
                        }
                        subMesh.colors.Add(SectionLayer_Hive.HiveDepthColor(this.vertDepth[k]));
                    }
                }
            }
            if (flag)
            {
                subMesh.disabled = false;
                subMesh.FinalizeMesh(MeshParts.Colors);
            }
            else
            {
                subMesh.disabled = true;
            }
        }
Ejemplo n.º 8
0
        public override IEnumerable Regenerate()
        {
            foreach (object result in base.Regenerate())
            {
                yield return(result);
            }
            LayerSubMesh             subMesh       = base.GetSubMesh(WorldMaterials.Roads);
            WorldGrid                grid          = Find.WorldGrid;
            List <RoadWorldLayerDef> roadLayerDefs = (from rwld in DefDatabase <RoadWorldLayerDef> .AllDefs
                                                      orderby rwld.order
                                                      select rwld).ToList <RoadWorldLayerDef>();

            for (int i = 0; i < grid.TilesCount; i++)
            {
                if (i % 1000 == 0)
                {
                    yield return(null);
                }
                if (subMesh.verts.Count > 60000)
                {
                    subMesh = base.GetSubMesh(WorldMaterials.Roads);
                }
                Tile tile = grid[i];
                if (!tile.WaterCovered)
                {
                    List <WorldLayer_Paths.OutputDirection> outputs = new List <WorldLayer_Paths.OutputDirection>();
                    if (tile.roads != null)
                    {
                        bool allowSmoothTransition = true;
                        for (int j = 0; j < tile.roads.Count - 1; j++)
                        {
                            if (tile.roads[j].road.worldTransitionGroup != tile.roads[j + 1].road.worldTransitionGroup)
                            {
                                allowSmoothTransition = false;
                            }
                        }
                        for (int k = 0; k < roadLayerDefs.Count; k++)
                        {
                            bool flag = false;
                            outputs.Clear();
                            for (int l = 0; l < tile.roads.Count; l++)
                            {
                                RoadDef road       = tile.roads[l].road;
                                float   layerWidth = road.GetLayerWidth(roadLayerDefs[k]);
                                if (layerWidth > 0f)
                                {
                                    flag = true;
                                }
                                outputs.Add(new WorldLayer_Paths.OutputDirection
                                {
                                    neighbor            = tile.roads[l].neighbor,
                                    width               = layerWidth,
                                    distortionFrequency = road.distortionFrequency,
                                    distortionIntensity = road.distortionIntensity
                                });
                            }
                            if (flag)
                            {
                                base.GeneratePaths(subMesh, i, outputs, roadLayerDefs[k].color, allowSmoothTransition);
                            }
                        }
                    }
                }
            }
            base.FinalizeMesh(MeshParts.All);
        }
Ejemplo n.º 9
0
        private static readonly IntVec2 TexturesInAtlas = new IntVec2(2, 2); // two by two, meaning four variants for each worldmaterial.
        public override IEnumerable Regenerate()
        {
            foreach (object obj in base.Regenerate())
            {
                yield return(obj);
            }
            Rand.PushState();
            Rand.Seed = Find.World.info.Seed;
            WorldGrid worldGrid = Find.WorldGrid;

            for (int tileID = 0; tileID < Find.WorldGrid.TilesCount; tileID++)
            {
                Tile tile = Find.WorldGrid[tileID];
                if (tile.biome.HasModExtension <BiomesKitControls>())
                {
                    Dictionary <Tile, Hilliness> backupHilliness = LateBiomeWorker.backupHilliness;
                    BiomesKitControls            biomesKit       = tile.biome.GetModExtension <BiomesKitControls>();
                    Vector3 vector = worldGrid.GetTileCenter(tileID);
                    if (biomesKit.hillMaterialPath != "World/MapGraphics/Default")
                    {
                        tile.hilliness = backupHilliness[tile];
                        Material hill;
                        if (tile.hilliness == Hilliness.SmallHills)
                        {
                            hill = MaterialPool.MatFrom(biomesKit.hillMaterialPath + "/Hills/SmallHills", ShaderDatabase.WorldOverlayTransparentLit, biomesKit.materialLayer);
                            LayerSubMesh subMeshHill = GetSubMesh(hill);
                            WorldRendererUtility.PrintQuadTangentialToPlanet(vector, vector, (worldGrid.averageTileSize * 1.5f), 0.01f, subMeshHill, false, biomesKit.materialRandomRotation, false);
                            WorldRendererUtility.PrintTextureAtlasUVs(Rand.Range(0, TexturesInAtlas.x), Rand.Range(0, TexturesInAtlas.z), TexturesInAtlas.x, TexturesInAtlas.z, subMeshHill);
                        }
                        if (tile.hilliness == Hilliness.LargeHills)
                        {
                            hill = MaterialPool.MatFrom(biomesKit.hillMaterialPath + "/Hills/LargeHills", ShaderDatabase.WorldOverlayTransparentLit, biomesKit.materialLayer);
                            LayerSubMesh subMeshHill = GetSubMesh(hill);
                            WorldRendererUtility.PrintQuadTangentialToPlanet(vector, vector, (worldGrid.averageTileSize * 1.5f), 0.01f, subMeshHill, false, biomesKit.materialRandomRotation, false);
                            WorldRendererUtility.PrintTextureAtlasUVs(Rand.Range(0, TexturesInAtlas.x), Rand.Range(0, TexturesInAtlas.z), TexturesInAtlas.x, TexturesInAtlas.z, subMeshHill);
                        }
                        if (tile.hilliness == Hilliness.Mountainous)
                        {
                            hill = MaterialPool.MatFrom(biomesKit.hillMaterialPath + "/Hills/Mountains", ShaderDatabase.WorldOverlayTransparentLit, biomesKit.materialLayer);
                            LayerSubMesh subMeshHill = GetSubMesh(hill);
                            WorldRendererUtility.PrintQuadTangentialToPlanet(vector, vector, (worldGrid.averageTileSize * 1.5f), 0.01f, subMeshHill, false, biomesKit.materialRandomRotation, false);
                            WorldRendererUtility.PrintTextureAtlasUVs(Rand.Range(0, TexturesInAtlas.x), Rand.Range(0, TexturesInAtlas.z), TexturesInAtlas.x, TexturesInAtlas.z, subMeshHill);
                        }
                        if (tile.hilliness == Hilliness.Impassable)
                        {
                            hill = MaterialPool.MatFrom(biomesKit.hillMaterialPath + "/Hills/Impassable", ShaderDatabase.WorldOverlayTransparentLit, biomesKit.materialLayer);
                            LayerSubMesh subMeshHill = GetSubMesh(hill);
                            WorldRendererUtility.PrintQuadTangentialToPlanet(vector, vector, (worldGrid.averageTileSize * 1.5f), 0.01f, subMeshHill, false, biomesKit.materialRandomRotation, false);
                            WorldRendererUtility.PrintTextureAtlasUVs(Rand.Range(0, TexturesInAtlas.x), Rand.Range(0, TexturesInAtlas.z), TexturesInAtlas.x, TexturesInAtlas.z, subMeshHill);
                        }
                    }
                    if (biomesKit.materialMaxHilliness != Hilliness.Undefined)
                    {
                        if (tile.hilliness > biomesKit.materialMaxHilliness || tile.hilliness < biomesKit.materialMinHilliness)
                        {
                            continue;
                        }
                    }
                    bool roadPresent = true;
                    if (tile.Roads == null || tile.Roads.Count == 0)
                    {
                        roadPresent = false;
                    }
                    bool riverPresent = true;
                    if (tile.Rivers == null || tile.Rivers.Count == 0)
                    {
                        riverPresent = false;
                    }
                    if (biomesKit.forestMaterialPath != "World/MapGraphics/Default")
                    {
                        if (!riverPresent && !roadPresent)
                        {
                            Material forestMaterial;
                            if (tile.temperature < biomesKit.forestSnowyBelow)
                            {
                                forestMaterial = MaterialPool.MatFrom(biomesKit.forestMaterialPath + "/Forest_Snowy", ShaderDatabase.WorldOverlayTransparentLit, biomesKit.materialLayer);
                            }
                            else if (tile.rainfall < biomesKit.forestSparseBelow)
                            {
                                forestMaterial = MaterialPool.MatFrom(biomesKit.forestMaterialPath + "/Forest_Sparse", ShaderDatabase.WorldOverlayTransparentLit, biomesKit.materialLayer);
                            }
                            else if (tile.rainfall > biomesKit.forestDenseAbove)
                            {
                                forestMaterial = MaterialPool.MatFrom(biomesKit.forestMaterialPath + "/Forest_Dense", ShaderDatabase.WorldOverlayTransparentLit, biomesKit.materialLayer);
                            }
                            else
                            {
                                forestMaterial = MaterialPool.MatFrom(biomesKit.forestMaterialPath + "/Forest", ShaderDatabase.WorldOverlayTransparentLit, biomesKit.materialLayer);
                            }
                            LayerSubMesh subMeshForest = GetSubMesh(forestMaterial);
                            WorldRendererUtility.PrintQuadTangentialToPlanet(vector, vector, (worldGrid.averageTileSize * biomesKit.materialSizeMultiplier), 0.01f, subMeshForest, false, biomesKit.materialRandomRotation, false);
                            WorldRendererUtility.PrintTextureAtlasUVs(Rand.Range(0, TexturesInAtlas.x), Rand.Range(0, TexturesInAtlas.z), TexturesInAtlas.x, TexturesInAtlas.z, subMeshForest);
                        }
                    }
                    if (biomesKit.materialPath != "World/MapGraphics/Default")
                    {
                        Material     material = MaterialPool.MatFrom(biomesKit.materialPath, ShaderDatabase.WorldOverlayTransparentLit, biomesKit.materialLayer);
                        LayerSubMesh subMesh  = GetSubMesh(material);
                        WorldRendererUtility.PrintQuadTangentialToPlanet(vector, vector, (worldGrid.averageTileSize * biomesKit.materialSizeMultiplier), 0.01f, subMesh, false, biomesKit.materialRandomRotation, false);
                        WorldRendererUtility.PrintTextureAtlasUVs(Rand.Range(0, TexturesInAtlas.x), Rand.Range(0, TexturesInAtlas.z), TexturesInAtlas.x, TexturesInAtlas.z, subMesh);
                    }
                }
            }
            Rand.PopState();
            base.FinalizeMesh(MeshParts.All);
            yield break;
        }
Ejemplo n.º 10
0
        private static void                 _Regenerate(this object obj)
        {
            if (!MatBases.SunShadow.shader.isSupported)
            {
                return;
            }

            Section section      = obj.Section();
            var     sectionLayer = obj as SectionLayer;

            LayerSubMesh subMesh = sectionLayer.GetSubMesh(MatBases.IndoorMask);

            subMesh.Clear(MeshParts.All);
            Building[] innerArray = Find.EdificeGrid.InnerArray;
            CellRect   cellRect   = new CellRect(
                section.botLeft.x,
                section.botLeft.z,
                17,
                17);

            cellRect.ClipInsideMap();
            subMesh.verts.Capacity = cellRect.Area * 2;
            subMesh.tris.Capacity  = cellRect.Area * 4;
            float y = Altitudes.AltitudeFor(AltitudeLayer.MetaOverlays);

            for (int index1 = cellRect.minX; index1 <= cellRect.maxX; ++index1)
            {
                for (int index2 = cellRect.minZ; index2 <= cellRect.maxZ; ++index2)
                {
                    IntVec3 c1 = new IntVec3(index1, 0, index2);
                    if (!(bool)_HideRainPrimary.Invoke(obj, new System.Object[] { c1 }))
                    {
                        bool flag1 = c1.Roofed();
                        bool flag2 = false;
                        if (flag1)
                        {
                            for (int index3 = 0; index3 < 8; ++index3)
                            {
                                IntVec3 c2 = c1 + GenAdj.AdjacentCells[index3];
                                if (
                                    (c2.InBounds()) &&
                                    (!(bool)_HideRainPrimary.Invoke(obj, new System.Object[] { c2 }))
                                    )
                                {
                                    flag2 = true;
                                    break;
                                }
                            }
                        }
                        if (
                            (!flag1) ||
                            (!flag2)
                            )
                        {
                            continue;
                        }
                    }
                    Thing thing = innerArray[CellIndices.CellToIndex(index1, index2)];
                    float num   =
                        (thing == null) ||
                        (thing.def.passability != Traversability.Impassable) &&
                        (
                            (thing.def.thingClass != typeof(Building_Door)) ||
                            (!thing.def.thingClass.IsSubclassOf(typeof(Building_Door)))
                        )
                        ? 0.16f : 0.0f;
                    subMesh.verts.Add(new Vector3((float)index1 - num, y, (float)index2 - num));
                    subMesh.verts.Add(new Vector3((float)index1 - num, y, (float)(index2 + 1) + num));
                    subMesh.verts.Add(new Vector3((float)(index1 + 1) + num, y, (float)(index2 + 1) + num));
                    subMesh.verts.Add(new Vector3((float)(index1 + 1) + num, y, (float)index2 - num));
                    int count = subMesh.verts.Count;
                    subMesh.tris.Add(count - 4);
                    subMesh.tris.Add(count - 3);
                    subMesh.tris.Add(count - 2);
                    subMesh.tris.Add(count - 4);
                    subMesh.tris.Add(count - 2);
                    subMesh.tris.Add(count - 1);
                }
            }
            if (subMesh.verts.Count <= 0)
            {
                return;
            }
            subMesh.FinalizeMesh(MeshParts.Verts | MeshParts.Tris);
        }
Ejemplo n.º 11
0
        public override IEnumerable Regenerate()
        {
            IEnumerator enumerator = base.Regenerate().GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    object result = enumerator.Current;
                    yield return(result);
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
            Rand.PushState();
            Rand.Seed = Find.World.info.Seed;
            WorldGrid grid       = Find.WorldGrid;
            int       tilesCount = grid.TilesCount;
            int       i          = 0;

            while (i < tilesCount)
            {
                Tile       tile = grid[i];
                Material   material;
                FloatRange floatRange;
                switch (tile.hilliness)
                {
                case Hilliness.SmallHills:
                    material   = WorldMaterials.SmallHills;
                    floatRange = WorldLayer_Hills.BasePosOffsetRange_SmallHills;
                    goto IL_180;

                case Hilliness.LargeHills:
                    material   = WorldMaterials.LargeHills;
                    floatRange = WorldLayer_Hills.BasePosOffsetRange_LargeHills;
                    goto IL_180;

                case Hilliness.Mountainous:
                    material   = WorldMaterials.Mountains;
                    floatRange = WorldLayer_Hills.BasePosOffsetRange_Mountains;
                    goto IL_180;

                case Hilliness.Impassable:
                    material   = WorldMaterials.ImpassableMountains;
                    floatRange = WorldLayer_Hills.BasePosOffsetRange_ImpassableMountains;
                    goto IL_180;
                }
IL_25C:
                i++;
                continue;
IL_180:
                LayerSubMesh subMesh = base.GetSubMesh(material);
                Vector3 vector         = grid.GetTileCenter(i);
                Vector3 posForTangents = vector;
                float   magnitude      = vector.magnitude;
                vector = (vector + Rand.UnitVector3 * floatRange.RandomInRange * grid.averageTileSize).normalized * magnitude;
                WorldRendererUtility.PrintQuadTangentialToPlanet(vector, posForTangents, WorldLayer_Hills.BaseSizeRange.RandomInRange * grid.averageTileSize, 0.005f, subMesh, false, true, false);
                WorldRendererUtility.PrintTextureAtlasUVs(Rand.Range(0, WorldLayer_Hills.TexturesInAtlas.x), Rand.Range(0, WorldLayer_Hills.TexturesInAtlas.z), WorldLayer_Hills.TexturesInAtlas.x, WorldLayer_Hills.TexturesInAtlas.z, subMesh);
                goto IL_25C;
            }
            Rand.PopState();
            base.FinalizeMesh(MeshParts.All);
            yield break;
        }
        public override void Regenerate()
        {
            LayerSubMesh subMesh = base.GetSubMesh(Verse.MatBases.Snow);

            //		LayerSubMesh subMesh = base.GetSubMesh(MatBases.Frost); // for some reason the custom one was causing a huge memory issue and rendering in giant squares :(

            if (subMesh.mesh.vertexCount == 0)
            {
//				SectionLayerGeometryMaker_Solid.MakeBaseGeometry(this.section, subMesh, AltitudeLayer.MoteLow);
                SectionLayerGeometryMaker_Solid.MakeBaseGeometry(this.section, subMesh, AltitudeLayer.LayingPawn);                 //so frost forms over items/plants
            }
            subMesh.Clear(MeshParts.Colors);

            float[]  depthGridDirect_Unsafe = base.Map.GetComponent <FrostGrid>().DepthGridDirect_Unsafe;
            CellRect cellRect = this.section.CellRect;
            int      num      = base.Map.Size.z - 1;
            int      num2     = base.Map.Size.x - 1;
            bool     flag     = false;

            CellIndices cellIndices = base.Map.cellIndices;

            for (int i = cellRect.minX; i <= cellRect.maxX; i++)             // this is what renders it all blobby, I think
            {
                for (int j = cellRect.minZ; j <= cellRect.maxZ; j++)
                {
                    float num3 = depthGridDirect_Unsafe[cellIndices.CellToIndex(i, j)];
                    int   num4 = cellIndices.CellToIndex(i, j - 1);
                    float num5 = (j <= 0) ? num3 : depthGridDirect_Unsafe[num4];
                    num4 = cellIndices.CellToIndex(i - 1, j - 1);
                    float num6 = (j <= 0 || i <= 0) ? num3 : depthGridDirect_Unsafe[num4];
                    num4 = cellIndices.CellToIndex(i - 1, j);
                    float num7 = (i <= 0) ? num3 : depthGridDirect_Unsafe[num4];
                    num4 = cellIndices.CellToIndex(i - 1, j + 1);
                    float num8 = (j >= num || i <= 0) ? num3 : depthGridDirect_Unsafe[num4];
                    num4 = cellIndices.CellToIndex(i, j + 1);
                    float num9 = (j >= num) ? num3 : depthGridDirect_Unsafe[num4];
                    num4 = cellIndices.CellToIndex(i + 1, j + 1);
                    float num10 = (j >= num || i >= num2) ? num3 : depthGridDirect_Unsafe[num4];
                    num4 = cellIndices.CellToIndex(i + 1, j);
                    float num11 = (i >= num2) ? num3 : depthGridDirect_Unsafe[num4];
                    num4 = cellIndices.CellToIndex(i + 1, j - 1);
                    float num12 = (j <= 0 || i >= num2) ? num3 : depthGridDirect_Unsafe[num4];
                    this.vertDepth[0] = (num5 + num6 + num7 + num3) / 4f;
                    this.vertDepth[1] = (num7 + num3) / 2f;
                    this.vertDepth[2] = (num7 + num8 + num9 + num3) / 4f;
                    this.vertDepth[3] = (num9 + num3) / 2f;
                    this.vertDepth[4] = (num9 + num10 + num11 + num3) / 4f;
                    this.vertDepth[5] = (num11 + num3) / 2f;
                    this.vertDepth[6] = (num11 + num12 + num5 + num3) / 4f;
                    this.vertDepth[7] = (num5 + num3) / 2f;
                    this.vertDepth[8] = num3;
                    for (int k = 0; k < 9; k++)
                    {
                        if (this.vertDepth[k] > 0.01f)
                        {
                            flag = true;
                        }
                        subMesh.colors.Add(SectionLayer_Frost.FrostDepthColor(this.vertDepth[k]));
                    }
                }
            }
            if (flag)
            {
                subMesh.disabled = false;
                subMesh.FinalizeMesh(MeshParts.Colors);
            }
            else
            {
                subMesh.disabled = true;
            }
        }
Ejemplo n.º 13
0
        public void GeneratePaths(LayerSubMesh subMesh, int tileID, List <OutputDirection> nodes, Color32 color, bool allowSmoothTransition)
        {
            WorldGrid worldGrid = Find.WorldGrid;

            worldGrid.GetTileVertices(tileID, this.tmpVerts);
            worldGrid.GetTileNeighbors(tileID, this.tmpNeighbors);
            if (nodes.Count == 1 && this.pointyEnds)
            {
                int             count           = subMesh.verts.Count;
                List <Vector3>  verts           = this.tmpVerts;
                List <int>      list            = this.tmpNeighbors;
                OutputDirection outputDirection = nodes[0];
                this.AddPathEndpoint(subMesh, verts, list.IndexOf(outputDirection.neighbor), color, nodes[0]);
                List <Vector3>  verts2              = subMesh.verts;
                Vector3         tileCenter          = worldGrid.GetTileCenter(tileID);
                OutputDirection outputDirection2    = nodes[0];
                float           distortionFrequency = outputDirection2.distortionFrequency;
                OutputDirection outputDirection3    = nodes[0];
                verts2.Add(this.FinalizePoint(tileCenter, distortionFrequency, outputDirection3.distortionIntensity));
                subMesh.colors.Add(color.MutateAlpha(0));
                subMesh.tris.Add(count);
                subMesh.tris.Add(count + 3);
                subMesh.tris.Add(count + 1);
                subMesh.tris.Add(count + 1);
                subMesh.tris.Add(count + 3);
                subMesh.tris.Add(count + 2);
            }
            else
            {
                if (nodes.Count == 2)
                {
                    int             count2           = subMesh.verts.Count;
                    List <int>      list2            = this.tmpNeighbors;
                    OutputDirection outputDirection4 = nodes[0];
                    int             num              = list2.IndexOf(outputDirection4.neighbor);
                    List <int>      list3            = this.tmpNeighbors;
                    OutputDirection outputDirection5 = nodes[1];
                    int             num2             = list3.IndexOf(outputDirection5.neighbor);
                    if (allowSmoothTransition && Mathf.Abs(num - num2) > 1 && Mathf.Abs((num - num2 + this.tmpVerts.Count) % this.tmpVerts.Count) > 1)
                    {
                        this.AddPathEndpoint(subMesh, this.tmpVerts, num, color, nodes[0]);
                        this.AddPathEndpoint(subMesh, this.tmpVerts, num2, color, nodes[1]);
                        subMesh.tris.Add(count2);
                        subMesh.tris.Add(count2 + 5);
                        subMesh.tris.Add(count2 + 1);
                        subMesh.tris.Add(count2 + 5);
                        subMesh.tris.Add(count2 + 4);
                        subMesh.tris.Add(count2 + 1);
                        subMesh.tris.Add(count2 + 1);
                        subMesh.tris.Add(count2 + 4);
                        subMesh.tris.Add(count2 + 2);
                        subMesh.tris.Add(count2 + 4);
                        subMesh.tris.Add(count2 + 3);
                        subMesh.tris.Add(count2 + 2);
                        return;
                    }
                }
                float num3 = 0f;
                for (int i = 0; i < nodes.Count; i++)
                {
                    float           a = num3;
                    OutputDirection outputDirection6 = nodes[i];
                    num3 = Mathf.Max(a, outputDirection6.width);
                }
                Vector3 tileCenter2 = worldGrid.GetTileCenter(tileID);
                this.tmpHexVerts.Clear();
                for (int j = 0; j < this.tmpVerts.Count; j++)
                {
                    this.tmpHexVerts.Add(this.FinalizePoint(Vector3.LerpUnclamped(tileCenter2, this.tmpVerts[j], (float)(num3 * 0.5 * 2.0)), 0f, 0f));
                }
                tileCenter2 = this.FinalizePoint(tileCenter2, 0f, 0f);
                int count3 = subMesh.verts.Count;
                subMesh.verts.Add(tileCenter2);
                subMesh.colors.Add(color);
                int count4 = subMesh.verts.Count;
                for (int k = 0; k < this.tmpHexVerts.Count; k++)
                {
                    subMesh.verts.Add(this.tmpHexVerts[k]);
                    subMesh.colors.Add(color.MutateAlpha(0));
                    subMesh.tris.Add(count3);
                    subMesh.tris.Add(count4 + (k + 1) % this.tmpHexVerts.Count);
                    subMesh.tris.Add(count4 + k);
                }
                for (int l = 0; l < nodes.Count; l++)
                {
                    OutputDirection outputDirection7 = nodes[l];
                    if (outputDirection7.width != 0.0)
                    {
                        int             count5           = subMesh.verts.Count;
                        List <int>      list4            = this.tmpNeighbors;
                        OutputDirection outputDirection8 = nodes[l];
                        int             num4             = list4.IndexOf(outputDirection8.neighbor);
                        this.AddPathEndpoint(subMesh, this.tmpVerts, num4, color, nodes[l]);
                        subMesh.tris.Add(count5);
                        subMesh.tris.Add(count4 + (num4 + this.tmpHexVerts.Count - 1) % this.tmpHexVerts.Count);
                        subMesh.tris.Add(count3);
                        subMesh.tris.Add(count5);
                        subMesh.tris.Add(count3);
                        subMesh.tris.Add(count5 + 1);
                        subMesh.tris.Add(count5 + 1);
                        subMesh.tris.Add(count3);
                        subMesh.tris.Add(count5 + 2);
                        subMesh.tris.Add(count3);
                        subMesh.tris.Add(count4 + (num4 + 2) % this.tmpHexVerts.Count);
                        subMesh.tris.Add(count5 + 2);
                    }
                }
            }
        }
        public override void Regenerate()
        {
            if (Current.ProgramState != ProgramState.Playing)
            {
                return;
            }

            if (pawnFog == null)
            {
                pawnFog = base.Map.getMapComponentSeenFog();
            }

            if (pawnFog != null && pawnFog.initialized)
            {
                LayerSubMesh subMesh = base.GetSubMesh(MatBases.FogOfWar);
                bool         firstGeneration;
                if (subMesh.mesh.vertexCount == 0)
                {
                    firstGeneration = true;

                    subMesh.mesh.MarkDynamic();

                    MakeBaseGeometry(this.section, subMesh, AltitudeLayer.FogOfWar);

                    targetAlphas    = new byte[subMesh.mesh.vertexCount];
                    alphaChangeTick = new long[subMesh.mesh.vertexCount];
                    meshColors      = new Color32[subMesh.mesh.vertexCount];
                }
                else
                {
                    firstGeneration = false;
                }

                int colorIdx = 0;

                bool[] fogGrid = base.Map.fogGrid.fogGrid;
                if (this.factionShownGrid == null)
                {
                    this.factionShownGrid = pawnFog.getFactionShownCells(Faction.OfPlayer);
                }
                int[] factionShownGrid = this.factionShownGrid;

                bool[] knownGrid = pawnFog.knownCells;

                int mapSizeX = base.Map.Size.x;

                CellRect cellRect  = this.section.CellRect;
                int      mapHeight = base.Map.Size.z - 1;
                int      mapWidth  = mapSizeX - 1;


                bool hasFoggedVerts    = false;
                long fogTransitionTick = (long)(Find.TickManager.TicksGame * prefFadeSpeedMult);

                int cellIdx;
                int cellIdxN;
                int cellIdxS;
                int cellIdxE;
                int cellIdxW;
                int cellIdxSW;
                int cellIdxNW;
                int cellIdxNE;
                int cellIdxSE;

                bool cellKnown;
                bool adjCellKnown;

                byte alpha;
                for (int x = cellRect.minX; x <= cellRect.maxX; x++)
                {
                    for (int z = cellRect.minZ; z <= cellRect.maxZ; z++)
                    {
                        cellIdx = z * mapSizeX + x;
                        if (!fogGrid[cellIdx])
                        {
                            if (factionShownGrid[cellIdx] == 0)
                            {
                                cellKnown = knownGrid[cellIdx];
                                for (int n = 0; n < 9; n++)
                                {
                                    this.vertsNotShown[n] = true;
                                    this.vertsSeen[n]     = cellKnown;
                                }
                                if (cellKnown)
                                {
                                    cellIdxN  = (z + 1) * mapSizeX + x;
                                    cellIdxS  = (z - 1) * mapSizeX + x;
                                    cellIdxE  = z * mapSizeX + (x + 1);
                                    cellIdxW  = z * mapSizeX + (x - 1);
                                    cellIdxSW = (z - 1) * mapSizeX + (x - 1);
                                    cellIdxNW = (z + 1) * mapSizeX + (x - 1);
                                    cellIdxNE = (z + 1) * mapSizeX + (x + 1);
                                    cellIdxSE = (z - 1) * mapSizeX + (x + 1);

                                    if (z < mapHeight && !knownGrid[cellIdxN])
                                    {
                                        this.vertsSeen[2] = false;
                                        this.vertsSeen[3] = false;
                                        this.vertsSeen[4] = false;
                                    }
                                    if (z > 0 && !knownGrid[cellIdxS])
                                    {
                                        this.vertsSeen[6] = false;
                                        this.vertsSeen[7] = false;
                                        this.vertsSeen[0] = false;
                                    }
                                    if (x < mapWidth && !knownGrid[cellIdxE])
                                    {
                                        this.vertsSeen[4] = false;
                                        this.vertsSeen[5] = false;
                                        this.vertsSeen[6] = false;
                                    }
                                    if (x > 0 && !knownGrid[cellIdxW])
                                    {
                                        this.vertsSeen[0] = false;
                                        this.vertsSeen[1] = false;
                                        this.vertsSeen[2] = false;
                                    }
                                    if (z > 0 && x > 0 && !knownGrid[cellIdxSW])
                                    {
                                        this.vertsSeen[0] = false;
                                    }
                                    if (z < mapHeight && x > 0 && !knownGrid[cellIdxNW])
                                    {
                                        this.vertsSeen[2] = false;
                                    }
                                    if (z < mapHeight && x < mapWidth && !knownGrid[cellIdxNE])
                                    {
                                        this.vertsSeen[4] = false;
                                    }
                                    if (z > 0 && x < mapWidth && !knownGrid[cellIdxSE])
                                    {
                                        this.vertsSeen[6] = false;
                                    }
                                }
                            }
                            else
                            {
                                for (int l = 0; l < 9; l++)
                                {
                                    this.vertsNotShown[l] = false;
                                    this.vertsSeen[l]     = false;
                                }

                                cellIdxN  = (z + 1) * mapSizeX + x;
                                cellIdxS  = (z - 1) * mapSizeX + x;
                                cellIdxE  = z * mapSizeX + (x + 1);
                                cellIdxW  = z * mapSizeX + (x - 1);
                                cellIdxSW = (z - 1) * mapSizeX + (x - 1);
                                cellIdxNW = (z + 1) * mapSizeX + (x - 1);
                                cellIdxNE = (z + 1) * mapSizeX + (x + 1);
                                cellIdxSE = (z - 1) * mapSizeX + (x + 1);

                                if (z < mapHeight && factionShownGrid[cellIdxN] == 0)
                                {
                                    adjCellKnown          = knownGrid[cellIdxN];
                                    this.vertsNotShown[2] = true;
                                    this.vertsSeen[2]     = adjCellKnown;
                                    this.vertsNotShown[3] = true;
                                    this.vertsSeen[3]     = adjCellKnown;
                                    this.vertsNotShown[4] = true;
                                    this.vertsSeen[4]     = adjCellKnown;
                                }
                                if (z > 0 && factionShownGrid[cellIdxS] == 0)
                                {
                                    adjCellKnown          = knownGrid[cellIdxS];
                                    this.vertsNotShown[6] = true;
                                    this.vertsSeen[6]     = adjCellKnown;
                                    this.vertsNotShown[7] = true;
                                    this.vertsSeen[7]     = adjCellKnown;
                                    this.vertsNotShown[0] = true;
                                    this.vertsSeen[0]     = adjCellKnown;
                                }
                                if (x < mapWidth && factionShownGrid[cellIdxE] == 0)
                                {
                                    adjCellKnown          = knownGrid[cellIdxE];
                                    this.vertsNotShown[4] = true;
                                    this.vertsSeen[4]     = adjCellKnown;
                                    this.vertsNotShown[5] = true;
                                    this.vertsSeen[5]     = adjCellKnown;
                                    this.vertsNotShown[6] = true;
                                    this.vertsSeen[6]     = adjCellKnown;
                                }
                                if (x > 0 && factionShownGrid[cellIdxW] == 0)
                                {
                                    adjCellKnown          = knownGrid[cellIdxW];
                                    this.vertsNotShown[0] = true;
                                    this.vertsSeen[0]     = adjCellKnown;
                                    this.vertsNotShown[1] = true;
                                    this.vertsSeen[1]     = adjCellKnown;
                                    this.vertsNotShown[2] = true;
                                    this.vertsSeen[2]     = adjCellKnown;
                                }
                                if (z > 0 && x > 0 && factionShownGrid[cellIdxSW] == 0)
                                {
                                    adjCellKnown          = knownGrid[cellIdxSW];
                                    this.vertsNotShown[0] = true;
                                    this.vertsSeen[0]     = adjCellKnown;
                                }
                                if (z < mapHeight && x > 0 && factionShownGrid[cellIdxNW] == 0)
                                {
                                    adjCellKnown          = knownGrid[cellIdxNW];
                                    this.vertsNotShown[2] = true;
                                    this.vertsSeen[2]     = adjCellKnown;
                                }
                                if (z < mapHeight && x < mapWidth && factionShownGrid[cellIdxNE] == 0)
                                {
                                    adjCellKnown          = knownGrid[cellIdxNE];
                                    this.vertsNotShown[4] = true;
                                    this.vertsSeen[4]     = adjCellKnown;
                                }
                                if (z > 0 && x < mapWidth && factionShownGrid[cellIdxSE] == 0)
                                {
                                    adjCellKnown          = knownGrid[cellIdxSE];
                                    this.vertsNotShown[6] = true;
                                    this.vertsSeen[6]     = adjCellKnown;
                                }
                            }
                        }
                        else
                        {
                            for (int k = 0; k < 9; k++)
                            {
                                this.vertsNotShown[k] = true;
                                this.vertsSeen[k]     = false;
                            }
                        }
                        for (int m = 0; m < 9; m++)
                        {
                            if (this.vertsNotShown[m])
                            {
                                if (vertsSeen[m])
                                {
                                    alpha = prefFogAlpha;
                                }
                                else
                                {
                                    alpha = 255;
                                }

                                hasFoggedVerts = true;
                            }
                            else
                            {
                                alpha = 0;
                            }

                            if (!prefEnableFade || firstGeneration)
                            {
                                if (firstGeneration || meshColors[colorIdx].a != alpha)
                                {
                                    meshColors[colorIdx] = new Color32(255, 255, 255, alpha);
                                }
                                if (prefEnableFade)
                                {
                                    targetAlphas[colorIdx]    = alpha;
                                    alphaChangeTick[colorIdx] = fogTransitionTick;
                                }
                            }
                            else if (targetAlphas[colorIdx] != alpha)
                            {
                                activeFogTransitions      = true;
                                targetAlphas[colorIdx]    = alpha;
                                alphaChangeTick[colorIdx] = fogTransitionTick;
                            }

                            colorIdx++;
                        }
                    }
                }

                if (!prefEnableFade || firstGeneration)
                {
                    if (hasFoggedVerts)
                    {
                        subMesh.disabled      = false;
                        subMesh.mesh.colors32 = meshColors;
                    }
                    else
                    {
                        subMesh.disabled = true;
                    }
                }
            }
        }
Ejemplo n.º 15
0
 public override void Print(LayerSubMesh subMesh)
 {
 }
Ejemplo n.º 16
0
        public override void Print(LayerSubMesh subMesh)
        {
            float averageTileSize = Find.WorldGrid.averageTileSize;

            WorldRendererUtility.PrintQuadTangentialToPlanet(this.DrawPos, 10.7f * averageTileSize, 0.008f, subMesh, false, false, true);
        }
Ejemplo n.º 17
0
        public override IEnumerable Regenerate()
        {
            IEnumerator enumerator = base.Regenerate().GetEnumerator();

            try
            {
                if (enumerator.MoveNext())
                {
                    object result = enumerator.Current;
                    yield return(result);

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
            finally
            {
                IDisposable disposable;
                IDisposable disposable2 = disposable = (enumerator as IDisposable);
                if (disposable != null)
                {
                    disposable2.Dispose();
                }
            }
            World          world                 = Find.World;
            WorldGrid      grid                  = world.grid;
            int            tilesCount            = grid.TilesCount;
            List <Tile>    tiles                 = grid.tiles;
            List <int>     tileIDToVerts_offsets = grid.tileIDToVerts_offsets;
            List <Vector3> verts                 = grid.verts;

            triangleIndexToTileID.Clear();
            IEnumerator enumerator2 = CalculateInterpolatedVerticesParams().GetEnumerator();

            try
            {
                if (enumerator2.MoveNext())
                {
                    object result3 = enumerator2.Current;
                    yield return(result3);

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
            finally
            {
                IDisposable disposable;
                IDisposable disposable3 = disposable = (enumerator2 as IDisposable);
                if (disposable != null)
                {
                    disposable3.Dispose();
                }
            }
            int colorsAndUVsIndex = 0;

            for (int i = 0; i < tilesCount; i++)
            {
                Tile         tile  = tiles[i];
                BiomeDef     biome = tile.biome;
                int          subMeshIndex;
                LayerSubMesh subMesh = GetSubMesh(biome.DrawMaterial, out subMeshIndex);
                while (subMeshIndex >= triangleIndexToTileID.Count)
                {
                    triangleIndexToTileID.Add(new List <int>());
                }
                int count = subMesh.verts.Count;
                int num   = 0;
                int num2  = (i + 1 >= tileIDToVerts_offsets.Count) ? verts.Count : tileIDToVerts_offsets[i + 1];
                for (int j = tileIDToVerts_offsets[i]; j < num2; j++)
                {
                    subMesh.verts.Add(verts[j]);
                    subMesh.uvs.Add(elevationValues[colorsAndUVsIndex]);
                    colorsAndUVsIndex++;
                    if (j < num2 - 2)
                    {
                        subMesh.tris.Add(count + num + 2);
                        subMesh.tris.Add(count + num + 1);
                        subMesh.tris.Add(count);
                        triangleIndexToTileID[subMeshIndex].Add(i);
                    }
                    num++;
                }
            }
            FinalizeMesh(MeshParts.All);
            IEnumerator enumerator3 = RegenerateMeshColliders().GetEnumerator();

            try
            {
                if (enumerator3.MoveNext())
                {
                    object result2 = enumerator3.Current;
                    yield return(result2);

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
            finally
            {
                IDisposable disposable;
                IDisposable disposable4 = disposable = (enumerator3 as IDisposable);
                if (disposable != null)
                {
                    disposable4.Dispose();
                }
            }
            elevationValues.Clear();
            elevationValues.TrimExcess();
            yield break;
IL_042a:
            /*Error near IL_042b: Unexpected return in MoveNext()*/;
        }
Ejemplo n.º 18
0
        public static void PrintTextureAtlasUVs(int indexX, int indexY, int numX, int numY, LayerSubMesh subMesh)
        {
            float num  = 1f / (float)numX;
            float num2 = 1f / (float)numY;
            float num3 = (float)indexX * num;
            float num4 = (float)indexY * num2;

            subMesh.uvs.Add(new Vector2(num3, num4));
            subMesh.uvs.Add(new Vector2(num3, num4 + num2));
            subMesh.uvs.Add(new Vector2(num3 + num, num4 + num2));
            subMesh.uvs.Add(new Vector2(num3 + num, num4));
        }
        public static bool Prefix(MethodBase __originalMethod, SectionLayer_Things __instance)
        {
            if (!Active)
            {
                return(true);
            }

            if (ByDef)
            {
                if (!__instance.Visible)
                {
                    return(false);
                }
                int count = __instance.subMeshes.Count;



                for (int i = 0; i < count; i++)
                {
                    LayerSubMesh layerSubMesh = __instance.subMeshes[i];
                    if (layerSubMesh.finalized && !layerSubMesh.disabled)
                    {
                        string Namer()
                        {
                            var n = layerSubMesh.material?.mainTexture?.name ?? layerSubMesh.GetType().Name;

                            return(n);
                        }

                        var name = layerSubMesh.material?.mainTexture?.name ?? layerSubMesh.GetType().Name;

                        var prof = ProfileController.Start(name, Namer, __originalMethod.GetType(), null, null, __originalMethod);
                        Graphics.Internal_DrawMesh_Injected(layerSubMesh.mesh, 0, ref johnmatrix, layerSubMesh.material, 0, null, null, ShadowCastingMode.Off, false, null, LightProbeUsage.Off, null);

                        // Graphics.DrawMesh(layerSubMesh.mesh, Vector3.zeroVector, Quaternion.identityQuaternion, layerSubMesh.material, 0);
                        prof.Stop();
                    }
                }



                return(false);
            }

            {
                if (!__instance.Visible)
                {
                    return(false);
                }

                int count = __instance.subMeshes.Count;



                for (int i = 0; i < count; i++)
                {
                    LayerSubMesh layerSubMesh = __instance.subMeshes[i];
                    if (layerSubMesh.finalized && !layerSubMesh.disabled)
                    {
                        string Namer()
                        {
                            var n = layerSubMesh.material?.mainTexture?.name ?? layerSubMesh.GetType().Name;

                            return(n);
                        }

                        var name = layerSubMesh.material?.mainTexture?.name ?? layerSubMesh.GetType().Name;

                        var prof = ProfileController.Start(name, Namer, __originalMethod.GetType(), null, null,
                                                           __originalMethod);
                        Graphics.DrawMesh(layerSubMesh.mesh, Vector3.zero, Quaternion.identity, layerSubMesh.material,
                                          0);
                        prof.Stop();
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 20
0
        public static void PrintQuadTangentialToPlanet(Vector3 pos, Vector3 posForTangents, float size, float altOffset, LayerSubMesh subMesh, bool counterClockwise = false, bool randomizeRotation = false, bool printUVs = true)
        {
            GetTangentsToPlanet(posForTangents, out var first, out var second, randomizeRotation);
            Vector3 normalized = posForTangents.normalized;
            float   d          = size * 0.5f;
            Vector3 item       = pos - first * d - second * d + normalized * altOffset;
            Vector3 item2      = pos - first * d + second * d + normalized * altOffset;
            Vector3 item3      = pos + first * d + second * d + normalized * altOffset;
            Vector3 item4      = pos + first * d - second * d + normalized * altOffset;
            int     count      = subMesh.verts.Count;

            subMesh.verts.Add(item);
            subMesh.verts.Add(item2);
            subMesh.verts.Add(item3);
            subMesh.verts.Add(item4);
            if (printUVs)
            {
                subMesh.uvs.Add(new Vector2(0f, 0f));
                subMesh.uvs.Add(new Vector2(0f, 1f));
                subMesh.uvs.Add(new Vector2(1f, 1f));
                subMesh.uvs.Add(new Vector2(1f, 0f));
            }
            if (counterClockwise)
            {
                subMesh.tris.Add(count + 2);
                subMesh.tris.Add(count + 1);
                subMesh.tris.Add(count);
                subMesh.tris.Add(count + 3);
                subMesh.tris.Add(count + 2);
                subMesh.tris.Add(count);
            }
            else
            {
                subMesh.tris.Add(count);
                subMesh.tris.Add(count + 1);
                subMesh.tris.Add(count + 2);
                subMesh.tris.Add(count);
                subMesh.tris.Add(count + 2);
                subMesh.tris.Add(count + 3);
            }
        }
Ejemplo n.º 21
0
        public override void Regenerate()
        {
            try
            {
                var ZTracker = ZUtils.ZTracker;
                int curLevel = ZTracker.GetZIndexFor(base.Map);
                base.ClearSubMeshes(MeshParts.All);
                foreach (var map in ZTracker.GetAllMaps(base.Map.Tile)
                         .OrderByDescending(x => ZTracker.GetZIndexFor(x)))
                {
                    int baseLevel = ZTracker.GetZIndexFor(map);
                    if (curLevel > baseLevel && baseLevel >= 0)
                    {
                        TerrainGrid          terrainGrid = map.terrainGrid;
                        CellRect             cellRect    = this.section.CellRect;
                        TerrainDef[]         array       = new TerrainDef[8];
                        HashSet <TerrainDef> hashSet     = new HashSet <TerrainDef>();
                        bool[] array2 = new bool[8];
                        foreach (IntVec3 intVec in cellRect)
                        {
                            if (base.Map.terrainGrid.TerrainAt(intVec) == ZLevelsDefOf.ZL_OutsideTerrain)
                            {
                                hashSet.Clear();
                                TerrainDef   terrainDef = terrainGrid.TerrainAt(intVec);
                                LayerSubMesh subMesh    = base.GetSubMesh(this.GetMaterialFor(terrainDef));
                                if (subMesh != null && this.AllowRenderingFor(terrainDef))
                                {
                                    int count = subMesh.verts.Count;
                                    subMesh.verts.Add(new Vector3((float)intVec.x, 0f, (float)intVec.z));
                                    subMesh.verts.Add(new Vector3((float)intVec.x, 0f, (float)(intVec.z + 1)));
                                    subMesh.verts.Add(new Vector3((float)(intVec.x + 1), 0f, (float)(intVec.z + 1)));
                                    subMesh.verts.Add(new Vector3((float)(intVec.x + 1), 0f, (float)intVec.z));
                                    subMesh.colors.Add(SectionLayer_LowerTerrain.ColorWhite);
                                    subMesh.colors.Add(SectionLayer_LowerTerrain.ColorWhite);
                                    subMesh.colors.Add(SectionLayer_LowerTerrain.ColorWhite);
                                    subMesh.colors.Add(SectionLayer_LowerTerrain.ColorWhite);
                                    subMesh.tris.Add(count);
                                    subMesh.tris.Add(count + 1);
                                    subMesh.tris.Add(count + 2);
                                    subMesh.tris.Add(count);
                                    subMesh.tris.Add(count + 2);
                                    subMesh.tris.Add(count + 3);
                                }

                                for (int i = 0; i < 8; i++)
                                {
                                    IntVec3 c = intVec + GenAdj.AdjacentCellsAroundBottom[i];
                                    if (!c.InBounds(map))
                                    {
                                        array[i] = terrainDef;
                                    }
                                    else
                                    {
                                        TerrainDef terrainDef2 = terrainGrid.TerrainAt(c);
                                        Thing      edifice     = c.GetEdifice(map);
                                        if (edifice != null && edifice.def.coversFloor)
                                        {
                                            terrainDef2 = TerrainDefOf.Underwall;
                                        }
                                        array[i] = terrainDef2;
                                        if (terrainDef2 != terrainDef && terrainDef2.edgeType
                                            != TerrainDef.TerrainEdgeType.Hard &&
                                            terrainDef2.renderPrecedence >= terrainDef.renderPrecedence &&
                                            !hashSet.Contains(terrainDef2))
                                        {
                                            hashSet.Add(terrainDef2);
                                        }
                                    }
                                }
                                foreach (TerrainDef terrainDef3 in hashSet)
                                {
                                    LayerSubMesh subMesh2 = base.GetSubMesh(this.GetMaterialFor(terrainDef3));
                                    if (subMesh2 != null && this.AllowRenderingFor(terrainDef3))
                                    {
                                        int count = subMesh2.verts.Count;
                                        subMesh2.verts.Add(new Vector3((float)intVec.x + 0.5f, 0f, (float)intVec.z));
                                        subMesh2.verts.Add(new Vector3((float)intVec.x, 0f, (float)intVec.z));
                                        subMesh2.verts.Add(new Vector3((float)intVec.x, 0f, (float)intVec.z + 0.5f));
                                        subMesh2.verts.Add(new Vector3((float)intVec.x, 0f, (float)(intVec.z + 1)));
                                        subMesh2.verts.Add(new Vector3((float)intVec.x + 0.5f, 0f, (float)(intVec.z + 1)));
                                        subMesh2.verts.Add(new Vector3((float)(intVec.x + 1), 0f, (float)(intVec.z + 1)));
                                        subMesh2.verts.Add(new Vector3((float)(intVec.x + 1), 0f, (float)intVec.z + 0.5f));
                                        subMesh2.verts.Add(new Vector3((float)(intVec.x + 1), 0f, (float)intVec.z));
                                        subMesh2.verts.Add(new Vector3((float)intVec.x + 0.5f, 0f, (float)intVec.z + 0.5f));
                                        for (int j = 0; j < 8; j++)
                                        {
                                            array2[j] = false;
                                        }
                                        for (int k = 0; k < 8; k++)
                                        {
                                            if (k % 2 == 0)
                                            {
                                                if (array[k] == terrainDef3)
                                                {
                                                    array2[(k - 1 + 8) % 8] = true;
                                                    array2[k]           = true;
                                                    array2[(k + 1) % 8] = true;
                                                }
                                            }
                                            else if (array[k] == terrainDef3)
                                            {
                                                array2[k] = true;
                                            }
                                        }
                                        for (int l = 0; l < 8; l++)
                                        {
                                            if (array2[l])
                                            {
                                                subMesh2.colors.Add(SectionLayer_LowerTerrain.ColorWhite);
                                            }
                                            else
                                            {
                                                subMesh2.colors.Add(SectionLayer_LowerTerrain.ColorClear);
                                            }
                                        }
                                        subMesh2.colors.Add(SectionLayer_LowerTerrain.ColorClear);
                                        for (int m = 0; m < 8; m++)
                                        {
                                            subMesh2.tris.Add(count + m);
                                            subMesh2.tris.Add(count + (m + 1) % 8);
                                            subMesh2.tris.Add(count + 8);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                base.FinalizeMesh(MeshParts.All);
            }
            catch { };
        }
        public void GeneratePaths(LayerSubMesh subMesh, int tileID, List <WorldLayer_Paths.OutputDirection> nodes, Color32 color, bool allowSmoothTransition)
        {
            WorldGrid worldGrid = Find.WorldGrid;

            worldGrid.GetTileVertices(tileID, this.tmpVerts);
            worldGrid.GetTileNeighbors(tileID, this.tmpNeighbors);
            if (nodes.Count == 1 && this.pointyEnds)
            {
                int count = subMesh.verts.Count;
                this.AddPathEndpoint(subMesh, this.tmpVerts, this.tmpNeighbors.IndexOf(nodes[0].neighbor), color, tileID, nodes[0]);
                subMesh.verts.Add(this.FinalizePoint(worldGrid.GetTileCenter(tileID), nodes[0].distortionFrequency, nodes[0].distortionIntensity));
                subMesh.colors.Add(color.MutateAlpha(0));
                subMesh.tris.Add(count);
                subMesh.tris.Add(count + 3);
                subMesh.tris.Add(count + 1);
                subMesh.tris.Add(count + 1);
                subMesh.tris.Add(count + 3);
                subMesh.tris.Add(count + 2);
                return;
            }
            if (nodes.Count == 2)
            {
                int count2 = subMesh.verts.Count;
                int num    = this.tmpNeighbors.IndexOf(nodes[0].neighbor);
                int num2   = this.tmpNeighbors.IndexOf(nodes[1].neighbor);
                if (allowSmoothTransition && Mathf.Abs(num - num2) > 1 && Mathf.Abs((num - num2 + this.tmpVerts.Count) % this.tmpVerts.Count) > 1)
                {
                    this.AddPathEndpoint(subMesh, this.tmpVerts, num, color, tileID, nodes[0]);
                    this.AddPathEndpoint(subMesh, this.tmpVerts, num2, color, tileID, nodes[1]);
                    subMesh.tris.Add(count2);
                    subMesh.tris.Add(count2 + 5);
                    subMesh.tris.Add(count2 + 1);
                    subMesh.tris.Add(count2 + 5);
                    subMesh.tris.Add(count2 + 4);
                    subMesh.tris.Add(count2 + 1);
                    subMesh.tris.Add(count2 + 1);
                    subMesh.tris.Add(count2 + 4);
                    subMesh.tris.Add(count2 + 2);
                    subMesh.tris.Add(count2 + 4);
                    subMesh.tris.Add(count2 + 3);
                    subMesh.tris.Add(count2 + 2);
                    return;
                }
            }
            float num3 = 0f;

            for (int i = 0; i < nodes.Count; i++)
            {
                num3 = Mathf.Max(num3, nodes[i].width);
            }
            Vector3 vector = worldGrid.GetTileCenter(tileID);

            this.tmpHexVerts.Clear();
            for (int j = 0; j < this.tmpVerts.Count; j++)
            {
                this.tmpHexVerts.Add(this.FinalizePoint(Vector3.LerpUnclamped(vector, this.tmpVerts[j], num3 * 0.5f * 2f), 0f, 0f));
            }
            vector = this.FinalizePoint(vector, 0f, 0f);
            int count3 = subMesh.verts.Count;

            subMesh.verts.Add(vector);
            subMesh.colors.Add(color);
            int count4 = subMesh.verts.Count;

            for (int k = 0; k < this.tmpHexVerts.Count; k++)
            {
                subMesh.verts.Add(this.tmpHexVerts[k]);
                subMesh.colors.Add(color.MutateAlpha(0));
                subMesh.tris.Add(count3);
                subMesh.tris.Add(count4 + (k + 1) % this.tmpHexVerts.Count);
                subMesh.tris.Add(count4 + k);
            }
            for (int l = 0; l < nodes.Count; l++)
            {
                if (nodes[l].width != 0f)
                {
                    int count5 = subMesh.verts.Count;
                    int num4   = this.tmpNeighbors.IndexOf(nodes[l].neighbor);
                    this.AddPathEndpoint(subMesh, this.tmpVerts, num4, color, tileID, nodes[l]);
                    subMesh.tris.Add(count5);
                    subMesh.tris.Add(count4 + (num4 + this.tmpHexVerts.Count - 1) % this.tmpHexVerts.Count);
                    subMesh.tris.Add(count3);
                    subMesh.tris.Add(count5);
                    subMesh.tris.Add(count3);
                    subMesh.tris.Add(count5 + 1);
                    subMesh.tris.Add(count5 + 1);
                    subMesh.tris.Add(count3);
                    subMesh.tris.Add(count5 + 2);
                    subMesh.tris.Add(count3);
                    subMesh.tris.Add(count4 + (num4 + 2) % this.tmpHexVerts.Count);
                    subMesh.tris.Add(count5 + 2);
                }
            }
        }
        // 仮
        private static void MakeBaseGeometry(Section section, LayerSubMesh sm, AltitudeLayer altitudeLayer)
        {
            sm.Clear(MeshParts.Verts | MeshParts.Tris);
            var cellRect = new CellRect(section.botLeft.x, section.botLeft.z, 17, 17);

            cellRect.ClipInsideMap(section.map);
            var y = altitudeLayer.AltitudeFor();

            sm.verts.Capacity = cellRect.Area * 9;
            for (var i = cellRect.minX; i <= cellRect.maxX; i++)
            {
                for (var j = cellRect.minZ; j <= cellRect.maxZ; j++)
                {
                    sm.verts.Add(new Vector3(i, y, j));
                    sm.verts.Add(new Vector3(i, y, j + 0.5f));
                    sm.verts.Add(new Vector3(i, y, j + 1));
                    sm.verts.Add(new Vector3(i + 0.5f, y, j + 1));
                    sm.verts.Add(new Vector3(i + 1, y, j + 1));
                    sm.verts.Add(new Vector3(i + 1, y, j + 0.5f));
                    sm.verts.Add(new Vector3(i + 1, y, j));
                    sm.verts.Add(new Vector3(i + 0.5f, y, j));
                    sm.verts.Add(new Vector3(i + 0.5f, y, j + 0.5f));
                }
            }

            var num = cellRect.Area * 8 * 3;

            sm.tris.Capacity = num;
            var num2 = 0;

            while (sm.tris.Count < num)
            {
                sm.tris.Add(num2 + 7);
                sm.tris.Add(num2);
                sm.tris.Add(num2 + 1);
                sm.tris.Add(num2 + 1);
                sm.tris.Add(num2 + 2);
                sm.tris.Add(num2 + 3);
                sm.tris.Add(num2 + 3);
                sm.tris.Add(num2 + 4);
                sm.tris.Add(num2 + 5);
                sm.tris.Add(num2 + 5);
                sm.tris.Add(num2 + 6);
                sm.tris.Add(num2 + 7);
                sm.tris.Add(num2 + 7);
                sm.tris.Add(num2 + 1);
                sm.tris.Add(num2 + 8);
                sm.tris.Add(num2 + 1);
                sm.tris.Add(num2 + 3);
                sm.tris.Add(num2 + 8);
                sm.tris.Add(num2 + 3);
                sm.tris.Add(num2 + 5);
                sm.tris.Add(num2 + 8);
                sm.tris.Add(num2 + 5);
                sm.tris.Add(num2 + 7);
                sm.tris.Add(num2 + 8);
                num2 += 9;
            }

            sm.FinalizeMesh(MeshParts.Verts | MeshParts.Tris);
        }