Mercurial > hg > dmlib
annotate dmres.h @ 13:07bace8425d9
Optimize the scaled RGBA alpha blit MMX version further.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 28 Sep 2012 10:25:38 +0300 |
parents | e0fc7863d024 |
children | 2f463a59d732 |
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, | |
33 }; | |
34 | |
35 enum | |
36 { | |
37 DMF_PRELOAD = 0x0001, // Preload this resource | |
38 DMF_PERSIST = 0x0002, // Persist loaded resource (only freed at shutdown/explicit prune) | |
39 //DMF_STREAM = 0x0004, // This resource is streamed | |
4
e0fc7863d024
Mask out bits from resFlags that should not be there after initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
40 DMF_MASK = 0x0fff, |
0 | 41 |
42 DMF_LOADED = 0x1000, // Resource has been loaded | |
43 }; | |
44 | |
45 | |
46 /* Typedefs and structures | |
47 */ | |
48 struct DMResourceOps; | |
49 | |
50 typedef struct _DMResource | |
51 { | |
52 // Timestamps (in seconds from time()) | |
53 int mtime, // When resource was loaded | |
54 atime; // Last accessed (dmres_ref()/unref) | |
55 int refcount; // Reference count | |
56 | |
57 int flags; // Resource flags (DMF_*) | |
58 char *filename; | |
59 | |
60 size_t dataSize; // Size of data | |
61 off_t dataOffset; // Current offset in data | |
62 Uint8 *data; // Pointer to data | |
63 | |
64 int error; // Error code | |
65 | |
66 struct DMResourceOps *fops; // Pointer to file handling functions struct | |
67 struct _DMResource *next, *prev; | |
68 | |
69 FILE * fh; | |
70 } DMResource; | |
71 | |
72 | |
73 typedef struct DMResourceOps | |
74 { | |
75 int (*ferror)(DMResource *); | |
76 int (*fseek)(DMResource *, const off_t, const int); | |
77 off_t (*fsize)(DMResource *); | |
78 off_t (*ftell)(DMResource *); | |
79 BOOL (*feof)(DMResource *); | |
80 int (*fgetc)(DMResource *); | |
81 size_t (*fread)(void *, const size_t, const size_t, DMResource *); | |
82 | |
83 int (*fopen)(DMResource *); | |
84 void (*fclose)(DMResource *); | |
85 int (*preload)(DMResource *); | |
86 } DMResourceOps; | |
87 | |
88 | |
89 /* Functions | |
90 */ | |
91 int dmres_init(const char *filename, const char *path, int flags); | |
92 void dmres_close(void); | |
93 | |
94 void dmres_prune(int agems, int flags); | |
95 int dmres_preload(); | |
96 | |
97 int dmres_load_resfile(const char *filename); | |
98 int dmres_write_resfile(const char *filename); | |
99 | |
100 DMResource * dmres_find(const char *filename); | |
101 int dmres_ref(DMResource *); | |
102 int dmres_unref(DMResource *); | |
103 | |
104 | |
105 // Opening and closing resources | |
106 DMResource * dmf_open(const char *); | |
107 DMResource * dmf_open_memio(const char *, Uint8 *buf, size_t len); | |
108 #ifdef DMRES_STDIO | |
109 DMResource * dmf_create_stdio(const char *); | |
110 DMResource * dmf_create_stdio_stream(FILE *); | |
111 #endif | |
112 void dmf_close(DMResource *); | |
113 | |
114 | |
115 // Basic resource access functions | |
116 int dmferror(DMResource *); | |
117 int dmfseek(DMResource *, const off_t, const int); | |
118 off_t dmfsize(DMResource *); | |
119 off_t dmftell(DMResource *); | |
120 BOOL dmfeof(DMResource *); | |
121 int dmfgetc(DMResource *); | |
122 size_t dmfread(void *, const size_t, const size_t, DMResource *); | |
123 | |
124 | |
125 // Specialized functions for endianess based reading etc | |
126 int dmf_read_str(DMResource *, Uint8 *, size_t); | |
127 BOOL dmf_read_be16(DMResource *, Uint16 *); | |
128 BOOL dmf_read_be32(DMResource *, Uint32 *); | |
129 BOOL dmf_read_le16(DMResource *, Uint16 *); | |
130 BOOL dmf_read_le32(DMResource *, Uint32 *); | |
131 | |
132 #ifdef DM_HAVE_64BIT | |
133 BOOL dmf_read_be64(DMResource *, Uint64 *); | |
134 BOOL dmf_read_le64(DMResource *, Uint64 *); | |
135 #endif | |
136 | |
137 | |
138 #ifdef __cplusplus | |
139 } | |
140 #endif | |
141 | |
142 #endif // DMRES_H |