Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SDL2StreamWrapper"/> class.
        /// </summary>
        /// <param name="stream">The stream which will be wrapped by this object.</param>
        public SDL2StreamWrapper(Stream stream)
        {
            Contract.Require(stream, nameof(stream));

            this.stream   = stream;
            this.gchandle = GCHandle.Alloc(this, GCHandleType.Weak);

            this.rwops        = (SDL_RWops *)SDL.AllocRW();
            this.rwops->size  = Marshal.GetFunctionPointerForDelegate(new RWops_size(RWops_size_callback));
            this.rwops->seek  = Marshal.GetFunctionPointerForDelegate(new RWops_seek(RWops_seek_callback));
            this.rwops->read  = Marshal.GetFunctionPointerForDelegate(new RWops_read(RWops_read_callback));
            this.rwops->write = Marshal.GetFunctionPointerForDelegate(new RWops_write(RWops_write_callback));
            this.rwops->close = Marshal.GetFunctionPointerForDelegate(new RWops_close(RWops_close_callback));
            this.rwops->data1 = GCHandle.ToIntPtr(gchandle);
        }