… | |
… | |
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 |
… | |
… | |
184 | { |
189 | { |
185 | GSList *attrs = run->item->analysis.extra_attrs; |
190 | GSList *attrs = run->item->analysis.extra_attrs; |
186 | |
191 | |
187 | while (attrs) |
192 | while (attrs) |
188 | { |
193 | { |
189 | PangoAttribute *attr = attrs->data; |
194 | PangoAttribute *attr = (PangoAttribute *)attrs->data; |
190 | |
195 | |
191 | if (attr->klass->type == PANGO_ATTR_SHAPE) |
196 | if (attr->klass->type == PANGO_ATTR_SHAPE) |
192 | return 1; |
197 | return 1; |
193 | |
198 | |
194 | attrs = attrs->next; |
199 | attrs = attrs->next; |
195 | } |
200 | } |
196 | |
201 | |
197 | return 0; |
202 | return 0; |
198 | } |
203 | } |
199 | |
204 | |
200 | typedef struct cf_layout { |
205 | struct cf_layout { |
201 | PangoLayout *pl; |
206 | PangoLayout *pl; |
202 | float r, g, b, a; // default color for rgba mode |
207 | float r, g, b, a; // default color for rgba mode |
203 | int base_height; |
208 | int base_height; |
204 | DC__Font font; |
209 | DC__Font font; |
205 | rc_t *rc; |
210 | rc_t *rc; |
206 | } *DC__Layout; |
211 | }; |
|
|
212 | |
|
|
213 | typedef cf_layout *DC__Layout; |
207 | |
214 | |
208 | static DC__Font default_font; |
215 | static DC__Font default_font; |
209 | static PangoContext *opengl_context; |
216 | static PangoContext *opengl_context; |
210 | static PangoFontMap *opengl_fontmap; |
217 | static PangoFontMap *opengl_fontmap; |
211 | |
218 | |
212 | static void |
219 | static void |
213 | substitute_func (FcPattern *pattern, gpointer data) |
220 | substitute_func (FcPattern *pattern, gpointer data) |
214 | { |
221 | { |
215 | FcPatternAddBool (pattern, FC_HINTING, 1); |
222 | FcPatternAddBool (pattern, FC_HINTING, 1); |
216 | #ifdef FC_HINT_STYLE |
223 | #ifdef FC_HINT_STYLE |
217 | FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); |
224 | FcPatternAddInteger (pattern, FC_HINT_STYLE, FC_HINT_FULL); |
218 | #endif |
225 | #endif |
219 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
226 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
220 | } |
227 | } |
221 | |
228 | |
222 | static void |
229 | static void |
… | |
… | |
252 | } |
259 | } |
253 | |
260 | |
254 | typedef uint16_t tileid; |
261 | typedef uint16_t tileid; |
255 | typedef uint16_t faceid; |
262 | typedef uint16_t faceid; |
256 | |
263 | |
257 | typedef struct { |
264 | struct maptex |
|
|
265 | { |
258 | GLuint name; |
266 | GLuint name; |
259 | int w, h; |
267 | int w, h; |
260 | float s, t; |
268 | float s, t; |
261 | uint8_t r, g, b, a; |
269 | uint8_t r, g, b, a; |
262 | tileid smoothtile; |
270 | tileid smoothtile; |
263 | uint8_t smoothlevel; |
271 | uint8_t smoothlevel; |
264 | uint8_t unused; /* set to zero on use */ |
272 | uint8_t unused; /* set to zero on use */ |
265 | } maptex; |
273 | }; |
266 | |
274 | |
267 | typedef struct { |
275 | struct mapcell |
|
|
276 | { |
268 | uint32_t player; |
277 | uint32_t player; |
269 | tileid tile[3]; |
278 | tileid tile[3]; |
270 | uint16_t darkness; |
279 | uint16_t darkness; |
271 | uint8_t stat_width, stat_hp, flags, smoothmax; |
280 | uint8_t stat_width, stat_hp, flags, smoothmax; |
272 | } mapcell; |
281 | }; |
273 | |
282 | |
274 | typedef struct { |
283 | struct maprow |
|
|
284 | { |
275 | int32_t c0, c1; |
285 | int32_t c0, c1; |
276 | mapcell *col; |
286 | mapcell *col; |
277 | } maprow; |
287 | }; |
278 | |
288 | |
279 | typedef struct map { |
289 | struct mapgrid { |
280 | int x, y, w, h; |
290 | int x, y, w, h; |
281 | int ox, oy; /* offset to virtual global coordinate system */ |
291 | int ox, oy; /* offset to virtual global coordinate system */ |
282 | int faces; tileid *face2tile; // [faceid] |
292 | int faces; tileid *face2tile; // [faceid] |
283 | int texs; maptex *tex; // [tileid] |
293 | int texs; maptex *tex; // [tileid] |
284 | |
294 | |
285 | int32_t rows; |
295 | int32_t rows; |
286 | maprow *row; |
296 | maprow *row; |
287 | } *DC__Map; |
297 | }; |
|
|
298 | |
|
|
299 | typedef mapgrid *DC__Map; |
288 | |
300 | |
289 | static char * |
301 | static char * |
290 | prepend (char *ptr, int sze, int inc) |
302 | prepend (char *ptr, int sze, int inc) |
291 | { |
303 | { |
292 | char *p; |
304 | char *p; |
… | |
… | |
310 | |
322 | |
311 | #define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
323 | #define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
312 | #define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
324 | #define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
313 | |
325 | |
314 | static void |
326 | static void |
315 | need_facenum (struct map *self, faceid face) |
327 | need_facenum (struct mapgrid *self, faceid face) |
316 | { |
328 | { |
317 | while (self->faces <= face) |
329 | while (self->faces <= face) |
318 | { |
330 | { |
319 | Append (tileid, self->face2tile, self->faces, self->faces); |
331 | Append (tileid, self->face2tile, self->faces, self->faces); |
320 | self->faces *= 2; |
332 | self->faces *= 2; |
321 | } |
333 | } |
322 | } |
334 | } |
323 | |
335 | |
324 | static void |
336 | static void |
325 | need_texid (struct map *self, int texid) |
337 | need_texid (struct mapgrid *self, int texid) |
326 | { |
338 | { |
327 | while (self->texs <= texid) |
339 | while (self->texs <= texid) |
328 | { |
340 | { |
329 | Append (maptex, self->tex, self->texs, self->texs); |
341 | Append (maptex, self->tex, self->texs, self->texs); |
330 | self->texs *= 2; |
342 | self->texs *= 2; |
331 | } |
343 | } |
332 | } |
344 | } |
333 | |
345 | |
334 | static maprow * |
346 | static maprow * |
335 | map_get_row (DC__Map self, int y) |
347 | map_get_row (mapgrid *self, int y) |
336 | { |
348 | { |
337 | if (0 > y) |
349 | if (0 > y) |
338 | { |
350 | { |
339 | int extend = - y + MAP_EXTEND_Y; |
351 | int extend = - y + MAP_EXTEND_Y; |
340 | Prepend (maprow, self->row, self->rows, extend); |
352 | Prepend (maprow, self->row, self->rows, extend); |
… | |
… | |
378 | |
390 | |
379 | return row->col + (x - row->c0); |
391 | return row->col + (x - row->c0); |
380 | } |
392 | } |
381 | |
393 | |
382 | static mapcell * |
394 | static mapcell * |
383 | map_get_cell (DC__Map self, int x, int y) |
395 | map_get_cell (mapgrid *self, int x, int y) |
384 | { |
396 | { |
385 | return row_get_cell (map_get_row (self, y), x); |
397 | return row_get_cell (map_get_row (self, y), x); |
386 | } |
398 | } |
387 | |
399 | |
388 | static void |
400 | static void |
389 | map_clear (DC__Map self) |
401 | map_clear (mapgrid *self) |
390 | { |
402 | { |
391 | int r; |
403 | int r; |
392 | |
404 | |
393 | for (r = 0; r < self->rows; r++) |
405 | for (r = 0; r < self->rows; r++) |
394 | Safefree (self->row[r].col); |
406 | Safefree (self->row[r].col); |
… | |
… | |
412 | (cell)->flags = 0; \ |
424 | (cell)->flags = 0; \ |
413 | (cell)->player = 0; \ |
425 | (cell)->player = 0; \ |
414 | } while (0) |
426 | } while (0) |
415 | |
427 | |
416 | static void |
428 | static void |
417 | map_blank (DC__Map self, int x0, int y0, int w, int h) |
429 | map_blank (mapgrid *self, int x0, int y0, int w, int h) |
418 | { |
430 | { |
419 | int x, y; |
431 | int x, y; |
420 | maprow *row; |
432 | maprow *row; |
421 | mapcell *cell; |
433 | mapcell *cell; |
422 | |
434 | |
… | |
… | |
439 | CELL_CLEAR (cell); |
451 | CELL_CLEAR (cell); |
440 | } |
452 | } |
441 | } |
453 | } |
442 | } |
454 | } |
443 | |
455 | |
444 | typedef struct { |
456 | struct smooth_key |
|
|
457 | { |
445 | tileid tile; |
458 | tileid tile; |
446 | uint8_t x, y, level; |
459 | uint8_t x, y, level; |
447 | } smooth_key; |
460 | |
|
|
461 | bool operator == (const smooth_key &o) const |
|
|
462 | { |
|
|
463 | return tile == o.tile && x == o.x && y == o.y && level == o.level; |
|
|
464 | } |
|
|
465 | }; |
|
|
466 | |
|
|
467 | typedef ska::flat_hash_map<smooth_key, IV> smooth_hash; |
|
|
468 | |
|
|
469 | namespace std { |
|
|
470 | template <> |
|
|
471 | struct hash<smooth_key> |
|
|
472 | { |
|
|
473 | size_t operator () (const smooth_key &v) const |
|
|
474 | { |
|
|
475 | return v.tile + (v.x << 8) + (v.y << 16) + (v.level << 24); |
|
|
476 | } |
|
|
477 | }; |
|
|
478 | } |
448 | |
479 | |
449 | static void |
480 | static void |
450 | smooth_or_bits (HV *hv, smooth_key *key, IV bits) |
481 | smooth_or_bits (smooth_hash &h, smooth_key &key, IV bits) |
451 | { |
482 | { |
452 | SV **sv = hv_fetch (hv, (char *)key, sizeof (*key), 1); |
483 | auto &&it = h.find (key); |
453 | |
484 | |
454 | if (SvIOK (*sv)) |
485 | if (it == h.end ()) |
455 | SvIV_set (*sv, SvIVX (*sv) | bits); |
486 | h.insert (std::make_pair (key, bits)); |
456 | else |
487 | else |
457 | sv_setiv (*sv, bits); |
488 | it->second |= bits; |
458 | } |
489 | } |
459 | |
490 | |
460 | static void |
491 | static void |
461 | music_finished (void) |
492 | music_finished (void) |
462 | { |
493 | { |
… | |
… | |
481 | ev.data2 = 0; |
512 | ev.data2 = 0; |
482 | |
513 | |
483 | SDL_PushEvent ((SDL_Event *)&ev); |
514 | SDL_PushEvent ((SDL_Event *)&ev); |
484 | } |
515 | } |
485 | |
516 | |
|
|
517 | // approximately divide by 255 |
486 | static unsigned int |
518 | static unsigned int |
487 | div255 (unsigned int n) |
519 | div255 (unsigned int n) |
488 | { |
520 | { |
489 | return (n + (n >> 8)) >> 8; |
521 | return (n + (n >> 8)) >> 8; |
490 | } |
522 | } |
… | |
… | |
577 | |
609 | |
578 | return mod; |
610 | return mod; |
579 | } |
611 | } |
580 | |
612 | |
581 | static void |
613 | static void |
582 | deliantra_main () |
614 | deliantra_main (SV *real_main) |
583 | { |
615 | { |
584 | char *argv[] = { 0 }; |
616 | dSP; |
585 | call_argv ("DC::Main::main", G_DISCARD | G_VOID, argv); |
617 | |
|
|
618 | PUSHMARK (SP); |
|
|
619 | call_sv (real_main, G_DISCARD | G_VOID); |
586 | } |
620 | } |
587 | |
621 | |
588 | #ifdef __MACOSX__ |
622 | #ifdef __MACOSX__ |
|
|
623 | static SV *real_main; |
|
|
624 | |
589 | /* to due surprising braindamage on the side of SDL design, we |
625 | /* to due surprising braindamage on the side of SDL design, we |
590 | * do some mind-boggling hack here: SDL requires a custom main() |
626 | * do some mind-boggling hack here: SDL requires a custom main() |
591 | * on OS X, so... we provide one and call the original main(), which, |
627 | * on OS X, so... we provide one and call the original main(), which, |
592 | * due to shared library magic, calls -lSDLmain's main, not perl's main, |
628 | * due to shared library magic, calls -lSDLmain's main, not perl's main, |
593 | * and which calls our main (== SDL_main) back. |
629 | * and which calls our main (== SDL_main) back. |
594 | */ |
630 | */ |
595 | extern C_LINKAGE int |
631 | extern C_LINKAGE int |
596 | main (int argc, char *argv[]) |
632 | main (int argc, char *argv[]) |
597 | { |
633 | { |
598 | deliantra_main (); |
634 | deliantra_main (real_main); |
599 | } |
635 | } |
600 | |
636 | |
601 | #undef main |
637 | #undef main |
602 | |
638 | |
603 | extern C_LINKAGE int main (int argc, char *argv[]); |
639 | extern C_LINKAGE int main (int argc, char *argv[]); |
604 | |
640 | |
605 | static void |
641 | static void |
606 | SDL_braino (void) |
642 | SDL_main_hack (SV *real_main_) |
607 | { |
643 | { |
|
|
644 | real_main = real_main_; |
|
|
645 | |
608 | char *argv[] = { "deliantra client", 0 }; |
646 | char *argv[] = { "deliantra client", 0 }; |
609 | (main) (1, argv); |
647 | (main) (1, argv); |
610 | } |
648 | } |
611 | #else |
649 | #else |
612 | static void |
650 | static void |
613 | SDL_braino (void) |
651 | SDL_main_hack (SV *real_main) |
614 | { |
652 | { |
615 | deliantra_main (); |
653 | deliantra_main (real_main); |
616 | } |
654 | } |
617 | #endif |
655 | #endif |
618 | |
656 | |
619 | MODULE = Deliantra::Client PACKAGE = DC |
657 | MODULE = Deliantra::Client PACKAGE = DC |
620 | |
658 | |
… | |
… | |
871 | #endif |
909 | #endif |
872 | } |
910 | } |
873 | |
911 | |
874 | char *SDL_GetError () |
912 | char *SDL_GetError () |
875 | |
913 | |
876 | void SDL_braino () |
914 | void SDL_main_hack (SV *real_main) |
|
|
915 | PROTOTYPE: & |
877 | |
916 | |
878 | int SDL_Init (U32 flags) |
917 | int SDL_Init (U32 flags) |
879 | |
918 | |
880 | int SDL_InitSubSystem (U32 flags) |
919 | int SDL_InitSubSystem (U32 flags) |
881 | |
920 | |
882 | void SDL_QuitSubSystem (U32 flags) |
921 | void SDL_QuitSubSystem (U32 flags) |
883 | |
922 | |
884 | void SDL_Quit () |
923 | void SDL_Quit () |
885 | |
924 | |
886 | int SDL_GL_SetAttribute (int attr, int value) |
925 | int SDL_GL_SetAttribute (int attr, int value) |
|
|
926 | C_ARGS: (SDL_GLattr)attr, value |
887 | |
927 | |
888 | int SDL_GL_GetAttribute (int attr) |
928 | int SDL_GL_GetAttribute (int attr) |
889 | CODE: |
929 | CODE: |
890 | if (SDL_GL_GetAttribute (attr, &RETVAL)) |
930 | if (SDL_GL_GetAttribute ((SDL_GLattr)attr, &RETVAL)) |
891 | XSRETURN_UNDEF; |
931 | XSRETURN_UNDEF; |
892 | OUTPUT: |
932 | OUTPUT: |
893 | RETVAL |
933 | RETVAL |
894 | |
934 | |
895 | void |
935 | void |
… | |
… | |
968 | void |
1008 | void |
969 | SDL_GL_SwapBuffers () |
1009 | SDL_GL_SwapBuffers () |
970 | |
1010 | |
971 | char * |
1011 | char * |
972 | SDL_GetKeyName (int sym) |
1012 | SDL_GetKeyName (int sym) |
|
|
1013 | C_ARGS: (SDLKey)sym |
973 | |
1014 | |
974 | int |
1015 | int |
975 | SDL_GetAppState () |
1016 | SDL_GetAppState () |
976 | |
1017 | |
977 | int |
1018 | int |
… | |
… | |
1074 | OUTPUT: |
1115 | OUTPUT: |
1075 | RETVAL |
1116 | RETVAL |
1076 | |
1117 | |
1077 | int |
1118 | int |
1078 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
1119 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
1079 | POSTCALL: |
1120 | POSTCALL: |
1080 | Mix_HookMusicFinished (music_finished); |
1121 | Mix_HookMusicFinished (music_finished); |
1081 | Mix_ChannelFinished (channel_finished); |
1122 | Mix_ChannelFinished (channel_finished); |
1082 | |
1123 | |
1083 | void |
1124 | void |
1084 | Mix_QuerySpec () |
1125 | Mix_QuerySpec () |
… | |
… | |
1205 | |
1246 | |
1206 | SDL_LockSurface (surface2); |
1247 | SDL_LockSurface (surface2); |
1207 | EXTEND (SP, 6); |
1248 | EXTEND (SP, 6); |
1208 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
1249 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
1209 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
1250 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
1210 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
1251 | PUSHs (sv_2mortal (newSVpvn ((const char *)surface2->pixels, surface2->h * surface2->pitch))); |
1211 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
1252 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
1212 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
1253 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
1213 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
1254 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
1214 | SDL_UnlockSurface (surface2); |
1255 | SDL_UnlockSurface (surface2); |
1215 | |
1256 | |
… | |
… | |
1287 | MODULE = Deliantra::Client PACKAGE = DC::Font |
1328 | MODULE = Deliantra::Client PACKAGE = DC::Font |
1288 | |
1329 | |
1289 | PROTOTYPES: DISABLE |
1330 | PROTOTYPES: DISABLE |
1290 | |
1331 | |
1291 | DC::Font |
1332 | DC::Font |
1292 | new_from_file (SV *class, char *path, int id = 0) |
1333 | new_from_file (SV *klass, char *path, int id = 0) |
1293 | CODE: |
1334 | CODE: |
1294 | { |
1335 | { |
1295 | int count; |
1336 | int count; |
1296 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
1337 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
1297 | RETVAL = pango_fc_font_description_from_pattern (pattern, 0); |
1338 | RETVAL = pango_fc_font_description_from_pattern (pattern, 0); |
… | |
… | |
1326 | PROTOTYPE: |
1367 | PROTOTYPE: |
1327 | CODE: |
1368 | CODE: |
1328 | tc_restore (); |
1369 | tc_restore (); |
1329 | |
1370 | |
1330 | DC::Layout |
1371 | DC::Layout |
1331 | new (SV *class) |
1372 | new (SV *klass) |
1332 | CODE: |
1373 | CODE: |
1333 | New (0, RETVAL, 1, struct cf_layout); |
1374 | New (0, RETVAL, 1, struct cf_layout); |
1334 | |
1375 | |
1335 | RETVAL->pl = pango_layout_new (opengl_context); |
1376 | RETVAL->pl = pango_layout_new (opengl_context); |
1336 | RETVAL->r = 1.; |
1377 | RETVAL->r = 1.; |
… | |
… | |
1485 | |
1526 | |
1486 | void |
1527 | void |
1487 | set_height (DC::Layout self, int base_height) |
1528 | set_height (DC::Layout self, int base_height) |
1488 | CODE: |
1529 | CODE: |
1489 | if (self->base_height != base_height) |
1530 | if (self->base_height != base_height) |
1490 | { |
1531 | { |
1491 | self->base_height = base_height; |
1532 | self->base_height = base_height; |
1492 | layout_update_font (self); |
1533 | layout_update_font (self); |
1493 | } |
1534 | } |
1494 | |
1535 | |
1495 | void |
1536 | void |
… | |
… | |
1859 | MODULE = Deliantra::Client PACKAGE = DC::Map |
1900 | MODULE = Deliantra::Client PACKAGE = DC::Map |
1860 | |
1901 | |
1861 | PROTOTYPES: DISABLE |
1902 | PROTOTYPES: DISABLE |
1862 | |
1903 | |
1863 | DC::Map |
1904 | DC::Map |
1864 | new (SV *class) |
1905 | new (SV *klass) |
1865 | CODE: |
1906 | CODE: |
1866 | New (0, RETVAL, 1, struct map); |
1907 | New (0, RETVAL, 1, mapgrid); |
1867 | RETVAL->x = 0; |
1908 | RETVAL->x = 0; |
1868 | RETVAL->y = 0; |
1909 | RETVAL->y = 0; |
1869 | RETVAL->w = 0; |
1910 | RETVAL->w = 0; |
1870 | RETVAL->h = 0; |
1911 | RETVAL->h = 0; |
1871 | RETVAL->ox = 0; |
1912 | RETVAL->ox = 0; |
… | |
… | |
1908 | |
1949 | |
1909 | void |
1950 | void |
1910 | set_smooth (DC::Map self, int face, int smooth, int level) |
1951 | set_smooth (DC::Map self, int face, int smooth, int level) |
1911 | CODE: |
1952 | CODE: |
1912 | { |
1953 | { |
1913 | tileid texid; |
1954 | tileid texid; |
1914 | maptex *tex; |
1955 | maptex *tex; |
1915 | |
1956 | |
1916 | if (face < 0 || face >= self->faces) |
1957 | if (face < 0 || face >= self->faces) |
1917 | return; |
1958 | return; |
1918 | |
1959 | |
1919 | if (smooth < 0 || smooth >= self->faces) |
1960 | if (smooth < 0 || smooth >= self->faces) |
1920 | return; |
1961 | return; |
1921 | |
1962 | |
1922 | texid = self->face2tile [face]; |
1963 | texid = self->face2tile [face]; |
1923 | |
1964 | |
1924 | if (!texid) |
1965 | if (!texid) |
1925 | return; |
1966 | return; |
1926 | |
1967 | |
1927 | tex = self->tex + texid; |
1968 | tex = self->tex + texid; |
… | |
… | |
1960 | } |
2001 | } |
1961 | |
2002 | |
1962 | void |
2003 | void |
1963 | expire_textures (DC::Map self, int texid, int count) |
2004 | expire_textures (DC::Map self, int texid, int count) |
1964 | PPCODE: |
2005 | PPCODE: |
1965 | for (; texid < self->texs && count; ++texid, --count) |
2006 | for (; texid < self->texs && count; ++texid, --count) |
1966 | { |
2007 | { |
1967 | maptex *tex = self->tex + texid; |
2008 | maptex *tex = self->tex + texid; |
1968 | |
2009 | |
1969 | if (tex->name) |
2010 | if (tex->name) |
1970 | { |
2011 | { |
… | |
… | |
2025 | self->y += MAP_EXTEND_Y; |
2066 | self->y += MAP_EXTEND_Y; |
2026 | } |
2067 | } |
2027 | } |
2068 | } |
2028 | |
2069 | |
2029 | SV * |
2070 | SV * |
2030 | map1a_update (DC::Map self, SV *data_, int extmap) |
2071 | map1a_update (DC::Map self, SV *data_) |
2031 | CODE: |
2072 | CODE: |
2032 | { |
2073 | { |
2033 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
2074 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
2034 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
2075 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
2035 | mapcell *cell; |
2076 | mapcell *cell; |
… | |
… | |
2056 | |
2097 | |
2057 | //TODO: don't trust server data to be in-range(!) |
2098 | //TODO: don't trust server data to be in-range(!) |
2058 | |
2099 | |
2059 | if (flags & 8) |
2100 | if (flags & 8) |
2060 | { |
2101 | { |
|
|
2102 | uint8_t ext, cmd; |
|
|
2103 | |
2061 | if (extmap) |
2104 | do |
2062 | { |
2105 | { |
2063 | uint8_t ext, cmd; |
2106 | ext = *data++; |
|
|
2107 | cmd = ext & 0x7f; |
2064 | |
2108 | |
2065 | do |
2109 | if (cmd < 4) |
|
|
2110 | cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */ |
|
|
2111 | else if (cmd == 5) // health |
2066 | { |
2112 | { |
2067 | ext = *data++; |
|
|
2068 | cmd = ext & 0x7f; |
|
|
2069 | |
|
|
2070 | if (cmd < 4) |
|
|
2071 | cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */ |
|
|
2072 | else if (cmd == 5) // health |
|
|
2073 | { |
|
|
2074 | cell->stat_width = 1; |
2113 | cell->stat_width = 1; |
2075 | cell->stat_hp = *data++; |
2114 | cell->stat_hp = *data++; |
2076 | } |
|
|
2077 | else if (cmd == 6) // monster width |
|
|
2078 | cell->stat_width = *data++ + 1; |
|
|
2079 | else if (cmd == 0x47) |
|
|
2080 | { |
|
|
2081 | if (*data == 1) cell->player = data [1]; |
|
|
2082 | else if (*data == 2) cell->player = data [2] + (data [1] << 8); |
|
|
2083 | else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16); |
|
|
2084 | else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24); |
|
|
2085 | |
|
|
2086 | data += *data + 1; |
|
|
2087 | } |
|
|
2088 | else if (cmd == 8) // cell flags |
|
|
2089 | cell->flags = *data++; |
|
|
2090 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
2091 | data += *data + 1; |
|
|
2092 | else |
|
|
2093 | data++; |
|
|
2094 | } |
2115 | } |
2095 | while (ext & 0x80); |
2116 | else if (cmd == 6) // monster width |
|
|
2117 | cell->stat_width = *data++ + 1; |
|
|
2118 | else if (cmd == 0x47) |
|
|
2119 | { |
|
|
2120 | if (*data == 1) cell->player = data [1]; |
|
|
2121 | else if (*data == 2) cell->player = data [2] + (data [1] << 8); |
|
|
2122 | else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16); |
|
|
2123 | else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24); |
|
|
2124 | |
|
|
2125 | data += *data + 1; |
|
|
2126 | } |
|
|
2127 | else if (cmd == 8) // cell flags |
|
|
2128 | cell->flags = *data++; |
|
|
2129 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
2130 | data += *data + 1; |
|
|
2131 | else |
|
|
2132 | data++; |
2096 | } |
2133 | } |
2097 | else |
2134 | while (ext & 0x80); |
2098 | cell->darkness = *data++ + 1; |
|
|
2099 | } |
2135 | } |
2100 | |
2136 | |
2101 | for (z = 0; z <= 2; ++z) |
2137 | for (z = 0; z <= 2; ++z) |
2102 | if (flags & (4 >> z)) |
2138 | if (flags & (4 >> z)) |
2103 | { |
2139 | { |
… | |
… | |
2177 | | (b << 16) |
2213 | | (b << 16) |
2178 | | (a << 24); |
2214 | | (a << 24); |
2179 | } |
2215 | } |
2180 | } |
2216 | } |
2181 | |
2217 | |
2182 | RETVAL = map_sv; |
2218 | RETVAL = map_sv; |
2183 | } |
2219 | } |
2184 | OUTPUT: |
2220 | OUTPUT: |
2185 | RETVAL |
2221 | RETVAL |
2186 | |
2222 | |
2187 | void |
2223 | void |
2188 | draw (DC::Map self, int mx, int my, int sw, int sh, int Tw, int Th, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) |
2224 | draw (DC::Map self, int mx, int my, int sw, int sh, int Tw, int Th, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) |
2189 | CODE: |
2225 | CODE: |
2190 | { |
2226 | { |
2191 | int x, y, z; |
2227 | int x, y, z; |
2192 | |
2228 | |
2193 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
|
|
2194 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
|
|
2195 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) |
2229 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k), also, static! |
2196 | smooth_key skey; |
|
|
2197 | int pl_x, pl_y; |
2230 | int pl_x, pl_y; |
2198 | maptex pl_tex; |
2231 | maptex pl_tex; |
2199 | rc_t *rc = rc_alloc (); |
2232 | rc_t *rc = rc_alloc (); |
2200 | rc_t *rc_ov = rc_alloc (); |
2233 | rc_t *rc_ov = rc_alloc (); |
2201 | rc_key_t key; |
2234 | rc_key_t key; |
… | |
… | |
2204 | pl_tex.name = 0; |
2237 | pl_tex.name = 0; |
2205 | |
2238 | |
2206 | // that's current max. sorry. |
2239 | // that's current max. sorry. |
2207 | if (sw > 255) sw = 255; |
2240 | if (sw > 255) sw = 255; |
2208 | if (sh > 255) sh = 255; |
2241 | if (sh > 255) sh = 255; |
2209 | |
|
|
2210 | // clear key, in case of extra padding |
|
|
2211 | memset (&skey, 0, sizeof (skey)); |
|
|
2212 | |
2242 | |
2213 | memset (&key, 0, sizeof (key)); |
2243 | memset (&key, 0, sizeof (key)); |
2214 | key.r = 255; |
2244 | key.r = 255; |
2215 | key.g = 255; |
2245 | key.g = 255; |
2216 | key.b = 255; |
2246 | key.b = 255; |
… | |
… | |
2222 | my += self->y; |
2252 | my += self->y; |
2223 | |
2253 | |
2224 | // first pass: determine smooth_max |
2254 | // first pass: determine smooth_max |
2225 | // rather ugly, if you ask me |
2255 | // rather ugly, if you ask me |
2226 | // could also be stored inside mapcell and updated on change |
2256 | // could also be stored inside mapcell and updated on change |
2227 | memset (smooth_max, 0, sizeof (smooth_max)); |
2257 | memset (smooth_max, 0, sizeof (smooth_max[0]) * (sh + 1)); |
2228 | |
2258 | |
2229 | for (y = 0; y < sh; y++) |
2259 | for (y = 0; y < sh; y++) |
2230 | if (0 <= y + my && y + my < self->rows) |
2260 | if (0 <= y + my && y + my < self->rows) |
2231 | { |
2261 | { |
2232 | maprow *row = self->row + (y + my); |
2262 | maprow *row = self->row + (y + my); |
… | |
… | |
2247 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2277 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2248 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2278 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2249 | |
2279 | |
2250 | for (z = 0; z <= 2; z++) |
2280 | for (z = 0; z <= 2; z++) |
2251 | { |
2281 | { |
2252 | memset (smooth_level, 0, sizeof (smooth_level)); |
2282 | std::bitset<256> smooth_level; // one bit for every possible smooth level |
|
|
2283 | smooth_key skey; |
|
|
2284 | smooth_hash smooth; |
2253 | key.texname = -1; |
2285 | key.texname = -1; |
2254 | |
2286 | |
2255 | for (y = 0; y < sh; y++) |
2287 | for (y = 0; y < sh; y++) |
2256 | if (0 <= y + my && y + my < self->rows) |
2288 | if (0 <= y + my && y + my < self->rows) |
2257 | { |
2289 | { |
… | |
… | |
2299 | if (tex.smoothtile) |
2331 | if (tex.smoothtile) |
2300 | { |
2332 | { |
2301 | skey.tile = tex.smoothtile; |
2333 | skey.tile = tex.smoothtile; |
2302 | skey.level = tex.smoothlevel; |
2334 | skey.level = tex.smoothlevel; |
2303 | |
2335 | |
2304 | smooth_level [tex.smoothlevel >> 5] |= ((uint32_t)1) << (tex.smoothlevel & 31); |
2336 | smooth_level[tex.smoothlevel] = 1; |
2305 | |
2337 | |
2306 | // add bits to current tile and all neighbours. skey.x|y is |
2338 | // add bits to current tile and all neighbours. skey.x|y is |
2307 | // shifted +1|+1 so we always stay positive. |
2339 | // shifted +1|+1 so we always stay positive. |
2308 | |
2340 | |
2309 | // bits is ___n cccc CCCC bbbb |
2341 | // bits is ___n cccc CCCC bbbb |
… | |
… | |
2317 | |
2349 | |
2318 | // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· |
2350 | // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· |
2319 | // ·· ·· ·┏ ┓· |
2351 | // ·· ·· ·┏ ┓· |
2320 | |
2352 | |
2321 | // full tile |
2353 | // full tile |
2322 | skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x1000); |
2354 | skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x1000); |
2323 | |
2355 | |
2324 | // borders |
2356 | // borders |
2325 | skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0091); |
2357 | skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0091); |
2326 | skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0032); |
2358 | skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0032); |
2327 | skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0064); |
2359 | skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0064); |
2328 | skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, &skey, 0x00c8); |
2360 | skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, skey, 0x00c8); |
2329 | |
2361 | |
2330 | // corners |
2362 | // corners |
2331 | skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0100); |
2363 | skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0100); |
2332 | skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0200); |
2364 | skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0200); |
2333 | skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400); |
2365 | skey.x = x ; skey.y = y ; smooth_or_bits (smooth, skey, 0x0400); |
2334 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); |
2366 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, skey, 0x0800); |
2335 | } |
2367 | } |
2336 | } |
2368 | } |
2337 | |
2369 | |
2338 | if (expect_false (z == 2) && expect_false (cell->flags)) |
2370 | if (expect_false (z == 2) && expect_false (cell->flags)) |
2339 | { |
2371 | { |
… | |
… | |
2366 | { |
2398 | { |
2367 | int w, b; |
2399 | int w, b; |
2368 | |
2400 | |
2369 | glEnable (GL_TEXTURE_2D); |
2401 | glEnable (GL_TEXTURE_2D); |
2370 | glBegin (GL_QUADS); |
2402 | glBegin (GL_QUADS); |
2371 | for (w = 0; w < 256 / 32; ++w) |
2403 | for (int level = 0; level < smooth_level.size (); ++level) |
|
|
2404 | if (smooth_level[level]) |
|
|
2405 | for (auto &&it = smooth.begin (); it != smooth.end (); ++it) |
2372 | { |
2406 | { |
2373 | uint32_t smask = smooth_level [w]; |
2407 | smooth_key &skey = it->first; |
2374 | if (smask) |
2408 | IV bits = it->second; |
2375 | for (b = 0; b < 32; ++b) |
2409 | |
2376 | if (smask & (((uint32_t)1) << b)) |
2410 | if (!(bits & 0x1000) |
|
|
2411 | && skey.level == level |
|
|
2412 | && level > smooth_max [skey.x][skey.y]) |
2377 | { |
2413 | { |
2378 | int level = (w << 5) | b; |
2414 | maptex tex = self->tex [skey.tile]; |
|
|
2415 | int px = (((int)skey.x) - 1) * Tw; |
|
|
2416 | int py = (((int)skey.y) - 1) * Th; |
|
|
2417 | int border = bits & 15; |
|
|
2418 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
|
|
2419 | float dx = tex.s * .0625f; // 16 images/row |
|
|
2420 | float dy = tex.t * .5f ; // 2 images/column |
|
|
2421 | |
2379 | HE *he; |
2422 | if (tex.name) |
2380 | |
|
|
2381 | hv_iterinit (smooth); |
|
|
2382 | while ((he = hv_iternext (smooth))) |
|
|
2383 | { |
2423 | { |
2384 | smooth_key *skey = (smooth_key *)HeKEY (he); |
2424 | // this time avoiding texture state changes |
2385 | IV bits = SvIVX (HeVAL (he)); |
2425 | // save gobs of state changes. |
2386 | |
2426 | if (key.texname != tex.name) |
2387 | if (!(bits & 0x1000) |
|
|
2388 | && skey->level == level |
|
|
2389 | && level > smooth_max [skey->x][skey->y]) |
|
|
2390 | { |
2427 | { |
2391 | maptex tex = self->tex [skey->tile]; |
|
|
2392 | int px = (((int)skey->x) - 1) * Tw; |
|
|
2393 | int py = (((int)skey->y) - 1) * Th; |
|
|
2394 | int border = bits & 15; |
|
|
2395 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
|
|
2396 | float dx = tex.s * .0625f; // 16 images/row |
|
|
2397 | float dy = tex.t * .5f ; // 2 images/column |
|
|
2398 | |
|
|
2399 | if (tex.name) |
|
|
2400 | { |
|
|
2401 | // this time avoiding texture state changes |
|
|
2402 | // save gobs of state changes. |
|
|
2403 | if (key.texname != tex.name) |
|
|
2404 | { |
|
|
2405 | self->tex [skey->tile].unused = 0; |
2428 | self->tex [skey.tile].unused = 0; |
2406 | |
2429 | |
2407 | glEnd (); |
2430 | glEnd (); |
2408 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
2431 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
2409 | glBegin (GL_QUADS); |
2432 | glBegin (GL_QUADS); |
2410 | } |
2433 | } |
2411 | |
2434 | |
2412 | if (border) |
2435 | if (border) |
2413 | { |
2436 | { |
2414 | float ox = border * dx; |
2437 | float ox = border * dx; |
2415 | |
2438 | |
2416 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
2439 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
2417 | glTexCoord2f (ox , dy ); glVertex2i (px , py + Th); |
2440 | glTexCoord2f (ox , dy ); glVertex2i (px , py + Th); |
2418 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); |
2441 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); |
2419 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); |
2442 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); |
2420 | } |
2443 | } |
2421 | |
2444 | |
2422 | if (corner) |
2445 | if (corner) |
2423 | { |
2446 | { |
2424 | float ox = corner * dx; |
2447 | float ox = corner * dx; |
2425 | |
2448 | |
2426 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
2449 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
2427 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th); |
2450 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th); |
2428 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th); |
2451 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th); |
2429 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py ); |
2452 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py ); |
2430 | } |
|
|
2431 | } |
|
|
2432 | } |
2453 | } |
2433 | } |
2454 | } |
2434 | } |
2455 | } |
2435 | } |
2456 | } |
2436 | |
2457 | |
2437 | glEnd (); |
2458 | glEnd (); |
2438 | glDisable (GL_TEXTURE_2D); |
2459 | glDisable (GL_TEXTURE_2D); |
2439 | key.texname = -1; |
2460 | key.texname = -1; |
2440 | } |
2461 | } |
2441 | |
|
|
2442 | hv_clear (smooth); |
|
|
2443 | } |
2462 | } |
2444 | |
2463 | |
2445 | if (pl_tex.name) |
2464 | if (pl_tex.name) |
2446 | { |
2465 | { |
2447 | maptex tex = pl_tex; |
2466 | maptex tex = pl_tex; |
… | |
… | |
2716 | else |
2735 | else |
2717 | *data++ = 0; |
2736 | *data++ = 0; |
2718 | } |
2737 | } |
2719 | } |
2738 | } |
2720 | |
2739 | |
2721 | /* if size is w*h + 5 then no data has been found */ |
2740 | /* if size is w*h + 5 then no data has been found */ |
2722 | if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) |
2741 | if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) |
2723 | { |
2742 | { |
2724 | SvPOK_only (data_sv); |
2743 | SvPOK_only (data_sv); |
2725 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
2744 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
2726 | } |
2745 | } |
2727 | |
2746 | |
2728 | RETVAL = data_sv; |
2747 | RETVAL = data_sv; |
2729 | } |
2748 | } |
2730 | OUTPUT: |
2749 | OUTPUT: |
2731 | RETVAL |
2750 | RETVAL |
2732 | |
2751 | |
2733 | void |
2752 | void |
… | |
… | |
2740 | STRLEN len; |
2759 | STRLEN len; |
2741 | uint8_t *data, *end; |
2760 | uint8_t *data, *end; |
2742 | |
2761 | |
2743 | len = SvLEN (data_sv); |
2762 | len = SvLEN (data_sv); |
2744 | SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more |
2763 | SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more |
2745 | data = SvPVbyte_nolen (data_sv); |
2764 | data = (uint8_t *)SvPVbyte_nolen (data_sv); |
2746 | end = data + len + 8; |
2765 | end = data + len + 8; |
2747 | |
2766 | |
2748 | if (len < 5) |
2767 | if (len < 5) |
2749 | XSRETURN_EMPTY; |
2768 | XSRETURN_EMPTY; |
2750 | |
2769 | |
… | |
… | |
2811 | } |
2830 | } |
2812 | |
2831 | |
2813 | MODULE = Deliantra::Client PACKAGE = DC::RW |
2832 | MODULE = Deliantra::Client PACKAGE = DC::RW |
2814 | |
2833 | |
2815 | DC::RW |
2834 | DC::RW |
2816 | new (SV *class, SV *data_sv) |
2835 | new (SV *klass, SV *data_sv) |
2817 | CODE: |
2836 | CODE: |
2818 | { |
2837 | { |
2819 | STRLEN datalen; |
2838 | STRLEN datalen; |
2820 | char *data = SvPVbyte (data_sv, datalen); |
2839 | char *data = SvPVbyte (data_sv, datalen); |
2821 | |
2840 | |
… | |
… | |
2823 | } |
2842 | } |
2824 | OUTPUT: |
2843 | OUTPUT: |
2825 | RETVAL |
2844 | RETVAL |
2826 | |
2845 | |
2827 | DC::RW |
2846 | DC::RW |
2828 | new_from_file (SV *class, const char *path, const char *mode = "rb") |
2847 | new_from_file (SV *klass, const char *path, const char *mode = "rb") |
2829 | CODE: |
2848 | CODE: |
2830 | RETVAL = SDL_RWFromFile (path, mode); |
2849 | RETVAL = SDL_RWFromFile (path, mode); |
2831 | OUTPUT: |
2850 | OUTPUT: |
2832 | RETVAL |
2851 | RETVAL |
2833 | |
2852 | |
… | |
… | |
2942 | #else |
2961 | #else |
2943 | XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); |
2962 | XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); |
2944 | #endif |
2963 | #endif |
2945 | |
2964 | |
2946 | DC::MixChunk |
2965 | DC::MixChunk |
2947 | new (SV *class, DC::RW rwops) |
2966 | new (SV *klass, DC::RW rwops) |
2948 | CODE: |
2967 | CODE: |
2949 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2968 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2950 | OUTPUT: |
2969 | OUTPUT: |
2951 | RETVAL |
2970 | RETVAL |
2952 | |
2971 | |
… | |
… | |
3022 | RETVAL = Mix_PlayingMusic (); |
3041 | RETVAL = Mix_PlayingMusic (); |
3023 | OUTPUT: |
3042 | OUTPUT: |
3024 | RETVAL |
3043 | RETVAL |
3025 | |
3044 | |
3026 | DC::MixMusic |
3045 | DC::MixMusic |
3027 | new (SV *class, DC::RW rwops) |
3046 | new (SV *klass, DC::RW rwops) |
3028 | CODE: |
3047 | CODE: |
3029 | RETVAL = Mix_LoadMUS_RW (rwops); |
3048 | RETVAL = Mix_LoadMUS_RW (rwops); |
3030 | OUTPUT: |
3049 | OUTPUT: |
3031 | RETVAL |
3050 | RETVAL |
3032 | |
3051 | |
… | |
… | |
3185 | gl.BlendFuncSeparateEXT = 0; |
3204 | gl.BlendFuncSeparateEXT = 0; |
3186 | |
3205 | |
3187 | void |
3206 | void |
3188 | apple_nvidia_bug (int enable) |
3207 | apple_nvidia_bug (int enable) |
3189 | |
3208 | |
3190 | char * |
3209 | const char * |
3191 | gl_vendor () |
3210 | gl_vendor () |
3192 | CODE: |
3211 | CODE: |
3193 | RETVAL = (char *)glGetString (GL_VENDOR); |
3212 | RETVAL = (const char *)glGetString (GL_VENDOR); |
3194 | OUTPUT: |
3213 | OUTPUT: |
3195 | RETVAL |
3214 | RETVAL |
3196 | |
3215 | |
3197 | char * |
3216 | const char * |
3198 | gl_version () |
3217 | gl_version () |
3199 | CODE: |
3218 | CODE: |
3200 | RETVAL = (char *)glGetString (GL_VERSION); |
3219 | RETVAL = (const char *)glGetString (GL_VERSION); |
3201 | OUTPUT: |
3220 | OUTPUT: |
3202 | RETVAL |
3221 | RETVAL |
3203 | |
3222 | |
3204 | char * |
3223 | const char * |
3205 | gl_extensions () |
3224 | gl_extensions () |
3206 | CODE: |
3225 | CODE: |
3207 | RETVAL = (char *)glGetString (GL_EXTENSIONS); |
3226 | RETVAL = (const char *)glGetString (GL_EXTENSIONS); |
3208 | OUTPUT: |
3227 | OUTPUT: |
3209 | RETVAL |
3228 | RETVAL |
3210 | |
3229 | |
3211 | const char *glGetString (GLenum pname) |
3230 | const char *glGetString (GLenum pname) |
|
|
3231 | CODE: |
|
|
3232 | RETVAL = (const char *)glGetString (pname); |
|
|
3233 | OUTPUT: |
|
|
3234 | RETVAL |
3212 | |
3235 | |
3213 | GLint glGetInteger (GLenum pname) |
3236 | GLint glGetInteger (GLenum pname) |
3214 | CODE: |
3237 | CODE: |
3215 | glGetIntegerv (pname, &RETVAL); |
3238 | glGetIntegerv (pname, &RETVAL); |
3216 | OUTPUT: |
3239 | OUTPUT: |
… | |
… | |
3419 | |
3442 | |
3420 | void |
3443 | void |
3421 | find_widget (SV *self, NV x, NV y) |
3444 | find_widget (SV *self, NV x, NV y) |
3422 | PPCODE: |
3445 | PPCODE: |
3423 | { |
3446 | { |
3424 | if (within_widget (self, x, y)) |
3447 | if (within_widget (self, x, y)) |
3425 | XPUSHs (self); |
3448 | XPUSHs (self); |
3426 | } |
3449 | } |
3427 | |
3450 | |
3428 | BOOT: |
3451 | BOOT: |
3429 | { |
3452 | { |
… | |
… | |
3437 | |
3460 | |
3438 | void |
3461 | void |
3439 | draw (SV *self) |
3462 | draw (SV *self) |
3440 | CODE: |
3463 | CODE: |
3441 | { |
3464 | { |
3442 | HV *hv; |
3465 | HV *hv; |
3443 | SV **svp; |
3466 | SV **svp; |
3444 | NV x, y, w, h; |
3467 | NV x, y, w, h; |
3445 | SV *draw_x_sv = GvSV (draw_x_gv); |
3468 | SV *draw_x_sv = GvSV (draw_x_gv); |
3446 | SV *draw_y_sv = GvSV (draw_y_gv); |
3469 | SV *draw_y_sv = GvSV (draw_y_gv); |
3447 | SV *draw_w_sv = GvSV (draw_w_gv); |
3470 | SV *draw_w_sv = GvSV (draw_w_gv); |
3448 | SV *draw_h_sv = GvSV (draw_h_gv); |
3471 | SV *draw_h_sv = GvSV (draw_h_gv); |