Esempio n. 1
0
        private static bool LoadSoundInfo(ChunkReader chunkIO, Wad2 wad, Dictionary <long, WadSample> samples,
                                          out WadSoundInfo soundInfo, out long index)
        {
            var   tempSoundInfo = new WadSoundInfo(0);
            long  tempIndex     = 0;
            float volume        = 0;
            float chance        = 0;
            float pitch         = 0;
            float range         = 0;

            chunkIO.ReadChunks((id2, chunkSize2) =>
            {
                // XML_SOUND_SYSTEM
                if (id2 == Wad2Chunks.SoundInfoIndex)
                {
                    tempIndex = chunkIO.ReadChunkLong(chunkSize2);
                }
                else if (id2 == Wad2Chunks.SoundInfoVolume)
                {
                    volume = chunkIO.ReadChunkFloat(chunkSize2);
                }
                else if (id2 == Wad2Chunks.SoundInfoRange)
                {
                    range = chunkIO.ReadChunkFloat(chunkSize2);
                }
                else if (id2 == Wad2Chunks.SoundInfoPitch)
                {
                    pitch = chunkIO.ReadChunkFloat(chunkSize2);
                }
                else if (id2 == Wad2Chunks.SoundInfoChance)
                {
                    chance = chunkIO.ReadChunkFloat(chunkSize2);
                }
                else if (id2 == Wad2Chunks.SoundInfoDisablePanning)
                {
                    tempSoundInfo.DisablePanning = chunkIO.ReadChunkBool(chunkSize2);
                }
                else if (id2 == Wad2Chunks.SoundInfoRandomizePitch)
                {
                    tempSoundInfo.RandomizePitch = chunkIO.ReadChunkBool(chunkSize2);
                }
                else if (id2 == Wad2Chunks.SoundInfoRandomizeVolume)
                {
                    tempSoundInfo.RandomizeVolume = chunkIO.ReadChunkBool(chunkSize2);
                }
                else if (id2 == Wad2Chunks.SoundInfoLoopBehaviour)
                {
                    tempSoundInfo.LoopBehaviour = (WadSoundLoopBehaviour)(3 & chunkIO.ReadChunkByte(chunkSize2));
                }
                else if (id2 == Wad2Chunks.SoundInfoName || id2 == Wad2Chunks.SoundInfoNameObsolete)
                {
                    tempSoundInfo.Name = chunkIO.ReadChunkString(chunkSize2);
                }
                else if (id2 == Wad2Chunks.SoundInfoSampleIndex)
                {
                    tempSoundInfo.Samples.Add(samples[chunkIO.ReadChunkInt(chunkSize2)]); // Legacy
                }
                else
                {
                    return(false);
                }
                return(true);
            });

            // Convert from floats to ints
            tempSoundInfo.Volume         = (int)Math.Round(volume * 100.0f);
            tempSoundInfo.RangeInSectors = (int)range;
            tempSoundInfo.Chance         = (int)Math.Round(chance * 100.0f);
            tempSoundInfo.PitchFactor    = (int)Math.Round((pitch - 1.0f) * 100.0f);

            // Try to get the old ID
            tempSoundInfo.Id = TrCatalog.TryGetSoundInfoIdByDescription(wad.GameVersion, tempSoundInfo.Name);

            if (string.IsNullOrWhiteSpace(tempSoundInfo.Name))
            {
                tempSoundInfo.Name = TrCatalog.GetOriginalSoundName(wad.GameVersion, unchecked ((uint)tempIndex));
            }

            index     = tempIndex;
            soundInfo = tempSoundInfo;

            return(true);
        }