Exemple #1
0
        //  USE THIS METHOD TO ADD MORE WAVEBANKS!!!
        public static void UnloadData()
        {
            MyMwcLog.WriteLine("MyAudio.UnloadData - START");

            MyHudAudio.UnloadData();

            //  This will quiet down the sounds and music immediatelly so we won't hear squeaking when starting background unload thread
            if (m_audioEngine != null)
            {
                VolumeGame = 0;
                VolumeMusic = 0;
                m_audioEngine.DoWork();
            }

            //  We need to dispose sounds because when unloading whole game-play screen, we need to turn-off any currently played sounds
            if (m_waveBanks != null)
            {
                foreach (WaveBank waveBank in m_waveBanks)
                {
                    if (!waveBank.IsDisposed)
                        waveBank.Dispose();
                }
                m_waveBanks.Clear();
                m_waveBanks = null;
            }

            if (m_sfxSoundBank != null) m_sfxSoundBank.Dispose();
            if (m_musicSoundBank != null) m_musicSoundBank.Dispose();
            if (m_dialogueSoundBank != null) m_dialogueSoundBank.Dispose();
            if (m_voiceSoundBank != null) m_voiceSoundBank.Dispose();
            //if (m_voiceSoundBank != null) m_voiceSoundBank.Dispose();

            m_x3dAudio = null;

            m_cuePool.Dispose();

            if (m_audioEngine != null) m_audioEngine.Dispose();

            MyXactVariables.UnloadData();

            MyMwcLog.WriteLine("MyAudio.UnloadData - END");
        }
