ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/Client.xs
(Generate patch)

Comparing deliantra/Deliantra-Client/Client.xs (file contents):
Revision 1.309 by root, Mon Dec 26 22:30:21 2011 UTC vs.
Revision 1.335 by root, Mon Nov 19 01:56:11 2018 UTC

15 15
16#include "EXTERN.h" 16#include "EXTERN.h"
17#include "perl.h" 17#include "perl.h"
18#include "XSUB.h" 18#include "XSUB.h"
19 19
20#include "flat_hash_map.hpp"
21
20#ifdef _WIN32 22#ifdef _WIN32
21# undef pipe 23# undef pipe
22// microsoft vs. C 24// microsoft vs. C
23# define sqrtf(x) sqrt(x) 25# define sqrtf(x) sqrt(x)
24# define atan2f(x,y) atan2(x,y) 26# define atan2f(x,y) atan2(x,y)
25# define M_PI 3.14159265f 27# define M_PI 3.14159265f
26#endif 28#endif
27 29
28#include <assert.h> 30#include <cassert>
29#include <math.h> 31#include <cmath>
30#include <string.h> 32#include <cstring>
31#include <stdio.h> 33#include <cstdio>
32#include <stdlib.h> 34#include <cstdlib>
35
36#include <utility>
37#include <bitset>
33 38
34#define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW 39#define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW
35 40
36#include <SDL.h> 41#include <SDL.h>
37#include <SDL_thread.h> 42#include <SDL_thread.h>
48#endif 53#endif
49 54
50#define PANGO_ENABLE_BACKEND 55#define PANGO_ENABLE_BACKEND
51#define G_DISABLE_CAST_CHECKS 56#define G_DISABLE_CAST_CHECKS
52 57
53#include <glib/gmacros.h> 58#include <glib.h>
54 59
55#include <pango/pango.h> 60#include <pango/pango.h>
56 61
57#ifndef PANGO_VERSION_CHECK 62#ifndef PANGO_VERSION_CHECK
58# define PANGO_VERSION_CHECK(a,b,c) 0 63# define PANGO_VERSION_CHECK(a,b,c) 0
71# include <netinet/in.h> 76# include <netinet/in.h>
72# include <netinet/tcp.h> 77# include <netinet/tcp.h>
73# include <inttypes.h> 78# include <inttypes.h>
74#endif 79#endif
75 80
76#if __GNUC__ >= 4 81#include "ecb.h"
77# define expect(expr,value) __builtin_expect ((expr),(value)) 82#include "salloc.h"
78#else
79# define expect(expr,value) (expr)
80#endif
81
82#define expect_false(expr) expect ((expr) != 0, 0)
83#define expect_true(expr) expect ((expr) != 0, 1)
84 83
85#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ 84#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */
86 85
87/* this is used as fow flag as well, so has to have a different value */ 86/* this is used as fow flag as well, so has to have a different value */
88/* then anything that is computed by incoming darkness */ 87/* then anything that is computed by incoming darkness */
100#define KMOD_LRAM 0x10000 // our extension 99#define KMOD_LRAM 0x10000 // our extension
101 100
102#define TEXID_SPEECH 1 101#define TEXID_SPEECH 1
103#define TEXID_NOFACE 2 102#define TEXID_NOFACE 2
104 103
104// approximately divide by 255
105static unsigned int
106div255 (unsigned int n)
107{
108 return (n + (n >> 8)) >> 8;
109}
110
111static unsigned int
112minpot (unsigned int n)
113{
114 if (!n)
115 return 0;
116
117 --n;
118
119 n |= n >> 1;
120 n |= n >> 2;
121 n |= n >> 4;
122 n |= n >> 8;
123 n |= n >> 16;
124
125 return n + 1;
126}
127
105static char * 128static char *
106fast_sv_grow (SV *sv, STRLEN need) 129fast_sv_grow (SV *sv, STRLEN need)
107{ 130{
108 STRLEN len = SvLEN (sv); 131 STRLEN len = SvLEN (sv);
109 STRLEN want = SvCUR (sv) + need; 132 STRLEN want = SvCUR (sv) + need;
110 133
111 if (expect_false (len < want)) 134 if (ecb_expect_false (len < want))
112 { 135 {
113 do 136 do
114 len *= 2; 137 len *= 2;
115 while (len < want); 138 while (len < want);
116 139
184{ 207{
185 GSList *attrs = run->item->analysis.extra_attrs; 208 GSList *attrs = run->item->analysis.extra_attrs;
186 209
187 while (attrs) 210 while (attrs)
188 { 211 {
189 PangoAttribute *attr = attrs->data; 212 PangoAttribute *attr = (PangoAttribute *)attrs->data;
190 213
191 if (attr->klass->type == PANGO_ATTR_SHAPE) 214 if (attr->klass->type == PANGO_ATTR_SHAPE)
192 return 1; 215 return 1;
193 216
194 attrs = attrs->next; 217 attrs = attrs->next;
195 } 218 }
196 219
197 return 0; 220 return 0;
198} 221}
199 222
200typedef struct cf_layout { 223struct cf_layout {
201 PangoLayout *pl; 224 PangoLayout *pl;
202 float r, g, b, a; // default color for rgba mode 225 float r, g, b, a; // default color for rgba mode
203 int base_height; 226 int base_height;
204 DC__Font font; 227 DC__Font font;
205 rc_t *rc; 228 rc_t rc;
206} *DC__Layout; 229};
230
231typedef cf_layout *DC__Layout;
207 232
208static DC__Font default_font; 233static DC__Font default_font;
209static PangoContext *opengl_context; 234static PangoContext *opengl_context;
210static PangoFontMap *opengl_fontmap; 235static PangoFontMap *opengl_fontmap;
211 236
212static void 237static void
213substitute_func (FcPattern *pattern, gpointer data) 238substitute_func (FcPattern *pattern, gpointer data)
214{ 239{
215 FcPatternAddBool (pattern, FC_HINTING, 1); 240 FcPatternAddBool (pattern, FC_HINTING, 1);
216#ifdef FC_HINT_STYLE 241#ifdef FC_HINT_STYLE
217 FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); 242 FcPatternAddInteger (pattern, FC_HINT_STYLE, FC_HINT_FULL);
218#endif 243#endif
219 FcPatternAddBool (pattern, FC_AUTOHINT, 0); 244 FcPatternAddBool (pattern, FC_AUTOHINT, 0);
220} 245}
221 246
222static void 247static void
249 274
250 *w = rect.width; 275 *w = rect.width;
251 *h = rect.height; 276 *h = rect.height;
252} 277}
253 278
279/////////////////////////////////////////////////////////////////////////////
280
254typedef uint16_t tileid; 281typedef uint16_t tileid;
255typedef uint16_t faceid; 282typedef uint16_t faceid;
256 283
257typedef struct { 284struct maptex
285{
258 GLuint name; 286 GLuint name;
259 int w, h; 287 int w, h;
260 float s, t; 288 float s, t;
261 uint8_t r, g, b, a; 289 uint8_t r, g, b, a;
262 tileid smoothtile; 290 tileid smoothtile;
263 uint8_t smoothlevel; 291 uint8_t smoothlevel;
264 uint8_t unused; /* set to zero on use */ 292 uint8_t unused; /* set to zero on use */
265} maptex; 293};
266 294
267typedef struct { 295struct mapcell
296{
268 uint32_t player; 297 uint32_t player;
269 tileid tile[3]; 298 tileid tile[3];
270 uint16_t darkness; 299 uint16_t darkness;
271 uint8_t stat_width, stat_hp, flags, smoothmax; 300 uint8_t stat_width, stat_hp, flags, smoothmax;
272} mapcell; 301};
273 302
274typedef struct { 303struct maprow
304{
275 int32_t c0, c1; 305 int32_t c0, c1;
276 mapcell *col; 306 mapcell *col;
277} maprow; 307};
278 308
279typedef struct map { 309struct mapgrid {
280 int x, y, w, h; 310 int x, y, w, h;
281 int ox, oy; /* offset to virtual global coordinate system */ 311 int ox, oy; /* offset to virtual global coordinate system */
282 int faces; tileid *face2tile; // [faceid] 312 int faces; tileid *face2tile; // [faceid]
283 int texs; maptex *tex; // [tileid] 313 int texs; maptex *tex; // [tileid]
284 314
285 int32_t rows; 315 int32_t rows;
286 maprow *row; 316 maprow *row;
287} *DC__Map; 317};
288 318
289static char * 319typedef mapgrid *DC__Map;
320
321template<typename T>
322ecb_cold static void
290prepend (char *ptr, int sze, int inc) 323prepend (T *&ptr, int sze, int inc)
291{ 324{
292 char *p; 325 T *p;
293 326
294 New (0, p, sze + inc, char); 327 Newx (p, inc + sze, T);
295 Zero (p, inc, char); 328 Zero (p, inc, T);
296 Move (ptr, p + inc, sze, char); 329 Move (ptr, p + inc, sze, T);
297 Safefree (ptr); 330 Safefree (ptr);
298 331
299 return p; 332 ptr = p;
300} 333}
301 334
302static char * 335template<typename T>
336ecb_cold static void
303append (char *ptr, int sze, int inc) 337append (T *&ptr, int sze, int inc)
304{ 338{
305 Renew (ptr, sze + inc, char); 339 Renew (ptr, sze + inc, T);
306 Zero (ptr + sze, inc, char); 340 Zero (ptr + sze, inc, T);
307
308 return ptr;
309} 341}
310
311#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))
313 342
314static void 343static void
315need_facenum (struct map *self, faceid face) 344need_facenum (struct mapgrid *self, faceid face)
316{ 345{
317 while (self->faces <= face) 346 if (ecb_expect_true (self->faces > face))
318 { 347 return;
348
349 size_t newsize = minpot (face + 1);
319 Append (tileid, self->face2tile, self->faces, self->faces); 350 append (self->face2tile, self->faces, newsize - self->faces);
320 self->faces *= 2; 351 self->faces = newsize;
321 }
322} 352}
323 353
324static void 354static void
325need_texid (struct map *self, int texid) 355need_texid (struct mapgrid *self, int texid)
326{ 356{
327 while (self->texs <= texid) 357 if (ecb_expect_true (self->texs > texid))
328 { 358 return;
359
360 size_t newsize = minpot (texid + 1);
329 Append (maptex, self->tex, self->texs, self->texs); 361 append (self->tex, self->texs, newsize - self->texs);
330 self->texs *= 2; 362 self->texs = newsize;
331 }
332} 363}
333 364
334static maprow * 365static maprow *
335map_get_row (DC__Map self, int y) 366map_get_row (mapgrid *self, int y)
336{ 367{
337 if (0 > y) 368 if (0 > y)
338 { 369 {
339 int extend = - y + MAP_EXTEND_Y; 370 int extend = - y + MAP_EXTEND_Y;
340 Prepend (maprow, self->row, self->rows, extend); 371 prepend (self->row, self->rows, extend);
341 372
342 self->rows += extend; 373 self->rows += extend;
343 self->y += extend; 374 self->y += extend;
344 y += extend; 375 y += extend;
345 } 376 }
346 else if (y >= self->rows) 377 else if (y >= self->rows)
347 { 378 {
348 int extend = y - self->rows + MAP_EXTEND_Y; 379 int extend = y - self->rows + MAP_EXTEND_Y;
349 Append (maprow, self->row, self->rows, extend); 380 append (self->row, self->rows, extend);
350 self->rows += extend; 381 self->rows += extend;
351 } 382 }
352 383
353 return self->row + y; 384 return self->row + y;
354} 385}
364 } 395 }
365 396
366 if (row->c0 > x) 397 if (row->c0 > x)
367 { 398 {
368 int extend = row->c0 - x + MAP_EXTEND_X; 399 int extend = row->c0 - x + MAP_EXTEND_X;
369 Prepend (mapcell, row->col, row->c1 - row->c0, extend); 400 prepend (row->col, row->c1 - row->c0, extend);
370 row->c0 -= extend; 401 row->c0 -= extend;
371 } 402 }
372 else if (x >= row->c1) 403 else if (x >= row->c1)
373 { 404 {
374 int extend = x - row->c1 + MAP_EXTEND_X; 405 int extend = x - row->c1 + MAP_EXTEND_X;
375 Append (mapcell, row->col, row->c1 - row->c0, extend); 406 append (row->col, row->c1 - row->c0, extend);
376 row->c1 += extend; 407 row->c1 += extend;
377 } 408 }
378 409
379 return row->col + (x - row->c0); 410 return row->col + (x - row->c0);
380} 411}
381 412
382static mapcell * 413static mapcell *
383map_get_cell (DC__Map self, int x, int y) 414map_get_cell (mapgrid *self, int x, int y)
384{ 415{
385 return row_get_cell (map_get_row (self, y), x); 416 return row_get_cell (map_get_row (self, y), x);
386} 417}
387 418
388static void 419static void
389map_clear (DC__Map self) 420map_clear (mapgrid *self)
390{ 421{
391 int r; 422 int r;
392 423
393 for (r = 0; r < self->rows; r++) 424 for (r = 0; r < self->rows; r++)
394 Safefree (self->row[r].col); 425 Safefree (self->row[r].col);
412 (cell)->flags = 0; \ 443 (cell)->flags = 0; \
413 (cell)->player = 0; \ 444 (cell)->player = 0; \
414 } while (0) 445 } while (0)
415 446
416static void 447static void
417map_blank (DC__Map self, int x0, int y0, int w, int h) 448map_blank (mapgrid *self, int x0, int y0, int w, int h)
418{ 449{
419 int x, y; 450 int x, y;
420 maprow *row; 451 maprow *row;
421 mapcell *cell; 452 mapcell *cell;
422 453
439 CELL_CLEAR (cell); 470 CELL_CLEAR (cell);
440 } 471 }
441 } 472 }
442} 473}
443 474
444typedef struct { 475struct smooth_key
476{
445 tileid tile; 477 tileid tile;
446 uint8_t x, y, level; 478 uint8_t x, y, level;
447} smooth_key; 479
480 bool operator == (const smooth_key &o) const
481 {
482 return tile == o.tile && x == o.x && y == o.y && level == o.level;
483 }
484};
485
486typedef ska::flat_hash_map<smooth_key, IV, std::hash<smooth_key>, std::equal_to<smooth_key>, slice_allocator<smooth_key>> smooth_hash;
487
488namespace std {
489 template <>
490 struct hash<smooth_key>
491 {
492 size_t operator () (const smooth_key &v) const
493 {
494 return v.tile + (v.x << 8) + (v.y << 16) + (v.level << 24);
495 }
496 };
497}
448 498
449static void 499static void
450smooth_or_bits (HV *hv, smooth_key *key, IV bits) 500smooth_or_bits (smooth_hash &h, smooth_key &key, IV bits)
451{ 501{
452 SV **sv = hv_fetch (hv, (char *)key, sizeof (*key), 1); 502 auto &&it = h.find (key);
453 503
454 if (SvIOK (*sv)) 504 if (it == h.end ())
455 SvIV_set (*sv, SvIVX (*sv) | bits); 505 h.insert (std::make_pair (key, bits));
456 else 506 else
457 sv_setiv (*sv, bits); 507 it->second |= bits;
458} 508}
459 509
460static void 510static void
461music_finished (void) 511music_finished (void)
462{ 512{
481 ev.data2 = 0; 531 ev.data2 = 0;
482 532
483 SDL_PushEvent ((SDL_Event *)&ev); 533 SDL_PushEvent ((SDL_Event *)&ev);
484} 534}
485 535
486static unsigned int
487div255 (unsigned int n)
488{
489 return (n + (n >> 8)) >> 8;
490}
491
492static unsigned int
493minpot (unsigned int n)
494{
495 if (!n)
496 return 0;
497
498 --n;
499
500 n |= n >> 1;
501 n |= n >> 2;
502 n |= n >> 4;
503 n |= n >> 8;
504 n |= n >> 16;
505
506 return n + 1;
507}
508
509static unsigned int
510popcount (unsigned int n)
511{
512 n -= (n >> 1) & 0x55555555U;
513 n = ((n >> 2) & 0x33333333U) + (n & 0x33333333U);
514 n = ((n >> 4) + n) & 0x0f0f0f0fU;
515 n *= 0x01010101U;
516
517 return n >> 24;
518}
519
520/* SDL should provide this, really. */ 536/* SDL should provide this, really. */
521#define SDLK_MODIFIER_MIN 300 537#define SDLK_MODIFIER_MIN 300
522#define SDLK_MODIFIER_MAX 314 538#define SDLK_MODIFIER_MAX 314
523 539
524/******************************************************************************/ 540/******************************************************************************/
577 593
578 return mod; 594 return mod;
579} 595}
580 596
581static void 597static void
582deliantra_main () 598deliantra_main (SV *real_main)
583{ 599{
584 char *argv[] = { 0 }; 600 dSP;
585 call_argv ("::main", G_DISCARD | G_VOID, argv); 601
602 PUSHMARK (SP);
603 call_sv (real_main, G_DISCARD | G_VOID);
586} 604}
587 605
588#ifdef __MACOSX__ 606#ifdef __MACOSX__
607 static SV *real_main;
608
589 /* to due surprising braindamage on the side of SDL design, we 609 /* to due surprising braindamage on the side of SDL design, we
590 * do some mind-boggling hack here: SDL requires a custom main() 610 * 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, 611 * 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, 612 * due to shared library magic, calls -lSDLmain's main, not perl's main,
593 * and which calls our main (== SDL_main) back. 613 * and which calls our main (== SDL_main) back.
594 */ 614 */
595 extern C_LINKAGE int 615 extern C_LINKAGE int
596 main (int argc, char *argv[]) 616 main (int argc, char *argv[])
597 { 617 {
598 deliantra_main (); 618 deliantra_main (real_main);
599 } 619 }
600 620
601 #undef main 621 #undef main
602 622
603 extern C_LINKAGE int main (int argc, char *argv[]); 623 extern C_LINKAGE int main (int argc, char *argv[]);
604 624
605 static void 625 static void
606 SDL_braino (void) 626 SDL_main_hack (SV *real_main_)
607 { 627 {
628 real_main = real_main_;
629
608 char *argv[] = { "deliantra client", 0 }; 630 char *argv[] = { "deliantra client", 0 };
609 (main) (1, argv); 631 (main) (1, argv);
610 } 632 }
611#else 633#else
612 static void 634 static void
613 SDL_braino (void) 635 SDL_main_hack (SV *real_main)
614 { 636 {
615 deliantra_main (); 637 deliantra_main (real_main);
616 } 638 }
617#endif 639#endif
618 640
619MODULE = Deliantra::Client PACKAGE = DC 641MODULE = Deliantra::Client PACKAGE = DC
620 642
847 869
848NV ceil (NV x) 870NV ceil (NV x)
849 871
850IV minpot (UV n) 872IV minpot (UV n)
851 873
874UV ld32 (UV n)
875 CODE:
876 RETVAL = ecb_ld32 (n);
877 OUTPUT:
878 RETVAL
879
852IV popcount (UV n) 880IV popcount (UV n)
881 CODE:
882 RETVAL = ecb_popcount32 (n);
883 OUTPUT:
884 RETVAL
853 885
854NV distance (NV dx, NV dy) 886NV distance (NV dx, NV dy)
855 CODE: 887 CODE:
856 RETVAL = pow (dx * dx + dy * dy, 0.5); 888 RETVAL = pow (dx * dx + dy * dy, 0.5);
857 OUTPUT: 889 OUTPUT:
871#endif 903#endif
872} 904}
873 905
874char *SDL_GetError () 906char *SDL_GetError ()
875 907
876void SDL_braino () 908void SDL_main_hack (SV *real_main)
909 PROTOTYPE: &
877 910
878int SDL_Init (U32 flags) 911int SDL_Init (U32 flags)
879 912
880int SDL_InitSubSystem (U32 flags) 913int SDL_InitSubSystem (U32 flags)
881 914
882void SDL_QuitSubSystem (U32 flags) 915void SDL_QuitSubSystem (U32 flags)
883 916
884void SDL_Quit () 917void SDL_Quit ()
885 918
886int SDL_GL_SetAttribute (int attr, int value) 919int SDL_GL_SetAttribute (int attr, int value)
920 C_ARGS: (SDL_GLattr)attr, value
887 921
888int SDL_GL_GetAttribute (int attr) 922int SDL_GL_GetAttribute (int attr)
889 CODE: 923 CODE:
890 if (SDL_GL_GetAttribute (attr, &RETVAL)) 924 if (SDL_GL_GetAttribute ((SDL_GLattr)attr, &RETVAL))
891 XSRETURN_UNDEF; 925 XSRETURN_UNDEF;
892 OUTPUT: 926 OUTPUT:
893 RETVAL 927 RETVAL
894 928
895void 929void
950 ); 984 );
951 985
952 if (RETVAL) 986 if (RETVAL)
953 { 987 {
954 av_clear (texture_av); 988 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); 989#define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name);
958#include "glfunc.h" 990#include "glfunc.h"
959#undef GL_FUNC 991#undef GL_FUNC
960
961 if (!gl.ActiveTexture ) gl.ActiveTexture = gl.ActiveTextureARB; 992 if (!gl.ActiveTexture ) gl.ActiveTexture = gl.ActiveTextureARB;
962 if (!gl.MultiTexCoord2f) gl.MultiTexCoord2f = gl.MultiTexCoord2fARB; 993 if (!gl.MultiTexCoord2f) gl.MultiTexCoord2f = gl.MultiTexCoord2fARB;
963 } 994 }
964} 995}
965 OUTPUT: 996 OUTPUT:
966 RETVAL 997 RETVAL
967 998
968void 999void
1000SDL_WM_SetCaption (const char *title, const char *icon)
1001
1002void
969SDL_GL_SwapBuffers () 1003SDL_GL_SwapBuffers ()
970 1004
971char * 1005char *
972SDL_GetKeyName (int sym) 1006SDL_GetKeyName (int sym)
1007 C_ARGS: (SDLKey)sym
973 1008
974int 1009int
975SDL_GetAppState () 1010SDL_GetAppState ()
976 1011
977int 1012int
978SDL_GetModState () 1013SDL_GetModState ()
979 1014
1015int
1016SDL_WaitEvent ()
1017 C_ARGS: 0
1018
980void 1019void
1020SDL_PumpEvents ()
1021
1022void
981poll_events () 1023peep_events ()
982 PPCODE: 1024 PPCODE:
983{ 1025{
984 SDL_Event ev; 1026 SDL_Event ev;
985 1027
986 SDL_PumpEvents (); 1028 SDL_PumpEvents ();
1067 OUTPUT: 1109 OUTPUT:
1068 RETVAL 1110 RETVAL
1069 1111
1070int 1112int
1071Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) 1113Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096)
1072 POSTCALL: 1114 POSTCALL:
1073 Mix_HookMusicFinished (music_finished); 1115 Mix_HookMusicFinished (music_finished);
1074 Mix_ChannelFinished (channel_finished); 1116 Mix_ChannelFinished (channel_finished);
1075 1117
1076void 1118void
1077Mix_QuerySpec () 1119Mix_QuerySpec ()
1140 RETVAL 1182 RETVAL
1141 1183
1142void 1184void
1143IMG_Init (int flags = IMG_INIT_JPG | IMG_INIT_PNG) 1185IMG_Init (int flags = IMG_INIT_JPG | IMG_INIT_PNG)
1144 1186
1187# MIX_INIT_MP3 gives smpeg + libstdc++ + libgcc_s
1145void 1188void
1146Mix_Init (int flags = MIX_INIT_MOD | MIX_INIT_MP3 | MIX_INIT_OGG) 1189Mix_Init (int flags = MIX_INIT_MOD | MIX_INIT_OGG)
1147 1190
1148void 1191void
1149load_image_inline (SV *image_) 1192load_image_inline (SV *image_)
1150 ALIAS: 1193 ALIAS:
1151 load_image_file = 1 1194 load_image_file = 1
1197 1240
1198 SDL_LockSurface (surface2); 1241 SDL_LockSurface (surface2);
1199 EXTEND (SP, 6); 1242 EXTEND (SP, 6);
1200 PUSHs (sv_2mortal (newSViv (surface2->w))); 1243 PUSHs (sv_2mortal (newSViv (surface2->w)));
1201 PUSHs (sv_2mortal (newSViv (surface2->h))); 1244 PUSHs (sv_2mortal (newSViv (surface2->h)));
1202 PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); 1245 PUSHs (sv_2mortal (newSVpvn ((const char *)surface2->pixels, surface2->h * surface2->pitch)));
1203 PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); 1246 PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB)));
1204 PUSHs (sv_2mortal (newSViv (GL_RGBA))); 1247 PUSHs (sv_2mortal (newSViv (GL_RGBA)));
1205 PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); 1248 PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE)));
1206 SDL_UnlockSurface (surface2); 1249 SDL_UnlockSurface (surface2);
1207 1250
1279MODULE = Deliantra::Client PACKAGE = DC::Font 1322MODULE = Deliantra::Client PACKAGE = DC::Font
1280 1323
1281PROTOTYPES: DISABLE 1324PROTOTYPES: DISABLE
1282 1325
1283DC::Font 1326DC::Font
1284new_from_file (SV *class, char *path, int id = 0) 1327new_from_file (SV *klass, char *path, int id = 0)
1285 CODE: 1328 CODE:
1286{ 1329{
1287 int count; 1330 int count;
1288 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); 1331 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count);
1289 RETVAL = pango_fc_font_description_from_pattern (pattern, 0); 1332 RETVAL = pango_fc_font_description_from_pattern (pattern, 0);
1318 PROTOTYPE: 1361 PROTOTYPE:
1319 CODE: 1362 CODE:
1320 tc_restore (); 1363 tc_restore ();
1321 1364
1322DC::Layout 1365DC::Layout
1323new (SV *class) 1366new (SV *klass)
1324 CODE: 1367 CODE:
1325 New (0, RETVAL, 1, struct cf_layout); 1368 RETVAL = new cf_layout;
1326 1369
1327 RETVAL->pl = pango_layout_new (opengl_context); 1370 RETVAL->pl = pango_layout_new (opengl_context);
1328 RETVAL->r = 1.; 1371 RETVAL->r = 1.;
1329 RETVAL->g = 1.; 1372 RETVAL->g = 1.;
1330 RETVAL->b = 1.; 1373 RETVAL->b = 1.;
1331 RETVAL->a = 1.; 1374 RETVAL->a = 1.;
1332 RETVAL->base_height = MIN_FONT_HEIGHT; 1375 RETVAL->base_height = MIN_FONT_HEIGHT;
1333 RETVAL->font = 0; 1376 RETVAL->font = 0;
1334 RETVAL->rc = rc_alloc ();
1335 1377
1336 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); 1378 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR);
1337 layout_update_font (RETVAL); 1379 layout_update_font (RETVAL);
1338 OUTPUT: 1380 OUTPUT:
1339 RETVAL 1381 RETVAL
1340 1382
1341void 1383void
1342DESTROY (DC::Layout self) 1384DESTROY (DC::Layout self)
1343 CODE: 1385 CODE:
1344 g_object_unref (self->pl); 1386 g_object_unref (self->pl);
1345 rc_free (self->rc);
1346 Safefree (self); 1387 delete self;
1347 1388
1348void 1389void
1349set_text (DC::Layout self, SV *text_) 1390set_text (DC::Layout self, SV *text_)
1350 CODE: 1391 CODE:
1351{ 1392{
1477 1518
1478void 1519void
1479set_height (DC::Layout self, int base_height) 1520set_height (DC::Layout self, int base_height)
1480 CODE: 1521 CODE:
1481 if (self->base_height != base_height) 1522 if (self->base_height != base_height)
1482 { 1523 {
1483 self->base_height = base_height; 1524 self->base_height = base_height;
1484 layout_update_font (self); 1525 layout_update_font (self);
1485 } 1526 }
1486 1527
1487void 1528void
1605} 1646}
1606 1647
1607void 1648void
1608render (DC::Layout self, float x, float y, int flags = 0) 1649render (DC::Layout self, float x, float y, int flags = 0)
1609 CODE: 1650 CODE:
1610 rc_clear (self->rc); 1651 self->rc.clear ();
1611 pango_opengl_render_layout_subpixel ( 1652 pango_opengl_render_layout_subpixel (
1612 self->pl, 1653 self->pl,
1613 self->rc, 1654 &self->rc,
1614 x * PANGO_SCALE, y * PANGO_SCALE, 1655 x * PANGO_SCALE, y * PANGO_SCALE,
1615 self->r, self->g, self->b, self->a, 1656 self->r, self->g, self->b, self->a,
1616 flags 1657 flags
1617 ); 1658 );
1618 // we assume that context_change actually clears/frees stuff 1659 // we assume that context_change actually clears/frees stuff
1629 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 1670 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
1630 GL_ONE , GL_ONE_MINUS_SRC_ALPHA); 1671 GL_ONE , GL_ONE_MINUS_SRC_ALPHA);
1631 glEnable (GL_ALPHA_TEST); 1672 glEnable (GL_ALPHA_TEST);
1632 glAlphaFunc (GL_GREATER, 7.f / 255.f); 1673 glAlphaFunc (GL_GREATER, 7.f / 255.f);
1633 1674
1634 rc_draw (self->rc); 1675 self->rc.draw ();
1635 1676
1636 glDisable (GL_ALPHA_TEST); 1677 glDisable (GL_ALPHA_TEST);
1637 glDisable (GL_BLEND); 1678 glDisable (GL_BLEND);
1638 glDisable (GL_TEXTURE_2D); 1679 glDisable (GL_TEXTURE_2D);
1639} 1680}
1851MODULE = Deliantra::Client PACKAGE = DC::Map 1892MODULE = Deliantra::Client PACKAGE = DC::Map
1852 1893
1853PROTOTYPES: DISABLE 1894PROTOTYPES: DISABLE
1854 1895
1855DC::Map 1896DC::Map
1856new (SV *class) 1897new (SV *klass)
1857 CODE: 1898 CODE:
1858 New (0, RETVAL, 1, struct map); 1899 New (0, RETVAL, 1, mapgrid);
1859 RETVAL->x = 0; 1900 RETVAL->x = 0;
1860 RETVAL->y = 0; 1901 RETVAL->y = 0;
1861 RETVAL->w = 0; 1902 RETVAL->w = 0;
1862 RETVAL->h = 0; 1903 RETVAL->h = 0;
1863 RETVAL->ox = 0; 1904 RETVAL->ox = 0;
1900 1941
1901void 1942void
1902set_smooth (DC::Map self, int face, int smooth, int level) 1943set_smooth (DC::Map self, int face, int smooth, int level)
1903 CODE: 1944 CODE:
1904{ 1945{
1905 tileid texid; 1946 tileid texid;
1906 maptex *tex; 1947 maptex *tex;
1907 1948
1908 if (face < 0 || face >= self->faces) 1949 if (face < 0 || face >= self->faces)
1909 return; 1950 return;
1910 1951
1911 if (smooth < 0 || smooth >= self->faces) 1952 if (smooth < 0 || smooth >= self->faces)
1912 return; 1953 return;
1913 1954
1914 texid = self->face2tile [face]; 1955 texid = self->face2tile [face];
1915 1956
1916 if (!texid) 1957 if (!texid)
1917 return; 1958 return;
1918 1959
1919 tex = self->tex + texid; 1960 tex = self->tex + texid;
1952} 1993}
1953 1994
1954void 1995void
1955expire_textures (DC::Map self, int texid, int count) 1996expire_textures (DC::Map self, int texid, int count)
1956 PPCODE: 1997 PPCODE:
1957 for (; texid < self->texs && count; ++texid, --count) 1998 for (; texid < self->texs && count; ++texid, --count)
1958 { 1999 {
1959 maptex *tex = self->tex + texid; 2000 maptex *tex = self->tex + texid;
1960 2001
1961 if (tex->name) 2002 if (tex->name)
1962 { 2003 {
2009 self->ox += dx; self->x += dx; 2050 self->ox += dx; self->x += dx;
2010 self->oy += dy; self->y += dy; 2051 self->oy += dy; self->y += dy;
2011 2052
2012 while (self->y < 0) 2053 while (self->y < 0)
2013 { 2054 {
2014 Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); 2055 prepend (self->row, self->rows, MAP_EXTEND_Y);
2015 2056
2016 self->rows += MAP_EXTEND_Y; 2057 self->rows += MAP_EXTEND_Y;
2017 self->y += MAP_EXTEND_Y; 2058 self->y += MAP_EXTEND_Y;
2018 } 2059 }
2019} 2060}
2020 2061
2021SV * 2062SV *
2022map1a_update (DC::Map self, SV *data_, int extmap) 2063map1a_update (DC::Map self, SV *data_)
2023 CODE: 2064 CODE:
2024{ 2065{
2025 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 2066 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
2026 uint8_t *data_end = (uint8_t *)SvEND (data_); 2067 uint8_t *data_end = (uint8_t *)SvEND (data_);
2027 mapcell *cell; 2068 mapcell *cell;
2048 2089
2049 //TODO: don't trust server data to be in-range(!) 2090 //TODO: don't trust server data to be in-range(!)
2050 2091
2051 if (flags & 8) 2092 if (flags & 8)
2052 { 2093 {
2094 uint8_t ext, cmd;
2095
2053 if (extmap) 2096 do
2054 { 2097 {
2055 uint8_t ext, cmd; 2098 ext = *data++;
2099 cmd = ext & 0x7f;
2056 2100
2057 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
2058 { 2104 {
2059 ext = *data++;
2060 cmd = ext & 0x7f;
2061
2062 if (cmd < 4)
2063 cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */
2064 else if (cmd == 5) // health
2065 {
2066 cell->stat_width = 1; 2105 cell->stat_width = 1;
2067 cell->stat_hp = *data++; 2106 cell->stat_hp = *data++;
2068 }
2069 else if (cmd == 6) // monster width
2070 cell->stat_width = *data++ + 1;
2071 else if (cmd == 0x47)
2072 {
2073 if (*data == 1) cell->player = data [1];
2074 else if (*data == 2) cell->player = data [2] + (data [1] << 8);
2075 else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16);
2076 else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24);
2077
2078 data += *data + 1;
2079 }
2080 else if (cmd == 8) // cell flags
2081 cell->flags = *data++;
2082 else if (ext & 0x40) // unknown, multibyte => skip
2083 data += *data + 1;
2084 else
2085 data++;
2086 } 2107 }
2087 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++;
2088 } 2125 }
2089 else 2126 while (ext & 0x80);
2090 cell->darkness = *data++ + 1;
2091 } 2127 }
2092 2128
2093 for (z = 0; z <= 2; ++z) 2129 for (z = 0; z <= 2; ++z)
2094 if (flags & (4 >> z)) 2130 if (flags & (4 >> z))
2095 { 2131 {
2169 | (b << 16) 2205 | (b << 16)
2170 | (a << 24); 2206 | (a << 24);
2171 } 2207 }
2172 } 2208 }
2173 2209
2174 RETVAL = map_sv; 2210 RETVAL = map_sv;
2175} 2211}
2176 OUTPUT: 2212 OUTPUT:
2177 RETVAL 2213 RETVAL
2178 2214
2179void 2215void
2180draw (DC::Map self, int mx, int my, int sw, int sh, int Tw, int Th, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) 2216draw (DC::Map self, int mx, int my, int sw, int sh, int Tw, int Th, U32 player = 0xffffffff, int sdx = 0, int sdy = 0)
2181 CODE: 2217 CODE:
2182{ 2218{
2183 int x, y, z; 2219 int x, y, z;
2184 2220
2185 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ());
2186 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level
2187 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) 2221 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k), also, static!
2188 smooth_key skey;
2189 int pl_x, pl_y; 2222 int pl_x, pl_y;
2190 maptex pl_tex; 2223 maptex pl_tex;
2191 rc_t *rc = rc_alloc (); 2224 rc_t rc;
2192 rc_t *rc_ov = rc_alloc (); 2225 rc_t rc_ov;
2193 rc_key_t key; 2226 rc_key_t key;
2194 rc_array_t *arr; 2227 rc_t::array_t *arr;
2195 2228
2196 pl_tex.name = 0; 2229 pl_tex.name = 0;
2197 2230
2198 // that's current max. sorry. 2231 // that's current max. sorry.
2199 if (sw > 255) sw = 255; 2232 if (sw > 255) sw = 255;
2200 if (sh > 255) sh = 255; 2233 if (sh > 255) sh = 255;
2201
2202 // clear key, in case of extra padding
2203 memset (&skey, 0, sizeof (skey));
2204 2234
2205 memset (&key, 0, sizeof (key)); 2235 memset (&key, 0, sizeof (key));
2206 key.r = 255; 2236 key.r = 255;
2207 key.g = 255; 2237 key.g = 255;
2208 key.b = 255; 2238 key.b = 255;
2214 my += self->y; 2244 my += self->y;
2215 2245
2216 // first pass: determine smooth_max 2246 // first pass: determine smooth_max
2217 // rather ugly, if you ask me 2247 // rather ugly, if you ask me
2218 // could also be stored inside mapcell and updated on change 2248 // could also be stored inside mapcell and updated on change
2219 memset (smooth_max, 0, sizeof (smooth_max)); 2249 memset (smooth_max, 0, sizeof (smooth_max[0]) * (sh + 1));
2220 2250
2221 for (y = 0; y < sh; y++) 2251 for (y = 0; y < sh; y++)
2222 if (0 <= y + my && y + my < self->rows) 2252 if (0 <= y + my && y + my < self->rows)
2223 { 2253 {
2224 maprow *row = self->row + (y + my); 2254 maprow *row = self->row + (y + my);
2239 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2269 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2240 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 2270 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
2241 2271
2242 for (z = 0; z <= 2; z++) 2272 for (z = 0; z <= 2; z++)
2243 { 2273 {
2244 memset (smooth_level, 0, sizeof (smooth_level)); 2274 std::bitset<256> smooth_level; // one bit for every possible smooth level
2275 smooth_key skey;
2276 smooth_hash smooth;
2245 key.texname = -1; 2277 key.texname = -1;
2246 2278
2247 for (y = 0; y < sh; y++) 2279 for (y = 0; y < sh; y++)
2248 if (0 <= y + my && y + my < self->rows) 2280 if (0 <= y + my && y + my < self->rows)
2249 { 2281 {
2266 2298
2267 if (!tex.name) 2299 if (!tex.name)
2268 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ 2300 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */
2269 2301
2270 key.texname = tex.name; 2302 key.texname = tex.name;
2271 arr = rc_array (rc, &key); 2303 arr = &rc.array (key);
2272 } 2304 }
2273 2305
2274 px = (x + 1) * Th - tex.w; 2306 px = (x + 1) * Th - tex.w;
2275 py = (y + 1) * Tw - tex.h; 2307 py = (y + 1) * Tw - tex.h;
2276 2308
2277 if (expect_false (cell->player == player) && expect_false (z == 2)) 2309 if (ecb_expect_false (cell->player == player) && ecb_expect_false (z == 2))
2278 { 2310 {
2279 pl_x = px; 2311 pl_x = px;
2280 pl_y = py; 2312 pl_y = py;
2281 pl_tex = tex; 2313 pl_tex = tex;
2282 continue; 2314 continue;
2283 } 2315 }
2284 2316
2285 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2317 arr->t2f_v3f (0 , 0 , px , py , 0);
2286 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2318 arr->t2f_v3f (0 , tex.t, px , py + tex.h, 0);
2287 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); 2319 arr->t2f_v3f (tex.s, tex.t, px + tex.w, py + tex.h, 0);
2288 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); 2320 arr->t2f_v3f (tex.s, 0 , px + tex.w, py , 0);
2289 2321
2290 // update smooth hash 2322 // update smooth hash
2291 if (tex.smoothtile) 2323 if (tex.smoothtile)
2292 { 2324 {
2293 skey.tile = tex.smoothtile; 2325 skey.tile = tex.smoothtile;
2294 skey.level = tex.smoothlevel; 2326 skey.level = tex.smoothlevel;
2295 2327
2296 smooth_level [tex.smoothlevel >> 5] |= ((uint32_t)1) << (tex.smoothlevel & 31); 2328 smooth_level[tex.smoothlevel] = 1;
2297 2329
2298 // add bits to current tile and all neighbours. skey.x|y is 2330 // add bits to current tile and all neighbours. skey.x|y is
2299 // shifted +1|+1 so we always stay positive. 2331 // shifted +1|+1 so we always stay positive.
2300 2332
2301 // bits is ___n cccc CCCC bbbb 2333 // bits is ___n cccc CCCC bbbb
2309 2341
2310 // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· 2342 // corners: 1 ┛· 2 ·┗ 4 ·· 8 ··
2311 // ·· ·· ·┏ ┓· 2343 // ·· ·· ·┏ ┓·
2312 2344
2313 // full tile 2345 // full tile
2314 skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x1000); 2346 skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x1000);
2315 2347
2316 // borders 2348 // borders
2317 skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0091); 2349 skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0091);
2318 skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0032); 2350 skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0032);
2319 skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0064); 2351 skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0064);
2320 skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, &skey, 0x00c8); 2352 skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, skey, 0x00c8);
2321 2353
2322 // corners 2354 // corners
2323 skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0100); 2355 skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0100);
2324 skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0200); 2356 skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0200);
2325 skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400); 2357 skey.x = x ; skey.y = y ; smooth_or_bits (smooth, skey, 0x0400);
2326 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); 2358 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, skey, 0x0800);
2327 } 2359 }
2328 } 2360 }
2329 2361
2330 if (expect_false (z == 2) && expect_false (cell->flags)) 2362 if (ecb_expect_false (z == 2) && ecb_expect_false (cell->flags))
2331 { 2363 {
2332 // overlays such as the speech bubble, probably more to come 2364 // overlays such as the speech bubble, probably more to come
2333 if (cell->flags & 1) 2365 if (cell->flags & 1)
2334 { 2366 {
2335 rc_key_t key_ov = key; 2367 rc_key_t key_ov = key;
2336 maptex tex = self->tex [TEXID_SPEECH]; 2368 maptex tex = self->tex[TEXID_SPEECH];
2337 rc_array_t *arr;
2338 int px = x * Tw + Tw * 2 / 32; 2369 int px = x * Tw + Tw * 2 / 32;
2339 int py = y * Th - Th * 6 / 32; 2370 int py = y * Th - Th * 6 / 32;
2340 2371
2341 key_ov.texname = tex.name; 2372 key_ov.texname = tex.name;
2342 arr = rc_array (rc_ov, &key_ov); 2373 rc_t::array_t &arr = rc_ov.array (key_ov);
2343 2374
2344 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2375 arr.t2f_v3f (0 , 0 , px , py , 0);
2345 rc_t2f_v3f (arr, 0 , tex.t, px , py + Th, 0); 2376 arr.t2f_v3f (0 , tex.t, px , py + Th, 0);
2346 rc_t2f_v3f (arr, tex.s, tex.t, px + Tw, py + Th, 0); 2377 arr.t2f_v3f (tex.s, tex.t, px + Tw, py + Th, 0);
2347 rc_t2f_v3f (arr, tex.s, 0 , px + Tw, py , 0); 2378 arr.t2f_v3f (tex.s, 0 , px + Tw, py , 0);
2348 } 2379 }
2349 } 2380 }
2350 } 2381 }
2351 } 2382 }
2352 2383
2353 rc_draw (rc); 2384 rc.draw ();
2354 rc_clear (rc); 2385 rc.clear ();
2355 2386
2356 // go through all smoothlevels, lowest to highest, then draw. 2387 // go through all smoothlevels, lowest to highest, then draw.
2357 // this is basically counting sort 2388 // this is basically counting sort
2358 { 2389 {
2359 int w, b; 2390 int w, b;
2360 2391
2361 glEnable (GL_TEXTURE_2D); 2392 glEnable (GL_TEXTURE_2D);
2362 glBegin (GL_QUADS); 2393 glBegin (GL_QUADS);
2363 for (w = 0; w < 256 / 32; ++w) 2394 for (int level = 0; level < smooth_level.size (); ++level)
2395 if (smooth_level[level])
2396 for (auto &&it = smooth.begin (); it != smooth.end (); ++it)
2364 { 2397 {
2365 uint32_t smask = smooth_level [w]; 2398 smooth_key &skey = it->first;
2366 if (smask) 2399 IV bits = it->second;
2367 for (b = 0; b < 32; ++b) 2400
2368 if (smask & (((uint32_t)1) << b)) 2401 if (!(bits & 0x1000)
2402 && skey.level == level
2403 && level > smooth_max [skey.x][skey.y])
2369 { 2404 {
2370 int level = (w << 5) | b; 2405 maptex tex = self->tex [skey.tile];
2406 int px = (((int)skey.x) - 1) * Tw;
2407 int py = (((int)skey.y) - 1) * Th;
2408 int border = bits & 15;
2409 int corner = (bits >> 8) & ~(bits >> 4) & 15;
2410 float dx = tex.s * .0625f; // 16 images/row
2411 float dy = tex.t * .5f ; // 2 images/column
2412
2371 HE *he; 2413 if (tex.name)
2372
2373 hv_iterinit (smooth);
2374 while ((he = hv_iternext (smooth)))
2375 { 2414 {
2376 smooth_key *skey = (smooth_key *)HeKEY (he); 2415 // this time avoiding texture state changes
2377 IV bits = SvIVX (HeVAL (he)); 2416 // save gobs of state changes.
2378 2417 if (key.texname != tex.name)
2379 if (!(bits & 0x1000)
2380 && skey->level == level
2381 && level > smooth_max [skey->x][skey->y])
2382 { 2418 {
2383 maptex tex = self->tex [skey->tile];
2384 int px = (((int)skey->x) - 1) * Tw;
2385 int py = (((int)skey->y) - 1) * Th;
2386 int border = bits & 15;
2387 int corner = (bits >> 8) & ~(bits >> 4) & 15;
2388 float dx = tex.s * .0625f; // 16 images/row
2389 float dy = tex.t * .5f ; // 2 images/column
2390
2391 if (tex.name)
2392 {
2393 // this time avoiding texture state changes
2394 // save gobs of state changes.
2395 if (key.texname != tex.name)
2396 {
2397 self->tex [skey->tile].unused = 0; 2419 self->tex [skey.tile].unused = 0;
2398 2420
2399 glEnd (); 2421 glEnd ();
2400 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); 2422 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name);
2401 glBegin (GL_QUADS); 2423 glBegin (GL_QUADS);
2402 } 2424 }
2403 2425
2404 if (border) 2426 if (border)
2405 { 2427 {
2406 float ox = border * dx; 2428 float ox = border * dx;
2407 2429
2408 glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); 2430 glTexCoord2f (ox , 0.f ); glVertex2i (px , py );
2409 glTexCoord2f (ox , dy ); glVertex2i (px , py + Th); 2431 glTexCoord2f (ox , dy ); glVertex2i (px , py + Th);
2410 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); 2432 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th);
2411 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); 2433 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py );
2412 } 2434 }
2413 2435
2414 if (corner) 2436 if (corner)
2415 { 2437 {
2416 float ox = corner * dx; 2438 float ox = corner * dx;
2417 2439
2418 glTexCoord2f (ox , dy ); glVertex2i (px , py ); 2440 glTexCoord2f (ox , dy ); glVertex2i (px , py );
2419 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th); 2441 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th);
2420 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th); 2442 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th);
2421 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py ); 2443 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py );
2422 }
2423 }
2424 } 2444 }
2425 } 2445 }
2426 } 2446 }
2427 } 2447 }
2428 2448
2429 glEnd (); 2449 glEnd ();
2430 glDisable (GL_TEXTURE_2D); 2450 glDisable (GL_TEXTURE_2D);
2431 key.texname = -1; 2451 key.texname = -1;
2432 } 2452 }
2433
2434 hv_clear (smooth);
2435 } 2453 }
2436 2454
2437 if (pl_tex.name) 2455 if (pl_tex.name)
2438 { 2456 {
2439 maptex tex = pl_tex; 2457 maptex tex = pl_tex;
2440 int px = pl_x + sdx; 2458 int px = pl_x + sdx;
2441 int py = pl_y + sdy; 2459 int py = pl_y + sdy;
2442 2460
2443 key.texname = tex.name; 2461 key.texname = tex.name;
2444 arr = rc_array (rc, &key); 2462 rc_t::array_t &arr = rc.array (key);
2445 2463
2446 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2464 arr.t2f_v3f (0 , 0 , px , py , 0);
2447 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2465 arr.t2f_v3f (0 , tex.t, px , py + tex.h, 0);
2448 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); 2466 arr.t2f_v3f (tex.s, tex.t, px + tex.w, py + tex.h, 0);
2449 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); 2467 arr.t2f_v3f (tex.s, 0 , px + tex.w, py , 0);
2450 2468
2451 rc_draw (rc); 2469 rc.draw ();
2452 } 2470 }
2453 2471
2454 rc_draw (rc_ov); 2472 rc_ov.draw ();
2455 rc_clear (rc_ov); 2473 rc_ov.clear ();
2456 2474
2457 glDisable (GL_BLEND); 2475 glDisable (GL_BLEND);
2458 rc_free (rc);
2459 rc_free (rc_ov);
2460 2476
2461 // top layer: overlays such as the health bar 2477 // top layer: overlays such as the health bar
2462 for (y = 0; y < sh; y++) 2478 for (y = 0; y < sh; y++)
2463 if (0 <= y + my && y + my < self->rows) 2479 if (0 <= y + my && y + my < self->rows)
2464 { 2480 {
2470 mapcell *cell = row->col + (x + mx - row->c0); 2486 mapcell *cell = row->col + (x + mx - row->c0);
2471 2487
2472 int px = x * Tw; 2488 int px = x * Tw;
2473 int py = y * Th; 2489 int py = y * Th;
2474 2490
2475 if (expect_false (cell->player == player)) 2491 if (ecb_expect_false (cell->player == player))
2476 { 2492 {
2477 px += sdx; 2493 px += sdx;
2478 py += sdy; 2494 py += sdy;
2479 } 2495 }
2480 2496
2708 else 2724 else
2709 *data++ = 0; 2725 *data++ = 0;
2710 } 2726 }
2711 } 2727 }
2712 2728
2713 /* if size is w*h + 5 then no data has been found */ 2729 /* if size is w*h + 5 then no data has been found */
2714 if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) 2730 if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5)
2715 { 2731 {
2716 SvPOK_only (data_sv); 2732 SvPOK_only (data_sv);
2717 SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); 2733 SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv));
2718 } 2734 }
2719 2735
2720 RETVAL = data_sv; 2736 RETVAL = data_sv;
2721} 2737}
2722 OUTPUT: 2738 OUTPUT:
2723 RETVAL 2739 RETVAL
2724 2740
2725void 2741void
2732 STRLEN len; 2748 STRLEN len;
2733 uint8_t *data, *end; 2749 uint8_t *data, *end;
2734 2750
2735 len = SvLEN (data_sv); 2751 len = SvLEN (data_sv);
2736 SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more 2752 SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more
2737 data = SvPVbyte_nolen (data_sv); 2753 data = (uint8_t *)SvPVbyte_nolen (data_sv);
2738 end = data + len + 8; 2754 end = data + len + 8;
2739 2755
2740 if (len < 5) 2756 if (len < 5)
2741 XSRETURN_EMPTY; 2757 XSRETURN_EMPTY;
2742 2758
2803} 2819}
2804 2820
2805MODULE = Deliantra::Client PACKAGE = DC::RW 2821MODULE = Deliantra::Client PACKAGE = DC::RW
2806 2822
2807DC::RW 2823DC::RW
2808new (SV *class, SV *data_sv) 2824new (SV *klass, SV *data_sv)
2809 CODE: 2825 CODE:
2810{ 2826{
2811 STRLEN datalen; 2827 STRLEN datalen;
2812 char *data = SvPVbyte (data_sv, datalen); 2828 char *data = SvPVbyte (data_sv, datalen);
2813 2829
2815} 2831}
2816 OUTPUT: 2832 OUTPUT:
2817 RETVAL 2833 RETVAL
2818 2834
2819DC::RW 2835DC::RW
2820new_from_file (SV *class, const char *path, const char *mode = "rb") 2836new_from_file (SV *klass, const char *path, const char *mode = "rb")
2821 CODE: 2837 CODE:
2822 RETVAL = SDL_RWFromFile (path, mode); 2838 RETVAL = SDL_RWFromFile (path, mode);
2823 OUTPUT: 2839 OUTPUT:
2824 RETVAL 2840 RETVAL
2825 2841
2934#else 2950#else
2935 XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); 2951 XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0)));
2936#endif 2952#endif
2937 2953
2938DC::MixChunk 2954DC::MixChunk
2939new (SV *class, DC::RW rwops) 2955new (SV *klass, DC::RW rwops)
2940 CODE: 2956 CODE:
2941 RETVAL = Mix_LoadWAV_RW (rwops, 1); 2957 RETVAL = Mix_LoadWAV_RW (rwops, 1);
2942 OUTPUT: 2958 OUTPUT:
2943 RETVAL 2959 RETVAL
2944 2960
3014 RETVAL = Mix_PlayingMusic (); 3030 RETVAL = Mix_PlayingMusic ();
3015 OUTPUT: 3031 OUTPUT:
3016 RETVAL 3032 RETVAL
3017 3033
3018DC::MixMusic 3034DC::MixMusic
3019new (SV *class, DC::RW rwops) 3035new (SV *klass, DC::RW rwops)
3020 CODE: 3036 CODE:
3021 RETVAL = Mix_LoadMUS_RW (rwops); 3037 RETVAL = Mix_LoadMUS_RW (rwops);
3022 OUTPUT: 3038 OUTPUT:
3023 RETVAL 3039 RETVAL
3024 3040
3177 gl.BlendFuncSeparateEXT = 0; 3193 gl.BlendFuncSeparateEXT = 0;
3178 3194
3179void 3195void
3180apple_nvidia_bug (int enable) 3196apple_nvidia_bug (int enable)
3181 3197
3182char * 3198const char *
3183gl_vendor () 3199gl_vendor ()
3184 CODE: 3200 CODE:
3185 RETVAL = (char *)glGetString (GL_VENDOR); 3201 RETVAL = (const char *)glGetString (GL_VENDOR);
3186 OUTPUT: 3202 OUTPUT:
3187 RETVAL 3203 RETVAL
3188 3204
3189char * 3205const char *
3190gl_version () 3206gl_version ()
3191 CODE: 3207 CODE:
3192 RETVAL = (char *)glGetString (GL_VERSION); 3208 RETVAL = (const char *)glGetString (GL_VERSION);
3193 OUTPUT: 3209 OUTPUT:
3194 RETVAL 3210 RETVAL
3195 3211
3196char * 3212const char *
3197gl_extensions () 3213gl_extensions ()
3198 CODE: 3214 CODE:
3199 RETVAL = (char *)glGetString (GL_EXTENSIONS); 3215 RETVAL = (const char *)glGetString (GL_EXTENSIONS);
3200 OUTPUT: 3216 OUTPUT:
3201 RETVAL 3217 RETVAL
3202 3218
3203const char *glGetString (GLenum pname) 3219const char *glGetString (GLenum pname)
3220 CODE:
3221 RETVAL = (const char *)glGetString (pname);
3222 OUTPUT:
3223 RETVAL
3204 3224
3205GLint glGetInteger (GLenum pname) 3225GLint glGetInteger (GLenum pname)
3206 CODE: 3226 CODE:
3207 glGetIntegerv (pname, &RETVAL); 3227 glGetIntegerv (pname, &RETVAL);
3208 OUTPUT: 3228 OUTPUT:
3411 3431
3412void 3432void
3413find_widget (SV *self, NV x, NV y) 3433find_widget (SV *self, NV x, NV y)
3414 PPCODE: 3434 PPCODE:
3415{ 3435{
3416 if (within_widget (self, x, y)) 3436 if (within_widget (self, x, y))
3417 XPUSHs (self); 3437 XPUSHs (self);
3418} 3438}
3419 3439
3420BOOT: 3440BOOT:
3421{ 3441{
3429 3449
3430void 3450void
3431draw (SV *self) 3451draw (SV *self)
3432 CODE: 3452 CODE:
3433{ 3453{
3434 HV *hv; 3454 HV *hv;
3435 SV **svp; 3455 SV **svp;
3436 NV x, y, w, h; 3456 NV x, y, w, h;
3437 SV *draw_x_sv = GvSV (draw_x_gv); 3457 SV *draw_x_sv = GvSV (draw_x_gv);
3438 SV *draw_y_sv = GvSV (draw_y_gv); 3458 SV *draw_y_sv = GvSV (draw_y_gv);
3439 SV *draw_w_sv = GvSV (draw_w_gv); 3459 SV *draw_w_sv = GvSV (draw_w_gv);
3440 SV *draw_h_sv = GvSV (draw_h_gv); 3460 SV *draw_h_sv = GvSV (draw_h_gv);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines