scenefile
diff src/scene.h @ 3:b30f83409769
foo
author | John Tsiombikas <nuclear@mutantstargoat.com> |
---|---|
date | Sat, 21 Jan 2012 04:14:24 +0200 |
parents | c15992cedec9 |
children |
line diff
1.1 --- a/src/scene.h Sun Jan 15 08:32:19 2012 +0200 1.2 +++ b/src/scene.h Sat Jan 21 04:14:24 2012 +0200 1.3 @@ -4,6 +4,7 @@ 1.4 #include "mesh.h" 1.5 1.6 struct scenefile; 1.7 +struct scnfile_io; 1.8 1.9 #ifdef __cplusplus 1.10 extern "C" { 1.11 @@ -20,11 +21,49 @@ 1.12 1.13 1.14 int scnfile_load(struct scenefile *scn, const char *fname); 1.15 +int scnfile_read_file(struct scenefile *scn, FILE *fp); 1.16 +int scnfile_read(struct scenefile *scn, struct scnfile_io *io); 1.17 1.18 int scnfile_find_mesh(struct scenefile *scn, const char *fname); 1.19 struct mesh *scnfile_mesh(struct scenefile *scn, int idx); 1.20 int scnfile_count(struct scenefile *scn); 1.21 1.22 + 1.23 +/* These functions can be used to fill an scnfile_io struct before it's passed to 1.24 + * one of the user-defined i/o image reading/writing functions (scnfile_read/scnfile_write). 1.25 + * 1.26 + * User-defined i/o functions: 1.27 + * 1.28 + * - size_t read_func(void *buffer, size_t bytes, void *user_ptr) 1.29 + * Must try to fill the buffer with the specified number of bytes, and return 1.30 + * the number of bytes actually read. 1.31 + * 1.32 + * - size_t write_func(void *buffer, size_t bytes, void *user_ptr) 1.33 + * Must write the specified number of bytes from the supplied buffer and return 1.34 + * the number of bytes actually written. 1.35 + * 1.36 + * - long seek_func(long offset, int whence, void *user_ptr) 1.37 + * Must seek offset bytes from: the beginning of the file if whence is SEEK_SET, 1.38 + * the current position if whence is SEEK_CUR, or the end of the file if whence is 1.39 + * SEEK_END, and return the resulting file offset from the beginning of the file. 1.40 + * (i.e. seek_func(0, SEEK_CUR, user_ptr); must be equivalent to an ftell). 1.41 + * 1.42 + * All three functions get the user-data pointer set through scnfile_io_set_user_data 1.43 + * as their last argument. 1.44 + * 1.45 + * Note: obviously you don't need to set a write function if you're only going 1.46 + * to call scnfile_read, or the read and seek function if you're only going to call 1.47 + * scnfile_write. 1.48 + * 1.49 + * Note: if the user-supplied write function is buffered, make sure to flush 1.50 + * (or close the file) after scnfile_write returns. 1.51 + */ 1.52 +void scnfile_io_user_data(struct scnfile_io *io, void *uptr); 1.53 +void scnfile_io_read_func(struct scnfile_io *io, size_t (*read)(void*, size_t, void*)); 1.54 +void scnfile_io_write_func(struct scnfile_io *io, size_t (*write)(void*, size_t, void*)); 1.55 +void scnfile_io_seek_func(struct scnfile_io *io, long (*seek)(long, int, void*)); 1.56 + 1.57 + 1.58 #ifdef __cplusplus 1.59 } 1.60 #endif