示例#1
0
            }   // end of Playing()

            #endregion

            #region Internal

            private void Restart(AudioCue audioCue, GameThing emitter)
            {
                audioCue.Reset();
                Cue cue = BokuGame.Audio.SoundBank.GetCue(soundName);

                audioCue.Set(cue, emitter);
                audioCue.Play();
                frame    = Time.FrameCounter;
                lastTime = Time.WallClockTotalSeconds;
            }   // end of Restart()
示例#2
0
        /// <summary>
        /// Pass an update to the underlying audio engine, as well as
        /// cull dead sounds from our active list. Finally, give active
        /// cues a chance to apply 3d effects.
        /// </summary>
        public void Update()
        {
            //            this.updateTimer.Start();

            // Limit audio updates to 60 fps
            //if (Time.GameTimeTotalSeconds > lastFrameTimeSeconds &&
            //    Time.GameTimeTotalSeconds - lastFrameTimeSeconds < 1 / 60.0f)
            //    return;

            lastFrameTimeSeconds = Time.GameTimeTotalSeconds;

            if (Enabled)
            {
                engine.Update();

                if (InGame.inGame != null)
                {
                    // Update 3D audio listener values from camera state
                    listener.Position = InGame.inGame.Camera.ActualFrom;
                    listener.Up       = InGame.inGame.Camera.ViewUp;
                    listener.Forward  = InGame.inGame.Camera.ViewDir;
                    listener.Velocity = Vector3.Zero; // Camera doesn't expose a "Velocity" property
                }
            }

            // Loop through active audio cues, updating 3D values and recycling completed cues
            for (int cueIndex = activeCues.Count - 1; cueIndex >= 0; --cueIndex)
            {
                AudioCue cue = activeCues[cueIndex];

                if (cue.VirtualDone())
                {
                    cue.DetachSound();
                }

                // If cue is done playing, recycle it. Because we create
                // and destroy AudioCue objects frequently, this helps avoid
                // unnecessary garbage collector activity.
                if (cue.IsComplete)
                {
                    cue.Reset();
                    spareCues.Add(cue);
                    activeCues.RemoveAt(cueIndex);
                    continue;
                }

                // Update cue's 3D audio values
                if (Enabled)
                {
                    cue.Apply3D(listener);
                }
            }
            //            this.updateTimer.Stop();
        }