示例#1
0
        public static uint RegisterTemp(Vector3 pos)
        {
            AkAuxSendArray array = new AkAuxSendArray(Zone.MaxAuxSend);

            Zone.AuxSend(pos, array);
            return(AkSoundEngine.RegisterTemp(pos, array));
        }
示例#2
0
文件: Water.cs 项目: schmittens/Lemma
        void IUpdateableComponent.Update(float dt)
        {
            if (this.main.Paused)
            {
                return;
            }

            bool newUnderwater = this.Fluid.BoundingBox.Contains(this.main.Camera.Position) != ContainmentType.Disjoint;

            if (newUnderwater != this.underwater)
            {
                AkSoundEngine.SetState(AK.STATES.WATER.GROUP, newUnderwater ? AK.STATES.WATER.STATE.UNDERWATER : AK.STATES.WATER.STATE.NORMAL);
            }
            this.underwater = newUnderwater;

            int drawOrder = this.CannotSuspendByDistance && newUnderwater ? 10 : -15;

            if (this.DrawOrder != drawOrder)
            {
                this.DrawOrder.Value = drawOrder;
            }

            Water.BigWaterShader.Value = this.CannotSuspendByDistance && !newUnderwater;

            float waterHeight = this.Position.Value.Y;

            float time = this.main.TotalTime;

            lock (this.Fluid.NotifyEntries)
            {
                foreach (BEPUphysics.BroadPhaseEntries.MobileCollidables.EntityCollidable collidable in this.Fluid.NotifyEntries)
                {
                    if (collidable.Entity == null)
                    {
                        continue;
                    }

                    float speed = collidable.Entity.LinearVelocity.Length();

                    if (speed > 9.0f)
                    {
                        float volume = Math.Min(speed * collidable.Entity.Mass * speedMassVolumeCoefficient, 1.0f);
                        if (volume > 0.1f && !this.submerged.ContainsKey(collidable))
                        {
                            uint temp = AkSoundEngine.RegisterTemp(collidable.Entity.Position);
                            if (collidable.Entity.Mass > 40.0f)
                            {
                                AkSoundEngine.PostEvent(AK.EVENTS.PLAY_WATER_SPLASH_HEAVY, temp);
                            }
                            else
                            {
                                AkSoundEngine.PostEvent(AK.EVENTS.PLAY_WATER_SPLASH, temp);
                            }
                            AkSoundEngine.SetRTPCValue(AK.GAME_PARAMETERS.SFX_WATER_SPLASH_VOLUME, volume, temp);
                            AkSoundEngine.UnregisterTemp(temp);
                        }
                    }

                    if (speed > 5.0f)
                    {
                        collidable.UpdateBoundingBox();
                        BoundingBox boundingBox       = collidable.BoundingBox;
                        Vector3     diff              = boundingBox.Max - boundingBox.Min;
                        Vector3[]   particlePositions = new Vector3[5 * (int)(diff.X * diff.Z)];

                        Voxel v             = collidable.Tag as Voxel;
                        int   particleIndex = 0;
                        for (int i = 0; i < particlePositions.Length; i++)
                        {
                            Vector3 pos = particlePositions[particleIndex] = new Vector3
                                                                             (
                                boundingBox.Min.X + ((float)this.random.NextDouble() * diff.X),
                                waterHeight,
                                boundingBox.Min.Z + ((float)this.random.NextDouble() * diff.Z)
                                                                             );
                            if (v == null || v[pos] != Voxel.States.Empty)
                            {
                                particleIndex++;
                            }
                        }

                        ParticleEmitter.Emit(this.main, "Splash", particlePositions.Take(particleIndex));

                        ParticleEmitter.Emit(this.main, "BigSplash", particlePositions.Take(particleIndex / 5));
                    }

                    this.submerged[collidable] = time;
                }
                this.Fluid.NotifyEntries.Clear();
            }

            foreach (KeyValuePair <BEPUphysics.BroadPhaseEntries.MobileCollidables.EntityCollidable, float> p in this.submerged.ToList())
            {
                if (time - p.Value > 0.1f)
                {
                    if (p.Key.Entity != null)
                    {
                        float speed = p.Key.Entity.LinearVelocity.Y;
                        if (speed > 2.0f)
                        {
                            float volume = Math.Min(speed * p.Key.Entity.Mass * speedMassVolumeCoefficient, 1.0f);
                            if (volume > 0.1f)
                            {
                                uint temp = AkSoundEngine.RegisterTemp(p.Key.Entity.Position);
                                AkSoundEngine.PostEvent(AK.EVENTS.PLAY_WATER_SPLASH_OUT, temp);
                                AkSoundEngine.SetRTPCValue(AK.GAME_PARAMETERS.SFX_WATER_SPLASH_VOLUME, volume, temp);
                                AkSoundEngine.UnregisterTemp(temp);
                            }
                        }
                    }
                    this.submerged.Remove(p.Key);
                }
            }
        }