public void StopPreviewSound()
        {
            if (this.prevSoundInst == null) return;

            this.prevSoundInst.FadeOut(0.25f);
            this.prevSoundInst = null;
            this.Invalidate();
        }
		public void PlayPreviewSound()
		{
			if (this.prevSound == null) return;
			if (this.prevSoundInst != null) return;

			this.prevSoundInst = DualityApp.Sound.PlaySound(this.prevSound);
			this.prevSoundInst.Looped = true;
			this.Invalidate();
		}
        public void OnUpdate()
        {
            ((AnimSpriteRenderer) GameObj.Renderer).AnimPaused = true;

            var elapsedTime = Time.TimeScale * (Time.LastDelta / 1000);

            if (DualityApp.Keyboard[Key.D])
            {
                GameObj.Transform.Pos = new Vector3(GameObj.Transform.Pos.X + BaseSpeed * _speedDamping * elapsedTime, GameObj.Transform.Pos.Y, GameObj.Transform.Pos.Z);
                ((AnimSpriteRenderer) GameObj.Renderer).AnimPaused = false;
                ((AnimSpriteRenderer) GameObj.Renderer).SharedMaterial = GameRes.Data.Material.HunterWalk_Material;

                GameObj.ChildByName("AxeLeft").Active = false;
                GameObj.ChildByName("AxeRight").Active = true;

                if(_footstepSound == null || _footstepSound.PlayTime > 0.9f)
                    _footstepSound = DualityApp.Sound.PlaySound(GameRes.Data.Sounds.footstep_snow_2_Sound);
            }
            else if (DualityApp.Keyboard[Key.A])
            {
                GameObj.Transform.Pos = new Vector3(GameObj.Transform.Pos.X - BaseSpeed * _speedDamping * elapsedTime, GameObj.Transform.Pos.Y, GameObj.Transform.Pos.Z);
                ((AnimSpriteRenderer)GameObj.Renderer).AnimPaused = false;
                ((AnimSpriteRenderer)GameObj.Renderer).SharedMaterial = GameRes.Data.Material.HunterWalkLeft_Material;

                GameObj.ChildByName("AxeLeft").Active = true;
                GameObj.ChildByName("AxeRight").Active = false;

                if (_footstepSound == null || _footstepSound.PlayTime > 0.9f)
                    _footstepSound = DualityApp.Sound.PlaySound(GameRes.Data.Sounds.footstep_snow_2_Sound);
            }

            if (DualityApp.Keyboard.KeyHit(Key.Space) && _woodComponent.CurrentWood < MaxLogs)
            {
                DualityApp.Sound.PlaySound(GameRes.Data.Sounds.axe_swoosh_Sound);
                GameObj.GetComponentsInChildren<Axe>().First(c => c.Active).Chop();
            }

            var snowSkirt = Scene.Current.FindGameObject("SnowSkirt").GetComponent<SnowSkirt>();
            var snowHeight = snowSkirt.GetSnowHeightAtPoint(GameObj.Transform.Pos.X);

            _speedDamping = MathF.Clamp(1 - MathF.Abs(snowHeight) / 500, 0.3f, 1);

            if (DualityApp.Keyboard.KeyHit(Key.E) && _woodComponent.HasAnyWood)
            {
                var log = GameRes.Data.Prefabs.BurningLog_Prefab.Res.Instantiate();
                log.Transform.Pos += GameObj.Transform.Pos;
                Scene.Current.AddObject(log);
                _woodComponent.TakeWood();
            }
        }
Exemple #4
0
		private void OnDisposed(bool manually)
		{
			this.prio = SoundBudgetPriority.Lowest;
			if (this.instance != null)
			{
				this.instance.Stop();
				this.instance = null;
			}
		}
Exemple #5
0
		}					//	GS
		
		internal SoundBudgetPad(SoundInstance snd, SoundBudgetPriority prio)
		{
			this.instance = snd;
			this.prio = prio;
		}
Exemple #6
0
		/// <summary>
		/// Plays a sound 3d "in space".
		/// </summary>
		/// <param name="snd">The Sound to play.</param>
		/// <param name="attachTo">The GameObject to which the sound will be attached.</param>
		/// <param name="relativePos">The position of the sound relative to the GameObject.</param>
		/// <returns>A new SoundInstance representing the currentply playing sound.</returns>
		public SoundInstance PlaySound3D(ContentRef<Sound> snd, GameObject attachTo, Vector3 relativePos)
		{
			SoundInstance inst = new SoundInstance(snd, attachTo);
			inst.Pos = relativePos;
			this.sounds.Add(inst);
			return inst;
		}
Exemple #7
0
		/// <summary>
		/// Plays a sound 3d "in space".
		/// </summary>
		/// <param name="snd">The Sound to play.</param>
		/// <param name="attachTo">The GameObject to which the sound will be attached.</param>
		/// <returns>A new SoundInstance representing the currentply playing sound.</returns>
		public SoundInstance PlaySound3D(ContentRef<Sound> snd, GameObject attachTo)
		{
			SoundInstance inst = new SoundInstance(snd, attachTo);
			this.sounds.Add(inst);
			return inst;
		}
Exemple #8
0
		/// <summary>
		/// Plays a sound 3d "in space".
		/// </summary>
		/// <param name="snd">The Sound to play.</param>
		/// <param name="pos">The position of the sound in space.</param>
		/// <returns>A new SoundInstance representing the currentply playing sound.</returns>
		public SoundInstance PlaySound3D(ContentRef<Sound> snd, Vector3 pos)
		{
			SoundInstance inst = new SoundInstance(snd, pos);
			this.sounds.Add(inst);
			return inst;
		}
