Mercurial > hg > dmlib
annotate src/dmlib.h @ 813:b0cd28b6c9f3
Add new utility functions.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 16 May 2014 15:17:48 +0300 |
parents | 1e5cf1144f36 |
children | 091461e0213f |
rev | line source |
---|---|
0 | 1 /* |
2 * DMLib | |
3 * -- Main header file | |
4 * Programmed and designed by Matti 'ccr' Hamalainen | |
805 | 5 * (C) Copyright 2011-2014 Tecnic Software productions (TNSP) |
0 | 6 */ |
7 #ifndef DMLIB_H | |
8 #define DMLIB_H | |
9 | |
288
e2f286781180
Use more glanular header includes from SDL, enables us to succesfully link
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
10 #include <SDL_config.h> |
e2f286781180
Use more glanular header includes from SDL, enables us to succesfully link
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
11 #include <SDL_endian.h> |
e2f286781180
Use more glanular header includes from SDL, enables us to succesfully link
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
12 #include <SDL_types.h> |
e2f286781180
Use more glanular header includes from SDL, enables us to succesfully link
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
13 #include <SDL_mutex.h> |
781
e15e0469499a
Add initial code for simulating audio playback while in no-sound situation.
Matti Hamalainen <ccr@tnsp.org>
parents:
770
diff
changeset
|
14 #include <SDL_thread.h> |
288
e2f286781180
Use more glanular header includes from SDL, enables us to succesfully link
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
15 #include <SDL_video.h> |
0 | 16 #include <stdarg.h> |
17 | |
18 #ifdef DM_USE_ASSERTS | |
770 | 19 # include <assert.h> |
0 | 20 #else |
770 | 21 # define assert(NEXPR) // stub |
0 | 22 #endif |
23 | |
24 #ifdef __cplusplus | |
25 extern "C" { | |
26 #endif | |
27 | |
28 // Defaults | |
805 | 29 #define DM_PROG_AUTHOR "By Matti 'ccr' Hamalainen (C) Copyright 2014 TNSP" |
341 | 30 #define DM_PROG_LICENSE "Et all, see README / COPYING for more information." |
0 | 31 |
32 /* Error codes | |
33 */ | |
34 enum { | |
770 | 35 // General error codes |
36 DMERR_OK = 0, | |
37 DMERR_PROGRESS, // Status OK, but operation in progress | |
26
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
38 |
770 | 39 DMERR_FOPEN, |
40 DMERR_FREAD, | |
41 DMERR_FWRITE, | |
42 DMERR_FSEEK, | |
43 DMERR_NOT_FOUND, // Resource/data not found | |
0 | 44 |
770 | 45 DMERR_INVALID_DATA, // Some data was invalid |
46 DMERR_MALLOC, // Memory allocation failure | |
47 DMERR_ALREADY_INIT, // Resource has already been initialized | |
48 DMERR_INIT_FAIL, // General initialization failure | |
49 DMERR_INVALID_ARGS, | |
0 | 50 |
770 | 51 DMERR_NULLPTR, // NULL pointer specified in critical argument |
52 DMERR_NOT_SUPPORTED,// Operation not supported | |
53 DMERR_OUT_OF_DATA, | |
54 DMERR_EXTRA_DATA, | |
55 DMERR_BOUNDS, | |
0 | 56 |
770 | 57 DMERR_INTERNAL, |
506
443228332e5b
Add new error code for internal errors.
Matti Hamalainen <ccr@tnsp.org>
parents:
411
diff
changeset
|
58 |
770 | 59 // PACK-file subsystem |
60 DMERR_NOTPACK, | |
61 DMERR_VERSION, | |
62 DMERR_INVALID, | |
63 DMERR_COMPRESSION, | |
0 | 64 }; |
65 | |
813 | 66 // Directory/path separator stuff |
67 #define DM_DIR_SEPARATOR '/' | |
68 | |
0 | 69 |
70 // Resource management defines | |
71 #define DMRES_NAME_LEN 32 | |
72 #define DMRES_DATA_PACK "data.pak" // Name of the data-file | |
601
588998ccc07a
Change resource directory path DATA/ -> data/
Matti Hamalainen <ccr@tnsp.org>
parents:
569
diff
changeset
|
73 #define DMRES_DATA_PATH "data/" // Sub-directory path |
0 | 74 #define DMRES_RES_FILE "res.txt" // Resource data file |
75 | |
76 | |
77 /* Define a boolean type | |
78 */ | |
79 #if !defined(FALSE) && !defined(TRUE) && !defined(BOOL) | |
80 typedef enum { FALSE = 0, TRUE = 1 } BOOL; | |
81 #endif | |
82 | |
83 #ifndef BOOL | |
770 | 84 # ifdef bool |
85 # define BOOL bool | |
86 # else | |
87 # define BOOL int | |
88 # endif | |
0 | 89 #endif |
90 | |
91 | |
305
036fde2fd630
Add mathematical constants DM_PI, DM_PI2 and DM_E.
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
92 /* Math constants |
036fde2fd630
Add mathematical constants DM_PI, DM_PI2 and DM_E.
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
93 */ |
036fde2fd630
Add mathematical constants DM_PI, DM_PI2 and DM_E.
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
94 #define DM_PI 3.14159265358f |
036fde2fd630
Add mathematical constants DM_PI, DM_PI2 and DM_E.
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
95 #define DM_PI2 6.28318530718f |
036fde2fd630
Add mathematical constants DM_PI, DM_PI2 and DM_E.
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
96 #define DM_E 2.71828182846f |
036fde2fd630
Add mathematical constants DM_PI, DM_PI2 and DM_E.
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
97 |
036fde2fd630
Add mathematical constants DM_PI, DM_PI2 and DM_E.
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
98 |
0 | 99 /* Fixed point math type |
100 */ | |
101 typedef union | |
102 { | |
36
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
103 Sint64 dw; |
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
104 Sint32 w[2]; |
0 | 105 } DMFixedPoint; |
106 | |
107 | |
108 typedef union | |
109 { | |
36
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
110 Sint32 dw; |
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
111 Sint16 w[2]; |
0 | 112 } DMFixedPoint32; |
113 | |
114 | |
115 /* Macros for fixed point math | |
116 */ | |
117 #if __GNUC__ >= 3 | |
118 # define FP_SET(a, k) a.dw = k ## ULL | |
119 #else | |
120 # define FP_SET(a, k) a.dw = k | |
121 #endif | |
122 | |
138
459a1be2bd0f
A minor improvement to FP_CONV() fixed point macro.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
123 #define FP_CONV(a, k) a.dw = (k) |
0 | 124 |
125 #ifndef SDL_BYTEORDER | |
126 # error Undefined byteorder! | |
127 #endif | |
128 | |
129 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) | |
130 # define FP_SETH(a, k) a.w[0] = (k) | |
131 # define FP_SETL(a, k) a.w[1] = (k) | |
132 # define FP_SETHL(a, h, l) { a.w[0] = (h); a.w[1] = (l); } | |
809
eba3b87f3f84
Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents:
805
diff
changeset
|
133 # define FP_GETH32(a) a.w[0] |
eba3b87f3f84
Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents:
805
diff
changeset
|
134 # define FP_GETL32(a) a.w[1] |
eba3b87f3f84
Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents:
805
diff
changeset
|
135 # define FP_GETH16(a) a.w[0] |
eba3b87f3f84
Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents:
805
diff
changeset
|
136 # define FP_GETL16(a) a.w[1] |
0 | 137 #elif (SDL_BYTEORDER == SDL_LIL_ENDIAN) |
138 # define FP_SETH(a, k) a.w[1] = (k) | |
139 # define FP_SETL(a, k) a.w[0] = (k) | |
140 # define FP_SETHL(a, h, l) { a.w[1] = (h); a.w[0] = (l); } | |
809
eba3b87f3f84
Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents:
805
diff
changeset
|
141 # define FP_GETH32(a) a.w[1] |
eba3b87f3f84
Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents:
805
diff
changeset
|
142 # define FP_GETL32(a) a.w[0] |
eba3b87f3f84
Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents:
805
diff
changeset
|
143 # define FP_GETH16(a) a.w[1] |
eba3b87f3f84
Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents:
805
diff
changeset
|
144 # define FP_GETL16(a) a.w[0] |
0 | 145 #else |
146 # error Unsupported byte order! | |
147 #endif | |
148 | |
809
eba3b87f3f84
Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents:
805
diff
changeset
|
149 #define FP_PRINTF64(a) printf("%.8x:%.8x", FP_GETH32(a), FP_GETL32(a)) |
eba3b87f3f84
Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents:
805
diff
changeset
|
150 #define FP_PRINTF32(a) printf("%.4x:%.4x", FP_GETH16(a), FP_GETL16(a)) |
0 | 151 |
152 #define FP_ADD(a, b) a.dw += b.dw | |
153 #define FP_SUB(a, b) a.dw -= b.dw | |
154 #define FP_ADD_R(r, a, b) r.dw = a.dw + b.dw | |
155 #define FP_SUB_R(r, a, b) r.dw = a.dw - b.dw | |
156 #define FP_DIV(a, b) a.dw /= b.dw | |
157 #define FP_MUL(a, b) a.dw *= b.dw | |
158 #define FP_DIV_R(r, a, b) r.dw = (a.dw / b.dw) | |
159 #define FP_MUL_R(r, a, b) r.dw = (a.dw * b.dw) | |
160 | |
161 | |
162 /* Miscellaneous types | |
163 */ | |
164 typedef struct | |
165 { | |
166 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) | |
167 Uint8 a,g,b,r; | |
168 #elif (SDL_BYTEORDER == SDL_LIL_ENDIAN) | |
169 Uint8 r,g,b,a; | |
170 #endif | |
171 } DMRGBA32; | |
172 | |
173 | |
174 typedef float DMFloat; | |
175 | |
176 | |
118
c36e0316de9f
Move DM_SWAP() macro to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
177 // Macro for swapping two lvalues of same type |
c36e0316de9f
Move DM_SWAP() macro to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
178 #define DM_SWAP(T, A, B) { if ((B) < (A)) { T swtmp = (B); B = (A); A = swtmp; } } |
c36e0316de9f
Move DM_SWAP() macro to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
179 |
c36e0316de9f
Move DM_SWAP() macro to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
180 |
0 | 181 /* Drawing modes used by blitting and some other functions. |
182 */ | |
183 enum | |
184 { | |
185 DMD_NONE = 0x0000, | |
186 DMD_TRANSPARENT = 0x0001, | |
187 DMD_SATURATE = 0x0002, | |
188 | |
189 DMD_ANTIALIAS = 0x0004, | |
190 | |
191 DMD_NMODES = 6 | |
192 }; | |
193 | |
194 | |
195 // Available bitdepths. Not all functions may support every one of these. | |
196 enum | |
197 { | |
198 DMD_8BIT = 0, | |
199 DMD_32BIT, | |
200 | |
201 DMD_NBITDEPTHS | |
202 }; | |
203 | |
204 | |
205 static inline int dmBitsPerPixel2Index(int bpp) | |
206 { | |
207 return (bpp == 8 ? 0 : (bpp == 32 ? 1 : -1)); | |
208 } | |
209 | |
210 | |
211 /* Generic parameter interpolation | |
212 */ | |
213 #define DMM_S_CURVE(t) ((t) * (t) * (3.0f - 2.0f * (t))) | |
214 #define DMM_LERP(t, a, b) ((a) + (t) * ((b) - (a))) | |
215 | |
216 typedef struct | |
217 { | |
218 DMFloat start, end, nsteps; | |
219 } DMLerpContext; | |
220 | |
221 | |
222 void dmLerpInit(DMLerpContext *ctx, DMFloat start, DMFloat end, DMFloat nsteps); | |
108
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
223 DMFloat dmCatmullRom(const DMFloat t, const DMFloat p0, const DMFloat p1, const DMFloat p2, const DMFloat p3); |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
224 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
225 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
226 static inline DMFloat dmClamp10(const DMFloat a) |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
227 { |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
228 return (a < 0.0f ? 0.0f : (a > 1.0f ? 1.0f : a)); |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
229 } |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
230 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
231 |
153
0b2866e25bf1
Add dmClamp(value, min, max) for clamping integer values.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
232 static inline int dmClamp(const int v, const int min, const int max) |
0b2866e25bf1
Add dmClamp(value, min, max) for clamping integer values.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
233 { |
0b2866e25bf1
Add dmClamp(value, min, max) for clamping integer values.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
234 return (v < min ? min : (v > max ? max : v)); |
0b2866e25bf1
Add dmClamp(value, min, max) for clamping integer values.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
235 } |
0b2866e25bf1
Add dmClamp(value, min, max) for clamping integer values.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
236 |
0b2866e25bf1
Add dmClamp(value, min, max) for clamping integer values.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
237 |
108
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
238 static inline DMFloat dmLerpSCurve(DMLerpContext *ctx, const DMFloat step) |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
239 { |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
240 const DMFloat n = step / ctx->nsteps; |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
241 const DMFloat v = DMM_S_CURVE(n); |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
242 return DMM_LERP(v, ctx->start, ctx->end); |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
243 } |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
244 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
245 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
246 static inline DMFloat dmLerpSCurveClamp(DMLerpContext *ctx, const DMFloat step) |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
247 { |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
248 const DMFloat n = dmClamp10(step / ctx->nsteps); |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
249 const DMFloat v = DMM_S_CURVE(n); |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
250 return DMM_LERP(v, ctx->start, ctx->end); |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
251 } |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
252 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
253 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
254 static inline DMFloat dmLerp1(DMLerpContext *ctx, const DMFloat step) |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
255 { |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
256 const DMFloat v = step / ctx->nsteps; |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
257 return DMM_LERP(v, ctx->start, ctx->end); |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
258 } |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
259 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
260 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
261 static inline DMFloat dmLerp1Clamp(DMLerpContext *ctx, const DMFloat step) |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
262 { |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
263 const DMFloat v = dmClamp10(step / ctx->nsteps); |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
264 return DMM_LERP(v, ctx->start, ctx->end); |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
265 } |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
266 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
267 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
268 static inline DMFloat dmCatmullRomClamp(const DMFloat t, const DMFloat p0, const DMFloat p1, const DMFloat p2, const DMFloat p3) |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
269 { |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
270 return dmCatmullRom(dmClamp10(t), p0, p1, p2, p3); |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
271 } |
0 | 272 |
273 | |
274 /* Perlin noise | |
275 */ | |
276 void dmPerlinInit(void); | |
277 DMFloat dmPerlinNoise2D(DMFloat x, DMFloat y, DMFloat alpha, DMFloat beta, int n); | |
278 | |
279 | |
280 /* Arbitrary line drawing | |
281 */ | |
282 #ifdef DM_GFX_LINES | |
232
79dac918c81e
Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
283 #define DM_HEADER |
79dac918c81e
Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
284 #include "dmlinefunc.h" |
234
a2abd0b991b6
Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
285 |
262
9d015d32841a
Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
286 enum |
9d015d32841a
Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
287 { |
9d015d32841a
Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
288 CLIP_TOP = 1, |
9d015d32841a
Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
289 CLIP_BOTTOM = 2, |
9d015d32841a
Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
290 CLIP_RIGHT = 4, |
9d015d32841a
Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
291 CLIP_LEFT = 8 |
9d015d32841a
Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
292 }; |
9d015d32841a
Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
293 |
234
a2abd0b991b6
Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
294 #define DM_CLIP_FUNC dmClipLineCoordsFloat |
a2abd0b991b6
Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
295 #define DM_COORD_TYPE DMFloat |
a2abd0b991b6
Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
296 #include "dmlineclip.h" |
a2abd0b991b6
Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
297 |
232
79dac918c81e
Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
298 #undef DM_HEADER |
0 | 299 #endif |
300 | |
95
0430f484641b
Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
301 |
0430f484641b
Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
302 /* Various blitting functions |
0 | 303 */ |
304 #ifdef DM_GFX_BLITS | |
305 typedef int (*DMScaledBlitFunc)(SDL_Surface *src, const int x0, const int y0, const int dwidth, const int dheight, SDL_Surface *dst); | |
306 DMScaledBlitFunc dmGetScaledBlitFunc(SDL_PixelFormat *src, SDL_PixelFormat *dst, int mode); | |
307 int dmScaledBlitSurfaceAny(SDL_Surface *src, const int x0, const int y0, const int dwidth, const int dheight, SDL_Surface *dst, int mode); | |
19
10f58ff516b3
Add function prototypes for two special case scaled blit functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
308 |
95
0430f484641b
Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
309 typedef int (*DMUnscaledBlitFunc)(SDL_Surface *src, const int x0, const int y0, SDL_Surface *dst); |
0430f484641b
Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
310 DMUnscaledBlitFunc dmGetUnscaledBlitFunc(SDL_PixelFormat *src, SDL_PixelFormat *dst, int mode); |
0430f484641b
Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
311 int dmUnscaledBlitSurfaceAny(SDL_Surface *src, const int x0, const int y0, SDL_Surface *dst, int mode); |
232
79dac918c81e
Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
312 |
610
e74ad60b1e85
Add new scaled surface conversion function.
Matti Hamalainen <ccr@tnsp.org>
parents:
601
diff
changeset
|
313 SDL_Surface *dmConvertScaledSurface(SDL_Surface *src, SDL_PixelFormat *fmt, Uint32 flags, const int dwidth, const int dheight); |
e74ad60b1e85
Add new scaled surface conversion function.
Matti Hamalainen <ccr@tnsp.org>
parents:
601
diff
changeset
|
314 |
e74ad60b1e85
Add new scaled surface conversion function.
Matti Hamalainen <ccr@tnsp.org>
parents:
601
diff
changeset
|
315 |
232
79dac918c81e
Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
316 #define DM_HEADER |
79dac918c81e
Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
317 #include "dmblitfunc.h" |
79dac918c81e
Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
318 #undef DM_HEADER |
612
696f03f30c0e
Make certain static inline graphics functions always available, no need to
Matti Hamalainen <ccr@tnsp.org>
parents:
611
diff
changeset
|
319 |
696f03f30c0e
Make certain static inline graphics functions always available, no need to
Matti Hamalainen <ccr@tnsp.org>
parents:
611
diff
changeset
|
320 #endif // DM_GFX_BLITS |
0 | 321 |
95
0430f484641b
Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
322 |
0 | 323 /* Misc functions |
324 */ | |
325 #ifdef DM_GFX_MISC | |
612
696f03f30c0e
Make certain static inline graphics functions always available, no need to
Matti Hamalainen <ccr@tnsp.org>
parents:
611
diff
changeset
|
326 |
0 | 327 void dmFillRect(SDL_Surface *screen, int x0, int y0, int x1, int y1, const Uint32 col); |
328 void dmDrawHLine(SDL_Surface *screen, int x0, int x1, int yc, const Uint32 col); | |
329 void dmDrawVLine(SDL_Surface *screen, int y0, int y1, int xc, const Uint32 col); | |
150
e147c07e41cb
Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
330 |
e147c07e41cb
Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
331 void dmDrawBox3D(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 ucol, Uint32 dcol); |
e147c07e41cb
Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
332 void dmFillBox3D(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 bgcol, Uint32 ucol, Uint32 dcol); |
e147c07e41cb
Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
333 |
612
696f03f30c0e
Make certain static inline graphics functions always available, no need to
Matti Hamalainen <ccr@tnsp.org>
parents:
611
diff
changeset
|
334 #endif // DM_GFX_MISC |
696f03f30c0e
Make certain static inline graphics functions always available, no need to
Matti Hamalainen <ccr@tnsp.org>
parents:
611
diff
changeset
|
335 |
90
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
336 |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
337 static inline void dmClearSurface(SDL_Surface *screen, const Uint32 col) |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
338 { |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
339 SDL_FillRect(screen, NULL, col); |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
340 } |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
341 |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
342 |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
343 static inline Uint32 dmMapRGB(SDL_Surface *screen, int r, int g, int b) |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
344 { |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
345 return SDL_MapRGB(screen->format, r, g, b); |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
346 } |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
347 |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
348 |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
349 static inline Uint32 dmMapRGBA(SDL_Surface *screen, int r, int g, int b, int a) |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
350 { |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
351 return SDL_MapRGBA(screen->format, r, g, b, a); |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
352 } |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
353 |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
354 |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
355 static inline int dmDirectBlitSurface(SDL_Surface *bmp, SDL_Surface *screen) |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
356 { |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
357 return SDL_BlitSurface(bmp, NULL, screen, NULL); |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
358 } |
0 | 359 |
360 | |
611
828d86cd10e0
Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
610
diff
changeset
|
361 static inline SDL_Surface *dmCopySurface(SDL_Surface *src) |
828d86cd10e0
Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
610
diff
changeset
|
362 { |
828d86cd10e0
Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
610
diff
changeset
|
363 if (src != NULL) |
828d86cd10e0
Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
610
diff
changeset
|
364 return SDL_ConvertSurface(src, src->format, src->flags); |
828d86cd10e0
Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
610
diff
changeset
|
365 else |
828d86cd10e0
Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
610
diff
changeset
|
366 return NULL; |
828d86cd10e0
Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
610
diff
changeset
|
367 } |
828d86cd10e0
Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
610
diff
changeset
|
368 |
828d86cd10e0
Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
610
diff
changeset
|
369 |
0 | 370 /* Global variables |
371 */ | |
372 extern char *dmProgName, | |
373 *dmProgDesc, | |
374 *dmProgVersion, | |
375 *dmProgAuthor, | |
376 *dmProgLicense; | |
377 | |
378 extern int dmVerbosity; | |
379 void dmInitProg(char *name, char *desc, char *version, char *author, char *license); | |
380 void dmPrintBanner(FILE *outFile, const char *name, const char *usage); | |
381 | |
382 void dmMsgVA(int level, const char *fmt, va_list ap); | |
383 void dmMsg(int level, const char *fmt, ...); | |
384 void dmPrintVA(int level, const char *fmt, va_list ap); | |
385 void dmPrint(int level, const char *fmt, ...); | |
386 void dmErrorVA(const char *fmt, va_list); | |
387 void dmError(const char *fmt, ...); | |
388 | |
389 void * dmMalloc(size_t); | |
390 void * dmMalloc0(size_t); | |
391 void * dmRealloc(void *, size_t); | |
392 void * dmCalloc(size_t, size_t); | |
393 void dmFree(void *); | |
394 | |
395 BOOL dmGetIntVal(const char *s, int *i); | |
396 | |
397 int dmGetErrno(); | |
398 const char *dmErrorStr(int error); | |
399 | |
400 char * dm_strdup(const char *); | |
744
2726d91e3409
Add implementation of dm_strndup().
Matti Hamalainen <ccr@tnsp.org>
parents:
612
diff
changeset
|
401 char * dm_strndup(const char *, const size_t n); |
0 | 402 char * dm_strdup_vprintf(const char *, va_list); |
403 char * dm_strdup_printf(const char *, ...); | |
404 | |
813 | 405 char * dm_basefilename(const char *filename); |
406 char * dm_strdup_fext(const char *filename, const char *fmt); | |
407 | |
0 | 408 |
294
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
409 /* Mutexes |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
410 */ |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
411 #ifdef DM_MUTEX_DEBUG |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
412 |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
413 typedef struct |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
414 { |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
415 BOOL used; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
416 Uint32 id; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
417 int state; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
418 } DMMutexLock; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
419 |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
420 typedef struct |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
421 { |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
422 char *cr_file; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
423 int cr_line; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
424 SDL_mutex *m; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
425 DMMutexLock locks[8]; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
426 } DMMutex; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
427 |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
428 #define dmMutexLock(x) dmDOMutexLock(x, __FILE__, (int) __LINE__) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
429 #define dmMutexUnlock(x) dmDOMutexUnlock(x, __FILE__, (int) __LINE__) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
430 #define dmCreateMutex(x) dmDOCreateMutex(__FILE__, (int) __LINE__) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
431 |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
432 int dmDOMutexLock(DMMutex *mutex, const char *file, const int line); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
433 int dmDOMutexUnlock(DMMutex *mutex, const char *file, const int line); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
434 DMMutex * dmDOCreateMutex(const char *file, const int line); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
435 void dmDestroyMutex(DMMutex *mutex); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
436 |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
437 #else |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
438 #define DMMutex SDL_mutex |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
439 #define dmCreateMutex() SDL_CreateMutex() |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
440 #define dmDestroyMutex(x) SDL_DestroyMutex(x) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
441 #define dmMutexLock(x) SDL_mutexP(x) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
442 #define dmMutexUnlock(x) SDL_mutexV(x) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
443 #endif |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
444 |
0 | 445 /* Endianess swapping macros |
446 */ | |
447 #define DM_SWAP_16_LE_BE(value) ((Uint16) ( \ | |
448 (Uint16) ((Uint16) (value) >> 8) | \ | |
449 (Uint16) ((Uint16) (value) << 8)) ) | |
450 | |
451 | |
452 #define DM_SWAP_32_LE_BE(value) ((Uint32) ( \ | |
453 (((Uint32) (value) & (Uint32) 0x000000ffU) << 24) | \ | |
454 (((Uint32) (value) & (Uint32) 0x0000ff00U) << 8) | \ | |
455 (((Uint32) (value) & (Uint32) 0x00ff0000U) >> 8) | \ | |
456 (((Uint32) (value) & (Uint32) 0xff000000U) >> 24))) | |
457 | |
458 #ifdef DM_HAVE_64BIT | |
459 #define DM_SWAP_64_LE_BE(value) ((Uint64) ( \ | |
460 (((Uint64) (value) & (Uint64) 0x00000000000000ffULL) << 56) | \ | |
461 (((Uint64) (value) & (Uint64) 0x000000000000ff00ULL) << 40) | \ | |
462 (((Uint64) (value) & (Uint64) 0x0000000000ff0000ULL) << 24) | \ | |
463 (((Uint64) (value) & (Uint64) 0x00000000ff000000ULL) << 8) | \ | |
464 (((Uint64) (value) & (Uint64) 0x000000ff00000000ULL) >> 8) | \ | |
465 (((Uint64) (value) & (Uint64) 0x0000ff0000000000ULL) >> 24) | \ | |
466 (((Uint64) (value) & (Uint64) 0x00ff000000000000ULL) >> 40) | \ | |
467 (((Uint64) (value) & (Uint64) 0xff00000000000000ULL) >> 56))) | |
468 #endif | |
469 | |
470 /* Macros that swap only when needed ... | |
471 */ | |
472 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) | |
770 | 473 # define DM_LE16_TO_NATIVE(value) DM_SWAP_16_LE_BE(value) |
474 # define DM_LE32_TO_NATIVE(value) DM_SWAP_32_LE_BE(value) | |
475 # define DM_NATIVE_TO_LE16(value) DM_SWAP_16_LE_BE(value) | |
476 # define DM_NATIVE_TO_LE32(value) DM_SWAP_32_LE_BE(value) | |
0 | 477 |
770 | 478 # define DM_BE16_TO_NATIVE(value) ((Uint16) (value)) |
479 # define DM_BE32_TO_NATIVE(value) ((Uint32) (value)) | |
480 # define DM_NATIVE_TO_BE16(value) ((Uint16) (value)) | |
481 # define DM_NATIVE_TO_BE32(value) ((Uint32) (value)) | |
0 | 482 |
770 | 483 # ifdef DM_HAVE_64BIT |
484 # define DM_LE64_TO_NATIVE(value) DM_SWAP_64_LE_BE(value) | |
485 # define DM_NATIVE_TO_LE64(value) DM_SWAP_64_LE_BE(value) | |
486 # define DM_BE64_TO_NATIVE(value) ((Uint64) (value)) | |
487 # define DM_NATIVE_TO_BE64(value) ((Uint64) (value)) | |
488 # endif | |
0 | 489 |
490 #elif (SDL_BYTEORDER == SDL_LIL_ENDIAN) | |
491 | |
770 | 492 # define DM_LE16_TO_NATIVE(value) ((Uint16) (value)) |
493 # define DM_LE32_TO_NATIVE(value) ((Uint32) (value)) | |
494 # define DM_NATIVE_TO_LE16(value) ((Uint16) (value)) | |
495 # define DM_NATIVE_TO_LE32(value) ((Uint32) (value)) | |
0 | 496 |
770 | 497 # define DM_BE16_TO_NATIVE(value) DM_SWAP_16_LE_BE(value) |
498 # define DM_BE32_TO_NATIVE(value) DM_SWAP_32_LE_BE(value) | |
499 # define DM_NATIVE_TO_BE16(value) DM_SWAP_16_LE_BE(value) | |
500 # define DM_NATIVE_TO_BE32(value) DM_SWAP_32_LE_BE(value) | |
0 | 501 |
770 | 502 # ifdef DM_HAVE_64BIT |
503 # define DM_LE64_TO_NATIVE(value) ((Uint64) (value)) | |
504 # define DM_NATIVE_TO_LE64(value) ((Uint64) (value)) | |
505 # define DM_BE64_TO_NATIVE(value) DM_SWAP_64_LE_BE(value) | |
506 # define DM_NATIVE_TO_BE64(value) DM_SWAP_64_LE_BE(value) | |
507 # endif | |
0 | 508 #endif |
509 | |
510 | |
511 #ifdef __cplusplus | |
512 } | |
513 #endif | |
359
59045853853d
Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents:
341
diff
changeset
|
514 |
0 | 515 #endif // DMLIB_H |