… | |
… | |
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 */ |
… | |
… | |
99 | |
97 | |
100 | #define KMOD_LRAM 0x10000 // our extension |
98 | #define KMOD_LRAM 0x10000 // our extension |
101 | |
99 | |
102 | #define TEXID_SPEECH 1 |
100 | #define TEXID_SPEECH 1 |
103 | #define TEXID_NOFACE 2 |
101 | #define TEXID_NOFACE 2 |
|
|
102 | |
|
|
103 | static char * |
|
|
104 | fast_sv_grow (SV *sv, STRLEN need) |
|
|
105 | { |
|
|
106 | STRLEN len = SvLEN (sv); |
|
|
107 | STRLEN want = SvCUR (sv) + need; |
|
|
108 | |
|
|
109 | if (ecb_expect_false (len < want)) |
|
|
110 | { |
|
|
111 | do |
|
|
112 | len *= 2; |
|
|
113 | while (len < want); |
|
|
114 | |
|
|
115 | sv_grow (sv, len); |
|
|
116 | } |
|
|
117 | |
|
|
118 | SvCUR_set (sv, want); |
|
|
119 | return SvEND (sv) - need; |
|
|
120 | } |
104 | |
121 | |
105 | static AV *texture_av; |
122 | static AV *texture_av; |
106 | |
123 | |
107 | static struct |
124 | static struct |
108 | { |
125 | { |
… | |
… | |
165 | { |
182 | { |
166 | GSList *attrs = run->item->analysis.extra_attrs; |
183 | GSList *attrs = run->item->analysis.extra_attrs; |
167 | |
184 | |
168 | while (attrs) |
185 | while (attrs) |
169 | { |
186 | { |
170 | PangoAttribute *attr = attrs->data; |
187 | PangoAttribute *attr = (PangoAttribute *)attrs->data; |
171 | |
188 | |
172 | if (attr->klass->type == PANGO_ATTR_SHAPE) |
189 | if (attr->klass->type == PANGO_ATTR_SHAPE) |
173 | return 1; |
190 | return 1; |
174 | |
191 | |
175 | attrs = attrs->next; |
192 | attrs = attrs->next; |
176 | } |
193 | } |
177 | |
194 | |
178 | return 0; |
195 | return 0; |
179 | } |
196 | } |
180 | |
197 | |
181 | typedef struct cf_layout { |
198 | struct cf_layout { |
182 | PangoLayout *pl; |
199 | PangoLayout *pl; |
183 | float r, g, b, a; // default color for rgba mode |
200 | float r, g, b, a; // default color for rgba mode |
184 | int base_height; |
201 | int base_height; |
185 | DC__Font font; |
202 | DC__Font font; |
186 | rc_t *rc; |
203 | rc_t rc; |
187 | } *DC__Layout; |
204 | }; |
|
|
205 | |
|
|
206 | typedef cf_layout *DC__Layout; |
188 | |
207 | |
189 | static DC__Font default_font; |
208 | static DC__Font default_font; |
190 | static PangoContext *opengl_context; |
209 | static PangoContext *opengl_context; |
191 | static PangoFontMap *opengl_fontmap; |
210 | static PangoFontMap *opengl_fontmap; |
192 | |
211 | |
193 | static void |
212 | static void |
194 | substitute_func (FcPattern *pattern, gpointer data) |
213 | substitute_func (FcPattern *pattern, gpointer data) |
195 | { |
214 | { |
196 | FcPatternAddBool (pattern, FC_HINTING, 1); |
215 | FcPatternAddBool (pattern, FC_HINTING, 1); |
197 | #ifdef FC_HINT_STYLE |
216 | #ifdef FC_HINT_STYLE |
198 | FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); |
217 | FcPatternAddInteger (pattern, FC_HINT_STYLE, FC_HINT_FULL); |
199 | #endif |
218 | #endif |
200 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
219 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
201 | } |
220 | } |
202 | |
221 | |
203 | static void |
222 | static void |
… | |
… | |
230 | |
249 | |
231 | *w = rect.width; |
250 | *w = rect.width; |
232 | *h = rect.height; |
251 | *h = rect.height; |
233 | } |
252 | } |
234 | |
253 | |
|
|
254 | ///////////////////////////////////////////////////////////////////////////// |
|
|
255 | |
235 | typedef uint16_t tileid; |
256 | typedef uint16_t tileid; |
236 | typedef uint16_t faceid; |
257 | typedef uint16_t faceid; |
237 | |
258 | |
238 | typedef struct { |
259 | struct maptex |
|
|
260 | { |
239 | GLuint name; |
261 | GLuint name; |
240 | int w, h; |
262 | int w, h; |
241 | float s, t; |
263 | float s, t; |
242 | uint8_t r, g, b, a; |
264 | uint8_t r, g, b, a; |
243 | tileid smoothtile; |
265 | tileid smoothtile; |
244 | uint8_t smoothlevel; |
266 | uint8_t smoothlevel; |
245 | uint8_t unused; /* set to zero on use */ |
267 | uint8_t unused; /* set to zero on use */ |
246 | } maptex; |
268 | }; |
247 | |
269 | |
248 | typedef struct { |
270 | struct mapcell |
|
|
271 | { |
249 | uint32_t player; |
272 | uint32_t player; |
250 | tileid tile[3]; |
273 | tileid tile[3]; |
251 | uint16_t darkness; |
274 | uint16_t darkness; |
252 | uint8_t stat_width, stat_hp, flags, smoothmax; |
275 | uint8_t stat_width, stat_hp, flags, smoothmax; |
253 | } mapcell; |
276 | }; |
254 | |
277 | |
255 | typedef struct { |
278 | struct maprow |
|
|
279 | { |
256 | int32_t c0, c1; |
280 | int32_t c0, c1; |
257 | mapcell *col; |
281 | mapcell *col; |
258 | } maprow; |
282 | }; |
259 | |
283 | |
260 | typedef struct map { |
284 | struct mapgrid { |
261 | int x, y, w, h; |
285 | int x, y, w, h; |
262 | int ox, oy; /* offset to virtual global coordinate system */ |
286 | int ox, oy; /* offset to virtual global coordinate system */ |
263 | int faces; tileid *face2tile; // [faceid] |
287 | int faces; tileid *face2tile; // [faceid] |
264 | int texs; maptex *tex; // [tileid] |
288 | int texs; maptex *tex; // [tileid] |
265 | |
289 | |
266 | int32_t rows; |
290 | int32_t rows; |
267 | maprow *row; |
291 | maprow *row; |
268 | } *DC__Map; |
292 | }; |
269 | |
293 | |
270 | static char * |
294 | typedef mapgrid *DC__Map; |
|
|
295 | |
|
|
296 | template<typename T> |
|
|
297 | static void |
271 | prepend (char *ptr, int sze, int inc) |
298 | prepend (T *&ptr, int sze, int inc) |
272 | { |
299 | { |
273 | char *p; |
300 | T *p; |
274 | |
301 | |
275 | New (0, p, sze + inc, char); |
302 | Newx (p, inc + sze, T); |
276 | Zero (p, inc, char); |
303 | Zero (p, inc, T); |
277 | Move (ptr, p + inc, sze, char); |
304 | Move (ptr, p + inc, sze, T); |
278 | Safefree (ptr); |
305 | Safefree (ptr); |
279 | |
306 | |
280 | return p; |
307 | ptr = p; |
281 | } |
308 | } |
282 | |
309 | |
283 | static char * |
310 | template<typename T> |
284 | append (char *ptr, int sze, int inc) |
|
|
285 | { |
|
|
286 | Renew (ptr, sze + inc, char); |
|
|
287 | Zero (ptr + sze, inc, char); |
|
|
288 | |
|
|
289 | return ptr; |
|
|
290 | } |
|
|
291 | |
|
|
292 | #define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
|
|
293 | #define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
|
|
294 | |
|
|
295 | 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 |
296 | need_facenum (struct map *self, faceid face) |
319 | need_facenum (struct mapgrid *self, faceid face) |
297 | { |
320 | { |
298 | while (self->faces <= face) |
321 | while (self->faces <= face) |
299 | { |
322 | { |
300 | Append (tileid, self->face2tile, self->faces, self->faces); |
323 | append (self->face2tile, self->faces, self->faces); |
301 | self->faces *= 2; |
324 | self->faces *= 2; |
302 | } |
325 | } |
303 | } |
326 | } |
304 | |
327 | |
305 | static void |
328 | static void |
306 | need_texid (struct map *self, int texid) |
329 | need_texid (struct mapgrid *self, int texid) |
307 | { |
330 | { |
308 | while (self->texs <= texid) |
331 | while (self->texs <= texid) |
309 | { |
332 | { |
310 | Append (maptex, self->tex, self->texs, self->texs); |
333 | append (self->tex, self->texs, self->texs); |
311 | self->texs *= 2; |
334 | self->texs *= 2; |
312 | } |
335 | } |
313 | } |
336 | } |
314 | |
337 | |
315 | static maprow * |
338 | static maprow * |
316 | map_get_row (DC__Map self, int y) |
339 | map_get_row (mapgrid *self, int y) |
317 | { |
340 | { |
318 | if (0 > y) |
341 | if (0 > y) |
319 | { |
342 | { |
320 | int extend = - y + MAP_EXTEND_Y; |
343 | int extend = - y + MAP_EXTEND_Y; |
321 | Prepend (maprow, self->row, self->rows, extend); |
344 | prepend (self->row, self->rows, extend); |
322 | |
345 | |
323 | self->rows += extend; |
346 | self->rows += extend; |
324 | self->y += extend; |
347 | self->y += extend; |
325 | y += extend; |
348 | y += extend; |
326 | } |
349 | } |
327 | else if (y >= self->rows) |
350 | else if (y >= self->rows) |
328 | { |
351 | { |
329 | int extend = y - self->rows + MAP_EXTEND_Y; |
352 | int extend = y - self->rows + MAP_EXTEND_Y; |
330 | Append (maprow, self->row, self->rows, extend); |
353 | append (self->row, self->rows, extend); |
331 | self->rows += extend; |
354 | self->rows += extend; |
332 | } |
355 | } |
333 | |
356 | |
334 | return self->row + y; |
357 | return self->row + y; |
335 | } |
358 | } |
… | |
… | |
345 | } |
368 | } |
346 | |
369 | |
347 | if (row->c0 > x) |
370 | if (row->c0 > x) |
348 | { |
371 | { |
349 | int extend = row->c0 - x + MAP_EXTEND_X; |
372 | int extend = row->c0 - x + MAP_EXTEND_X; |
350 | Prepend (mapcell, row->col, row->c1 - row->c0, extend); |
373 | prepend (row->col, row->c1 - row->c0, extend); |
351 | row->c0 -= extend; |
374 | row->c0 -= extend; |
352 | } |
375 | } |
353 | else if (x >= row->c1) |
376 | else if (x >= row->c1) |
354 | { |
377 | { |
355 | int extend = x - row->c1 + MAP_EXTEND_X; |
378 | int extend = x - row->c1 + MAP_EXTEND_X; |
356 | Append (mapcell, row->col, row->c1 - row->c0, extend); |
379 | append (row->col, row->c1 - row->c0, extend); |
357 | row->c1 += extend; |
380 | row->c1 += extend; |
358 | } |
381 | } |
359 | |
382 | |
360 | return row->col + (x - row->c0); |
383 | return row->col + (x - row->c0); |
361 | } |
384 | } |
362 | |
385 | |
363 | static mapcell * |
386 | static mapcell * |
364 | map_get_cell (DC__Map self, int x, int y) |
387 | map_get_cell (mapgrid *self, int x, int y) |
365 | { |
388 | { |
366 | return row_get_cell (map_get_row (self, y), x); |
389 | return row_get_cell (map_get_row (self, y), x); |
367 | } |
390 | } |
368 | |
391 | |
369 | static void |
392 | static void |
370 | map_clear (DC__Map self) |
393 | map_clear (mapgrid *self) |
371 | { |
394 | { |
372 | int r; |
395 | int r; |
373 | |
396 | |
374 | for (r = 0; r < self->rows; r++) |
397 | for (r = 0; r < self->rows; r++) |
375 | Safefree (self->row[r].col); |
398 | Safefree (self->row[r].col); |
… | |
… | |
393 | (cell)->flags = 0; \ |
416 | (cell)->flags = 0; \ |
394 | (cell)->player = 0; \ |
417 | (cell)->player = 0; \ |
395 | } while (0) |
418 | } while (0) |
396 | |
419 | |
397 | static void |
420 | static void |
398 | 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) |
399 | { |
422 | { |
400 | int x, y; |
423 | int x, y; |
401 | maprow *row; |
424 | maprow *row; |
402 | mapcell *cell; |
425 | mapcell *cell; |
403 | |
426 | |
… | |
… | |
420 | CELL_CLEAR (cell); |
443 | CELL_CLEAR (cell); |
421 | } |
444 | } |
422 | } |
445 | } |
423 | } |
446 | } |
424 | |
447 | |
425 | typedef struct { |
448 | struct smooth_key |
|
|
449 | { |
426 | tileid tile; |
450 | tileid tile; |
427 | uint8_t x, y, level; |
451 | uint8_t x, y, level; |
428 | } 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 | } |
429 | |
471 | |
430 | static void |
472 | static void |
431 | smooth_or_bits (HV *hv, smooth_key *key, IV bits) |
473 | smooth_or_bits (smooth_hash &h, smooth_key &key, IV bits) |
432 | { |
474 | { |
433 | SV **sv = hv_fetch (hv, (char *)key, sizeof (*key), 1); |
475 | auto &&it = h.find (key); |
434 | |
476 | |
435 | if (SvIOK (*sv)) |
477 | if (it == h.end ()) |
436 | SvIV_set (*sv, SvIVX (*sv) | bits); |
478 | h.insert (std::make_pair (key, bits)); |
437 | else |
479 | else |
438 | sv_setiv (*sv, bits); |
480 | it->second |= bits; |
439 | } |
481 | } |
440 | |
482 | |
441 | static void |
483 | static void |
442 | music_finished (void) |
484 | music_finished (void) |
443 | { |
485 | { |
… | |
… | |
460 | ev.code = 1; |
502 | ev.code = 1; |
461 | ev.data1 = (void *)(long)channel; |
503 | ev.data1 = (void *)(long)channel; |
462 | ev.data2 = 0; |
504 | ev.data2 = 0; |
463 | |
505 | |
464 | SDL_PushEvent ((SDL_Event *)&ev); |
506 | SDL_PushEvent ((SDL_Event *)&ev); |
|
|
507 | } |
|
|
508 | |
|
|
509 | // approximately divide by 255 |
|
|
510 | static unsigned int |
|
|
511 | div255 (unsigned int n) |
|
|
512 | { |
|
|
513 | return (n + (n >> 8)) >> 8; |
465 | } |
514 | } |
466 | |
515 | |
467 | static unsigned int |
516 | static unsigned int |
468 | minpot (unsigned int n) |
517 | minpot (unsigned int n) |
469 | { |
518 | { |
… | |
… | |
479 | n |= n >> 16; |
528 | n |= n >> 16; |
480 | |
529 | |
481 | return n + 1; |
530 | return n + 1; |
482 | } |
531 | } |
483 | |
532 | |
484 | static unsigned int |
|
|
485 | popcount (unsigned int n) |
|
|
486 | { |
|
|
487 | n -= (n >> 1) & 0x55555555U; |
|
|
488 | n = ((n >> 2) & 0x33333333U) + (n & 0x33333333U); |
|
|
489 | n = ((n >> 4) + n) & 0x0f0f0f0fU; |
|
|
490 | n *= 0x01010101U; |
|
|
491 | |
|
|
492 | return n >> 24; |
|
|
493 | } |
|
|
494 | |
|
|
495 | /* SDL should provide this, really. */ |
533 | /* SDL should provide this, really. */ |
496 | #define SDLK_MODIFIER_MIN 300 |
534 | #define SDLK_MODIFIER_MIN 300 |
497 | #define SDLK_MODIFIER_MAX 314 |
535 | #define SDLK_MODIFIER_MAX 314 |
498 | |
536 | |
499 | /******************************************************************************/ |
537 | /******************************************************************************/ |
… | |
… | |
552 | |
590 | |
553 | return mod; |
591 | return mod; |
554 | } |
592 | } |
555 | |
593 | |
556 | static void |
594 | static void |
557 | deliantra_main () |
595 | deliantra_main (SV *real_main) |
558 | { |
596 | { |
559 | char *argv[] = { 0 }; |
597 | dSP; |
560 | call_argv ("::main", G_DISCARD | G_VOID, argv); |
598 | |
|
|
599 | PUSHMARK (SP); |
|
|
600 | call_sv (real_main, G_DISCARD | G_VOID); |
561 | } |
601 | } |
562 | |
602 | |
563 | #ifdef __MACOSX__ |
603 | #ifdef __MACOSX__ |
|
|
604 | static SV *real_main; |
|
|
605 | |
564 | /* to due surprising braindamage on the side of SDL design, we |
606 | /* to due surprising braindamage on the side of SDL design, we |
565 | * do some mind-boggling hack here: SDL requires a custom main() |
607 | * do some mind-boggling hack here: SDL requires a custom main() |
566 | * on OS X, so... we provide one and call the original main(), which, |
608 | * on OS X, so... we provide one and call the original main(), which, |
567 | * due to share dlibrary magic, calls -lSDLmain's main, not perl's main, |
609 | * due to shared library magic, calls -lSDLmain's main, not perl's main, |
568 | * and which calls our main (== SDL_main) back. |
610 | * and which calls our main (== SDL_main) back. |
569 | */ |
611 | */ |
570 | extern C_LINKAGE int |
612 | extern C_LINKAGE int |
571 | main (int argc, char *argv[]) |
613 | main (int argc, char *argv[]) |
572 | { |
614 | { |
573 | deliantra_main (); |
615 | deliantra_main (real_main); |
574 | } |
616 | } |
575 | |
617 | |
576 | #undef main |
618 | #undef main |
577 | |
619 | |
578 | extern C_LINKAGE int main (int argc, char *argv[]); |
620 | extern C_LINKAGE int main (int argc, char *argv[]); |
579 | |
621 | |
580 | static void |
622 | static void |
581 | SDL_braino (void) |
623 | SDL_main_hack (SV *real_main_) |
582 | { |
624 | { |
|
|
625 | real_main = real_main_; |
|
|
626 | |
583 | char *argv[] = { "deliantra client", 0 }; |
627 | char *argv[] = { "deliantra client", 0 }; |
584 | (main) (1, argv); |
628 | (main) (1, argv); |
585 | } |
629 | } |
586 | #else |
630 | #else |
587 | static void |
631 | static void |
588 | SDL_braino (void) |
632 | SDL_main_hack (SV *real_main) |
589 | { |
633 | { |
590 | deliantra_main (); |
634 | deliantra_main (real_main); |
591 | } |
635 | } |
592 | #endif |
636 | #endif |
593 | |
637 | |
594 | MODULE = Deliantra::Client PACKAGE = DC |
638 | MODULE = Deliantra::Client PACKAGE = DC |
595 | |
639 | |
… | |
… | |
796 | |
840 | |
797 | const_iv (FOW_DARKNESS) |
841 | const_iv (FOW_DARKNESS) |
798 | # undef const_iv |
842 | # undef const_iv |
799 | }; |
843 | }; |
800 | |
844 | |
801 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
845 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
802 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
846 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
803 | |
847 | |
804 | assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK); |
848 | assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK); |
805 | assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE); |
849 | assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE); |
806 | } |
850 | } |
807 | |
851 | |
… | |
… | |
822 | |
866 | |
823 | NV ceil (NV x) |
867 | NV ceil (NV x) |
824 | |
868 | |
825 | IV minpot (UV n) |
869 | IV minpot (UV n) |
826 | |
870 | |
|
|
871 | UV ld32 (UV n) |
|
|
872 | CODE: |
|
|
873 | RETVAL = ecb_ld32 (n); |
|
|
874 | OUTPUT: |
|
|
875 | RETVAL |
|
|
876 | |
827 | IV popcount (UV n) |
877 | IV popcount (UV n) |
|
|
878 | CODE: |
|
|
879 | RETVAL = ecb_popcount32 (n); |
|
|
880 | OUTPUT: |
|
|
881 | RETVAL |
828 | |
882 | |
829 | NV distance (NV dx, NV dy) |
883 | NV distance (NV dx, NV dy) |
830 | CODE: |
884 | CODE: |
831 | RETVAL = pow (dx * dx + dy * dy, 0.5); |
885 | RETVAL = pow (dx * dx + dy * dy, 0.5); |
832 | OUTPUT: |
886 | OUTPUT: |
… | |
… | |
846 | #endif |
900 | #endif |
847 | } |
901 | } |
848 | |
902 | |
849 | char *SDL_GetError () |
903 | char *SDL_GetError () |
850 | |
904 | |
851 | void SDL_braino () |
905 | void SDL_main_hack (SV *real_main) |
|
|
906 | PROTOTYPE: & |
852 | |
907 | |
853 | int SDL_Init (U32 flags) |
908 | int SDL_Init (U32 flags) |
854 | |
909 | |
855 | int SDL_InitSubSystem (U32 flags) |
910 | int SDL_InitSubSystem (U32 flags) |
856 | |
911 | |
857 | void SDL_QuitSubSystem (U32 flags) |
912 | void SDL_QuitSubSystem (U32 flags) |
858 | |
913 | |
859 | void SDL_Quit () |
914 | void SDL_Quit () |
860 | |
915 | |
861 | int SDL_GL_SetAttribute (int attr, int value) |
916 | int SDL_GL_SetAttribute (int attr, int value) |
|
|
917 | C_ARGS: (SDL_GLattr)attr, value |
862 | |
918 | |
863 | int SDL_GL_GetAttribute (int attr) |
919 | int SDL_GL_GetAttribute (int attr) |
864 | CODE: |
920 | CODE: |
865 | if (SDL_GL_GetAttribute (attr, &RETVAL)) |
921 | if (SDL_GL_GetAttribute ((SDL_GLattr)attr, &RETVAL)) |
866 | XSRETURN_UNDEF; |
922 | XSRETURN_UNDEF; |
867 | OUTPUT: |
923 | OUTPUT: |
868 | RETVAL |
924 | RETVAL |
869 | |
925 | |
870 | void |
926 | void |
… | |
… | |
925 | ); |
981 | ); |
926 | |
982 | |
927 | if (RETVAL) |
983 | if (RETVAL) |
928 | { |
984 | { |
929 | av_clear (texture_av); |
985 | av_clear (texture_av); |
930 | |
|
|
931 | SDL_WM_SetCaption ("Deliantra MORPG Client " VERSION, "Deliantra"); |
|
|
932 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
986 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
933 | #include "glfunc.h" |
987 | #include "glfunc.h" |
934 | #undef GL_FUNC |
988 | #undef GL_FUNC |
935 | |
|
|
936 | if (!gl.ActiveTexture ) gl.ActiveTexture = gl.ActiveTextureARB; |
989 | if (!gl.ActiveTexture ) gl.ActiveTexture = gl.ActiveTextureARB; |
937 | if (!gl.MultiTexCoord2f) gl.MultiTexCoord2f = gl.MultiTexCoord2fARB; |
990 | if (!gl.MultiTexCoord2f) gl.MultiTexCoord2f = gl.MultiTexCoord2fARB; |
938 | } |
991 | } |
939 | } |
992 | } |
940 | OUTPUT: |
993 | OUTPUT: |
941 | RETVAL |
994 | RETVAL |
942 | |
995 | |
943 | void |
996 | void |
|
|
997 | SDL_WM_SetCaption (const char *title, const char *icon) |
|
|
998 | |
|
|
999 | void |
944 | SDL_GL_SwapBuffers () |
1000 | SDL_GL_SwapBuffers () |
945 | |
1001 | |
946 | char * |
1002 | char * |
947 | SDL_GetKeyName (int sym) |
1003 | SDL_GetKeyName (int sym) |
|
|
1004 | C_ARGS: (SDLKey)sym |
948 | |
1005 | |
949 | int |
1006 | int |
950 | SDL_GetAppState () |
1007 | SDL_GetAppState () |
951 | |
1008 | |
952 | int |
1009 | int |
953 | SDL_GetModState () |
1010 | SDL_GetModState () |
954 | |
1011 | |
|
|
1012 | int |
|
|
1013 | SDL_WaitEvent () |
|
|
1014 | C_ARGS: 0 |
|
|
1015 | |
955 | void |
1016 | void |
|
|
1017 | SDL_PumpEvents () |
|
|
1018 | |
|
|
1019 | void |
956 | poll_events () |
1020 | peep_events () |
957 | PPCODE: |
1021 | PPCODE: |
958 | { |
1022 | { |
959 | SDL_Event ev; |
1023 | SDL_Event ev; |
960 | |
1024 | |
961 | SDL_PumpEvents (); |
1025 | SDL_PumpEvents (); |
… | |
… | |
1042 | OUTPUT: |
1106 | OUTPUT: |
1043 | RETVAL |
1107 | RETVAL |
1044 | |
1108 | |
1045 | int |
1109 | int |
1046 | 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) |
1047 | POSTCALL: |
1111 | POSTCALL: |
1048 | Mix_HookMusicFinished (music_finished); |
1112 | Mix_HookMusicFinished (music_finished); |
1049 | Mix_ChannelFinished (channel_finished); |
1113 | Mix_ChannelFinished (channel_finished); |
1050 | |
1114 | |
1051 | void |
1115 | void |
1052 | Mix_QuerySpec () |
1116 | Mix_QuerySpec () |
… | |
… | |
1111 | add_font (char *file) |
1175 | add_font (char *file) |
1112 | CODE: |
1176 | CODE: |
1113 | RETVAL = FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
1177 | RETVAL = FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
1114 | OUTPUT: |
1178 | OUTPUT: |
1115 | RETVAL |
1179 | RETVAL |
|
|
1180 | |
|
|
1181 | void |
|
|
1182 | IMG_Init (int flags = IMG_INIT_JPG | IMG_INIT_PNG) |
|
|
1183 | |
|
|
1184 | # MIX_INIT_MP3 gives smpeg + libstdc++ + libgcc_s |
|
|
1185 | void |
|
|
1186 | Mix_Init (int flags = MIX_INIT_MOD | MIX_INIT_OGG) |
1116 | |
1187 | |
1117 | void |
1188 | void |
1118 | load_image_inline (SV *image_) |
1189 | load_image_inline (SV *image_) |
1119 | ALIAS: |
1190 | ALIAS: |
1120 | load_image_file = 1 |
1191 | load_image_file = 1 |
… | |
… | |
1166 | |
1237 | |
1167 | SDL_LockSurface (surface2); |
1238 | SDL_LockSurface (surface2); |
1168 | EXTEND (SP, 6); |
1239 | EXTEND (SP, 6); |
1169 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
1240 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
1170 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
1241 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
1171 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
1242 | PUSHs (sv_2mortal (newSVpvn ((const char *)surface2->pixels, surface2->h * surface2->pitch))); |
1172 | 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))); |
1173 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
1244 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
1174 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
1245 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
1175 | SDL_UnlockSurface (surface2); |
1246 | SDL_UnlockSurface (surface2); |
1176 | |
1247 | |
… | |
… | |
1248 | MODULE = Deliantra::Client PACKAGE = DC::Font |
1319 | MODULE = Deliantra::Client PACKAGE = DC::Font |
1249 | |
1320 | |
1250 | PROTOTYPES: DISABLE |
1321 | PROTOTYPES: DISABLE |
1251 | |
1322 | |
1252 | DC::Font |
1323 | DC::Font |
1253 | new_from_file (SV *class, char *path, int id = 0) |
1324 | new_from_file (SV *klass, char *path, int id = 0) |
1254 | CODE: |
1325 | CODE: |
1255 | { |
1326 | { |
1256 | int count; |
1327 | int count; |
1257 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
1328 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
1258 | RETVAL = pango_fc_font_description_from_pattern (pattern, 0); |
1329 | RETVAL = pango_fc_font_description_from_pattern (pattern, 0); |
… | |
… | |
1287 | PROTOTYPE: |
1358 | PROTOTYPE: |
1288 | CODE: |
1359 | CODE: |
1289 | tc_restore (); |
1360 | tc_restore (); |
1290 | |
1361 | |
1291 | DC::Layout |
1362 | DC::Layout |
1292 | new (SV *class) |
1363 | new (SV *klass) |
1293 | CODE: |
1364 | CODE: |
1294 | New (0, RETVAL, 1, struct cf_layout); |
1365 | RETVAL = new cf_layout; |
1295 | |
1366 | |
1296 | RETVAL->pl = pango_layout_new (opengl_context); |
1367 | RETVAL->pl = pango_layout_new (opengl_context); |
1297 | RETVAL->r = 1.; |
1368 | RETVAL->r = 1.; |
1298 | RETVAL->g = 1.; |
1369 | RETVAL->g = 1.; |
1299 | RETVAL->b = 1.; |
1370 | RETVAL->b = 1.; |
1300 | RETVAL->a = 1.; |
1371 | RETVAL->a = 1.; |
1301 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1372 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1302 | RETVAL->font = 0; |
1373 | RETVAL->font = 0; |
1303 | RETVAL->rc = rc_alloc (); |
|
|
1304 | |
1374 | |
1305 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1375 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1306 | layout_update_font (RETVAL); |
1376 | layout_update_font (RETVAL); |
1307 | OUTPUT: |
1377 | OUTPUT: |
1308 | RETVAL |
1378 | RETVAL |
1309 | |
1379 | |
1310 | void |
1380 | void |
1311 | DESTROY (DC::Layout self) |
1381 | DESTROY (DC::Layout self) |
1312 | CODE: |
1382 | CODE: |
1313 | g_object_unref (self->pl); |
1383 | g_object_unref (self->pl); |
1314 | rc_free (self->rc); |
|
|
1315 | Safefree (self); |
1384 | delete self; |
1316 | |
1385 | |
1317 | void |
1386 | void |
1318 | set_text (DC::Layout self, SV *text_) |
1387 | set_text (DC::Layout self, SV *text_) |
1319 | CODE: |
1388 | CODE: |
1320 | { |
1389 | { |
… | |
… | |
1446 | |
1515 | |
1447 | void |
1516 | void |
1448 | set_height (DC::Layout self, int base_height) |
1517 | set_height (DC::Layout self, int base_height) |
1449 | CODE: |
1518 | CODE: |
1450 | if (self->base_height != base_height) |
1519 | if (self->base_height != base_height) |
1451 | { |
1520 | { |
1452 | self->base_height = base_height; |
1521 | self->base_height = base_height; |
1453 | layout_update_font (self); |
1522 | layout_update_font (self); |
1454 | } |
1523 | } |
1455 | |
1524 | |
1456 | void |
1525 | void |
… | |
… | |
1574 | } |
1643 | } |
1575 | |
1644 | |
1576 | void |
1645 | void |
1577 | render (DC::Layout self, float x, float y, int flags = 0) |
1646 | render (DC::Layout self, float x, float y, int flags = 0) |
1578 | CODE: |
1647 | CODE: |
1579 | rc_clear (self->rc); |
1648 | self->rc.clear (); |
1580 | pango_opengl_render_layout_subpixel ( |
1649 | pango_opengl_render_layout_subpixel ( |
1581 | self->pl, |
1650 | self->pl, |
1582 | self->rc, |
1651 | &self->rc, |
1583 | x * PANGO_SCALE, y * PANGO_SCALE, |
1652 | x * PANGO_SCALE, y * PANGO_SCALE, |
1584 | self->r, self->g, self->b, self->a, |
1653 | self->r, self->g, self->b, self->a, |
1585 | flags |
1654 | flags |
1586 | ); |
1655 | ); |
1587 | // we assume that context_change actually clears/frees stuff |
1656 | // we assume that context_change actually clears/frees stuff |
… | |
… | |
1598 | gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
1667 | gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
1599 | GL_ONE , GL_ONE_MINUS_SRC_ALPHA); |
1668 | GL_ONE , GL_ONE_MINUS_SRC_ALPHA); |
1600 | glEnable (GL_ALPHA_TEST); |
1669 | glEnable (GL_ALPHA_TEST); |
1601 | glAlphaFunc (GL_GREATER, 7.f / 255.f); |
1670 | glAlphaFunc (GL_GREATER, 7.f / 255.f); |
1602 | |
1671 | |
1603 | rc_draw (self->rc); |
1672 | self->rc.draw (); |
1604 | |
1673 | |
1605 | glDisable (GL_ALPHA_TEST); |
1674 | glDisable (GL_ALPHA_TEST); |
1606 | glDisable (GL_BLEND); |
1675 | glDisable (GL_BLEND); |
1607 | glDisable (GL_TEXTURE_2D); |
1676 | glDisable (GL_TEXTURE_2D); |
1608 | } |
1677 | } |
… | |
… | |
1820 | MODULE = Deliantra::Client PACKAGE = DC::Map |
1889 | MODULE = Deliantra::Client PACKAGE = DC::Map |
1821 | |
1890 | |
1822 | PROTOTYPES: DISABLE |
1891 | PROTOTYPES: DISABLE |
1823 | |
1892 | |
1824 | DC::Map |
1893 | DC::Map |
1825 | new (SV *class) |
1894 | new (SV *klass) |
1826 | CODE: |
1895 | CODE: |
1827 | New (0, RETVAL, 1, struct map); |
1896 | New (0, RETVAL, 1, mapgrid); |
1828 | RETVAL->x = 0; |
1897 | RETVAL->x = 0; |
1829 | RETVAL->y = 0; |
1898 | RETVAL->y = 0; |
1830 | RETVAL->w = 0; |
1899 | RETVAL->w = 0; |
1831 | RETVAL->h = 0; |
1900 | RETVAL->h = 0; |
1832 | RETVAL->ox = 0; |
1901 | RETVAL->ox = 0; |
… | |
… | |
1869 | |
1938 | |
1870 | void |
1939 | void |
1871 | set_smooth (DC::Map self, int face, int smooth, int level) |
1940 | set_smooth (DC::Map self, int face, int smooth, int level) |
1872 | CODE: |
1941 | CODE: |
1873 | { |
1942 | { |
1874 | tileid texid; |
1943 | tileid texid; |
1875 | maptex *tex; |
1944 | maptex *tex; |
1876 | |
1945 | |
1877 | if (face < 0 || face >= self->faces) |
1946 | if (face < 0 || face >= self->faces) |
1878 | return; |
1947 | return; |
1879 | |
1948 | |
1880 | if (smooth < 0 || smooth >= self->faces) |
1949 | if (smooth < 0 || smooth >= self->faces) |
1881 | return; |
1950 | return; |
1882 | |
1951 | |
1883 | texid = self->face2tile [face]; |
1952 | texid = self->face2tile [face]; |
1884 | |
1953 | |
1885 | if (!texid) |
1954 | if (!texid) |
1886 | return; |
1955 | return; |
1887 | |
1956 | |
1888 | tex = self->tex + texid; |
1957 | tex = self->tex + texid; |
… | |
… | |
1921 | } |
1990 | } |
1922 | |
1991 | |
1923 | void |
1992 | void |
1924 | expire_textures (DC::Map self, int texid, int count) |
1993 | expire_textures (DC::Map self, int texid, int count) |
1925 | PPCODE: |
1994 | PPCODE: |
1926 | for (; texid < self->texs && count; ++texid, --count) |
1995 | for (; texid < self->texs && count; ++texid, --count) |
1927 | { |
1996 | { |
1928 | maptex *tex = self->tex + texid; |
1997 | maptex *tex = self->tex + texid; |
1929 | |
1998 | |
1930 | if (tex->name) |
1999 | if (tex->name) |
1931 | { |
2000 | { |
… | |
… | |
1978 | self->ox += dx; self->x += dx; |
2047 | self->ox += dx; self->x += dx; |
1979 | self->oy += dy; self->y += dy; |
2048 | self->oy += dy; self->y += dy; |
1980 | |
2049 | |
1981 | while (self->y < 0) |
2050 | while (self->y < 0) |
1982 | { |
2051 | { |
1983 | Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); |
2052 | prepend (self->row, self->rows, MAP_EXTEND_Y); |
1984 | |
2053 | |
1985 | self->rows += MAP_EXTEND_Y; |
2054 | self->rows += MAP_EXTEND_Y; |
1986 | self->y += MAP_EXTEND_Y; |
2055 | self->y += MAP_EXTEND_Y; |
1987 | } |
2056 | } |
1988 | } |
2057 | } |
1989 | |
2058 | |
1990 | SV * |
2059 | SV * |
1991 | map1a_update (DC::Map self, SV *data_, int extmap) |
2060 | map1a_update (DC::Map self, SV *data_) |
1992 | CODE: |
2061 | CODE: |
1993 | { |
2062 | { |
1994 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
2063 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1995 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
2064 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1996 | mapcell *cell; |
2065 | mapcell *cell; |
… | |
… | |
2017 | |
2086 | |
2018 | //TODO: don't trust server data to be in-range(!) |
2087 | //TODO: don't trust server data to be in-range(!) |
2019 | |
2088 | |
2020 | if (flags & 8) |
2089 | if (flags & 8) |
2021 | { |
2090 | { |
|
|
2091 | uint8_t ext, cmd; |
|
|
2092 | |
2022 | if (extmap) |
2093 | do |
2023 | { |
2094 | { |
2024 | uint8_t ext, cmd; |
2095 | ext = *data++; |
|
|
2096 | cmd = ext & 0x7f; |
2025 | |
2097 | |
2026 | 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 |
2027 | { |
2101 | { |
2028 | ext = *data++; |
|
|
2029 | cmd = ext & 0x7f; |
|
|
2030 | |
|
|
2031 | if (cmd < 4) |
|
|
2032 | cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */ |
|
|
2033 | else if (cmd == 5) // health |
|
|
2034 | { |
|
|
2035 | cell->stat_width = 1; |
2102 | cell->stat_width = 1; |
2036 | cell->stat_hp = *data++; |
2103 | cell->stat_hp = *data++; |
2037 | } |
|
|
2038 | else if (cmd == 6) // monster width |
|
|
2039 | cell->stat_width = *data++ + 1; |
|
|
2040 | else if (cmd == 0x47) |
|
|
2041 | { |
|
|
2042 | if (*data == 1) cell->player = data [1]; |
|
|
2043 | else if (*data == 2) cell->player = data [2] + (data [1] << 8); |
|
|
2044 | else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16); |
|
|
2045 | else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24); |
|
|
2046 | |
|
|
2047 | data += *data + 1; |
|
|
2048 | } |
|
|
2049 | else if (cmd == 8) // cell flags |
|
|
2050 | cell->flags = *data++; |
|
|
2051 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
2052 | data += *data + 1; |
|
|
2053 | else |
|
|
2054 | data++; |
|
|
2055 | } |
2104 | } |
2056 | 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++; |
2057 | } |
2122 | } |
2058 | else |
2123 | while (ext & 0x80); |
2059 | cell->darkness = *data++ + 1; |
|
|
2060 | } |
2124 | } |
2061 | |
2125 | |
2062 | for (z = 0; z <= 2; ++z) |
2126 | for (z = 0; z <= 2; ++z) |
2063 | if (flags & (4 >> z)) |
2127 | if (flags & (4 >> z)) |
2064 | { |
2128 | { |
… | |
… | |
2112 | ? self->row + y |
2176 | ? self->row + y |
2113 | : 0; |
2177 | : 0; |
2114 | |
2178 | |
2115 | for (x = x0; x < x1; x++) |
2179 | for (x = x0; x < x1; x++) |
2116 | { |
2180 | { |
2117 | int r = 32, g = 32, b = 32, a = 192; |
2181 | unsigned int r = 32, g = 32, b = 32, a = 192; |
2118 | |
2182 | |
2119 | if (row && row->c0 <= x && x < row->c1) |
2183 | if (row && row->c0 <= x && x < row->c1) |
2120 | { |
2184 | { |
2121 | mapcell *cell = row->col + (x - row->c0); |
2185 | mapcell *cell = row->col + (x - row->c0); |
2122 | |
2186 | |
… | |
… | |
2124 | { |
2188 | { |
2125 | maptex tex = self->tex [cell->tile [z]]; |
2189 | maptex tex = self->tex [cell->tile [z]]; |
2126 | int a0 = 255 - tex.a; |
2190 | int a0 = 255 - tex.a; |
2127 | int a1 = tex.a; |
2191 | int a1 = tex.a; |
2128 | |
2192 | |
2129 | r = (r * a0 + tex.r * a1) / 255; |
2193 | r = div255 (r * a0 + tex.r * a1); |
2130 | g = (g * a0 + tex.g * a1) / 255; |
2194 | g = div255 (g * a0 + tex.g * a1); |
2131 | b = (b * a0 + tex.b * a1) / 255; |
2195 | b = div255 (b * a0 + tex.b * a1); |
2132 | a = (a * a0 + tex.a * a1) / 255; |
2196 | a = div255 (a * a0 + tex.a * a1); |
2133 | } |
2197 | } |
2134 | } |
2198 | } |
2135 | |
2199 | |
2136 | *map++ = (r ) |
2200 | *map++ = (r ) |
2137 | | (g << 8) |
2201 | | (g << 8) |
2138 | | (b << 16) |
2202 | | (b << 16) |
2139 | | (a << 24); |
2203 | | (a << 24); |
2140 | } |
2204 | } |
2141 | } |
2205 | } |
2142 | |
2206 | |
2143 | RETVAL = map_sv; |
2207 | RETVAL = map_sv; |
2144 | } |
2208 | } |
2145 | OUTPUT: |
2209 | OUTPUT: |
2146 | RETVAL |
2210 | RETVAL |
2147 | |
2211 | |
2148 | void |
2212 | void |
2149 | draw (DC::Map self, int mx, int my, int sw, int sh, int T, 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) |
2150 | CODE: |
2214 | CODE: |
2151 | { |
2215 | { |
2152 | int x, y, z; |
2216 | int x, y, z; |
2153 | |
2217 | |
2154 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
|
|
2155 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
|
|
2156 | 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! |
2157 | smooth_key skey; |
|
|
2158 | int pl_x, pl_y; |
2219 | int pl_x, pl_y; |
2159 | maptex pl_tex; |
2220 | maptex pl_tex; |
2160 | rc_t *rc = rc_alloc (); |
2221 | rc_t rc; |
2161 | rc_t *rc_ov = rc_alloc (); |
2222 | rc_t rc_ov; |
2162 | rc_key_t key; |
2223 | rc_key_t key; |
2163 | rc_array_t *arr; |
2224 | rc_t::array_t *arr; |
2164 | |
2225 | |
2165 | pl_tex.name = 0; |
2226 | pl_tex.name = 0; |
2166 | |
2227 | |
2167 | // that's current max. sorry. |
2228 | // that's current max. sorry. |
2168 | if (sw > 255) sw = 255; |
2229 | if (sw > 255) sw = 255; |
2169 | if (sh > 255) sh = 255; |
2230 | if (sh > 255) sh = 255; |
2170 | |
|
|
2171 | // clear key, in case of extra padding |
|
|
2172 | memset (&skey, 0, sizeof (skey)); |
|
|
2173 | |
2231 | |
2174 | memset (&key, 0, sizeof (key)); |
2232 | memset (&key, 0, sizeof (key)); |
2175 | key.r = 255; |
2233 | key.r = 255; |
2176 | key.g = 255; |
2234 | key.g = 255; |
2177 | key.b = 255; |
2235 | key.b = 255; |
… | |
… | |
2183 | my += self->y; |
2241 | my += self->y; |
2184 | |
2242 | |
2185 | // first pass: determine smooth_max |
2243 | // first pass: determine smooth_max |
2186 | // rather ugly, if you ask me |
2244 | // rather ugly, if you ask me |
2187 | // could also be stored inside mapcell and updated on change |
2245 | // could also be stored inside mapcell and updated on change |
2188 | memset (smooth_max, 0, sizeof (smooth_max)); |
2246 | memset (smooth_max, 0, sizeof (smooth_max[0]) * (sh + 1)); |
2189 | |
2247 | |
2190 | for (y = 0; y < sh; y++) |
2248 | for (y = 0; y < sh; y++) |
2191 | if (0 <= y + my && y + my < self->rows) |
2249 | if (0 <= y + my && y + my < self->rows) |
2192 | { |
2250 | { |
2193 | maprow *row = self->row + (y + my); |
2251 | maprow *row = self->row + (y + my); |
… | |
… | |
2208 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2266 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2209 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2267 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2210 | |
2268 | |
2211 | for (z = 0; z <= 2; z++) |
2269 | for (z = 0; z <= 2; z++) |
2212 | { |
2270 | { |
2213 | 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; |
2214 | key.texname = -1; |
2274 | key.texname = -1; |
2215 | |
2275 | |
2216 | for (y = 0; y < sh; y++) |
2276 | for (y = 0; y < sh; y++) |
2217 | if (0 <= y + my && y + my < self->rows) |
2277 | if (0 <= y + my && y + my < self->rows) |
2218 | { |
2278 | { |
… | |
… | |
2235 | |
2295 | |
2236 | if (!tex.name) |
2296 | if (!tex.name) |
2237 | tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ |
2297 | tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ |
2238 | |
2298 | |
2239 | key.texname = tex.name; |
2299 | key.texname = tex.name; |
2240 | arr = rc_array (rc, &key); |
2300 | arr = &rc.array (key); |
2241 | } |
2301 | } |
2242 | |
2302 | |
2243 | px = (x + 1) * T - tex.w; |
2303 | px = (x + 1) * Th - tex.w; |
2244 | py = (y + 1) * T - tex.h; |
2304 | py = (y + 1) * Tw - tex.h; |
2245 | |
2305 | |
2246 | if (expect_false (cell->player == player) && expect_false (z == 2)) |
2306 | if (ecb_expect_false (cell->player == player) && ecb_expect_false (z == 2)) |
2247 | { |
2307 | { |
2248 | pl_x = px; |
2308 | pl_x = px; |
2249 | pl_y = py; |
2309 | pl_y = py; |
2250 | pl_tex = tex; |
2310 | pl_tex = tex; |
2251 | continue; |
2311 | continue; |
2252 | } |
2312 | } |
2253 | |
2313 | |
2254 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
2314 | arr->t2f_v3f (0 , 0 , px , py , 0); |
2255 | rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); |
2315 | arr->t2f_v3f (0 , tex.t, px , py + tex.h, 0); |
2256 | 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); |
2257 | rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); |
2317 | arr->t2f_v3f (tex.s, 0 , px + tex.w, py , 0); |
2258 | |
2318 | |
2259 | // update smooth hash |
2319 | // update smooth hash |
2260 | if (tex.smoothtile) |
2320 | if (tex.smoothtile) |
2261 | { |
2321 | { |
2262 | skey.tile = tex.smoothtile; |
2322 | skey.tile = tex.smoothtile; |
2263 | skey.level = tex.smoothlevel; |
2323 | skey.level = tex.smoothlevel; |
2264 | |
2324 | |
2265 | smooth_level [tex.smoothlevel >> 5] |= ((uint32_t)1) << (tex.smoothlevel & 31); |
2325 | smooth_level[tex.smoothlevel] = 1; |
2266 | |
2326 | |
2267 | // 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 |
2268 | // shifted +1|+1 so we always stay positive. |
2328 | // shifted +1|+1 so we always stay positive. |
2269 | |
2329 | |
2270 | // bits is ___n cccc CCCC bbbb |
2330 | // bits is ___n cccc CCCC bbbb |
… | |
… | |
2278 | |
2338 | |
2279 | // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· |
2339 | // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· |
2280 | // ·· ·· ·┏ ┓· |
2340 | // ·· ·· ·┏ ┓· |
2281 | |
2341 | |
2282 | // full tile |
2342 | // full tile |
2283 | 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); |
2284 | |
2344 | |
2285 | // borders |
2345 | // borders |
2286 | 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); |
2287 | 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); |
2288 | 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); |
2289 | 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); |
2290 | |
2350 | |
2291 | // corners |
2351 | // corners |
2292 | 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); |
2293 | 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); |
2294 | 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); |
2295 | 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); |
2296 | } |
2356 | } |
2297 | } |
2357 | } |
2298 | |
2358 | |
2299 | if (expect_false (z == 2) && expect_false (cell->flags)) |
2359 | if (ecb_expect_false (z == 2) && ecb_expect_false (cell->flags)) |
2300 | { |
2360 | { |
2301 | // overlays such as the speech bubble, probably more to come |
2361 | // overlays such as the speech bubble, probably more to come |
2302 | if (cell->flags & 1) |
2362 | if (cell->flags & 1) |
2303 | { |
2363 | { |
2304 | rc_key_t key_ov = key; |
2364 | rc_key_t key_ov = key; |
2305 | maptex tex = self->tex [TEXID_SPEECH]; |
2365 | maptex tex = self->tex[TEXID_SPEECH]; |
2306 | rc_array_t *arr; |
|
|
2307 | int px = x * T + T * 2 / 32; |
2366 | int px = x * Tw + Tw * 2 / 32; |
2308 | int py = y * T - T * 6 / 32; |
2367 | int py = y * Th - Th * 6 / 32; |
2309 | |
2368 | |
2310 | key_ov.texname = tex.name; |
2369 | key_ov.texname = tex.name; |
2311 | arr = rc_array (rc_ov, &key_ov); |
2370 | rc_t::array_t &arr = rc_ov.array (key_ov); |
2312 | |
2371 | |
2313 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
2372 | arr.t2f_v3f (0 , 0 , px , py , 0); |
2314 | rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0); |
2373 | arr.t2f_v3f (0 , tex.t, px , py + Th, 0); |
2315 | rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0); |
2374 | arr.t2f_v3f (tex.s, tex.t, px + Tw, py + Th, 0); |
2316 | rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0); |
2375 | arr.t2f_v3f (tex.s, 0 , px + Tw, py , 0); |
2317 | } |
2376 | } |
2318 | } |
2377 | } |
2319 | } |
2378 | } |
2320 | } |
2379 | } |
2321 | |
2380 | |
2322 | rc_draw (rc); |
2381 | rc.draw (); |
2323 | rc_clear (rc); |
2382 | rc.clear (); |
2324 | |
2383 | |
2325 | // go through all smoothlevels, lowest to highest, then draw. |
2384 | // go through all smoothlevels, lowest to highest, then draw. |
2326 | // this is basically counting sort |
2385 | // this is basically counting sort |
2327 | { |
2386 | { |
2328 | int w, b; |
2387 | int w, b; |
2329 | |
2388 | |
2330 | glEnable (GL_TEXTURE_2D); |
2389 | glEnable (GL_TEXTURE_2D); |
2331 | glBegin (GL_QUADS); |
2390 | glBegin (GL_QUADS); |
2332 | 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) |
2333 | { |
2394 | { |
2334 | uint32_t smask = smooth_level [w]; |
2395 | smooth_key &skey = it->first; |
2335 | if (smask) |
2396 | IV bits = it->second; |
2336 | for (b = 0; b < 32; ++b) |
2397 | |
2337 | if (smask & (((uint32_t)1) << b)) |
2398 | if (!(bits & 0x1000) |
|
|
2399 | && skey.level == level |
|
|
2400 | && level > smooth_max [skey.x][skey.y]) |
2338 | { |
2401 | { |
2339 | 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 | |
2340 | HE *he; |
2410 | if (tex.name) |
2341 | |
|
|
2342 | hv_iterinit (smooth); |
|
|
2343 | while ((he = hv_iternext (smooth))) |
|
|
2344 | { |
2411 | { |
2345 | smooth_key *skey = (smooth_key *)HeKEY (he); |
2412 | // this time avoiding texture state changes |
2346 | IV bits = SvIVX (HeVAL (he)); |
2413 | // save gobs of state changes. |
2347 | |
2414 | if (key.texname != tex.name) |
2348 | if (!(bits & 0x1000) |
|
|
2349 | && skey->level == level |
|
|
2350 | && level > smooth_max [skey->x][skey->y]) |
|
|
2351 | { |
2415 | { |
2352 | maptex tex = self->tex [skey->tile]; |
|
|
2353 | int px = (((int)skey->x) - 1) * T; |
|
|
2354 | int py = (((int)skey->y) - 1) * T; |
|
|
2355 | int border = bits & 15; |
|
|
2356 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
|
|
2357 | float dx = tex.s * .0625f; // 16 images/row |
|
|
2358 | float dy = tex.t * .5f ; // 2 images/column |
|
|
2359 | |
|
|
2360 | if (tex.name) |
|
|
2361 | { |
|
|
2362 | // this time avoiding texture state changes |
|
|
2363 | // save gobs of state changes. |
|
|
2364 | if (key.texname != tex.name) |
|
|
2365 | { |
|
|
2366 | self->tex [skey->tile].unused = 0; |
2416 | self->tex [skey.tile].unused = 0; |
2367 | |
2417 | |
2368 | glEnd (); |
2418 | glEnd (); |
2369 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
2419 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
2370 | glBegin (GL_QUADS); |
2420 | glBegin (GL_QUADS); |
2371 | } |
2421 | } |
2372 | |
2422 | |
2373 | if (border) |
2423 | if (border) |
2374 | { |
2424 | { |
2375 | float ox = border * dx; |
2425 | float ox = border * dx; |
2376 | |
2426 | |
2377 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
2427 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
2378 | glTexCoord2f (ox , dy ); glVertex2i (px , py + T); |
2428 | glTexCoord2f (ox , dy ); glVertex2i (px , py + Th); |
2379 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py + T); |
2429 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); |
2380 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + T, py ); |
2430 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); |
2381 | } |
2431 | } |
2382 | |
2432 | |
2383 | if (corner) |
2433 | if (corner) |
2384 | { |
2434 | { |
2385 | float ox = corner * dx; |
2435 | float ox = corner * dx; |
2386 | |
2436 | |
2387 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
2437 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
2388 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + T); |
2438 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th); |
2389 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + T, py + T); |
2439 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th); |
2390 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py ); |
2440 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py ); |
2391 | } |
|
|
2392 | } |
|
|
2393 | } |
2441 | } |
2394 | } |
2442 | } |
2395 | } |
2443 | } |
2396 | } |
2444 | } |
2397 | |
2445 | |
2398 | glEnd (); |
2446 | glEnd (); |
2399 | glDisable (GL_TEXTURE_2D); |
2447 | glDisable (GL_TEXTURE_2D); |
2400 | key.texname = -1; |
2448 | key.texname = -1; |
2401 | } |
2449 | } |
2402 | |
|
|
2403 | hv_clear (smooth); |
|
|
2404 | } |
2450 | } |
2405 | |
2451 | |
2406 | if (pl_tex.name) |
2452 | if (pl_tex.name) |
2407 | { |
2453 | { |
2408 | maptex tex = pl_tex; |
2454 | maptex tex = pl_tex; |
2409 | int px = pl_x + sdx; |
2455 | int px = pl_x + sdx; |
2410 | int py = pl_y + sdy; |
2456 | int py = pl_y + sdy; |
2411 | |
2457 | |
2412 | key.texname = tex.name; |
2458 | key.texname = tex.name; |
2413 | arr = rc_array (rc, &key); |
2459 | rc_t::array_t &arr = rc.array (key); |
2414 | |
2460 | |
2415 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
2461 | arr.t2f_v3f (0 , 0 , px , py , 0); |
2416 | rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); |
2462 | arr.t2f_v3f (0 , tex.t, px , py + tex.h, 0); |
2417 | 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); |
2418 | rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); |
2464 | arr.t2f_v3f (tex.s, 0 , px + tex.w, py , 0); |
2419 | |
2465 | |
2420 | rc_draw (rc); |
2466 | rc.draw (); |
2421 | } |
2467 | } |
2422 | |
2468 | |
2423 | rc_draw (rc_ov); |
2469 | rc_ov.draw (); |
2424 | rc_clear (rc_ov); |
2470 | rc_ov.clear (); |
2425 | |
2471 | |
2426 | glDisable (GL_BLEND); |
2472 | glDisable (GL_BLEND); |
2427 | rc_free (rc); |
|
|
2428 | rc_free (rc_ov); |
|
|
2429 | |
2473 | |
2430 | // top layer: overlays such as the health bar |
2474 | // top layer: overlays such as the health bar |
2431 | for (y = 0; y < sh; y++) |
2475 | for (y = 0; y < sh; y++) |
2432 | if (0 <= y + my && y + my < self->rows) |
2476 | if (0 <= y + my && y + my < self->rows) |
2433 | { |
2477 | { |
… | |
… | |
2436 | for (x = 0; x < sw; x++) |
2480 | for (x = 0; x < sw; x++) |
2437 | if (row->c0 <= x + mx && x + mx < row->c1) |
2481 | if (row->c0 <= x + mx && x + mx < row->c1) |
2438 | { |
2482 | { |
2439 | mapcell *cell = row->col + (x + mx - row->c0); |
2483 | mapcell *cell = row->col + (x + mx - row->c0); |
2440 | |
2484 | |
2441 | int px = x * T; |
2485 | int px = x * Tw; |
2442 | int py = y * T; |
2486 | int py = y * Th; |
2443 | |
2487 | |
2444 | if (expect_false (cell->player == player)) |
2488 | if (ecb_expect_false (cell->player == player)) |
2445 | { |
2489 | { |
2446 | px += sdx; |
2490 | px += sdx; |
2447 | py += sdy; |
2491 | py += sdy; |
2448 | } |
2492 | } |
2449 | |
2493 | |
2450 | if (cell->stat_hp) |
2494 | if (cell->stat_hp) |
2451 | { |
2495 | { |
2452 | int width = cell->stat_width * T; |
2496 | int width = cell->stat_width * Tw; |
2453 | int thick = (sh * T / 32 + 27) / 28 + 1 + cell->stat_width; |
2497 | int thick = (sh * Th / 32 + 27) / 28 + 1 + cell->stat_width; |
2454 | |
2498 | |
2455 | glColor3ub (0, 0, 0); |
2499 | glColor3ub (0, 0, 0); |
2456 | glRectf (px + 1, py - thick - 2, |
2500 | glRectf (px + 1, py - thick - 2, |
2457 | px + width - 1, py); |
2501 | px + width - 1, py); |
2458 | |
2502 | |
… | |
… | |
2538 | int x, y; |
2582 | int x, y; |
2539 | int sw1 = sw + 2; |
2583 | int sw1 = sw + 2; |
2540 | int sh1 = sh + 2; |
2584 | int sh1 = sh + 2; |
2541 | int sh3 = sh * 3; |
2585 | int sh3 = sh * 3; |
2542 | int sw3 = sw * 3; |
2586 | int sw3 = sw * 3; |
2543 | uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); |
|
|
2544 | SV *darkness3_sv = sv_2mortal (newSV (sw3 * sh3)); |
2587 | SV *darkness3_sv = sv_2mortal (newSV (sw3 * sh3)); |
2545 | uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv); |
2588 | uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv); |
|
|
2589 | uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); |
|
|
2590 | memset (darkness1, 0, sw1*sh1); |
2546 | |
2591 | |
2547 | SvPOK_only (darkness3_sv); |
2592 | SvPOK_only (darkness3_sv); |
2548 | SvCUR_set (darkness3_sv, sw3 * sh3); |
2593 | SvCUR_set (darkness3_sv, sw3 * sh3); |
2549 | |
2594 | |
2550 | mx += self->x - 1; |
2595 | mx += self->x - 1; |
… | |
… | |
2676 | else |
2721 | else |
2677 | *data++ = 0; |
2722 | *data++ = 0; |
2678 | } |
2723 | } |
2679 | } |
2724 | } |
2680 | |
2725 | |
2681 | /* 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 */ |
2682 | if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) |
2727 | if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) |
2683 | { |
2728 | { |
2684 | SvPOK_only (data_sv); |
2729 | SvPOK_only (data_sv); |
2685 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
2730 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
2686 | } |
2731 | } |
2687 | |
2732 | |
2688 | RETVAL = data_sv; |
2733 | RETVAL = data_sv; |
2689 | } |
2734 | } |
2690 | OUTPUT: |
2735 | OUTPUT: |
2691 | RETVAL |
2736 | RETVAL |
2692 | |
2737 | |
2693 | void |
2738 | void |
… | |
… | |
2700 | STRLEN len; |
2745 | STRLEN len; |
2701 | uint8_t *data, *end; |
2746 | uint8_t *data, *end; |
2702 | |
2747 | |
2703 | len = SvLEN (data_sv); |
2748 | len = SvLEN (data_sv); |
2704 | SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more |
2749 | SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more |
2705 | data = SvPVbyte_nolen (data_sv); |
2750 | data = (uint8_t *)SvPVbyte_nolen (data_sv); |
2706 | end = data + len + 8; |
2751 | end = data + len + 8; |
2707 | |
2752 | |
2708 | if (len < 5) |
2753 | if (len < 5) |
2709 | XSRETURN_EMPTY; |
2754 | XSRETURN_EMPTY; |
2710 | |
2755 | |
… | |
… | |
2771 | } |
2816 | } |
2772 | |
2817 | |
2773 | MODULE = Deliantra::Client PACKAGE = DC::RW |
2818 | MODULE = Deliantra::Client PACKAGE = DC::RW |
2774 | |
2819 | |
2775 | DC::RW |
2820 | DC::RW |
2776 | new (SV *class, SV *data_sv) |
2821 | new (SV *klass, SV *data_sv) |
2777 | CODE: |
2822 | CODE: |
2778 | { |
2823 | { |
2779 | STRLEN datalen; |
2824 | STRLEN datalen; |
2780 | char *data = SvPVbyte (data_sv, datalen); |
2825 | char *data = SvPVbyte (data_sv, datalen); |
2781 | |
2826 | |
… | |
… | |
2783 | } |
2828 | } |
2784 | OUTPUT: |
2829 | OUTPUT: |
2785 | RETVAL |
2830 | RETVAL |
2786 | |
2831 | |
2787 | DC::RW |
2832 | DC::RW |
2788 | 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") |
2789 | CODE: |
2834 | CODE: |
2790 | RETVAL = SDL_RWFromFile (path, mode); |
2835 | RETVAL = SDL_RWFromFile (path, mode); |
2791 | OUTPUT: |
2836 | OUTPUT: |
2792 | RETVAL |
2837 | RETVAL |
2793 | |
2838 | |
… | |
… | |
2902 | #else |
2947 | #else |
2903 | XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); |
2948 | XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); |
2904 | #endif |
2949 | #endif |
2905 | |
2950 | |
2906 | DC::MixChunk |
2951 | DC::MixChunk |
2907 | new (SV *class, DC::RW rwops) |
2952 | new (SV *klass, DC::RW rwops) |
2908 | CODE: |
2953 | CODE: |
2909 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2954 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2910 | OUTPUT: |
2955 | OUTPUT: |
2911 | RETVAL |
2956 | RETVAL |
2912 | |
2957 | |
… | |
… | |
2982 | RETVAL = Mix_PlayingMusic (); |
3027 | RETVAL = Mix_PlayingMusic (); |
2983 | OUTPUT: |
3028 | OUTPUT: |
2984 | RETVAL |
3029 | RETVAL |
2985 | |
3030 | |
2986 | DC::MixMusic |
3031 | DC::MixMusic |
2987 | new (SV *class, DC::RW rwops) |
3032 | new (SV *klass, DC::RW rwops) |
2988 | CODE: |
3033 | CODE: |
2989 | RETVAL = Mix_LoadMUS_RW (rwops); |
3034 | RETVAL = Mix_LoadMUS_RW (rwops); |
2990 | OUTPUT: |
3035 | OUTPUT: |
2991 | RETVAL |
3036 | RETVAL |
2992 | |
3037 | |
… | |
… | |
3129 | const_iv (GL_FUNC_SUBTRACT), |
3174 | const_iv (GL_FUNC_SUBTRACT), |
3130 | const_iv (GL_FUNC_REVERSE_SUBTRACT), |
3175 | const_iv (GL_FUNC_REVERSE_SUBTRACT), |
3131 | # undef const_iv |
3176 | # undef const_iv |
3132 | }; |
3177 | }; |
3133 | |
3178 | |
3134 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
3179 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
3135 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
3180 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
3136 | |
3181 | |
3137 | texture_av = newAV (); |
3182 | texture_av = newAV (); |
3138 | AvREAL_off (texture_av); |
3183 | AvREAL_off (texture_av); |
3139 | } |
3184 | } |
3140 | |
3185 | |
… | |
… | |
3145 | gl.BlendFuncSeparateEXT = 0; |
3190 | gl.BlendFuncSeparateEXT = 0; |
3146 | |
3191 | |
3147 | void |
3192 | void |
3148 | apple_nvidia_bug (int enable) |
3193 | apple_nvidia_bug (int enable) |
3149 | |
3194 | |
3150 | char * |
3195 | const char * |
3151 | gl_vendor () |
3196 | gl_vendor () |
3152 | CODE: |
3197 | CODE: |
3153 | RETVAL = (char *)glGetString (GL_VENDOR); |
3198 | RETVAL = (const char *)glGetString (GL_VENDOR); |
3154 | OUTPUT: |
3199 | OUTPUT: |
3155 | RETVAL |
3200 | RETVAL |
3156 | |
3201 | |
3157 | char * |
3202 | const char * |
3158 | gl_version () |
3203 | gl_version () |
3159 | CODE: |
3204 | CODE: |
3160 | RETVAL = (char *)glGetString (GL_VERSION); |
3205 | RETVAL = (const char *)glGetString (GL_VERSION); |
3161 | OUTPUT: |
3206 | OUTPUT: |
3162 | RETVAL |
3207 | RETVAL |
3163 | |
3208 | |
3164 | char * |
3209 | const char * |
3165 | gl_extensions () |
3210 | gl_extensions () |
3166 | CODE: |
3211 | CODE: |
3167 | RETVAL = (char *)glGetString (GL_EXTENSIONS); |
3212 | RETVAL = (const char *)glGetString (GL_EXTENSIONS); |
3168 | OUTPUT: |
3213 | OUTPUT: |
3169 | RETVAL |
3214 | RETVAL |
3170 | |
3215 | |
3171 | const char *glGetString (GLenum pname) |
3216 | const char *glGetString (GLenum pname) |
|
|
3217 | CODE: |
|
|
3218 | RETVAL = (const char *)glGetString (pname); |
|
|
3219 | OUTPUT: |
|
|
3220 | RETVAL |
3172 | |
3221 | |
3173 | GLint glGetInteger (GLenum pname) |
3222 | GLint glGetInteger (GLenum pname) |
3174 | CODE: |
3223 | CODE: |
3175 | glGetIntegerv (pname, &RETVAL); |
3224 | glGetIntegerv (pname, &RETVAL); |
3176 | OUTPUT: |
3225 | OUTPUT: |
… | |
… | |
3183 | RETVAL |
3232 | RETVAL |
3184 | |
3233 | |
3185 | int glGetError () |
3234 | int glGetError () |
3186 | |
3235 | |
3187 | void glFinish () |
3236 | void glFinish () |
|
|
3237 | |
|
|
3238 | void glFlush () |
3188 | |
3239 | |
3189 | void glClear (int mask) |
3240 | void glClear (int mask) |
3190 | |
3241 | |
3191 | void glClearColor (float r, float g, float b, float a = 1.0) |
3242 | void glClearColor (float r, float g, float b, float a = 1.0) |
3192 | PROTOTYPE: @ |
3243 | PROTOTYPE: @ |
… | |
… | |
3377 | |
3428 | |
3378 | void |
3429 | void |
3379 | find_widget (SV *self, NV x, NV y) |
3430 | find_widget (SV *self, NV x, NV y) |
3380 | PPCODE: |
3431 | PPCODE: |
3381 | { |
3432 | { |
3382 | if (within_widget (self, x, y)) |
3433 | if (within_widget (self, x, y)) |
3383 | XPUSHs (self); |
3434 | XPUSHs (self); |
3384 | } |
3435 | } |
3385 | |
3436 | |
3386 | BOOT: |
3437 | BOOT: |
3387 | { |
3438 | { |
… | |
… | |
3395 | |
3446 | |
3396 | void |
3447 | void |
3397 | draw (SV *self) |
3448 | draw (SV *self) |
3398 | CODE: |
3449 | CODE: |
3399 | { |
3450 | { |
3400 | HV *hv; |
3451 | HV *hv; |
3401 | SV **svp; |
3452 | SV **svp; |
3402 | NV x, y, w, h; |
3453 | NV x, y, w, h; |
3403 | SV *draw_x_sv = GvSV (draw_x_gv); |
3454 | SV *draw_x_sv = GvSV (draw_x_gv); |
3404 | SV *draw_y_sv = GvSV (draw_y_gv); |
3455 | SV *draw_y_sv = GvSV (draw_y_gv); |
3405 | SV *draw_w_sv = GvSV (draw_w_gv); |
3456 | SV *draw_w_sv = GvSV (draw_w_gv); |
3406 | SV *draw_h_sv = GvSV (draw_h_gv); |
3457 | SV *draw_h_sv = GvSV (draw_h_gv); |