Exemple #1
0
        public int CostlyUpdate(WaveParticlesQuadtree quadtree, float deltaTime)
        {
            float num;

            if (this.Frequency < 0.025f)
            {
                float x = this._Position.x + this.Direction.x / this.Frequency;
                float z = this._Position.y + this.Direction.y / this.Frequency;
                num = Mathf.Max(StaticWaterInteraction.GetTotalDepthAt(this._Position.x, this._Position.y), StaticWaterInteraction.GetTotalDepthAt(x, z));
            }
            else
            {
                num = StaticWaterInteraction.GetTotalDepthAt(this._Position.x, this._Position.y);
            }
            if (num <= 0.001f)
            {
                this.Destroy();
                return(0);
            }
            this.UpdateWaveParameters(deltaTime, num);
            int result = 0;

            if (quadtree != null && !this.DisallowSubdivision)
            {
                if (this.LeftNeighbour != null)
                {
                    this.Subdivide(quadtree, this.LeftNeighbour, this, ref result);
                }
                if (this.RightNeighbour != null)
                {
                    this.Subdivide(quadtree, this, this.RightNeighbour, ref result);
                }
            }
            return(result);
        }
Exemple #2
0
        public void CostlyUpdate(WaveParticlesQuadtree quadtree, float time)
        {
            WaveParticle waveParticle = this.LeftParticle;
            float        deltaTime    = time - this.LastCostlyUpdateTime;

            this.LastCostlyUpdateTime = time;
            int num = 0;

            do
            {
                WaveParticle waveParticle2 = waveParticle;
                waveParticle = waveParticle.RightNeighbour;
                num         += waveParticle2.CostlyUpdate((num >= 30) ? null : quadtree, deltaTime);
            }while (waveParticle != null);
            waveParticle = this.LeftParticle;
            if (waveParticle == null)
            {
                return;
            }
            WaveParticle waveParticle3 = waveParticle;
            int          num2          = 0;

            do
            {
                WaveParticle waveParticle4 = waveParticle;
                waveParticle = waveParticle.RightNeighbour;
                num2++;
                if (waveParticle4 != waveParticle3 && (waveParticle4.DisallowSubdivision || waveParticle == null))
                {
                    if (num2 > 3)
                    {
                        WaveParticlesGroup.FilterRefractedDirections(waveParticle3, num2);
                    }
                    waveParticle3 = waveParticle;
                    num2          = 0;
                }
            }while (waveParticle != null);
        }
Exemple #3
0
        private void Subdivide(WaveParticlesQuadtree quadtree, WaveParticle left, WaveParticle right, ref int numSubdivisions)
        {
            Vector2 a         = left._Position - right._Position;
            float   magnitude = a.magnitude;

            if (magnitude * this.Frequency > 1f && magnitude > 1f && quadtree.FreeSpace != 0)
            {
                WaveParticle waveParticle = WaveParticle.Create(right._Position + a * 0.5f, (left.Direction + right.Direction) * 0.5f, (left.BaseFrequency + right.BaseFrequency) * 0.5f, (left.BaseAmplitude + right.BaseAmplitude) * 0.5f, (left.Lifetime + right.Lifetime) * 0.5f, left.IsShoreWave);
                if (waveParticle != null)
                {
                    waveParticle.Group               = left.Group;
                    waveParticle.Amplitude           = (left.Amplitude + right.Amplitude) * 0.5f;
                    waveParticle.Frequency           = (left.Frequency + right.Frequency) * 0.5f;
                    waveParticle.Speed               = (left.Speed + right.Speed) * 0.5f;
                    waveParticle.TargetSpeed         = (left.TargetSpeed + right.TargetSpeed) * 0.5f;
                    waveParticle.EnergyBalance       = (left.EnergyBalance + right.EnergyBalance) * 0.5f;
                    waveParticle.Shoaling            = (left.Shoaling + right.Shoaling) * 0.5f;
                    waveParticle.TargetInvKh         = (left.TargetInvKh + right.TargetInvKh) * 0.5f;
                    waveParticle.Lifetime            = (left.Lifetime + right.Lifetime) * 0.5f;
                    waveParticle.TargetEnergyBalance = (left.TargetEnergyBalance + right.TargetEnergyBalance) * 0.5f;
                    waveParticle.AmplitudeModifiers  = (left.AmplitudeModifiers + right.AmplitudeModifiers) * 0.5f;
                    waveParticle.AmplitudeModifiers2 = (left.AmplitudeModifiers2 + right.AmplitudeModifiers2) * 0.5f;
                    waveParticle.Invkh               = (left.Invkh + right.Invkh) * 0.5f;
                    waveParticle.BaseSpeed           = (left.BaseSpeed + right.BaseSpeed) * 0.5f;
                    waveParticle.ExpansionEnergyLoss = (left.ExpansionEnergyLoss + right.ExpansionEnergyLoss) * 0.5f;
                    waveParticle.Direction           = left.Direction;
                    if (quadtree.AddElement(waveParticle))
                    {
                        waveParticle.LeftNeighbour  = left;
                        waveParticle.RightNeighbour = right;
                        left.RightNeighbour         = waveParticle;
                        right.LeftNeighbour         = waveParticle;
                    }
                    numSubdivisions++;
                }
            }
        }
