示例#1
0
 internal static void Reset()
 {
     DigBlock = PlayerHit = UseItem = NpcHit = NpcKilled = PlayerKilled = CutGrass
                                                                              = GrabItem = DoorOpen = MenuOpen = MenuClose = MenuTick = Shatter
                                                                                                                                            = ZombieIdle = NpcAttackSound = DoubleJump = Run = Buy = Splash = FemaleHit
                                                                                                                                                                                                                  = DigOre = Unlock = Drown = Chat = MaxMana = MummyIdle = PixieIdle
                                                                                                                                                                                                                                                                               = MechBuzz = NpcIdleSound = DuckIdle = FrogIdle = NpcIdleSoundQuiet = BeetleIdle = AmbientWater
                                                                                                                                                                                                                                                                                                                                                                      = AmbientLava = NpcAttackSoundExpert = Meowmere = CoinPickup = AmbientDrip = Camera = MoonLordCry
                                                                                                                                                                                                                                                                                                                                                                                                                                                                = null;
 }
示例#2
0
        static Tuple <int, float, float, float> CalcParams(SfxEntry e, Vector2 pos, int v, PlaySoundEvent onPlay)
        {
            var volSetting = e.IsAmbient ? (Main.gameInactive ? 0f : Main.ambientVolume) : Main.soundVolume;

            if (volSetting <= 0f)
            {
                return(null);
            }

            bool shouldPlay = true;
            float
                vol = 1f, pitch = 0f, pan = 0f;

            if (pos.X <= 0f || pos.Y <= 0f || Single.IsNaN(pos.X) || Single.IsNaN(pos.Y))
            {
                shouldPlay = true;
            }
            else
            {
#pragma warning disable RECS0091 // Use 'var' keyword when possible
                                 // to the code analyser: learn to C#
                Rectangle
#pragma warning restore RECS0091
                screen = new Rectangle((int)(Main.screenPosition.X - Main.screenWidth * 2), (int)(Main.screenPosition.Y - Main.screenHeight * 2), Main.screenWidth * 5, Main.screenHeight * 5),
                sound  = new Rectangle((int)pos.X, (int)pos.Y, 1, 1);

                shouldPlay |= sound.Intersects(screen);

                if (shouldPlay)
                {
                    var screenCentre = new Vector2(Main.screenPosition.X + Main.screenWidth * 0.5f, Main.screenPosition.Y + Main.screenHeight * 0.5f);

                    pan = (pos.X - screenCentre.X) / (Main.screenWidth * 0.5f);
                    vol = 1f - Vector2.Distance(pos, screenCentre) / (Main.screenWidth * 1.5f);
                }
            }
            pan = MathHelper.Clamp(pan, -1f, 1f);
            vol = Math.Min(vol * volSetting, 1f);

            if (vol <= 0f)
            {
                return(null);
            }

            if (onPlay != null && !onPlay(e, pos, ref v, ref vol, ref pitch, ref pan))
            {
                return(null);
            }

            vol   = MathHelper.Clamp(vol, 0f, 1f);
            pitch = MathHelper.Clamp(pitch, -1f, 1f);
            pan   = MathHelper.Clamp(pan, -1f, 1f);

            return(Tuple.Create(v, vol, pitch, pan));
        }
示例#3
0
        public static SoundEffectInstance Play(SfxEntry entry, Point tilePos, int variant, float volMod = Single.NaN, float pitch = Single.NaN, float panMod = Single.NaN)
        {
            return(Play(entry, tilePos.ToVector2() * 16f, variant, (SfxEntry e, Vector2 p, ref int v, ref float vol, ref float pi, ref float pan) =>
            {
                if (!Single.IsNaN(vol))
                {
                    vol *= volMod;
                }
                if (!Single.IsNaN(pi))
                {
                    pi = pitch;
                }
                if (!Single.IsNaN(pan))
                {
                    pan *= panMod;
                }

                return true;
            }));
        }
示例#4
0
        public static SoundEffectInstance Play(SfxEntry entry, Vector2 position, int variant, float volMod = Single.NaN, float pitch = Single.NaN, float panMod = Single.NaN)
        {
            return(Play(entry, position, variant, (SfxEntry e, Vector2 p, ref int v, ref float vol, ref float pi, ref float pan) =>
            {
                if (!Single.IsNaN(volMod))
                {
                    vol *= volMod;
                }
                if (!Single.IsNaN(pitch))
                {
                    pi = pitch;
                }
                if (!Single.IsNaN(panMod))
                {
                    pan *= panMod;
                }

                return true;
            }));
        }
