Ejemplo n.º 1
0
        public override Texture2D Load(ContentStream stream, LoaderContext ctx)
        {
            // Read the ushort dimensions
            uint w     = stream.ReadUInt16();
            uint h     = stream.ReadUInt16();
            uint count = w * h;

            if ((count * 4) != stream.Remaining)
            {
                throw new Exception($"the expected and available texture data lengths do not match ({count * 4} != {stream.Remaining}).");
            }

            // Read in the entirety of the pixel data  (stored as RGBA packed uints)
            var data = new uint[count];

            for (uint i = 0; i < count; ++i)
            {
                data[i] = stream.ReadUInt32();
            }

            // Create the texture, upload the pixels, and return
            Texture2D tex = new Texture2D(w, h);

            tex.SetData(data);
            return(tex);
        }
Ejemplo n.º 2
0
        public unsafe override IAudioSource Load(ContentStream stream, LoaderContext ctx)
        {
            uint frameCount = stream.ReadUInt32();
            uint sampleRate = stream.ReadUInt32();
            bool isStereo   = stream.ReadBoolean();
            bool isLossy    = stream.ReadBoolean();

            if (ctx.ContentType == SOUNDEFFECT_TYPE)
            {
                uint fullLen = frameCount * 2 * (isStereo ? 2u : 1u);
                var  data    = Marshal.AllocHGlobal((int)fullLen);

                try
                {
                    RLADStream.DecodeAll(stream, (short *)data.ToPointer(), isStereo, frameCount);

                    var sb = new SoundBuffer();
                    sb.SetData(data, isStereo ? AudioFormat.Stereo16 : AudioFormat.Mono16, sampleRate, fullLen);
                    return(new SoundEffect(sb));
                }
                finally
                {
                    Marshal.FreeHGlobal(data);
                }
            }
            else             // Song
            {
                var astream = new RLADStream(stream.Duplicate(), isStereo, frameCount);
                return(new Song(astream, sampleRate));
            }
        }
Ejemplo n.º 3
0
 object IContentLoader.Load(ContentStream stream, LoaderContext ctx) => Load(stream, ctx);
Ejemplo n.º 4
0
 /// <summary>
 /// Implements the loading logic of reading in a content file and producing a runtime type. Returning null
 /// from this function is considered an error.
 /// <para>
 /// It is important that this function does not reference the stream for later use, as each stream instance
 /// is shared across multiple <see cref="ContentLoader{T}"/> instances. If you need to read the content file
 /// outside of this function (such as for streaming), use <see cref="ContentStream.Duplicate"/> to create a
 /// usable copy of the stream.
 /// </para>
 /// </summary>
 /// <param name="stream">The opaque stream to the content data on disk.</param>
 /// <param name="ctx">Extra information about the current load process.</param>
 /// <returns>A new runtime type loaded from the content item data on disk.</returns>
 public abstract T Load(ContentStream stream, LoaderContext ctx);
Ejemplo n.º 5
0
 public override byte[] Load(ContentStream stream, LoaderContext ctx)
 {
     return(stream.ReadBytes(ctx.DataLength));
 }