예제 #1
0
            private static void GenerateWorldMapMT(Minimap __instance)
            {
                int   halfSize     = __instance.m_textureSize / 2;
                float halfSizeF    = __instance.m_pixelSize / 2f;
                var   mapPixels    = new Color32[__instance.m_textureSize * __instance.m_textureSize];
                var   forestPixels = new Color32[__instance.m_textureSize * __instance.m_textureSize];
                var   heightPixels = new Color[__instance.m_textureSize * __instance.m_textureSize];

                GameUtils.SimpleParallelFor(4, 0, __instance.m_textureSize, i =>
                {
                    for (int j = 0; j < __instance.m_textureSize; j++)
                    {
                        float wx          = (float)(j - halfSize) * __instance.m_pixelSize + halfSizeF;
                        float wy          = (float)(i - halfSize) * __instance.m_pixelSize + halfSizeF;
                        var biome         = WorldGenerator.instance.GetBiome(wx, wy);
                        float biomeHeight = WorldGenerator.instance.GetBiomeHeight(biome, wx, wy);
                        mapPixels[i * __instance.m_textureSize + j]    = __instance.GetPixelColor(biome);
                        forestPixels[i * __instance.m_textureSize + j] = __instance.GetMaskColor(wx, wy, biomeHeight, biome);
                        heightPixels[i * __instance.m_textureSize + j] = new Color(biomeHeight, 0f, 0f);
                    }
                });

                __instance.m_forestMaskTexture.SetPixels32(forestPixels);
                __instance.m_forestMaskTexture.Apply();
                __instance.m_mapTexture.SetPixels32(mapPixels);
                __instance.m_mapTexture.Apply();
                __instance.m_heightTexture.SetPixels(heightPixels);
                __instance.m_heightTexture.Apply();
            }
        // This is slower, at least for the 64x64 tiles
        private static void BuildMT(HeightmapBuilder.HMBuildData data)
        {
            int            num      = data.m_width + 1;
            int            num2     = num * num;
            Vector3        vector   = data.m_center + new Vector3((float)data.m_width * data.m_scale * -0.5f, 0f, (float)data.m_width * data.m_scale * -0.5f);
            WorldGenerator worldGen = data.m_worldGen;

            data.m_cornerBiomes    = new Heightmap.Biome[4];
            data.m_cornerBiomes[0] = worldGen.GetBiome(vector.x, vector.z);
            data.m_cornerBiomes[1] = worldGen.GetBiome(vector.x + (float)data.m_width * data.m_scale, vector.z);
            data.m_cornerBiomes[2] = worldGen.GetBiome(vector.x, vector.z + (float)data.m_width * data.m_scale);
            data.m_cornerBiomes[3] = worldGen.GetBiome(vector.x + (float)data.m_width * data.m_scale, vector.z + (float)data.m_width * data.m_scale);
            Heightmap.Biome biome  = data.m_cornerBiomes[0];
            Heightmap.Biome biome2 = data.m_cornerBiomes[1];
            Heightmap.Biome biome3 = data.m_cornerBiomes[2];
            Heightmap.Biome biome4 = data.m_cornerBiomes[3];
            data.m_baseHeights = new List <float>(num * num);
            for (int i = 0; i < num2; i++)
            {
                data.m_baseHeights.Add(0f);
            }

            GameUtils.SimpleParallelFor(4, 0, num, j =>
                                        //for (int j = 0; j < num; j++)
            {
                float wy = vector.z + (float)j * data.m_scale;
                float t  = Mathf.SmoothStep(0f, 1f, (float)j / (float)data.m_width);
                for (int k = 0; k < num; k++)
                {
                    float wx = vector.x + (float)k * data.m_scale;
                    float t2 = Mathf.SmoothStep(0f, 1f, (float)k / (float)data.m_width);
                    float value;
                    if (data.m_distantLod)
                    {
                        Heightmap.Biome biome5 = worldGen.GetBiome(wx, wy);
                        value = worldGen.GetBiomeHeight(biome5, wx, wy);
                    }
                    else if (biome3 == biome && biome2 == biome && biome4 == biome)
                    {
                        value = worldGen.GetBiomeHeight(biome, wx, wy);
                    }
                    else
                    {
                        float biomeHeight  = worldGen.GetBiomeHeight(biome, wx, wy);
                        float biomeHeight2 = worldGen.GetBiomeHeight(biome2, wx, wy);
                        float biomeHeight3 = worldGen.GetBiomeHeight(biome3, wx, wy);
                        float biomeHeight4 = worldGen.GetBiomeHeight(biome4, wx, wy);
                        float a            = Mathf.Lerp(biomeHeight, biomeHeight2, t2);
                        float b            = Mathf.Lerp(biomeHeight3, biomeHeight4, t2);
                        value = Mathf.Lerp(a, b, t);
                    }

                    data.m_baseHeights[j * num + k] = value;
                }
            });

            if (data.m_distantLod)
            {
                for (int l = 0; l < 4; l++)
                {
                    List <float> list = new List <float>(data.m_baseHeights);
                    for (int m = 1; m < num - 1; m++)
                    {
                        for (int n = 1; n < num - 1; n++)
                        {
                            float num3 = list[m * num + n];
                            float num4 = list[(m - 1) * num + n];
                            float num5 = list[(m + 1) * num + n];
                            float num6 = list[m * num + n - 1];
                            float num7 = list[m * num + n + 1];
                            if (Mathf.Abs(num3 - num4) > 10f)
                            {
                                num3 = (num3 + num4) * 0.5f;
                            }
                            if (Mathf.Abs(num3 - num5) > 10f)
                            {
                                num3 = (num3 + num5) * 0.5f;
                            }
                            if (Mathf.Abs(num3 - num6) > 10f)
                            {
                                num3 = (num3 + num6) * 0.5f;
                            }
                            if (Mathf.Abs(num3 - num7) > 10f)
                            {
                                num3 = (num3 + num7) * 0.5f;
                            }
                            data.m_baseHeights[m * num + n] = num3;
                        }
                    }
                }
            }
        }