… | |
… | |
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; |
195 | } |
199 | } |
196 | |
200 | |
197 | return 0; |
201 | return 0; |
198 | } |
202 | } |
199 | |
203 | |
200 | typedef struct cf_layout { |
204 | struct cf_layout { |
201 | PangoLayout *pl; |
205 | PangoLayout *pl; |
202 | float r, g, b, a; // default color for rgba mode |
206 | float r, g, b, a; // default color for rgba mode |
203 | int base_height; |
207 | int base_height; |
204 | DC__Font font; |
208 | DC__Font font; |
205 | rc_t *rc; |
209 | rc_t *rc; |
206 | } *DC__Layout; |
210 | }; |
|
|
211 | |
|
|
212 | typedef cf_layout *DC__Layout; |
207 | |
213 | |
208 | static DC__Font default_font; |
214 | static DC__Font default_font; |
209 | static PangoContext *opengl_context; |
215 | static PangoContext *opengl_context; |
210 | static PangoFontMap *opengl_fontmap; |
216 | static PangoFontMap *opengl_fontmap; |
211 | |
217 | |
212 | static void |
218 | static void |
213 | substitute_func (FcPattern *pattern, gpointer data) |
219 | substitute_func (FcPattern *pattern, gpointer data) |
214 | { |
220 | { |
215 | FcPatternAddBool (pattern, FC_HINTING, 1); |
221 | FcPatternAddBool (pattern, FC_HINTING, 1); |
216 | #ifdef FC_HINT_STYLE |
222 | #ifdef FC_HINT_STYLE |
217 | FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); |
223 | FcPatternAddInteger (pattern, FC_HINT_STYLE, FC_HINT_FULL); |
218 | #endif |
224 | #endif |
219 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
225 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
220 | } |
226 | } |
221 | |
227 | |
222 | static void |
228 | static void |
… | |
… | |
252 | } |
258 | } |
253 | |
259 | |
254 | typedef uint16_t tileid; |
260 | typedef uint16_t tileid; |
255 | typedef uint16_t faceid; |
261 | typedef uint16_t faceid; |
256 | |
262 | |
257 | typedef struct { |
263 | struct maptex |
|
|
264 | { |
258 | GLuint name; |
265 | GLuint name; |
259 | int w, h; |
266 | int w, h; |
260 | float s, t; |
267 | float s, t; |
261 | uint8_t r, g, b, a; |
268 | uint8_t r, g, b, a; |
262 | tileid smoothtile; |
269 | tileid smoothtile; |
263 | uint8_t smoothlevel; |
270 | uint8_t smoothlevel; |
264 | uint8_t unused; /* set to zero on use */ |
271 | uint8_t unused; /* set to zero on use */ |
265 | } maptex; |
272 | }; |
266 | |
273 | |
267 | typedef struct { |
274 | struct mapcell |
|
|
275 | { |
268 | uint32_t player; |
276 | uint32_t player; |
269 | tileid tile[3]; |
277 | tileid tile[3]; |
270 | uint16_t darkness; |
278 | uint16_t darkness; |
271 | uint8_t stat_width, stat_hp, flags, smoothmax; |
279 | uint8_t stat_width, stat_hp, flags, smoothmax; |
272 | } mapcell; |
280 | }; |
273 | |
281 | |
274 | typedef struct { |
282 | struct maprow |
|
|
283 | { |
275 | int32_t c0, c1; |
284 | int32_t c0, c1; |
276 | mapcell *col; |
285 | mapcell *col; |
277 | } maprow; |
286 | }; |
278 | |
287 | |
279 | typedef struct map { |
288 | struct mapgrid { |
280 | int x, y, w, h; |
289 | int x, y, w, h; |
281 | int ox, oy; /* offset to virtual global coordinate system */ |
290 | int ox, oy; /* offset to virtual global coordinate system */ |
282 | int faces; tileid *face2tile; // [faceid] |
291 | int faces; tileid *face2tile; // [faceid] |
283 | int texs; maptex *tex; // [tileid] |
292 | int texs; maptex *tex; // [tileid] |
284 | |
293 | |
285 | int32_t rows; |
294 | int32_t rows; |
286 | maprow *row; |
295 | maprow *row; |
287 | } *DC__Map; |
296 | }; |
|
|
297 | |
|
|
298 | typedef mapgrid *DC__Map; |
288 | |
299 | |
289 | static char * |
300 | static char * |
290 | prepend (char *ptr, int sze, int inc) |
301 | prepend (char *ptr, int sze, int inc) |
291 | { |
302 | { |
292 | char *p; |
303 | char *p; |
… | |
… | |
310 | |
321 | |
311 | #define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
322 | #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)) |
323 | #define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
313 | |
324 | |
314 | static void |
325 | static void |
315 | need_facenum (struct map *self, faceid face) |
326 | need_facenum (struct mapgrid *self, faceid face) |
316 | { |
327 | { |
317 | while (self->faces <= face) |
328 | while (self->faces <= face) |
318 | { |
329 | { |
319 | Append (tileid, self->face2tile, self->faces, self->faces); |
330 | Append (tileid, self->face2tile, self->faces, self->faces); |
320 | self->faces *= 2; |
331 | self->faces *= 2; |
321 | } |
332 | } |
322 | } |
333 | } |
323 | |
334 | |
324 | static void |
335 | static void |
325 | need_texid (struct map *self, int texid) |
336 | need_texid (struct mapgrid *self, int texid) |
326 | { |
337 | { |
327 | while (self->texs <= texid) |
338 | while (self->texs <= texid) |
328 | { |
339 | { |
329 | Append (maptex, self->tex, self->texs, self->texs); |
340 | Append (maptex, self->tex, self->texs, self->texs); |
330 | self->texs *= 2; |
341 | self->texs *= 2; |
331 | } |
342 | } |
332 | } |
343 | } |
333 | |
344 | |
334 | static maprow * |
345 | static maprow * |
335 | map_get_row (DC__Map self, int y) |
346 | map_get_row (mapgrid *self, int y) |
336 | { |
347 | { |
337 | if (0 > y) |
348 | if (0 > y) |
338 | { |
349 | { |
339 | int extend = - y + MAP_EXTEND_Y; |
350 | int extend = - y + MAP_EXTEND_Y; |
340 | Prepend (maprow, self->row, self->rows, extend); |
351 | Prepend (maprow, self->row, self->rows, extend); |
… | |
… | |
378 | |
389 | |
379 | return row->col + (x - row->c0); |
390 | return row->col + (x - row->c0); |
380 | } |
391 | } |
381 | |
392 | |
382 | static mapcell * |
393 | static mapcell * |
383 | map_get_cell (DC__Map self, int x, int y) |
394 | map_get_cell (mapgrid *self, int x, int y) |
384 | { |
395 | { |
385 | return row_get_cell (map_get_row (self, y), x); |
396 | return row_get_cell (map_get_row (self, y), x); |
386 | } |
397 | } |
387 | |
398 | |
388 | static void |
399 | static void |
389 | map_clear (DC__Map self) |
400 | map_clear (mapgrid *self) |
390 | { |
401 | { |
391 | int r; |
402 | int r; |
392 | |
403 | |
393 | for (r = 0; r < self->rows; r++) |
404 | for (r = 0; r < self->rows; r++) |
394 | Safefree (self->row[r].col); |
405 | Safefree (self->row[r].col); |
… | |
… | |
412 | (cell)->flags = 0; \ |
423 | (cell)->flags = 0; \ |
413 | (cell)->player = 0; \ |
424 | (cell)->player = 0; \ |
414 | } while (0) |
425 | } while (0) |
415 | |
426 | |
416 | static void |
427 | static void |
417 | map_blank (DC__Map self, int x0, int y0, int w, int h) |
428 | map_blank (mapgrid *self, int x0, int y0, int w, int h) |
418 | { |
429 | { |
419 | int x, y; |
430 | int x, y; |
420 | maprow *row; |
431 | maprow *row; |
421 | mapcell *cell; |
432 | mapcell *cell; |
422 | |
433 | |
… | |
… | |
439 | CELL_CLEAR (cell); |
450 | CELL_CLEAR (cell); |
440 | } |
451 | } |
441 | } |
452 | } |
442 | } |
453 | } |
443 | |
454 | |
444 | typedef struct { |
455 | struct smooth_key |
|
|
456 | { |
445 | tileid tile; |
457 | tileid tile; |
446 | uint8_t x, y, level; |
458 | uint8_t x, y, level; |
447 | } smooth_key; |
459 | |
|
|
460 | bool operator == (const smooth_key &o) const |
|
|
461 | { |
|
|
462 | return tile == o.tile && x == o.x && y == o.y && level == o.level; |
|
|
463 | } |
|
|
464 | }; |
|
|
465 | |
|
|
466 | typedef ska::flat_hash_map<smooth_key, IV> smooth_hash; |
|
|
467 | |
|
|
468 | namespace std { |
|
|
469 | template <> |
|
|
470 | struct hash<smooth_key> |
|
|
471 | { |
|
|
472 | size_t operator () (const smooth_key &v) const |
|
|
473 | { |
|
|
474 | return v.tile + (v.x << 8) + (v.y << 16) + (v.level << 24); |
|
|
475 | } |
|
|
476 | }; |
|
|
477 | } |
448 | |
478 | |
449 | static void |
479 | static void |
450 | smooth_or_bits (HV *hv, smooth_key *key, IV bits) |
480 | smooth_or_bits (smooth_hash &h, smooth_key &key, IV bits) |
451 | { |
481 | { |
452 | SV **sv = hv_fetch (hv, (char *)key, sizeof (*key), 1); |
482 | auto &&it = h.find (key); |
453 | |
483 | |
454 | if (SvIOK (*sv)) |
484 | if (it == h.end ()) |
455 | SvIV_set (*sv, SvIVX (*sv) | bits); |
485 | h.insert (std::make_pair (key, bits)); |
456 | else |
486 | else |
457 | sv_setiv (*sv, bits); |
487 | it->second |= bits; |
458 | } |
488 | } |
459 | |
489 | |
460 | static void |
490 | static void |
461 | music_finished (void) |
491 | music_finished (void) |
462 | { |
492 | { |
… | |
… | |
481 | ev.data2 = 0; |
511 | ev.data2 = 0; |
482 | |
512 | |
483 | SDL_PushEvent ((SDL_Event *)&ev); |
513 | SDL_PushEvent ((SDL_Event *)&ev); |
484 | } |
514 | } |
485 | |
515 | |
|
|
516 | // approximately divide by 255 |
486 | static unsigned int |
517 | static unsigned int |
487 | div255 (unsigned int n) |
518 | div255 (unsigned int n) |
488 | { |
519 | { |
489 | return (n + (n >> 8)) >> 8; |
520 | return (n + (n >> 8)) >> 8; |
490 | } |
521 | } |
… | |
… | |
607 | extern C_LINKAGE int main (int argc, char *argv[]); |
638 | extern C_LINKAGE int main (int argc, char *argv[]); |
608 | |
639 | |
609 | static void |
640 | static void |
610 | SDL_main_hack (SV *real_main_) |
641 | SDL_main_hack (SV *real_main_) |
611 | { |
642 | { |
612 | real_main = real_main; |
643 | real_main = real_main_; |
613 | |
644 | |
614 | char *argv[] = { "deliantra client", 0 }; |
645 | char *argv[] = { "deliantra client", 0 }; |
615 | (main) (1, argv); |
646 | (main) (1, argv); |
616 | } |
647 | } |
617 | #else |
648 | #else |
… | |
… | |
889 | void SDL_QuitSubSystem (U32 flags) |
920 | void SDL_QuitSubSystem (U32 flags) |
890 | |
921 | |
891 | void SDL_Quit () |
922 | void SDL_Quit () |
892 | |
923 | |
893 | int SDL_GL_SetAttribute (int attr, int value) |
924 | int SDL_GL_SetAttribute (int attr, int value) |
|
|
925 | C_ARGS: (SDL_GLattr)attr, value |
894 | |
926 | |
895 | int SDL_GL_GetAttribute (int attr) |
927 | int SDL_GL_GetAttribute (int attr) |
896 | CODE: |
928 | CODE: |
897 | if (SDL_GL_GetAttribute (attr, &RETVAL)) |
929 | if (SDL_GL_GetAttribute ((SDL_GLattr)attr, &RETVAL)) |
898 | XSRETURN_UNDEF; |
930 | XSRETURN_UNDEF; |
899 | OUTPUT: |
931 | OUTPUT: |
900 | RETVAL |
932 | RETVAL |
901 | |
933 | |
902 | void |
934 | void |
… | |
… | |
975 | void |
1007 | void |
976 | SDL_GL_SwapBuffers () |
1008 | SDL_GL_SwapBuffers () |
977 | |
1009 | |
978 | char * |
1010 | char * |
979 | SDL_GetKeyName (int sym) |
1011 | SDL_GetKeyName (int sym) |
|
|
1012 | C_ARGS: (SDLKey)sym |
980 | |
1013 | |
981 | int |
1014 | int |
982 | SDL_GetAppState () |
1015 | SDL_GetAppState () |
983 | |
1016 | |
984 | int |
1017 | int |
… | |
… | |
1081 | OUTPUT: |
1114 | OUTPUT: |
1082 | RETVAL |
1115 | RETVAL |
1083 | |
1116 | |
1084 | int |
1117 | int |
1085 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
1118 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
1086 | POSTCALL: |
1119 | POSTCALL: |
1087 | Mix_HookMusicFinished (music_finished); |
1120 | Mix_HookMusicFinished (music_finished); |
1088 | Mix_ChannelFinished (channel_finished); |
1121 | Mix_ChannelFinished (channel_finished); |
1089 | |
1122 | |
1090 | void |
1123 | void |
1091 | Mix_QuerySpec () |
1124 | Mix_QuerySpec () |
… | |
… | |
1212 | |
1245 | |
1213 | SDL_LockSurface (surface2); |
1246 | SDL_LockSurface (surface2); |
1214 | EXTEND (SP, 6); |
1247 | EXTEND (SP, 6); |
1215 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
1248 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
1216 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
1249 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
1217 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
1250 | PUSHs (sv_2mortal (newSVpvn ((const char *)surface2->pixels, surface2->h * surface2->pitch))); |
1218 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
1251 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
1219 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
1252 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
1220 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
1253 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
1221 | SDL_UnlockSurface (surface2); |
1254 | SDL_UnlockSurface (surface2); |
1222 | |
1255 | |
… | |
… | |
1294 | MODULE = Deliantra::Client PACKAGE = DC::Font |
1327 | MODULE = Deliantra::Client PACKAGE = DC::Font |
1295 | |
1328 | |
1296 | PROTOTYPES: DISABLE |
1329 | PROTOTYPES: DISABLE |
1297 | |
1330 | |
1298 | DC::Font |
1331 | DC::Font |
1299 | new_from_file (SV *class, char *path, int id = 0) |
1332 | new_from_file (SV *klass, char *path, int id = 0) |
1300 | CODE: |
1333 | CODE: |
1301 | { |
1334 | { |
1302 | int count; |
1335 | int count; |
1303 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
1336 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
1304 | RETVAL = pango_fc_font_description_from_pattern (pattern, 0); |
1337 | RETVAL = pango_fc_font_description_from_pattern (pattern, 0); |
… | |
… | |
1333 | PROTOTYPE: |
1366 | PROTOTYPE: |
1334 | CODE: |
1367 | CODE: |
1335 | tc_restore (); |
1368 | tc_restore (); |
1336 | |
1369 | |
1337 | DC::Layout |
1370 | DC::Layout |
1338 | new (SV *class) |
1371 | new (SV *klass) |
1339 | CODE: |
1372 | CODE: |
1340 | New (0, RETVAL, 1, struct cf_layout); |
1373 | New (0, RETVAL, 1, struct cf_layout); |
1341 | |
1374 | |
1342 | RETVAL->pl = pango_layout_new (opengl_context); |
1375 | RETVAL->pl = pango_layout_new (opengl_context); |
1343 | RETVAL->r = 1.; |
1376 | RETVAL->r = 1.; |
… | |
… | |
1492 | |
1525 | |
1493 | void |
1526 | void |
1494 | set_height (DC::Layout self, int base_height) |
1527 | set_height (DC::Layout self, int base_height) |
1495 | CODE: |
1528 | CODE: |
1496 | if (self->base_height != base_height) |
1529 | if (self->base_height != base_height) |
1497 | { |
1530 | { |
1498 | self->base_height = base_height; |
1531 | self->base_height = base_height; |
1499 | layout_update_font (self); |
1532 | layout_update_font (self); |
1500 | } |
1533 | } |
1501 | |
1534 | |
1502 | void |
1535 | void |
… | |
… | |
1866 | MODULE = Deliantra::Client PACKAGE = DC::Map |
1899 | MODULE = Deliantra::Client PACKAGE = DC::Map |
1867 | |
1900 | |
1868 | PROTOTYPES: DISABLE |
1901 | PROTOTYPES: DISABLE |
1869 | |
1902 | |
1870 | DC::Map |
1903 | DC::Map |
1871 | new (SV *class) |
1904 | new (SV *klass) |
1872 | CODE: |
1905 | CODE: |
1873 | New (0, RETVAL, 1, struct map); |
1906 | New (0, RETVAL, 1, mapgrid); |
1874 | RETVAL->x = 0; |
1907 | RETVAL->x = 0; |
1875 | RETVAL->y = 0; |
1908 | RETVAL->y = 0; |
1876 | RETVAL->w = 0; |
1909 | RETVAL->w = 0; |
1877 | RETVAL->h = 0; |
1910 | RETVAL->h = 0; |
1878 | RETVAL->ox = 0; |
1911 | RETVAL->ox = 0; |
… | |
… | |
1915 | |
1948 | |
1916 | void |
1949 | void |
1917 | set_smooth (DC::Map self, int face, int smooth, int level) |
1950 | set_smooth (DC::Map self, int face, int smooth, int level) |
1918 | CODE: |
1951 | CODE: |
1919 | { |
1952 | { |
1920 | tileid texid; |
1953 | tileid texid; |
1921 | maptex *tex; |
1954 | maptex *tex; |
1922 | |
1955 | |
1923 | if (face < 0 || face >= self->faces) |
1956 | if (face < 0 || face >= self->faces) |
1924 | return; |
1957 | return; |
1925 | |
1958 | |
1926 | if (smooth < 0 || smooth >= self->faces) |
1959 | if (smooth < 0 || smooth >= self->faces) |
1927 | return; |
1960 | return; |
1928 | |
1961 | |
1929 | texid = self->face2tile [face]; |
1962 | texid = self->face2tile [face]; |
1930 | |
1963 | |
1931 | if (!texid) |
1964 | if (!texid) |
1932 | return; |
1965 | return; |
1933 | |
1966 | |
1934 | tex = self->tex + texid; |
1967 | tex = self->tex + texid; |
… | |
… | |
1967 | } |
2000 | } |
1968 | |
2001 | |
1969 | void |
2002 | void |
1970 | expire_textures (DC::Map self, int texid, int count) |
2003 | expire_textures (DC::Map self, int texid, int count) |
1971 | PPCODE: |
2004 | PPCODE: |
1972 | for (; texid < self->texs && count; ++texid, --count) |
2005 | for (; texid < self->texs && count; ++texid, --count) |
1973 | { |
2006 | { |
1974 | maptex *tex = self->tex + texid; |
2007 | maptex *tex = self->tex + texid; |
1975 | |
2008 | |
1976 | if (tex->name) |
2009 | if (tex->name) |
1977 | { |
2010 | { |
… | |
… | |
2032 | self->y += MAP_EXTEND_Y; |
2065 | self->y += MAP_EXTEND_Y; |
2033 | } |
2066 | } |
2034 | } |
2067 | } |
2035 | |
2068 | |
2036 | SV * |
2069 | SV * |
2037 | map1a_update (DC::Map self, SV *data_, int extmap) |
2070 | map1a_update (DC::Map self, SV *data_) |
2038 | CODE: |
2071 | CODE: |
2039 | { |
2072 | { |
2040 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
2073 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
2041 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
2074 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
2042 | mapcell *cell; |
2075 | mapcell *cell; |
… | |
… | |
2063 | |
2096 | |
2064 | //TODO: don't trust server data to be in-range(!) |
2097 | //TODO: don't trust server data to be in-range(!) |
2065 | |
2098 | |
2066 | if (flags & 8) |
2099 | if (flags & 8) |
2067 | { |
2100 | { |
|
|
2101 | uint8_t ext, cmd; |
|
|
2102 | |
2068 | if (extmap) |
2103 | do |
2069 | { |
2104 | { |
2070 | uint8_t ext, cmd; |
2105 | ext = *data++; |
|
|
2106 | cmd = ext & 0x7f; |
2071 | |
2107 | |
2072 | do |
2108 | if (cmd < 4) |
|
|
2109 | cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */ |
|
|
2110 | else if (cmd == 5) // health |
2073 | { |
2111 | { |
2074 | ext = *data++; |
|
|
2075 | cmd = ext & 0x7f; |
|
|
2076 | |
|
|
2077 | if (cmd < 4) |
|
|
2078 | cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */ |
|
|
2079 | else if (cmd == 5) // health |
|
|
2080 | { |
|
|
2081 | cell->stat_width = 1; |
2112 | cell->stat_width = 1; |
2082 | cell->stat_hp = *data++; |
2113 | cell->stat_hp = *data++; |
2083 | } |
|
|
2084 | else if (cmd == 6) // monster width |
|
|
2085 | cell->stat_width = *data++ + 1; |
|
|
2086 | else if (cmd == 0x47) |
|
|
2087 | { |
|
|
2088 | if (*data == 1) cell->player = data [1]; |
|
|
2089 | else if (*data == 2) cell->player = data [2] + (data [1] << 8); |
|
|
2090 | else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16); |
|
|
2091 | else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24); |
|
|
2092 | |
|
|
2093 | data += *data + 1; |
|
|
2094 | } |
|
|
2095 | else if (cmd == 8) // cell flags |
|
|
2096 | cell->flags = *data++; |
|
|
2097 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
2098 | data += *data + 1; |
|
|
2099 | else |
|
|
2100 | data++; |
|
|
2101 | } |
2114 | } |
2102 | while (ext & 0x80); |
2115 | else if (cmd == 6) // monster width |
|
|
2116 | cell->stat_width = *data++ + 1; |
|
|
2117 | else if (cmd == 0x47) |
|
|
2118 | { |
|
|
2119 | if (*data == 1) cell->player = data [1]; |
|
|
2120 | else if (*data == 2) cell->player = data [2] + (data [1] << 8); |
|
|
2121 | else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16); |
|
|
2122 | else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24); |
|
|
2123 | |
|
|
2124 | data += *data + 1; |
|
|
2125 | } |
|
|
2126 | else if (cmd == 8) // cell flags |
|
|
2127 | cell->flags = *data++; |
|
|
2128 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
2129 | data += *data + 1; |
|
|
2130 | else |
|
|
2131 | data++; |
2103 | } |
2132 | } |
2104 | else |
2133 | while (ext & 0x80); |
2105 | cell->darkness = *data++ + 1; |
|
|
2106 | } |
2134 | } |
2107 | |
2135 | |
2108 | for (z = 0; z <= 2; ++z) |
2136 | for (z = 0; z <= 2; ++z) |
2109 | if (flags & (4 >> z)) |
2137 | if (flags & (4 >> z)) |
2110 | { |
2138 | { |
… | |
… | |
2184 | | (b << 16) |
2212 | | (b << 16) |
2185 | | (a << 24); |
2213 | | (a << 24); |
2186 | } |
2214 | } |
2187 | } |
2215 | } |
2188 | |
2216 | |
2189 | RETVAL = map_sv; |
2217 | RETVAL = map_sv; |
2190 | } |
2218 | } |
2191 | OUTPUT: |
2219 | OUTPUT: |
2192 | RETVAL |
2220 | RETVAL |
2193 | |
2221 | |
2194 | void |
2222 | void |
2195 | draw (DC::Map self, int mx, int my, int sw, int sh, int Tw, int Th, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) |
2223 | draw (DC::Map self, int mx, int my, int sw, int sh, int Tw, int Th, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) |
2196 | CODE: |
2224 | CODE: |
2197 | { |
2225 | { |
2198 | int x, y, z; |
2226 | int x, y, z; |
2199 | |
2227 | |
2200 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
|
|
2201 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
2228 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
2202 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) |
2229 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) |
2203 | smooth_key skey; |
2230 | smooth_key skey; |
2204 | int pl_x, pl_y; |
2231 | int pl_x, pl_y; |
2205 | maptex pl_tex; |
2232 | maptex pl_tex; |
… | |
… | |
2254 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2281 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2255 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2282 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2256 | |
2283 | |
2257 | for (z = 0; z <= 2; z++) |
2284 | for (z = 0; z <= 2; z++) |
2258 | { |
2285 | { |
|
|
2286 | smooth_hash smooth; |
2259 | memset (smooth_level, 0, sizeof (smooth_level)); |
2287 | memset (smooth_level, 0, sizeof (smooth_level)); |
2260 | key.texname = -1; |
2288 | key.texname = -1; |
2261 | |
2289 | |
2262 | for (y = 0; y < sh; y++) |
2290 | for (y = 0; y < sh; y++) |
2263 | if (0 <= y + my && y + my < self->rows) |
2291 | if (0 <= y + my && y + my < self->rows) |
… | |
… | |
2324 | |
2352 | |
2325 | // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· |
2353 | // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· |
2326 | // ·· ·· ·┏ ┓· |
2354 | // ·· ·· ·┏ ┓· |
2327 | |
2355 | |
2328 | // full tile |
2356 | // full tile |
2329 | skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x1000); |
2357 | skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x1000); |
2330 | |
2358 | |
2331 | // borders |
2359 | // borders |
2332 | skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0091); |
2360 | skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0091); |
2333 | skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0032); |
2361 | skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0032); |
2334 | skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0064); |
2362 | skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0064); |
2335 | skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, &skey, 0x00c8); |
2363 | skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, skey, 0x00c8); |
2336 | |
2364 | |
2337 | // corners |
2365 | // corners |
2338 | skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0100); |
2366 | skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0100); |
2339 | skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0200); |
2367 | skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0200); |
2340 | skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400); |
2368 | skey.x = x ; skey.y = y ; smooth_or_bits (smooth, skey, 0x0400); |
2341 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); |
2369 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, skey, 0x0800); |
2342 | } |
2370 | } |
2343 | } |
2371 | } |
2344 | |
2372 | |
2345 | if (expect_false (z == 2) && expect_false (cell->flags)) |
2373 | if (expect_false (z == 2) && expect_false (cell->flags)) |
2346 | { |
2374 | { |
… | |
… | |
2383 | if (smask & (((uint32_t)1) << b)) |
2411 | if (smask & (((uint32_t)1) << b)) |
2384 | { |
2412 | { |
2385 | int level = (w << 5) | b; |
2413 | int level = (w << 5) | b; |
2386 | HE *he; |
2414 | HE *he; |
2387 | |
2415 | |
2388 | hv_iterinit (smooth); |
2416 | for (auto &&it = smooth.begin (); it != smooth.end (); ++it) |
2389 | while ((he = hv_iternext (smooth))) |
|
|
2390 | { |
2417 | { |
2391 | smooth_key *skey = (smooth_key *)HeKEY (he); |
2418 | smooth_key &skey = it->first; |
2392 | IV bits = SvIVX (HeVAL (he)); |
2419 | IV bits = it->second; |
2393 | |
2420 | |
2394 | if (!(bits & 0x1000) |
2421 | if (!(bits & 0x1000) |
2395 | && skey->level == level |
2422 | && skey.level == level |
2396 | && level > smooth_max [skey->x][skey->y]) |
2423 | && level > smooth_max [skey.x][skey.y]) |
2397 | { |
2424 | { |
2398 | maptex tex = self->tex [skey->tile]; |
2425 | maptex tex = self->tex [skey.tile]; |
2399 | int px = (((int)skey->x) - 1) * Tw; |
2426 | int px = (((int)skey.x) - 1) * Tw; |
2400 | int py = (((int)skey->y) - 1) * Th; |
2427 | int py = (((int)skey.y) - 1) * Th; |
2401 | int border = bits & 15; |
2428 | int border = bits & 15; |
2402 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
2429 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
2403 | float dx = tex.s * .0625f; // 16 images/row |
2430 | float dx = tex.s * .0625f; // 16 images/row |
2404 | float dy = tex.t * .5f ; // 2 images/column |
2431 | float dy = tex.t * .5f ; // 2 images/column |
2405 | |
2432 | |
… | |
… | |
2407 | { |
2434 | { |
2408 | // this time avoiding texture state changes |
2435 | // this time avoiding texture state changes |
2409 | // save gobs of state changes. |
2436 | // save gobs of state changes. |
2410 | if (key.texname != tex.name) |
2437 | if (key.texname != tex.name) |
2411 | { |
2438 | { |
2412 | self->tex [skey->tile].unused = 0; |
2439 | self->tex [skey.tile].unused = 0; |
2413 | |
2440 | |
2414 | glEnd (); |
2441 | glEnd (); |
2415 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
2442 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
2416 | glBegin (GL_QUADS); |
2443 | glBegin (GL_QUADS); |
2417 | } |
2444 | } |
… | |
… | |
2443 | |
2470 | |
2444 | glEnd (); |
2471 | glEnd (); |
2445 | glDisable (GL_TEXTURE_2D); |
2472 | glDisable (GL_TEXTURE_2D); |
2446 | key.texname = -1; |
2473 | key.texname = -1; |
2447 | } |
2474 | } |
2448 | |
|
|
2449 | hv_clear (smooth); |
|
|
2450 | } |
2475 | } |
2451 | |
2476 | |
2452 | if (pl_tex.name) |
2477 | if (pl_tex.name) |
2453 | { |
2478 | { |
2454 | maptex tex = pl_tex; |
2479 | maptex tex = pl_tex; |
… | |
… | |
2723 | else |
2748 | else |
2724 | *data++ = 0; |
2749 | *data++ = 0; |
2725 | } |
2750 | } |
2726 | } |
2751 | } |
2727 | |
2752 | |
2728 | /* if size is w*h + 5 then no data has been found */ |
2753 | /* if size is w*h + 5 then no data has been found */ |
2729 | if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) |
2754 | if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) |
2730 | { |
2755 | { |
2731 | SvPOK_only (data_sv); |
2756 | SvPOK_only (data_sv); |
2732 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
2757 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
2733 | } |
2758 | } |
2734 | |
2759 | |
2735 | RETVAL = data_sv; |
2760 | RETVAL = data_sv; |
2736 | } |
2761 | } |
2737 | OUTPUT: |
2762 | OUTPUT: |
2738 | RETVAL |
2763 | RETVAL |
2739 | |
2764 | |
2740 | void |
2765 | void |
… | |
… | |
2747 | STRLEN len; |
2772 | STRLEN len; |
2748 | uint8_t *data, *end; |
2773 | uint8_t *data, *end; |
2749 | |
2774 | |
2750 | len = SvLEN (data_sv); |
2775 | len = SvLEN (data_sv); |
2751 | SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more |
2776 | SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more |
2752 | data = SvPVbyte_nolen (data_sv); |
2777 | data = (uint8_t *)SvPVbyte_nolen (data_sv); |
2753 | end = data + len + 8; |
2778 | end = data + len + 8; |
2754 | |
2779 | |
2755 | if (len < 5) |
2780 | if (len < 5) |
2756 | XSRETURN_EMPTY; |
2781 | XSRETURN_EMPTY; |
2757 | |
2782 | |
… | |
… | |
2818 | } |
2843 | } |
2819 | |
2844 | |
2820 | MODULE = Deliantra::Client PACKAGE = DC::RW |
2845 | MODULE = Deliantra::Client PACKAGE = DC::RW |
2821 | |
2846 | |
2822 | DC::RW |
2847 | DC::RW |
2823 | new (SV *class, SV *data_sv) |
2848 | new (SV *klass, SV *data_sv) |
2824 | CODE: |
2849 | CODE: |
2825 | { |
2850 | { |
2826 | STRLEN datalen; |
2851 | STRLEN datalen; |
2827 | char *data = SvPVbyte (data_sv, datalen); |
2852 | char *data = SvPVbyte (data_sv, datalen); |
2828 | |
2853 | |
… | |
… | |
2830 | } |
2855 | } |
2831 | OUTPUT: |
2856 | OUTPUT: |
2832 | RETVAL |
2857 | RETVAL |
2833 | |
2858 | |
2834 | DC::RW |
2859 | DC::RW |
2835 | new_from_file (SV *class, const char *path, const char *mode = "rb") |
2860 | new_from_file (SV *klass, const char *path, const char *mode = "rb") |
2836 | CODE: |
2861 | CODE: |
2837 | RETVAL = SDL_RWFromFile (path, mode); |
2862 | RETVAL = SDL_RWFromFile (path, mode); |
2838 | OUTPUT: |
2863 | OUTPUT: |
2839 | RETVAL |
2864 | RETVAL |
2840 | |
2865 | |
… | |
… | |
2949 | #else |
2974 | #else |
2950 | XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); |
2975 | XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); |
2951 | #endif |
2976 | #endif |
2952 | |
2977 | |
2953 | DC::MixChunk |
2978 | DC::MixChunk |
2954 | new (SV *class, DC::RW rwops) |
2979 | new (SV *klass, DC::RW rwops) |
2955 | CODE: |
2980 | CODE: |
2956 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2981 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2957 | OUTPUT: |
2982 | OUTPUT: |
2958 | RETVAL |
2983 | RETVAL |
2959 | |
2984 | |
… | |
… | |
3029 | RETVAL = Mix_PlayingMusic (); |
3054 | RETVAL = Mix_PlayingMusic (); |
3030 | OUTPUT: |
3055 | OUTPUT: |
3031 | RETVAL |
3056 | RETVAL |
3032 | |
3057 | |
3033 | DC::MixMusic |
3058 | DC::MixMusic |
3034 | new (SV *class, DC::RW rwops) |
3059 | new (SV *klass, DC::RW rwops) |
3035 | CODE: |
3060 | CODE: |
3036 | RETVAL = Mix_LoadMUS_RW (rwops); |
3061 | RETVAL = Mix_LoadMUS_RW (rwops); |
3037 | OUTPUT: |
3062 | OUTPUT: |
3038 | RETVAL |
3063 | RETVAL |
3039 | |
3064 | |
… | |
… | |
3192 | gl.BlendFuncSeparateEXT = 0; |
3217 | gl.BlendFuncSeparateEXT = 0; |
3193 | |
3218 | |
3194 | void |
3219 | void |
3195 | apple_nvidia_bug (int enable) |
3220 | apple_nvidia_bug (int enable) |
3196 | |
3221 | |
3197 | char * |
3222 | const char * |
3198 | gl_vendor () |
3223 | gl_vendor () |
3199 | CODE: |
3224 | CODE: |
3200 | RETVAL = (char *)glGetString (GL_VENDOR); |
3225 | RETVAL = (const char *)glGetString (GL_VENDOR); |
3201 | OUTPUT: |
3226 | OUTPUT: |
3202 | RETVAL |
3227 | RETVAL |
3203 | |
3228 | |
3204 | char * |
3229 | const char * |
3205 | gl_version () |
3230 | gl_version () |
3206 | CODE: |
3231 | CODE: |
3207 | RETVAL = (char *)glGetString (GL_VERSION); |
3232 | RETVAL = (const char *)glGetString (GL_VERSION); |
3208 | OUTPUT: |
3233 | OUTPUT: |
3209 | RETVAL |
3234 | RETVAL |
3210 | |
3235 | |
3211 | char * |
3236 | const char * |
3212 | gl_extensions () |
3237 | gl_extensions () |
3213 | CODE: |
3238 | CODE: |
3214 | RETVAL = (char *)glGetString (GL_EXTENSIONS); |
3239 | RETVAL = (const char *)glGetString (GL_EXTENSIONS); |
3215 | OUTPUT: |
3240 | OUTPUT: |
3216 | RETVAL |
3241 | RETVAL |
3217 | |
3242 | |
3218 | const char *glGetString (GLenum pname) |
3243 | const char *glGetString (GLenum pname) |
|
|
3244 | CODE: |
|
|
3245 | RETVAL = (const char *)glGetString (pname); |
|
|
3246 | OUTPUT: |
|
|
3247 | RETVAL |
3219 | |
3248 | |
3220 | GLint glGetInteger (GLenum pname) |
3249 | GLint glGetInteger (GLenum pname) |
3221 | CODE: |
3250 | CODE: |
3222 | glGetIntegerv (pname, &RETVAL); |
3251 | glGetIntegerv (pname, &RETVAL); |
3223 | OUTPUT: |
3252 | OUTPUT: |
… | |
… | |
3426 | |
3455 | |
3427 | void |
3456 | void |
3428 | find_widget (SV *self, NV x, NV y) |
3457 | find_widget (SV *self, NV x, NV y) |
3429 | PPCODE: |
3458 | PPCODE: |
3430 | { |
3459 | { |
3431 | if (within_widget (self, x, y)) |
3460 | if (within_widget (self, x, y)) |
3432 | XPUSHs (self); |
3461 | XPUSHs (self); |
3433 | } |
3462 | } |
3434 | |
3463 | |
3435 | BOOT: |
3464 | BOOT: |
3436 | { |
3465 | { |
… | |
… | |
3444 | |
3473 | |
3445 | void |
3474 | void |
3446 | draw (SV *self) |
3475 | draw (SV *self) |
3447 | CODE: |
3476 | CODE: |
3448 | { |
3477 | { |
3449 | HV *hv; |
3478 | HV *hv; |
3450 | SV **svp; |
3479 | SV **svp; |
3451 | NV x, y, w, h; |
3480 | NV x, y, w, h; |
3452 | SV *draw_x_sv = GvSV (draw_x_gv); |
3481 | SV *draw_x_sv = GvSV (draw_x_gv); |
3453 | SV *draw_y_sv = GvSV (draw_y_gv); |
3482 | SV *draw_y_sv = GvSV (draw_y_gv); |
3454 | SV *draw_w_sv = GvSV (draw_w_gv); |
3483 | SV *draw_w_sv = GvSV (draw_w_gv); |
3455 | SV *draw_h_sv = GvSV (draw_h_gv); |
3484 | SV *draw_h_sv = GvSV (draw_h_gv); |