Exemple #4
0
 private WaveParticlesQuadtree(WaveParticlesQuadtree root, Rect rect, int maxElementsPerNode) : this(rect, maxElementsPerNode, 0)
 {
     this._Qroot = root;
 }
Exemple #5
0
        private void UpdateParticles(float time)
        {
            List <WaterCamera> enabledWaterCameras = WaterCamera.EnabledWaterCameras;
            int  count = enabledWaterCameras.Count;
            bool flag  = false;

            for (int i = 0; i < count; i++)
            {
                if (base.Rect.Overlaps(enabledWaterCameras[i].LocalMapsRect))
                {
                    flag = true;
                    break;
                }
            }
            int num;
            int num2;
            int num3;

            if (!flag)
            {
                num  = this._LastUpdateIndex;
                num2 = this._LastUpdateIndex + 8;
                num3 = num << 2;
                if (num2 >= this._Elements.Length)
                {
                    num2 = this._Elements.Length;
                    this._LastUpdateIndex = 0;
                }
                else
                {
                    this._LastUpdateIndex = num2;
                }
            }
            else
            {
                num  = 0;
                num2 = this._Elements.Length;
                num3 = 0;
            }
            WaveParticlesQuadtree quadtree = (!flag) ? null : this._Qroot;
            float num4  = (!flag) ? 1.5f : 0.01f;
            float num5  = (!flag) ? 8f : 0.4f;
            bool  flag2 = false;

            num4 *= this._Qroot._Stress;
            num5 *= this._Qroot._Stress;
            int num6 = 0;

            while (this._ParticleGroups != null && num6 < this._ParticleGroups.Length)
            {
                WaveParticlesGroup waveParticlesGroup = this._ParticleGroups[num6];
                if (waveParticlesGroup != null)
                {
                    if (waveParticlesGroup.LeftParticle == null || !waveParticlesGroup.LeftParticle.IsAlive)
                    {
                        this._NumParticleGroups--;
                        this._ParticleGroups[num6] = null;
                    }
                    else if (time >= waveParticlesGroup.LastUpdateTime + num4)
                    {
                        if (time >= waveParticlesGroup.LastCostlyUpdateTime + num5 && !flag2)
                        {
                            if (!this.RectContainsParticleGroup(waveParticlesGroup))
                            {
                                this._NumParticleGroups--;
                                this._ParticleGroups[num6] = null;
                                goto IL_201;
                            }
                            waveParticlesGroup.CostlyUpdate(quadtree, time);
                            flag2 = true;
                            if (waveParticlesGroup.LeftParticle == null || !waveParticlesGroup.LeftParticle.IsAlive)
                            {
                                this._NumParticleGroups--;
                                this._ParticleGroups[num6] = null;
                                goto IL_201;
                            }
                        }
                        waveParticlesGroup.Update(time);
                    }
                }
IL_201:
                num6++;
            }
            if (this._Elements != null)
            {
                for (int j = num; j < num2; j++)
                {
                    WaveParticle waveParticle = this._Elements[j];
                    if (waveParticle != null)
                    {
                        if (waveParticle.IsAlive)
                        {
                            if (this._MarginRect.Contains(waveParticle.Position))
                            {
                                Vector3 vertexData         = waveParticle.VertexData;
                                Vector4 packedParticleData = waveParticle.PackedParticleData;
                                this._Vertices[num3]       = vertexData;
                                this._TangentsPack[num3++] = packedParticleData;
                                this._Vertices[num3]       = vertexData;
                                this._TangentsPack[num3++] = packedParticleData;
                                this._Vertices[num3]       = vertexData;
                                this._TangentsPack[num3++] = packedParticleData;
                                this._Vertices[num3]       = vertexData;
                                this._TangentsPack[num3++] = packedParticleData;
                                this._TangentsPackChanged  = true;
                            }
                            else
                            {
                                base.RemoveElementAt(j);
                                this._Vertices[num3++].x = float.NaN;
                                this._Vertices[num3++].x = float.NaN;
                                this._Vertices[num3++].x = float.NaN;
                                this._Vertices[num3++].x = float.NaN;
                                this._Qroot.AddElement(waveParticle);
                            }
                        }
                        else
                        {
                            base.RemoveElementAt(j);
                            this._Vertices[num3++].x = float.NaN;
                            this._Vertices[num3++].x = float.NaN;
                            this._Vertices[num3++].x = float.NaN;
                            this._Vertices[num3++].x = float.NaN;
                            waveParticle.AddToCache();
                        }
                    }
                    else
                    {
                        num3 += 4;
                    }
                }
            }
        }