// ---- METHODS ------------------------------------------------------------------------------------------------ void IResData.Load(ResFileLoader loader) { Name = loader.LoadString(); BufferIndex = loader.ReadByte(); loader.Seek(1); Offset = loader.ReadUInt16(); Format = loader.ReadEnum <GX2AttribFormat>(true); }
/// <summary> /// Writes <see cref="Vector4U"/> instances into the current stream with the given /// <paramref name="attribFormat"/>. /// </summary> /// <param name="self">The extended <see cref="BinaryDataWriter"/>.</param> /// <param name="values">The <see cref="Vector4U"/> instances.</param> /// <param name="attribFormat">The <see cref="GX2AttribFormat"/> of the data.</param> public static void Write(this BinaryDataWriter self, IEnumerable <Vector4F> values, GX2AttribFormat attribFormat) { Action <BinaryDataWriter, Vector4F> callback = self.GetGX2AttribCallback(attribFormat); foreach (Vector4F value in values) { callback.Invoke(self, value); } }
/// <summary> /// Reads a <see cref="Vector4F"/> instances converted from the given <paramref name="attribFormat"/> and /// returns them. /// </summary> /// <param name="self">The extended <see cref="BinaryDataReader"/>.</param> /// <param name="count">The number of instances to read.</param> /// <param name="attribFormat">The <see cref="GX2AttribFormat"/> of the data.</param> /// <returns>The <see cref="Vector4F"/> instances.</returns> public static IList <Vector4F> ReadGX2Attribs(this BinaryDataReader self, int count, GX2AttribFormat attribFormat) { Func <BinaryDataReader, Vector4F> callback = self.GetGX2AttribCallback(attribFormat); Vector4F[] values = new Vector4F[count]; for (int i = 0; i < count; i++) { values[i] = callback.Invoke(self); } return(values); }
// ---- METHODS ------------------------------------------------------------------------------------------------ void IResData.Load(ResFileLoader loader) { if (loader.IsSwitch) { Name = loader.LoadString(); loader.ByteOrder = ByteOrder.BigEndian; Format = ConvertToGX2(loader.ReadEnum <SwitchAttribFormat>(true)); loader.ByteOrder = ByteOrder.LittleEndian; loader.Seek(2); //padding Offset = loader.ReadUInt16(); BufferIndex = (byte)loader.ReadUInt16(); } else { Name = loader.LoadString(); BufferIndex = loader.ReadByte(); loader.Seek(1); Offset = loader.ReadUInt16(); Format = loader.ReadEnum <GX2AttribFormat>(true); } }
/// <summary> /// Reads a <see cref="Vector4F"/> instance converted from the given <paramref name="attribFormat"/> and /// returns it. /// </summary> /// <param name="self">The extended <see cref="BinaryDataReader"/>.</param> /// <param name="attribFormat">The <see cref="GX2AttribFormat"/> of the data.</param> /// <returns>The <see cref="Vector4F"/> instance.</returns> public static Vector4F ReadGX2Attrib(this BinaryDataReader self, GX2AttribFormat attribFormat) { return(self.GetGX2AttribCallback(attribFormat).Invoke(self)); }
/// <summary> /// Returns the conversion delegate for converting data available in the given <paramref name="attribFormat"/> /// into a <see cref="Vector4F"/> instance. Useful to prevent repetitive lookup for multiple values. /// </summary> /// <param name="self">The extended <see cref="BinaryDataReader"/>.</param> /// <param name="attribFormat">The <see cref="GX2AttribFormat"/> of the data.</param> /// <returns>A conversion delegate for the data.</returns> public static Func <BinaryDataReader, Vector4F> GetGX2AttribCallback(this BinaryDataReader self, GX2AttribFormat attribFormat) { switch (attribFormat) { // 8-bit (8 x 1) case GX2AttribFormat.Format_8_UNorm: return(Read_8_UNorm); case GX2AttribFormat.Format_8_UInt: return(Read_8_UInt); case GX2AttribFormat.Format_8_SNorm: return(Read_8_SNorm); case GX2AttribFormat.Format_8_SInt: return(Read_8_SInt); case GX2AttribFormat.Format_8_UIntToSingle: return(Read_8_UIntToSingle); case GX2AttribFormat.Format_8_SIntToSingle: return(Read_8_SIntToSingle); // 8-bit (4 x 2) case GX2AttribFormat.Format_4_4_UNorm: return(Read_4_4_UNorm); // 16-bit (16 x 1) case GX2AttribFormat.Format_16_UNorm: return(Read_16_UNorm); case GX2AttribFormat.Format_16_UInt: return(Read_16_UInt); case GX2AttribFormat.Format_16_SNorm: return(Read_16_SNorm); case GX2AttribFormat.Format_16_SInt: return(Read_16_SInt); case GX2AttribFormat.Format_16_Single: return(Read_16_Single); case GX2AttribFormat.Format_16_UIntToSingle: return(Read_16_UIntToSingle); case GX2AttribFormat.Format_16_SIntToSingle: return(Read_16_SIntToSingle); // 16-bit (8 x 2) case GX2AttribFormat.Format_8_8_UNorm: return(Read_8_8_UNorm); case GX2AttribFormat.Format_8_8_UInt: return(Read_8_8_UInt); case GX2AttribFormat.Format_8_8_SNorm: return(Read_8_8_SNorm); case GX2AttribFormat.Format_8_8_SInt: return(Read_8_8_SInt); case GX2AttribFormat.Format_8_8_UIntToSingle: return(Read_8_8_UIntToSingle); case GX2AttribFormat.Format_8_8_SIntToSingle: return(Read_8_8_SIntToSingle); // 32-bit (32 x 1) case GX2AttribFormat.Format_32_UInt: return(Read_32_UInt); case GX2AttribFormat.Format_32_SInt: return(Read_32_SInt); case GX2AttribFormat.Format_32_Single: return(Read_32_Single); // 32-bit (16 x 2) case GX2AttribFormat.Format_16_16_UNorm: return(Read_16_16_UNorm); case GX2AttribFormat.Format_16_16_UInt: return(Read_16_16_UInt); case GX2AttribFormat.Format_16_16_SNorm: return(Read_16_16_SNorm); case GX2AttribFormat.Format_16_16_SInt: return(Read_16_16_SInt); case GX2AttribFormat.Format_16_16_Single: return(Read_16_16_Single); case GX2AttribFormat.Format_16_16_UIntToSingle: return(Read_16_16_UIntToSingle); case GX2AttribFormat.Format_16_16_SIntToSingle: return(Read_16_16_SIntToSingle); // 32-bit (10/11 x 3) case GX2AttribFormat.Format_10_11_11_Single: return(Read_10_11_11_Single); // 32-bit (8 x 4) case GX2AttribFormat.Format_8_8_8_8_UNorm: return(Read_8_8_8_8_UNorm); case GX2AttribFormat.Format_8_8_8_8_UInt: return(Read_8_8_8_8_UInt); case GX2AttribFormat.Format_8_8_8_8_SNorm: return(Read_8_8_8_8_SNorm); case GX2AttribFormat.Format_8_8_8_8_SInt: return(Read_8_8_8_8_SInt); case GX2AttribFormat.Format_8_8_8_8_UIntToSingle: return(Read_8_8_8_8_UIntToSingle); case GX2AttribFormat.Format_8_8_8_8_SIntToSingle: return(Read_8_8_8_8_SIntToSingle); // 32-bit (10 x 3 + 2) case GX2AttribFormat.Format_10_10_10_2_UNorm: return(Read_10_10_10_2_UNorm); case GX2AttribFormat.Format_10_10_10_2_UInt: return(Read_10_10_10_2_UInt); case GX2AttribFormat.Format_10_10_10_2_SNorm: return(Read_10_10_10_2_SNorm); case GX2AttribFormat.Format_10_10_10_2_SInt: return(Read_10_10_10_2_SInt); // 64-bit (32 x 2) case GX2AttribFormat.Format_32_32_UInt: return(Read_32_32_UInt); case GX2AttribFormat.Format_32_32_SInt: return(Read_32_32_SInt); case GX2AttribFormat.Format_32_32_Single: return(Read_32_32_Single); // 64-bit (16 x 4) case GX2AttribFormat.Format_16_16_16_16_UNorm: return(Read_16_16_16_16_UNorm); case GX2AttribFormat.Format_16_16_16_16_UInt: return(Read_16_16_16_16_UInt); case GX2AttribFormat.Format_16_16_16_16_SNorm: return(Read_16_16_16_16_SNorm); case GX2AttribFormat.Format_16_16_16_16_SInt: return(Read_16_16_16_16_SInt); case GX2AttribFormat.Format_16_16_16_16_Single: return(Read_16_16_16_16_Single); case GX2AttribFormat.Format_16_16_16_16_UIntToSingle: return(Read_16_16_16_16_UIntToSingle); case GX2AttribFormat.Format_16_16_16_16_SIntToSingle: return(Read_16_16_16_16_SIntToSingle); // 96-bit (32 x 3) case GX2AttribFormat.Format_32_32_32_UInt: return(Read_32_32_32_UInt); case GX2AttribFormat.Format_32_32_32_SInt: return(Read_32_32_32_SInt); case GX2AttribFormat.Format_32_32_32_Single: return(Read_32_32_32_Single); // 128-bit (32 x 4) case GX2AttribFormat.Format_32_32_32_32_UInt: return(Read_32_32_32_32_UInt); case GX2AttribFormat.Format_32_32_32_32_SInt: return(Read_32_32_32_32_SInt); case GX2AttribFormat.Format_32_32_32_32_Single: return(Read_32_32_32_32_Single); // Invalid default: throw new ArgumentException($"Invalid {nameof(GX2AttribFormat)} {attribFormat}.", nameof(attribFormat)); } }
/// <summary> /// Writes a <see cref="Vector4U"/> instance into the current stream with the given /// <paramref name="attribFormat"/>. /// </summary> /// <param name="self">The extended <see cref="BinaryDataWriter"/>.</param> /// <param name="value">The <see cref="Vector4F"/> instance.</param> /// <param name="attribFormat">The <see cref="GX2AttribFormat"/> of the data.</param> public static void Write(this BinaryDataWriter self, Vector4F value, GX2AttribFormat attribFormat) { self.GetGX2AttribCallback(attribFormat).Invoke(self, value); }
private SwitchAttribFormat ConvertFromGX2(GX2AttribFormat att) { return((SwitchAttribFormat)Enum.Parse(typeof(SwitchAttribFormat), att.ToString())); }