protected internal override T[] Read(ContentReader input, T[] existingInstance) { uint count = input.ReadUInt32(); T[] array = existingInstance; if (array == null) { array = new T[count]; } if (ReflectionHelpers.IsValueType(typeof(T))) { for (uint i = 0; i < count; i++) { array[i] = input.ReadObject <T>(elementReader); } } else { for (uint i = 0; i < count; i++) { var readerType = input.Read7BitEncodedInt(); array[i] = readerType > 0 ? input.ReadObject <T>(input.TypeReaders[readerType - 1]) : default(T); } } return(array); }
protected internal override List <T> Read( ContentReader input, List <T> existingInstance ) { int count = input.ReadInt32(); List <T> list = existingInstance; if (list == null) { list = new List <T>(count); } for (int i = 0; i < count; i += 1) { Type objectType = typeof(T); if (objectType.IsValueType) { list.Add(input.ReadObject <T>(elementReader)); } else { int readerType = input.Read7BitEncodedInt(); list.Add((readerType > 0) ? input.ReadObject <T>(input.TypeReaders[readerType - 1]) : default(T)); } } return(list); }
protected internal override T[] Read(ContentReader input, T[] existingInstance) { uint count = input.ReadUInt32(); T[] array = existingInstance; if (array == null) { array = new T[count]; } #if WINRT if (typeof(T).GetTypeInfo().IsValueType) #else if (typeof(T).IsValueType) #endif { for (uint i = 0; i < count; i++) { array[i] = input.ReadObject <T>(elementReader); } } else { for (uint i = 0; i < count; i++) { int readerType = input.Read7BitEncodedInt(); array[i] = readerType > 0 ? input.ReadObject <T>(input.TypeReaders[readerType - 1]) : default(T); } } return(array); }
protected internal override Array Read(ContentReader input, Array existingInstance) { var rank = input.ReadInt32(); if (rank < 1) { throw new RankException(); } var dimensions = new int[rank]; var count = 1; for (int d = 0; d < dimensions.Length; d++) { count *= dimensions[d] = input.ReadInt32(); } var array = existingInstance; if (array == null) { array = Array.CreateInstance(typeof(T), dimensions);//new T[count]; } else if (dimensions.Length != array.Rank) { throw new RankException("existingInstance"); } var indices = new int[rank]; for (int i = 0; i < count; i++) { T value; if (ReflectionHelpers.IsValueType(typeof(T))) { value = input.ReadObject <T>(elementReader); } else { var readerType = input.Read7BitEncodedInt(); if (readerType > 0) { value = input.ReadObject <T>(input.TypeReaders[readerType - 1]); } else { value = default(T); } } CalcIndices(array, i, indices); array.SetValue(value, indices); } return(array); }
protected internal override Dictionary <TKey, TValue> Read(ContentReader input, Dictionary <TKey, TValue> existingInstance) { int count = input.ReadInt32(); Dictionary <TKey, TValue> dictionary = existingInstance; if (dictionary == null) { dictionary = new Dictionary <TKey, TValue>(count); } else { dictionary.Clear(); } for (int i = 0; i < count; i++) { TKey key; TValue value; if (ReflectionHelpers.IsValueType(keyType)) { key = input.ReadObject <TKey>(keyReader); } else { var readerType = input.Read7BitEncodedInt(); key = readerType > 0 ? input.ReadObject <TKey>(input.TypeReaders[readerType - 1]) : default(TKey); } if (ReflectionHelpers.IsValueType(valueType)) { value = input.ReadObject <TValue>(valueReader); } else { var readerType = input.Read7BitEncodedInt(); value = readerType > 0 ? input.ReadObject <TValue>(input.TypeReaders[readerType - 1]) : default(TValue); } dictionary.Add(key, value); } return(dictionary); }
internal ContentTypeReader[] LoadAssetReaders(ContentReader reader) { /* The first content byte i read tells me the number of * content readers in this XNB file. */ int numberOfReaders = reader.Read7BitEncodedInt(); ContentTypeReader[] newReaders = new ContentTypeReader[numberOfReaders]; BitArray needsInitialize = new BitArray(numberOfReaders); /* Lock until we're done allocating and initializing any new * content type readers... this ensures we can load content * from multiple threads and still cache the readers. */ lock (locker) { /* For each reader in the file, we read out the * length of the string which contains the type * of the reader, then we read out the string. * Finally we instantiate an instance of that * reader using reflection. */ for (int i = 0; i < numberOfReaders; i += 1) { /* This string tells us what reader we * need to decode the following data. */ string originalReaderTypeString = reader.ReadString(); bool needsInit = false; ContentTypeReader typeReader = GetReaderByTypeName(originalReaderTypeString, out needsInit); newReaders[i] = typeReader; needsInitialize[i] = needsInit; /* I think the next 4 bytes refer to the "Version" of the type reader, * although it always seems to be zero. */ reader.ReadInt32(); } // Initialize any new readers. for (int i = 0; i < newReaders.Length; i += 1) { if (needsInitialize.Get(i)) { newReaders[i].Initialize(this); } } } // lock (locker) return(newReaders); }
protected internal override T[] Read(ContentReader input, T[] existingInstance) { uint num1 = input.ReadUInt32(); T[] objArray = existingInstance ?? new T[(IntPtr)num1]; if (typeof(T).IsValueType) { for (uint index = 0U; index < num1; ++index) { objArray[(IntPtr)index] = input.ReadObject <T>(this.elementReader); } } else { for (uint index = 0U; index < num1; ++index) { int num2 = input.Read7BitEncodedInt(); objArray[(IntPtr)index] = num2 > 0 ? input.ReadObject <T>(input.TypeReaders[num2 - 1]) : default(T); } } return(objArray); }
protected internal override List <T> Read(ContentReader input, List <T> existingInstance) { int count = input.ReadInt32(); List <T> list = existingInstance; if (list == null) { list = new List <T>(count); } for (int i = 0; i < count; i++) { if (ReflectionHelpers.IsValueType(typeof(T))) { list.Add(input.ReadObject <T>(elementReader)); } else { var readerType = input.Read7BitEncodedInt(); list.Add(readerType > 0 ? input.ReadObject <T>(input.TypeReaders[readerType - 1]) : default(T)); } } return(list); }
protected internal override T[] Read(ContentReader input, T[] existingInstance) { uint count = input.ReadUInt32(); T[] array = existingInstance; if (array == null) { array = new T[count]; } if (typeof(T).IsValueType) { for (uint i = 0; i < count; i += 1) { array[i] = input.ReadObject <T>(elementReader); } } else { for (uint i = 0; i < count; i += 1) { int readerType = input.Read7BitEncodedInt(); if (readerType > 0) { array[i] = input.ReadObject <T>( input.TypeReaders[readerType - 1] ); } else { array[i] = default(T); } } } return(array); }
internal ContentTypeReader[] LoadAssetReaders(ContentReader reader) { #pragma warning disable 0219, 0649 // Trick to prevent the linker removing the code, but not actually execute the code if (falseflag) { // Dummy variables required for it to work on iDevices ** DO NOT DELETE ** // This forces the classes not to be optimized out when deploying to iDevices var hByteReader = new ByteReader(); var hSByteReader = new SByteReader(); var hDateTimeReader = new DateTimeReader(); var hDecimalReader = new DecimalReader(); var hBoundingSphereReader = new BoundingSphereReader(); var hBoundingFrustumReader = new BoundingFrustumReader(); var hRayReader = new RayReader(); var hCharListReader = new ListReader <Char>(); var hRectangleListReader = new ListReader <Rectangle>(); var hRectangleArrayReader = new ArrayReader <Rectangle>(); var hVector3ListReader = new ListReader <Vector3>(); var hStringListReader = new ListReader <StringReader>(); var hIntListReader = new ListReader <Int32>(); var hSpriteFontReader = new SpriteFontReader(); var hTexture2DReader = new Texture2DReader(); var hCharReader = new CharReader(); var hRectangleReader = new RectangleReader(); var hStringReader = new StringReader(); var hVector2Reader = new Vector2Reader(); var hVector3Reader = new Vector3Reader(); var hVector4Reader = new Vector4Reader(); var hCurveReader = new CurveReader(); var hIndexBufferReader = new IndexBufferReader(); var hBoundingBoxReader = new BoundingBoxReader(); var hMatrixReader = new MatrixReader(); var hBasicEffectReader = new BasicEffectReader(); var hVertexBufferReader = new VertexBufferReader(); var hAlphaTestEffectReader = new AlphaTestEffectReader(); var hEnumSpriteEffectsReader = new EnumReader <Graphics.SpriteEffects>(); var hArrayFloatReader = new ArrayReader <float>(); var hArrayVector2Reader = new ArrayReader <Vector2>(); var hListVector2Reader = new ListReader <Vector2>(); var hArrayMatrixReader = new ArrayReader <Matrix>(); var hEnumBlendReader = new EnumReader <Graphics.Blend>(); var hNullableRectReader = new NullableReader <Rectangle>(); var hEffectMaterialReader = new EffectMaterialReader(); var hExternalReferenceReader = new ExternalReferenceReader(); var hSoundEffectReader = new SoundEffectReader(); var hSongReader = new SongReader(); var hModelReader = new ModelReader(); var hInt32Reader = new Int32Reader(); var hEffectReader = new EffectReader(); var hSingleReader = new SingleReader(); // At the moment the Video class doesn't exist // on all platforms... Allow it to compile anyway. #if ANDROID || (IOS && !TVOS) || MONOMAC || (WINDOWS && !OPENGL) || WINDOWS_UAP var hVideoReader = new VideoReader(); #endif } #pragma warning restore 0219, 0649 // The first content byte i read tells me the number of content readers in this XNB file var numberOfReaders = reader.Read7BitEncodedInt(); var contentReaders = new ContentTypeReader[numberOfReaders]; var needsInitialize = new BitArray(numberOfReaders); _contentReaders = new Dictionary <Type, ContentTypeReader>(numberOfReaders); // Lock until we're done allocating and initializing any new // content type readers... this ensures we can load content // from multiple threads and still cache the readers. lock (_locker) { // For each reader in the file, we read out the length of the string which contains the type of the reader, // then we read out the string. Finally we instantiate an instance of that reader using reflection for (var i = 0; i < numberOfReaders; i++) { // This string tells us what reader we need to decode the following data // string readerTypeString = reader.ReadString(); string originalReaderTypeString = reader.ReadString(); Func <ContentTypeReader> readerFunc; if (typeCreators.TryGetValue(originalReaderTypeString, out readerFunc)) { contentReaders[i] = readerFunc(); needsInitialize[i] = true; } else { //System.Diagnostics.Debug.WriteLine(originalReaderTypeString); // Need to resolve namespace differences string readerTypeString = originalReaderTypeString; readerTypeString = PrepareType(readerTypeString); var l_readerType = Type.GetType(readerTypeString); if (l_readerType != null) { ContentTypeReader typeReader; if (!_contentReadersCache.TryGetValue(l_readerType, out typeReader)) { try { typeReader = l_readerType.GetDefaultConstructor().Invoke(null) as ContentTypeReader; } catch (TargetInvocationException ex) { // If you are getting here, the Mono runtime is most likely not able to JIT the type. // In particular, MonoTouch needs help instantiating types that are only defined in strings in Xnb files. throw new InvalidOperationException( "Failed to get default constructor for ContentTypeReader. To work around, add a creation function to ContentTypeReaderManager.AddTypeCreator() " + "with the following failed type string: " + originalReaderTypeString, ex); } needsInitialize[i] = true; _contentReadersCache.Add(l_readerType, typeReader); } contentReaders[i] = typeReader; } else { throw new ContentLoadException( "Could not find ContentTypeReader Type. Please ensure the name of the Assembly that contains the Type matches the assembly in the full type name: " + originalReaderTypeString + " (" + readerTypeString + ")"); } } var targetType = contentReaders[i].TargetType; if (targetType != null) { if (!_contentReaders.ContainsKey(targetType)) { _contentReaders.Add(targetType, contentReaders[i]); } } // I think the next 4 bytes refer to the "Version" of the type reader, // although it always seems to be zero reader.ReadInt32(); } // Initialize any new readers. for (var i = 0; i < contentReaders.Length; i++) { if (needsInitialize.Get(i)) { contentReaders[i].Initialize(this); } } } // lock (_locker) return(contentReaders); }
internal ContentTypeReader[] LoadAssetReaders(ContentReader reader) { #pragma warning disable 0219, 0649 /* Trick to prevent the linker removing the code, but not actually execute the code * FIXME: Do we really need this in FNA? */ if (falseflag) { /* Dummy variables required for it to work on iDevices ** DO NOT DELETE ** * This forces the classes not to be optimized out when deploying to iDevices */ ByteReader hByteReader = new ByteReader(); SByteReader hSByteReader = new SByteReader(); DateTimeReader hDateTimeReader = new DateTimeReader(); DecimalReader hDecimalReader = new DecimalReader(); BoundingSphereReader hBoundingSphereReader = new BoundingSphereReader(); BoundingFrustumReader hBoundingFrustumReader = new BoundingFrustumReader(); RayReader hRayReader = new RayReader(); ListReader <char> hCharListReader = new ListReader <Char>(); ListReader <Rectangle> hRectangleListReader = new ListReader <Rectangle>(); ArrayReader <Rectangle> hRectangleArrayReader = new ArrayReader <Rectangle>(); ListReader <Vector3> hVector3ListReader = new ListReader <Vector3>(); ListReader <StringReader> hStringListReader = new ListReader <StringReader>(); ListReader <int> hIntListReader = new ListReader <Int32>(); SpriteFontReader hSpriteFontReader = new SpriteFontReader(); Texture2DReader hTexture2DReader = new Texture2DReader(); CharReader hCharReader = new CharReader(); RectangleReader hRectangleReader = new RectangleReader(); StringReader hStringReader = new StringReader(); Vector2Reader hVector2Reader = new Vector2Reader(); Vector3Reader hVector3Reader = new Vector3Reader(); Vector4Reader hVector4Reader = new Vector4Reader(); CurveReader hCurveReader = new CurveReader(); IndexBufferReader hIndexBufferReader = new IndexBufferReader(); BoundingBoxReader hBoundingBoxReader = new BoundingBoxReader(); MatrixReader hMatrixReader = new MatrixReader(); BasicEffectReader hBasicEffectReader = new BasicEffectReader(); VertexBufferReader hVertexBufferReader = new VertexBufferReader(); AlphaTestEffectReader hAlphaTestEffectReader = new AlphaTestEffectReader(); EnumReader <Microsoft.Xna.Framework.Graphics.SpriteEffects> hEnumSpriteEffectsReader = new EnumReader <Graphics.SpriteEffects>(); ArrayReader <float> hArrayFloatReader = new ArrayReader <float>(); ArrayReader <Vector2> hArrayVector2Reader = new ArrayReader <Vector2>(); ListReader <Vector2> hListVector2Reader = new ListReader <Vector2>(); ArrayReader <Matrix> hArrayMatrixReader = new ArrayReader <Matrix>(); EnumReader <Microsoft.Xna.Framework.Graphics.Blend> hEnumBlendReader = new EnumReader <Graphics.Blend>(); NullableReader <Rectangle> hNullableRectReader = new NullableReader <Rectangle>(); EffectMaterialReader hEffectMaterialReader = new EffectMaterialReader(); ExternalReferenceReader hExternalReferenceReader = new ExternalReferenceReader(); SoundEffectReader hSoundEffectReader = new SoundEffectReader(); SongReader hSongReader = new SongReader(); ModelReader hModelReader = new ModelReader(); Int32Reader hInt32Reader = new Int32Reader(); } #pragma warning restore 0219, 0649 /* The first content byte i read tells me the number of * content readers in this XNB file. */ int numberOfReaders = reader.Read7BitEncodedInt(); ContentTypeReader[] newReaders = new ContentTypeReader[numberOfReaders]; BitArray needsInitialize = new BitArray(numberOfReaders); contentReaders = new Dictionary <Type, ContentTypeReader>(numberOfReaders); /* Lock until we're done allocating and initializing any new * content type readers... this ensures we can load content * from multiple threads and still cache the readers. */ lock (locker) { /* For each reader in the file, we read out the * length of the string which contains the type * of the reader, then we read out the string. * Finally we instantiate an instance of that * reader using reflection. */ for (int i = 0; i < numberOfReaders; i += 1) { /* This string tells us what reader we * need to decode the following data. */ string originalReaderTypeString = reader.ReadString(); Func <ContentTypeReader> readerFunc; if (typeCreators.TryGetValue(originalReaderTypeString, out readerFunc)) { newReaders[i] = readerFunc(); needsInitialize[i] = true; } else { // Need to resolve namespace differences string readerTypeString = originalReaderTypeString; readerTypeString = PrepareType(readerTypeString); Type l_readerType = Type.GetType(readerTypeString); if (l_readerType != null) { ContentTypeReader typeReader; if (!contentReadersCache.TryGetValue(l_readerType, out typeReader)) { try { typeReader = l_readerType.GetDefaultConstructor().Invoke(null) as ContentTypeReader; } catch (TargetInvocationException ex) { /* If you are getting here, the Mono runtime * is most likely not able to JIT the type. * In particular, MonoTouch needs help * instantiating types that are only defined * in strings in Xnb files. */ throw new InvalidOperationException( "Failed to get default constructor for ContentTypeReader. " + "To work around, add a creation function to ContentTypeReaderManager.AddTypeCreator() " + "with the following failed type string: " + originalReaderTypeString, ex ); } needsInitialize[i] = true; contentReadersCache.Add(l_readerType, typeReader); } newReaders[i] = typeReader; } else { throw new ContentLoadException( "Could not find ContentTypeReader Type. " + "Please ensure the name of the Assembly that " + "contains the Type matches the assembly in the full type name: " + originalReaderTypeString + " (" + readerTypeString + ")" ); } } contentReaders.Add(newReaders[i].TargetType, newReaders[i]); /* I think the next 4 bytes refer to the "Version" of the type reader, * although it always seems to be zero. */ reader.ReadInt32(); } // Initialize any new readers. for (int i = 0; i < newReaders.Length; i += 1) { if (needsInitialize.Get(i)) { newReaders[i].Initialize(this); } } } // lock (locker) return(newReaders); }
internal ContentTypeReader[] LoadAssetReaders(ContentReader reader) { #pragma warning disable 0219, 0649 /* Trick to prevent the linker removing the code, but not actually execute the code * FIXME: Do we really need this in FNA? */ if (falseflag) { /* Dummy variables required for it to work on iDevices ** DO NOT DELETE ** * This forces the classes not to be optimized out when deploying to iDevices */ ByteReader hByteReader = new ByteReader(); SByteReader hSByteReader = new SByteReader(); DateTimeReader hDateTimeReader = new DateTimeReader(); DecimalReader hDecimalReader = new DecimalReader(); BoundingSphereReader hBoundingSphereReader = new BoundingSphereReader(); BoundingFrustumReader hBoundingFrustumReader = new BoundingFrustumReader(); RayReader hRayReader = new RayReader(); ListReader<char> hCharListReader = new ListReader<Char>(); ListReader<Rectangle> hRectangleListReader = new ListReader<Rectangle>(); ArrayReader<Rectangle> hRectangleArrayReader = new ArrayReader<Rectangle>(); ListReader<Vector3> hVector3ListReader = new ListReader<Vector3>(); ListReader<StringReader> hStringListReader = new ListReader<StringReader>(); ListReader<int> hIntListReader = new ListReader<Int32>(); SpriteFontReader hSpriteFontReader = new SpriteFontReader(); Texture2DReader hTexture2DReader = new Texture2DReader(); CharReader hCharReader = new CharReader(); RectangleReader hRectangleReader = new RectangleReader(); StringReader hStringReader = new StringReader(); Vector2Reader hVector2Reader = new Vector2Reader(); Vector3Reader hVector3Reader = new Vector3Reader(); Vector4Reader hVector4Reader = new Vector4Reader(); CurveReader hCurveReader = new CurveReader(); IndexBufferReader hIndexBufferReader = new IndexBufferReader(); BoundingBoxReader hBoundingBoxReader = new BoundingBoxReader(); MatrixReader hMatrixReader = new MatrixReader(); BasicEffectReader hBasicEffectReader = new BasicEffectReader(); VertexBufferReader hVertexBufferReader = new VertexBufferReader(); AlphaTestEffectReader hAlphaTestEffectReader = new AlphaTestEffectReader(); EnumReader<Microsoft.Xna.Framework.Graphics.SpriteEffects> hEnumSpriteEffectsReader = new EnumReader<Graphics.SpriteEffects>(); ArrayReader<float> hArrayFloatReader = new ArrayReader<float>(); ArrayReader<Vector2> hArrayVector2Reader = new ArrayReader<Vector2>(); ListReader<Vector2> hListVector2Reader = new ListReader<Vector2>(); ArrayReader<Matrix> hArrayMatrixReader = new ArrayReader<Matrix>(); EnumReader<Microsoft.Xna.Framework.Graphics.Blend> hEnumBlendReader = new EnumReader<Graphics.Blend>(); NullableReader<Rectangle> hNullableRectReader = new NullableReader<Rectangle>(); EffectMaterialReader hEffectMaterialReader = new EffectMaterialReader(); ExternalReferenceReader hExternalReferenceReader = new ExternalReferenceReader(); SoundEffectReader hSoundEffectReader = new SoundEffectReader(); SongReader hSongReader = new SongReader(); } #pragma warning restore 0219, 0649 /* The first content byte i read tells me the number of * content readers in this XNB file. */ int numberOfReaders = reader.Read7BitEncodedInt(); ContentTypeReader[] newReaders = new ContentTypeReader[numberOfReaders]; BitArray needsInitialize = new BitArray(numberOfReaders); contentReaders = new Dictionary<Type, ContentTypeReader>(numberOfReaders); /* Lock until we're done allocating and initializing any new * content type readers... this ensures we can load content * from multiple threads and still cache the readers. */ lock (locker) { /* For each reader in the file, we read out the * length of the string which contains the type * of the reader, then we read out the string. * Finally we instantiate an instance of that * reader using reflection. */ for (int i = 0; i < numberOfReaders; i += 1) { /* This string tells us what reader we * need to decode the following data. */ string originalReaderTypeString = reader.ReadString(); Func<ContentTypeReader> readerFunc; if (typeCreators.TryGetValue(originalReaderTypeString, out readerFunc)) { newReaders[i] = readerFunc(); needsInitialize[i] = true; } else { // Need to resolve namespace differences string readerTypeString = originalReaderTypeString; readerTypeString = PrepareType(readerTypeString); Type l_readerType = Type.GetType(readerTypeString); if (l_readerType != null) { ContentTypeReader typeReader; if (!contentReadersCache.TryGetValue(l_readerType, out typeReader)) { try { typeReader = l_readerType.GetDefaultConstructor().Invoke(null) as ContentTypeReader; } catch (TargetInvocationException ex) { /* If you are getting here, the Mono runtime * is most likely not able to JIT the type. * In particular, MonoTouch needs help * instantiating types that are only defined * in strings in Xnb files. */ throw new InvalidOperationException( "Failed to get default constructor for ContentTypeReader. " + "To work around, add a creation function to ContentTypeReaderManager.AddTypeCreator() " + "with the following failed type string: " + originalReaderTypeString, ex ); } needsInitialize[i] = true; contentReadersCache.Add(l_readerType, typeReader); } newReaders[i] = typeReader; } else { throw new ContentLoadException( "Could not find ContentTypeReader Type. " + "Please ensure the name of the Assembly that " + "contains the Type matches the assembly in the full type name: " + originalReaderTypeString + " (" + readerTypeString + ")" ); } } contentReaders.Add(newReaders[i].TargetType, newReaders[i]); /* I think the next 4 bytes refer to the "Version" of the type reader, * although it always seems to be zero. */ reader.ReadInt32(); } // Initialize any new readers. for (int i = 0; i < newReaders.Length; i += 1) { if (needsInitialize.Get(i)) { newReaders[i].Initialize(this); } } } // lock (locker) return newReaders; }
internal ContentTypeReader[] LoadAssetReaders() { #pragma warning disable 0219, 0649 // Trick to prevent the linker removing the code, but not actually execute the code if (falseflag) { // Dummy variables required for it to work on iDevices ** DO NOT DELETE ** // This forces the classes not to be optimized out when deploying to iDevices var hByteReader = new ByteReader(); var hSByteReader = new SByteReader(); var hDateTimeReader = new DateTimeReader(); var hDecimalReader = new DecimalReader(); var hBoundingSphereReader = new BoundingSphereReader(); var hBoundingFrustumReader = new BoundingFrustumReader(); var hRayReader = new RayReader(); var hCharListReader = new ListReader <Char>(); var hRectangleListReader = new ListReader <Rectangle>(); var hRectangleArrayReader = new ArrayReader <Rectangle>(); var hVector3ListReader = new ListReader <Vector3>(); var hStringListReader = new ListReader <StringReader>(); var hIntListReader = new ListReader <Int32>(); var hSpriteFontReader = new SpriteFontReader(); var hTexture2DReader = new Texture2DReader(); var hCharReader = new CharReader(); var hRectangleReader = new RectangleReader(); var hStringReader = new StringReader(); var hVector2Reader = new Vector2Reader(); var hVector3Reader = new Vector3Reader(); var hVector4Reader = new Vector4Reader(); var hCurveReader = new CurveReader(); var hIndexBufferReader = new IndexBufferReader(); var hBoundingBoxReader = new BoundingBoxReader(); var hMatrixReader = new MatrixReader(); var hBasicEffectReader = new BasicEffectReader(); var hVertexBufferReader = new VertexBufferReader(); var hAlphaTestEffectReader = new AlphaTestEffectReader(); var hEnumSpriteEffectsReader = new EnumReader <Graphics.SpriteEffects>(); var hArrayFloatReader = new ArrayReader <float>(); var hArrayVector2Reader = new ArrayReader <Vector2>(); var hListVector2Reader = new ListReader <Vector2>(); var hArrayMatrixReader = new ArrayReader <Matrix>(); var hEnumBlendReader = new EnumReader <Graphics.Blend>(); var hNullableRectReader = new NullableReader <Rectangle>(); var hEffectMaterialReader = new EffectMaterialReader(); var hExternalReferenceReader = new ExternalReferenceReader(); var hSoundEffectReader = new SoundEffectReader(); var hSongReader = new SongReader(); } #pragma warning restore 0219, 0649 int numberOfReaders; // The first content byte i read tells me the number of content readers in this XNB file numberOfReaders = _reader.Read7BitEncodedInt(); contentReaders = new ContentTypeReader[numberOfReaders]; // For each reader in the file, we read out the length of the string which contains the type of the reader, // then we read out the string. Finally we instantiate an instance of that reader using reflection for (int i = 0; i < numberOfReaders; i++) { // This string tells us what reader we need to decode the following data // string readerTypeString = reader.ReadString(); string originalReaderTypeString = _reader.ReadString(); Func <ContentTypeReader> readerFunc; if (typeCreators.TryGetValue(originalReaderTypeString, out readerFunc)) { contentReaders[i] = readerFunc(); } else { //System.Diagnostics.Debug.WriteLine(originalReaderTypeString); // Need to resolve namespace differences string readerTypeString = originalReaderTypeString; readerTypeString = PrepareType(readerTypeString); var l_readerType = Type.GetType(readerTypeString); if (l_readerType != null) { try { contentReaders[i] = l_readerType.GetDefaultConstructor().Invoke(null) as ContentTypeReader; } catch (TargetInvocationException ex) { // If you are getting here, the Mono runtime is most likely not able to JIT the type. // In particular, MonoTouch needs help instantiating types that are only defined in strings in Xnb files. throw new InvalidOperationException( "Failed to get default constructor for ContentTypeReader. To work around, add a creation function to ContentTypeReaderManager.AddTypeCreator() " + "with the following failed type string: " + originalReaderTypeString); } } else { throw new ContentLoadException( "Could not find ContentTypeReader Type. Please ensure the name of the Assembly that contains the Type matches the assembly in the full type name: " + originalReaderTypeString + " (" + readerTypeString + ")"); } } // I think the next 4 bytes refer to the "Version" of the type reader, // although it always seems to be zero int typeReaderVersion = _reader.ReadInt32(); } return(contentReaders); }
internal ContentTypeReader[] LoadAssetReaders(ContentReader reader) { #pragma warning disable 0219, 0649 // Trick to prevent the linker removing the code, but not actually execute the code if (falseflag) { // Dummy variables required for it to work on iDevices ** DO NOT DELETE ** // This forces the classes not to be optimized out when deploying to iDevices var hByteReader = new ByteReader(); var hSByteReader = new SByteReader(); var hDateTimeReader = new DateTimeReader(); var hDecimalReader = new DecimalReader(); var hBoundingSphereReader = new BoundingSphereReader(); var hBoundingFrustumReader = new BoundingFrustumReader(); var hRayReader = new RayReader(); var hCharListReader = new ListReader<Char>(); var hRectangleListReader = new ListReader<Rectangle>(); var hRectangleArrayReader = new ArrayReader<Rectangle>(); var hVector3ListReader = new ListReader<Vector3>(); var hStringListReader = new ListReader<StringReader>(); var hIntListReader = new ListReader<Int32>(); var hSpriteFontReader = new SpriteFontReader(); var hTexture2DReader = new Texture2DReader(); var hCharReader = new CharReader(); var hRectangleReader = new RectangleReader(); var hStringReader = new StringReader(); var hVector2Reader = new Vector2Reader(); var hVector3Reader = new Vector3Reader(); var hVector4Reader = new Vector4Reader(); var hCurveReader = new CurveReader(); var hIndexBufferReader = new IndexBufferReader(); var hBoundingBoxReader = new BoundingBoxReader(); var hMatrixReader = new MatrixReader(); var hBasicEffectReader = new BasicEffectReader(); var hVertexBufferReader = new VertexBufferReader(); var hAlphaTestEffectReader = new AlphaTestEffectReader(); var hEnumSpriteEffectsReader = new EnumReader<Graphics.SpriteEffects>(); var hArrayFloatReader = new ArrayReader<float>(); var hArrayVector2Reader = new ArrayReader<Vector2>(); var hListVector2Reader = new ListReader<Vector2>(); var hArrayMatrixReader = new ArrayReader<Matrix>(); var hEnumBlendReader = new EnumReader<Graphics.Blend>(); var hNullableRectReader = new NullableReader<Rectangle>(); var hEffectMaterialReader = new EffectMaterialReader(); var hExternalReferenceReader = new ExternalReferenceReader(); var hSoundEffectReader = new SoundEffectReader(); var hSongReader = new SongReader(); var hModelReader = new ModelReader(); var hInt32Reader = new Int32Reader(); // At the moment the Video class doesn't exist // on all platforms... Allow it to compile anyway. #if ANDROID || IOS || MONOMAC || (WINDOWS && !OPENGL) || (WINRT && !WINDOWS_PHONE) var hVideoReader = new VideoReader(); #endif } #pragma warning restore 0219, 0649 // The first content byte i read tells me the number of content readers in this XNB file var numberOfReaders = reader.Read7BitEncodedInt(); var contentReaders = new ContentTypeReader[numberOfReaders]; var needsInitialize = new BitArray(numberOfReaders); _contentReaders = new Dictionary<Type, ContentTypeReader>(numberOfReaders); // Lock until we're done allocating and initializing any new // content type readers... this ensures we can load content // from multiple threads and still cache the readers. lock (_locker) { // For each reader in the file, we read out the length of the string which contains the type of the reader, // then we read out the string. Finally we instantiate an instance of that reader using reflection for (var i = 0; i < numberOfReaders; i++) { // This string tells us what reader we need to decode the following data // string readerTypeString = reader.ReadString(); string originalReaderTypeString = reader.ReadString(); Func<ContentTypeReader> readerFunc; if (typeCreators.TryGetValue(originalReaderTypeString, out readerFunc)) { contentReaders[i] = readerFunc(); needsInitialize[i] = true; } else { //System.Diagnostics.Debug.WriteLine(originalReaderTypeString); // Need to resolve namespace differences string readerTypeString = originalReaderTypeString; readerTypeString = PrepareType(readerTypeString); var l_readerType = Type.GetType(readerTypeString); if (l_readerType != null) { ContentTypeReader typeReader; if (!_contentReadersCache.TryGetValue(l_readerType, out typeReader)) { try { typeReader = l_readerType.GetDefaultConstructor().Invoke(null) as ContentTypeReader; } catch (TargetInvocationException ex) { // If you are getting here, the Mono runtime is most likely not able to JIT the type. // In particular, MonoTouch needs help instantiating types that are only defined in strings in Xnb files. throw new InvalidOperationException( "Failed to get default constructor for ContentTypeReader. To work around, add a creation function to ContentTypeReaderManager.AddTypeCreator() " + "with the following failed type string: " + originalReaderTypeString, ex); } needsInitialize[i] = true; _contentReadersCache.Add(l_readerType, typeReader); } contentReaders[i] = typeReader; } else throw new ContentLoadException( "Could not find ContentTypeReader Type. Please ensure the name of the Assembly that contains the Type matches the assembly in the full type name: " + originalReaderTypeString + " (" + readerTypeString + ")"); } var targetType = contentReaders[i].TargetType; if (targetType != null) _contentReaders.Add(targetType, contentReaders[i]); // I think the next 4 bytes refer to the "Version" of the type reader, // although it always seems to be zero reader.ReadInt32(); } // Initialize any new readers. for (var i = 0; i < contentReaders.Length; i++) { if (needsInitialize.Get(i)) contentReaders[i].Initialize(this); } } // lock (_locker) return contentReaders; }
internal ContentTypeReader[] LoadAssetReaders() { #pragma warning disable 0219, 0649 // Trick to prevent the linker removing the code, but not actually execute the code if (falseflag) { // Dummy variables required for it to work on iDevices ** DO NOT DELETE ** // This forces the classes not to be optimized out when deploying to iDevices var hByteReader = new ByteReader(); var hSByteReader = new SByteReader(); var hDateTimeReader = new DateTimeReader(); var hDecimalReader = new DecimalReader(); var hBoundingSphereReader = new BoundingSphereReader(); var hBoundingFrustumReader = new BoundingFrustumReader(); var hRayReader = new RayReader(); var hCharListReader = new ListReader <Char>(); var hRectangleListReader = new ListReader <Rectangle>(); var hVector3ListReader = new ListReader <Vector3>(); var hStringListReader = new ListReader <StringReader>(); var hSpriteFontReader = new SpriteFontReader(); var hTexture2DReader = new Texture2DReader(); var hCharReader = new CharReader(); var hRectangleReader = new RectangleReader(); var hStringReader = new StringReader(); var hVector2Reader = new Vector2Reader(); var hVector3Reader = new Vector3Reader(); var hVector4Reader = new Vector4Reader(); var hCurveReader = new CurveReader(); var hIndexBufferReader = new IndexBufferReader(); var hBoundingBoxReader = new BoundingBoxReader(); var hMatrixReader = new MatrixReader(); var hBasicEffectReader = new BasicEffectReader(); var hVertexBufferReader = new VertexBufferReader(); var hAlphaTestEffectReader = new AlphaTestEffectReader(); } #pragma warning restore 0219, 0649 int numberOfReaders; // The first content byte i read tells me the number of content readers in this XNB file numberOfReaders = _reader.Read7BitEncodedInt(); contentReaders = new ContentTypeReader[numberOfReaders]; // For each reader in the file, we read out the length of the string which contains the type of the reader, // then we read out the string. Finally we instantiate an instance of that reader using reflection for (int i = 0; i < numberOfReaders; i++) { // This string tells us what reader we need to decode the following data // string readerTypeString = reader.ReadString(); string originalReaderTypeString = _reader.ReadString(); // Need to resolve namespace differences string readerTypeString = originalReaderTypeString; readerTypeString = PrepareType(readerTypeString); Type l_readerType = Type.GetType(readerTypeString); if (l_readerType != null) { contentReaders[i] = (ContentTypeReader)Activator.CreateInstance(l_readerType, true); } else { throw new ContentLoadException("Could not find matching content reader of type " + originalReaderTypeString + " (" + readerTypeString + ")"); } // I think the next 4 bytes refer to the "Version" of the type reader, // although it always seems to be zero int typeReaderVersion = _reader.ReadInt32(); } return(contentReaders); }