/// <summary>
        ///     Translates a stringID into an index into the global debug strings array.
        /// </summary>
        /// <param name="id">The StringID to translate.</param>
        /// <returns>The index of the string in the global debug strings array.</returns>
        public int StringIDToIndex(StringID id)
        {
            // Find the index of the first set which is less than the set in the ID
            int closestSetIndex = ListSearching.BinarySearch(_setsByID.Keys, id.GetSet(IDLayout));

            if (closestSetIndex < 0)
            {
                // BinarySearch returns the bitwise complement of the index of the next highest value if not found
                // So, use the set that comes before it...
                closestSetIndex = ~closestSetIndex - 1;
                if (closestSetIndex < 0)
                {
                    return((int)id.Value);                     // No previous set defined - just return the handle
                }
            }

            // If the index falls outside the set's min value, then put it into the previous set
            if (id.GetIndex(IDLayout) < _setsByID.Values[closestSetIndex].MinIndex)
            {
                closestSetIndex--;
                if (closestSetIndex < 0)
                {
                    return((int)id.Value);
                }
            }

            // Calculate the array index by subtracting the value of the first ID in the set
            // and then adding the index in the global array of the set's first string
            StringIDSet set     = _setsByID.Values[closestSetIndex];
            var         firstId = new StringID(set.ID, set.MinIndex, IDLayout);

            return((int)(id.Value - firstId.Value + set.GlobalIndex));
        }
Пример #2
0
		/// <summary>
		///     Translates a stringID into an index into the global debug strings array.
		/// </summary>
		/// <param name="id">The StringID to translate.</param>
		/// <returns>The index of the string in the global debug strings array.</returns>
		public int StringIDToIndex(StringID id)
		{
			// Find the index of the first set which is less than the set in the ID
			int closestSetIndex = ListSearching.BinarySearch(_setsByID.Keys, id.GetSet(IDLayout));
			if (closestSetIndex < 0)
			{
				// BinarySearch returns the bitwise complement of the index of the next highest value if not found
				// So, use the set that comes before it...
				closestSetIndex = ~closestSetIndex - 1;
				if (closestSetIndex < 0)
					return (int) id.Value; // No previous set defined - just return the handle
			}

			// If the index falls outside the set's min value, then put it into the previous set
			if (id.GetIndex(IDLayout) < _setsByID.Values[closestSetIndex].MinIndex)
			{
				closestSetIndex--;
				if (closestSetIndex < 0)
					return (int) id.Value;
			}

			// Calculate the array index by subtracting the value of the first ID in the set
			// and then adding the index in the global array of the set's first string
			StringIDSet set = _setsByID.Values[closestSetIndex];
			var firstId = new StringID(set.ID, set.MinIndex, IDLayout);
			return (int) (id.Value - firstId.Value + set.GlobalIndex);
		}
 /// <summary>
 /// Translates a stringID into an index into the global debug strings array.
 /// </summary>
 /// <param name="id">The StringID to translate.</param>
 /// <returns>The index of the string in the global debug strings array.</returns>
 public int StringIDToIndex(StringID id)
 {
     return (int)id.GetIndex(IDLayout);
 }
 /// <summary>
 ///     Translates a stringID into an index into the global debug strings array.
 /// </summary>
 /// <param name="id">The StringID to translate.</param>
 /// <returns>The index of the string in the global debug strings array.</returns>
 public int StringIDToIndex(StringID id)
 {
     return(id.GetIndex(IDLayout));
 }