Re: [AD] Custom packfiles |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Chris wrote:
Peter Wang wrote:
nor can you use pack_fopen_chunk() on
vtable-packfiles.
Well, as has been mentioned before, I think Allegro's default pack_*
functions should be implemented as a vtable that's always used for
pack_fopen(). pack_fopen_chunk can simply check that the vtable is
Allegro's, and fail if it isn't. Yeah, this would mean the
pack_*_chunk would be "special", but since they're of limited use
outside of Allegro's datafiles anyway, I can deal with that. People
can easilly support zips or their own archive format anyway.
Note my patch already made pack_*_chunk do this check already. And you
know what I think about packfile_password()-style semantics for
pack_fopen().
However, one thing I would like is for the vtable to contain pf_open
and pf_close methods. That would potentially cut down on a lot of
duplicate code. So the user could do, for instance:
struct mystruct data = {
"myfile.wad", 0
};
PACKFILE *pf = pack_fopen_vtable(&my_vtable, &data);
Then the my_vtable.pf_fopen function would do the actual opening of
the specified file "myfile.wad and could seek to a specific object
(specified through an index 0 in this case) in the file.
I don't see how it cuts down on duplicate code. Say you're going to
write a wrapper like:
PACKFILE *load_wad_object(const char *filename, int index);
With your style:
PACKFILE *load_wad_object(const char *filename, int index)
{
struct mystruct *data = malloc(sizeof *data);
data->filename = filename;
data->index = index;
return pack_fopen_vtable(&my_vtable, &data);
}
int my_fopen(struct mystruct *data)
{
data->fd = open(data->filename);
seek_to_object(data->fd, data->index);
return ok;
}
With my style:
PACKFILE *load_wad_object(const char *filename, int index)
{
int fd = open(filename);
struct mystruct *data = malloc(sizeof *data);
data->fd = fd;
seek_to_object(data->fd, index);
return pack_fopen_vtable(&my_vtable, &data);
}
i.e. with my style pack_fopen_vtable() is only called after the rest of
the opening process is complete. You don't have to stuff input
arguments into a struct just to get it through to pf_fopen.
BTW, I found that if we drop support for old-style packfile encryption
then the LZSS compression/decompression code can be completely decoupled
from packfiles (I have done it in my local copy). What do you guys
think about that? New-style encryption was introduced in 3.9.30.
Peter