Exemple #2
0
        public static void LoadData()
        {
            MyMwcLog.WriteLine("MyAudio.LoadData - START");
            MyMwcLog.IncreaseIndent();

            m_canPlay = true;
            try
            {
                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("new AudioEngine");
                //TimeSpan timeSpan = TimeSpan.FromMilliseconds(250);
                //m_audioEngine = new AudioEngine(MyPlugins.GetAudioFolder() + "Audio.xgs", timeSpan, "");
                using (var file = File.OpenRead(MyPlugins.GetAudioFolder() + "Audio.xgs"))
                {
                    m_audioEngine = new AudioEngine(file);
                    m_cuePool = new MyCuePool(m_audioEngine);
                }

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("new MyX3DAudio");

                m_x3dAudio = new MyX3DAudio(m_audioEngine);

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
            }
            catch (Exception ex)
            {
                MyMwcLog.WriteLine("Exception during loading audio engine. Game continues, but without sound. Details: " + ex.ToString(), LoggingOptions.AUDIO);

                //  This exception is the only way I can know if we can play sound (e.g. if computer doesn't have sound card).
                //  I didn't find other ways of checking it.
                m_canPlay = false;
            }

            if (m_canPlay)
            {
                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyXactVariables.LoadData");
                MyXactVariables.LoadData();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("AddWaveBanks");
                // IMPORTANT!!! Currently, there is problem with multiple XACT projects, that when anything changes in Music.xap or Voice.xap,
                // it is necessary to open and save Sounds.xap also, in order to run the game properly(otherwise it has problem to load the SoundBank.xsb)
                // this will be solved later in future
                AddWaveBanks();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("Adding sound banks");

                MyMwcLog.WriteLine("Adding sound banks", LoggingOptions.AUDIO);
                using (var file = File.OpenRead(MyPlugins.GetAudioFolder() + "Music.xsb"))
                {
                    m_musicSoundBank = new SoundBank(m_audioEngine, file);
                }
                using (var file = File.OpenRead(MyPlugins.GetAudioFolder() + "Sounds.xsb"))
                {
                    m_sfxSoundBank = new SoundBank(m_audioEngine, file);
                }
                using (var file = File.OpenRead(MyPlugins.GetAudioFolder() + "Dialogues.xsb"))
                {
                    m_dialogueSoundBank = new SoundBank(m_audioEngine, file);
                }
                using (var file = File.OpenRead(MyPlugins.GetAudioFolder() + "Voice.xsb"))
                {
                    m_voiceSoundBank = new SoundBank(m_audioEngine, file);
                }

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("Categories");

                //m_voiceSoundBank = new SoundBank(m_audioEngine, MyPlugins.GetAudioFolder() + "Voice.xsb");
                m_listener = new Listener();
                m_listener.SetDefaultValues();
                m_helperEmitter = new Emitter();
                m_helperEmitter.SetDefaultValues();
                m_defaultCategory = m_audioEngine.GetCategoryInstance("Default");
                m_wep2DCategory = m_audioEngine.GetCategoryInstance("wep2d");
                m_cockpitCategory = m_audioEngine.GetCategoryInstance("Cockpit");
                m_musicCategory = m_audioEngine.GetCategoryInstance("Music");
                m_guiCategory = m_audioEngine.GetCategoryInstance("Gui");
                m_doorCategory = m_audioEngine.GetCategoryInstance("Door");
                m_enginesCategory = m_audioEngine.GetCategoryInstance("Engines");
                m_dialogueCategory = m_audioEngine.GetCategoryInstance("Dialogues");
                m_shoutsCategory = m_audioEngine.GetCategoryInstance("Shouts");
                m_hudCategory = m_audioEngine.GetCategoryInstance("VocHud");
                m_ambCategory = m_audioEngine.GetCategoryInstance("Amb");
                m_drillsCategory = m_audioEngine.GetCategoryInstance("Drills");
                m_impCategory = m_audioEngine.GetCategoryInstance("Imp");
                m_importantsCategory = m_audioEngine.GetCategoryInstance("IMPORTANTS");
                m_sfxCategory = m_audioEngine.GetCategoryInstance("Sfx");
                m_voiceCategory = m_audioEngine.GetCategoryInstance("Voice");
                m_welcomeCategory = m_audioEngine.GetCategoryInstance("Welcomes");
                m_wep3DCategory = m_audioEngine.GetCategoryInstance("Wep3D");
                m_xCategory = m_audioEngine.GetCategoryInstance("X");

                m_gameCategories = new List<AudioCategory>();
                m_gameCategories.Add(m_defaultCategory);
                m_gameCategories.Add(m_wep2DCategory);
                m_gameCategories.Add(m_cockpitCategory);
                m_gameCategories.Add(m_doorCategory);
                m_gameCategories.Add(m_enginesCategory);
                m_gameCategories.Add(m_dialogueCategory);
                m_gameCategories.Add(m_shoutsCategory);
                m_gameCategories.Add(m_hudCategory);
                m_gameCategories.Add(m_ambCategory);
                m_gameCategories.Add(m_drillsCategory);
                m_gameCategories.Add(m_impCategory);
                m_gameCategories.Add(m_importantsCategory);
                m_gameCategories.Add(m_sfxCategory);
                m_gameCategories.Add(m_voiceCategory);
                m_gameCategories.Add(m_welcomeCategory);
                m_gameCategories.Add(m_wep3DCategory);
                m_gameCategories.Add(m_xCategory);

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("WaitForWaveBanks");

                //  AudioEngine.Update needs to be called at least once before a streaming wave bank is ready
                MyMwcLog.WriteLine("Updating audio engine...", LoggingOptions.AUDIO);
                WaitForWaveBanks();

                //  This is reverb turned to off, so we hear sounds as they are defined in wav files
                ReverbControl = 100;

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("PreloadCueInfo");

                PreloadCueInfo(); // Takes about 26 ms

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("ValidateCues");

#if DEBUG
                ThreadPool.QueueUserWorkItem(ValidateCue_Thread); // Takes 4000 ms on background thread
#endif

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("InitCueParameters");

                InitCueParameters();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("InitNonLoopableCuesLimitRemoveHelper");

                InitNonLoopableCuesLimitRemoveHelper();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyHudAudio.LoadData");

                MyHudAudio.LoadData();

                //  Volume from config
                m_musicOn = true;
                m_gameSoundsOn = true;
                m_musicAllowed = true;
                VolumeMusic = MyConfig.MusicVolume;
                VolumeGame = MyConfig.GameVolume;
                VolumeGui = MyConfig.GameVolume;
                MyConfig.MusicVolume = VolumeMusic;
                MyConfig.GameVolume = VolumeGame;

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyConfig.Save");

                MyConfig.Save();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
            }

            MyMwcLog.DecreaseIndent();
            MyMwcLog.WriteLine("MyAudio.LoadData - END");
        }