Exemple #9
0
		/// <summary>
		/// Plays a sound.
		/// </summary>
		/// <param name="snd">The Sound to play.</param>
		/// <returns>A new SoundInstance representing the currentply playing sound.</returns>
		public SoundInstance PlaySound(ContentRef<Sound> snd)
		{
			SoundInstance inst = new SoundInstance(snd);
			this.sounds.Add(inst);
			return inst;
		}
		protected virtual void OnDisposed(bool disposing)
		{
			if (!this.disposed)
			{
				this.prio = SoundBudgetPriority.Lowest;
				if (this.sound != null)
				{
					this.sound.Stop();
					this.sound = null;
				}
				this.disposed = true;
			}
		}
		}					//	GS
		
		internal SoundBudgetPad(SoundInstance snd, SoundBudgetPriority prio, bool music = true)
		{
			this.sound = snd;
			this.prio = prio;
		}
Exemple #12
0
        }                                               //	GS

        internal SoundBudgetPad(SoundInstance snd, SoundBudgetPriority prio)
        {
            this.instance = snd;
            this.prio     = prio;
        }
Exemple #13
0
        private static void ThreadStreamFunc(object param)
        {
            SoundInstance sndInst = (SoundInstance)param;

            while (true)
            {
                lock (sndInst.strLock)
                {
                    if (sndInst.Disposed)
                    {
                        return;
                    }
                    if (!DualityApp.Sound.IsAvailable)
                    {
                        return;
                    }

                    ALSourceState stateTemp = ALSourceState.Stopped;
                    if (sndInst.alSource > AlSource_NotAvailable)
                    {
                        stateTemp = AL.GetSourceState(sndInst.alSource);
                    }

                    if (sndInst.strStopReq)
                    {
                        // Stopped intentionally due to Stop() or eof. If strStopReq is NOT set,
                        // the source stopped playing because it reached the end of the buffer
                        // but in fact only because we were too slow inserting new data.
                        if (stateTemp != ALSourceState.Stopped)
                        {
                            sndInst.Stop();
                        }
                        return;
                    }

                    Sound res = sndInst.snd.Res;
                    if (res == null)
                    {
                        sndInst.Dispose();
                        return;
                    }
                    if (stateTemp == ALSourceState.Initial)
                    {
                        // Generate streaming buffers
                        sndInst.strAlBuffers = new int[3];
                        for (int i = 0; i < sndInst.strAlBuffers.Length; ++i)
                        {
                            AL.GenBuffers(1, out sndInst.strAlBuffers[i]);
                        }

                        // Begin streaming
                        OV.BeginStreamFromMemory(res.Data.Res.OggVorbisData, out sndInst.strOvStr);

                        // Initially, completely fill all buffers
                        for (int i = 0; i < sndInst.strAlBuffers.Length; ++i)
                        {
                            PcmData pcm;
                            bool    eof = !OV.StreamChunk(sndInst.strOvStr, out pcm);
                            if (pcm.data.Length > 0)
                            {
                                AL.BufferData(
                                    sndInst.strAlBuffers[i],
                                    pcm.channelCount == 1 ? ALFormat.Mono16 : ALFormat.Stereo16,
                                    pcm.data,
                                    pcm.data.Length,
                                    pcm.sampleRate);
                                AL.SourceQueueBuffer(sndInst.alSource, sndInst.strAlBuffers[i]);
                                if (eof)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }

                        // Initially play source
                        AL.SourcePlay(sndInst.alSource);
                        stateTemp = AL.GetSourceState(sndInst.alSource);
                    }
                    else
                    {
                        int num;
                        AL.GetSource(sndInst.alSource, ALGetSourcei.BuffersProcessed, out num);
                        while (num > 0)
                        {
                            num--;

                            int unqueued;
                            unqueued = AL.SourceUnqueueBuffer(sndInst.alSource);

                            if (sndInst.strOvStr != IntPtr.Zero)
                            {
                                PcmData pcm;
                                bool    eof = !OV.StreamChunk(sndInst.strOvStr, out pcm);
                                if (pcm.data.Length > 0)
                                {
                                    AL.BufferData(
                                        unqueued,
                                        pcm.channelCount == 1 ? ALFormat.Mono16 : ALFormat.Stereo16,
                                        pcm.data,
                                        pcm.data.Length,
                                        pcm.sampleRate);
                                }
                                AL.SourceQueueBuffer(sndInst.alSource, unqueued);
                                if (eof && pcm.data.Length == 0)
                                {
                                    OV.EndStream(ref sndInst.strOvStr);
                                    if (sndInst.looped)
                                    {
                                        OV.BeginStreamFromMemory(res.Data.Res.OggVorbisData, out sndInst.strOvStr);
                                    }
                                    else
                                    {
                                        sndInst.strStopReq = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    if (stateTemp == ALSourceState.Stopped && !sndInst.strStopReq)
                    {
                        // If the source stopped unintentionally, restart it. (See above)
                        AL.SourcePlay(sndInst.alSource);
                    }
                }
                Thread.Sleep(8);
            }
        }
Exemple #14
0
		/// <summary>
		/// Enqueues the specified <see cref="SoundInstance"/> in the streaming thread.
		/// </summary>
		/// <param name="instance"></param>
		internal void EnqueueForStreaming(SoundInstance instance)
		{
			lock (this.streamWorkerQueue)
			{
				if (this.streamWorkerQueue.Contains(instance)) return;
				this.streamWorkerQueue.Add(instance);
			}
			this.streamWorkerQueueEvent.Set();
		}