… | |
… | |
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 ("DC::Main::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 shared library 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 |
… | |
… | |
1074 | OUTPUT: |
1107 | OUTPUT: |
1075 | RETVAL |
1108 | RETVAL |
1076 | |
1109 | |
1077 | int |
1110 | int |
1078 | 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) |
1079 | POSTCALL: |
1112 | POSTCALL: |
1080 | Mix_HookMusicFinished (music_finished); |
1113 | Mix_HookMusicFinished (music_finished); |
1081 | Mix_ChannelFinished (channel_finished); |
1114 | Mix_ChannelFinished (channel_finished); |
1082 | |
1115 | |
1083 | void |
1116 | void |
1084 | Mix_QuerySpec () |
1117 | Mix_QuerySpec () |
… | |
… | |
1147 | RETVAL |
1180 | RETVAL |
1148 | |
1181 | |
1149 | void |
1182 | void |
1150 | IMG_Init (int flags = IMG_INIT_JPG | IMG_INIT_PNG) |
1183 | IMG_Init (int flags = IMG_INIT_JPG | IMG_INIT_PNG) |
1151 | |
1184 | |
|
|
1185 | # MIX_INIT_MP3 gives smpeg + libstdc++ + libgcc_s |
1152 | void |
1186 | void |
1153 | Mix_Init (int flags = MIX_INIT_MOD | MIX_INIT_MP3 | MIX_INIT_OGG) |
1187 | Mix_Init (int flags = MIX_INIT_MOD | MIX_INIT_OGG) |
1154 | |
1188 | |
1155 | void |
1189 | void |
1156 | load_image_inline (SV *image_) |
1190 | load_image_inline (SV *image_) |
1157 | ALIAS: |
1191 | ALIAS: |
1158 | load_image_file = 1 |
1192 | load_image_file = 1 |
… | |
… | |
1204 | |
1238 | |
1205 | SDL_LockSurface (surface2); |
1239 | SDL_LockSurface (surface2); |
1206 | EXTEND (SP, 6); |
1240 | EXTEND (SP, 6); |
1207 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
1241 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
1208 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
1242 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
1209 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
1243 | PUSHs (sv_2mortal (newSVpvn ((const char *)surface2->pixels, surface2->h * surface2->pitch))); |
1210 | 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))); |
1211 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
1245 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
1212 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
1246 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
1213 | SDL_UnlockSurface (surface2); |
1247 | SDL_UnlockSurface (surface2); |
1214 | |
1248 | |
… | |
… | |
1286 | MODULE = Deliantra::Client PACKAGE = DC::Font |
1320 | MODULE = Deliantra::Client PACKAGE = DC::Font |
1287 | |
1321 | |
1288 | PROTOTYPES: DISABLE |
1322 | PROTOTYPES: DISABLE |
1289 | |
1323 | |
1290 | DC::Font |
1324 | DC::Font |
1291 | new_from_file (SV *class, char *path, int id = 0) |
1325 | new_from_file (SV *klass, char *path, int id = 0) |
1292 | CODE: |
1326 | CODE: |
1293 | { |
1327 | { |
1294 | int count; |
1328 | int count; |
1295 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
1329 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
1296 | RETVAL = pango_fc_font_description_from_pattern (pattern, 0); |
1330 | RETVAL = pango_fc_font_description_from_pattern (pattern, 0); |
… | |
… | |
1325 | PROTOTYPE: |
1359 | PROTOTYPE: |
1326 | CODE: |
1360 | CODE: |
1327 | tc_restore (); |
1361 | tc_restore (); |
1328 | |
1362 | |
1329 | DC::Layout |
1363 | DC::Layout |
1330 | new (SV *class) |
1364 | new (SV *klass) |
1331 | CODE: |
1365 | CODE: |
1332 | New (0, RETVAL, 1, struct cf_layout); |
1366 | New (0, RETVAL, 1, struct cf_layout); |
1333 | |
1367 | |
1334 | RETVAL->pl = pango_layout_new (opengl_context); |
1368 | RETVAL->pl = pango_layout_new (opengl_context); |
1335 | RETVAL->r = 1.; |
1369 | RETVAL->r = 1.; |
… | |
… | |
1484 | |
1518 | |
1485 | void |
1519 | void |
1486 | set_height (DC::Layout self, int base_height) |
1520 | set_height (DC::Layout self, int base_height) |
1487 | CODE: |
1521 | CODE: |
1488 | if (self->base_height != base_height) |
1522 | if (self->base_height != base_height) |
1489 | { |
1523 | { |
1490 | self->base_height = base_height; |
1524 | self->base_height = base_height; |
1491 | layout_update_font (self); |
1525 | layout_update_font (self); |
1492 | } |
1526 | } |
1493 | |
1527 | |
1494 | void |
1528 | void |
… | |
… | |
1858 | MODULE = Deliantra::Client PACKAGE = DC::Map |
1892 | MODULE = Deliantra::Client PACKAGE = DC::Map |
1859 | |
1893 | |
1860 | PROTOTYPES: DISABLE |
1894 | PROTOTYPES: DISABLE |
1861 | |
1895 | |
1862 | DC::Map |
1896 | DC::Map |
1863 | new (SV *class) |
1897 | new (SV *klass) |
1864 | CODE: |
1898 | CODE: |
1865 | New (0, RETVAL, 1, struct map); |
1899 | New (0, RETVAL, 1, struct map); |
1866 | RETVAL->x = 0; |
1900 | RETVAL->x = 0; |
1867 | RETVAL->y = 0; |
1901 | RETVAL->y = 0; |
1868 | RETVAL->w = 0; |
1902 | RETVAL->w = 0; |
… | |
… | |
1907 | |
1941 | |
1908 | void |
1942 | void |
1909 | set_smooth (DC::Map self, int face, int smooth, int level) |
1943 | set_smooth (DC::Map self, int face, int smooth, int level) |
1910 | CODE: |
1944 | CODE: |
1911 | { |
1945 | { |
1912 | tileid texid; |
1946 | tileid texid; |
1913 | maptex *tex; |
1947 | maptex *tex; |
1914 | |
1948 | |
1915 | if (face < 0 || face >= self->faces) |
1949 | if (face < 0 || face >= self->faces) |
1916 | return; |
1950 | return; |
1917 | |
1951 | |
1918 | if (smooth < 0 || smooth >= self->faces) |
1952 | if (smooth < 0 || smooth >= self->faces) |
1919 | return; |
1953 | return; |
1920 | |
1954 | |
1921 | texid = self->face2tile [face]; |
1955 | texid = self->face2tile [face]; |
1922 | |
1956 | |
1923 | if (!texid) |
1957 | if (!texid) |
1924 | return; |
1958 | return; |
1925 | |
1959 | |
1926 | tex = self->tex + texid; |
1960 | tex = self->tex + texid; |
… | |
… | |
1959 | } |
1993 | } |
1960 | |
1994 | |
1961 | void |
1995 | void |
1962 | expire_textures (DC::Map self, int texid, int count) |
1996 | expire_textures (DC::Map self, int texid, int count) |
1963 | PPCODE: |
1997 | PPCODE: |
1964 | for (; texid < self->texs && count; ++texid, --count) |
1998 | for (; texid < self->texs && count; ++texid, --count) |
1965 | { |
1999 | { |
1966 | maptex *tex = self->tex + texid; |
2000 | maptex *tex = self->tex + texid; |
1967 | |
2001 | |
1968 | if (tex->name) |
2002 | if (tex->name) |
1969 | { |
2003 | { |
… | |
… | |
2024 | self->y += MAP_EXTEND_Y; |
2058 | self->y += MAP_EXTEND_Y; |
2025 | } |
2059 | } |
2026 | } |
2060 | } |
2027 | |
2061 | |
2028 | SV * |
2062 | SV * |
2029 | map1a_update (DC::Map self, SV *data_, int extmap) |
2063 | map1a_update (DC::Map self, SV *data_) |
2030 | CODE: |
2064 | CODE: |
2031 | { |
2065 | { |
2032 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
2066 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
2033 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
2067 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
2034 | mapcell *cell; |
2068 | mapcell *cell; |
… | |
… | |
2055 | |
2089 | |
2056 | //TODO: don't trust server data to be in-range(!) |
2090 | //TODO: don't trust server data to be in-range(!) |
2057 | |
2091 | |
2058 | if (flags & 8) |
2092 | if (flags & 8) |
2059 | { |
2093 | { |
|
|
2094 | uint8_t ext, cmd; |
|
|
2095 | |
2060 | if (extmap) |
2096 | do |
2061 | { |
2097 | { |
2062 | uint8_t ext, cmd; |
2098 | ext = *data++; |
|
|
2099 | cmd = ext & 0x7f; |
2063 | |
2100 | |
2064 | 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 |
2065 | { |
2104 | { |
2066 | ext = *data++; |
|
|
2067 | cmd = ext & 0x7f; |
|
|
2068 | |
|
|
2069 | if (cmd < 4) |
|
|
2070 | cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */ |
|
|
2071 | else if (cmd == 5) // health |
|
|
2072 | { |
|
|
2073 | cell->stat_width = 1; |
2105 | cell->stat_width = 1; |
2074 | cell->stat_hp = *data++; |
2106 | cell->stat_hp = *data++; |
2075 | } |
|
|
2076 | else if (cmd == 6) // monster width |
|
|
2077 | cell->stat_width = *data++ + 1; |
|
|
2078 | else if (cmd == 0x47) |
|
|
2079 | { |
|
|
2080 | if (*data == 1) cell->player = data [1]; |
|
|
2081 | else if (*data == 2) cell->player = data [2] + (data [1] << 8); |
|
|
2082 | else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16); |
|
|
2083 | else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24); |
|
|
2084 | |
|
|
2085 | data += *data + 1; |
|
|
2086 | } |
|
|
2087 | else if (cmd == 8) // cell flags |
|
|
2088 | cell->flags = *data++; |
|
|
2089 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
2090 | data += *data + 1; |
|
|
2091 | else |
|
|
2092 | data++; |
|
|
2093 | } |
2107 | } |
2094 | 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++; |
2095 | } |
2125 | } |
2096 | else |
2126 | while (ext & 0x80); |
2097 | cell->darkness = *data++ + 1; |
|
|
2098 | } |
2127 | } |
2099 | |
2128 | |
2100 | for (z = 0; z <= 2; ++z) |
2129 | for (z = 0; z <= 2; ++z) |
2101 | if (flags & (4 >> z)) |
2130 | if (flags & (4 >> z)) |
2102 | { |
2131 | { |
… | |
… | |
2176 | | (b << 16) |
2205 | | (b << 16) |
2177 | | (a << 24); |
2206 | | (a << 24); |
2178 | } |
2207 | } |
2179 | } |
2208 | } |
2180 | |
2209 | |
2181 | RETVAL = map_sv; |
2210 | RETVAL = map_sv; |
2182 | } |
2211 | } |
2183 | OUTPUT: |
2212 | OUTPUT: |
2184 | RETVAL |
2213 | RETVAL |
2185 | |
2214 | |
2186 | void |
2215 | void |
2187 | 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) |
2188 | CODE: |
2217 | CODE: |
2189 | { |
2218 | { |
2190 | int x, y, z; |
2219 | int x, y, z; |
2191 | |
2220 | |
2192 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
|
|
2193 | 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 |
2194 | 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) |
2195 | smooth_key skey; |
2223 | smooth_key skey; |
2196 | int pl_x, pl_y; |
2224 | int pl_x, pl_y; |
2197 | maptex pl_tex; |
2225 | maptex pl_tex; |
… | |
… | |
2246 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2274 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2247 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2275 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2248 | |
2276 | |
2249 | for (z = 0; z <= 2; z++) |
2277 | for (z = 0; z <= 2; z++) |
2250 | { |
2278 | { |
|
|
2279 | smooth_hash smooth; |
2251 | memset (smooth_level, 0, sizeof (smooth_level)); |
2280 | memset (smooth_level, 0, sizeof (smooth_level)); |
2252 | key.texname = -1; |
2281 | key.texname = -1; |
2253 | |
2282 | |
2254 | for (y = 0; y < sh; y++) |
2283 | for (y = 0; y < sh; y++) |
2255 | if (0 <= y + my && y + my < self->rows) |
2284 | if (0 <= y + my && y + my < self->rows) |
… | |
… | |
2316 | |
2345 | |
2317 | // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· |
2346 | // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· |
2318 | // ·· ·· ·┏ ┓· |
2347 | // ·· ·· ·┏ ┓· |
2319 | |
2348 | |
2320 | // full tile |
2349 | // full tile |
2321 | 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); |
2322 | |
2351 | |
2323 | // borders |
2352 | // borders |
2324 | 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); |
2325 | 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); |
2326 | 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); |
2327 | 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); |
2328 | |
2357 | |
2329 | // corners |
2358 | // corners |
2330 | 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); |
2331 | 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); |
2332 | 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); |
2333 | 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); |
2334 | } |
2363 | } |
2335 | } |
2364 | } |
2336 | |
2365 | |
2337 | if (expect_false (z == 2) && expect_false (cell->flags)) |
2366 | if (expect_false (z == 2) && expect_false (cell->flags)) |
2338 | { |
2367 | { |
… | |
… | |
2375 | if (smask & (((uint32_t)1) << b)) |
2404 | if (smask & (((uint32_t)1) << b)) |
2376 | { |
2405 | { |
2377 | int level = (w << 5) | b; |
2406 | int level = (w << 5) | b; |
2378 | HE *he; |
2407 | HE *he; |
2379 | |
2408 | |
2380 | hv_iterinit (smooth); |
2409 | for (auto &&it = smooth.begin (); it != smooth.end (); ++it) |
2381 | while ((he = hv_iternext (smooth))) |
|
|
2382 | { |
2410 | { |
2383 | smooth_key *skey = (smooth_key *)HeKEY (he); |
2411 | smooth_key &skey = it->first; |
2384 | IV bits = SvIVX (HeVAL (he)); |
2412 | IV bits = it->second; |
2385 | |
2413 | |
2386 | if (!(bits & 0x1000) |
2414 | if (!(bits & 0x1000) |
2387 | && skey->level == level |
2415 | && skey.level == level |
2388 | && level > smooth_max [skey->x][skey->y]) |
2416 | && level > smooth_max [skey.x][skey.y]) |
2389 | { |
2417 | { |
2390 | maptex tex = self->tex [skey->tile]; |
2418 | maptex tex = self->tex [skey.tile]; |
2391 | int px = (((int)skey->x) - 1) * Tw; |
2419 | int px = (((int)skey.x) - 1) * Tw; |
2392 | int py = (((int)skey->y) - 1) * Th; |
2420 | int py = (((int)skey.y) - 1) * Th; |
2393 | int border = bits & 15; |
2421 | int border = bits & 15; |
2394 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
2422 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
2395 | float dx = tex.s * .0625f; // 16 images/row |
2423 | float dx = tex.s * .0625f; // 16 images/row |
2396 | float dy = tex.t * .5f ; // 2 images/column |
2424 | float dy = tex.t * .5f ; // 2 images/column |
2397 | |
2425 | |
… | |
… | |
2399 | { |
2427 | { |
2400 | // this time avoiding texture state changes |
2428 | // this time avoiding texture state changes |
2401 | // save gobs of state changes. |
2429 | // save gobs of state changes. |
2402 | if (key.texname != tex.name) |
2430 | if (key.texname != tex.name) |
2403 | { |
2431 | { |
2404 | self->tex [skey->tile].unused = 0; |
2432 | self->tex [skey.tile].unused = 0; |
2405 | |
2433 | |
2406 | glEnd (); |
2434 | glEnd (); |
2407 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
2435 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
2408 | glBegin (GL_QUADS); |
2436 | glBegin (GL_QUADS); |
2409 | } |
2437 | } |
… | |
… | |
2435 | |
2463 | |
2436 | glEnd (); |
2464 | glEnd (); |
2437 | glDisable (GL_TEXTURE_2D); |
2465 | glDisable (GL_TEXTURE_2D); |
2438 | key.texname = -1; |
2466 | key.texname = -1; |
2439 | } |
2467 | } |
2440 | |
|
|
2441 | hv_clear (smooth); |
|
|
2442 | } |
2468 | } |
2443 | |
2469 | |
2444 | if (pl_tex.name) |
2470 | if (pl_tex.name) |
2445 | { |
2471 | { |
2446 | maptex tex = pl_tex; |
2472 | maptex tex = pl_tex; |
… | |
… | |
2715 | else |
2741 | else |
2716 | *data++ = 0; |
2742 | *data++ = 0; |
2717 | } |
2743 | } |
2718 | } |
2744 | } |
2719 | |
2745 | |
2720 | /* 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 */ |
2721 | if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) |
2747 | if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) |
2722 | { |
2748 | { |
2723 | SvPOK_only (data_sv); |
2749 | SvPOK_only (data_sv); |
2724 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
2750 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
2725 | } |
2751 | } |
2726 | |
2752 | |
2727 | RETVAL = data_sv; |
2753 | RETVAL = data_sv; |
2728 | } |
2754 | } |
2729 | OUTPUT: |
2755 | OUTPUT: |
2730 | RETVAL |
2756 | RETVAL |
2731 | |
2757 | |
2732 | void |
2758 | void |
… | |
… | |
2739 | STRLEN len; |
2765 | STRLEN len; |
2740 | uint8_t *data, *end; |
2766 | uint8_t *data, *end; |
2741 | |
2767 | |
2742 | len = SvLEN (data_sv); |
2768 | len = SvLEN (data_sv); |
2743 | SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more |
2769 | SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more |
2744 | data = SvPVbyte_nolen (data_sv); |
2770 | data = (uint8_t *)SvPVbyte_nolen (data_sv); |
2745 | end = data + len + 8; |
2771 | end = data + len + 8; |
2746 | |
2772 | |
2747 | if (len < 5) |
2773 | if (len < 5) |
2748 | XSRETURN_EMPTY; |
2774 | XSRETURN_EMPTY; |
2749 | |
2775 | |
… | |
… | |
2810 | } |
2836 | } |
2811 | |
2837 | |
2812 | MODULE = Deliantra::Client PACKAGE = DC::RW |
2838 | MODULE = Deliantra::Client PACKAGE = DC::RW |
2813 | |
2839 | |
2814 | DC::RW |
2840 | DC::RW |
2815 | new (SV *class, SV *data_sv) |
2841 | new (SV *klass, SV *data_sv) |
2816 | CODE: |
2842 | CODE: |
2817 | { |
2843 | { |
2818 | STRLEN datalen; |
2844 | STRLEN datalen; |
2819 | char *data = SvPVbyte (data_sv, datalen); |
2845 | char *data = SvPVbyte (data_sv, datalen); |
2820 | |
2846 | |
… | |
… | |
2822 | } |
2848 | } |
2823 | OUTPUT: |
2849 | OUTPUT: |
2824 | RETVAL |
2850 | RETVAL |
2825 | |
2851 | |
2826 | DC::RW |
2852 | DC::RW |
2827 | 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") |
2828 | CODE: |
2854 | CODE: |
2829 | RETVAL = SDL_RWFromFile (path, mode); |
2855 | RETVAL = SDL_RWFromFile (path, mode); |
2830 | OUTPUT: |
2856 | OUTPUT: |
2831 | RETVAL |
2857 | RETVAL |
2832 | |
2858 | |
… | |
… | |
2941 | #else |
2967 | #else |
2942 | XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); |
2968 | XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); |
2943 | #endif |
2969 | #endif |
2944 | |
2970 | |
2945 | DC::MixChunk |
2971 | DC::MixChunk |
2946 | new (SV *class, DC::RW rwops) |
2972 | new (SV *klass, DC::RW rwops) |
2947 | CODE: |
2973 | CODE: |
2948 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2974 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2949 | OUTPUT: |
2975 | OUTPUT: |
2950 | RETVAL |
2976 | RETVAL |
2951 | |
2977 | |
… | |
… | |
3021 | RETVAL = Mix_PlayingMusic (); |
3047 | RETVAL = Mix_PlayingMusic (); |
3022 | OUTPUT: |
3048 | OUTPUT: |
3023 | RETVAL |
3049 | RETVAL |
3024 | |
3050 | |
3025 | DC::MixMusic |
3051 | DC::MixMusic |
3026 | new (SV *class, DC::RW rwops) |
3052 | new (SV *klass, DC::RW rwops) |
3027 | CODE: |
3053 | CODE: |
3028 | RETVAL = Mix_LoadMUS_RW (rwops); |
3054 | RETVAL = Mix_LoadMUS_RW (rwops); |
3029 | OUTPUT: |
3055 | OUTPUT: |
3030 | RETVAL |
3056 | RETVAL |
3031 | |
3057 | |
… | |
… | |
3184 | gl.BlendFuncSeparateEXT = 0; |
3210 | gl.BlendFuncSeparateEXT = 0; |
3185 | |
3211 | |
3186 | void |
3212 | void |
3187 | apple_nvidia_bug (int enable) |
3213 | apple_nvidia_bug (int enable) |
3188 | |
3214 | |
3189 | char * |
3215 | const char * |
3190 | gl_vendor () |
3216 | gl_vendor () |
3191 | CODE: |
3217 | CODE: |
3192 | RETVAL = (char *)glGetString (GL_VENDOR); |
3218 | RETVAL = (const char *)glGetString (GL_VENDOR); |
3193 | OUTPUT: |
3219 | OUTPUT: |
3194 | RETVAL |
3220 | RETVAL |
3195 | |
3221 | |
3196 | char * |
3222 | const char * |
3197 | gl_version () |
3223 | gl_version () |
3198 | CODE: |
3224 | CODE: |
3199 | RETVAL = (char *)glGetString (GL_VERSION); |
3225 | RETVAL = (const char *)glGetString (GL_VERSION); |
3200 | OUTPUT: |
3226 | OUTPUT: |
3201 | RETVAL |
3227 | RETVAL |
3202 | |
3228 | |
3203 | char * |
3229 | const char * |
3204 | gl_extensions () |
3230 | gl_extensions () |
3205 | CODE: |
3231 | CODE: |
3206 | RETVAL = (char *)glGetString (GL_EXTENSIONS); |
3232 | RETVAL = (const char *)glGetString (GL_EXTENSIONS); |
3207 | OUTPUT: |
3233 | OUTPUT: |
3208 | RETVAL |
3234 | RETVAL |
3209 | |
3235 | |
3210 | const char *glGetString (GLenum pname) |
3236 | const char *glGetString (GLenum pname) |
|
|
3237 | CODE: |
|
|
3238 | RETVAL = (const char *)glGetString (pname); |
|
|
3239 | OUTPUT: |
|
|
3240 | RETVAL |
3211 | |
3241 | |
3212 | GLint glGetInteger (GLenum pname) |
3242 | GLint glGetInteger (GLenum pname) |
3213 | CODE: |
3243 | CODE: |
3214 | glGetIntegerv (pname, &RETVAL); |
3244 | glGetIntegerv (pname, &RETVAL); |
3215 | OUTPUT: |
3245 | OUTPUT: |
… | |
… | |
3418 | |
3448 | |
3419 | void |
3449 | void |
3420 | find_widget (SV *self, NV x, NV y) |
3450 | find_widget (SV *self, NV x, NV y) |
3421 | PPCODE: |
3451 | PPCODE: |
3422 | { |
3452 | { |
3423 | if (within_widget (self, x, y)) |
3453 | if (within_widget (self, x, y)) |
3424 | XPUSHs (self); |
3454 | XPUSHs (self); |
3425 | } |
3455 | } |
3426 | |
3456 | |
3427 | BOOT: |
3457 | BOOT: |
3428 | { |
3458 | { |
… | |
… | |
3436 | |
3466 | |
3437 | void |
3467 | void |
3438 | draw (SV *self) |
3468 | draw (SV *self) |
3439 | CODE: |
3469 | CODE: |
3440 | { |
3470 | { |
3441 | HV *hv; |
3471 | HV *hv; |
3442 | SV **svp; |
3472 | SV **svp; |
3443 | NV x, y, w, h; |
3473 | NV x, y, w, h; |
3444 | SV *draw_x_sv = GvSV (draw_x_gv); |
3474 | SV *draw_x_sv = GvSV (draw_x_gv); |
3445 | SV *draw_y_sv = GvSV (draw_y_gv); |
3475 | SV *draw_y_sv = GvSV (draw_y_gv); |
3446 | SV *draw_w_sv = GvSV (draw_w_gv); |
3476 | SV *draw_w_sv = GvSV (draw_w_gv); |
3447 | SV *draw_h_sv = GvSV (draw_h_gv); |
3477 | SV *draw_h_sv = GvSV (draw_h_gv); |