Пример #1
0
 public object Read(ContentStream stream, object existingObject)
 {
     if (existingObject == null)
     {
         BinaryReader binaryReader      = new BinaryReader(stream);
         bool         flag              = binaryReader.ReadBoolean();
         int          channelsCount     = binaryReader.ReadInt32();
         int          samplingFrequency = binaryReader.ReadInt32();
         int          bytesCount        = binaryReader.ReadInt32();
         if (flag)
         {
             MemoryStream memoryStream = new MemoryStream();
             using (StreamingSource streamingSource = Ogg.Stream(stream))
             {
                 streamingSource.CopyTo(memoryStream);
                 if (memoryStream.Length > int.MaxValue)
                 {
                     throw new InvalidOperationException("Audio data too long.");
                 }
                 memoryStream.Position = 0L;
                 return(new SoundBuffer(memoryStream, (int)memoryStream.Length, channelsCount, samplingFrequency));
             }
         }
         return(new SoundBuffer(stream, bytesCount, channelsCount, samplingFrequency));
     }
     throw new NotSupportedException();
 }
Пример #2
0
 public object Read(ContentStream stream, object existingObject)
 {
     if (existingObject == null)
     {
         return(new BinaryReader(stream).ReadString());
     }
     throw new NotSupportedException();
 }
Пример #3
0
 public object Read(ContentStream stream, object existingObject)
 {
     if (existingObject == null)
     {
         return(ReadImage(stream));
     }
     throw new NotSupportedException();
 }
Пример #4
0
 public object Read(ContentStream stream, object existingObject)
 {
     if (existingObject == null)
     {
         SoundFileFormat format = SoundData.DetermineFileFormat(stream);
         return(SoundData.Stream(stream.Duplicate(), format));
     }
     throw new NotSupportedException();
 }
Пример #5
0
 public object Read(ContentStream stream, object existingObject)
 {
     if (existingObject == null)
     {
         return(ReadBitmapFont(stream));
     }
     InitializeBitmapFont(stream, (BitmapFont)existingObject);
     return(existingObject);
 }
Пример #6
0
 public static void LoadContent(ContentDescription contentDescription)
 {
     if (contentDescription.Stream != null)
     {
         IContentReader contentReader = GetContentReader(contentDescription.TypeName);
         ContentStream  stream        = PrepareContentStream(contentDescription);
         contentDescription.Content = contentReader.Read(stream, contentDescription.Content);
         return;
     }
     throw new InvalidOperationException("Cannot load manually added content item. Item must have been disposed and accessed again.");
 }
Пример #7
0
        public object Read(ContentStream stream, object existingObject)
        {
            if (existingObject == null)
            {
                return(ReadTexture(stream));
            }
            Texture2D texture2D = (Texture2D)existingObject;

            stream.Position += 12L;
            LoadTextureData(stream, texture2D, keepSourceImageInTag: false);
            return(texture2D);
        }
Пример #8
0
        public object Read(ContentStream stream, object existingObject)
        {
            bool      keepSourceVertexDataInTags = new BinaryReader(stream).ReadBoolean();
            ModelData modelData = ModelDataContentReader.ReadModelData(stream);

            if (existingObject == null)
            {
                return(Model.Load(modelData, keepSourceVertexDataInTags));
            }
            Model obj = (Model)existingObject;

            obj.Initialize(modelData, keepSourceVertexDataInTags);
            return(obj);
        }
Пример #9
0
 public object Read(ContentStream stream, object existingObject)
 {
     if (existingObject == null)
     {
         BinaryReader  binaryReader     = new BinaryReader(stream);
         string        vertexShaderCode = binaryReader.ReadString();
         string        pixelShaderCode  = binaryReader.ReadString();
         int           num   = binaryReader.ReadInt32();
         ShaderMacro[] array = new ShaderMacro[num];
         for (int i = 0; i < num; i++)
         {
             string name  = binaryReader.ReadString();
             string value = binaryReader.ReadString();
             array[i] = new ShaderMacro(name, value);
         }
         return(new Shader(vertexShaderCode, pixelShaderCode, array));
     }
     throw new NotSupportedException();
 }
Пример #10
0
        public ContentStream Duplicate()
        {
            ContentStream contentStream = new ContentStream();

            contentStream.m_streamFactory = m_streamFactory;
            contentStream.m_data          = m_data;
            if (m_data != null)
            {
                contentStream.m_stream = new PadStream(new MemoryStream(m_data, writable: false));
            }
            else
            {
                contentStream.m_stream = new PadStream(m_streamFactory());
            }
            contentStream.m_stream.Position = m_stream.Position;
            contentStream.m_start           = m_start;
            contentStream.m_length          = m_length;
            contentStream.Pad = Pad;
            return(contentStream);
        }
Пример #11
0
 public static void AddPackage(Func <Stream> streamFactory, byte[] tocPad = null, byte[] contentPad = null)
 {
     lock (m_lock)
     {
         if (!m_isInitialized)
         {
             m_isInitialized      = true;
             Display.DeviceReset += Display_DeviceReset;
         }
         ContentStream contentStream = new ContentStream(streamFactory);
         using (BinaryReader binaryReader = new BinaryReader(contentStream, Encoding.UTF8, leaveOpen: true))
         {
             byte[] array = new byte[4];
             if (binaryReader.Read(array, 0, array.Length) != array.Length || array[0] != 80 || array[1] != 75 || array[2] != 50 || array[3] != 0)
             {
                 throw new InvalidOperationException("Invalid package header.");
             }
             contentStream.Pad = tocPad;
             long num  = binaryReader.ReadInt64();
             int  num2 = binaryReader.ReadInt32();
             for (int i = 0; i < num2; i++)
             {
                 string name       = binaryReader.ReadString();
                 string typeName   = binaryReader.ReadString();
                 long   position   = binaryReader.ReadInt64() + num;
                 long   bytesCount = binaryReader.ReadInt64();
                 SetContentDescription(name, new ContentDescription
                 {
                     TypeName   = typeName,
                     Stream     = contentStream,
                     Position   = position,
                     BytesCount = bytesCount
                 });
             }
             contentStream.Pad = contentPad;
         }
     }
 }