示例#5
0
 public static SoundEffectInstance Play(SfxEntry entry, Point tilePos)
 {
     return(Play(entry, tilePos.ToVector2() * 16f, -1, null));
 }
示例#6
0
 public static SoundEffectInstance Play(SfxEntry entry, Point tilePos, int variant, PlaySoundEvent onPlay)
 {
     return(Play(entry, tilePos.ToVector2() * 16f, variant, onPlay));
 }
示例#7
0
 public static SoundEffectInstance Play(SfxEntry entry, Vector2 position)
 {
     return(Play(entry, position, -1, null));
 }
示例#8
0
        public static SoundEffectInstance Play(SfxEntry entry, Vector2 position, int variant, PlaySoundEvent onPlay)
        {
            if (Main.dedServ || WorldGen.gen || Main.netMode == 2)
            {
                return(null);
            }

            var kvp = new KeyValuePair <SfxEntry, int>(entry, entry.Variants == 1 ? 0 : variant);

            var t = CalcParams(entry, position, variant, onPlay);

            if (t == null || t.Item2 <= 0f)
            {
                return(null);
            }

            SoundEffectInstance inst;
            var b = entry.PlayBehaviour(variant);

            switch (b)
            {
            case SfxPlayBehaviour.MultipleInstances:
                inst = entry.GetInstance(variant);

                if (inst == null)
                {
                    return(null);
                }

                instancePool.Add(inst);     // don't GC
                break;

            case SfxPlayBehaviour.PlayIfStopped:
            case SfxPlayBehaviour.PlayIfStoppedUpdateParams:
                if (instanceMap.ContainsKey(kvp))
                {
                    var inst_ = instanceMap[kvp];

                    if (inst_.State == SoundState.Stopped)
                    {
                        inst = inst_;
                    }
                    else
                    {
                        if (b == SfxPlayBehaviour.PlayIfStoppedUpdateParams)
                        {
                            ApplyParams(inst_, t);
                        }

                        return(null);
                    }
                }
                else
                {
                    inst = entry.GetInstance(variant);

                    if (inst == null)
                    {
                        return(null);
                    }

                    instanceMap.Add(kvp, inst);
                }
                break;

            case SfxPlayBehaviour.Singleton:
                if (instanceMap.ContainsKey(kvp))
                {
                    var inst_ = instanceMap[kvp];

                    inst_.Stop();

                    instanceMap.Remove(kvp);
                }

                inst = entry.GetInstance(variant);

                if (inst == null)
                {
                    return(null);
                }

                instanceMap.Add(kvp, inst);
                break;

            // required, compiler will complain about 'inst' not being assigned to otherwise
            // and this is more foolproof than setting 'inst' to null.
            default:
                return(null);
            }

            ApplyParams(inst, t);

            inst.Play(); // !

            CleanupLingeringInstances();

            return(inst);
        }
