Mercurial > hg > dmlib
annotate dmlib.h @ 288:e2f286781180
Use more glanular header includes from SDL, enables us to succesfully link
binaries without the SDL dependancy (where it is not actually needed) under
Windows.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 11 Oct 2012 11:10:30 +0300 |
parents | 51ba74f7668c |
children | dd9809a93425 |
rev | line source |
---|---|
0 | 1 /* |
2 * DMLib | |
3 * -- Main header file | |
4 * Programmed and designed by Matti 'ccr' Hamalainen | |
5 * (C) Copyright 2011 Tecnic Software productions (TNSP) | |
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> |
e2f286781180
Use more glanular header includes from SDL, enables us to succesfully link
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
14 #include <SDL_video.h> |
0 | 15 #include <stdarg.h> |
16 | |
17 #ifdef DM_USE_ASSERTS | |
18 #include <assert.h> | |
19 #else | |
20 #define assert(NEXPR) // stub | |
21 #endif | |
22 | |
23 #ifdef __cplusplus | |
24 extern "C" { | |
25 #endif | |
26 | |
27 // Defaults | |
28 //#define DM_PROG_AUTHOR "By Matti 'ccr' Hmlinen (C) Copyright 2012 TNSP" | |
29 //#define DM_PROG_LICENSE "This software is licensed under GNU GPL version 2" | |
30 | |
31 #define DM_PROG_AUTHOR "" | |
32 #define DM_PROG_LICENSE "" | |
33 | |
34 /* Error codes | |
35 */ | |
36 enum { | |
37 // General error codes | |
38 DMERR_OK = 0, | |
26
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
39 DMERR_PROGRESS, // Status OK, but operation in progress |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
40 |
0 | 41 DMERR_FOPEN, |
42 DMERR_FREAD, | |
43 DMERR_FWRITE, | |
44 DMERR_FSEEK, | |
26
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
45 DMERR_NOT_FOUND, // Resource/data not found |
0 | 46 |
26
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
47 DMERR_INVALID_DATA, // Some data was invalid |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
48 DMERR_MALLOC, // Memory allocation failure |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
49 DMERR_ALREADY_INIT, // Resource has already been initialized |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
50 DMERR_INIT_FAIL, // General initialization failure |
0 | 51 DMERR_INVALID_ARGS, |
52 | |
26
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
53 DMERR_NULLPTR, // NULL pointer specified in critical argument |
2f463a59d732
Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
54 DMERR_NOT_SUPPORTED,// Operation not supported |
0 | 55 DMERR_OUT_OF_DATA, |
56 DMERR_EXTRA_DATA, | |
57 DMERR_BOUNDS, | |
58 | |
59 // PACK-file subsystem | |
60 DMERR_NOTPACK, | |
61 DMERR_VERSION, | |
62 DMERR_INVALID, | |
63 DMERR_COMPRESSION, | |
64 }; | |
65 | |
66 | |
67 // Resource management defines | |
68 #define DMRES_NAME_LEN 32 | |
69 #define DMRES_DATA_PACK "data.pak" // Name of the data-file | |
70 #define DMRES_DATA_PATH "DATA/" // Sub-directory path | |
71 #define DMRES_RES_FILE "res.txt" // Resource data file | |
72 | |
73 | |
74 // Mutexes | |
75 #define DMMutex SDL_mutex | |
76 #define dmCreateMutex() SDL_CreateMutex() | |
77 #define dmDestroyMutex(x) SDL_DestroyMutex(x) | |
78 #define dmMutexLock(x) SDL_mutexP(x) | |
79 #define dmMutexUnlock(x) SDL_mutexV(x) | |
80 | |
81 | |
82 /* Define a boolean type | |
83 */ | |
84 #if !defined(FALSE) && !defined(TRUE) && !defined(BOOL) | |
85 typedef enum { FALSE = 0, TRUE = 1 } BOOL; | |
86 #endif | |
87 | |
88 #ifndef BOOL | |
89 #ifdef bool | |
90 #define BOOL bool | |
91 #else | |
92 #define BOOL int | |
93 #endif | |
94 #endif | |
95 | |
96 | |
97 /* Fixed point math type | |
98 */ | |
99 typedef union | |
100 { | |
36
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
101 Sint64 dw; |
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
102 Sint32 w[2]; |
0 | 103 } DMFixedPoint; |
104 | |
105 | |
106 typedef union | |
107 { | |
36
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
108 Sint32 dw; |
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
109 Sint16 w[2]; |
0 | 110 } DMFixedPoint32; |
111 | |
112 | |
113 /* Macros for fixed point math | |
114 */ | |
115 #if __GNUC__ >= 3 | |
116 # define FP_SET(a, k) a.dw = k ## ULL | |
117 #else | |
118 # define FP_SET(a, k) a.dw = k | |
119 #endif | |
120 | |
138
459a1be2bd0f
A minor improvement to FP_CONV() fixed point macro.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
121 #define FP_CONV(a, k) a.dw = (k) |
0 | 122 |
123 #ifndef SDL_BYTEORDER | |
124 # error Undefined byteorder! | |
125 #endif | |
126 | |
127 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) | |
128 # define FP_SETH(a, k) a.w[0] = (k) | |
129 # define FP_SETL(a, k) a.w[1] = (k) | |
130 # define FP_SETHL(a, h, l) { a.w[0] = (h); a.w[1] = (l); } | |
131 # define FP_GETH(a) a.w[0] | |
132 # define FP_GETL(a) a.w[1] | |
133 #elif (SDL_BYTEORDER == SDL_LIL_ENDIAN) | |
134 # define FP_SETH(a, k) a.w[1] = (k) | |
135 # define FP_SETL(a, k) a.w[0] = (k) | |
136 # define FP_SETHL(a, h, l) { a.w[1] = (h); a.w[0] = (l); } | |
137 # define FP_GETH(a) a.w[1] | |
138 # define FP_GETL(a) a.w[0] | |
139 #else | |
140 # error Unsupported byte order! | |
141 #endif | |
142 | |
143 #define FP_PRINTF(a) printf("%.8x:%.8x", FP_GETH(a), FP_GETL(a)) | |
144 #define FP_PRINTF32(a) printf("%.4x:%.4x", FP_GETH(a), FP_GETL(a)) | |
145 | |
146 #define FP_ADD(a, b) a.dw += b.dw | |
147 #define FP_SUB(a, b) a.dw -= b.dw | |
148 #define FP_ADD_R(r, a, b) r.dw = a.dw + b.dw | |
149 #define FP_SUB_R(r, a, b) r.dw = a.dw - b.dw | |
150 #define FP_DIV(a, b) a.dw /= b.dw | |
151 #define FP_MUL(a, b) a.dw *= b.dw | |
152 #define FP_DIV_R(r, a, b) r.dw = (a.dw / b.dw) | |
153 #define FP_MUL_R(r, a, b) r.dw = (a.dw * b.dw) | |
154 | |
155 | |
156 /* Miscellaneous types | |
157 */ | |
158 typedef struct | |
159 { | |
160 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) | |
161 Uint8 a,g,b,r; | |
162 #elif (SDL_BYTEORDER == SDL_LIL_ENDIAN) | |
163 Uint8 r,g,b,a; | |
164 #endif | |
165 } DMRGBA32; | |
166 | |
167 | |
168 typedef float DMFloat; | |
169 | |
170 | |
118
c36e0316de9f
Move DM_SWAP() macro to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
171 // 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
|
172 #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
|
173 |
c36e0316de9f
Move DM_SWAP() macro to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
174 |
0 | 175 /* Drawing modes used by blitting and some other functions. |
176 */ | |
177 enum | |
178 { | |
179 DMD_NONE = 0x0000, | |
180 DMD_TRANSPARENT = 0x0001, | |
181 DMD_SATURATE = 0x0002, | |
182 | |
183 DMD_ANTIALIAS = 0x0004, | |
184 | |
185 DMD_NMODES = 6 | |
186 }; | |
187 | |
188 | |
189 // Available bitdepths. Not all functions may support every one of these. | |
190 enum | |
191 { | |
192 DMD_8BIT = 0, | |
193 DMD_32BIT, | |
194 | |
195 DMD_NBITDEPTHS | |
196 }; | |
197 | |
198 | |
199 static inline int dmBitsPerPixel2Index(int bpp) | |
200 { | |
201 return (bpp == 8 ? 0 : (bpp == 32 ? 1 : -1)); | |
202 } | |
203 | |
204 | |
205 /* Generic parameter interpolation | |
206 */ | |
207 #define DMM_S_CURVE(t) ((t) * (t) * (3.0f - 2.0f * (t))) | |
208 #define DMM_LERP(t, a, b) ((a) + (t) * ((b) - (a))) | |
209 | |
210 typedef struct | |
211 { | |
212 DMFloat start, end, nsteps; | |
213 } DMLerpContext; | |
214 | |
215 | |
216 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
|
217 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
|
218 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
219 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
220 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
|
221 { |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
222 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
|
223 } |
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 |
153
0b2866e25bf1
Add dmClamp(value, min, max) for clamping integer values.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
226 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
|
227 { |
0b2866e25bf1
Add dmClamp(value, min, max) for clamping integer values.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
228 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
|
229 } |
0b2866e25bf1
Add dmClamp(value, min, max) for clamping integer values.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
230 |
0b2866e25bf1
Add dmClamp(value, min, max) for clamping integer values.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
231 |
108
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
232 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
|
233 { |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
234 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
|
235 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
|
236 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
|
237 } |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
238 |
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 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
|
241 { |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 } |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
246 |
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 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
|
249 { |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
250 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
|
251 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
|
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 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
255 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
|
256 { |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
257 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
|
258 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
|
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 |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
262 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
|
263 { |
72813cece1ba
Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
264 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
|
265 } |
0 | 266 |
267 | |
268 /* Perlin noise | |
269 */ | |
270 void dmPerlinInit(void); | |
271 DMFloat dmPerlinNoise2D(DMFloat x, DMFloat y, DMFloat alpha, DMFloat beta, int n); | |
272 | |
273 | |
274 /* Arbitrary line drawing | |
275 */ | |
276 #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
|
277 #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
|
278 #include "dmlinefunc.h" |
234
a2abd0b991b6
Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
279 |
262
9d015d32841a
Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
280 enum |
9d015d32841a
Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
281 { |
9d015d32841a
Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
282 CLIP_TOP = 1, |
9d015d32841a
Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
283 CLIP_BOTTOM = 2, |
9d015d32841a
Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
284 CLIP_RIGHT = 4, |
9d015d32841a
Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
285 CLIP_LEFT = 8 |
9d015d32841a
Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
286 }; |
9d015d32841a
Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
287 |
234
a2abd0b991b6
Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
288 #define DM_CLIP_FUNC dmClipLineCoordsFloat |
a2abd0b991b6
Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
289 #define DM_COORD_TYPE DMFloat |
a2abd0b991b6
Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
290 #include "dmlineclip.h" |
a2abd0b991b6
Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
291 |
232
79dac918c81e
Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
292 #undef DM_HEADER |
0 | 293 #endif |
294 | |
95
0430f484641b
Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
295 |
0430f484641b
Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
296 /* Various blitting functions |
0 | 297 */ |
298 #ifdef DM_GFX_BLITS | |
299 typedef int (*DMScaledBlitFunc)(SDL_Surface *src, const int x0, const int y0, const int dwidth, const int dheight, SDL_Surface *dst); | |
300 DMScaledBlitFunc dmGetScaledBlitFunc(SDL_PixelFormat *src, SDL_PixelFormat *dst, int mode); | |
301 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
|
302 |
95
0430f484641b
Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
303 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
|
304 DMUnscaledBlitFunc dmGetUnscaledBlitFunc(SDL_PixelFormat *src, SDL_PixelFormat *dst, int mode); |
0430f484641b
Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
305 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
|
306 |
79dac918c81e
Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
307 #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
|
308 #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
|
309 #undef DM_HEADER |
0 | 310 #endif |
311 | |
95
0430f484641b
Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
312 |
0 | 313 /* Misc functions |
314 */ | |
315 #ifdef DM_GFX_MISC | |
316 void dmFillRect(SDL_Surface *screen, int x0, int y0, int x1, int y1, const Uint32 col); | |
317 void dmDrawHLine(SDL_Surface *screen, int x0, int x1, int yc, const Uint32 col); | |
318 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
|
319 |
e147c07e41cb
Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
320 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
|
321 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
|
322 |
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
|
323 |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
324 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
|
325 { |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
326 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
|
327 } |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
328 |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
329 |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
330 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
|
331 { |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
332 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
|
333 } |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
334 |
1ab3fd8b9afc
Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
335 |
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 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
|
337 { |
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 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
|
339 } |
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 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
|
343 { |
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 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
|
345 } |
0 | 346 #endif |
347 | |
348 | |
349 /* Global variables | |
350 */ | |
351 extern char *dmProgName, | |
352 *dmProgDesc, | |
353 *dmProgVersion, | |
354 *dmProgAuthor, | |
355 *dmProgLicense; | |
356 | |
357 extern int dmVerbosity; | |
358 void dmInitProg(char *name, char *desc, char *version, char *author, char *license); | |
359 void dmPrintBanner(FILE *outFile, const char *name, const char *usage); | |
360 | |
361 void dmMsgVA(int level, const char *fmt, va_list ap); | |
362 void dmMsg(int level, const char *fmt, ...); | |
363 void dmPrintVA(int level, const char *fmt, va_list ap); | |
364 void dmPrint(int level, const char *fmt, ...); | |
365 void dmErrorVA(const char *fmt, va_list); | |
366 void dmError(const char *fmt, ...); | |
367 | |
368 void * dmMalloc(size_t); | |
369 void * dmMalloc0(size_t); | |
370 void * dmRealloc(void *, size_t); | |
371 void * dmCalloc(size_t, size_t); | |
372 void dmFree(void *); | |
373 | |
374 BOOL dmGetIntVal(const char *s, int *i); | |
375 | |
376 int dmGetErrno(); | |
377 const char *dmErrorStr(int error); | |
378 | |
379 char * dm_strdup(const char *); | |
380 char * dm_strdup_vprintf(const char *, va_list); | |
381 char * dm_strdup_printf(const char *, ...); | |
382 | |
383 | |
384 /* Endianess swapping macros | |
385 */ | |
386 #define DM_SWAP_16_LE_BE(value) ((Uint16) ( \ | |
387 (Uint16) ((Uint16) (value) >> 8) | \ | |
388 (Uint16) ((Uint16) (value) << 8)) ) | |
389 | |
390 | |
391 #define DM_SWAP_32_LE_BE(value) ((Uint32) ( \ | |
392 (((Uint32) (value) & (Uint32) 0x000000ffU) << 24) | \ | |
393 (((Uint32) (value) & (Uint32) 0x0000ff00U) << 8) | \ | |
394 (((Uint32) (value) & (Uint32) 0x00ff0000U) >> 8) | \ | |
395 (((Uint32) (value) & (Uint32) 0xff000000U) >> 24))) | |
396 | |
397 #ifdef DM_HAVE_64BIT | |
398 #define DM_SWAP_64_LE_BE(value) ((Uint64) ( \ | |
399 (((Uint64) (value) & (Uint64) 0x00000000000000ffULL) << 56) | \ | |
400 (((Uint64) (value) & (Uint64) 0x000000000000ff00ULL) << 40) | \ | |
401 (((Uint64) (value) & (Uint64) 0x0000000000ff0000ULL) << 24) | \ | |
402 (((Uint64) (value) & (Uint64) 0x00000000ff000000ULL) << 8) | \ | |
403 (((Uint64) (value) & (Uint64) 0x000000ff00000000ULL) >> 8) | \ | |
404 (((Uint64) (value) & (Uint64) 0x0000ff0000000000ULL) >> 24) | \ | |
405 (((Uint64) (value) & (Uint64) 0x00ff000000000000ULL) >> 40) | \ | |
406 (((Uint64) (value) & (Uint64) 0xff00000000000000ULL) >> 56))) | |
407 #endif | |
408 | |
409 /* Macros that swap only when needed ... | |
410 */ | |
411 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) | |
412 # define DM_LE16_TO_NATIVE(value) DM_SWAP_16_LE_BE(value) | |
413 # define DM_LE32_TO_NATIVE(value) DM_SWAP_32_LE_BE(value) | |
414 # define DM_NATIVE_TO_LE16(value) DM_SWAP_16_LE_BE(value) | |
415 # define DM_NATIVE_TO_LE32(value) DM_SWAP_32_LE_BE(value) | |
416 | |
417 # define DM_BE16_TO_NATIVE(value) ((Uint16) (value)) | |
418 # define DM_BE32_TO_NATIVE(value) ((Uint32) (value)) | |
419 # define DM_NATIVE_TO_BE16(value) ((Uint16) (value)) | |
420 # define DM_NATIVE_TO_BE32(value) ((Uint32) (value)) | |
421 | |
422 # ifdef DM_HAVE_64BIT | |
423 # define DM_LE64_TO_NATIVE(value) DM_SWAP_64_LE_BE(value) | |
424 # define DM_NATIVE_TO_LE64(value) DM_SWAP_64_LE_BE(value) | |
425 # define DM_BE64_TO_NATIVE(value) ((Uint64) (value)) | |
426 # define DM_NATIVE_TO_BE64(value) ((Uint64) (value)) | |
427 # endif | |
428 | |
429 #elif (SDL_BYTEORDER == SDL_LIL_ENDIAN) | |
430 | |
431 # define DM_LE16_TO_NATIVE(value) ((Uint16) (value)) | |
432 # define DM_LE32_TO_NATIVE(value) ((Uint32) (value)) | |
433 # define DM_NATIVE_TO_LE16(value) ((Uint16) (value)) | |
434 # define DM_NATIVE_TO_LE32(value) ((Uint32) (value)) | |
435 | |
436 # define DM_BE16_TO_NATIVE(value) DM_SWAP_16_LE_BE(value) | |
437 # define DM_BE32_TO_NATIVE(value) DM_SWAP_32_LE_BE(value) | |
438 # define DM_NATIVE_TO_BE16(value) DM_SWAP_16_LE_BE(value) | |
439 # define DM_NATIVE_TO_BE32(value) DM_SWAP_32_LE_BE(value) | |
440 | |
441 # ifdef DM_HAVE_64BIT | |
442 # define DM_LE64_TO_NATIVE(value) ((Uint64) (value)) | |
443 # define DM_NATIVE_TO_LE64(value) ((Uint64) (value)) | |
444 # define DM_BE64_TO_NATIVE(value) DM_SWAP_64_LE_BE(value) | |
445 # define DM_NATIVE_TO_BE64(value) DM_SWAP_64_LE_BE(value) | |
446 # endif | |
447 #endif | |
448 | |
449 | |
450 #ifdef __cplusplus | |
451 } | |
452 #endif | |
453 #endif // DMLIB_H |