Пример #1
0
        public static void FlattenTerrainReformALT(this PlanetFactory planetFactory, Vector3 center, float radius, int reformSize, bool veinBuried, float localRadius, float realRadius, float fade0 = 3f)
        {
            if (planetFactory.tmp_ids == null)
            {
                planetFactory.tmp_ids = new int[1024];
            }
            if (planetFactory.tmp_entity_ids == null)
            {
                planetFactory.tmp_entity_ids = new int[1024];
            }
            Array.Clear(planetFactory.tmp_ids, 0, planetFactory.tmp_ids.Length);
            Array.Clear(planetFactory.tmp_entity_ids, 0, planetFactory.tmp_entity_ids.Length);
            Vector3       zero = Vector3.zero;
            PlanetRawData data = planetFactory.planet.data;

            ushort[] heightData = data.heightData;
            float    f          = ((float)(int)heightData[data.QueryIndex(center)] - realRadius * 100f + 20f) * 0.01f * 2f;

            //f = Mathf.Min(9f, Mathf.Abs(f));
            f      = Mathf.Min(5f, Mathf.Abs(f));
            fade0 += f;
            float areaRadius = radius + fade0;
            short num        = (short)(realRadius * 100f + 20f);
            bool  levelized  = planetFactory.planet.levelized;
            int   num2       = Mathf.RoundToInt((center.magnitude - 0.2f - realRadius) / 1.33333325f);
            int   num3       = num2 * 133 + num - 60;
            float num4       = localRadius * 100f - 20f;

            foreach (KeyValuePair <int, int> tmp_levelChange in planetFactory.tmp_levelChanges)
            {
                /*
                 * if (tmp_levelChange.Value <= 0)
                 * {
                 *  continue;
                 * }
                 */
                ushort num5 = heightData[tmp_levelChange.Key];
                if (levelized)
                {
                    if (num5 >= num3)
                    {
                        if (data.GetModLevel(tmp_levelChange.Key) < 3)
                        {
                            data.SetModPlane(tmp_levelChange.Key, num2);
                        }
                        planetFactory.planet.AddHeightMapModLevel(tmp_levelChange.Key, tmp_levelChange.Value);
                    }
                }
                else
                {
                    Debug.Log("AddHeightMapModLevel: " + tmp_levelChange.Key + ", " + tmp_levelChange.Value);
                    planetFactory.planet.AddHeightMapModLevelALT(tmp_levelChange.Key, tmp_levelChange.Value);
                }
                if ((float)(int)num5 < num4)
                {
                    planetFactory.planet.landPercentDirty = true;
                }
            }
            if (planetFactory.planet.UpdateDirtyMeshes())
            {
                planetFactory.RenderLocalPlanetHeightmap();
            }
            radius -= (float)reformSize * 0.15f;
            NearColliderLogic nearColliderLogic = planetFactory.planet.physics.nearColliderLogic;
            int   vegetablesInAreaNonAlloc      = nearColliderLogic.GetVegetablesInAreaNonAlloc(center, areaRadius, planetFactory.tmp_ids);
            float num6 = radius * radius;

            for (int i = 0; i < vegetablesInAreaNonAlloc; i++)
            {
                int num7 = planetFactory.tmp_ids[i];
                zero  = planetFactory.vegePool[num7].pos;
                zero -= center;
                if (zero.x * zero.x + zero.y * zero.y + zero.z * zero.z <= num6 + 2.2f)
                {
                    planetFactory.RemoveVegeWithComponents(num7);
                    continue;
                }
                float num8 = data.QueryModifiedHeight(planetFactory.vegePool[num7].pos) - 0.03f;
                planetFactory.vegePool[num7].pos = planetFactory.vegePool[num7].pos.normalized * num8;
                GameMain.gpuiManager.AlterModel(planetFactory.vegePool[num7].modelIndex, planetFactory.vegePool[num7].modelId, num7, planetFactory.vegePool[num7].pos, planetFactory.vegePool[num7].rot, setBuffer: false);
            }
            float num9 = 50f;

            vegetablesInAreaNonAlloc = ((!veinBuried) ? nearColliderLogic.GetVeinsInOceanInAreaNonAlloc(center, areaRadius, planetFactory.tmp_ids) : nearColliderLogic.GetVeinsInAreaNonAlloc(center, areaRadius, planetFactory.tmp_ids));
            for (int j = 0; j < vegetablesInAreaNonAlloc; j++)
            {
                int num10 = planetFactory.tmp_ids[j];
                zero = planetFactory.veinPool[num10].pos;
                float   num11  = realRadius + 0.2f;
                Vector3 vector = zero.normalized * num11 - center;
                if (!(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z <= num6 + 2f))
                {
                    continue;
                }
                PlanetPhysics physics      = planetFactory.planet.physics;
                int           colliderId   = planetFactory.veinPool[num10].colliderId;
                ColliderData  colliderData = physics.GetColliderData(colliderId);
                if (veinBuried)
                {
                    num11 -= num9;
                }
                else
                {
                    Vector3 center2 = zero.normalized * num11;
                    int     entitiesInAreaWhenReformNonAlloc = nearColliderLogic.GetEntitiesInAreaWhenReformNonAlloc(center2, colliderData.radius, planetFactory.tmp_entity_ids);
                    if (entitiesInAreaWhenReformNonAlloc > 0)
                    {
                        num11 = zero.magnitude;
                    }
                }
                Vector3 pos   = colliderData.pos.normalized * num11;
                int     num12 = colliderId >> 20;
                colliderId &= 0xFFFFF;
                physics.colChunks[num12].colliderPool[colliderId].pos = pos;
                planetFactory.veinPool[num10].pos = zero.normalized * num11;
                physics.RefreshColliders();
                GameMain.gpuiManager.AlterModel(planetFactory.veinPool[num10].modelIndex, planetFactory.veinPool[num10].modelId, num10, planetFactory.veinPool[num10].pos, setBuffer: false);
            }
            planetFactory.tmp_levelChanges.Clear();
            Array.Clear(planetFactory.tmp_ids, 0, planetFactory.tmp_ids.Length);
            Array.Clear(planetFactory.tmp_ids, 0, planetFactory.tmp_entity_ids.Length);
            GameMain.gpuiManager.SyncAllGPUBuffer();
        }
