Re: [AD] file slices |
[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]
I'm guessing that you wanted the 'f' prefix to make people think
about stdio operations but I think its not needed. slice_close, slice_open, al_open_slice, etc looks better to me. On 07/29/2011 03:14 PM, Matthew Leverton wrote: On Tue, Jul 19, 2011 at 7:09 PM, Peter Wang <novalazy@xxxxxxxxxx> wrote:That still sounds complicated. I prefer your previous suggestion to remove any buffering from file slices. Then file slices are analogous to sub-bitmaps, and memfiles are analogous to memory bitmaps.Attached is an implementation of unbuffered file slices. To run the included test, you need to make test.tga that contains texture.tga twice: cat texture.tga texture.tga > test.tga When using slices both can be loaded successfully, but without them the second try fails. (I think the TGA loader doesn't seek to the end of file when done.) It would introduce one function: ALLEGRO_FILE *al_fopen_slice(ALLEGRO_FILE *fp, size_t initial_size, const char *mode); It opens the slice at the current location of the file with an initial size as specified by the user. Modes can be any combination of [r]eadable, [w]ritable, and [e]xpandable. If the file is not expandable, then writes and reads will be limited to that initial size. If the file is expandable, then the size will increase as data is read or written. In such case, the initial_size would affect what SEEK_END initially does. There is no "until EOF" size, as the programmer can just do that himself by passing al_fsize(fp) - al_ftell(fp) as initial size. When closing the file, the parent is always moved to the end of the slice's current size. The following limitations exist: * the underlying file must be random access (if reading) * the underlying file must be open in regular write mode (if writing) as the slice assumes that writes happen in place at the current position. * the parent cannot be used while the slice is open * only one slice can be open per parent at a time, but slicing a slice should theoretically work. And of course there are some other edge cases that are left undefined, like specifying a size that is larger than the parent, etc. But the programmer should be well aware of what he is doing, so I don't think that matters. -- Matthew Leverton |
Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |