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.307 by root, Thu Oct 14 03:44:18 2010 UTC vs.
Revision 1.329 by root, Sun Nov 18 13:07:51 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
184{ 189{
185 GSList *attrs = run->item->analysis.extra_attrs; 190 GSList *attrs = run->item->analysis.extra_attrs;
186 191
187 while (attrs) 192 while (attrs)
188 { 193 {
189 PangoAttribute *attr = attrs->data; 194 PangoAttribute *attr = (PangoAttribute *)attrs->data;
190 195
191 if (attr->klass->type == PANGO_ATTR_SHAPE) 196 if (attr->klass->type == PANGO_ATTR_SHAPE)
192 return 1; 197 return 1;
193 198
194 attrs = attrs->next; 199 attrs = attrs->next;
195 } 200 }
196 201
197 return 0; 202 return 0;
198} 203}
199 204
200typedef struct cf_layout { 205struct cf_layout {
201 PangoLayout *pl; 206 PangoLayout *pl;
202 float r, g, b, a; // default color for rgba mode 207 float r, g, b, a; // default color for rgba mode
203 int base_height; 208 int base_height;
204 DC__Font font; 209 DC__Font font;
205 rc_t *rc; 210 rc_t rc;
206} *DC__Layout; 211};
212
213typedef cf_layout *DC__Layout;
207 214
208static DC__Font default_font; 215static DC__Font default_font;
209static PangoContext *opengl_context; 216static PangoContext *opengl_context;
210static PangoFontMap *opengl_fontmap; 217static PangoFontMap *opengl_fontmap;
211 218
212static void 219static void
213substitute_func (FcPattern *pattern, gpointer data) 220substitute_func (FcPattern *pattern, gpointer data)
214{ 221{
215 FcPatternAddBool (pattern, FC_HINTING, 1); 222 FcPatternAddBool (pattern, FC_HINTING, 1);
216#ifdef FC_HINT_STYLE 223#ifdef FC_HINT_STYLE
217 FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); 224 FcPatternAddInteger (pattern, FC_HINT_STYLE, FC_HINT_FULL);
218#endif 225#endif
219 FcPatternAddBool (pattern, FC_AUTOHINT, 0); 226 FcPatternAddBool (pattern, FC_AUTOHINT, 0);
220} 227}
221 228
222static void 229static void
252} 259}
253 260
254typedef uint16_t tileid; 261typedef uint16_t tileid;
255typedef uint16_t faceid; 262typedef uint16_t faceid;
256 263
257typedef struct { 264struct maptex
265{
258 GLuint name; 266 GLuint name;
259 int w, h; 267 int w, h;
260 float s, t; 268 float s, t;
261 uint8_t r, g, b, a; 269 uint8_t r, g, b, a;
262 tileid smoothtile; 270 tileid smoothtile;
263 uint8_t smoothlevel; 271 uint8_t smoothlevel;
264 uint8_t unused; /* set to zero on use */ 272 uint8_t unused; /* set to zero on use */
265} maptex; 273};
266 274
267typedef struct { 275struct mapcell
276{
268 uint32_t player; 277 uint32_t player;
269 tileid tile[3]; 278 tileid tile[3];
270 uint16_t darkness; 279 uint16_t darkness;
271 uint8_t stat_width, stat_hp, flags, smoothmax; 280 uint8_t stat_width, stat_hp, flags, smoothmax;
272} mapcell; 281};
273 282
274typedef struct { 283struct maprow
284{
275 int32_t c0, c1; 285 int32_t c0, c1;
276 mapcell *col; 286 mapcell *col;
277} maprow; 287};
278 288
279typedef struct map { 289struct mapgrid {
280 int x, y, w, h; 290 int x, y, w, h;
281 int ox, oy; /* offset to virtual global coordinate system */ 291 int ox, oy; /* offset to virtual global coordinate system */
282 int faces; tileid *face2tile; // [faceid] 292 int faces; tileid *face2tile; // [faceid]
283 int texs; maptex *tex; // [tileid] 293 int texs; maptex *tex; // [tileid]
284 294
285 int32_t rows; 295 int32_t rows;
286 maprow *row; 296 maprow *row;
287} *DC__Map; 297};
288 298
289static char * 299typedef mapgrid *DC__Map;
300
301template<typename T>
302static void
290prepend (char *ptr, int sze, int inc) 303prepend (T *&ptr, int sze, int inc)
291{ 304{
292 char *p; 305 T *p;
293 306
294 New (0, p, sze + inc, char); 307 New (0, p, sze + inc, T);
295 Zero (p, inc, char); 308 Zero (p, inc, T);
296 Move (ptr, p + inc, sze, char); 309 Move (ptr, p + inc, sze, T);
297 Safefree (ptr); 310 Safefree (ptr);
298 311
299 return p; 312 ptr = p;
300} 313}
301 314
302static char * 315template<typename T>
303append (char *ptr, int sze, int inc)
304{
305 Renew (ptr, sze + inc, char);
306 Zero (ptr + sze, inc, char);
307
308 return ptr;
309}
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
314static void 316static void
317append (T *&ptr, int sze, int inc)
318{
319 Renew (ptr, sze + inc, T);
320 Zero (ptr + sze, inc, T);
321}
322
323static void
315need_facenum (struct map *self, faceid face) 324need_facenum (struct mapgrid *self, faceid face)
316{ 325{
317 while (self->faces <= face) 326 while (self->faces <= face)
318 { 327 {
319 Append (tileid, self->face2tile, self->faces, self->faces); 328 append (self->face2tile, self->faces, self->faces);
320 self->faces *= 2; 329 self->faces *= 2;
321 } 330 }
322} 331}
323 332
324static void 333static void
325need_texid (struct map *self, int texid) 334need_texid (struct mapgrid *self, int texid)
326{ 335{
327 while (self->texs <= texid) 336 while (self->texs <= texid)
328 { 337 {
329 Append (maptex, self->tex, self->texs, self->texs); 338 append (self->tex, self->texs, self->texs);
330 self->texs *= 2; 339 self->texs *= 2;
331 } 340 }
332} 341}
333 342
334static maprow * 343static maprow *
335map_get_row (DC__Map self, int y) 344map_get_row (mapgrid *self, int y)
336{ 345{
337 if (0 > y) 346 if (0 > y)
338 { 347 {
339 int extend = - y + MAP_EXTEND_Y; 348 int extend = - y + MAP_EXTEND_Y;
340 Prepend (maprow, self->row, self->rows, extend); 349 prepend (self->row, self->rows, extend);
341 350
342 self->rows += extend; 351 self->rows += extend;
343 self->y += extend; 352 self->y += extend;
344 y += extend; 353 y += extend;
345 } 354 }
346 else if (y >= self->rows) 355 else if (y >= self->rows)
347 { 356 {
348 int extend = y - self->rows + MAP_EXTEND_Y; 357 int extend = y - self->rows + MAP_EXTEND_Y;
349 Append (maprow, self->row, self->rows, extend); 358 append (self->row, self->rows, extend);
350 self->rows += extend; 359 self->rows += extend;
351 } 360 }
352 361
353 return self->row + y; 362 return self->row + y;
354} 363}
364 } 373 }
365 374
366 if (row->c0 > x) 375 if (row->c0 > x)
367 { 376 {
368 int extend = row->c0 - x + MAP_EXTEND_X; 377 int extend = row->c0 - x + MAP_EXTEND_X;
369 Prepend (mapcell, row->col, row->c1 - row->c0, extend); 378 prepend (row->col, row->c1 - row->c0, extend);
370 row->c0 -= extend; 379 row->c0 -= extend;
371 } 380 }
372 else if (x >= row->c1) 381 else if (x >= row->c1)
373 { 382 {
374 int extend = x - row->c1 + MAP_EXTEND_X; 383 int extend = x - row->c1 + MAP_EXTEND_X;
375 Append (mapcell, row->col, row->c1 - row->c0, extend); 384 append (row->col, row->c1 - row->c0, extend);
376 row->c1 += extend; 385 row->c1 += extend;
377 } 386 }
378 387
379 return row->col + (x - row->c0); 388 return row->col + (x - row->c0);
380} 389}
381 390
382static mapcell * 391static mapcell *
383map_get_cell (DC__Map self, int x, int y) 392map_get_cell (mapgrid *self, int x, int y)
384{ 393{
385 return row_get_cell (map_get_row (self, y), x); 394 return row_get_cell (map_get_row (self, y), x);
386} 395}
387 396
388static void 397static void
389map_clear (DC__Map self) 398map_clear (mapgrid *self)
390{ 399{
391 int r; 400 int r;
392 401
393 for (r = 0; r < self->rows; r++) 402 for (r = 0; r < self->rows; r++)
394 Safefree (self->row[r].col); 403 Safefree (self->row[r].col);
412 (cell)->flags = 0; \ 421 (cell)->flags = 0; \
413 (cell)->player = 0; \ 422 (cell)->player = 0; \
414 } while (0) 423 } while (0)
415 424
416static void 425static void
417map_blank (DC__Map self, int x0, int y0, int w, int h) 426map_blank (mapgrid *self, int x0, int y0, int w, int h)
418{ 427{
419 int x, y; 428 int x, y;
420 maprow *row; 429 maprow *row;
421 mapcell *cell; 430 mapcell *cell;
422 431
439 CELL_CLEAR (cell); 448 CELL_CLEAR (cell);
440 } 449 }
441 } 450 }
442} 451}
443 452
444typedef struct { 453struct smooth_key
454{
445 tileid tile; 455 tileid tile;
446 uint8_t x, y, level; 456 uint8_t x, y, level;
447} smooth_key; 457
458 bool operator == (const smooth_key &o) const
459 {
460 return tile == o.tile && x == o.x && y == o.y && level == o.level;
461 }
462};
463
464typedef ska::flat_hash_map<smooth_key, IV> smooth_hash;
465
466namespace std {
467 template <>
468 struct hash<smooth_key>
469 {
470 size_t operator () (const smooth_key &v) const
471 {
472 return v.tile + (v.x << 8) + (v.y << 16) + (v.level << 24);
473 }
474 };
475}
448 476
449static void 477static void
450smooth_or_bits (HV *hv, smooth_key *key, IV bits) 478smooth_or_bits (smooth_hash &h, smooth_key &key, IV bits)
451{ 479{
452 SV **sv = hv_fetch (hv, (char *)key, sizeof (*key), 1); 480 auto &&it = h.find (key);
453 481
454 if (SvIOK (*sv)) 482 if (it == h.end ())
455 SvIV_set (*sv, SvIVX (*sv) | bits); 483 h.insert (std::make_pair (key, bits));
456 else 484 else
457 sv_setiv (*sv, bits); 485 it->second |= bits;
458} 486}
459 487
460static void 488static void
461music_finished (void) 489music_finished (void)
462{ 490{
481 ev.data2 = 0; 509 ev.data2 = 0;
482 510
483 SDL_PushEvent ((SDL_Event *)&ev); 511 SDL_PushEvent ((SDL_Event *)&ev);
484} 512}
485 513
514// approximately divide by 255
486static unsigned int 515static unsigned int
487div255 (unsigned int n) 516div255 (unsigned int n)
488{ 517{
489 return (n + (n >> 8)) >> 8; 518 return (n + (n >> 8)) >> 8;
490} 519}
577 606
578 return mod; 607 return mod;
579} 608}
580 609
581static void 610static void
582deliantra_main () 611deliantra_main (SV *real_main)
583{ 612{
584 char *argv[] = { 0 }; 613 dSP;
585 call_argv ("::main", G_DISCARD | G_VOID, argv); 614
615 PUSHMARK (SP);
616 call_sv (real_main, G_DISCARD | G_VOID);
586} 617}
587 618
588#ifdef __MACOSX__ 619#ifdef __MACOSX__
620 static SV *real_main;
621
589 /* to due surprising braindamage on the side of SDL design, we 622 /* to due surprising braindamage on the side of SDL design, we
590 * do some mind-boggling hack here: SDL requires a custom main() 623 * 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, 624 * 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, 625 * due to shared library magic, calls -lSDLmain's main, not perl's main,
593 * and which calls our main (== SDL_main) back. 626 * and which calls our main (== SDL_main) back.
594 */ 627 */
595 extern C_LINKAGE int 628 extern C_LINKAGE int
596 main (int argc, char *argv[]) 629 main (int argc, char *argv[])
597 { 630 {
598 deliantra_main (); 631 deliantra_main (real_main);
599 } 632 }
600 633
601 #undef main 634 #undef main
602 635
603 extern C_LINKAGE int main (int argc, char *argv[]); 636 extern C_LINKAGE int main (int argc, char *argv[]);
604 637
605 static void 638 static void
606 SDL_braino (void) 639 SDL_main_hack (SV *real_main_)
607 { 640 {
641 real_main = real_main_;
642
608 char *argv[] = { "deliantra client", 0 }; 643 char *argv[] = { "deliantra client", 0 };
609 (main) (1, argv); 644 (main) (1, argv);
610 } 645 }
611#else 646#else
612 static void 647 static void
613 SDL_braino (void) 648 SDL_main_hack (SV *real_main)
614 { 649 {
615 deliantra_main (); 650 deliantra_main (real_main);
616 } 651 }
617#endif 652#endif
618 653
619MODULE = Deliantra::Client PACKAGE = DC 654MODULE = Deliantra::Client PACKAGE = DC
620 655
821 856
822 const_iv (FOW_DARKNESS) 857 const_iv (FOW_DARKNESS)
823# undef const_iv 858# undef const_iv
824 }; 859 };
825 860
826 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 861 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
827 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 862 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
828 863
829 assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK); 864 assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK);
830 assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE); 865 assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE);
831} 866}
832 867
871#endif 906#endif
872} 907}
873 908
874char *SDL_GetError () 909char *SDL_GetError ()
875 910
876void SDL_braino () 911void SDL_main_hack (SV *real_main)
912 PROTOTYPE: &
877 913
878int SDL_Init (U32 flags) 914int SDL_Init (U32 flags)
879 915
880int SDL_InitSubSystem (U32 flags) 916int SDL_InitSubSystem (U32 flags)
881 917
882void SDL_QuitSubSystem (U32 flags) 918void SDL_QuitSubSystem (U32 flags)
883 919
884void SDL_Quit () 920void SDL_Quit ()
885 921
886int SDL_GL_SetAttribute (int attr, int value) 922int SDL_GL_SetAttribute (int attr, int value)
923 C_ARGS: (SDL_GLattr)attr, value
887 924
888int SDL_GL_GetAttribute (int attr) 925int SDL_GL_GetAttribute (int attr)
889 CODE: 926 CODE:
890 if (SDL_GL_GetAttribute (attr, &RETVAL)) 927 if (SDL_GL_GetAttribute ((SDL_GLattr)attr, &RETVAL))
891 XSRETURN_UNDEF; 928 XSRETURN_UNDEF;
892 OUTPUT: 929 OUTPUT:
893 RETVAL 930 RETVAL
894 931
895void 932void
950 ); 987 );
951 988
952 if (RETVAL) 989 if (RETVAL)
953 { 990 {
954 av_clear (texture_av); 991 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); 992#define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name);
958#include "glfunc.h" 993#include "glfunc.h"
959#undef GL_FUNC 994#undef GL_FUNC
960
961 if (!gl.ActiveTexture ) gl.ActiveTexture = gl.ActiveTextureARB; 995 if (!gl.ActiveTexture ) gl.ActiveTexture = gl.ActiveTextureARB;
962 if (!gl.MultiTexCoord2f) gl.MultiTexCoord2f = gl.MultiTexCoord2fARB; 996 if (!gl.MultiTexCoord2f) gl.MultiTexCoord2f = gl.MultiTexCoord2fARB;
963 } 997 }
964} 998}
965 OUTPUT: 999 OUTPUT:
966 RETVAL 1000 RETVAL
967 1001
968void 1002void
1003SDL_WM_SetCaption (const char *title, const char *icon)
1004
1005void
969SDL_GL_SwapBuffers () 1006SDL_GL_SwapBuffers ()
970 1007
971char * 1008char *
972SDL_GetKeyName (int sym) 1009SDL_GetKeyName (int sym)
1010 C_ARGS: (SDLKey)sym
973 1011
974int 1012int
975SDL_GetAppState () 1013SDL_GetAppState ()
976 1014
977int 1015int
978SDL_GetModState () 1016SDL_GetModState ()
979 1017
1018int
1019SDL_WaitEvent ()
1020 C_ARGS: 0
1021
980void 1022void
1023SDL_PumpEvents ()
1024
1025void
981poll_events () 1026peep_events ()
982 PPCODE: 1027 PPCODE:
983{ 1028{
984 SDL_Event ev; 1029 SDL_Event ev;
985 1030
986 SDL_PumpEvents (); 1031 SDL_PumpEvents ();
1067 OUTPUT: 1112 OUTPUT:
1068 RETVAL 1113 RETVAL
1069 1114
1070int 1115int
1071Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) 1116Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096)
1072 POSTCALL: 1117 POSTCALL:
1073 Mix_HookMusicFinished (music_finished); 1118 Mix_HookMusicFinished (music_finished);
1074 Mix_ChannelFinished (channel_finished); 1119 Mix_ChannelFinished (channel_finished);
1075 1120
1076void 1121void
1077Mix_QuerySpec () 1122Mix_QuerySpec ()
1139 OUTPUT: 1184 OUTPUT:
1140 RETVAL 1185 RETVAL
1141 1186
1142void 1187void
1143IMG_Init (int flags = IMG_INIT_JPG | IMG_INIT_PNG) 1188IMG_Init (int flags = IMG_INIT_JPG | IMG_INIT_PNG)
1189
1190# MIX_INIT_MP3 gives smpeg + libstdc++ + libgcc_s
1191void
1192Mix_Init (int flags = MIX_INIT_MOD | MIX_INIT_OGG)
1144 1193
1145void 1194void
1146load_image_inline (SV *image_) 1195load_image_inline (SV *image_)
1147 ALIAS: 1196 ALIAS:
1148 load_image_file = 1 1197 load_image_file = 1
1194 1243
1195 SDL_LockSurface (surface2); 1244 SDL_LockSurface (surface2);
1196 EXTEND (SP, 6); 1245 EXTEND (SP, 6);
1197 PUSHs (sv_2mortal (newSViv (surface2->w))); 1246 PUSHs (sv_2mortal (newSViv (surface2->w)));
1198 PUSHs (sv_2mortal (newSViv (surface2->h))); 1247 PUSHs (sv_2mortal (newSViv (surface2->h)));
1199 PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); 1248 PUSHs (sv_2mortal (newSVpvn ((const char *)surface2->pixels, surface2->h * surface2->pitch)));
1200 PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); 1249 PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB)));
1201 PUSHs (sv_2mortal (newSViv (GL_RGBA))); 1250 PUSHs (sv_2mortal (newSViv (GL_RGBA)));
1202 PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); 1251 PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE)));
1203 SDL_UnlockSurface (surface2); 1252 SDL_UnlockSurface (surface2);
1204 1253
1276MODULE = Deliantra::Client PACKAGE = DC::Font 1325MODULE = Deliantra::Client PACKAGE = DC::Font
1277 1326
1278PROTOTYPES: DISABLE 1327PROTOTYPES: DISABLE
1279 1328
1280DC::Font 1329DC::Font
1281new_from_file (SV *class, char *path, int id = 0) 1330new_from_file (SV *klass, char *path, int id = 0)
1282 CODE: 1331 CODE:
1283{ 1332{
1284 int count; 1333 int count;
1285 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); 1334 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count);
1286 RETVAL = pango_fc_font_description_from_pattern (pattern, 0); 1335 RETVAL = pango_fc_font_description_from_pattern (pattern, 0);
1315 PROTOTYPE: 1364 PROTOTYPE:
1316 CODE: 1365 CODE:
1317 tc_restore (); 1366 tc_restore ();
1318 1367
1319DC::Layout 1368DC::Layout
1320new (SV *class) 1369new (SV *klass)
1321 CODE: 1370 CODE:
1322 New (0, RETVAL, 1, struct cf_layout); 1371 RETVAL = new cf_layout;
1323 1372
1324 RETVAL->pl = pango_layout_new (opengl_context); 1373 RETVAL->pl = pango_layout_new (opengl_context);
1325 RETVAL->r = 1.; 1374 RETVAL->r = 1.;
1326 RETVAL->g = 1.; 1375 RETVAL->g = 1.;
1327 RETVAL->b = 1.; 1376 RETVAL->b = 1.;
1328 RETVAL->a = 1.; 1377 RETVAL->a = 1.;
1329 RETVAL->base_height = MIN_FONT_HEIGHT; 1378 RETVAL->base_height = MIN_FONT_HEIGHT;
1330 RETVAL->font = 0; 1379 RETVAL->font = 0;
1331 RETVAL->rc = rc_alloc ();
1332 1380
1333 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); 1381 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR);
1334 layout_update_font (RETVAL); 1382 layout_update_font (RETVAL);
1335 OUTPUT: 1383 OUTPUT:
1336 RETVAL 1384 RETVAL
1337 1385
1338void 1386void
1339DESTROY (DC::Layout self) 1387DESTROY (DC::Layout self)
1340 CODE: 1388 CODE:
1341 g_object_unref (self->pl); 1389 g_object_unref (self->pl);
1342 rc_free (self->rc);
1343 Safefree (self); 1390 delete self;
1344 1391
1345void 1392void
1346set_text (DC::Layout self, SV *text_) 1393set_text (DC::Layout self, SV *text_)
1347 CODE: 1394 CODE:
1348{ 1395{
1474 1521
1475void 1522void
1476set_height (DC::Layout self, int base_height) 1523set_height (DC::Layout self, int base_height)
1477 CODE: 1524 CODE:
1478 if (self->base_height != base_height) 1525 if (self->base_height != base_height)
1479 { 1526 {
1480 self->base_height = base_height; 1527 self->base_height = base_height;
1481 layout_update_font (self); 1528 layout_update_font (self);
1482 } 1529 }
1483 1530
1484void 1531void
1602} 1649}
1603 1650
1604void 1651void
1605render (DC::Layout self, float x, float y, int flags = 0) 1652render (DC::Layout self, float x, float y, int flags = 0)
1606 CODE: 1653 CODE:
1607 rc_clear (self->rc); 1654 self->rc.clear ();
1608 pango_opengl_render_layout_subpixel ( 1655 pango_opengl_render_layout_subpixel (
1609 self->pl, 1656 self->pl,
1610 self->rc, 1657 &self->rc,
1611 x * PANGO_SCALE, y * PANGO_SCALE, 1658 x * PANGO_SCALE, y * PANGO_SCALE,
1612 self->r, self->g, self->b, self->a, 1659 self->r, self->g, self->b, self->a,
1613 flags 1660 flags
1614 ); 1661 );
1615 // we assume that context_change actually clears/frees stuff 1662 // we assume that context_change actually clears/frees stuff
1626 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 1673 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
1627 GL_ONE , GL_ONE_MINUS_SRC_ALPHA); 1674 GL_ONE , GL_ONE_MINUS_SRC_ALPHA);
1628 glEnable (GL_ALPHA_TEST); 1675 glEnable (GL_ALPHA_TEST);
1629 glAlphaFunc (GL_GREATER, 7.f / 255.f); 1676 glAlphaFunc (GL_GREATER, 7.f / 255.f);
1630 1677
1631 rc_draw (self->rc); 1678 self->rc.draw ();
1632 1679
1633 glDisable (GL_ALPHA_TEST); 1680 glDisable (GL_ALPHA_TEST);
1634 glDisable (GL_BLEND); 1681 glDisable (GL_BLEND);
1635 glDisable (GL_TEXTURE_2D); 1682 glDisable (GL_TEXTURE_2D);
1636} 1683}
1848MODULE = Deliantra::Client PACKAGE = DC::Map 1895MODULE = Deliantra::Client PACKAGE = DC::Map
1849 1896
1850PROTOTYPES: DISABLE 1897PROTOTYPES: DISABLE
1851 1898
1852DC::Map 1899DC::Map
1853new (SV *class) 1900new (SV *klass)
1854 CODE: 1901 CODE:
1855 New (0, RETVAL, 1, struct map); 1902 New (0, RETVAL, 1, mapgrid);
1856 RETVAL->x = 0; 1903 RETVAL->x = 0;
1857 RETVAL->y = 0; 1904 RETVAL->y = 0;
1858 RETVAL->w = 0; 1905 RETVAL->w = 0;
1859 RETVAL->h = 0; 1906 RETVAL->h = 0;
1860 RETVAL->ox = 0; 1907 RETVAL->ox = 0;
1897 1944
1898void 1945void
1899set_smooth (DC::Map self, int face, int smooth, int level) 1946set_smooth (DC::Map self, int face, int smooth, int level)
1900 CODE: 1947 CODE:
1901{ 1948{
1902 tileid texid; 1949 tileid texid;
1903 maptex *tex; 1950 maptex *tex;
1904 1951
1905 if (face < 0 || face >= self->faces) 1952 if (face < 0 || face >= self->faces)
1906 return; 1953 return;
1907 1954
1908 if (smooth < 0 || smooth >= self->faces) 1955 if (smooth < 0 || smooth >= self->faces)
1909 return; 1956 return;
1910 1957
1911 texid = self->face2tile [face]; 1958 texid = self->face2tile [face];
1912 1959
1913 if (!texid) 1960 if (!texid)
1914 return; 1961 return;
1915 1962
1916 tex = self->tex + texid; 1963 tex = self->tex + texid;
1949} 1996}
1950 1997
1951void 1998void
1952expire_textures (DC::Map self, int texid, int count) 1999expire_textures (DC::Map self, int texid, int count)
1953 PPCODE: 2000 PPCODE:
1954 for (; texid < self->texs && count; ++texid, --count) 2001 for (; texid < self->texs && count; ++texid, --count)
1955 { 2002 {
1956 maptex *tex = self->tex + texid; 2003 maptex *tex = self->tex + texid;
1957 2004
1958 if (tex->name) 2005 if (tex->name)
1959 { 2006 {
2006 self->ox += dx; self->x += dx; 2053 self->ox += dx; self->x += dx;
2007 self->oy += dy; self->y += dy; 2054 self->oy += dy; self->y += dy;
2008 2055
2009 while (self->y < 0) 2056 while (self->y < 0)
2010 { 2057 {
2011 Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); 2058 prepend (self->row, self->rows, MAP_EXTEND_Y);
2012 2059
2013 self->rows += MAP_EXTEND_Y; 2060 self->rows += MAP_EXTEND_Y;
2014 self->y += MAP_EXTEND_Y; 2061 self->y += MAP_EXTEND_Y;
2015 } 2062 }
2016} 2063}
2017 2064
2018SV * 2065SV *
2019map1a_update (DC::Map self, SV *data_, int extmap) 2066map1a_update (DC::Map self, SV *data_)
2020 CODE: 2067 CODE:
2021{ 2068{
2022 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 2069 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
2023 uint8_t *data_end = (uint8_t *)SvEND (data_); 2070 uint8_t *data_end = (uint8_t *)SvEND (data_);
2024 mapcell *cell; 2071 mapcell *cell;
2045 2092
2046 //TODO: don't trust server data to be in-range(!) 2093 //TODO: don't trust server data to be in-range(!)
2047 2094
2048 if (flags & 8) 2095 if (flags & 8)
2049 { 2096 {
2097 uint8_t ext, cmd;
2098
2050 if (extmap) 2099 do
2051 { 2100 {
2052 uint8_t ext, cmd; 2101 ext = *data++;
2102 cmd = ext & 0x7f;
2053 2103
2054 do 2104 if (cmd < 4)
2105 cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */
2106 else if (cmd == 5) // health
2055 { 2107 {
2056 ext = *data++;
2057 cmd = ext & 0x7f;
2058
2059 if (cmd < 4)
2060 cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */
2061 else if (cmd == 5) // health
2062 {
2063 cell->stat_width = 1; 2108 cell->stat_width = 1;
2064 cell->stat_hp = *data++; 2109 cell->stat_hp = *data++;
2065 }
2066 else if (cmd == 6) // monster width
2067 cell->stat_width = *data++ + 1;
2068 else if (cmd == 0x47)
2069 {
2070 if (*data == 1) cell->player = data [1];
2071 else if (*data == 2) cell->player = data [2] + (data [1] << 8);
2072 else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16);
2073 else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24);
2074
2075 data += *data + 1;
2076 }
2077 else if (cmd == 8) // cell flags
2078 cell->flags = *data++;
2079 else if (ext & 0x40) // unknown, multibyte => skip
2080 data += *data + 1;
2081 else
2082 data++;
2083 } 2110 }
2084 while (ext & 0x80); 2111 else if (cmd == 6) // monster width
2112 cell->stat_width = *data++ + 1;
2113 else if (cmd == 0x47)
2114 {
2115 if (*data == 1) cell->player = data [1];
2116 else if (*data == 2) cell->player = data [2] + (data [1] << 8);
2117 else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16);
2118 else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24);
2119
2120 data += *data + 1;
2121 }
2122 else if (cmd == 8) // cell flags
2123 cell->flags = *data++;
2124 else if (ext & 0x40) // unknown, multibyte => skip
2125 data += *data + 1;
2126 else
2127 data++;
2085 } 2128 }
2086 else 2129 while (ext & 0x80);
2087 cell->darkness = *data++ + 1;
2088 } 2130 }
2089 2131
2090 for (z = 0; z <= 2; ++z) 2132 for (z = 0; z <= 2; ++z)
2091 if (flags & (4 >> z)) 2133 if (flags & (4 >> z))
2092 { 2134 {
2166 | (b << 16) 2208 | (b << 16)
2167 | (a << 24); 2209 | (a << 24);
2168 } 2210 }
2169 } 2211 }
2170 2212
2171 RETVAL = map_sv; 2213 RETVAL = map_sv;
2172} 2214}
2173 OUTPUT: 2215 OUTPUT:
2174 RETVAL 2216 RETVAL
2175 2217
2176void 2218void
2177draw (DC::Map self, int mx, int my, int sw, int sh, int Tw, int Th, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) 2219draw (DC::Map self, int mx, int my, int sw, int sh, int Tw, int Th, U32 player = 0xffffffff, int sdx = 0, int sdy = 0)
2178 CODE: 2220 CODE:
2179{ 2221{
2180 int x, y, z; 2222 int x, y, z;
2181 2223
2182 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ());
2183 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level
2184 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) 2224 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k), also, static!
2185 smooth_key skey;
2186 int pl_x, pl_y; 2225 int pl_x, pl_y;
2187 maptex pl_tex; 2226 maptex pl_tex;
2188 rc_t *rc = rc_alloc (); 2227 rc_t rc;
2189 rc_t *rc_ov = rc_alloc (); 2228 rc_t rc_ov;
2190 rc_key_t key; 2229 rc_key_t key;
2191 rc_array_t *arr; 2230 rc_t::array_t *arr;
2192 2231
2193 pl_tex.name = 0; 2232 pl_tex.name = 0;
2194 2233
2195 // that's current max. sorry. 2234 // that's current max. sorry.
2196 if (sw > 255) sw = 255; 2235 if (sw > 255) sw = 255;
2197 if (sh > 255) sh = 255; 2236 if (sh > 255) sh = 255;
2198
2199 // clear key, in case of extra padding
2200 memset (&skey, 0, sizeof (skey));
2201 2237
2202 memset (&key, 0, sizeof (key)); 2238 memset (&key, 0, sizeof (key));
2203 key.r = 255; 2239 key.r = 255;
2204 key.g = 255; 2240 key.g = 255;
2205 key.b = 255; 2241 key.b = 255;
2211 my += self->y; 2247 my += self->y;
2212 2248
2213 // first pass: determine smooth_max 2249 // first pass: determine smooth_max
2214 // rather ugly, if you ask me 2250 // rather ugly, if you ask me
2215 // could also be stored inside mapcell and updated on change 2251 // could also be stored inside mapcell and updated on change
2216 memset (smooth_max, 0, sizeof (smooth_max)); 2252 memset (smooth_max, 0, sizeof (smooth_max[0]) * (sh + 1));
2217 2253
2218 for (y = 0; y < sh; y++) 2254 for (y = 0; y < sh; y++)
2219 if (0 <= y + my && y + my < self->rows) 2255 if (0 <= y + my && y + my < self->rows)
2220 { 2256 {
2221 maprow *row = self->row + (y + my); 2257 maprow *row = self->row + (y + my);
2236 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2272 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2237 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 2273 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
2238 2274
2239 for (z = 0; z <= 2; z++) 2275 for (z = 0; z <= 2; z++)
2240 { 2276 {
2241 memset (smooth_level, 0, sizeof (smooth_level)); 2277 std::bitset<256> smooth_level; // one bit for every possible smooth level
2278 smooth_key skey;
2279 smooth_hash smooth;
2242 key.texname = -1; 2280 key.texname = -1;
2243 2281
2244 for (y = 0; y < sh; y++) 2282 for (y = 0; y < sh; y++)
2245 if (0 <= y + my && y + my < self->rows) 2283 if (0 <= y + my && y + my < self->rows)
2246 { 2284 {
2263 2301
2264 if (!tex.name) 2302 if (!tex.name)
2265 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ 2303 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */
2266 2304
2267 key.texname = tex.name; 2305 key.texname = tex.name;
2268 arr = rc_array (rc, &key); 2306 arr = &rc.array (key);
2269 } 2307 }
2270 2308
2271 px = (x + 1) * Th - tex.w; 2309 px = (x + 1) * Th - tex.w;
2272 py = (y + 1) * Tw - tex.h; 2310 py = (y + 1) * Tw - tex.h;
2273 2311
2277 pl_y = py; 2315 pl_y = py;
2278 pl_tex = tex; 2316 pl_tex = tex;
2279 continue; 2317 continue;
2280 } 2318 }
2281 2319
2282 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2320 arr->t2f_v3f (0 , 0 , px , py , 0);
2283 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2321 arr->t2f_v3f (0 , tex.t, px , py + tex.h, 0);
2284 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); 2322 arr->t2f_v3f (tex.s, tex.t, px + tex.w, py + tex.h, 0);
2285 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); 2323 arr->t2f_v3f (tex.s, 0 , px + tex.w, py , 0);
2286 2324
2287 // update smooth hash 2325 // update smooth hash
2288 if (tex.smoothtile) 2326 if (tex.smoothtile)
2289 { 2327 {
2290 skey.tile = tex.smoothtile; 2328 skey.tile = tex.smoothtile;
2291 skey.level = tex.smoothlevel; 2329 skey.level = tex.smoothlevel;
2292 2330
2293 smooth_level [tex.smoothlevel >> 5] |= ((uint32_t)1) << (tex.smoothlevel & 31); 2331 smooth_level[tex.smoothlevel] = 1;
2294 2332
2295 // add bits to current tile and all neighbours. skey.x|y is 2333 // add bits to current tile and all neighbours. skey.x|y is
2296 // shifted +1|+1 so we always stay positive. 2334 // shifted +1|+1 so we always stay positive.
2297 2335
2298 // bits is ___n cccc CCCC bbbb 2336 // bits is ___n cccc CCCC bbbb
2306 2344
2307 // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· 2345 // corners: 1 ┛· 2 ·┗ 4 ·· 8 ··
2308 // ·· ·· ·┏ ┓· 2346 // ·· ·· ·┏ ┓·
2309 2347
2310 // full tile 2348 // full tile
2311 skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x1000); 2349 skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x1000);
2312 2350
2313 // borders 2351 // borders
2314 skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0091); 2352 skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0091);
2315 skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0032); 2353 skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0032);
2316 skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0064); 2354 skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0064);
2317 skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, &skey, 0x00c8); 2355 skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, skey, 0x00c8);
2318 2356
2319 // corners 2357 // corners
2320 skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0100); 2358 skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0100);
2321 skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0200); 2359 skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0200);
2322 skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400); 2360 skey.x = x ; skey.y = y ; smooth_or_bits (smooth, skey, 0x0400);
2323 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); 2361 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, skey, 0x0800);
2324 } 2362 }
2325 } 2363 }
2326 2364
2327 if (expect_false (z == 2) && expect_false (cell->flags)) 2365 if (expect_false (z == 2) && expect_false (cell->flags))
2328 { 2366 {
2329 // overlays such as the speech bubble, probably more to come 2367 // overlays such as the speech bubble, probably more to come
2330 if (cell->flags & 1) 2368 if (cell->flags & 1)
2331 { 2369 {
2332 rc_key_t key_ov = key; 2370 rc_key_t key_ov = key;
2333 maptex tex = self->tex [TEXID_SPEECH]; 2371 maptex tex = self->tex[TEXID_SPEECH];
2334 rc_array_t *arr;
2335 int px = x * Tw + Tw * 2 / 32; 2372 int px = x * Tw + Tw * 2 / 32;
2336 int py = y * Th - Th * 6 / 32; 2373 int py = y * Th - Th * 6 / 32;
2337 2374
2338 key_ov.texname = tex.name; 2375 key_ov.texname = tex.name;
2339 arr = rc_array (rc_ov, &key_ov); 2376 rc_t::array_t &arr = rc_ov.array (key_ov);
2340 2377
2341 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2378 arr.t2f_v3f (0 , 0 , px , py , 0);
2342 rc_t2f_v3f (arr, 0 , tex.t, px , py + Th, 0); 2379 arr.t2f_v3f (0 , tex.t, px , py + Th, 0);
2343 rc_t2f_v3f (arr, tex.s, tex.t, px + Tw, py + Th, 0); 2380 arr.t2f_v3f (tex.s, tex.t, px + Tw, py + Th, 0);
2344 rc_t2f_v3f (arr, tex.s, 0 , px + Tw, py , 0); 2381 arr.t2f_v3f (tex.s, 0 , px + Tw, py , 0);
2345 } 2382 }
2346 } 2383 }
2347 } 2384 }
2348 } 2385 }
2349 2386
2350 rc_draw (rc); 2387 rc.draw ();
2351 rc_clear (rc); 2388 rc.clear ();
2352 2389
2353 // go through all smoothlevels, lowest to highest, then draw. 2390 // go through all smoothlevels, lowest to highest, then draw.
2354 // this is basically counting sort 2391 // this is basically counting sort
2355 { 2392 {
2356 int w, b; 2393 int w, b;
2357 2394
2358 glEnable (GL_TEXTURE_2D); 2395 glEnable (GL_TEXTURE_2D);
2359 glBegin (GL_QUADS); 2396 glBegin (GL_QUADS);
2360 for (w = 0; w < 256 / 32; ++w) 2397 for (int level = 0; level < smooth_level.size (); ++level)
2398 if (smooth_level[level])
2399 for (auto &&it = smooth.begin (); it != smooth.end (); ++it)
2361 { 2400 {
2362 uint32_t smask = smooth_level [w]; 2401 smooth_key &skey = it->first;
2363 if (smask) 2402 IV bits = it->second;
2364 for (b = 0; b < 32; ++b) 2403
2365 if (smask & (((uint32_t)1) << b)) 2404 if (!(bits & 0x1000)
2405 && skey.level == level
2406 && level > smooth_max [skey.x][skey.y])
2366 { 2407 {
2367 int level = (w << 5) | b; 2408 maptex tex = self->tex [skey.tile];
2409 int px = (((int)skey.x) - 1) * Tw;
2410 int py = (((int)skey.y) - 1) * Th;
2411 int border = bits & 15;
2412 int corner = (bits >> 8) & ~(bits >> 4) & 15;
2413 float dx = tex.s * .0625f; // 16 images/row
2414 float dy = tex.t * .5f ; // 2 images/column
2415
2368 HE *he; 2416 if (tex.name)
2369
2370 hv_iterinit (smooth);
2371 while ((he = hv_iternext (smooth)))
2372 { 2417 {
2373 smooth_key *skey = (smooth_key *)HeKEY (he); 2418 // this time avoiding texture state changes
2374 IV bits = SvIVX (HeVAL (he)); 2419 // save gobs of state changes.
2375 2420 if (key.texname != tex.name)
2376 if (!(bits & 0x1000)
2377 && skey->level == level
2378 && level > smooth_max [skey->x][skey->y])
2379 { 2421 {
2380 maptex tex = self->tex [skey->tile];
2381 int px = (((int)skey->x) - 1) * Tw;
2382 int py = (((int)skey->y) - 1) * Th;
2383 int border = bits & 15;
2384 int corner = (bits >> 8) & ~(bits >> 4) & 15;
2385 float dx = tex.s * .0625f; // 16 images/row
2386 float dy = tex.t * .5f ; // 2 images/column
2387
2388 if (tex.name)
2389 {
2390 // this time avoiding texture state changes
2391 // save gobs of state changes.
2392 if (key.texname != tex.name)
2393 {
2394 self->tex [skey->tile].unused = 0; 2422 self->tex [skey.tile].unused = 0;
2395 2423
2396 glEnd (); 2424 glEnd ();
2397 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); 2425 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name);
2398 glBegin (GL_QUADS); 2426 glBegin (GL_QUADS);
2399 } 2427 }
2400 2428
2401 if (border) 2429 if (border)
2402 { 2430 {
2403 float ox = border * dx; 2431 float ox = border * dx;
2404 2432
2405 glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); 2433 glTexCoord2f (ox , 0.f ); glVertex2i (px , py );
2406 glTexCoord2f (ox , dy ); glVertex2i (px , py + Th); 2434 glTexCoord2f (ox , dy ); glVertex2i (px , py + Th);
2407 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); 2435 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th);
2408 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); 2436 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py );
2409 } 2437 }
2410 2438
2411 if (corner) 2439 if (corner)
2412 { 2440 {
2413 float ox = corner * dx; 2441 float ox = corner * dx;
2414 2442
2415 glTexCoord2f (ox , dy ); glVertex2i (px , py ); 2443 glTexCoord2f (ox , dy ); glVertex2i (px , py );
2416 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th); 2444 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th);
2417 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th); 2445 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th);
2418 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py ); 2446 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py );
2419 }
2420 }
2421 } 2447 }
2422 } 2448 }
2423 } 2449 }
2424 } 2450 }
2425 2451
2426 glEnd (); 2452 glEnd ();
2427 glDisable (GL_TEXTURE_2D); 2453 glDisable (GL_TEXTURE_2D);
2428 key.texname = -1; 2454 key.texname = -1;
2429 } 2455 }
2430
2431 hv_clear (smooth);
2432 } 2456 }
2433 2457
2434 if (pl_tex.name) 2458 if (pl_tex.name)
2435 { 2459 {
2436 maptex tex = pl_tex; 2460 maptex tex = pl_tex;
2437 int px = pl_x + sdx; 2461 int px = pl_x + sdx;
2438 int py = pl_y + sdy; 2462 int py = pl_y + sdy;
2439 2463
2440 key.texname = tex.name; 2464 key.texname = tex.name;
2441 arr = rc_array (rc, &key); 2465 rc_t::array_t &arr = rc.array (key);
2442 2466
2443 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2467 arr.t2f_v3f (0 , 0 , px , py , 0);
2444 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2468 arr.t2f_v3f (0 , tex.t, px , py + tex.h, 0);
2445 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); 2469 arr.t2f_v3f (tex.s, tex.t, px + tex.w, py + tex.h, 0);
2446 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); 2470 arr.t2f_v3f (tex.s, 0 , px + tex.w, py , 0);
2447 2471
2448 rc_draw (rc); 2472 rc.draw ();
2449 } 2473 }
2450 2474
2451 rc_draw (rc_ov); 2475 rc_ov.draw ();
2452 rc_clear (rc_ov); 2476 rc_ov.clear ();
2453 2477
2454 glDisable (GL_BLEND); 2478 glDisable (GL_BLEND);
2455 rc_free (rc);
2456 rc_free (rc_ov);
2457 2479
2458 // top layer: overlays such as the health bar 2480 // top layer: overlays such as the health bar
2459 for (y = 0; y < sh; y++) 2481 for (y = 0; y < sh; y++)
2460 if (0 <= y + my && y + my < self->rows) 2482 if (0 <= y + my && y + my < self->rows)
2461 { 2483 {
2705 else 2727 else
2706 *data++ = 0; 2728 *data++ = 0;
2707 } 2729 }
2708 } 2730 }
2709 2731
2710 /* if size is w*h + 5 then no data has been found */ 2732 /* if size is w*h + 5 then no data has been found */
2711 if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) 2733 if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5)
2712 { 2734 {
2713 SvPOK_only (data_sv); 2735 SvPOK_only (data_sv);
2714 SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); 2736 SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv));
2715 } 2737 }
2716 2738
2717 RETVAL = data_sv; 2739 RETVAL = data_sv;
2718} 2740}
2719 OUTPUT: 2741 OUTPUT:
2720 RETVAL 2742 RETVAL
2721 2743
2722void 2744void
2729 STRLEN len; 2751 STRLEN len;
2730 uint8_t *data, *end; 2752 uint8_t *data, *end;
2731 2753
2732 len = SvLEN (data_sv); 2754 len = SvLEN (data_sv);
2733 SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more 2755 SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more
2734 data = SvPVbyte_nolen (data_sv); 2756 data = (uint8_t *)SvPVbyte_nolen (data_sv);
2735 end = data + len + 8; 2757 end = data + len + 8;
2736 2758
2737 if (len < 5) 2759 if (len < 5)
2738 XSRETURN_EMPTY; 2760 XSRETURN_EMPTY;
2739 2761
2800} 2822}
2801 2823
2802MODULE = Deliantra::Client PACKAGE = DC::RW 2824MODULE = Deliantra::Client PACKAGE = DC::RW
2803 2825
2804DC::RW 2826DC::RW
2805new (SV *class, SV *data_sv) 2827new (SV *klass, SV *data_sv)
2806 CODE: 2828 CODE:
2807{ 2829{
2808 STRLEN datalen; 2830 STRLEN datalen;
2809 char *data = SvPVbyte (data_sv, datalen); 2831 char *data = SvPVbyte (data_sv, datalen);
2810 2832
2812} 2834}
2813 OUTPUT: 2835 OUTPUT:
2814 RETVAL 2836 RETVAL
2815 2837
2816DC::RW 2838DC::RW
2817new_from_file (SV *class, const char *path, const char *mode = "rb") 2839new_from_file (SV *klass, const char *path, const char *mode = "rb")
2818 CODE: 2840 CODE:
2819 RETVAL = SDL_RWFromFile (path, mode); 2841 RETVAL = SDL_RWFromFile (path, mode);
2820 OUTPUT: 2842 OUTPUT:
2821 RETVAL 2843 RETVAL
2822 2844
2931#else 2953#else
2932 XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); 2954 XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0)));
2933#endif 2955#endif
2934 2956
2935DC::MixChunk 2957DC::MixChunk
2936new (SV *class, DC::RW rwops) 2958new (SV *klass, DC::RW rwops)
2937 CODE: 2959 CODE:
2938 RETVAL = Mix_LoadWAV_RW (rwops, 1); 2960 RETVAL = Mix_LoadWAV_RW (rwops, 1);
2939 OUTPUT: 2961 OUTPUT:
2940 RETVAL 2962 RETVAL
2941 2963
3011 RETVAL = Mix_PlayingMusic (); 3033 RETVAL = Mix_PlayingMusic ();
3012 OUTPUT: 3034 OUTPUT:
3013 RETVAL 3035 RETVAL
3014 3036
3015DC::MixMusic 3037DC::MixMusic
3016new (SV *class, DC::RW rwops) 3038new (SV *klass, DC::RW rwops)
3017 CODE: 3039 CODE:
3018 RETVAL = Mix_LoadMUS_RW (rwops); 3040 RETVAL = Mix_LoadMUS_RW (rwops);
3019 OUTPUT: 3041 OUTPUT:
3020 RETVAL 3042 RETVAL
3021 3043
3158 const_iv (GL_FUNC_SUBTRACT), 3180 const_iv (GL_FUNC_SUBTRACT),
3159 const_iv (GL_FUNC_REVERSE_SUBTRACT), 3181 const_iv (GL_FUNC_REVERSE_SUBTRACT),
3160# undef const_iv 3182# undef const_iv
3161 }; 3183 };
3162 3184
3163 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 3185 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
3164 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 3186 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
3165 3187
3166 texture_av = newAV (); 3188 texture_av = newAV ();
3167 AvREAL_off (texture_av); 3189 AvREAL_off (texture_av);
3168} 3190}
3169 3191
3174 gl.BlendFuncSeparateEXT = 0; 3196 gl.BlendFuncSeparateEXT = 0;
3175 3197
3176void 3198void
3177apple_nvidia_bug (int enable) 3199apple_nvidia_bug (int enable)
3178 3200
3179char * 3201const char *
3180gl_vendor () 3202gl_vendor ()
3181 CODE: 3203 CODE:
3182 RETVAL = (char *)glGetString (GL_VENDOR); 3204 RETVAL = (const char *)glGetString (GL_VENDOR);
3183 OUTPUT: 3205 OUTPUT:
3184 RETVAL 3206 RETVAL
3185 3207
3186char * 3208const char *
3187gl_version () 3209gl_version ()
3188 CODE: 3210 CODE:
3189 RETVAL = (char *)glGetString (GL_VERSION); 3211 RETVAL = (const char *)glGetString (GL_VERSION);
3190 OUTPUT: 3212 OUTPUT:
3191 RETVAL 3213 RETVAL
3192 3214
3193char * 3215const char *
3194gl_extensions () 3216gl_extensions ()
3195 CODE: 3217 CODE:
3196 RETVAL = (char *)glGetString (GL_EXTENSIONS); 3218 RETVAL = (const char *)glGetString (GL_EXTENSIONS);
3197 OUTPUT: 3219 OUTPUT:
3198 RETVAL 3220 RETVAL
3199 3221
3200const char *glGetString (GLenum pname) 3222const char *glGetString (GLenum pname)
3223 CODE:
3224 RETVAL = (const char *)glGetString (pname);
3225 OUTPUT:
3226 RETVAL
3201 3227
3202GLint glGetInteger (GLenum pname) 3228GLint glGetInteger (GLenum pname)
3203 CODE: 3229 CODE:
3204 glGetIntegerv (pname, &RETVAL); 3230 glGetIntegerv (pname, &RETVAL);
3205 OUTPUT: 3231 OUTPUT:
3408 3434
3409void 3435void
3410find_widget (SV *self, NV x, NV y) 3436find_widget (SV *self, NV x, NV y)
3411 PPCODE: 3437 PPCODE:
3412{ 3438{
3413 if (within_widget (self, x, y)) 3439 if (within_widget (self, x, y))
3414 XPUSHs (self); 3440 XPUSHs (self);
3415} 3441}
3416 3442
3417BOOT: 3443BOOT:
3418{ 3444{
3426 3452
3427void 3453void
3428draw (SV *self) 3454draw (SV *self)
3429 CODE: 3455 CODE:
3430{ 3456{
3431 HV *hv; 3457 HV *hv;
3432 SV **svp; 3458 SV **svp;
3433 NV x, y, w, h; 3459 NV x, y, w, h;
3434 SV *draw_x_sv = GvSV (draw_x_gv); 3460 SV *draw_x_sv = GvSV (draw_x_gv);
3435 SV *draw_y_sv = GvSV (draw_y_gv); 3461 SV *draw_y_sv = GvSV (draw_y_gv);
3436 SV *draw_w_sv = GvSV (draw_w_gv); 3462 SV *draw_w_sv = GvSV (draw_w_gv);
3437 SV *draw_h_sv = GvSV (draw_h_gv); 3463 SV *draw_h_sv = GvSV (draw_h_gv);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines