/// <summary> /// Creates texturepacks and adds them to the packs list. /// </summary> private void LoadTexturePacks(IODataPack ioDataPack) { XElement xml = ioDataPack.Xml; IOContent contentType = ioDataPack.Type; IOOperation operation = ioDataPack.Operation; int totalFiles = FileCount(xml); int loadedFiles = 0; int progress = 0; OnStart(this, new IOEventArgs(progress, operation, contentType)); IEnumerable <XElement> xmlPacks = from element in xml.Elements() select element; foreach (XElement xmlData in xmlPacks) { int id = Convert.ToInt32(xmlData.Element("id").Value); int count = Convert.ToInt32(xmlData.Element("frames").Value); string folder = xmlData.Element("folder").Value; string name = xmlData.Element("name").Value; packs.Add(CreateTexturePack(id, name, folder, count, ref loadedFiles, ref totalFiles, contentType, operation)); links.Add(name, packs.Count - 1); links.Add(id, packs.Count - 1); OnNewPack(this, new IOEventArgs(progress, operation, contentType)); } OnComplete(this, new IOEventArgs(progress, operation, contentType)); }
public FontsCollection(Game game, XElement xml, IOOperation op, IOContent type) : base(game) { fonts = new List<FontPack>(); links = new Hashtable(); Game.Components.Add(this); ThreadPool.QueueUserWorkItem(new WaitCallback(Load), new IODataPack(xml, op, type)); }
/// <summary> /// Creates a new GraphicsCollection and starts loading the textures from the received XML. /// </summary> public GraphicsCollection(Game game, XElement _xml, IOContent type, IOOperation op) : base(game) { packs = new List <TexturePack>(); links = new Hashtable(); Game.Components.Add(this); ThreadPool.QueueUserWorkItem(new WaitCallback(Load), new IODataPack(_xml, op, type)); }
public IOEventArgs(double progress, IOOperation op,IOContent c) { progressPercent = progress; content = c; operation = op; }
/// <summary> /// Creates a new GameInterface_Graphics or GameMap instance in a separate thread /// or (loades a new profile and shows the CommandCenter) using a separate thread /// </summary> /// <param name="operation"></param> public void InstanciateInterface(IOOperation operation) { preloader.Visible = true; preloader.Enabled = true; preloader.Status = operation; ThreadPool.QueueUserWorkItem(new WaitCallback(InstanciateInterfaceWrapper), operation); //InstanciateInterfaceWrapper(operation); }
public void ShowPreloaderTimerMode(IOOperation operation) { CameraFreeze(); preloader.Visible = true; preloader.Enabled = true; preloader.Width = camera.Screen.Width; preloader.Height = camera.Screen.Height; preloader.X = (int)camera.Position.X; preloader.Y = (int)camera.Position.Y; preloader.Status = operation; preloader.TimerMode(); }
/// <summary> /// Writes a sequence of bytes to the stream and advances the current /// position within this stream by the number of bytes written. /// </summary> /// <remarks> /// Filters the provided buffer through each of the filters before finally writing /// the result to the underlying <see cref="Source"/> stream. /// </remarks> /// <param name='buffer'>The buffer to write.</param> /// <param name='offset'>The offset of the first byte to write.</param> /// <param name='count'>The number of bytes to write.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="buffer"/> is <c>null</c>. /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// <para><paramref name="offset"/> is less than zero or greater than the length of <paramref name="buffer"/>.</para> /// <para>-or-</para> /// <para>The <paramref name="buffer"/> is not large enough to contain <paramref name="count"/> bytes strting /// at the specified <paramref name="offset"/>.</para> /// </exception> /// <exception cref="System.ObjectDisposedException"> /// The stream has been disposed. /// </exception> /// <exception cref="System.NotSupportedException"> /// The stream does not support writing. /// </exception> /// <exception cref="System.IO.IOException"> /// An I/O error occurred. /// </exception> public override void Write(byte[] buffer, int offset, int count) { CheckDisposed (); CheckCanWrite (); ValidateArguments (buffer, offset, count); lastOp = IOOperation.Write; flushed = false; filteredIndex = offset; filteredLength = count; filtered = buffer; foreach (var filter in filters) filtered = filter.Filter (filtered, filteredIndex, filteredLength, out filteredIndex, out filteredLength); Source.Write (filtered, filteredIndex, filteredLength); }
/// <summary> /// Reads a sequence of bytes from the stream and advances the position /// within the stream by the number of bytes read. /// </summary> /// <remarks> /// Reads up to the requested number of bytes, passing the data read from the <see cref="Source"/> stream /// through each of the filters before finally copying the result into the provided buffer. /// </remarks> /// <returns>The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many /// bytes are not currently available, or zero (0) if the end of the stream has been reached.</returns> /// <param name="buffer">The buffer to read data into.</param> /// <param name="offset">The offset into the buffer to start reading data.</param> /// <param name="count">The number of bytes to read.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="buffer"/> is <c>null</c>. /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// <para><paramref name="offset"/> is less than zero or greater than the length of <paramref name="buffer"/>.</para> /// <para>-or-</para> /// <para>The <paramref name="buffer"/> is not large enough to contain <paramref name="count"/> bytes strting /// at the specified <paramref name="offset"/>.</para> /// </exception> /// <exception cref="System.ObjectDisposedException"> /// The stream has been disposed. /// </exception> /// <exception cref="System.NotSupportedException"> /// The stream does not support reading. /// </exception> /// <exception cref="System.IO.IOException"> /// An I/O error occurred. /// </exception> public override int Read(byte[] buffer, int offset, int count) { CheckDisposed (); CheckCanRead (); ValidateArguments (buffer, offset, count); lastOp = IOOperation.Read; if (readbuf == null) readbuf = new byte[ReadBufferSize]; int nread; if (filteredLength == 0) { if ((nread = Source.Read (readbuf, 0, ReadBufferSize)) <= 0) return nread; // filter the data we've just read... filteredLength = nread; filteredIndex = 0; filtered = readbuf; foreach (var filter in filters) filtered = filter.Filter (filtered, filteredIndex, filteredLength, out filteredIndex, out filteredLength); } // copy our filtered data into our caller's buffer nread = Math.Min (filteredLength, count); if (nread > 0) { Array.Copy (filtered, filteredIndex, buffer, offset, nread); filteredLength -= nread; filteredIndex += nread; } return nread; }
public void AddFontsFromXml(XElement xml, IOOperation op, IOContent type) { ThreadPool.QueueUserWorkItem(new WaitCallback(Load), new IODataPack(xml, op, type)); }
/// <summary> /// Creates a new GraphicsCollection and starts loading the textures from the received XML. /// </summary> public GraphicsCollection(Game game, XElement _xml, IOContent type, IOOperation op) : base(game) { packs = new List<TexturePack>(); links = new Hashtable(); Game.Components.Add(this); ThreadPool.QueueUserWorkItem(new WaitCallback(Load), new IODataPack(_xml, op, type)); }
public IODataPack(XElement _xml, IOOperation op,IOContent _type){ xml = _xml; type = _type; operation = op; }
/// <summary> /// Loads a pack of textures and returns a new TexturePack. /// </summary> /// <param name="id">The id of the TexturePack returned.</param> /// <param name="name">The name of the TexturePack returned.</param> /// <param name="folder">The path of the TexturePack returned.</param> /// <param name="count">The number of frames.</param> private TexturePack CreateTexturePack(int id, string name, string folder, int count, ref int loadedFiles, ref int totalFiles, IOContent contentType, IOOperation operation) { List<Texture2D> temp = new List<Texture2D>(count); for (int i = 0; i < count; i++) { string path = folder + "//" + (10000 + i).ToString(); Texture2D tex = Game.Content.Load<Texture2D>(path); //Thread.Sleep(500); loadedFiles++; double progress = (double)loadedFiles/(double)totalFiles*100; OnProgress(this, new IOEventArgs(progress,operation, contentType)); temp.Add(tex); } return new TexturePack(name, id, temp); }
public IOSelectorJob(IOOperation operation, IOAsyncCallback callback, IOAsyncResult state) { this.operation = operation; this.callback = callback; this.state = state; }
public IODataPack(XElement _xml, IOOperation op, IOContent _type) { xml = _xml; type = _type; operation = op; }
/// <summary> /// Loads a pack of textures and returns a new TexturePack. /// </summary> /// <param name="id">The id of the TexturePack returned.</param> /// <param name="name">The name of the TexturePack returned.</param> /// <param name="folder">The path of the TexturePack returned.</param> /// <param name="count">The number of frames.</param> private TexturePack CreateTexturePack(int id, string name, string folder, int count, ref int loadedFiles, ref int totalFiles, IOContent contentType, IOOperation operation) { List <Texture2D> temp = new List <Texture2D>(count); for (int i = 0; i < count; i++) { string path = folder + "//" + (10000 + i).ToString(); Texture2D tex = Game.Content.Load <Texture2D>(path); //Thread.Sleep(500); loadedFiles++; double progress = (double)loadedFiles / (double)totalFiles * 100; OnProgress(this, new IOEventArgs(progress, operation, contentType)); temp.Add(tex); } return(new TexturePack(name, id, temp)); }
/// <summary> /// Reads a sequence of bytes from the stream and advances the position /// within the stream by the number of bytes read. /// </summary> /// <remarks> /// Reads up to the requested number of bytes, passing the data read from the <see cref="Source"/> stream /// through each of the filters before finally copying the result into the provided buffer. /// </remarks> /// <returns>The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many /// bytes are not currently available, or zero (0) if the end of the stream has been reached.</returns> /// <param name="buffer">The buffer to read data into.</param> /// <param name="offset">The offset into the buffer to start reading data.</param> /// <param name="count">The number of bytes to read.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="buffer"/> is <c>null</c>. /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// <para><paramref name="offset"/> is less than zero or greater than the length of <paramref name="buffer"/>.</para> /// <para>-or-</para> /// <para>The <paramref name="buffer"/> is not large enough to contain <paramref name="count"/> bytes starting /// at the specified <paramref name="offset"/>.</para> /// </exception> /// <exception cref="System.ObjectDisposedException"> /// The stream has been disposed. /// </exception> /// <exception cref="System.NotSupportedException"> /// The stream does not support reading. /// </exception> /// <exception cref="System.OperationCanceledException"> /// The operation was canceled via the cancellation token. /// </exception> /// <exception cref="System.IO.IOException"> /// An I/O error occurred. /// </exception> public int Read (byte[] buffer, int offset, int count, CancellationToken cancellationToken) { CheckDisposed (); CheckCanRead (); ValidateArguments (buffer, offset, count); lastOp = IOOperation.Read; if (readbuf == null) readbuf = new byte[ReadBufferSize]; int nread; if (filteredLength == 0) { var cancellable = Source as ICancellableStream; if (cancellable != null) { if ((nread = cancellable.Read (readbuf, 0, ReadBufferSize, cancellationToken)) <= 0) return nread; } else { cancellationToken.ThrowIfCancellationRequested (); if ((nread = Source.Read (readbuf, 0, ReadBufferSize)) <= 0) return nread; } // filter the data we've just read... filteredLength = nread; filteredIndex = 0; filtered = readbuf; foreach (var filter in filters) filtered = filter.Filter (filtered, filteredIndex, filteredLength, out filteredIndex, out filteredLength); } // copy our filtered data into our caller's buffer nread = Math.Min (filteredLength, count); if (nread > 0) { Buffer.BlockCopy (filtered, filteredIndex, buffer, offset, nread); filteredLength -= nread; filteredIndex += nread; } return nread; }
/// <summary> /// Writes a sequence of bytes to the stream and advances the current /// position within this stream by the number of bytes written. /// </summary> /// <remarks> /// Filters the provided buffer through each of the filters before finally writing /// the result to the underlying <see cref="Source"/> stream. /// </remarks> /// <param name="buffer">The buffer to write.</param> /// <param name="offset">The offset of the first byte to write.</param> /// <param name="count">The number of bytes to write.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="buffer"/> is <c>null</c>. /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// <para><paramref name="offset"/> is less than zero or greater than the length of <paramref name="buffer"/>.</para> /// <para>-or-</para> /// <para>The <paramref name="buffer"/> is not large enough to contain <paramref name="count"/> bytes starting /// at the specified <paramref name="offset"/>.</para> /// </exception> /// <exception cref="System.ObjectDisposedException"> /// The stream has been disposed. /// </exception> /// <exception cref="System.NotSupportedException"> /// The stream does not support writing. /// </exception> /// <exception cref="System.OperationCanceledException"> /// The operation was canceled via the cancellation token. /// </exception> /// <exception cref="System.IO.IOException"> /// An I/O error occurred. /// </exception> public void Write (byte[] buffer, int offset, int count, CancellationToken cancellationToken) { CheckDisposed (); CheckCanWrite (); ValidateArguments (buffer, offset, count); lastOp = IOOperation.Write; flushed = false; filteredIndex = offset; filteredLength = count; filtered = buffer; foreach (var filter in filters) filtered = filter.Filter (filtered, filteredIndex, filteredLength, out filteredIndex, out filteredLength); var cancellable = Source as ICancellableStream; if (cancellable != null) { cancellable.Write (filtered, filteredIndex, filteredLength, cancellationToken); } else { cancellationToken.ThrowIfCancellationRequested (); Source.Write (filtered, filteredIndex, filteredLength); } }
public IOSelectorJob (IOOperation operation, IOAsyncCallback callback, IOAsyncResult state) { this.operation = operation; this.callback = callback; this.state = state; }