示例#9
0
        internal static void FillVanilla()
        {
            DigBlock  = GetVanilla(Main.soundDig);
            PlayerHit = GetVanilla(Main.soundPlayerHit);

            UseItem = GetVanilla(Main.soundItem, v =>
            {
                switch (v)
                {
                case 55:
                case 57:
                    return(SfxPlayBehaviour.PlayIfStopped);

                case 9:
                case 10:
                case 24:
                case 26:
                case 34:
                case 43:
                case 103:
                    return(SfxPlayBehaviour.MultipleInstances);

                default:
                    return(SfxPlayBehaviour.Singleton);
                }
            });
            NpcHit    = GetVanilla(Main.soundNPCHit, v => v == 57 /* moon lord roar */ ? SfxPlayBehaviour.PlayIfStopped : SfxPlayBehaviour.Singleton);
            NpcKilled = GetVanilla(Main.soundNPCKilled, v => v == 10 /* wall of flesh  */ ? SfxPlayBehaviour.PlayIfStopped : SfxPlayBehaviour.MultipleInstances);

            PlayerKilled = GetVanilla(Main.soundPlayerKilled);
            CutGrass     = GetVanilla(Main.soundGrass);
            GrabItem     = GetVanilla(Main.soundGrab);
            DoorOpen     = GetVanilla(Main.soundDoorOpen);
            DoorClose    = GetVanilla(Main.soundDoorClosed);
            MenuClose    = GetVanilla(Main.soundMenuClose);
            MenuOpen     = GetVanilla(Main.soundMenuOpen);
            MenuTick     = GetVanilla(Main.soundMenuTick);
            Shatter      = GetVanilla(Main.soundShatter);

            ZombieIdle = new SfxEntry(v =>
            {
                v = v == NPCID.BloodZombie ? Main.rand.Next(21, 24) : Main.rand.Next(3);

                return(Main.soundZombie[v].CreateInstance());
            }, NPCID.BloodZombie + 1, _ => SfxPlayBehaviour.MultipleInstances);

            NpcAttackSound = new SfxEntry(v => Main.soundRoar[v == -1 ? 0 : v].CreateInstance(), Main.soundRoar.Length, _ => SfxPlayBehaviour.PlayIfStopped);

            DoubleJump = GetVanilla(Main.soundDoubleJump);
            Run        = GetVanilla(Main.soundRun);

            Buy = GetVanilla(Main.soundCoins, SfxPlayBehaviour.MultipleInstances);

            Splash = GetVanilla(Main.soundSplash, SfxPlayBehaviour.PlayIfStopped);

            FemaleHit = GetVanilla(Main.soundFemaleHit);
            DigOre    = GetVanilla(Main.soundTink);
            Unlock    = GetVanilla(Main.soundUnlock);
            Drown     = GetVanilla(Main.soundDrown);

            Chat    = GetVanilla(Main.soundChat, SfxPlayBehaviour.MultipleInstances);
            MaxMana = GetVanilla(Main.soundMaxMana, SfxPlayBehaviour.MultipleInstances);

            MummyIdle    = GetVanilla(Main.soundZombie.Subarray(3, 3), SfxPlayBehaviour.MultipleInstances);
            PixieIdle    = GetVanilla(Main.soundPixie, SfxPlayBehaviour.PlayIfStoppedUpdateParams);
            MechBuzz     = GetVanilla(Main.soundMech, SfxPlayBehaviour.PlayIfStopped);
            NpcIdleSound = GetVanilla(Main.soundZombie, SfxPlayBehaviour.PlayIfStopped);

            DuckIdle = new SfxEntry(v =>
            {
                v = Main.rand.Next(300) == 0 ? 12 : (v == -1 ? Main.rand.Next(10, 12) : v + 10);

                return(Main.soundZombie[v].CreateInstance());
            }, 2, _ => SfxPlayBehaviour.PlayIfStopped, true);

            FrogIdle          = GetVanilla(Main.soundZombie[13], SfxPlayBehaviour.MultipleInstances, true);
            NpcIdleSoundQuiet = GetVanilla(Main.soundZombie, SfxPlayBehaviour.PlayIfStopped, true);
            BeetleIdle        = GetVanilla(Main.soundZombie[15], SfxPlayBehaviour.PlayIfStopped, true);

            AmbientWater = GetVanilla(Main.soundLiquid[0], SfxPlayBehaviour.PlayIfStoppedUpdateParams, true);
            AmbientLava  = GetVanilla(Main.soundLiquid[1], SfxPlayBehaviour.PlayIfStoppedUpdateParams, true);

            NpcAttackSoundExpert = new SfxEntry(v => Main.soundRoar[v == -1 ? 0 : v].CreateInstance(), Main.soundRoar.Length, _ => SfxPlayBehaviour.MultipleInstances);

            Meowmere   = GetVanilla(Main.soundItem.Subarray(57, 2), SfxPlayBehaviour.MultipleInstances);
            CoinPickup = GetVanilla(Main.soundCoin, SfxPlayBehaviour.MultipleInstances);

            AmbientDrip = GetVanilla(Main.soundDrip, SfxPlayBehaviour.MultipleInstances, true);

            Camera = GetVanilla(Main.soundCamera);

            MoonLordCry = GetVanilla(Main.soundNPCKilled[10], SfxPlayBehaviour.MultipleInstances);

            PopulateDict();
        }