Esempio n. 1
0
        internal bool VerifyInstance(XSound owner)
        {
            if (owner.soundEffectInstance == null)
            {
                return(false);
            }

            if (this.NumberOfInstances > 0)
            {
                if (this.instanceOwners == null || this.instanceOwners[owner.soundEffectInstance] != owner.GetHashCode())
                {
                    owner.soundEffectInstance = null;
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 2
0
        internal bool CheckOutInstance(XSound owner)
        {
            SoundEffectInstance result = null;

            if (this.NumberOfInstances > 0)
            {
                // limited number of instances

                var currCheckoutTime = GameEngine.Instance.CycleNumber;

                int checkedoutThisCycle        = 0;
                int oldestCycle                = int.MaxValue;
                SoundEffectInstance oldestItem = null;
                foreach (var item in this.instanceCheckoutTimes)
                {
                    // if the instance already belongs to the owner - quit
                    if (this.instanceOwners[item.Key] == owner.GetHashCode())
                    {
                        result = item.Key;
                        break;
                    }

                    // find the oldest instance
                    if (oldestCycle > item.Value)
                    {
                        oldestCycle = item.Value;
                        oldestItem  = item.Key;
                    }

                    // count the numbe of instances checked out in this cycle
                    if (item.Value == currCheckoutTime)
                    {
                        checkedoutThisCycle++;
                    }
                }


                if (result == null)
                {
                    // if we exceeded the limit - quit
                    if (this.MaxStartAtOnce > 0 && checkedoutThisCycle >= this.MaxStartAtOnce)
                    {
                        owner.soundEffectInstance = null;
                        return(false);
                    }

                    result = oldestItem;
                    this.instanceOwners[result] = owner.GetHashCode();
                }

                this.instanceCheckoutTimes[result] = currCheckoutTime;

                /*
                 * Console.WriteLine("*** Id:" + this.Id + " Source:" + this.Source + " Result:" + result.GetHashCode() + " ***");
                 * Console.WriteLine("*** chekout times *** ");
                 * foreach(var item in this.instanceCheckoutTimes)
                 * {
                 *      Console.WriteLine(item.Key.GetHashCode().ToString() + " - " + item.Value);
                 * }
                 * Console.WriteLine("*** owners *** ");
                 * foreach(var item in this.instanceOwners)
                 * {
                 *      Console.WriteLine(item.Key.GetHashCode().ToString() + " - " + item.Value);
                 * }
                 * Console.WriteLine("******");
                 */
            }
            else
            {
                if (!this.ownerInstances.TryGetValue(owner.GetHashCode(), out result))
                {
                    result = this.soundEffect.CreateInstance();
                    this.ownerInstances[owner.GetHashCode()] = result;
                }
            }

            owner.soundEffectInstance = result;

            return(true);
        }
Esempio n. 3
0
		internal bool CheckOutInstance(XSound owner)
		{
			SoundEffectInstance result = null;

			if (this.NumberOfInstances > 0)
			{
				// limited number of instances

				var currCheckoutTime = GameEngine.Instance.CycleNumber;

				int checkedoutThisCycle = 0;
				int oldestCycle = int.MaxValue;
				SoundEffectInstance oldestItem = null;
				foreach(var item in this.instanceCheckoutTimes)
				{
					// if the instance already belongs to the owner - quit
					if (this.instanceOwners[item.Key] == owner.GetHashCode())
					{
						result = item.Key;
						break;
					}

					// find the oldest instance
					if (oldestCycle > item.Value)
					{
						oldestCycle = item.Value;
						oldestItem = item.Key;
					}

					// count the numbe of instances checked out in this cycle
					if (item.Value == currCheckoutTime)
						checkedoutThisCycle++;
			    }


				if (result == null)
				{
					// if we exceeded the limit - quit
					if (this.MaxStartAtOnce > 0 && checkedoutThisCycle >= this.MaxStartAtOnce)
					{
						owner.soundEffectInstance = null;
						return false;
					}

					result = oldestItem;
					this.instanceOwners[result] = owner.GetHashCode();
				}

				this.instanceCheckoutTimes[result] = currCheckoutTime;

				/*
				Console.WriteLine("*** Id:" + this.Id + " Source:" + this.Source + " Result:" + result.GetHashCode() + " ***");
				Console.WriteLine("*** chekout times *** ");
				foreach(var item in this.instanceCheckoutTimes)
				{
					Console.WriteLine(item.Key.GetHashCode().ToString() + " - " + item.Value);
				}
				Console.WriteLine("*** owners *** ");
				foreach(var item in this.instanceOwners)
				{
					Console.WriteLine(item.Key.GetHashCode().ToString() + " - " + item.Value);
				}
				Console.WriteLine("******");
				*/
			}
			else
			{

				if (!this.ownerInstances.TryGetValue(owner.GetHashCode(), out result))
				{
					result = this.soundEffect.CreateInstance();
					this.ownerInstances[owner.GetHashCode()] = result;
				}
			}

			owner.soundEffectInstance = result;

			return true;
		}
Esempio n. 4
0
		internal bool VerifyInstance(XSound owner)
		{
			if (owner.soundEffectInstance == null)
				return false;

			if (this.NumberOfInstances > 0)
			{
				if (this.instanceOwners == null || this.instanceOwners[owner.soundEffectInstance] != owner.GetHashCode())
				{
					owner.soundEffectInstance = null;
					return false;
				}
			}

			return true;
		}