Mercurial > hg > dmlib
annotate dmres.h @ 100:f16d102dbbac
Add a function for setting bitmapped font palette.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 02 Oct 2012 20:33:01 +0300 |
parents | 23ac82365a65 |
children | d97accc86365 |
rev | line source |
---|---|
0 | 1 /* |
2 * DMLib | |
3 * -- Resource management | |
4 * Programmed and designed by Matti 'ccr' Hamalainen | |
5 * (C) Copyright 2011-2012 Tecnic Software productions (TNSP) | |
6 */ | |
7 #ifndef DMRES_H | |
8 #define DMRES_H | |
9 | |
10 #include "dmlib.h" | |
11 | |
12 #ifdef DMRES_PACKFS | |
13 #include <zlib.h> | |
14 #include "dmpack.h" | |
15 #endif | |
16 | |
17 #ifdef __cplusplus | |
18 extern "C" { | |
19 #endif | |
20 | |
21 | |
22 /* Constants | |
23 */ | |
24 enum | |
25 { | |
26 DMPRUNE_ATIME = 0x0001, | |
27 DMPRUNE_MTIME = 0x0002, | |
28 }; | |
29 | |
30 enum | |
31 { | |
32 DRF_USE_PACK = 0x0001, | |
26
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
33 DRF_PRELOAD_ALL = 0x0002, |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
34 DRF_PRELOAD_RES = 0x0004, |
0 | 35 }; |
36 | |
37 enum | |
38 { | |
26
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
39 DMF_PRELOAD_RAW = 0x0001, // Preload raw data |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
40 DMF_PRELOAD_RES = 0x0002, // Perform resource preloading (not |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
41 DMF_PERSIST = 0x0004, // Persist loaded resource (only freed at shutdown/explicit prune) |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
42 DMF_STREAM = 0x0008, // This resource is streamed (UNSUPPORTED FOR NOW) |
4
e0fc7863d024
Mask out bits from resFlags that should not be there after initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
43 DMF_MASK = 0x0fff, |
0 | 44 |
26
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
45 DMF_LOADED_RAW = 0x1000, // Raw data has been loaded |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
46 DMF_LOADED_RES = 0x2000, // Resource has been loaded |
0 | 47 }; |
48 | |
49 | |
50 /* Typedefs and structures | |
51 */ | |
26
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
52 struct DMResourceDataOps; |
0 | 53 struct DMResourceOps; |
26
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
54 struct DMResource; |
0 | 55 |
26
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
56 typedef struct DMResource |
0 | 57 { |
58 // Timestamps (in seconds from time()) | |
59 int mtime, // When resource was loaded | |
60 atime; // Last accessed (dmres_ref()/unref) | |
61 int refcount; // Reference count | |
62 | |
63 int flags; // Resource flags (DMF_*) | |
64 char *filename; | |
65 | |
66 size_t dataSize; // Size of data | |
67 off_t dataOffset; // Current offset in data | |
68 Uint8 *data; // Pointer to data | |
69 | |
70 int error; // Error code | |
71 | |
72 struct DMResourceOps *fops; // Pointer to file handling functions struct | |
26
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
73 struct DMResource *next, *prev; |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
74 |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
75 void *rdata; |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
76 struct DMResourceDataOps *rops; |
0 | 77 |
78 FILE * fh; | |
79 } DMResource; | |
80 | |
81 | |
26
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
82 typedef struct DMResourceDataOps |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
83 { |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
84 int (*load)(DMResource *res); |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
85 void (*free)(DMResource *res); |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
86 } DMResourceDataOps; |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
87 |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
88 |
0 | 89 typedef struct DMResourceOps |
90 { | |
91 int (*ferror)(DMResource *); | |
92 int (*fseek)(DMResource *, const off_t, const int); | |
93 off_t (*fsize)(DMResource *); | |
94 off_t (*ftell)(DMResource *); | |
95 BOOL (*feof)(DMResource *); | |
96 int (*fgetc)(DMResource *); | |
59
c560703e85ed
Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
97 int (*fputc)(int, DMResource *); |
0 | 98 size_t (*fread)(void *, const size_t, const size_t, DMResource *); |
59
c560703e85ed
Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
99 size_t (*fwrite)(void *, const size_t, const size_t, DMResource *); |
0 | 100 |
101 int (*fopen)(DMResource *); | |
102 void (*fclose)(DMResource *); | |
103 int (*preload)(DMResource *); | |
104 } DMResourceOps; | |
105 | |
106 | |
107 /* Functions | |
108 */ | |
26
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
109 int dmres_init(const char *filename, const char *path, int flags, int (*classifier)(DMResource *)); |
0 | 110 void dmres_close(void); |
111 | |
112 void dmres_prune(int agems, int flags); | |
26
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
113 int dmres_preload(BOOL start, int *loaded, int *total); |
0 | 114 |
115 int dmres_load_resfile(const char *filename); | |
116 int dmres_write_resfile(const char *filename); | |
117 | |
118 DMResource * dmres_find(const char *filename); | |
119 int dmres_ref(DMResource *); | |
120 int dmres_unref(DMResource *); | |
121 | |
122 | |
123 // Opening and closing resources | |
124 DMResource * dmf_open(const char *); | |
125 DMResource * dmf_open_memio(const char *, Uint8 *buf, size_t len); | |
126 #ifdef DMRES_STDIO | |
74
23ac82365a65
Add file mode to dmf_create_stdio().
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
127 DMResource * dmf_create_stdio(const char *filename, const char *mode); |
0 | 128 DMResource * dmf_create_stdio_stream(FILE *); |
129 #endif | |
130 void dmf_close(DMResource *); | |
131 | |
132 | |
133 // Basic resource access functions | |
134 int dmferror(DMResource *); | |
135 int dmfseek(DMResource *, const off_t, const int); | |
136 off_t dmfsize(DMResource *); | |
137 off_t dmftell(DMResource *); | |
138 BOOL dmfeof(DMResource *); | |
139 int dmfgetc(DMResource *); | |
59
c560703e85ed
Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
140 int dmfputc(int, DMResource *); |
0 | 141 size_t dmfread(void *, const size_t, const size_t, DMResource *); |
59
c560703e85ed
Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
142 size_t dmfwrite(void *, const size_t, const size_t, DMResource *); |
0 | 143 |
144 | |
145 // Specialized functions for endianess based reading etc | |
146 int dmf_read_str(DMResource *, Uint8 *, size_t); | |
147 BOOL dmf_read_be16(DMResource *, Uint16 *); | |
148 BOOL dmf_read_be32(DMResource *, Uint32 *); | |
149 BOOL dmf_read_le16(DMResource *, Uint16 *); | |
150 BOOL dmf_read_le32(DMResource *, Uint32 *); | |
151 | |
152 #ifdef DM_HAVE_64BIT | |
153 BOOL dmf_read_be64(DMResource *, Uint64 *); | |
154 BOOL dmf_read_le64(DMResource *, Uint64 *); | |
155 #endif | |
156 | |
157 | |
158 #ifdef __cplusplus | |
159 } | |
160 #endif | |
161 | |
162 #endif // DMRES_H |