… | |
… | |
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> |
… | |
… | |
48 | #endif |
53 | #endif |
49 | |
54 | |
50 | #define PANGO_ENABLE_BACKEND |
55 | #define PANGO_ENABLE_BACKEND |
51 | #define G_DISABLE_CAST_CHECKS |
56 | #define G_DISABLE_CAST_CHECKS |
52 | |
57 | |
53 | #include <glib/gmacros.h> |
58 | #include <glib.h> |
54 | |
59 | |
55 | #include <pango/pango.h> |
60 | #include <pango/pango.h> |
56 | |
61 | |
57 | #ifndef PANGO_VERSION_CHECK |
62 | #ifndef PANGO_VERSION_CHECK |
58 | # define PANGO_VERSION_CHECK(a,b,c) 0 |
63 | # define PANGO_VERSION_CHECK(a,b,c) 0 |
… | |
… | |
71 | # include <netinet/in.h> |
76 | # include <netinet/in.h> |
72 | # include <netinet/tcp.h> |
77 | # include <netinet/tcp.h> |
73 | # include <inttypes.h> |
78 | # include <inttypes.h> |
74 | #endif |
79 | #endif |
75 | |
80 | |
76 | #if __GNUC__ >= 4 |
81 | #include "ecb.h" |
77 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
|
|
78 | #else |
|
|
79 | # define expect(expr,value) (expr) |
|
|
80 | #endif |
|
|
81 | |
|
|
82 | #define expect_false(expr) expect ((expr) != 0, 0) |
|
|
83 | #define expect_true(expr) expect ((expr) != 0, 1) |
|
|
84 | |
82 | |
85 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ |
83 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ |
86 | |
84 | |
87 | /* this is used as fow flag as well, so has to have a different value */ |
85 | /* this is used as fow flag as well, so has to have a different value */ |
88 | /* then anything that is computed by incoming darkness */ |
86 | /* then anything that is computed by incoming darkness */ |
… | |
… | |
106 | fast_sv_grow (SV *sv, STRLEN need) |
104 | fast_sv_grow (SV *sv, STRLEN need) |
107 | { |
105 | { |
108 | STRLEN len = SvLEN (sv); |
106 | STRLEN len = SvLEN (sv); |
109 | STRLEN want = SvCUR (sv) + need; |
107 | STRLEN want = SvCUR (sv) + need; |
110 | |
108 | |
111 | if (expect_false (len < want)) |
109 | if (ecb_expect_false (len < want)) |
112 | { |
110 | { |
113 | do |
111 | do |
114 | len *= 2; |
112 | len *= 2; |
115 | while (len < want); |
113 | while (len < want); |
116 | |
114 | |
… | |
… | |
184 | { |
182 | { |
185 | GSList *attrs = run->item->analysis.extra_attrs; |
183 | GSList *attrs = run->item->analysis.extra_attrs; |
186 | |
184 | |
187 | while (attrs) |
185 | while (attrs) |
188 | { |
186 | { |
189 | PangoAttribute *attr = attrs->data; |
187 | PangoAttribute *attr = (PangoAttribute *)attrs->data; |
190 | |
188 | |
191 | if (attr->klass->type == PANGO_ATTR_SHAPE) |
189 | if (attr->klass->type == PANGO_ATTR_SHAPE) |
192 | return 1; |
190 | return 1; |
193 | |
191 | |
194 | attrs = attrs->next; |
192 | attrs = attrs->next; |
195 | } |
193 | } |
196 | |
194 | |
197 | return 0; |
195 | return 0; |
198 | } |
196 | } |
199 | |
197 | |
200 | typedef struct cf_layout { |
198 | struct cf_layout { |
201 | PangoLayout *pl; |
199 | PangoLayout *pl; |
202 | float r, g, b, a; // default color for rgba mode |
200 | float r, g, b, a; // default color for rgba mode |
203 | int base_height; |
201 | int base_height; |
204 | DC__Font font; |
202 | DC__Font font; |
205 | rc_t *rc; |
203 | rc_t rc; |
206 | } *DC__Layout; |
204 | }; |
|
|
205 | |
|
|
206 | typedef cf_layout *DC__Layout; |
207 | |
207 | |
208 | static DC__Font default_font; |
208 | static DC__Font default_font; |
209 | static PangoContext *opengl_context; |
209 | static PangoContext *opengl_context; |
210 | static PangoFontMap *opengl_fontmap; |
210 | static PangoFontMap *opengl_fontmap; |
211 | |
211 | |
212 | static void |
212 | static void |
213 | substitute_func (FcPattern *pattern, gpointer data) |
213 | substitute_func (FcPattern *pattern, gpointer data) |
214 | { |
214 | { |
215 | FcPatternAddBool (pattern, FC_HINTING, 1); |
215 | FcPatternAddBool (pattern, FC_HINTING, 1); |
216 | #ifdef FC_HINT_STYLE |
216 | #ifdef FC_HINT_STYLE |
217 | FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); |
217 | FcPatternAddInteger (pattern, FC_HINT_STYLE, FC_HINT_FULL); |
218 | #endif |
218 | #endif |
219 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
219 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
220 | } |
220 | } |
221 | |
221 | |
222 | static void |
222 | static void |
… | |
… | |
249 | |
249 | |
250 | *w = rect.width; |
250 | *w = rect.width; |
251 | *h = rect.height; |
251 | *h = rect.height; |
252 | } |
252 | } |
253 | |
253 | |
|
|
254 | ///////////////////////////////////////////////////////////////////////////// |
|
|
255 | |
254 | typedef uint16_t tileid; |
256 | typedef uint16_t tileid; |
255 | typedef uint16_t faceid; |
257 | typedef uint16_t faceid; |
256 | |
258 | |
257 | typedef struct { |
259 | struct maptex |
|
|
260 | { |
258 | GLuint name; |
261 | GLuint name; |
259 | int w, h; |
262 | int w, h; |
260 | float s, t; |
263 | float s, t; |
261 | uint8_t r, g, b, a; |
264 | uint8_t r, g, b, a; |
262 | tileid smoothtile; |
265 | tileid smoothtile; |
263 | uint8_t smoothlevel; |
266 | uint8_t smoothlevel; |
264 | uint8_t unused; /* set to zero on use */ |
267 | uint8_t unused; /* set to zero on use */ |
265 | } maptex; |
268 | }; |
266 | |
269 | |
267 | typedef struct { |
270 | struct mapcell |
|
|
271 | { |
268 | uint32_t player; |
272 | uint32_t player; |
269 | tileid tile[3]; |
273 | tileid tile[3]; |
270 | uint16_t darkness; |
274 | uint16_t darkness; |
271 | uint8_t stat_width, stat_hp, flags, smoothmax; |
275 | uint8_t stat_width, stat_hp, flags, smoothmax; |
272 | } mapcell; |
276 | }; |
273 | |
277 | |
274 | typedef struct { |
278 | struct maprow |
|
|
279 | { |
275 | int32_t c0, c1; |
280 | int32_t c0, c1; |
276 | mapcell *col; |
281 | mapcell *col; |
277 | } maprow; |
282 | }; |
278 | |
283 | |
279 | typedef struct map { |
284 | struct mapgrid { |
280 | int x, y, w, h; |
285 | int x, y, w, h; |
281 | int ox, oy; /* offset to virtual global coordinate system */ |
286 | int ox, oy; /* offset to virtual global coordinate system */ |
282 | int faces; tileid *face2tile; // [faceid] |
287 | int faces; tileid *face2tile; // [faceid] |
283 | int texs; maptex *tex; // [tileid] |
288 | int texs; maptex *tex; // [tileid] |
284 | |
289 | |
285 | int32_t rows; |
290 | int32_t rows; |
286 | maprow *row; |
291 | maprow *row; |
287 | } *DC__Map; |
292 | }; |
288 | |
293 | |
289 | static char * |
294 | typedef mapgrid *DC__Map; |
|
|
295 | |
|
|
296 | template<typename T> |
|
|
297 | static void |
290 | prepend (char *ptr, int sze, int inc) |
298 | prepend (T *&ptr, int sze, int inc) |
291 | { |
299 | { |
292 | char *p; |
300 | T *p; |
293 | |
301 | |
294 | New (0, p, sze + inc, char); |
302 | Newx (p, inc + sze, T); |
295 | Zero (p, inc, char); |
303 | Zero (p, inc, T); |
296 | Move (ptr, p + inc, sze, char); |
304 | Move (ptr, p + inc, sze, T); |
297 | Safefree (ptr); |
305 | Safefree (ptr); |
298 | |
306 | |
299 | return p; |
307 | ptr = p; |
300 | } |
308 | } |
301 | |
309 | |
302 | static char * |
310 | template<typename T> |
303 | append (char *ptr, int sze, int inc) |
|
|
304 | { |
|
|
305 | Renew (ptr, sze + inc, char); |
|
|
306 | Zero (ptr + sze, inc, char); |
|
|
307 | |
|
|
308 | return ptr; |
|
|
309 | } |
|
|
310 | |
|
|
311 | #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)) |
|
|
313 | |
|
|
314 | static void |
311 | static void |
|
|
312 | append (T *&ptr, int sze, int inc) |
|
|
313 | { |
|
|
314 | Renew (ptr, sze + inc, T); |
|
|
315 | Zero (ptr + sze, inc, T); |
|
|
316 | } |
|
|
317 | |
|
|
318 | static void |
315 | need_facenum (struct map *self, faceid face) |
319 | need_facenum (struct mapgrid *self, faceid face) |
316 | { |
320 | { |
317 | while (self->faces <= face) |
321 | while (self->faces <= face) |
318 | { |
322 | { |
319 | Append (tileid, self->face2tile, self->faces, self->faces); |
323 | append (self->face2tile, self->faces, self->faces); |
320 | self->faces *= 2; |
324 | self->faces *= 2; |
321 | } |
325 | } |
322 | } |
326 | } |
323 | |
327 | |
324 | static void |
328 | static void |
325 | need_texid (struct map *self, int texid) |
329 | need_texid (struct mapgrid *self, int texid) |
326 | { |
330 | { |
327 | while (self->texs <= texid) |
331 | while (self->texs <= texid) |
328 | { |
332 | { |
329 | Append (maptex, self->tex, self->texs, self->texs); |
333 | append (self->tex, self->texs, self->texs); |
330 | self->texs *= 2; |
334 | self->texs *= 2; |
331 | } |
335 | } |
332 | } |
336 | } |
333 | |
337 | |
334 | static maprow * |
338 | static maprow * |
335 | map_get_row (DC__Map self, int y) |
339 | map_get_row (mapgrid *self, int y) |
336 | { |
340 | { |
337 | if (0 > y) |
341 | if (0 > y) |
338 | { |
342 | { |
339 | int extend = - y + MAP_EXTEND_Y; |
343 | int extend = - y + MAP_EXTEND_Y; |
340 | Prepend (maprow, self->row, self->rows, extend); |
344 | prepend (self->row, self->rows, extend); |
341 | |
345 | |
342 | self->rows += extend; |
346 | self->rows += extend; |
343 | self->y += extend; |
347 | self->y += extend; |
344 | y += extend; |
348 | y += extend; |
345 | } |
349 | } |
346 | else if (y >= self->rows) |
350 | else if (y >= self->rows) |
347 | { |
351 | { |
348 | int extend = y - self->rows + MAP_EXTEND_Y; |
352 | int extend = y - self->rows + MAP_EXTEND_Y; |
349 | Append (maprow, self->row, self->rows, extend); |
353 | append (self->row, self->rows, extend); |
350 | self->rows += extend; |
354 | self->rows += extend; |
351 | } |
355 | } |
352 | |
356 | |
353 | return self->row + y; |
357 | return self->row + y; |
354 | } |
358 | } |
… | |
… | |
364 | } |
368 | } |
365 | |
369 | |
366 | if (row->c0 > x) |
370 | if (row->c0 > x) |
367 | { |
371 | { |
368 | int extend = row->c0 - x + MAP_EXTEND_X; |
372 | int extend = row->c0 - x + MAP_EXTEND_X; |
369 | Prepend (mapcell, row->col, row->c1 - row->c0, extend); |
373 | prepend (row->col, row->c1 - row->c0, extend); |
370 | row->c0 -= extend; |
374 | row->c0 -= extend; |
371 | } |
375 | } |
372 | else if (x >= row->c1) |
376 | else if (x >= row->c1) |
373 | { |
377 | { |
374 | int extend = x - row->c1 + MAP_EXTEND_X; |
378 | int extend = x - row->c1 + MAP_EXTEND_X; |
375 | Append (mapcell, row->col, row->c1 - row->c0, extend); |
379 | append (row->col, row->c1 - row->c0, extend); |
376 | row->c1 += extend; |
380 | row->c1 += extend; |
377 | } |
381 | } |
378 | |
382 | |
379 | return row->col + (x - row->c0); |
383 | return row->col + (x - row->c0); |
380 | } |
384 | } |
381 | |
385 | |
382 | static mapcell * |
386 | static mapcell * |
383 | map_get_cell (DC__Map self, int x, int y) |
387 | map_get_cell (mapgrid *self, int x, int y) |
384 | { |
388 | { |
385 | return row_get_cell (map_get_row (self, y), x); |
389 | return row_get_cell (map_get_row (self, y), x); |
386 | } |
390 | } |
387 | |
391 | |
388 | static void |
392 | static void |
389 | map_clear (DC__Map self) |
393 | map_clear (mapgrid *self) |
390 | { |
394 | { |
391 | int r; |
395 | int r; |
392 | |
396 | |
393 | for (r = 0; r < self->rows; r++) |
397 | for (r = 0; r < self->rows; r++) |
394 | Safefree (self->row[r].col); |
398 | Safefree (self->row[r].col); |
… | |
… | |
412 | (cell)->flags = 0; \ |
416 | (cell)->flags = 0; \ |
413 | (cell)->player = 0; \ |
417 | (cell)->player = 0; \ |
414 | } while (0) |
418 | } while (0) |
415 | |
419 | |
416 | static void |
420 | static void |
417 | map_blank (DC__Map self, int x0, int y0, int w, int h) |
421 | map_blank (mapgrid *self, int x0, int y0, int w, int h) |
418 | { |
422 | { |
419 | int x, y; |
423 | int x, y; |
420 | maprow *row; |
424 | maprow *row; |
421 | mapcell *cell; |
425 | mapcell *cell; |
422 | |
426 | |
… | |
… | |
439 | CELL_CLEAR (cell); |
443 | CELL_CLEAR (cell); |
440 | } |
444 | } |
441 | } |
445 | } |
442 | } |
446 | } |
443 | |
447 | |
444 | typedef struct { |
448 | struct smooth_key |
|
|
449 | { |
445 | tileid tile; |
450 | tileid tile; |
446 | uint8_t x, y, level; |
451 | uint8_t x, y, level; |
447 | } smooth_key; |
452 | |
|
|
453 | bool operator == (const smooth_key &o) const |
|
|
454 | { |
|
|
455 | return tile == o.tile && x == o.x && y == o.y && level == o.level; |
|
|
456 | } |
|
|
457 | }; |
|
|
458 | |
|
|
459 | typedef ska::flat_hash_map<smooth_key, IV> smooth_hash; |
|
|
460 | |
|
|
461 | namespace std { |
|
|
462 | template <> |
|
|
463 | struct hash<smooth_key> |
|
|
464 | { |
|
|
465 | size_t operator () (const smooth_key &v) const |
|
|
466 | { |
|
|
467 | return v.tile + (v.x << 8) + (v.y << 16) + (v.level << 24); |
|
|
468 | } |
|
|
469 | }; |
|
|
470 | } |
448 | |
471 | |
449 | static void |
472 | static void |
450 | smooth_or_bits (HV *hv, smooth_key *key, IV bits) |
473 | smooth_or_bits (smooth_hash &h, smooth_key &key, IV bits) |
451 | { |
474 | { |
452 | SV **sv = hv_fetch (hv, (char *)key, sizeof (*key), 1); |
475 | auto &&it = h.find (key); |
453 | |
476 | |
454 | if (SvIOK (*sv)) |
477 | if (it == h.end ()) |
455 | SvIV_set (*sv, SvIVX (*sv) | bits); |
478 | h.insert (std::make_pair (key, bits)); |
456 | else |
479 | else |
457 | sv_setiv (*sv, bits); |
480 | it->second |= bits; |
458 | } |
481 | } |
459 | |
482 | |
460 | static void |
483 | static void |
461 | music_finished (void) |
484 | music_finished (void) |
462 | { |
485 | { |
… | |
… | |
481 | ev.data2 = 0; |
504 | ev.data2 = 0; |
482 | |
505 | |
483 | SDL_PushEvent ((SDL_Event *)&ev); |
506 | SDL_PushEvent ((SDL_Event *)&ev); |
484 | } |
507 | } |
485 | |
508 | |
|
|
509 | // approximately divide by 255 |
486 | static unsigned int |
510 | static unsigned int |
487 | div255 (unsigned int n) |
511 | div255 (unsigned int n) |
488 | { |
512 | { |
489 | return (n + (n >> 8)) >> 8; |
513 | return (n + (n >> 8)) >> 8; |
490 | } |
514 | } |
… | |
… | |
502 | n |= n >> 4; |
526 | n |= n >> 4; |
503 | n |= n >> 8; |
527 | n |= n >> 8; |
504 | n |= n >> 16; |
528 | n |= n >> 16; |
505 | |
529 | |
506 | return n + 1; |
530 | return n + 1; |
507 | } |
|
|
508 | |
|
|
509 | static unsigned int |
|
|
510 | popcount (unsigned int n) |
|
|
511 | { |
|
|
512 | n -= (n >> 1) & 0x55555555U; |
|
|
513 | n = ((n >> 2) & 0x33333333U) + (n & 0x33333333U); |
|
|
514 | n = ((n >> 4) + n) & 0x0f0f0f0fU; |
|
|
515 | n *= 0x01010101U; |
|
|
516 | |
|
|
517 | return n >> 24; |
|
|
518 | } |
531 | } |
519 | |
532 | |
520 | /* SDL should provide this, really. */ |
533 | /* SDL should provide this, really. */ |
521 | #define SDLK_MODIFIER_MIN 300 |
534 | #define SDLK_MODIFIER_MIN 300 |
522 | #define SDLK_MODIFIER_MAX 314 |
535 | #define SDLK_MODIFIER_MAX 314 |
… | |
… | |
853 | |
866 | |
854 | NV ceil (NV x) |
867 | NV ceil (NV x) |
855 | |
868 | |
856 | IV minpot (UV n) |
869 | IV minpot (UV n) |
857 | |
870 | |
|
|
871 | UV ld32 (UV n) |
|
|
872 | CODE: |
|
|
873 | RETVAL = ecb_ld32 (n); |
|
|
874 | OUTPUT: |
|
|
875 | RETVAL |
|
|
876 | |
858 | IV popcount (UV n) |
877 | IV popcount (UV n) |
|
|
878 | CODE: |
|
|
879 | RETVAL = ecb_popcount32 (n); |
|
|
880 | OUTPUT: |
|
|
881 | RETVAL |
859 | |
882 | |
860 | NV distance (NV dx, NV dy) |
883 | NV distance (NV dx, NV dy) |
861 | CODE: |
884 | CODE: |
862 | RETVAL = pow (dx * dx + dy * dy, 0.5); |
885 | RETVAL = pow (dx * dx + dy * dy, 0.5); |
863 | OUTPUT: |
886 | OUTPUT: |
… | |
… | |
889 | void SDL_QuitSubSystem (U32 flags) |
912 | void SDL_QuitSubSystem (U32 flags) |
890 | |
913 | |
891 | void SDL_Quit () |
914 | void SDL_Quit () |
892 | |
915 | |
893 | int SDL_GL_SetAttribute (int attr, int value) |
916 | int SDL_GL_SetAttribute (int attr, int value) |
|
|
917 | C_ARGS: (SDL_GLattr)attr, value |
894 | |
918 | |
895 | int SDL_GL_GetAttribute (int attr) |
919 | int SDL_GL_GetAttribute (int attr) |
896 | CODE: |
920 | CODE: |
897 | if (SDL_GL_GetAttribute (attr, &RETVAL)) |
921 | if (SDL_GL_GetAttribute ((SDL_GLattr)attr, &RETVAL)) |
898 | XSRETURN_UNDEF; |
922 | XSRETURN_UNDEF; |
899 | OUTPUT: |
923 | OUTPUT: |
900 | RETVAL |
924 | RETVAL |
901 | |
925 | |
902 | void |
926 | void |
… | |
… | |
975 | void |
999 | void |
976 | SDL_GL_SwapBuffers () |
1000 | SDL_GL_SwapBuffers () |
977 | |
1001 | |
978 | char * |
1002 | char * |
979 | SDL_GetKeyName (int sym) |
1003 | SDL_GetKeyName (int sym) |
|
|
1004 | C_ARGS: (SDLKey)sym |
980 | |
1005 | |
981 | int |
1006 | int |
982 | SDL_GetAppState () |
1007 | SDL_GetAppState () |
983 | |
1008 | |
984 | int |
1009 | int |
… | |
… | |
1081 | OUTPUT: |
1106 | OUTPUT: |
1082 | RETVAL |
1107 | RETVAL |
1083 | |
1108 | |
1084 | int |
1109 | int |
1085 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
1110 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
1086 | POSTCALL: |
1111 | POSTCALL: |
1087 | Mix_HookMusicFinished (music_finished); |
1112 | Mix_HookMusicFinished (music_finished); |
1088 | Mix_ChannelFinished (channel_finished); |
1113 | Mix_ChannelFinished (channel_finished); |
1089 | |
1114 | |
1090 | void |
1115 | void |
1091 | Mix_QuerySpec () |
1116 | Mix_QuerySpec () |
… | |
… | |
1212 | |
1237 | |
1213 | SDL_LockSurface (surface2); |
1238 | SDL_LockSurface (surface2); |
1214 | EXTEND (SP, 6); |
1239 | EXTEND (SP, 6); |
1215 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
1240 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
1216 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
1241 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
1217 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
1242 | PUSHs (sv_2mortal (newSVpvn ((const char *)surface2->pixels, surface2->h * surface2->pitch))); |
1218 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
1243 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
1219 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
1244 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
1220 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
1245 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
1221 | SDL_UnlockSurface (surface2); |
1246 | SDL_UnlockSurface (surface2); |
1222 | |
1247 | |
… | |
… | |
1294 | MODULE = Deliantra::Client PACKAGE = DC::Font |
1319 | MODULE = Deliantra::Client PACKAGE = DC::Font |
1295 | |
1320 | |
1296 | PROTOTYPES: DISABLE |
1321 | PROTOTYPES: DISABLE |
1297 | |
1322 | |
1298 | DC::Font |
1323 | DC::Font |
1299 | new_from_file (SV *class, char *path, int id = 0) |
1324 | new_from_file (SV *klass, char *path, int id = 0) |
1300 | CODE: |
1325 | CODE: |
1301 | { |
1326 | { |
1302 | int count; |
1327 | int count; |
1303 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
1328 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
1304 | RETVAL = pango_fc_font_description_from_pattern (pattern, 0); |
1329 | RETVAL = pango_fc_font_description_from_pattern (pattern, 0); |
… | |
… | |
1333 | PROTOTYPE: |
1358 | PROTOTYPE: |
1334 | CODE: |
1359 | CODE: |
1335 | tc_restore (); |
1360 | tc_restore (); |
1336 | |
1361 | |
1337 | DC::Layout |
1362 | DC::Layout |
1338 | new (SV *class) |
1363 | new (SV *klass) |
1339 | CODE: |
1364 | CODE: |
1340 | New (0, RETVAL, 1, struct cf_layout); |
1365 | RETVAL = new cf_layout; |
1341 | |
1366 | |
1342 | RETVAL->pl = pango_layout_new (opengl_context); |
1367 | RETVAL->pl = pango_layout_new (opengl_context); |
1343 | RETVAL->r = 1.; |
1368 | RETVAL->r = 1.; |
1344 | RETVAL->g = 1.; |
1369 | RETVAL->g = 1.; |
1345 | RETVAL->b = 1.; |
1370 | RETVAL->b = 1.; |
1346 | RETVAL->a = 1.; |
1371 | RETVAL->a = 1.; |
1347 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1372 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1348 | RETVAL->font = 0; |
1373 | RETVAL->font = 0; |
1349 | RETVAL->rc = rc_alloc (); |
|
|
1350 | |
1374 | |
1351 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1375 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1352 | layout_update_font (RETVAL); |
1376 | layout_update_font (RETVAL); |
1353 | OUTPUT: |
1377 | OUTPUT: |
1354 | RETVAL |
1378 | RETVAL |
1355 | |
1379 | |
1356 | void |
1380 | void |
1357 | DESTROY (DC::Layout self) |
1381 | DESTROY (DC::Layout self) |
1358 | CODE: |
1382 | CODE: |
1359 | g_object_unref (self->pl); |
1383 | g_object_unref (self->pl); |
1360 | rc_free (self->rc); |
|
|
1361 | Safefree (self); |
1384 | delete self; |
1362 | |
1385 | |
1363 | void |
1386 | void |
1364 | set_text (DC::Layout self, SV *text_) |
1387 | set_text (DC::Layout self, SV *text_) |
1365 | CODE: |
1388 | CODE: |
1366 | { |
1389 | { |
… | |
… | |
1492 | |
1515 | |
1493 | void |
1516 | void |
1494 | set_height (DC::Layout self, int base_height) |
1517 | set_height (DC::Layout self, int base_height) |
1495 | CODE: |
1518 | CODE: |
1496 | if (self->base_height != base_height) |
1519 | if (self->base_height != base_height) |
1497 | { |
1520 | { |
1498 | self->base_height = base_height; |
1521 | self->base_height = base_height; |
1499 | layout_update_font (self); |
1522 | layout_update_font (self); |
1500 | } |
1523 | } |
1501 | |
1524 | |
1502 | void |
1525 | void |
… | |
… | |
1620 | } |
1643 | } |
1621 | |
1644 | |
1622 | void |
1645 | void |
1623 | render (DC::Layout self, float x, float y, int flags = 0) |
1646 | render (DC::Layout self, float x, float y, int flags = 0) |
1624 | CODE: |
1647 | CODE: |
1625 | rc_clear (self->rc); |
1648 | self->rc.clear (); |
1626 | pango_opengl_render_layout_subpixel ( |
1649 | pango_opengl_render_layout_subpixel ( |
1627 | self->pl, |
1650 | self->pl, |
1628 | self->rc, |
1651 | &self->rc, |
1629 | x * PANGO_SCALE, y * PANGO_SCALE, |
1652 | x * PANGO_SCALE, y * PANGO_SCALE, |
1630 | self->r, self->g, self->b, self->a, |
1653 | self->r, self->g, self->b, self->a, |
1631 | flags |
1654 | flags |
1632 | ); |
1655 | ); |
1633 | // we assume that context_change actually clears/frees stuff |
1656 | // we assume that context_change actually clears/frees stuff |
… | |
… | |
1644 | gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
1667 | gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
1645 | GL_ONE , GL_ONE_MINUS_SRC_ALPHA); |
1668 | GL_ONE , GL_ONE_MINUS_SRC_ALPHA); |
1646 | glEnable (GL_ALPHA_TEST); |
1669 | glEnable (GL_ALPHA_TEST); |
1647 | glAlphaFunc (GL_GREATER, 7.f / 255.f); |
1670 | glAlphaFunc (GL_GREATER, 7.f / 255.f); |
1648 | |
1671 | |
1649 | rc_draw (self->rc); |
1672 | self->rc.draw (); |
1650 | |
1673 | |
1651 | glDisable (GL_ALPHA_TEST); |
1674 | glDisable (GL_ALPHA_TEST); |
1652 | glDisable (GL_BLEND); |
1675 | glDisable (GL_BLEND); |
1653 | glDisable (GL_TEXTURE_2D); |
1676 | glDisable (GL_TEXTURE_2D); |
1654 | } |
1677 | } |
… | |
… | |
1866 | MODULE = Deliantra::Client PACKAGE = DC::Map |
1889 | MODULE = Deliantra::Client PACKAGE = DC::Map |
1867 | |
1890 | |
1868 | PROTOTYPES: DISABLE |
1891 | PROTOTYPES: DISABLE |
1869 | |
1892 | |
1870 | DC::Map |
1893 | DC::Map |
1871 | new (SV *class) |
1894 | new (SV *klass) |
1872 | CODE: |
1895 | CODE: |
1873 | New (0, RETVAL, 1, struct map); |
1896 | New (0, RETVAL, 1, mapgrid); |
1874 | RETVAL->x = 0; |
1897 | RETVAL->x = 0; |
1875 | RETVAL->y = 0; |
1898 | RETVAL->y = 0; |
1876 | RETVAL->w = 0; |
1899 | RETVAL->w = 0; |
1877 | RETVAL->h = 0; |
1900 | RETVAL->h = 0; |
1878 | RETVAL->ox = 0; |
1901 | RETVAL->ox = 0; |
… | |
… | |
1915 | |
1938 | |
1916 | void |
1939 | void |
1917 | set_smooth (DC::Map self, int face, int smooth, int level) |
1940 | set_smooth (DC::Map self, int face, int smooth, int level) |
1918 | CODE: |
1941 | CODE: |
1919 | { |
1942 | { |
1920 | tileid texid; |
1943 | tileid texid; |
1921 | maptex *tex; |
1944 | maptex *tex; |
1922 | |
1945 | |
1923 | if (face < 0 || face >= self->faces) |
1946 | if (face < 0 || face >= self->faces) |
1924 | return; |
1947 | return; |
1925 | |
1948 | |
1926 | if (smooth < 0 || smooth >= self->faces) |
1949 | if (smooth < 0 || smooth >= self->faces) |
1927 | return; |
1950 | return; |
1928 | |
1951 | |
1929 | texid = self->face2tile [face]; |
1952 | texid = self->face2tile [face]; |
1930 | |
1953 | |
1931 | if (!texid) |
1954 | if (!texid) |
1932 | return; |
1955 | return; |
1933 | |
1956 | |
1934 | tex = self->tex + texid; |
1957 | tex = self->tex + texid; |
… | |
… | |
1967 | } |
1990 | } |
1968 | |
1991 | |
1969 | void |
1992 | void |
1970 | expire_textures (DC::Map self, int texid, int count) |
1993 | expire_textures (DC::Map self, int texid, int count) |
1971 | PPCODE: |
1994 | PPCODE: |
1972 | for (; texid < self->texs && count; ++texid, --count) |
1995 | for (; texid < self->texs && count; ++texid, --count) |
1973 | { |
1996 | { |
1974 | maptex *tex = self->tex + texid; |
1997 | maptex *tex = self->tex + texid; |
1975 | |
1998 | |
1976 | if (tex->name) |
1999 | if (tex->name) |
1977 | { |
2000 | { |
… | |
… | |
2024 | self->ox += dx; self->x += dx; |
2047 | self->ox += dx; self->x += dx; |
2025 | self->oy += dy; self->y += dy; |
2048 | self->oy += dy; self->y += dy; |
2026 | |
2049 | |
2027 | while (self->y < 0) |
2050 | while (self->y < 0) |
2028 | { |
2051 | { |
2029 | Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); |
2052 | prepend (self->row, self->rows, MAP_EXTEND_Y); |
2030 | |
2053 | |
2031 | self->rows += MAP_EXTEND_Y; |
2054 | self->rows += MAP_EXTEND_Y; |
2032 | self->y += MAP_EXTEND_Y; |
2055 | self->y += MAP_EXTEND_Y; |
2033 | } |
2056 | } |
2034 | } |
2057 | } |
2035 | |
2058 | |
2036 | SV * |
2059 | SV * |
2037 | map1a_update (DC::Map self, SV *data_, int extmap) |
2060 | map1a_update (DC::Map self, SV *data_) |
2038 | CODE: |
2061 | CODE: |
2039 | { |
2062 | { |
2040 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
2063 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
2041 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
2064 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
2042 | mapcell *cell; |
2065 | mapcell *cell; |
… | |
… | |
2063 | |
2086 | |
2064 | //TODO: don't trust server data to be in-range(!) |
2087 | //TODO: don't trust server data to be in-range(!) |
2065 | |
2088 | |
2066 | if (flags & 8) |
2089 | if (flags & 8) |
2067 | { |
2090 | { |
|
|
2091 | uint8_t ext, cmd; |
|
|
2092 | |
2068 | if (extmap) |
2093 | do |
2069 | { |
2094 | { |
2070 | uint8_t ext, cmd; |
2095 | ext = *data++; |
|
|
2096 | cmd = ext & 0x7f; |
2071 | |
2097 | |
2072 | do |
2098 | if (cmd < 4) |
|
|
2099 | cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */ |
|
|
2100 | else if (cmd == 5) // health |
2073 | { |
2101 | { |
2074 | ext = *data++; |
|
|
2075 | cmd = ext & 0x7f; |
|
|
2076 | |
|
|
2077 | if (cmd < 4) |
|
|
2078 | cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */ |
|
|
2079 | else if (cmd == 5) // health |
|
|
2080 | { |
|
|
2081 | cell->stat_width = 1; |
2102 | cell->stat_width = 1; |
2082 | cell->stat_hp = *data++; |
2103 | cell->stat_hp = *data++; |
2083 | } |
|
|
2084 | else if (cmd == 6) // monster width |
|
|
2085 | cell->stat_width = *data++ + 1; |
|
|
2086 | else if (cmd == 0x47) |
|
|
2087 | { |
|
|
2088 | if (*data == 1) cell->player = data [1]; |
|
|
2089 | else if (*data == 2) cell->player = data [2] + (data [1] << 8); |
|
|
2090 | else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16); |
|
|
2091 | else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24); |
|
|
2092 | |
|
|
2093 | data += *data + 1; |
|
|
2094 | } |
|
|
2095 | else if (cmd == 8) // cell flags |
|
|
2096 | cell->flags = *data++; |
|
|
2097 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
2098 | data += *data + 1; |
|
|
2099 | else |
|
|
2100 | data++; |
|
|
2101 | } |
2104 | } |
2102 | while (ext & 0x80); |
2105 | else if (cmd == 6) // monster width |
|
|
2106 | cell->stat_width = *data++ + 1; |
|
|
2107 | else if (cmd == 0x47) |
|
|
2108 | { |
|
|
2109 | if (*data == 1) cell->player = data [1]; |
|
|
2110 | else if (*data == 2) cell->player = data [2] + (data [1] << 8); |
|
|
2111 | else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16); |
|
|
2112 | else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24); |
|
|
2113 | |
|
|
2114 | data += *data + 1; |
|
|
2115 | } |
|
|
2116 | else if (cmd == 8) // cell flags |
|
|
2117 | cell->flags = *data++; |
|
|
2118 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
2119 | data += *data + 1; |
|
|
2120 | else |
|
|
2121 | data++; |
2103 | } |
2122 | } |
2104 | else |
2123 | while (ext & 0x80); |
2105 | cell->darkness = *data++ + 1; |
|
|
2106 | } |
2124 | } |
2107 | |
2125 | |
2108 | for (z = 0; z <= 2; ++z) |
2126 | for (z = 0; z <= 2; ++z) |
2109 | if (flags & (4 >> z)) |
2127 | if (flags & (4 >> z)) |
2110 | { |
2128 | { |
… | |
… | |
2184 | | (b << 16) |
2202 | | (b << 16) |
2185 | | (a << 24); |
2203 | | (a << 24); |
2186 | } |
2204 | } |
2187 | } |
2205 | } |
2188 | |
2206 | |
2189 | RETVAL = map_sv; |
2207 | RETVAL = map_sv; |
2190 | } |
2208 | } |
2191 | OUTPUT: |
2209 | OUTPUT: |
2192 | RETVAL |
2210 | RETVAL |
2193 | |
2211 | |
2194 | void |
2212 | void |
2195 | 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) |
2213 | 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) |
2196 | CODE: |
2214 | CODE: |
2197 | { |
2215 | { |
2198 | int x, y, z; |
2216 | int x, y, z; |
2199 | |
2217 | |
2200 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
|
|
2201 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
|
|
2202 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) |
2218 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k), also, static! |
2203 | smooth_key skey; |
|
|
2204 | int pl_x, pl_y; |
2219 | int pl_x, pl_y; |
2205 | maptex pl_tex; |
2220 | maptex pl_tex; |
2206 | rc_t *rc = rc_alloc (); |
2221 | rc_t rc; |
2207 | rc_t *rc_ov = rc_alloc (); |
2222 | rc_t rc_ov; |
2208 | rc_key_t key; |
2223 | rc_key_t key; |
2209 | rc_array_t *arr; |
2224 | rc_t::array_t *arr; |
2210 | |
2225 | |
2211 | pl_tex.name = 0; |
2226 | pl_tex.name = 0; |
2212 | |
2227 | |
2213 | // that's current max. sorry. |
2228 | // that's current max. sorry. |
2214 | if (sw > 255) sw = 255; |
2229 | if (sw > 255) sw = 255; |
2215 | if (sh > 255) sh = 255; |
2230 | if (sh > 255) sh = 255; |
2216 | |
|
|
2217 | // clear key, in case of extra padding |
|
|
2218 | memset (&skey, 0, sizeof (skey)); |
|
|
2219 | |
2231 | |
2220 | memset (&key, 0, sizeof (key)); |
2232 | memset (&key, 0, sizeof (key)); |
2221 | key.r = 255; |
2233 | key.r = 255; |
2222 | key.g = 255; |
2234 | key.g = 255; |
2223 | key.b = 255; |
2235 | key.b = 255; |
… | |
… | |
2229 | my += self->y; |
2241 | my += self->y; |
2230 | |
2242 | |
2231 | // first pass: determine smooth_max |
2243 | // first pass: determine smooth_max |
2232 | // rather ugly, if you ask me |
2244 | // rather ugly, if you ask me |
2233 | // could also be stored inside mapcell and updated on change |
2245 | // could also be stored inside mapcell and updated on change |
2234 | memset (smooth_max, 0, sizeof (smooth_max)); |
2246 | memset (smooth_max, 0, sizeof (smooth_max[0]) * (sh + 1)); |
2235 | |
2247 | |
2236 | for (y = 0; y < sh; y++) |
2248 | for (y = 0; y < sh; y++) |
2237 | if (0 <= y + my && y + my < self->rows) |
2249 | if (0 <= y + my && y + my < self->rows) |
2238 | { |
2250 | { |
2239 | maprow *row = self->row + (y + my); |
2251 | maprow *row = self->row + (y + my); |
… | |
… | |
2254 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2266 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2255 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2267 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2256 | |
2268 | |
2257 | for (z = 0; z <= 2; z++) |
2269 | for (z = 0; z <= 2; z++) |
2258 | { |
2270 | { |
2259 | memset (smooth_level, 0, sizeof (smooth_level)); |
2271 | std::bitset<256> smooth_level; // one bit for every possible smooth level |
|
|
2272 | smooth_key skey; |
|
|
2273 | smooth_hash smooth; |
2260 | key.texname = -1; |
2274 | key.texname = -1; |
2261 | |
2275 | |
2262 | for (y = 0; y < sh; y++) |
2276 | for (y = 0; y < sh; y++) |
2263 | if (0 <= y + my && y + my < self->rows) |
2277 | if (0 <= y + my && y + my < self->rows) |
2264 | { |
2278 | { |
… | |
… | |
2281 | |
2295 | |
2282 | if (!tex.name) |
2296 | if (!tex.name) |
2283 | tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ |
2297 | tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ |
2284 | |
2298 | |
2285 | key.texname = tex.name; |
2299 | key.texname = tex.name; |
2286 | arr = rc_array (rc, &key); |
2300 | arr = &rc.array (key); |
2287 | } |
2301 | } |
2288 | |
2302 | |
2289 | px = (x + 1) * Th - tex.w; |
2303 | px = (x + 1) * Th - tex.w; |
2290 | py = (y + 1) * Tw - tex.h; |
2304 | py = (y + 1) * Tw - tex.h; |
2291 | |
2305 | |
2292 | if (expect_false (cell->player == player) && expect_false (z == 2)) |
2306 | if (ecb_expect_false (cell->player == player) && ecb_expect_false (z == 2)) |
2293 | { |
2307 | { |
2294 | pl_x = px; |
2308 | pl_x = px; |
2295 | pl_y = py; |
2309 | pl_y = py; |
2296 | pl_tex = tex; |
2310 | pl_tex = tex; |
2297 | continue; |
2311 | continue; |
2298 | } |
2312 | } |
2299 | |
2313 | |
2300 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
2314 | arr->t2f_v3f (0 , 0 , px , py , 0); |
2301 | rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); |
2315 | arr->t2f_v3f (0 , tex.t, px , py + tex.h, 0); |
2302 | rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); |
2316 | arr->t2f_v3f (tex.s, tex.t, px + tex.w, py + tex.h, 0); |
2303 | rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); |
2317 | arr->t2f_v3f (tex.s, 0 , px + tex.w, py , 0); |
2304 | |
2318 | |
2305 | // update smooth hash |
2319 | // update smooth hash |
2306 | if (tex.smoothtile) |
2320 | if (tex.smoothtile) |
2307 | { |
2321 | { |
2308 | skey.tile = tex.smoothtile; |
2322 | skey.tile = tex.smoothtile; |
2309 | skey.level = tex.smoothlevel; |
2323 | skey.level = tex.smoothlevel; |
2310 | |
2324 | |
2311 | smooth_level [tex.smoothlevel >> 5] |= ((uint32_t)1) << (tex.smoothlevel & 31); |
2325 | smooth_level[tex.smoothlevel] = 1; |
2312 | |
2326 | |
2313 | // add bits to current tile and all neighbours. skey.x|y is |
2327 | // add bits to current tile and all neighbours. skey.x|y is |
2314 | // shifted +1|+1 so we always stay positive. |
2328 | // shifted +1|+1 so we always stay positive. |
2315 | |
2329 | |
2316 | // bits is ___n cccc CCCC bbbb |
2330 | // bits is ___n cccc CCCC bbbb |
… | |
… | |
2324 | |
2338 | |
2325 | // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· |
2339 | // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· |
2326 | // ·· ·· ·┏ ┓· |
2340 | // ·· ·· ·┏ ┓· |
2327 | |
2341 | |
2328 | // full tile |
2342 | // full tile |
2329 | skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x1000); |
2343 | skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x1000); |
2330 | |
2344 | |
2331 | // borders |
2345 | // borders |
2332 | skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0091); |
2346 | skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0091); |
2333 | skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0032); |
2347 | skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0032); |
2334 | skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0064); |
2348 | skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0064); |
2335 | skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, &skey, 0x00c8); |
2349 | skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, skey, 0x00c8); |
2336 | |
2350 | |
2337 | // corners |
2351 | // corners |
2338 | skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0100); |
2352 | skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0100); |
2339 | skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0200); |
2353 | skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0200); |
2340 | skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400); |
2354 | skey.x = x ; skey.y = y ; smooth_or_bits (smooth, skey, 0x0400); |
2341 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); |
2355 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, skey, 0x0800); |
2342 | } |
2356 | } |
2343 | } |
2357 | } |
2344 | |
2358 | |
2345 | if (expect_false (z == 2) && expect_false (cell->flags)) |
2359 | if (ecb_expect_false (z == 2) && ecb_expect_false (cell->flags)) |
2346 | { |
2360 | { |
2347 | // overlays such as the speech bubble, probably more to come |
2361 | // overlays such as the speech bubble, probably more to come |
2348 | if (cell->flags & 1) |
2362 | if (cell->flags & 1) |
2349 | { |
2363 | { |
2350 | rc_key_t key_ov = key; |
2364 | rc_key_t key_ov = key; |
2351 | maptex tex = self->tex [TEXID_SPEECH]; |
2365 | maptex tex = self->tex[TEXID_SPEECH]; |
2352 | rc_array_t *arr; |
|
|
2353 | int px = x * Tw + Tw * 2 / 32; |
2366 | int px = x * Tw + Tw * 2 / 32; |
2354 | int py = y * Th - Th * 6 / 32; |
2367 | int py = y * Th - Th * 6 / 32; |
2355 | |
2368 | |
2356 | key_ov.texname = tex.name; |
2369 | key_ov.texname = tex.name; |
2357 | arr = rc_array (rc_ov, &key_ov); |
2370 | rc_t::array_t &arr = rc_ov.array (key_ov); |
2358 | |
2371 | |
2359 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
2372 | arr.t2f_v3f (0 , 0 , px , py , 0); |
2360 | rc_t2f_v3f (arr, 0 , tex.t, px , py + Th, 0); |
2373 | arr.t2f_v3f (0 , tex.t, px , py + Th, 0); |
2361 | rc_t2f_v3f (arr, tex.s, tex.t, px + Tw, py + Th, 0); |
2374 | arr.t2f_v3f (tex.s, tex.t, px + Tw, py + Th, 0); |
2362 | rc_t2f_v3f (arr, tex.s, 0 , px + Tw, py , 0); |
2375 | arr.t2f_v3f (tex.s, 0 , px + Tw, py , 0); |
2363 | } |
2376 | } |
2364 | } |
2377 | } |
2365 | } |
2378 | } |
2366 | } |
2379 | } |
2367 | |
2380 | |
2368 | rc_draw (rc); |
2381 | rc.draw (); |
2369 | rc_clear (rc); |
2382 | rc.clear (); |
2370 | |
2383 | |
2371 | // go through all smoothlevels, lowest to highest, then draw. |
2384 | // go through all smoothlevels, lowest to highest, then draw. |
2372 | // this is basically counting sort |
2385 | // this is basically counting sort |
2373 | { |
2386 | { |
2374 | int w, b; |
2387 | int w, b; |
2375 | |
2388 | |
2376 | glEnable (GL_TEXTURE_2D); |
2389 | glEnable (GL_TEXTURE_2D); |
2377 | glBegin (GL_QUADS); |
2390 | glBegin (GL_QUADS); |
2378 | for (w = 0; w < 256 / 32; ++w) |
2391 | for (int level = 0; level < smooth_level.size (); ++level) |
|
|
2392 | if (smooth_level[level]) |
|
|
2393 | for (auto &&it = smooth.begin (); it != smooth.end (); ++it) |
2379 | { |
2394 | { |
2380 | uint32_t smask = smooth_level [w]; |
2395 | smooth_key &skey = it->first; |
2381 | if (smask) |
2396 | IV bits = it->second; |
2382 | for (b = 0; b < 32; ++b) |
2397 | |
2383 | if (smask & (((uint32_t)1) << b)) |
2398 | if (!(bits & 0x1000) |
|
|
2399 | && skey.level == level |
|
|
2400 | && level > smooth_max [skey.x][skey.y]) |
2384 | { |
2401 | { |
2385 | int level = (w << 5) | b; |
2402 | maptex tex = self->tex [skey.tile]; |
|
|
2403 | int px = (((int)skey.x) - 1) * Tw; |
|
|
2404 | int py = (((int)skey.y) - 1) * Th; |
|
|
2405 | int border = bits & 15; |
|
|
2406 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
|
|
2407 | float dx = tex.s * .0625f; // 16 images/row |
|
|
2408 | float dy = tex.t * .5f ; // 2 images/column |
|
|
2409 | |
2386 | HE *he; |
2410 | if (tex.name) |
2387 | |
|
|
2388 | hv_iterinit (smooth); |
|
|
2389 | while ((he = hv_iternext (smooth))) |
|
|
2390 | { |
2411 | { |
2391 | smooth_key *skey = (smooth_key *)HeKEY (he); |
2412 | // this time avoiding texture state changes |
2392 | IV bits = SvIVX (HeVAL (he)); |
2413 | // save gobs of state changes. |
2393 | |
2414 | if (key.texname != tex.name) |
2394 | if (!(bits & 0x1000) |
|
|
2395 | && skey->level == level |
|
|
2396 | && level > smooth_max [skey->x][skey->y]) |
|
|
2397 | { |
2415 | { |
2398 | maptex tex = self->tex [skey->tile]; |
|
|
2399 | int px = (((int)skey->x) - 1) * Tw; |
|
|
2400 | int py = (((int)skey->y) - 1) * Th; |
|
|
2401 | int border = bits & 15; |
|
|
2402 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
|
|
2403 | float dx = tex.s * .0625f; // 16 images/row |
|
|
2404 | float dy = tex.t * .5f ; // 2 images/column |
|
|
2405 | |
|
|
2406 | if (tex.name) |
|
|
2407 | { |
|
|
2408 | // this time avoiding texture state changes |
|
|
2409 | // save gobs of state changes. |
|
|
2410 | if (key.texname != tex.name) |
|
|
2411 | { |
|
|
2412 | self->tex [skey->tile].unused = 0; |
2416 | self->tex [skey.tile].unused = 0; |
2413 | |
2417 | |
2414 | glEnd (); |
2418 | glEnd (); |
2415 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
2419 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
2416 | glBegin (GL_QUADS); |
2420 | glBegin (GL_QUADS); |
2417 | } |
2421 | } |
2418 | |
2422 | |
2419 | if (border) |
2423 | if (border) |
2420 | { |
2424 | { |
2421 | float ox = border * dx; |
2425 | float ox = border * dx; |
2422 | |
2426 | |
2423 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
2427 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
2424 | glTexCoord2f (ox , dy ); glVertex2i (px , py + Th); |
2428 | glTexCoord2f (ox , dy ); glVertex2i (px , py + Th); |
2425 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); |
2429 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); |
2426 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); |
2430 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); |
2427 | } |
2431 | } |
2428 | |
2432 | |
2429 | if (corner) |
2433 | if (corner) |
2430 | { |
2434 | { |
2431 | float ox = corner * dx; |
2435 | float ox = corner * dx; |
2432 | |
2436 | |
2433 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
2437 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
2434 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th); |
2438 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th); |
2435 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th); |
2439 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th); |
2436 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py ); |
2440 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py ); |
2437 | } |
|
|
2438 | } |
|
|
2439 | } |
2441 | } |
2440 | } |
2442 | } |
2441 | } |
2443 | } |
2442 | } |
2444 | } |
2443 | |
2445 | |
2444 | glEnd (); |
2446 | glEnd (); |
2445 | glDisable (GL_TEXTURE_2D); |
2447 | glDisable (GL_TEXTURE_2D); |
2446 | key.texname = -1; |
2448 | key.texname = -1; |
2447 | } |
2449 | } |
2448 | |
|
|
2449 | hv_clear (smooth); |
|
|
2450 | } |
2450 | } |
2451 | |
2451 | |
2452 | if (pl_tex.name) |
2452 | if (pl_tex.name) |
2453 | { |
2453 | { |
2454 | maptex tex = pl_tex; |
2454 | maptex tex = pl_tex; |
2455 | int px = pl_x + sdx; |
2455 | int px = pl_x + sdx; |
2456 | int py = pl_y + sdy; |
2456 | int py = pl_y + sdy; |
2457 | |
2457 | |
2458 | key.texname = tex.name; |
2458 | key.texname = tex.name; |
2459 | arr = rc_array (rc, &key); |
2459 | rc_t::array_t &arr = rc.array (key); |
2460 | |
2460 | |
2461 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
2461 | arr.t2f_v3f (0 , 0 , px , py , 0); |
2462 | rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); |
2462 | arr.t2f_v3f (0 , tex.t, px , py + tex.h, 0); |
2463 | rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); |
2463 | arr.t2f_v3f (tex.s, tex.t, px + tex.w, py + tex.h, 0); |
2464 | rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); |
2464 | arr.t2f_v3f (tex.s, 0 , px + tex.w, py , 0); |
2465 | |
2465 | |
2466 | rc_draw (rc); |
2466 | rc.draw (); |
2467 | } |
2467 | } |
2468 | |
2468 | |
2469 | rc_draw (rc_ov); |
2469 | rc_ov.draw (); |
2470 | rc_clear (rc_ov); |
2470 | rc_ov.clear (); |
2471 | |
2471 | |
2472 | glDisable (GL_BLEND); |
2472 | glDisable (GL_BLEND); |
2473 | rc_free (rc); |
|
|
2474 | rc_free (rc_ov); |
|
|
2475 | |
2473 | |
2476 | // top layer: overlays such as the health bar |
2474 | // top layer: overlays such as the health bar |
2477 | for (y = 0; y < sh; y++) |
2475 | for (y = 0; y < sh; y++) |
2478 | if (0 <= y + my && y + my < self->rows) |
2476 | if (0 <= y + my && y + my < self->rows) |
2479 | { |
2477 | { |
… | |
… | |
2485 | mapcell *cell = row->col + (x + mx - row->c0); |
2483 | mapcell *cell = row->col + (x + mx - row->c0); |
2486 | |
2484 | |
2487 | int px = x * Tw; |
2485 | int px = x * Tw; |
2488 | int py = y * Th; |
2486 | int py = y * Th; |
2489 | |
2487 | |
2490 | if (expect_false (cell->player == player)) |
2488 | if (ecb_expect_false (cell->player == player)) |
2491 | { |
2489 | { |
2492 | px += sdx; |
2490 | px += sdx; |
2493 | py += sdy; |
2491 | py += sdy; |
2494 | } |
2492 | } |
2495 | |
2493 | |
… | |
… | |
2723 | else |
2721 | else |
2724 | *data++ = 0; |
2722 | *data++ = 0; |
2725 | } |
2723 | } |
2726 | } |
2724 | } |
2727 | |
2725 | |
2728 | /* if size is w*h + 5 then no data has been found */ |
2726 | /* if size is w*h + 5 then no data has been found */ |
2729 | if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) |
2727 | if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) |
2730 | { |
2728 | { |
2731 | SvPOK_only (data_sv); |
2729 | SvPOK_only (data_sv); |
2732 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
2730 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
2733 | } |
2731 | } |
2734 | |
2732 | |
2735 | RETVAL = data_sv; |
2733 | RETVAL = data_sv; |
2736 | } |
2734 | } |
2737 | OUTPUT: |
2735 | OUTPUT: |
2738 | RETVAL |
2736 | RETVAL |
2739 | |
2737 | |
2740 | void |
2738 | void |
… | |
… | |
2747 | STRLEN len; |
2745 | STRLEN len; |
2748 | uint8_t *data, *end; |
2746 | uint8_t *data, *end; |
2749 | |
2747 | |
2750 | len = SvLEN (data_sv); |
2748 | len = SvLEN (data_sv); |
2751 | SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more |
2749 | SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more |
2752 | data = SvPVbyte_nolen (data_sv); |
2750 | data = (uint8_t *)SvPVbyte_nolen (data_sv); |
2753 | end = data + len + 8; |
2751 | end = data + len + 8; |
2754 | |
2752 | |
2755 | if (len < 5) |
2753 | if (len < 5) |
2756 | XSRETURN_EMPTY; |
2754 | XSRETURN_EMPTY; |
2757 | |
2755 | |
… | |
… | |
2818 | } |
2816 | } |
2819 | |
2817 | |
2820 | MODULE = Deliantra::Client PACKAGE = DC::RW |
2818 | MODULE = Deliantra::Client PACKAGE = DC::RW |
2821 | |
2819 | |
2822 | DC::RW |
2820 | DC::RW |
2823 | new (SV *class, SV *data_sv) |
2821 | new (SV *klass, SV *data_sv) |
2824 | CODE: |
2822 | CODE: |
2825 | { |
2823 | { |
2826 | STRLEN datalen; |
2824 | STRLEN datalen; |
2827 | char *data = SvPVbyte (data_sv, datalen); |
2825 | char *data = SvPVbyte (data_sv, datalen); |
2828 | |
2826 | |
… | |
… | |
2830 | } |
2828 | } |
2831 | OUTPUT: |
2829 | OUTPUT: |
2832 | RETVAL |
2830 | RETVAL |
2833 | |
2831 | |
2834 | DC::RW |
2832 | DC::RW |
2835 | new_from_file (SV *class, const char *path, const char *mode = "rb") |
2833 | new_from_file (SV *klass, const char *path, const char *mode = "rb") |
2836 | CODE: |
2834 | CODE: |
2837 | RETVAL = SDL_RWFromFile (path, mode); |
2835 | RETVAL = SDL_RWFromFile (path, mode); |
2838 | OUTPUT: |
2836 | OUTPUT: |
2839 | RETVAL |
2837 | RETVAL |
2840 | |
2838 | |
… | |
… | |
2949 | #else |
2947 | #else |
2950 | XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); |
2948 | XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); |
2951 | #endif |
2949 | #endif |
2952 | |
2950 | |
2953 | DC::MixChunk |
2951 | DC::MixChunk |
2954 | new (SV *class, DC::RW rwops) |
2952 | new (SV *klass, DC::RW rwops) |
2955 | CODE: |
2953 | CODE: |
2956 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2954 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2957 | OUTPUT: |
2955 | OUTPUT: |
2958 | RETVAL |
2956 | RETVAL |
2959 | |
2957 | |
… | |
… | |
3029 | RETVAL = Mix_PlayingMusic (); |
3027 | RETVAL = Mix_PlayingMusic (); |
3030 | OUTPUT: |
3028 | OUTPUT: |
3031 | RETVAL |
3029 | RETVAL |
3032 | |
3030 | |
3033 | DC::MixMusic |
3031 | DC::MixMusic |
3034 | new (SV *class, DC::RW rwops) |
3032 | new (SV *klass, DC::RW rwops) |
3035 | CODE: |
3033 | CODE: |
3036 | RETVAL = Mix_LoadMUS_RW (rwops); |
3034 | RETVAL = Mix_LoadMUS_RW (rwops); |
3037 | OUTPUT: |
3035 | OUTPUT: |
3038 | RETVAL |
3036 | RETVAL |
3039 | |
3037 | |
… | |
… | |
3192 | gl.BlendFuncSeparateEXT = 0; |
3190 | gl.BlendFuncSeparateEXT = 0; |
3193 | |
3191 | |
3194 | void |
3192 | void |
3195 | apple_nvidia_bug (int enable) |
3193 | apple_nvidia_bug (int enable) |
3196 | |
3194 | |
3197 | char * |
3195 | const char * |
3198 | gl_vendor () |
3196 | gl_vendor () |
3199 | CODE: |
3197 | CODE: |
3200 | RETVAL = (char *)glGetString (GL_VENDOR); |
3198 | RETVAL = (const char *)glGetString (GL_VENDOR); |
3201 | OUTPUT: |
3199 | OUTPUT: |
3202 | RETVAL |
3200 | RETVAL |
3203 | |
3201 | |
3204 | char * |
3202 | const char * |
3205 | gl_version () |
3203 | gl_version () |
3206 | CODE: |
3204 | CODE: |
3207 | RETVAL = (char *)glGetString (GL_VERSION); |
3205 | RETVAL = (const char *)glGetString (GL_VERSION); |
3208 | OUTPUT: |
3206 | OUTPUT: |
3209 | RETVAL |
3207 | RETVAL |
3210 | |
3208 | |
3211 | char * |
3209 | const char * |
3212 | gl_extensions () |
3210 | gl_extensions () |
3213 | CODE: |
3211 | CODE: |
3214 | RETVAL = (char *)glGetString (GL_EXTENSIONS); |
3212 | RETVAL = (const char *)glGetString (GL_EXTENSIONS); |
3215 | OUTPUT: |
3213 | OUTPUT: |
3216 | RETVAL |
3214 | RETVAL |
3217 | |
3215 | |
3218 | const char *glGetString (GLenum pname) |
3216 | const char *glGetString (GLenum pname) |
|
|
3217 | CODE: |
|
|
3218 | RETVAL = (const char *)glGetString (pname); |
|
|
3219 | OUTPUT: |
|
|
3220 | RETVAL |
3219 | |
3221 | |
3220 | GLint glGetInteger (GLenum pname) |
3222 | GLint glGetInteger (GLenum pname) |
3221 | CODE: |
3223 | CODE: |
3222 | glGetIntegerv (pname, &RETVAL); |
3224 | glGetIntegerv (pname, &RETVAL); |
3223 | OUTPUT: |
3225 | OUTPUT: |
… | |
… | |
3426 | |
3428 | |
3427 | void |
3429 | void |
3428 | find_widget (SV *self, NV x, NV y) |
3430 | find_widget (SV *self, NV x, NV y) |
3429 | PPCODE: |
3431 | PPCODE: |
3430 | { |
3432 | { |
3431 | if (within_widget (self, x, y)) |
3433 | if (within_widget (self, x, y)) |
3432 | XPUSHs (self); |
3434 | XPUSHs (self); |
3433 | } |
3435 | } |
3434 | |
3436 | |
3435 | BOOT: |
3437 | BOOT: |
3436 | { |
3438 | { |
… | |
… | |
3444 | |
3446 | |
3445 | void |
3447 | void |
3446 | draw (SV *self) |
3448 | draw (SV *self) |
3447 | CODE: |
3449 | CODE: |
3448 | { |
3450 | { |
3449 | HV *hv; |
3451 | HV *hv; |
3450 | SV **svp; |
3452 | SV **svp; |
3451 | NV x, y, w, h; |
3453 | NV x, y, w, h; |
3452 | SV *draw_x_sv = GvSV (draw_x_gv); |
3454 | SV *draw_x_sv = GvSV (draw_x_gv); |
3453 | SV *draw_y_sv = GvSV (draw_y_gv); |
3455 | SV *draw_y_sv = GvSV (draw_y_gv); |
3454 | SV *draw_w_sv = GvSV (draw_w_gv); |
3456 | SV *draw_w_sv = GvSV (draw_w_gv); |
3455 | SV *draw_h_sv = GvSV (draw_h_gv); |
3457 | SV *draw_h_sv = GvSV (draw_h_gv); |