Mercurial > hg > dmlib
comparison src/dmres.h @ 2446:8193f62a541d
Remove some useless complexity from resource system .. could remove more.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 10 Mar 2020 00:20:05 +0200 |
parents | fa089a430121 |
children | 9807ae37ad69 |
comparison
equal
deleted
inserted
replaced
2445:fa089a430121 | 2446:8193f62a541d |
---|---|
20 | 20 |
21 /* Constants | 21 /* Constants |
22 */ | 22 */ |
23 enum | 23 enum |
24 { | 24 { |
25 DMPRUNE_ATIME = 0x0001, | |
26 DMPRUNE_MTIME = 0x0002, | |
27 }; | |
28 | |
29 enum | |
30 { | |
31 DRF_USE_PACK = 0x0001, | 25 DRF_USE_PACK = 0x0001, |
32 DRF_USE_STDIO = 0x0002, | 26 DRF_USE_STDIO = 0x0002, |
33 DRF_PRELOAD_RAW = 0x0004, | 27 DRF_PRELOAD_RAW = 0x0004, |
34 DRF_PRELOAD_RES = 0x0008, | 28 DRF_PRELOAD_RES = 0x0008, |
35 }; | 29 }; |
36 | 30 |
37 enum | 31 enum |
38 { | 32 { |
39 DMF_PERSIST = 0x0001, // Persist loaded RAW resource | 33 DMF_PERSIST = 0x0001, // Persist loaded RAW resource |
40 DMF_COMPRESSED = 0x0002, // Resource is compressed in PACK file, otherwise raw | 34 DMF_COMPRESSED = 0x0002, // Resource is compressed in PACK file, otherwise raw |
41 DMF_TEMPORARY = 0x0004, | |
42 DMF_PACK_MASK = 0x00ff, // Mask for flags that may be specified in PACK | 35 DMF_PACK_MASK = 0x00ff, // Mask for flags that may be specified in PACK |
43 | 36 |
44 DMF_UNALLOCATED = 0x1000, // The raw data is not allocated, so do not free it | 37 DMF_UNALLOCATED = 0x1000, // The raw data is not allocated, so do not free it |
45 DMF_LOADED_RAW = 0x2000, // Raw data has been loaded | 38 DMF_LOADED_RAW = 0x2000, // Raw data has been loaded |
46 DMF_LOADED_RES = 0x4000, // Resource has been loaded | 39 DMF_LOADED_RES = 0x4000, // Resource has been loaded |
55 struct DMResource; | 48 struct DMResource; |
56 | 49 |
57 typedef struct DMResource | 50 typedef struct DMResource |
58 { | 51 { |
59 // Timestamps (in seconds from time()) | 52 // Timestamps (in seconds from time()) |
60 int mtime, // When resource was loaded | |
61 atime; // Last accessed (dmResourceRef()/unref) | |
62 int refcount; // Reference count | 53 int refcount; // Reference count |
63 | 54 |
64 int flags; // Resource flags (DMF_*) | 55 int flags; // Resource flags (DMF_*) |
65 char *filename; | 56 char *filename; |
66 | 57 |
114 | 105 |
115 typedef struct DMResourceOps | 106 typedef struct DMResourceOps |
116 { | 107 { |
117 char *name; | 108 char *name; |
118 | 109 |
110 int (*fopen)(DMResource *); | |
111 void (*fclose)(DMResource *); | |
112 int (*preload)(DMResource *); | |
113 | |
119 int (*freset)(DMResource *); | 114 int (*freset)(DMResource *); |
120 int (*ferror)(DMResource *); | 115 int (*ferror)(DMResource *); |
121 int (*fseek)(DMResource *, const off_t, const int); | 116 int (*fseek)(DMResource *, const off_t, const int); |
122 off_t (*fsize)(DMResource *); | 117 off_t (*fsize)(DMResource *); |
123 off_t (*ftell)(DMResource *); | 118 off_t (*ftell)(DMResource *); |
125 int (*fgetc)(DMResource *); | 120 int (*fgetc)(DMResource *); |
126 int (*fputc)(int, DMResource *); | 121 int (*fputc)(int, DMResource *); |
127 size_t (*fread)(void *, const size_t, const size_t, DMResource *); | 122 size_t (*fread)(void *, const size_t, const size_t, DMResource *); |
128 size_t (*fwrite)(const void *, const size_t, const size_t, DMResource *); | 123 size_t (*fwrite)(const void *, const size_t, const size_t, DMResource *); |
129 | 124 |
130 int (*fopen)(DMResource *); | |
131 void (*fclose)(DMResource *); | |
132 int (*preload)(DMResource *); | |
133 } DMResourceOps; | 125 } DMResourceOps; |
134 | 126 |
135 | 127 |
136 /* Functions | 128 /* Functions |
137 */ | 129 */ |
138 int dmResourcesInit(DMResourceLib **lib, const char *filename, const char *path, const int flags, int (*classifier)(DMResource *)); | 130 int dmResourcesInit(DMResourceLib **lib, const char *filename, const char *path, const int flags, int (*classifier)(DMResource *)); |
139 int dmResourcesClose(DMResourceLib *lib); | 131 int dmResourcesClose(DMResourceLib *lib); |
140 | 132 |
141 void dmResourcesPrune(DMResourceLib *lib, const int agems, int const flags); | |
142 int dmResourcesPreload(DMResourceLib *lib, BOOL start, int *loaded, int *total); | 133 int dmResourcesPreload(DMResourceLib *lib, BOOL start, int *loaded, int *total); |
143 | 134 |
144 DMResource * dmResourceNew(DMResourceLib *lib, const char *filename, const size_t size, const int flags); | 135 DMResource * dmResourceNew(DMResourceLib *lib, const char *filename, const size_t size, const int flags); |
145 void dmResourceFree(DMResource *node); | 136 void dmResourceFree(DMResource *node); |
146 void dmResourceInsert(DMResourceLib *lib, DMResource * node); | 137 void dmResourceInsert(DMResourceLib *lib, DMResource * node); |
147 void dmResourceDelete(DMResourceLib *lib, DMResource * node); | 138 void dmResourceDelete(DMResourceLib *lib, DMResource * node); |
148 DMResource * dmResourceFind(DMResourceLib *lib, const char *filename); | 139 DMResource * dmResourceFind(DMResourceLib *lib, const char *filename); |
140 | |
149 int dmResourceRef(DMResource *); | 141 int dmResourceRef(DMResource *); |
150 int dmResourceUnref(DMResource *); | 142 int dmResourceUnref(DMResource *); |
151 | 143 |
152 | 144 |
153 // Opening and closing resources | 145 // Opening and closing resources |