comparison dmres.h @ 26:2f463a59d732

Implement rudimentary resource system.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 29 Sep 2012 05:29:38 +0300
parents e0fc7863d024
children c560703e85ed
comparison
equal deleted inserted replaced
25:372b68c0752a 26:2f463a59d732
28 }; 28 };
29 29
30 enum 30 enum
31 { 31 {
32 DRF_USE_PACK = 0x0001, 32 DRF_USE_PACK = 0x0001,
33 DRF_PRELOAD_ALL = 0x0002,
34 DRF_PRELOAD_RES = 0x0004,
33 }; 35 };
34 36
35 enum 37 enum
36 { 38 {
37 DMF_PRELOAD = 0x0001, // Preload this resource 39 DMF_PRELOAD_RAW = 0x0001, // Preload raw data
38 DMF_PERSIST = 0x0002, // Persist loaded resource (only freed at shutdown/explicit prune) 40 DMF_PRELOAD_RES = 0x0002, // Perform resource preloading (not
39 //DMF_STREAM = 0x0004, // This resource is streamed 41 DMF_PERSIST = 0x0004, // Persist loaded resource (only freed at shutdown/explicit prune)
42 DMF_STREAM = 0x0008, // This resource is streamed (UNSUPPORTED FOR NOW)
40 DMF_MASK = 0x0fff, 43 DMF_MASK = 0x0fff,
41 44
42 DMF_LOADED = 0x1000, // Resource has been loaded 45 DMF_LOADED_RAW = 0x1000, // Raw data has been loaded
46 DMF_LOADED_RES = 0x2000, // Resource has been loaded
43 }; 47 };
44 48
45 49
46 /* Typedefs and structures 50 /* Typedefs and structures
47 */ 51 */
52 struct DMResourceDataOps;
48 struct DMResourceOps; 53 struct DMResourceOps;
54 struct DMResource;
49 55
50 typedef struct _DMResource 56 typedef struct DMResource
51 { 57 {
52 // Timestamps (in seconds from time()) 58 // Timestamps (in seconds from time())
53 int mtime, // When resource was loaded 59 int mtime, // When resource was loaded
54 atime; // Last accessed (dmres_ref()/unref) 60 atime; // Last accessed (dmres_ref()/unref)
55 int refcount; // Reference count 61 int refcount; // Reference count
62 Uint8 *data; // Pointer to data 68 Uint8 *data; // Pointer to data
63 69
64 int error; // Error code 70 int error; // Error code
65 71
66 struct DMResourceOps *fops; // Pointer to file handling functions struct 72 struct DMResourceOps *fops; // Pointer to file handling functions struct
67 struct _DMResource *next, *prev; 73 struct DMResource *next, *prev;
74
75 void *rdata;
76 struct DMResourceDataOps *rops;
68 77
69 FILE * fh; 78 FILE * fh;
70 } DMResource; 79 } DMResource;
80
81
82 typedef struct DMResourceDataOps
83 {
84 int (*load)(DMResource *res);
85 void (*free)(DMResource *res);
86 } DMResourceDataOps;
71 87
72 88
73 typedef struct DMResourceOps 89 typedef struct DMResourceOps
74 { 90 {
75 int (*ferror)(DMResource *); 91 int (*ferror)(DMResource *);
86 } DMResourceOps; 102 } DMResourceOps;
87 103
88 104
89 /* Functions 105 /* Functions
90 */ 106 */
91 int dmres_init(const char *filename, const char *path, int flags); 107 int dmres_init(const char *filename, const char *path, int flags, int (*classifier)(DMResource *));
92 void dmres_close(void); 108 void dmres_close(void);
93 109
94 void dmres_prune(int agems, int flags); 110 void dmres_prune(int agems, int flags);
95 int dmres_preload(); 111 int dmres_preload(BOOL start, int *loaded, int *total);
96 112
97 int dmres_load_resfile(const char *filename); 113 int dmres_load_resfile(const char *filename);
98 int dmres_write_resfile(const char *filename); 114 int dmres_write_resfile(const char *filename);
99 115
100 DMResource * dmres_find(const char *filename); 116 DMResource * dmres_find(const char *filename);