… | |
… | |
15 | |
15 | |
16 | #include "EXTERN.h" |
16 | #include "EXTERN.h" |
17 | #include "perl.h" |
17 | #include "perl.h" |
18 | #include "XSUB.h" |
18 | #include "XSUB.h" |
19 | |
19 | |
|
|
20 | #include "flat_hash_map.hpp" |
|
|
21 | |
20 | #ifdef _WIN32 |
22 | #ifdef _WIN32 |
21 | # undef pipe |
23 | # undef pipe |
22 | // microsoft vs. C |
24 | // microsoft vs. C |
23 | # define sqrtf(x) sqrt(x) |
25 | # define sqrtf(x) sqrt(x) |
24 | # define atan2f(x,y) atan2(x,y) |
26 | # define atan2f(x,y) atan2(x,y) |
25 | # define M_PI 3.14159265f |
27 | # define M_PI 3.14159265f |
26 | #endif |
28 | #endif |
27 | |
29 | |
28 | #include <assert.h> |
30 | #include <cassert> |
29 | #include <math.h> |
31 | #include <cmath> |
30 | #include <string.h> |
32 | #include <cstring> |
31 | #include <stdio.h> |
33 | #include <cstdio> |
32 | #include <stdlib.h> |
34 | #include <cstdlib> |
|
|
35 | |
|
|
36 | #include <utility> |
|
|
37 | #include <bitset> |
33 | |
38 | |
34 | #define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW |
39 | #define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW |
35 | |
40 | |
36 | #include <SDL.h> |
41 | #include <SDL.h> |
37 | #include <SDL_thread.h> |
42 | #include <SDL_thread.h> |
… | |
… | |
195 | } |
200 | } |
196 | |
201 | |
197 | return 0; |
202 | return 0; |
198 | } |
203 | } |
199 | |
204 | |
200 | typedef struct cf_layout { |
205 | struct cf_layout { |
201 | PangoLayout *pl; |
206 | PangoLayout *pl; |
202 | float r, g, b, a; // default color for rgba mode |
207 | float r, g, b, a; // default color for rgba mode |
203 | int base_height; |
208 | int base_height; |
204 | DC__Font font; |
209 | DC__Font font; |
205 | rc_t *rc; |
210 | rc_t *rc; |
206 | } *DC__Layout; |
211 | }; |
|
|
212 | |
|
|
213 | typedef cf_layout *DC__Layout; |
207 | |
214 | |
208 | static DC__Font default_font; |
215 | static DC__Font default_font; |
209 | static PangoContext *opengl_context; |
216 | static PangoContext *opengl_context; |
210 | static PangoFontMap *opengl_fontmap; |
217 | static PangoFontMap *opengl_fontmap; |
211 | |
218 | |
… | |
… | |
252 | } |
259 | } |
253 | |
260 | |
254 | typedef uint16_t tileid; |
261 | typedef uint16_t tileid; |
255 | typedef uint16_t faceid; |
262 | typedef uint16_t faceid; |
256 | |
263 | |
257 | typedef struct { |
264 | struct maptex |
|
|
265 | { |
258 | GLuint name; |
266 | GLuint name; |
259 | int w, h; |
267 | int w, h; |
260 | float s, t; |
268 | float s, t; |
261 | uint8_t r, g, b, a; |
269 | uint8_t r, g, b, a; |
262 | tileid smoothtile; |
270 | tileid smoothtile; |
263 | uint8_t smoothlevel; |
271 | uint8_t smoothlevel; |
264 | uint8_t unused; /* set to zero on use */ |
272 | uint8_t unused; /* set to zero on use */ |
265 | } maptex; |
273 | }; |
266 | |
274 | |
267 | typedef struct { |
275 | struct mapcell |
|
|
276 | { |
268 | uint32_t player; |
277 | uint32_t player; |
269 | tileid tile[3]; |
278 | tileid tile[3]; |
270 | uint16_t darkness; |
279 | uint16_t darkness; |
271 | uint8_t stat_width, stat_hp, flags, smoothmax; |
280 | uint8_t stat_width, stat_hp, flags, smoothmax; |
272 | } mapcell; |
281 | }; |
273 | |
282 | |
274 | typedef struct { |
283 | struct maprow |
|
|
284 | { |
275 | int32_t c0, c1; |
285 | int32_t c0, c1; |
276 | mapcell *col; |
286 | mapcell *col; |
277 | } maprow; |
287 | }; |
278 | |
288 | |
279 | typedef struct map { |
289 | struct mapgrid { |
280 | int x, y, w, h; |
290 | int x, y, w, h; |
281 | int ox, oy; /* offset to virtual global coordinate system */ |
291 | int ox, oy; /* offset to virtual global coordinate system */ |
282 | int faces; tileid *face2tile; // [faceid] |
292 | int faces; tileid *face2tile; // [faceid] |
283 | int texs; maptex *tex; // [tileid] |
293 | int texs; maptex *tex; // [tileid] |
284 | |
294 | |
285 | int32_t rows; |
295 | int32_t rows; |
286 | maprow *row; |
296 | maprow *row; |
287 | } *DC__Map; |
297 | }; |
|
|
298 | |
|
|
299 | typedef mapgrid *DC__Map; |
288 | |
300 | |
289 | static char * |
301 | static char * |
290 | prepend (char *ptr, int sze, int inc) |
302 | prepend (char *ptr, int sze, int inc) |
291 | { |
303 | { |
292 | char *p; |
304 | char *p; |
… | |
… | |
310 | |
322 | |
311 | #define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
323 | #define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
312 | #define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
324 | #define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
313 | |
325 | |
314 | static void |
326 | static void |
315 | need_facenum (struct map *self, faceid face) |
327 | need_facenum (struct mapgrid *self, faceid face) |
316 | { |
328 | { |
317 | while (self->faces <= face) |
329 | while (self->faces <= face) |
318 | { |
330 | { |
319 | Append (tileid, self->face2tile, self->faces, self->faces); |
331 | Append (tileid, self->face2tile, self->faces, self->faces); |
320 | self->faces *= 2; |
332 | self->faces *= 2; |
321 | } |
333 | } |
322 | } |
334 | } |
323 | |
335 | |
324 | static void |
336 | static void |
325 | need_texid (struct map *self, int texid) |
337 | need_texid (struct mapgrid *self, int texid) |
326 | { |
338 | { |
327 | while (self->texs <= texid) |
339 | while (self->texs <= texid) |
328 | { |
340 | { |
329 | Append (maptex, self->tex, self->texs, self->texs); |
341 | Append (maptex, self->tex, self->texs, self->texs); |
330 | self->texs *= 2; |
342 | self->texs *= 2; |
331 | } |
343 | } |
332 | } |
344 | } |
333 | |
345 | |
334 | static maprow * |
346 | static maprow * |
335 | map_get_row (DC__Map self, int y) |
347 | map_get_row (mapgrid *self, int y) |
336 | { |
348 | { |
337 | if (0 > y) |
349 | if (0 > y) |
338 | { |
350 | { |
339 | int extend = - y + MAP_EXTEND_Y; |
351 | int extend = - y + MAP_EXTEND_Y; |
340 | Prepend (maprow, self->row, self->rows, extend); |
352 | Prepend (maprow, self->row, self->rows, extend); |
… | |
… | |
378 | |
390 | |
379 | return row->col + (x - row->c0); |
391 | return row->col + (x - row->c0); |
380 | } |
392 | } |
381 | |
393 | |
382 | static mapcell * |
394 | static mapcell * |
383 | map_get_cell (DC__Map self, int x, int y) |
395 | map_get_cell (mapgrid *self, int x, int y) |
384 | { |
396 | { |
385 | return row_get_cell (map_get_row (self, y), x); |
397 | return row_get_cell (map_get_row (self, y), x); |
386 | } |
398 | } |
387 | |
399 | |
388 | static void |
400 | static void |
389 | map_clear (DC__Map self) |
401 | map_clear (mapgrid *self) |
390 | { |
402 | { |
391 | int r; |
403 | int r; |
392 | |
404 | |
393 | for (r = 0; r < self->rows; r++) |
405 | for (r = 0; r < self->rows; r++) |
394 | Safefree (self->row[r].col); |
406 | Safefree (self->row[r].col); |
… | |
… | |
412 | (cell)->flags = 0; \ |
424 | (cell)->flags = 0; \ |
413 | (cell)->player = 0; \ |
425 | (cell)->player = 0; \ |
414 | } while (0) |
426 | } while (0) |
415 | |
427 | |
416 | static void |
428 | static void |
417 | map_blank (DC__Map self, int x0, int y0, int w, int h) |
429 | map_blank (mapgrid *self, int x0, int y0, int w, int h) |
418 | { |
430 | { |
419 | int x, y; |
431 | int x, y; |
420 | maprow *row; |
432 | maprow *row; |
421 | mapcell *cell; |
433 | mapcell *cell; |
422 | |
434 | |
… | |
… | |
439 | CELL_CLEAR (cell); |
451 | CELL_CLEAR (cell); |
440 | } |
452 | } |
441 | } |
453 | } |
442 | } |
454 | } |
443 | |
455 | |
444 | typedef struct { |
456 | struct smooth_key |
|
|
457 | { |
445 | tileid tile; |
458 | tileid tile; |
446 | uint8_t x, y, level; |
459 | uint8_t x, y, level; |
447 | } smooth_key; |
460 | |
|
|
461 | bool operator == (const smooth_key &o) const |
|
|
462 | { |
|
|
463 | return tile == o.tile && x == o.x && y == o.y && level == o.level; |
|
|
464 | } |
|
|
465 | }; |
|
|
466 | |
|
|
467 | typedef ska::flat_hash_map<smooth_key, IV> smooth_hash; |
|
|
468 | |
|
|
469 | namespace std { |
|
|
470 | template <> |
|
|
471 | struct hash<smooth_key> |
|
|
472 | { |
|
|
473 | size_t operator () (const smooth_key &v) const |
|
|
474 | { |
|
|
475 | return v.tile + (v.x << 8) + (v.y << 16) + (v.level << 24); |
|
|
476 | } |
|
|
477 | }; |
|
|
478 | } |
448 | |
479 | |
449 | static void |
480 | static void |
450 | smooth_or_bits (HV *hv, smooth_key *key, IV bits) |
481 | smooth_or_bits (smooth_hash &h, smooth_key &key, IV bits) |
451 | { |
482 | { |
452 | SV **sv = hv_fetch (hv, (char *)key, sizeof (*key), 1); |
483 | auto &&it = h.find (key); |
453 | |
484 | |
454 | if (SvIOK (*sv)) |
485 | if (it == h.end ()) |
455 | SvIV_set (*sv, SvIVX (*sv) | bits); |
486 | h.insert (std::make_pair (key, bits)); |
456 | else |
487 | else |
457 | sv_setiv (*sv, bits); |
488 | it->second |= bits; |
458 | } |
489 | } |
459 | |
490 | |
460 | static void |
491 | static void |
461 | music_finished (void) |
492 | music_finished (void) |
462 | { |
493 | { |
… | |
… | |
481 | ev.data2 = 0; |
512 | ev.data2 = 0; |
482 | |
513 | |
483 | SDL_PushEvent ((SDL_Event *)&ev); |
514 | SDL_PushEvent ((SDL_Event *)&ev); |
484 | } |
515 | } |
485 | |
516 | |
|
|
517 | // approximately divide by 255 |
486 | static unsigned int |
518 | static unsigned int |
487 | div255 (unsigned int n) |
519 | div255 (unsigned int n) |
488 | { |
520 | { |
489 | return (n + (n >> 8)) >> 8; |
521 | return (n + (n >> 8)) >> 8; |
490 | } |
522 | } |
… | |
… | |
1083 | OUTPUT: |
1115 | OUTPUT: |
1084 | RETVAL |
1116 | RETVAL |
1085 | |
1117 | |
1086 | int |
1118 | int |
1087 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
1119 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
1088 | POSTCALL: |
1120 | POSTCALL: |
1089 | Mix_HookMusicFinished (music_finished); |
1121 | Mix_HookMusicFinished (music_finished); |
1090 | Mix_ChannelFinished (channel_finished); |
1122 | Mix_ChannelFinished (channel_finished); |
1091 | |
1123 | |
1092 | void |
1124 | void |
1093 | Mix_QuerySpec () |
1125 | Mix_QuerySpec () |
… | |
… | |
1870 | PROTOTYPES: DISABLE |
1902 | PROTOTYPES: DISABLE |
1871 | |
1903 | |
1872 | DC::Map |
1904 | DC::Map |
1873 | new (SV *klass) |
1905 | new (SV *klass) |
1874 | CODE: |
1906 | CODE: |
1875 | New (0, RETVAL, 1, struct map); |
1907 | New (0, RETVAL, 1, mapgrid); |
1876 | RETVAL->x = 0; |
1908 | RETVAL->x = 0; |
1877 | RETVAL->y = 0; |
1909 | RETVAL->y = 0; |
1878 | RETVAL->w = 0; |
1910 | RETVAL->w = 0; |
1879 | RETVAL->h = 0; |
1911 | RETVAL->h = 0; |
1880 | RETVAL->ox = 0; |
1912 | RETVAL->ox = 0; |
… | |
… | |
1917 | |
1949 | |
1918 | void |
1950 | void |
1919 | set_smooth (DC::Map self, int face, int smooth, int level) |
1951 | set_smooth (DC::Map self, int face, int smooth, int level) |
1920 | CODE: |
1952 | CODE: |
1921 | { |
1953 | { |
1922 | tileid texid; |
1954 | tileid texid; |
1923 | maptex *tex; |
1955 | maptex *tex; |
1924 | |
1956 | |
1925 | if (face < 0 || face >= self->faces) |
1957 | if (face < 0 || face >= self->faces) |
1926 | return; |
1958 | return; |
1927 | |
1959 | |
1928 | if (smooth < 0 || smooth >= self->faces) |
1960 | if (smooth < 0 || smooth >= self->faces) |
1929 | return; |
1961 | return; |
1930 | |
1962 | |
1931 | texid = self->face2tile [face]; |
1963 | texid = self->face2tile [face]; |
1932 | |
1964 | |
1933 | if (!texid) |
1965 | if (!texid) |
1934 | return; |
1966 | return; |
1935 | |
1967 | |
1936 | tex = self->tex + texid; |
1968 | tex = self->tex + texid; |
… | |
… | |
1969 | } |
2001 | } |
1970 | |
2002 | |
1971 | void |
2003 | void |
1972 | expire_textures (DC::Map self, int texid, int count) |
2004 | expire_textures (DC::Map self, int texid, int count) |
1973 | PPCODE: |
2005 | PPCODE: |
1974 | for (; texid < self->texs && count; ++texid, --count) |
2006 | for (; texid < self->texs && count; ++texid, --count) |
1975 | { |
2007 | { |
1976 | maptex *tex = self->tex + texid; |
2008 | maptex *tex = self->tex + texid; |
1977 | |
2009 | |
1978 | if (tex->name) |
2010 | if (tex->name) |
1979 | { |
2011 | { |
… | |
… | |
2181 | | (b << 16) |
2213 | | (b << 16) |
2182 | | (a << 24); |
2214 | | (a << 24); |
2183 | } |
2215 | } |
2184 | } |
2216 | } |
2185 | |
2217 | |
2186 | RETVAL = map_sv; |
2218 | RETVAL = map_sv; |
2187 | } |
2219 | } |
2188 | OUTPUT: |
2220 | OUTPUT: |
2189 | RETVAL |
2221 | RETVAL |
2190 | |
2222 | |
2191 | void |
2223 | void |
2192 | draw (DC::Map self, int mx, int my, int sw, int sh, int Tw, int Th, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) |
2224 | draw (DC::Map self, int mx, int my, int sw, int sh, int Tw, int Th, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) |
2193 | CODE: |
2225 | CODE: |
2194 | { |
2226 | { |
2195 | int x, y, z; |
2227 | int x, y, z; |
2196 | |
2228 | |
2197 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
|
|
2198 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
|
|
2199 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) |
2229 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k), also, static! |
2200 | smooth_key skey; |
|
|
2201 | int pl_x, pl_y; |
2230 | int pl_x, pl_y; |
2202 | maptex pl_tex; |
2231 | maptex pl_tex; |
2203 | rc_t *rc = rc_alloc (); |
2232 | rc_t *rc = rc_alloc (); |
2204 | rc_t *rc_ov = rc_alloc (); |
2233 | rc_t *rc_ov = rc_alloc (); |
2205 | rc_key_t key; |
2234 | rc_key_t key; |
… | |
… | |
2208 | pl_tex.name = 0; |
2237 | pl_tex.name = 0; |
2209 | |
2238 | |
2210 | // that's current max. sorry. |
2239 | // that's current max. sorry. |
2211 | if (sw > 255) sw = 255; |
2240 | if (sw > 255) sw = 255; |
2212 | if (sh > 255) sh = 255; |
2241 | if (sh > 255) sh = 255; |
2213 | |
|
|
2214 | // clear key, in case of extra padding |
|
|
2215 | memset (&skey, 0, sizeof (skey)); |
|
|
2216 | |
2242 | |
2217 | memset (&key, 0, sizeof (key)); |
2243 | memset (&key, 0, sizeof (key)); |
2218 | key.r = 255; |
2244 | key.r = 255; |
2219 | key.g = 255; |
2245 | key.g = 255; |
2220 | key.b = 255; |
2246 | key.b = 255; |
… | |
… | |
2226 | my += self->y; |
2252 | my += self->y; |
2227 | |
2253 | |
2228 | // first pass: determine smooth_max |
2254 | // first pass: determine smooth_max |
2229 | // rather ugly, if you ask me |
2255 | // rather ugly, if you ask me |
2230 | // could also be stored inside mapcell and updated on change |
2256 | // could also be stored inside mapcell and updated on change |
2231 | memset (smooth_max, 0, sizeof (smooth_max)); |
2257 | memset (smooth_max, 0, sizeof (smooth_max[0]) * (sh + 1)); |
2232 | |
2258 | |
2233 | for (y = 0; y < sh; y++) |
2259 | for (y = 0; y < sh; y++) |
2234 | if (0 <= y + my && y + my < self->rows) |
2260 | if (0 <= y + my && y + my < self->rows) |
2235 | { |
2261 | { |
2236 | maprow *row = self->row + (y + my); |
2262 | maprow *row = self->row + (y + my); |
… | |
… | |
2251 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2277 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2252 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2278 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2253 | |
2279 | |
2254 | for (z = 0; z <= 2; z++) |
2280 | for (z = 0; z <= 2; z++) |
2255 | { |
2281 | { |
|
|
2282 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
|
|
2283 | smooth_key skey; |
|
|
2284 | smooth_hash smooth; |
2256 | memset (smooth_level, 0, sizeof (smooth_level)); |
2285 | memset (smooth_level, 0, sizeof (smooth_level)); |
2257 | key.texname = -1; |
2286 | key.texname = -1; |
2258 | |
2287 | |
2259 | for (y = 0; y < sh; y++) |
2288 | for (y = 0; y < sh; y++) |
2260 | if (0 <= y + my && y + my < self->rows) |
2289 | if (0 <= y + my && y + my < self->rows) |
… | |
… | |
2321 | |
2350 | |
2322 | // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· |
2351 | // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· |
2323 | // ·· ·· ·┏ ┓· |
2352 | // ·· ·· ·┏ ┓· |
2324 | |
2353 | |
2325 | // full tile |
2354 | // full tile |
2326 | skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x1000); |
2355 | skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x1000); |
2327 | |
2356 | |
2328 | // borders |
2357 | // borders |
2329 | skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0091); |
2358 | skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0091); |
2330 | skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0032); |
2359 | skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0032); |
2331 | skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0064); |
2360 | skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0064); |
2332 | skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, &skey, 0x00c8); |
2361 | skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, skey, 0x00c8); |
2333 | |
2362 | |
2334 | // corners |
2363 | // corners |
2335 | skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0100); |
2364 | skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0100); |
2336 | skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0200); |
2365 | skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0200); |
2337 | skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400); |
2366 | skey.x = x ; skey.y = y ; smooth_or_bits (smooth, skey, 0x0400); |
2338 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); |
2367 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, skey, 0x0800); |
2339 | } |
2368 | } |
2340 | } |
2369 | } |
2341 | |
2370 | |
2342 | if (expect_false (z == 2) && expect_false (cell->flags)) |
2371 | if (expect_false (z == 2) && expect_false (cell->flags)) |
2343 | { |
2372 | { |
… | |
… | |
2380 | if (smask & (((uint32_t)1) << b)) |
2409 | if (smask & (((uint32_t)1) << b)) |
2381 | { |
2410 | { |
2382 | int level = (w << 5) | b; |
2411 | int level = (w << 5) | b; |
2383 | HE *he; |
2412 | HE *he; |
2384 | |
2413 | |
2385 | hv_iterinit (smooth); |
2414 | for (auto &&it = smooth.begin (); it != smooth.end (); ++it) |
2386 | while ((he = hv_iternext (smooth))) |
|
|
2387 | { |
2415 | { |
2388 | smooth_key *skey = (smooth_key *)HeKEY (he); |
2416 | smooth_key &skey = it->first; |
2389 | IV bits = SvIVX (HeVAL (he)); |
2417 | IV bits = it->second; |
2390 | |
2418 | |
2391 | if (!(bits & 0x1000) |
2419 | if (!(bits & 0x1000) |
2392 | && skey->level == level |
2420 | && skey.level == level |
2393 | && level > smooth_max [skey->x][skey->y]) |
2421 | && level > smooth_max [skey.x][skey.y]) |
2394 | { |
2422 | { |
2395 | maptex tex = self->tex [skey->tile]; |
2423 | maptex tex = self->tex [skey.tile]; |
2396 | int px = (((int)skey->x) - 1) * Tw; |
2424 | int px = (((int)skey.x) - 1) * Tw; |
2397 | int py = (((int)skey->y) - 1) * Th; |
2425 | int py = (((int)skey.y) - 1) * Th; |
2398 | int border = bits & 15; |
2426 | int border = bits & 15; |
2399 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
2427 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
2400 | float dx = tex.s * .0625f; // 16 images/row |
2428 | float dx = tex.s * .0625f; // 16 images/row |
2401 | float dy = tex.t * .5f ; // 2 images/column |
2429 | float dy = tex.t * .5f ; // 2 images/column |
2402 | |
2430 | |
… | |
… | |
2404 | { |
2432 | { |
2405 | // this time avoiding texture state changes |
2433 | // this time avoiding texture state changes |
2406 | // save gobs of state changes. |
2434 | // save gobs of state changes. |
2407 | if (key.texname != tex.name) |
2435 | if (key.texname != tex.name) |
2408 | { |
2436 | { |
2409 | self->tex [skey->tile].unused = 0; |
2437 | self->tex [skey.tile].unused = 0; |
2410 | |
2438 | |
2411 | glEnd (); |
2439 | glEnd (); |
2412 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
2440 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
2413 | glBegin (GL_QUADS); |
2441 | glBegin (GL_QUADS); |
2414 | } |
2442 | } |
… | |
… | |
2440 | |
2468 | |
2441 | glEnd (); |
2469 | glEnd (); |
2442 | glDisable (GL_TEXTURE_2D); |
2470 | glDisable (GL_TEXTURE_2D); |
2443 | key.texname = -1; |
2471 | key.texname = -1; |
2444 | } |
2472 | } |
2445 | |
|
|
2446 | hv_clear (smooth); |
|
|
2447 | } |
2473 | } |
2448 | |
2474 | |
2449 | if (pl_tex.name) |
2475 | if (pl_tex.name) |
2450 | { |
2476 | { |
2451 | maptex tex = pl_tex; |
2477 | maptex tex = pl_tex; |
… | |
… | |
2720 | else |
2746 | else |
2721 | *data++ = 0; |
2747 | *data++ = 0; |
2722 | } |
2748 | } |
2723 | } |
2749 | } |
2724 | |
2750 | |
2725 | /* if size is w*h + 5 then no data has been found */ |
2751 | /* if size is w*h + 5 then no data has been found */ |
2726 | if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) |
2752 | if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) |
2727 | { |
2753 | { |
2728 | SvPOK_only (data_sv); |
2754 | SvPOK_only (data_sv); |
2729 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
2755 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
2730 | } |
2756 | } |
2731 | |
2757 | |
2732 | RETVAL = data_sv; |
2758 | RETVAL = data_sv; |
2733 | } |
2759 | } |
2734 | OUTPUT: |
2760 | OUTPUT: |
2735 | RETVAL |
2761 | RETVAL |
2736 | |
2762 | |
2737 | void |
2763 | void |
… | |
… | |
3427 | |
3453 | |
3428 | void |
3454 | void |
3429 | find_widget (SV *self, NV x, NV y) |
3455 | find_widget (SV *self, NV x, NV y) |
3430 | PPCODE: |
3456 | PPCODE: |
3431 | { |
3457 | { |
3432 | if (within_widget (self, x, y)) |
3458 | if (within_widget (self, x, y)) |
3433 | XPUSHs (self); |
3459 | XPUSHs (self); |
3434 | } |
3460 | } |
3435 | |
3461 | |
3436 | BOOT: |
3462 | BOOT: |
3437 | { |
3463 | { |
… | |
… | |
3445 | |
3471 | |
3446 | void |
3472 | void |
3447 | draw (SV *self) |
3473 | draw (SV *self) |
3448 | CODE: |
3474 | CODE: |
3449 | { |
3475 | { |
3450 | HV *hv; |
3476 | HV *hv; |
3451 | SV **svp; |
3477 | SV **svp; |
3452 | NV x, y, w, h; |
3478 | NV x, y, w, h; |
3453 | SV *draw_x_sv = GvSV (draw_x_gv); |
3479 | SV *draw_x_sv = GvSV (draw_x_gv); |
3454 | SV *draw_y_sv = GvSV (draw_y_gv); |
3480 | SV *draw_y_sv = GvSV (draw_y_gv); |
3455 | SV *draw_w_sv = GvSV (draw_w_gv); |
3481 | SV *draw_w_sv = GvSV (draw_w_gv); |
3456 | SV *draw_h_sv = GvSV (draw_h_gv); |
3482 | SV *draw_h_sv = GvSV (draw_h_gv); |