… | |
… | |
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> |
33 | |
37 | |
34 | #define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW |
38 | #define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW |
35 | |
39 | |
36 | #include <SDL.h> |
40 | #include <SDL.h> |
37 | #include <SDL_thread.h> |
41 | #include <SDL_thread.h> |
… | |
… | |
48 | #endif |
52 | #endif |
49 | |
53 | |
50 | #define PANGO_ENABLE_BACKEND |
54 | #define PANGO_ENABLE_BACKEND |
51 | #define G_DISABLE_CAST_CHECKS |
55 | #define G_DISABLE_CAST_CHECKS |
52 | |
56 | |
53 | #include <glib/gmacros.h> |
57 | #include <glib.h> |
54 | |
58 | |
55 | #include <pango/pango.h> |
59 | #include <pango/pango.h> |
56 | |
60 | |
57 | #ifndef PANGO_VERSION_CHECK |
61 | #ifndef PANGO_VERSION_CHECK |
58 | # define PANGO_VERSION_CHECK(a,b,c) 0 |
62 | # define PANGO_VERSION_CHECK(a,b,c) 0 |
… | |
… | |
184 | { |
188 | { |
185 | GSList *attrs = run->item->analysis.extra_attrs; |
189 | GSList *attrs = run->item->analysis.extra_attrs; |
186 | |
190 | |
187 | while (attrs) |
191 | while (attrs) |
188 | { |
192 | { |
189 | PangoAttribute *attr = attrs->data; |
193 | PangoAttribute *attr = (PangoAttribute *)attrs->data; |
190 | |
194 | |
191 | if (attr->klass->type == PANGO_ATTR_SHAPE) |
195 | if (attr->klass->type == PANGO_ATTR_SHAPE) |
192 | return 1; |
196 | return 1; |
193 | |
197 | |
194 | attrs = attrs->next; |
198 | attrs = attrs->next; |
… | |
… | |
212 | static void |
216 | static void |
213 | substitute_func (FcPattern *pattern, gpointer data) |
217 | substitute_func (FcPattern *pattern, gpointer data) |
214 | { |
218 | { |
215 | FcPatternAddBool (pattern, FC_HINTING, 1); |
219 | FcPatternAddBool (pattern, FC_HINTING, 1); |
216 | #ifdef FC_HINT_STYLE |
220 | #ifdef FC_HINT_STYLE |
217 | FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); |
221 | FcPatternAddInteger (pattern, FC_HINT_STYLE, FC_HINT_FULL); |
218 | #endif |
222 | #endif |
219 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
223 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
220 | } |
224 | } |
221 | |
225 | |
222 | static void |
226 | static void |
… | |
… | |
439 | CELL_CLEAR (cell); |
443 | CELL_CLEAR (cell); |
440 | } |
444 | } |
441 | } |
445 | } |
442 | } |
446 | } |
443 | |
447 | |
444 | typedef struct { |
448 | struct smooth_key |
|
|
449 | { |
445 | tileid tile; |
450 | tileid tile; |
446 | uint8_t x, y, level; |
451 | uint8_t x, y, level; |
447 | } smooth_key; |
452 | |
|
|
453 | bool operator == (const smooth_key &o) const |
|
|
454 | { |
|
|
455 | return tile == o.tile && x == o.x && y == o.y && level == o.level; |
|
|
456 | } |
|
|
457 | }; |
|
|
458 | |
|
|
459 | typedef ska::flat_hash_map<smooth_key, IV> smooth_hash; |
|
|
460 | |
|
|
461 | namespace std { |
|
|
462 | template <> |
|
|
463 | struct hash<smooth_key> |
|
|
464 | { |
|
|
465 | size_t operator () (const smooth_key &v) const |
|
|
466 | { |
|
|
467 | return v.tile + (v.x << 8) + (v.y << 16) + (v.level << 24); |
|
|
468 | } |
|
|
469 | }; |
|
|
470 | } |
448 | |
471 | |
449 | static void |
472 | static void |
450 | smooth_or_bits (HV *hv, smooth_key *key, IV bits) |
473 | smooth_or_bits (smooth_hash &h, smooth_key &key, IV bits) |
451 | { |
474 | { |
452 | SV **sv = hv_fetch (hv, (char *)key, sizeof (*key), 1); |
475 | auto &&it = h.find (key); |
453 | |
476 | |
454 | if (SvIOK (*sv)) |
477 | if (it == h.end ()) |
455 | SvIV_set (*sv, SvIVX (*sv) | bits); |
478 | h.insert (std::make_pair (key, bits)); |
456 | else |
479 | else |
457 | sv_setiv (*sv, bits); |
480 | it->second |= bits; |
458 | } |
481 | } |
459 | |
482 | |
460 | static void |
483 | static void |
461 | music_finished (void) |
484 | music_finished (void) |
462 | { |
485 | { |
… | |
… | |
481 | ev.data2 = 0; |
504 | ev.data2 = 0; |
482 | |
505 | |
483 | SDL_PushEvent ((SDL_Event *)&ev); |
506 | SDL_PushEvent ((SDL_Event *)&ev); |
484 | } |
507 | } |
485 | |
508 | |
|
|
509 | // approximately divide by 255 |
486 | static unsigned int |
510 | static unsigned int |
487 | div255 (unsigned int n) |
511 | div255 (unsigned int n) |
488 | { |
512 | { |
489 | return (n + (n >> 8)) >> 8; |
513 | return (n + (n >> 8)) >> 8; |
490 | } |
514 | } |
… | |
… | |
577 | |
601 | |
578 | return mod; |
602 | return mod; |
579 | } |
603 | } |
580 | |
604 | |
581 | static void |
605 | static void |
582 | deliantra_main () |
606 | deliantra_main (SV *real_main) |
583 | { |
607 | { |
584 | char *argv[] = { 0 }; |
608 | dSP; |
585 | call_argv ("::main", G_DISCARD | G_VOID, argv); |
609 | |
|
|
610 | PUSHMARK (SP); |
|
|
611 | call_sv (real_main, G_DISCARD | G_VOID); |
586 | } |
612 | } |
587 | |
613 | |
588 | #ifdef __MACOSX__ |
614 | #ifdef __MACOSX__ |
|
|
615 | static SV *real_main; |
|
|
616 | |
589 | /* to due surprising braindamage on the side of SDL design, we |
617 | /* to due surprising braindamage on the side of SDL design, we |
590 | * do some mind-boggling hack here: SDL requires a custom main() |
618 | * 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, |
619 | * on OS X, so... we provide one and call the original main(), which, |
592 | * due to share dlibrary magic, calls -lSDLmain's main, not perl's main, |
620 | * due to shared library magic, calls -lSDLmain's main, not perl's main, |
593 | * and which calls our main (== SDL_main) back. |
621 | * and which calls our main (== SDL_main) back. |
594 | */ |
622 | */ |
595 | extern C_LINKAGE int |
623 | extern C_LINKAGE int |
596 | main (int argc, char *argv[]) |
624 | main (int argc, char *argv[]) |
597 | { |
625 | { |
598 | deliantra_main (); |
626 | deliantra_main (real_main); |
599 | } |
627 | } |
600 | |
628 | |
601 | #undef main |
629 | #undef main |
602 | |
630 | |
603 | extern C_LINKAGE int main (int argc, char *argv[]); |
631 | extern C_LINKAGE int main (int argc, char *argv[]); |
604 | |
632 | |
605 | static void |
633 | static void |
606 | SDL_braino (void) |
634 | SDL_main_hack (SV *real_main_) |
607 | { |
635 | { |
|
|
636 | real_main = real_main_; |
|
|
637 | |
608 | char *argv[] = { "deliantra client", 0 }; |
638 | char *argv[] = { "deliantra client", 0 }; |
609 | (main) (1, argv); |
639 | (main) (1, argv); |
610 | } |
640 | } |
611 | #else |
641 | #else |
612 | static void |
642 | static void |
613 | SDL_braino (void) |
643 | SDL_main_hack (SV *real_main) |
614 | { |
644 | { |
615 | deliantra_main (); |
645 | deliantra_main (real_main); |
616 | } |
646 | } |
617 | #endif |
647 | #endif |
618 | |
648 | |
619 | MODULE = Deliantra::Client PACKAGE = DC |
649 | MODULE = Deliantra::Client PACKAGE = DC |
620 | |
650 | |
… | |
… | |
871 | #endif |
901 | #endif |
872 | } |
902 | } |
873 | |
903 | |
874 | char *SDL_GetError () |
904 | char *SDL_GetError () |
875 | |
905 | |
876 | void SDL_braino () |
906 | void SDL_main_hack (SV *real_main) |
|
|
907 | PROTOTYPE: & |
877 | |
908 | |
878 | int SDL_Init (U32 flags) |
909 | int SDL_Init (U32 flags) |
879 | |
910 | |
880 | int SDL_InitSubSystem (U32 flags) |
911 | int SDL_InitSubSystem (U32 flags) |
881 | |
912 | |
882 | void SDL_QuitSubSystem (U32 flags) |
913 | void SDL_QuitSubSystem (U32 flags) |
883 | |
914 | |
884 | void SDL_Quit () |
915 | void SDL_Quit () |
885 | |
916 | |
886 | int SDL_GL_SetAttribute (int attr, int value) |
917 | int SDL_GL_SetAttribute (int attr, int value) |
|
|
918 | C_ARGS: (SDL_GLattr)attr, value |
887 | |
919 | |
888 | int SDL_GL_GetAttribute (int attr) |
920 | int SDL_GL_GetAttribute (int attr) |
889 | CODE: |
921 | CODE: |
890 | if (SDL_GL_GetAttribute (attr, &RETVAL)) |
922 | if (SDL_GL_GetAttribute ((SDL_GLattr)attr, &RETVAL)) |
891 | XSRETURN_UNDEF; |
923 | XSRETURN_UNDEF; |
892 | OUTPUT: |
924 | OUTPUT: |
893 | RETVAL |
925 | RETVAL |
894 | |
926 | |
895 | void |
927 | void |
… | |
… | |
950 | ); |
982 | ); |
951 | |
983 | |
952 | if (RETVAL) |
984 | if (RETVAL) |
953 | { |
985 | { |
954 | av_clear (texture_av); |
986 | av_clear (texture_av); |
955 | |
|
|
956 | SDL_WM_SetCaption ("Deliantra MORPG Client " VERSION, "Deliantra"); |
|
|
957 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
987 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
958 | #include "glfunc.h" |
988 | #include "glfunc.h" |
959 | #undef GL_FUNC |
989 | #undef GL_FUNC |
960 | |
|
|
961 | if (!gl.ActiveTexture ) gl.ActiveTexture = gl.ActiveTextureARB; |
990 | if (!gl.ActiveTexture ) gl.ActiveTexture = gl.ActiveTextureARB; |
962 | if (!gl.MultiTexCoord2f) gl.MultiTexCoord2f = gl.MultiTexCoord2fARB; |
991 | if (!gl.MultiTexCoord2f) gl.MultiTexCoord2f = gl.MultiTexCoord2fARB; |
963 | } |
992 | } |
964 | } |
993 | } |
965 | OUTPUT: |
994 | OUTPUT: |
966 | RETVAL |
995 | RETVAL |
967 | |
996 | |
968 | void |
997 | void |
|
|
998 | SDL_WM_SetCaption (const char *title, const char *icon) |
|
|
999 | |
|
|
1000 | void |
969 | SDL_GL_SwapBuffers () |
1001 | SDL_GL_SwapBuffers () |
970 | |
1002 | |
971 | char * |
1003 | char * |
972 | SDL_GetKeyName (int sym) |
1004 | SDL_GetKeyName (int sym) |
|
|
1005 | C_ARGS: (SDLKey)sym |
973 | |
1006 | |
974 | int |
1007 | int |
975 | SDL_GetAppState () |
1008 | SDL_GetAppState () |
976 | |
1009 | |
977 | int |
1010 | int |
978 | SDL_GetModState () |
1011 | SDL_GetModState () |
979 | |
1012 | |
|
|
1013 | int |
|
|
1014 | SDL_WaitEvent () |
|
|
1015 | C_ARGS: 0 |
|
|
1016 | |
980 | void |
1017 | void |
|
|
1018 | SDL_PumpEvents () |
|
|
1019 | |
|
|
1020 | void |
981 | poll_events () |
1021 | peep_events () |
982 | PPCODE: |
1022 | PPCODE: |
983 | { |
1023 | { |
984 | SDL_Event ev; |
1024 | SDL_Event ev; |
985 | |
1025 | |
986 | SDL_PumpEvents (); |
1026 | SDL_PumpEvents (); |
… | |
… | |
1067 | OUTPUT: |
1107 | OUTPUT: |
1068 | RETVAL |
1108 | RETVAL |
1069 | |
1109 | |
1070 | int |
1110 | int |
1071 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
1111 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
1072 | POSTCALL: |
1112 | POSTCALL: |
1073 | Mix_HookMusicFinished (music_finished); |
1113 | Mix_HookMusicFinished (music_finished); |
1074 | Mix_ChannelFinished (channel_finished); |
1114 | Mix_ChannelFinished (channel_finished); |
1075 | |
1115 | |
1076 | void |
1116 | void |
1077 | Mix_QuerySpec () |
1117 | Mix_QuerySpec () |
… | |
… | |
1139 | OUTPUT: |
1179 | OUTPUT: |
1140 | RETVAL |
1180 | RETVAL |
1141 | |
1181 | |
1142 | void |
1182 | void |
1143 | IMG_Init (int flags = IMG_INIT_JPG | IMG_INIT_PNG) |
1183 | IMG_Init (int flags = IMG_INIT_JPG | IMG_INIT_PNG) |
|
|
1184 | |
|
|
1185 | # MIX_INIT_MP3 gives smpeg + libstdc++ + libgcc_s |
|
|
1186 | void |
|
|
1187 | Mix_Init (int flags = MIX_INIT_MOD | MIX_INIT_OGG) |
1144 | |
1188 | |
1145 | void |
1189 | void |
1146 | load_image_inline (SV *image_) |
1190 | load_image_inline (SV *image_) |
1147 | ALIAS: |
1191 | ALIAS: |
1148 | load_image_file = 1 |
1192 | load_image_file = 1 |
… | |
… | |
1194 | |
1238 | |
1195 | SDL_LockSurface (surface2); |
1239 | SDL_LockSurface (surface2); |
1196 | EXTEND (SP, 6); |
1240 | EXTEND (SP, 6); |
1197 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
1241 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
1198 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
1242 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
1199 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
1243 | PUSHs (sv_2mortal (newSVpvn ((const char *)surface2->pixels, surface2->h * surface2->pitch))); |
1200 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
1244 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
1201 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
1245 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
1202 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
1246 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
1203 | SDL_UnlockSurface (surface2); |
1247 | SDL_UnlockSurface (surface2); |
1204 | |
1248 | |
… | |
… | |
1276 | MODULE = Deliantra::Client PACKAGE = DC::Font |
1320 | MODULE = Deliantra::Client PACKAGE = DC::Font |
1277 | |
1321 | |
1278 | PROTOTYPES: DISABLE |
1322 | PROTOTYPES: DISABLE |
1279 | |
1323 | |
1280 | DC::Font |
1324 | DC::Font |
1281 | new_from_file (SV *class, char *path, int id = 0) |
1325 | new_from_file (SV *klass, char *path, int id = 0) |
1282 | CODE: |
1326 | CODE: |
1283 | { |
1327 | { |
1284 | int count; |
1328 | int count; |
1285 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
1329 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
1286 | RETVAL = pango_fc_font_description_from_pattern (pattern, 0); |
1330 | RETVAL = pango_fc_font_description_from_pattern (pattern, 0); |
… | |
… | |
1315 | PROTOTYPE: |
1359 | PROTOTYPE: |
1316 | CODE: |
1360 | CODE: |
1317 | tc_restore (); |
1361 | tc_restore (); |
1318 | |
1362 | |
1319 | DC::Layout |
1363 | DC::Layout |
1320 | new (SV *class) |
1364 | new (SV *klass) |
1321 | CODE: |
1365 | CODE: |
1322 | New (0, RETVAL, 1, struct cf_layout); |
1366 | New (0, RETVAL, 1, struct cf_layout); |
1323 | |
1367 | |
1324 | RETVAL->pl = pango_layout_new (opengl_context); |
1368 | RETVAL->pl = pango_layout_new (opengl_context); |
1325 | RETVAL->r = 1.; |
1369 | RETVAL->r = 1.; |
… | |
… | |
1474 | |
1518 | |
1475 | void |
1519 | void |
1476 | set_height (DC::Layout self, int base_height) |
1520 | set_height (DC::Layout self, int base_height) |
1477 | CODE: |
1521 | CODE: |
1478 | if (self->base_height != base_height) |
1522 | if (self->base_height != base_height) |
1479 | { |
1523 | { |
1480 | self->base_height = base_height; |
1524 | self->base_height = base_height; |
1481 | layout_update_font (self); |
1525 | layout_update_font (self); |
1482 | } |
1526 | } |
1483 | |
1527 | |
1484 | void |
1528 | void |
… | |
… | |
1848 | MODULE = Deliantra::Client PACKAGE = DC::Map |
1892 | MODULE = Deliantra::Client PACKAGE = DC::Map |
1849 | |
1893 | |
1850 | PROTOTYPES: DISABLE |
1894 | PROTOTYPES: DISABLE |
1851 | |
1895 | |
1852 | DC::Map |
1896 | DC::Map |
1853 | new (SV *class) |
1897 | new (SV *klass) |
1854 | CODE: |
1898 | CODE: |
1855 | New (0, RETVAL, 1, struct map); |
1899 | New (0, RETVAL, 1, struct map); |
1856 | RETVAL->x = 0; |
1900 | RETVAL->x = 0; |
1857 | RETVAL->y = 0; |
1901 | RETVAL->y = 0; |
1858 | RETVAL->w = 0; |
1902 | RETVAL->w = 0; |
… | |
… | |
1897 | |
1941 | |
1898 | void |
1942 | void |
1899 | set_smooth (DC::Map self, int face, int smooth, int level) |
1943 | set_smooth (DC::Map self, int face, int smooth, int level) |
1900 | CODE: |
1944 | CODE: |
1901 | { |
1945 | { |
1902 | tileid texid; |
1946 | tileid texid; |
1903 | maptex *tex; |
1947 | maptex *tex; |
1904 | |
1948 | |
1905 | if (face < 0 || face >= self->faces) |
1949 | if (face < 0 || face >= self->faces) |
1906 | return; |
1950 | return; |
1907 | |
1951 | |
1908 | if (smooth < 0 || smooth >= self->faces) |
1952 | if (smooth < 0 || smooth >= self->faces) |
1909 | return; |
1953 | return; |
1910 | |
1954 | |
1911 | texid = self->face2tile [face]; |
1955 | texid = self->face2tile [face]; |
1912 | |
1956 | |
1913 | if (!texid) |
1957 | if (!texid) |
1914 | return; |
1958 | return; |
1915 | |
1959 | |
1916 | tex = self->tex + texid; |
1960 | tex = self->tex + texid; |
… | |
… | |
1949 | } |
1993 | } |
1950 | |
1994 | |
1951 | void |
1995 | void |
1952 | expire_textures (DC::Map self, int texid, int count) |
1996 | expire_textures (DC::Map self, int texid, int count) |
1953 | PPCODE: |
1997 | PPCODE: |
1954 | for (; texid < self->texs && count; ++texid, --count) |
1998 | for (; texid < self->texs && count; ++texid, --count) |
1955 | { |
1999 | { |
1956 | maptex *tex = self->tex + texid; |
2000 | maptex *tex = self->tex + texid; |
1957 | |
2001 | |
1958 | if (tex->name) |
2002 | if (tex->name) |
1959 | { |
2003 | { |
… | |
… | |
2014 | self->y += MAP_EXTEND_Y; |
2058 | self->y += MAP_EXTEND_Y; |
2015 | } |
2059 | } |
2016 | } |
2060 | } |
2017 | |
2061 | |
2018 | SV * |
2062 | SV * |
2019 | map1a_update (DC::Map self, SV *data_, int extmap) |
2063 | map1a_update (DC::Map self, SV *data_) |
2020 | CODE: |
2064 | CODE: |
2021 | { |
2065 | { |
2022 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
2066 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
2023 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
2067 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
2024 | mapcell *cell; |
2068 | mapcell *cell; |
… | |
… | |
2045 | |
2089 | |
2046 | //TODO: don't trust server data to be in-range(!) |
2090 | //TODO: don't trust server data to be in-range(!) |
2047 | |
2091 | |
2048 | if (flags & 8) |
2092 | if (flags & 8) |
2049 | { |
2093 | { |
|
|
2094 | uint8_t ext, cmd; |
|
|
2095 | |
2050 | if (extmap) |
2096 | do |
2051 | { |
2097 | { |
2052 | uint8_t ext, cmd; |
2098 | ext = *data++; |
|
|
2099 | cmd = ext & 0x7f; |
2053 | |
2100 | |
2054 | do |
2101 | if (cmd < 4) |
|
|
2102 | cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */ |
|
|
2103 | else if (cmd == 5) // health |
2055 | { |
2104 | { |
2056 | ext = *data++; |
|
|
2057 | cmd = ext & 0x7f; |
|
|
2058 | |
|
|
2059 | if (cmd < 4) |
|
|
2060 | cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */ |
|
|
2061 | else if (cmd == 5) // health |
|
|
2062 | { |
|
|
2063 | cell->stat_width = 1; |
2105 | cell->stat_width = 1; |
2064 | cell->stat_hp = *data++; |
2106 | cell->stat_hp = *data++; |
2065 | } |
|
|
2066 | else if (cmd == 6) // monster width |
|
|
2067 | cell->stat_width = *data++ + 1; |
|
|
2068 | else if (cmd == 0x47) |
|
|
2069 | { |
|
|
2070 | if (*data == 1) cell->player = data [1]; |
|
|
2071 | else if (*data == 2) cell->player = data [2] + (data [1] << 8); |
|
|
2072 | else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16); |
|
|
2073 | else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24); |
|
|
2074 | |
|
|
2075 | data += *data + 1; |
|
|
2076 | } |
|
|
2077 | else if (cmd == 8) // cell flags |
|
|
2078 | cell->flags = *data++; |
|
|
2079 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
2080 | data += *data + 1; |
|
|
2081 | else |
|
|
2082 | data++; |
|
|
2083 | } |
2107 | } |
2084 | while (ext & 0x80); |
2108 | else if (cmd == 6) // monster width |
|
|
2109 | cell->stat_width = *data++ + 1; |
|
|
2110 | else if (cmd == 0x47) |
|
|
2111 | { |
|
|
2112 | if (*data == 1) cell->player = data [1]; |
|
|
2113 | else if (*data == 2) cell->player = data [2] + (data [1] << 8); |
|
|
2114 | else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16); |
|
|
2115 | else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24); |
|
|
2116 | |
|
|
2117 | data += *data + 1; |
|
|
2118 | } |
|
|
2119 | else if (cmd == 8) // cell flags |
|
|
2120 | cell->flags = *data++; |
|
|
2121 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
2122 | data += *data + 1; |
|
|
2123 | else |
|
|
2124 | data++; |
2085 | } |
2125 | } |
2086 | else |
2126 | while (ext & 0x80); |
2087 | cell->darkness = *data++ + 1; |
|
|
2088 | } |
2127 | } |
2089 | |
2128 | |
2090 | for (z = 0; z <= 2; ++z) |
2129 | for (z = 0; z <= 2; ++z) |
2091 | if (flags & (4 >> z)) |
2130 | if (flags & (4 >> z)) |
2092 | { |
2131 | { |
… | |
… | |
2166 | | (b << 16) |
2205 | | (b << 16) |
2167 | | (a << 24); |
2206 | | (a << 24); |
2168 | } |
2207 | } |
2169 | } |
2208 | } |
2170 | |
2209 | |
2171 | RETVAL = map_sv; |
2210 | RETVAL = map_sv; |
2172 | } |
2211 | } |
2173 | OUTPUT: |
2212 | OUTPUT: |
2174 | RETVAL |
2213 | RETVAL |
2175 | |
2214 | |
2176 | void |
2215 | void |
2177 | 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) |
2216 | 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) |
2178 | CODE: |
2217 | CODE: |
2179 | { |
2218 | { |
2180 | int x, y, z; |
2219 | int x, y, z; |
2181 | |
2220 | |
2182 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
|
|
2183 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
2221 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
2184 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) |
2222 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) |
2185 | smooth_key skey; |
2223 | smooth_key skey; |
2186 | int pl_x, pl_y; |
2224 | int pl_x, pl_y; |
2187 | maptex pl_tex; |
2225 | maptex pl_tex; |
… | |
… | |
2236 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2274 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2237 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2275 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2238 | |
2276 | |
2239 | for (z = 0; z <= 2; z++) |
2277 | for (z = 0; z <= 2; z++) |
2240 | { |
2278 | { |
|
|
2279 | smooth_hash smooth; |
2241 | memset (smooth_level, 0, sizeof (smooth_level)); |
2280 | memset (smooth_level, 0, sizeof (smooth_level)); |
2242 | key.texname = -1; |
2281 | key.texname = -1; |
2243 | |
2282 | |
2244 | for (y = 0; y < sh; y++) |
2283 | for (y = 0; y < sh; y++) |
2245 | if (0 <= y + my && y + my < self->rows) |
2284 | if (0 <= y + my && y + my < self->rows) |
… | |
… | |
2306 | |
2345 | |
2307 | // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· |
2346 | // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· |
2308 | // ·· ·· ·┏ ┓· |
2347 | // ·· ·· ·┏ ┓· |
2309 | |
2348 | |
2310 | // full tile |
2349 | // full tile |
2311 | skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x1000); |
2350 | skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x1000); |
2312 | |
2351 | |
2313 | // borders |
2352 | // borders |
2314 | skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0091); |
2353 | skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0091); |
2315 | skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0032); |
2354 | skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0032); |
2316 | skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0064); |
2355 | skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0064); |
2317 | skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, &skey, 0x00c8); |
2356 | skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, skey, 0x00c8); |
2318 | |
2357 | |
2319 | // corners |
2358 | // corners |
2320 | skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0100); |
2359 | skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0100); |
2321 | skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0200); |
2360 | skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0200); |
2322 | skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400); |
2361 | skey.x = x ; skey.y = y ; smooth_or_bits (smooth, skey, 0x0400); |
2323 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); |
2362 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, skey, 0x0800); |
2324 | } |
2363 | } |
2325 | } |
2364 | } |
2326 | |
2365 | |
2327 | if (expect_false (z == 2) && expect_false (cell->flags)) |
2366 | if (expect_false (z == 2) && expect_false (cell->flags)) |
2328 | { |
2367 | { |
… | |
… | |
2365 | if (smask & (((uint32_t)1) << b)) |
2404 | if (smask & (((uint32_t)1) << b)) |
2366 | { |
2405 | { |
2367 | int level = (w << 5) | b; |
2406 | int level = (w << 5) | b; |
2368 | HE *he; |
2407 | HE *he; |
2369 | |
2408 | |
2370 | hv_iterinit (smooth); |
2409 | for (auto &&it = smooth.begin (); it != smooth.end (); ++it) |
2371 | while ((he = hv_iternext (smooth))) |
|
|
2372 | { |
2410 | { |
2373 | smooth_key *skey = (smooth_key *)HeKEY (he); |
2411 | smooth_key &skey = it->first; |
2374 | IV bits = SvIVX (HeVAL (he)); |
2412 | IV bits = it->second; |
2375 | |
2413 | |
2376 | if (!(bits & 0x1000) |
2414 | if (!(bits & 0x1000) |
2377 | && skey->level == level |
2415 | && skey.level == level |
2378 | && level > smooth_max [skey->x][skey->y]) |
2416 | && level > smooth_max [skey.x][skey.y]) |
2379 | { |
2417 | { |
2380 | maptex tex = self->tex [skey->tile]; |
2418 | maptex tex = self->tex [skey.tile]; |
2381 | int px = (((int)skey->x) - 1) * Tw; |
2419 | int px = (((int)skey.x) - 1) * Tw; |
2382 | int py = (((int)skey->y) - 1) * Th; |
2420 | int py = (((int)skey.y) - 1) * Th; |
2383 | int border = bits & 15; |
2421 | int border = bits & 15; |
2384 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
2422 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
2385 | float dx = tex.s * .0625f; // 16 images/row |
2423 | float dx = tex.s * .0625f; // 16 images/row |
2386 | float dy = tex.t * .5f ; // 2 images/column |
2424 | float dy = tex.t * .5f ; // 2 images/column |
2387 | |
2425 | |
… | |
… | |
2389 | { |
2427 | { |
2390 | // this time avoiding texture state changes |
2428 | // this time avoiding texture state changes |
2391 | // save gobs of state changes. |
2429 | // save gobs of state changes. |
2392 | if (key.texname != tex.name) |
2430 | if (key.texname != tex.name) |
2393 | { |
2431 | { |
2394 | self->tex [skey->tile].unused = 0; |
2432 | self->tex [skey.tile].unused = 0; |
2395 | |
2433 | |
2396 | glEnd (); |
2434 | glEnd (); |
2397 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
2435 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
2398 | glBegin (GL_QUADS); |
2436 | glBegin (GL_QUADS); |
2399 | } |
2437 | } |
… | |
… | |
2425 | |
2463 | |
2426 | glEnd (); |
2464 | glEnd (); |
2427 | glDisable (GL_TEXTURE_2D); |
2465 | glDisable (GL_TEXTURE_2D); |
2428 | key.texname = -1; |
2466 | key.texname = -1; |
2429 | } |
2467 | } |
2430 | |
|
|
2431 | hv_clear (smooth); |
|
|
2432 | } |
2468 | } |
2433 | |
2469 | |
2434 | if (pl_tex.name) |
2470 | if (pl_tex.name) |
2435 | { |
2471 | { |
2436 | maptex tex = pl_tex; |
2472 | maptex tex = pl_tex; |
… | |
… | |
2705 | else |
2741 | else |
2706 | *data++ = 0; |
2742 | *data++ = 0; |
2707 | } |
2743 | } |
2708 | } |
2744 | } |
2709 | |
2745 | |
2710 | /* if size is w*h + 5 then no data has been found */ |
2746 | /* if size is w*h + 5 then no data has been found */ |
2711 | if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) |
2747 | if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) |
2712 | { |
2748 | { |
2713 | SvPOK_only (data_sv); |
2749 | SvPOK_only (data_sv); |
2714 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
2750 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
2715 | } |
2751 | } |
2716 | |
2752 | |
2717 | RETVAL = data_sv; |
2753 | RETVAL = data_sv; |
2718 | } |
2754 | } |
2719 | OUTPUT: |
2755 | OUTPUT: |
2720 | RETVAL |
2756 | RETVAL |
2721 | |
2757 | |
2722 | void |
2758 | void |
… | |
… | |
2729 | STRLEN len; |
2765 | STRLEN len; |
2730 | uint8_t *data, *end; |
2766 | uint8_t *data, *end; |
2731 | |
2767 | |
2732 | len = SvLEN (data_sv); |
2768 | len = SvLEN (data_sv); |
2733 | SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more |
2769 | SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more |
2734 | data = SvPVbyte_nolen (data_sv); |
2770 | data = (uint8_t *)SvPVbyte_nolen (data_sv); |
2735 | end = data + len + 8; |
2771 | end = data + len + 8; |
2736 | |
2772 | |
2737 | if (len < 5) |
2773 | if (len < 5) |
2738 | XSRETURN_EMPTY; |
2774 | XSRETURN_EMPTY; |
2739 | |
2775 | |
… | |
… | |
2800 | } |
2836 | } |
2801 | |
2837 | |
2802 | MODULE = Deliantra::Client PACKAGE = DC::RW |
2838 | MODULE = Deliantra::Client PACKAGE = DC::RW |
2803 | |
2839 | |
2804 | DC::RW |
2840 | DC::RW |
2805 | new (SV *class, SV *data_sv) |
2841 | new (SV *klass, SV *data_sv) |
2806 | CODE: |
2842 | CODE: |
2807 | { |
2843 | { |
2808 | STRLEN datalen; |
2844 | STRLEN datalen; |
2809 | char *data = SvPVbyte (data_sv, datalen); |
2845 | char *data = SvPVbyte (data_sv, datalen); |
2810 | |
2846 | |
… | |
… | |
2812 | } |
2848 | } |
2813 | OUTPUT: |
2849 | OUTPUT: |
2814 | RETVAL |
2850 | RETVAL |
2815 | |
2851 | |
2816 | DC::RW |
2852 | DC::RW |
2817 | new_from_file (SV *class, const char *path, const char *mode = "rb") |
2853 | new_from_file (SV *klass, const char *path, const char *mode = "rb") |
2818 | CODE: |
2854 | CODE: |
2819 | RETVAL = SDL_RWFromFile (path, mode); |
2855 | RETVAL = SDL_RWFromFile (path, mode); |
2820 | OUTPUT: |
2856 | OUTPUT: |
2821 | RETVAL |
2857 | RETVAL |
2822 | |
2858 | |
… | |
… | |
2931 | #else |
2967 | #else |
2932 | XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); |
2968 | XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); |
2933 | #endif |
2969 | #endif |
2934 | |
2970 | |
2935 | DC::MixChunk |
2971 | DC::MixChunk |
2936 | new (SV *class, DC::RW rwops) |
2972 | new (SV *klass, DC::RW rwops) |
2937 | CODE: |
2973 | CODE: |
2938 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2974 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2939 | OUTPUT: |
2975 | OUTPUT: |
2940 | RETVAL |
2976 | RETVAL |
2941 | |
2977 | |
… | |
… | |
3011 | RETVAL = Mix_PlayingMusic (); |
3047 | RETVAL = Mix_PlayingMusic (); |
3012 | OUTPUT: |
3048 | OUTPUT: |
3013 | RETVAL |
3049 | RETVAL |
3014 | |
3050 | |
3015 | DC::MixMusic |
3051 | DC::MixMusic |
3016 | new (SV *class, DC::RW rwops) |
3052 | new (SV *klass, DC::RW rwops) |
3017 | CODE: |
3053 | CODE: |
3018 | RETVAL = Mix_LoadMUS_RW (rwops); |
3054 | RETVAL = Mix_LoadMUS_RW (rwops); |
3019 | OUTPUT: |
3055 | OUTPUT: |
3020 | RETVAL |
3056 | RETVAL |
3021 | |
3057 | |
… | |
… | |
3174 | gl.BlendFuncSeparateEXT = 0; |
3210 | gl.BlendFuncSeparateEXT = 0; |
3175 | |
3211 | |
3176 | void |
3212 | void |
3177 | apple_nvidia_bug (int enable) |
3213 | apple_nvidia_bug (int enable) |
3178 | |
3214 | |
3179 | char * |
3215 | const char * |
3180 | gl_vendor () |
3216 | gl_vendor () |
3181 | CODE: |
3217 | CODE: |
3182 | RETVAL = (char *)glGetString (GL_VENDOR); |
3218 | RETVAL = (const char *)glGetString (GL_VENDOR); |
3183 | OUTPUT: |
3219 | OUTPUT: |
3184 | RETVAL |
3220 | RETVAL |
3185 | |
3221 | |
3186 | char * |
3222 | const char * |
3187 | gl_version () |
3223 | gl_version () |
3188 | CODE: |
3224 | CODE: |
3189 | RETVAL = (char *)glGetString (GL_VERSION); |
3225 | RETVAL = (const char *)glGetString (GL_VERSION); |
3190 | OUTPUT: |
3226 | OUTPUT: |
3191 | RETVAL |
3227 | RETVAL |
3192 | |
3228 | |
3193 | char * |
3229 | const char * |
3194 | gl_extensions () |
3230 | gl_extensions () |
3195 | CODE: |
3231 | CODE: |
3196 | RETVAL = (char *)glGetString (GL_EXTENSIONS); |
3232 | RETVAL = (const char *)glGetString (GL_EXTENSIONS); |
3197 | OUTPUT: |
3233 | OUTPUT: |
3198 | RETVAL |
3234 | RETVAL |
3199 | |
3235 | |
3200 | const char *glGetString (GLenum pname) |
3236 | const char *glGetString (GLenum pname) |
|
|
3237 | CODE: |
|
|
3238 | RETVAL = (const char *)glGetString (pname); |
|
|
3239 | OUTPUT: |
|
|
3240 | RETVAL |
3201 | |
3241 | |
3202 | GLint glGetInteger (GLenum pname) |
3242 | GLint glGetInteger (GLenum pname) |
3203 | CODE: |
3243 | CODE: |
3204 | glGetIntegerv (pname, &RETVAL); |
3244 | glGetIntegerv (pname, &RETVAL); |
3205 | OUTPUT: |
3245 | OUTPUT: |
… | |
… | |
3408 | |
3448 | |
3409 | void |
3449 | void |
3410 | find_widget (SV *self, NV x, NV y) |
3450 | find_widget (SV *self, NV x, NV y) |
3411 | PPCODE: |
3451 | PPCODE: |
3412 | { |
3452 | { |
3413 | if (within_widget (self, x, y)) |
3453 | if (within_widget (self, x, y)) |
3414 | XPUSHs (self); |
3454 | XPUSHs (self); |
3415 | } |
3455 | } |
3416 | |
3456 | |
3417 | BOOT: |
3457 | BOOT: |
3418 | { |
3458 | { |
… | |
… | |
3426 | |
3466 | |
3427 | void |
3467 | void |
3428 | draw (SV *self) |
3468 | draw (SV *self) |
3429 | CODE: |
3469 | CODE: |
3430 | { |
3470 | { |
3431 | HV *hv; |
3471 | HV *hv; |
3432 | SV **svp; |
3472 | SV **svp; |
3433 | NV x, y, w, h; |
3473 | NV x, y, w, h; |
3434 | SV *draw_x_sv = GvSV (draw_x_gv); |
3474 | SV *draw_x_sv = GvSV (draw_x_gv); |
3435 | SV *draw_y_sv = GvSV (draw_y_gv); |
3475 | SV *draw_y_sv = GvSV (draw_y_gv); |
3436 | SV *draw_w_sv = GvSV (draw_w_gv); |
3476 | SV *draw_w_sv = GvSV (draw_w_gv); |
3437 | SV *draw_h_sv = GvSV (draw_h_gv); |
3477 | SV *draw_h_sv = GvSV (draw_h_gv); |