Пример #2
0
        public static void FlattenTerrainReform(PlanetFactory factory, List <Vector3> points, Vector3 center)
        {
            if (factory.tmp_ids == null)
            {
                factory.tmp_ids = new int[1024];
            }

            if (factory.tmp_entity_ids == null)
            {
                factory.tmp_entity_ids = new int[1024];
            }

            Array.Clear(factory.tmp_ids, 0, factory.tmp_ids.Length);
            Array.Clear(factory.tmp_entity_ids, 0, factory.tmp_entity_ids.Length);

            PlanetRawData data = factory.planet.data;

            ushort[] heightData = data.heightData;
            short    h          = (short)(factory.planet.realRadius * 100f + 20f);
            bool     levelized  = factory.planet.levelized;
            int      step       = Mathf.RoundToInt((center.magnitude - 0.2f - factory.planet.realRadius) / 1.3333333f);
            int      heightT    = step * 133 + h - 60;
            float    heightT2   = factory.planet.radius * 100f - 20f;

            foreach (KeyValuePair <int, int> keyValuePair in tmpLevelChanges)
            {
                if (keyValuePair.Value > 0)
                {
                    ushort height = heightData[keyValuePair.Key];
                    if (levelized)
                    {
                        if (height >= heightT)
                        {
                            if (data.GetModLevel(keyValuePair.Key) < 3)
                            {
                                data.SetModPlane(keyValuePair.Key, step);
                            }

                            factory.planet.AddHeightMapModLevel(keyValuePair.Key, keyValuePair.Value);
                        }
                    }
                    else
                    {
                        factory.planet.AddHeightMapModLevel(keyValuePair.Key, keyValuePair.Value);
                    }

                    if (height < heightT2)
                    {
                        factory.planet.landPercentDirty = true;
                    }
                }
            }

            if (factory.planet.UpdateDirtyMeshes())
            {
                factory.RenderLocalPlanetHeightmap();
            }

            foreach (Vector3 point in points)
            {
                NearColliderLogic nearColliderLogic = factory.planet.physics.nearColliderLogic;
                int num7 = nearColliderLogic.GetVegetablesInAreaNonAlloc(point, 1, factory.tmp_ids);
                for (int i = 0; i < num7; i++)
                {
                    int     id       = factory.tmp_ids[i];
                    Vector3 position = factory.vegePool[id].pos;
                    position -= point;
                    if (position.sqrMagnitude <= 9f)
                    {
                        factory.RemoveVegeWithComponents(id);
                    }
                    else
                    {
                        float d = data.QueryModifiedHeight(factory.vegePool[id].pos) - 0.03f;
                        factory.vegePool[id].pos = factory.vegePool[id].pos.normalized * d;
                        GameMain.gpuiManager.AlterModel(factory.vegePool[id].modelIndex, factory.vegePool[id].modelId, id,
                                                        factory.vegePool[id].pos, factory.vegePool[id].rot, false);
                    }
                }
            }


            tmpLevelChanges.Clear();
            Array.Clear(factory.tmp_ids, 0, factory.tmp_ids.Length);
            Array.Clear(factory.tmp_ids, 0, factory.tmp_entity_ids.Length);
            GameMain.gpuiManager.SyncAllGPUBuffer();
        }