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.280 by root, Wed Nov 26 23:08:34 2008 UTC vs.
Revision 1.323 by root, Sun Nov 18 01:48:39 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 roundf(x) (int)(x)
25# define atan2f(x,y) atan2(x,y) 26# define atan2f(x,y) atan2(x,y)
26# define M_PI 3.14159265f 27# define M_PI 3.14159265f
27#endif 28#endif
28 29
29#include <assert.h> 30#include <cassert>
30#include <math.h> 31#include <cmath>
31#include <string.h> 32#include <cstring>
32#include <stdio.h> 33#include <cstdio>
33#include <stdlib.h> 34#include <cstdlib>
35
36#include <utility>
34 37
35#define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW 38#define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW
36 39
37#include <SDL.h> 40#include <SDL.h>
38#include <SDL_thread.h> 41#include <SDL_thread.h>
42#include <SDL_opengl.h> 45#include <SDL_opengl.h>
43 46
44/* work around os x broken headers */ 47/* work around os x broken headers */
45#ifdef __MACOSX__ 48#ifdef __MACOSX__
46typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); 49typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
50typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture);
51typedef void (APIENTRYP PFNGLMULTITEXCOORD2FPROC) (GLenum target, GLfloat s, GLfloat t);
47#endif 52#endif
48 53
49#define PANGO_ENABLE_BACKEND 54#define PANGO_ENABLE_BACKEND
50#define G_DISABLE_CAST_CHECKS 55#define G_DISABLE_CAST_CHECKS
51 56
52#include <glib/gmacros.h> 57#include <glib.h>
53 58
54#include <pango/pango.h> 59#include <pango/pango.h>
55 60
56#ifndef PANGO_VERSION_CHECK 61#ifndef PANGO_VERSION_CHECK
57# define PANGO_VERSION_CHECK(a,b,c) 0 62# define PANGO_VERSION_CHECK(a,b,c) 0
81#define expect_false(expr) expect ((expr) != 0, 0) 86#define expect_false(expr) expect ((expr) != 0, 0)
82#define expect_true(expr) expect ((expr) != 0, 1) 87#define expect_true(expr) expect ((expr) != 0, 1)
83 88
84#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ 89#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */
85 90
91/* this is used as fow flag as well, so has to have a different value */
92/* then anything that is computed by incoming darkness */
86#define FOW_DARKNESS 32 93#define FOW_DARKNESS 50
94#define DARKNESS_ADJUST(n) (n)
87 95
88#define MAP_EXTEND_X 32 96#define MAP_EXTEND_X 32
89#define MAP_EXTEND_Y 512 97#define MAP_EXTEND_Y 512
90 98
91#define MIN_FONT_HEIGHT 10 99#define MIN_FONT_HEIGHT 10
92 100
93/* mask out modifiers we are not interested in */ 101/* mask out modifiers we are not interested in */
94#define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META) 102#define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META)
95 103
96#define KMOD_LRAM 0x10000 // our extension 104#define KMOD_LRAM 0x10000 // our extension
105
106#define TEXID_SPEECH 1
107#define TEXID_NOFACE 2
108
109static char *
110fast_sv_grow (SV *sv, STRLEN need)
111{
112 STRLEN len = SvLEN (sv);
113 STRLEN want = SvCUR (sv) + need;
114
115 if (expect_false (len < want))
116 {
117 do
118 len *= 2;
119 while (len < want);
120
121 sv_grow (sv, len);
122 }
123
124 SvCUR_set (sv, want);
125 return SvEND (sv) - need;
126}
97 127
98static AV *texture_av; 128static AV *texture_av;
99 129
100static struct 130static struct
101{ 131{
158{ 188{
159 GSList *attrs = run->item->analysis.extra_attrs; 189 GSList *attrs = run->item->analysis.extra_attrs;
160 190
161 while (attrs) 191 while (attrs)
162 { 192 {
163 PangoAttribute *attr = attrs->data; 193 PangoAttribute *attr = (PangoAttribute *)attrs->data;
164 194
165 if (attr->klass->type == PANGO_ATTR_SHAPE) 195 if (attr->klass->type == PANGO_ATTR_SHAPE)
166 return 1; 196 return 1;
167 197
168 attrs = attrs->next; 198 attrs = attrs->next;
169 } 199 }
170 200
171 return 0; 201 return 0;
172} 202}
173 203
174typedef struct cf_layout { 204struct cf_layout {
175 PangoLayout *pl; 205 PangoLayout *pl;
176 float r, g, b, a; // default color for rgba mode 206 float r, g, b, a; // default color for rgba mode
177 int base_height; 207 int base_height;
178 DC__Font font; 208 DC__Font font;
179 rc_t *rc; 209 rc_t *rc;
180} *DC__Layout; 210};
211
212typedef cf_layout *DC__Layout;
181 213
182static DC__Font default_font; 214static DC__Font default_font;
183static PangoContext *opengl_context; 215static PangoContext *opengl_context;
184static PangoFontMap *opengl_fontmap; 216static PangoFontMap *opengl_fontmap;
185 217
186static void 218static void
187substitute_func (FcPattern *pattern, gpointer data) 219substitute_func (FcPattern *pattern, gpointer data)
188{ 220{
189 FcPatternAddBool (pattern, FC_HINTING, 1); 221 FcPatternAddBool (pattern, FC_HINTING, 1);
190#ifdef FC_HINT_STYLE 222#ifdef FC_HINT_STYLE
191 FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); 223 FcPatternAddInteger (pattern, FC_HINT_STYLE, FC_HINT_FULL);
192#endif 224#endif
193 FcPatternAddBool (pattern, FC_AUTOHINT, 0); 225 FcPatternAddBool (pattern, FC_AUTOHINT, 0);
194} 226}
195 227
196static void 228static void
226} 258}
227 259
228typedef uint16_t tileid; 260typedef uint16_t tileid;
229typedef uint16_t faceid; 261typedef uint16_t faceid;
230 262
231typedef struct { 263struct maptex
264{
232 GLuint name; 265 GLuint name;
233 int w, h; 266 int w, h;
234 float s, t; 267 float s, t;
235 uint8_t r, g, b, a; 268 uint8_t r, g, b, a;
236 tileid smoothtile; 269 tileid smoothtile;
237 uint8_t smoothlevel; 270 uint8_t smoothlevel;
238 uint8_t unused; /* set to zero on use */ 271 uint8_t unused; /* set to zero on use */
239} maptex; 272};
240 273
241typedef struct { 274struct mapcell
275{
242 uint32_t player; 276 uint32_t player;
243 tileid tile[3]; 277 tileid tile[3];
244 uint16_t darkness; 278 uint16_t darkness;
245 uint8_t stat_width, stat_hp, flags, smoothmax; 279 uint8_t stat_width, stat_hp, flags, smoothmax;
246} mapcell; 280};
247 281
248typedef struct { 282struct maprow
283{
249 int32_t c0, c1; 284 int32_t c0, c1;
250 mapcell *col; 285 mapcell *col;
251} maprow; 286};
252 287
253typedef struct map { 288struct mapgrid {
254 int x, y, w, h; 289 int x, y, w, h;
255 int ox, oy; /* offset to virtual global coordinate system */ 290 int ox, oy; /* offset to virtual global coordinate system */
256 int faces; tileid *face2tile; // [faceid] 291 int faces; tileid *face2tile; // [faceid]
257 int texs; maptex *tex; // [tileid] 292 int texs; maptex *tex; // [tileid]
258 293
259 int32_t rows; 294 int32_t rows;
260 maprow *row; 295 maprow *row;
261} *DC__Map; 296};
297
298typedef mapgrid *DC__Map;
262 299
263static char * 300static char *
264prepend (char *ptr, int sze, int inc) 301prepend (char *ptr, int sze, int inc)
265{ 302{
266 char *p; 303 char *p;
284 321
285#define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) 322#define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
286#define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) 323#define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
287 324
288static void 325static void
289need_facenum (struct map *self, faceid face) 326need_facenum (struct mapgrid *self, faceid face)
290{ 327{
291 while (self->faces <= face) 328 while (self->faces <= face)
292 { 329 {
293 Append (tileid, self->face2tile, self->faces, self->faces); 330 Append (tileid, self->face2tile, self->faces, self->faces);
294 self->faces *= 2; 331 self->faces *= 2;
295 } 332 }
296} 333}
297 334
298static void 335static void
299need_texid (struct map *self, int texid) 336need_texid (struct mapgrid *self, int texid)
300{ 337{
301 while (self->texs <= texid) 338 while (self->texs <= texid)
302 { 339 {
303 Append (maptex, self->tex, self->texs, self->texs); 340 Append (maptex, self->tex, self->texs, self->texs);
304 self->texs *= 2; 341 self->texs *= 2;
305 } 342 }
306} 343}
307 344
308static maprow * 345static maprow *
309map_get_row (DC__Map self, int y) 346map_get_row (mapgrid *self, int y)
310{ 347{
311 if (0 > y) 348 if (0 > y)
312 { 349 {
313 int extend = - y + MAP_EXTEND_Y; 350 int extend = - y + MAP_EXTEND_Y;
314 Prepend (maprow, self->row, self->rows, extend); 351 Prepend (maprow, self->row, self->rows, extend);
352 389
353 return row->col + (x - row->c0); 390 return row->col + (x - row->c0);
354} 391}
355 392
356static mapcell * 393static mapcell *
357map_get_cell (DC__Map self, int x, int y) 394map_get_cell (mapgrid *self, int x, int y)
358{ 395{
359 return row_get_cell (map_get_row (self, y), x); 396 return row_get_cell (map_get_row (self, y), x);
360} 397}
361 398
362static void 399static void
363map_clear (DC__Map self) 400map_clear (mapgrid *self)
364{ 401{
365 int r; 402 int r;
366 403
367 for (r = 0; r < self->rows; r++) 404 for (r = 0; r < self->rows; r++)
368 Safefree (self->row[r].col); 405 Safefree (self->row[r].col);
386 (cell)->flags = 0; \ 423 (cell)->flags = 0; \
387 (cell)->player = 0; \ 424 (cell)->player = 0; \
388 } while (0) 425 } while (0)
389 426
390static void 427static void
391map_blank (DC__Map self, int x0, int y0, int w, int h) 428map_blank (mapgrid *self, int x0, int y0, int w, int h)
392{ 429{
393 int x, y; 430 int x, y;
394 maprow *row; 431 maprow *row;
395 mapcell *cell; 432 mapcell *cell;
396 433
413 CELL_CLEAR (cell); 450 CELL_CLEAR (cell);
414 } 451 }
415 } 452 }
416} 453}
417 454
418typedef struct { 455struct smooth_key
456{
419 tileid tile; 457 tileid tile;
420 uint8_t x, y, level; 458 uint8_t x, y, level;
421} smooth_key; 459
460 bool operator == (const smooth_key &o) const
461 {
462 return tile == o.tile && x == o.x && y == o.y && level == o.level;
463 }
464};
465
466typedef ska::flat_hash_map<smooth_key, IV> smooth_hash;
467
468namespace std {
469 template <>
470 struct hash<smooth_key>
471 {
472 size_t operator () (const smooth_key &v) const
473 {
474 return v.tile + (v.x << 8) + (v.y << 16) + (v.level << 24);
475 }
476 };
477}
422 478
423static void 479static void
424smooth_or_bits (HV *hv, smooth_key *key, IV bits) 480smooth_or_bits (smooth_hash &h, smooth_key &key, IV bits)
425{ 481{
426 SV **sv = hv_fetch (hv, (char *)key, sizeof (*key), 1); 482 auto &&it = h.find (key);
427 483
428 if (SvIOK (*sv)) 484 if (it == h.end ())
429 SvIV_set (*sv, SvIVX (*sv) | bits); 485 h.insert (std::make_pair (key, bits));
430 else 486 else
431 sv_setiv (*sv, bits); 487 it->second |= bits;
432} 488}
433 489
434static void 490static void
435music_finished (void) 491music_finished (void)
436{ 492{
453 ev.code = 1; 509 ev.code = 1;
454 ev.data1 = (void *)(long)channel; 510 ev.data1 = (void *)(long)channel;
455 ev.data2 = 0; 511 ev.data2 = 0;
456 512
457 SDL_PushEvent ((SDL_Event *)&ev); 513 SDL_PushEvent ((SDL_Event *)&ev);
514}
515
516// approximately divide by 255
517static unsigned int
518div255 (unsigned int n)
519{
520 return (n + (n >> 8)) >> 8;
458} 521}
459 522
460static unsigned int 523static unsigned int
461minpot (unsigned int n) 524minpot (unsigned int n)
462{ 525{
545 608
546 return mod; 609 return mod;
547} 610}
548 611
549static void 612static void
550deliantra_main () 613deliantra_main (SV *real_main)
551{ 614{
552 char *argv[] = { 0 }; 615 dSP;
553 call_argv ("::main", G_DISCARD | G_VOID, argv); 616
617 PUSHMARK (SP);
618 call_sv (real_main, G_DISCARD | G_VOID);
554} 619}
555 620
556#ifdef __MACOSX__ 621#ifdef __MACOSX__
622 static SV *real_main;
623
557 /* to due surprising braindamage on the side of SDL design, we 624 /* to due surprising braindamage on the side of SDL design, we
558 * do some mind-boggling hack here: SDL requires a custom main() 625 * do some mind-boggling hack here: SDL requires a custom main()
559 * on OS X, so... we provide one and call the original main(), which, 626 * on OS X, so... we provide one and call the original main(), which,
560 * due to share dlibrary magic, calls -lSDLmain's main, not perl's main, 627 * due to shared library magic, calls -lSDLmain's main, not perl's main,
561 * and which calls our main (== SDL_main) back. 628 * and which calls our main (== SDL_main) back.
562 */ 629 */
563 extern C_LINKAGE int 630 extern C_LINKAGE int
564 main (int argc, char *argv[]) 631 main (int argc, char *argv[])
565 { 632 {
566 deliantra_main (); 633 deliantra_main (real_main);
567 } 634 }
568 635
569 #undef main 636 #undef main
570 637
571 extern C_LINKAGE int main (int argc, char *argv[]); 638 extern C_LINKAGE int main (int argc, char *argv[]);
572 639
573 static void 640 static void
574 SDL_braino (void) 641 SDL_main_hack (SV *real_main_)
575 { 642 {
643 real_main = real_main_;
644
576 char *argv[] = { "deliantra client", 0 }; 645 char *argv[] = { "deliantra client", 0 };
577 (main) (1, argv); 646 (main) (1, argv);
578 } 647 }
579#else 648#else
580 static void 649 static void
581 SDL_braino (void) 650 SDL_main_hack (SV *real_main)
582 { 651 {
583 deliantra_main (); 652 deliantra_main (real_main);
584 } 653 }
585#endif 654#endif
586 655
587MODULE = Deliantra::Client PACKAGE = DC 656MODULE = Deliantra::Client PACKAGE = DC
588 657
789 858
790 const_iv (FOW_DARKNESS) 859 const_iv (FOW_DARKNESS)
791# undef const_iv 860# undef const_iv
792 }; 861 };
793 862
794 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 863 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
795 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 864 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
796 865
797 assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK); 866 assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK);
798 assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE); 867 assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE);
799} 868}
800 869
816NV ceil (NV x) 885NV ceil (NV x)
817 886
818IV minpot (UV n) 887IV minpot (UV n)
819 888
820IV popcount (UV n) 889IV popcount (UV n)
890
891NV distance (NV dx, NV dy)
892 CODE:
893 RETVAL = pow (dx * dx + dy * dy, 0.5);
894 OUTPUT:
895 RETVAL
821 896
822void 897void
823pango_init () 898pango_init ()
824 CODE: 899 CODE:
825{ 900{
833#endif 908#endif
834} 909}
835 910
836char *SDL_GetError () 911char *SDL_GetError ()
837 912
838void SDL_braino () 913void SDL_main_hack (SV *real_main)
914 PROTOTYPE: &
839 915
840int SDL_Init (U32 flags) 916int SDL_Init (U32 flags)
841 917
842int SDL_InitSubSystem (U32 flags) 918int SDL_InitSubSystem (U32 flags)
843 919
844void SDL_QuitSubSystem (U32 flags) 920void SDL_QuitSubSystem (U32 flags)
845 921
846void SDL_Quit () 922void SDL_Quit ()
847 923
848int SDL_GL_SetAttribute (int attr, int value) 924int SDL_GL_SetAttribute (int attr, int value)
925 C_ARGS: (SDL_GLattr)attr, value
849 926
850int SDL_GL_GetAttribute (int attr) 927int SDL_GL_GetAttribute (int attr)
851 CODE: 928 CODE:
852 if (SDL_GL_GetAttribute (attr, &RETVAL)) 929 if (SDL_GL_GetAttribute ((SDL_GLattr)attr, &RETVAL))
853 XSRETURN_UNDEF; 930 XSRETURN_UNDEF;
854 OUTPUT: 931 OUTPUT:
855 RETVAL 932 RETVAL
856 933
857void 934void
912 ); 989 );
913 990
914 if (RETVAL) 991 if (RETVAL)
915 { 992 {
916 av_clear (texture_av); 993 av_clear (texture_av);
917
918 SDL_WM_SetCaption ("Deliantra MORPG Client " VERSION, "Deliantra");
919#define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); 994#define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name);
920#include "glfunc.h" 995#include "glfunc.h"
921#undef GL_FUNC 996#undef GL_FUNC
997 if (!gl.ActiveTexture ) gl.ActiveTexture = gl.ActiveTextureARB;
998 if (!gl.MultiTexCoord2f) gl.MultiTexCoord2f = gl.MultiTexCoord2fARB;
922 } 999 }
923} 1000}
924 OUTPUT: 1001 OUTPUT:
925 RETVAL 1002 RETVAL
1003
1004void
1005SDL_WM_SetCaption (const char *title, const char *icon)
926 1006
927void 1007void
928SDL_GL_SwapBuffers () 1008SDL_GL_SwapBuffers ()
929 1009
930char * 1010char *
931SDL_GetKeyName (int sym) 1011SDL_GetKeyName (int sym)
1012 C_ARGS: (SDLKey)sym
932 1013
933int 1014int
934SDL_GetAppState () 1015SDL_GetAppState ()
935 1016
936int 1017int
937SDL_GetModState () 1018SDL_GetModState ()
938 1019
1020int
1021SDL_WaitEvent ()
1022 C_ARGS: 0
1023
939void 1024void
1025SDL_PumpEvents ()
1026
1027void
940poll_events () 1028peep_events ()
941 PPCODE: 1029 PPCODE:
942{ 1030{
943 SDL_Event ev; 1031 SDL_Event ev;
944 1032
945 SDL_PumpEvents (); 1033 SDL_PumpEvents ();
1011 1099
1012 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("DC::UI::Event", 1)))); 1100 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("DC::UI::Event", 1))));
1013 } 1101 }
1014} 1102}
1015 1103
1104char *
1105SDL_AudioDriverName ()
1106 CODE:
1107{
1108 char buf [256];
1109 if (!SDL_AudioDriverName (buf, sizeof (buf)))
1110 XSRETURN_UNDEF;
1111
1112 RETVAL = buf;
1113}
1114 OUTPUT:
1115 RETVAL
1116
1016int 1117int
1017Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) 1118Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096)
1018 POSTCALL: 1119 POSTCALL:
1019 Mix_HookMusicFinished (music_finished); 1120 Mix_HookMusicFinished (music_finished);
1020 Mix_ChannelFinished (channel_finished); 1121 Mix_ChannelFinished (channel_finished);
1021 1122
1022void 1123void
1023Mix_QuerySpec () 1124Mix_QuerySpec ()
1082add_font (char *file) 1183add_font (char *file)
1083 CODE: 1184 CODE:
1084 RETVAL = FcConfigAppFontAddFile (0, (const FcChar8 *)file); 1185 RETVAL = FcConfigAppFontAddFile (0, (const FcChar8 *)file);
1085 OUTPUT: 1186 OUTPUT:
1086 RETVAL 1187 RETVAL
1188
1189void
1190IMG_Init (int flags = IMG_INIT_JPG | IMG_INIT_PNG)
1191
1192# MIX_INIT_MP3 gives smpeg + libstdc++ + libgcc_s
1193void
1194Mix_Init (int flags = MIX_INIT_MOD | MIX_INIT_OGG)
1087 1195
1088void 1196void
1089load_image_inline (SV *image_) 1197load_image_inline (SV *image_)
1090 ALIAS: 1198 ALIAS:
1091 load_image_file = 1 1199 load_image_file = 1
1137 1245
1138 SDL_LockSurface (surface2); 1246 SDL_LockSurface (surface2);
1139 EXTEND (SP, 6); 1247 EXTEND (SP, 6);
1140 PUSHs (sv_2mortal (newSViv (surface2->w))); 1248 PUSHs (sv_2mortal (newSViv (surface2->w)));
1141 PUSHs (sv_2mortal (newSViv (surface2->h))); 1249 PUSHs (sv_2mortal (newSViv (surface2->h)));
1142 PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); 1250 PUSHs (sv_2mortal (newSVpvn ((const char *)surface2->pixels, surface2->h * surface2->pitch)));
1143 PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); 1251 PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB)));
1144 PUSHs (sv_2mortal (newSViv (GL_RGBA))); 1252 PUSHs (sv_2mortal (newSViv (GL_RGBA)));
1145 PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); 1253 PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE)));
1146 SDL_UnlockSurface (surface2); 1254 SDL_UnlockSurface (surface2);
1147 1255
1219MODULE = Deliantra::Client PACKAGE = DC::Font 1327MODULE = Deliantra::Client PACKAGE = DC::Font
1220 1328
1221PROTOTYPES: DISABLE 1329PROTOTYPES: DISABLE
1222 1330
1223DC::Font 1331DC::Font
1224new_from_file (SV *class, char *path, int id = 0) 1332new_from_file (SV *klass, char *path, int id = 0)
1225 CODE: 1333 CODE:
1226{ 1334{
1227 int count; 1335 int count;
1228 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); 1336 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count);
1229 RETVAL = pango_fc_font_description_from_pattern (pattern, 0); 1337 RETVAL = pango_fc_font_description_from_pattern (pattern, 0);
1258 PROTOTYPE: 1366 PROTOTYPE:
1259 CODE: 1367 CODE:
1260 tc_restore (); 1368 tc_restore ();
1261 1369
1262DC::Layout 1370DC::Layout
1263new (SV *class) 1371new (SV *klass)
1264 CODE: 1372 CODE:
1265 New (0, RETVAL, 1, struct cf_layout); 1373 New (0, RETVAL, 1, struct cf_layout);
1266 1374
1267 RETVAL->pl = pango_layout_new (opengl_context); 1375 RETVAL->pl = pango_layout_new (opengl_context);
1268 RETVAL->r = 1.; 1376 RETVAL->r = 1.;
1417 1525
1418void 1526void
1419set_height (DC::Layout self, int base_height) 1527set_height (DC::Layout self, int base_height)
1420 CODE: 1528 CODE:
1421 if (self->base_height != base_height) 1529 if (self->base_height != base_height)
1422 { 1530 {
1423 self->base_height = base_height; 1531 self->base_height = base_height;
1424 layout_update_font (self); 1532 layout_update_font (self);
1425 } 1533 }
1426 1534
1427void 1535void
1654 glDisable (GL_ALPHA_TEST); 1762 glDisable (GL_ALPHA_TEST);
1655 glDisable (GL_BLEND); 1763 glDisable (GL_BLEND);
1656 } 1764 }
1657} 1765}
1658 1766
1767void
1768draw_fow_texture (float intensity, int hidden_tex, int name1, uint8_t *data1, float s, float t, int w, int h, float blend = 0.f, int dx = 0, int dy = 0, int name2 = 0, uint8_t *data2 = data1)
1769 PROTOTYPE: @
1770 CODE:
1771{
1772 glEnable (GL_BLEND);
1773 glBlendFunc (intensity ? GL_SRC_ALPHA : GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1774 glEnable (GL_TEXTURE_2D);
1775 glBindTexture (GL_TEXTURE_2D, name1);
1776
1777 glColor3f (intensity, intensity, intensity);
1778 glPushMatrix ();
1779 glScalef (1./3, 1./3, 1.);
1780
1781 if (blend > 0.f)
1782 {
1783 float dx3 = dx * -3.f / w;
1784 float dy3 = dy * -3.f / h;
1785 GLfloat env_color[4] = { 0., 0., 0., blend };
1786
1787 /* interpolate the two shadow textures */
1788 /* stage 0 == rgb(glcolor) + alpha(t0) */
1789 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1790
1791 /* stage 1 == rgb(glcolor) + alpha(interpolate t0, t1, texenv) */
1792 gl.ActiveTexture (GL_TEXTURE1);
1793 glEnable (GL_TEXTURE_2D);
1794 glBindTexture (GL_TEXTURE_2D, name2);
1795 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
1796
1797 /* rgb == rgb(glcolor) */
1798 glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
1799 glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PRIMARY_COLOR);
1800 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
1801
1802 /* alpha = interpolate t0, t1 by env_alpha */
1803 glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, env_color);
1804
1805 glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_INTERPOLATE);
1806 glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);
1807 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
1808
1809 glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_PREVIOUS);
1810 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
1811
1812 glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE2_ALPHA, GL_CONSTANT);
1813 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA);
1814
1815 glBegin (GL_QUADS);
1816 gl.MultiTexCoord2f (GL_TEXTURE0, 0, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 , dy3 ); glVertex2i (0, 0);
1817 gl.MultiTexCoord2f (GL_TEXTURE0, 0, t); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 , dy3 + t); glVertex2i (0, h);
1818 gl.MultiTexCoord2f (GL_TEXTURE0, s, t); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 + s, dy3 + t); glVertex2i (w, h);
1819 gl.MultiTexCoord2f (GL_TEXTURE0, s, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 + s, dy3 ); glVertex2i (w, 0);
1820 glEnd ();
1821
1822 glDisable (GL_TEXTURE_2D);
1823 gl.ActiveTexture (GL_TEXTURE0);
1824 }
1825 else
1826 {
1827 /* simple blending of one texture, also opengl <1.3 path */
1828 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1829
1830 glBegin (GL_QUADS);
1831 glTexCoord2f (0, 0); glVertex2f (0, 0);
1832 glTexCoord2f (0, t); glVertex2f (0, h);
1833 glTexCoord2f (s, t); glVertex2f (w, h);
1834 glTexCoord2f (s, 0); glVertex2f (w, 0);
1835 glEnd ();
1836 }
1837
1838 /* draw ?-marks or equivalent, this is very clumsy code :/ */
1839 {
1840 int x, y;
1841 int dx3 = dx * 3;
1842 int dy3 = dy * 3;
1843
1844 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1845 glBindTexture (GL_TEXTURE_2D, hidden_tex);
1846 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1847 glTranslatef (-1., -1., 0);
1848 glBegin (GL_QUADS);
1849
1850 for (y = 1; y < h; y += 3)
1851 {
1852 int y1 = y - dy3;
1853 int y1valid = y1 >= 0 && y1 < h;
1854
1855 for (x = 1; x < w; x += 3)
1856 {
1857 int x1 = x - dx3;
1858 uint8_t h1 = data1 [x + y * w] == DARKNESS_ADJUST (255 - FOW_DARKNESS);
1859 uint8_t h2;
1860
1861 if (y1valid && x1 >= 0 && x1 < w)
1862 h2 = data2 [x1 + y1 * w] == DARKNESS_ADJUST (255 - FOW_DARKNESS);
1863 else
1864 h2 = 1; /* out of range == invisible */
1865
1866 if (h1 || h2)
1867 {
1868 float alpha = h1 == h2 ? 1.f : h1 ? 1.f - blend : blend;
1869 glColor4f (1., 1., 1., alpha);
1870
1871 glTexCoord2f (0, 0.); glVertex2i (x , y );
1872 glTexCoord2f (0, 1.); glVertex2i (x , y + 3);
1873 glTexCoord2f (1, 1.); glVertex2i (x + 3, y + 3);
1874 glTexCoord2f (1, 0.); glVertex2i (x + 3, y );
1875 }
1876 }
1877 }
1878 }
1879
1880 glEnd ();
1881
1882 glPopMatrix ();
1883
1884 glDisable (GL_TEXTURE_2D);
1885 glDisable (GL_BLEND);
1886}
1887
1659IV texture_valid_2d (GLint internalformat, GLsizei w, GLsizei h, GLenum format, GLenum type) 1888IV texture_valid_2d (GLint internalformat, GLsizei w, GLsizei h, GLenum format, GLenum type)
1660 CODE: 1889 CODE:
1661{ 1890{
1662 GLint width; 1891 GLint width;
1663 glTexImage2D (GL_PROXY_TEXTURE_2D, 0, internalformat, w, h, 0, format, type, 0); 1892 glTexImage2D (GL_PROXY_TEXTURE_2D, 0, internalformat, w, h, 0, format, type, 0);
1670MODULE = Deliantra::Client PACKAGE = DC::Map 1899MODULE = Deliantra::Client PACKAGE = DC::Map
1671 1900
1672PROTOTYPES: DISABLE 1901PROTOTYPES: DISABLE
1673 1902
1674DC::Map 1903DC::Map
1675new (SV *class) 1904new (SV *klass)
1676 CODE: 1905 CODE:
1677 New (0, RETVAL, 1, struct map); 1906 New (0, RETVAL, 1, mapgrid);
1678 RETVAL->x = 0; 1907 RETVAL->x = 0;
1679 RETVAL->y = 0; 1908 RETVAL->y = 0;
1680 RETVAL->w = 0; 1909 RETVAL->w = 0;
1681 RETVAL->h = 0; 1910 RETVAL->h = 0;
1682 RETVAL->ox = 0; 1911 RETVAL->ox = 0;
1719 1948
1720void 1949void
1721set_smooth (DC::Map self, int face, int smooth, int level) 1950set_smooth (DC::Map self, int face, int smooth, int level)
1722 CODE: 1951 CODE:
1723{ 1952{
1724 tileid texid; 1953 tileid texid;
1725 maptex *tex; 1954 maptex *tex;
1726 1955
1727 if (face < 0 || face >= self->faces) 1956 if (face < 0 || face >= self->faces)
1728 return; 1957 return;
1729 1958
1730 if (smooth < 0 || smooth >= self->faces) 1959 if (smooth < 0 || smooth >= self->faces)
1731 return; 1960 return;
1732 1961
1733 texid = self->face2tile [face]; 1962 texid = self->face2tile [face];
1734 1963
1735 if (!texid) 1964 if (!texid)
1736 return; 1965 return;
1737 1966
1738 tex = self->tex + texid; 1967 tex = self->tex + texid;
1771} 2000}
1772 2001
1773void 2002void
1774expire_textures (DC::Map self, int texid, int count) 2003expire_textures (DC::Map self, int texid, int count)
1775 PPCODE: 2004 PPCODE:
1776 for (; texid < self->texs && count; ++texid, --count) 2005 for (; texid < self->texs && count; ++texid, --count)
1777 { 2006 {
1778 maptex *tex = self->tex + texid; 2007 maptex *tex = self->tex + texid;
1779 2008
1780 if (tex->name) 2009 if (tex->name)
1781 { 2010 {
1782 if (tex->unused) 2011 if (tex->unused)
1783 { 2012 {
1784 tex->name = 0; 2013 tex->name = 0;
1785 tex->unused = 0, 2014 tex->unused = 0;
1786 XPUSHs (sv_2mortal (newSViv (texid))); 2015 XPUSHs (sv_2mortal (newSViv (texid)));
1787 } 2016 }
1788 else 2017 else
1789 tex->unused = 1; 2018 tex->unused = 1;
1790 } 2019 }
1836 self->y += MAP_EXTEND_Y; 2065 self->y += MAP_EXTEND_Y;
1837 } 2066 }
1838} 2067}
1839 2068
1840SV * 2069SV *
1841map1a_update (DC::Map self, SV *data_, int extmap) 2070map1a_update (DC::Map self, SV *data_)
1842 CODE: 2071 CODE:
1843{ 2072{
1844 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 2073 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1845 uint8_t *data_end = (uint8_t *)SvEND (data_); 2074 uint8_t *data_end = (uint8_t *)SvEND (data_);
1846 mapcell *cell; 2075 mapcell *cell;
1867 2096
1868 //TODO: don't trust server data to be in-range(!) 2097 //TODO: don't trust server data to be in-range(!)
1869 2098
1870 if (flags & 8) 2099 if (flags & 8)
1871 { 2100 {
2101 uint8_t ext, cmd;
2102
1872 if (extmap) 2103 do
1873 { 2104 {
1874 uint8_t ext, cmd; 2105 ext = *data++;
2106 cmd = ext & 0x7f;
1875 2107
1876 do 2108 if (cmd < 4)
2109 cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */
2110 else if (cmd == 5) // health
1877 { 2111 {
1878 ext = *data++;
1879 cmd = ext & 0x7f;
1880
1881 if (cmd < 4)
1882 cell->darkness = 255 - ext * 64 + 1;
1883 else if (cmd == 5) // health
1884 {
1885 cell->stat_width = 1; 2112 cell->stat_width = 1;
1886 cell->stat_hp = *data++; 2113 cell->stat_hp = *data++;
1887 }
1888 else if (cmd == 6) // monster width
1889 cell->stat_width = *data++ + 1;
1890 else if (cmd == 0x47)
1891 {
1892 if (*data == 1) cell->player = data [1];
1893 else if (*data == 2) cell->player = data [2] + (data [1] << 8);
1894 else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16);
1895 else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24);
1896
1897 data += *data + 1;
1898 }
1899 else if (cmd == 8) // cell flags
1900 cell->flags = *data++;
1901 else if (ext & 0x40) // unknown, multibyte => skip
1902 data += *data + 1;
1903 else
1904 data++;
1905 } 2114 }
1906 while (ext & 0x80); 2115 else if (cmd == 6) // monster width
2116 cell->stat_width = *data++ + 1;
2117 else if (cmd == 0x47)
2118 {
2119 if (*data == 1) cell->player = data [1];
2120 else if (*data == 2) cell->player = data [2] + (data [1] << 8);
2121 else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16);
2122 else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24);
2123
2124 data += *data + 1;
2125 }
2126 else if (cmd == 8) // cell flags
2127 cell->flags = *data++;
2128 else if (ext & 0x40) // unknown, multibyte => skip
2129 data += *data + 1;
2130 else
2131 data++;
1907 } 2132 }
1908 else 2133 while (ext & 0x80);
1909 cell->darkness = *data++ + 1;
1910 } 2134 }
1911 2135
1912 for (z = 0; z <= 2; ++z) 2136 for (z = 0; z <= 2; ++z)
1913 if (flags & (4 >> z)) 2137 if (flags & (4 >> z))
1914 { 2138 {
1962 ? self->row + y 2186 ? self->row + y
1963 : 0; 2187 : 0;
1964 2188
1965 for (x = x0; x < x1; x++) 2189 for (x = x0; x < x1; x++)
1966 { 2190 {
1967 int r = 32, g = 32, b = 32, a = 192; 2191 unsigned int r = 32, g = 32, b = 32, a = 192;
1968 2192
1969 if (row && row->c0 <= x && x < row->c1) 2193 if (row && row->c0 <= x && x < row->c1)
1970 { 2194 {
1971 mapcell *cell = row->col + (x - row->c0); 2195 mapcell *cell = row->col + (x - row->c0);
1972 2196
1974 { 2198 {
1975 maptex tex = self->tex [cell->tile [z]]; 2199 maptex tex = self->tex [cell->tile [z]];
1976 int a0 = 255 - tex.a; 2200 int a0 = 255 - tex.a;
1977 int a1 = tex.a; 2201 int a1 = tex.a;
1978 2202
1979 r = (r * a0 + tex.r * a1) / 255; 2203 r = div255 (r * a0 + tex.r * a1);
1980 g = (g * a0 + tex.g * a1) / 255; 2204 g = div255 (g * a0 + tex.g * a1);
1981 b = (b * a0 + tex.b * a1) / 255; 2205 b = div255 (b * a0 + tex.b * a1);
1982 a = (a * a0 + tex.a * a1) / 255; 2206 a = div255 (a * a0 + tex.a * a1);
1983 } 2207 }
1984 } 2208 }
1985 2209
1986 *map++ = (r ) 2210 *map++ = (r )
1987 | (g << 8) 2211 | (g << 8)
1988 | (b << 16) 2212 | (b << 16)
1989 | (a << 24); 2213 | (a << 24);
1990 } 2214 }
1991 } 2215 }
1992 2216
1993 RETVAL = map_sv; 2217 RETVAL = map_sv;
1994} 2218}
1995 OUTPUT: 2219 OUTPUT:
1996 RETVAL 2220 RETVAL
1997 2221
1998void 2222void
1999draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) 2223draw (DC::Map self, int mx, int my, int sw, int sh, int Tw, int Th, U32 player = 0xffffffff, int sdx = 0, int sdy = 0)
2000 CODE: 2224 CODE:
2001{ 2225{
2002 int x, y, z; 2226 int x, y, z;
2003 2227
2004 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ());
2005 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level 2228 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level
2006 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) 2229 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k)
2007 smooth_key skey; 2230 smooth_key skey;
2008 int pl_x, pl_y; 2231 int pl_x, pl_y;
2009 maptex pl_tex; 2232 maptex pl_tex;
2010 rc_t *rc = rc_alloc (); 2233 rc_t *rc = rc_alloc ();
2234 rc_t *rc_ov = rc_alloc ();
2011 rc_key_t key; 2235 rc_key_t key;
2012 rc_array_t *arr; 2236 rc_array_t *arr;
2013 2237
2014 pl_tex.name = 0; 2238 pl_tex.name = 0;
2015 2239
2016 // thats current max. sorry. 2240 // that's current max. sorry.
2017 if (sw > 255) sw = 255; 2241 if (sw > 255) sw = 255;
2018 if (sh > 255) sh = 255; 2242 if (sh > 255) sh = 255;
2019 2243
2020 // clear key, in case of extra padding 2244 // clear key, in case of extra padding
2021 memset (&skey, 0, sizeof (skey)); 2245 memset (&skey, 0, sizeof (skey));
2025 key.g = 255; 2249 key.g = 255;
2026 key.b = 255; 2250 key.b = 255;
2027 key.a = 255; 2251 key.a = 255;
2028 key.mode = GL_QUADS; 2252 key.mode = GL_QUADS;
2029 key.format = GL_T2F_V3F; 2253 key.format = GL_T2F_V3F;
2030 key.texname = -1;
2031 2254
2032 mx += self->x; 2255 mx += self->x;
2033 my += self->y; 2256 my += self->y;
2034 2257
2035 // first pass: determine smooth_max 2258 // first pass: determine smooth_max
2058 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2281 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2059 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 2282 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
2060 2283
2061 for (z = 0; z <= 2; z++) 2284 for (z = 0; z <= 2; z++)
2062 { 2285 {
2286 smooth_hash smooth;
2063 memset (smooth_level, 0, sizeof (smooth_level)); 2287 memset (smooth_level, 0, sizeof (smooth_level));
2288 key.texname = -1;
2064 2289
2065 for (y = 0; y < sh; y++) 2290 for (y = 0; y < sh; y++)
2066 if (0 <= y + my && y + my < self->rows) 2291 if (0 <= y + my && y + my < self->rows)
2067 { 2292 {
2068 maprow *row = self->row + (y + my); 2293 maprow *row = self->row + (y + my);
2074 tileid tile = cell->tile [z]; 2299 tileid tile = cell->tile [z];
2075 2300
2076 if (tile) 2301 if (tile)
2077 { 2302 {
2078 maptex tex = self->tex [tile]; 2303 maptex tex = self->tex [tile];
2079 int px = (x + 1) * T - tex.w; 2304 int px, py;
2080 int py = (y + 1) * T - tex.h;
2081 2305
2082 if (key.texname != tex.name) 2306 if (key.texname != tex.name)
2083 { 2307 {
2084 self->tex [tile].unused = 0; 2308 self->tex [tile].unused = 0;
2085 2309
2086 if (!tex.name) 2310 if (!tex.name)
2087 tex = self->tex [2]; /* missing, replace by noface */ 2311 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */
2088 2312
2089 key.texname = tex.name; 2313 key.texname = tex.name;
2090 arr = rc_array (rc, &key); 2314 arr = rc_array (rc, &key);
2091 } 2315 }
2316
2317 px = (x + 1) * Th - tex.w;
2318 py = (y + 1) * Tw - tex.h;
2092 2319
2093 if (expect_false (cell->player == player) && expect_false (z == 2)) 2320 if (expect_false (cell->player == player) && expect_false (z == 2))
2094 { 2321 {
2095 pl_x = px; 2322 pl_x = px;
2096 pl_y = py; 2323 pl_y = py;
2101 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2328 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
2102 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2329 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0);
2103 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); 2330 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0);
2104 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); 2331 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0);
2105 2332
2106 if (expect_false (cell->flags) && expect_false (z == 2))
2107 {
2108 // overlays such as the speech bubble, probably more to come
2109 if (cell->flags & 1)
2110 {
2111 maptex tex = self->tex [1];
2112 int px = x * T + T * 2 / 32;
2113 int py = y * T - T * 6 / 32;
2114
2115 if (tex.name)
2116 {
2117 if (key.texname != tex.name)
2118 {
2119 key.texname = tex.name;
2120 arr = rc_array (rc, &key);
2121 }
2122
2123 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
2124 rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0);
2125 rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0);
2126 rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0);
2127 }
2128 }
2129 }
2130
2131 // update smooth hash 2333 // update smooth hash
2132 if (tex.smoothtile) 2334 if (tex.smoothtile)
2133 { 2335 {
2134 skey.tile = tex.smoothtile; 2336 skey.tile = tex.smoothtile;
2135 skey.level = tex.smoothlevel; 2337 skey.level = tex.smoothlevel;
2150 2352
2151 // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· 2353 // corners: 1 ┛· 2 ·┗ 4 ·· 8 ··
2152 // ·· ·· ·┏ ┓· 2354 // ·· ·· ·┏ ┓·
2153 2355
2154 // full tile 2356 // full tile
2155 skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x1000); 2357 skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x1000);
2156 2358
2157 // borders 2359 // borders
2158 skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0091); 2360 skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0091);
2159 skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0032); 2361 skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0032);
2160 skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0064); 2362 skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0064);
2161 skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, &skey, 0x00c8); 2363 skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, skey, 0x00c8);
2162 2364
2163 // corners 2365 // corners
2164 skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0100); 2366 skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0100);
2165 skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0200); 2367 skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0200);
2166 skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400); 2368 skey.x = x ; skey.y = y ; smooth_or_bits (smooth, skey, 0x0400);
2167 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); 2369 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, skey, 0x0800);
2370 }
2371 }
2372
2373 if (expect_false (z == 2) && expect_false (cell->flags))
2374 {
2375 // overlays such as the speech bubble, probably more to come
2376 if (cell->flags & 1)
2377 {
2378 rc_key_t key_ov = key;
2379 maptex tex = self->tex [TEXID_SPEECH];
2380 rc_array_t *arr;
2381 int px = x * Tw + Tw * 2 / 32;
2382 int py = y * Th - Th * 6 / 32;
2383
2384 key_ov.texname = tex.name;
2385 arr = rc_array (rc_ov, &key_ov);
2386
2387 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
2388 rc_t2f_v3f (arr, 0 , tex.t, px , py + Th, 0);
2389 rc_t2f_v3f (arr, tex.s, tex.t, px + Tw, py + Th, 0);
2390 rc_t2f_v3f (arr, tex.s, 0 , px + Tw, py , 0);
2168 } 2391 }
2169 } 2392 }
2170 } 2393 }
2171 } 2394 }
2172 2395
2188 if (smask & (((uint32_t)1) << b)) 2411 if (smask & (((uint32_t)1) << b))
2189 { 2412 {
2190 int level = (w << 5) | b; 2413 int level = (w << 5) | b;
2191 HE *he; 2414 HE *he;
2192 2415
2193 hv_iterinit (smooth); 2416 for (auto &&it = smooth.begin (); it != smooth.end (); ++it)
2194 while ((he = hv_iternext (smooth)))
2195 { 2417 {
2196 smooth_key *skey = (smooth_key *)HeKEY (he); 2418 smooth_key &skey = it->first;
2197 IV bits = SvIVX (HeVAL (he)); 2419 IV bits = it->second;
2198 2420
2199 if (!(bits & 0x1000) 2421 if (!(bits & 0x1000)
2200 && skey->level == level 2422 && skey.level == level
2201 && level > smooth_max [skey->x][skey->y]) 2423 && level > smooth_max [skey.x][skey.y])
2202 { 2424 {
2203 maptex tex = self->tex [skey->tile]; 2425 maptex tex = self->tex [skey.tile];
2204 int px = (((int)skey->x) - 1) * T; 2426 int px = (((int)skey.x) - 1) * Tw;
2205 int py = (((int)skey->y) - 1) * T; 2427 int py = (((int)skey.y) - 1) * Th;
2206 int border = bits & 15; 2428 int border = bits & 15;
2207 int corner = (bits >> 8) & ~(bits >> 4) & 15; 2429 int corner = (bits >> 8) & ~(bits >> 4) & 15;
2208 float dx = tex.s * .0625f; // 16 images/row 2430 float dx = tex.s * .0625f; // 16 images/row
2209 float dy = tex.t * .5f ; // 2 images/column 2431 float dy = tex.t * .5f ; // 2 images/column
2210 2432
2212 { 2434 {
2213 // this time avoiding texture state changes 2435 // this time avoiding texture state changes
2214 // save gobs of state changes. 2436 // save gobs of state changes.
2215 if (key.texname != tex.name) 2437 if (key.texname != tex.name)
2216 { 2438 {
2217 self->tex [skey->tile].unused = 0; 2439 self->tex [skey.tile].unused = 0;
2218 2440
2219 glEnd (); 2441 glEnd ();
2220 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); 2442 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name);
2221 glBegin (GL_QUADS); 2443 glBegin (GL_QUADS);
2222 } 2444 }
2223 2445
2224 if (border) 2446 if (border)
2225 { 2447 {
2226 float ox = border * dx; 2448 float ox = border * dx;
2227 2449
2228 glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); 2450 glTexCoord2f (ox , 0.f ); glVertex2i (px , py );
2229 glTexCoord2f (ox , dy ); glVertex2i (px , py + T); 2451 glTexCoord2f (ox , dy ); glVertex2i (px , py + Th);
2230 glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py + T); 2452 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th);
2231 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + T, py ); 2453 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py );
2232 } 2454 }
2233 2455
2234 if (corner) 2456 if (corner)
2235 { 2457 {
2236 float ox = corner * dx; 2458 float ox = corner * dx;
2237 2459
2238 glTexCoord2f (ox , dy ); glVertex2i (px , py ); 2460 glTexCoord2f (ox , dy ); glVertex2i (px , py );
2239 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + T); 2461 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th);
2240 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + T, py + T); 2462 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th);
2241 glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py ); 2463 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py );
2242 } 2464 }
2243 } 2465 }
2244 } 2466 }
2245 } 2467 }
2246 } 2468 }
2248 2470
2249 glEnd (); 2471 glEnd ();
2250 glDisable (GL_TEXTURE_2D); 2472 glDisable (GL_TEXTURE_2D);
2251 key.texname = -1; 2473 key.texname = -1;
2252 } 2474 }
2253
2254 hv_clear (smooth);
2255 } 2475 }
2256 2476
2257 if (pl_tex.name) 2477 if (pl_tex.name)
2258 { 2478 {
2259 maptex tex = pl_tex; 2479 maptex tex = pl_tex;
2269 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); 2489 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0);
2270 2490
2271 rc_draw (rc); 2491 rc_draw (rc);
2272 } 2492 }
2273 2493
2494 rc_draw (rc_ov);
2495 rc_clear (rc_ov);
2496
2274 glDisable (GL_BLEND); 2497 glDisable (GL_BLEND);
2275 rc_free (rc); 2498 rc_free (rc);
2499 rc_free (rc_ov);
2276 2500
2277 // top layer: overlays such as the health bar 2501 // top layer: overlays such as the health bar
2278 for (y = 0; y < sh; y++) 2502 for (y = 0; y < sh; y++)
2279 if (0 <= y + my && y + my < self->rows) 2503 if (0 <= y + my && y + my < self->rows)
2280 { 2504 {
2283 for (x = 0; x < sw; x++) 2507 for (x = 0; x < sw; x++)
2284 if (row->c0 <= x + mx && x + mx < row->c1) 2508 if (row->c0 <= x + mx && x + mx < row->c1)
2285 { 2509 {
2286 mapcell *cell = row->col + (x + mx - row->c0); 2510 mapcell *cell = row->col + (x + mx - row->c0);
2287 2511
2288 int px = x * T; 2512 int px = x * Tw;
2289 int py = y * T; 2513 int py = y * Th;
2290 2514
2291 if (expect_false (cell->player == player)) 2515 if (expect_false (cell->player == player))
2292 { 2516 {
2293 px += sdx; 2517 px += sdx;
2294 py += sdy; 2518 py += sdy;
2295 } 2519 }
2296 2520
2297 if (cell->stat_hp) 2521 if (cell->stat_hp)
2298 { 2522 {
2299 int width = cell->stat_width * T; 2523 int width = cell->stat_width * Tw;
2300 int thick = (sh * T / 32 + 27) / 28 + 1 + cell->stat_width; 2524 int thick = (sh * Th / 32 + 27) / 28 + 1 + cell->stat_width;
2301 2525
2302 glColor3ub (0, 0, 0); 2526 glColor3ub (0, 0, 0);
2303 glRectf (px + 1, py - thick - 2, 2527 glRectf (px + 1, py - thick - 2,
2304 px + width - 1, py); 2528 px + width - 1, py);
2305 2529
2311 } 2535 }
2312 } 2536 }
2313} 2537}
2314 2538
2315void 2539void
2316draw_magicmap (DC::Map self, int dx, int dy, int w, int h, unsigned char *data) 2540draw_magicmap (DC::Map self, int w, int h, unsigned char *data)
2317 CODE: 2541 CODE:
2318{ 2542{
2319 static float color[16][3] = { 2543 static float color[16][3] = {
2320 { 0.00F, 0.00F, 0.00F }, 2544 { 0.00f, 0.00f, 0.00f },
2321 { 1.00F, 1.00F, 1.00F }, 2545 { 1.00f, 1.00f, 1.00f },
2322 { 0.00F, 0.00F, 0.55F }, 2546 { 0.00f, 0.00f, 0.55f },
2323 { 1.00F, 0.00F, 0.00F }, 2547 { 1.00f, 0.00f, 0.00f },
2324 2548
2325 { 1.00F, 0.54F, 0.00F }, 2549 { 1.00f, 0.54f, 0.00f },
2326 { 0.11F, 0.56F, 1.00F }, 2550 { 0.11f, 0.56f, 1.00f },
2327 { 0.93F, 0.46F, 0.00F }, 2551 { 0.93f, 0.46f, 0.00f },
2328 { 0.18F, 0.54F, 0.34F }, 2552 { 0.18f, 0.54f, 0.34f },
2329 2553
2330 { 0.56F, 0.73F, 0.56F }, 2554 { 0.56f, 0.73f, 0.56f },
2331 { 0.80F, 0.80F, 0.80F }, 2555 { 0.80f, 0.80f, 0.80f },
2332 { 0.55F, 0.41F, 0.13F }, 2556 { 0.55f, 0.41f, 0.13f },
2333 { 0.99F, 0.77F, 0.26F }, 2557 { 0.99f, 0.77f, 0.26f },
2334 2558
2335 { 0.74F, 0.65F, 0.41F }, 2559 { 0.74f, 0.65f, 0.41f },
2336 2560
2337 { 0.00F, 1.00F, 1.00F }, 2561 { 0.00f, 1.00f, 1.00f },
2338 { 1.00F, 0.00F, 1.00F }, 2562 { 1.00f, 0.00f, 1.00f },
2339 { 1.00F, 1.00F, 0.00F }, 2563 { 1.00f, 1.00f, 0.00f },
2340 }; 2564 };
2341 2565
2342 int x, y; 2566 int x, y;
2343 2567
2344 glEnable (GL_TEXTURE_2D); 2568 glEnable (GL_TEXTURE_2D);
2569 /* GL_REPLACE would be correct, as we don't need to modulate alpha,
2570 * but the nvidia driver (185.18.14) mishandles alpha textures
2571 * and takes the colour from god knows where instead of using
2572 * Cp. MODULATE results in the same colour, but slightly different
2573 * alpha, but atcually gives us the correct colour with nvidia.
2574 */
2345 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 2575 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
2346 glEnable (GL_BLEND); 2576 glEnable (GL_BLEND);
2347 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2577 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2348 glBegin (GL_QUADS); 2578 glBegin (GL_QUADS);
2349 2579
2350 for (y = 0; y < h; y++) 2580 for (y = 0; y < h; y++)
2354 2584
2355 if (m) 2585 if (m)
2356 { 2586 {
2357 float *c = color [m & 15]; 2587 float *c = color [m & 15];
2358 2588
2359 float tx1 = m & 0x40 ? 0.5 : 0.; 2589 float tx1 = m & 0x40 ? 0.5f : 0.f;
2360 float tx2 = tx1 + 0.5; 2590 float tx2 = tx1 + 0.5f;
2361 2591
2362 glColor4f (c[0], c[1], c[2], 0.75); 2592 glColor4f (c[0], c[1], c[2], 1);
2363 glTexCoord2f (tx1, 0.); glVertex2i (x , y ); 2593 glTexCoord2f (tx1, 0.); glVertex2i (x , y );
2364 glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1); 2594 glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1);
2365 glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1); 2595 glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1);
2366 glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y ); 2596 glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y );
2367 } 2597 }
2375void 2605void
2376fow_texture (DC::Map self, int mx, int my, int sw, int sh) 2606fow_texture (DC::Map self, int mx, int my, int sw, int sh)
2377 PPCODE: 2607 PPCODE:
2378{ 2608{
2379 int x, y; 2609 int x, y;
2380 int sw1 = sw + 2; 2610 int sw1 = sw + 2;
2381 int sh1 = sh + 2; 2611 int sh1 = sh + 2;
2382 int sh3 = sh * 3; 2612 int sh3 = sh * 3;
2383 int sw34 = (sw * 3 + 3) & ~3; 2613 int sw3 = sw * 3;
2614 SV *darkness3_sv = sv_2mortal (newSV (sw3 * sh3));
2615 uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv);
2384 uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); 2616 uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1);
2385 SV *darkness3_sv = sv_2mortal (newSV (sw34 * sh3)); 2617 memset (darkness1, 0, sw1*sh1);
2386 uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv);
2387 2618
2388 SvPOK_only (darkness3_sv); 2619 SvPOK_only (darkness3_sv);
2389 SvCUR_set (darkness3_sv, sw34 * sh3); 2620 SvCUR_set (darkness3_sv, sw3 * sh3);
2390 2621
2391 mx += self->x - 1; 2622 mx += self->x - 1;
2392 my += self->y - 1; 2623 my += self->y - 1;
2393
2394 memset (darkness1, 255 - FOW_DARKNESS, sw1 * sh1);
2395 2624
2396 for (y = 0; y < sh1; y++) 2625 for (y = 0; y < sh1; y++)
2397 if (0 <= y + my && y + my < self->rows) 2626 if (0 <= y + my && y + my < self->rows)
2398 { 2627 {
2399 maprow *row = self->row + (y + my); 2628 maprow *row = self->row + (y + my);
2402 if (row->c0 <= x + mx && x + mx < row->c1) 2631 if (row->c0 <= x + mx && x + mx < row->c1)
2403 { 2632 {
2404 mapcell *cell = row->col + (x + mx - row->c0); 2633 mapcell *cell = row->col + (x + mx - row->c0);
2405 2634
2406 darkness1 [y * sw1 + x] = cell->darkness 2635 darkness1 [y * sw1 + x] = cell->darkness
2407 ? 255 - (cell->darkness - 1) 2636 ? DARKNESS_ADJUST (255 - (cell->darkness - 1))
2408 : 255 - FOW_DARKNESS; 2637 : DARKNESS_ADJUST (255 - FOW_DARKNESS);
2409 } 2638 }
2410 } 2639 }
2411 2640
2412 for (y = 0; y < sh; ++y) 2641 for (y = 0; y < sh; ++y)
2413 for (x = 0; x < sw; ++x) 2642 for (x = 0; x < sw; ++x)
2432 2661
2433 uint8_t r13 = (d13 + d23 + d12) / 3; 2662 uint8_t r13 = (d13 + d23 + d12) / 3;
2434 uint8_t r23 = d23; 2663 uint8_t r23 = d23;
2435 uint8_t r33 = (d23 + d33 + d32) / 3; 2664 uint8_t r33 = (d23 + d33 + d32) / 3;
2436 2665
2437 darkness3 [(y * 3 ) * sw34 + (x * 3 )] = MAX (d22, r11); 2666 darkness3 [(y * 3 ) * sw3 + (x * 3 )] = MAX (d22, r11);
2438 darkness3 [(y * 3 ) * sw34 + (x * 3 + 1)] = MAX (d22, r21); 2667 darkness3 [(y * 3 ) * sw3 + (x * 3 + 1)] = MAX (d22, r21);
2439 darkness3 [(y * 3 ) * sw34 + (x * 3 + 2)] = MAX (d22, r31); 2668 darkness3 [(y * 3 ) * sw3 + (x * 3 + 2)] = MAX (d22, r31);
2440 darkness3 [(y * 3 + 1) * sw34 + (x * 3 )] = MAX (d22, r12); 2669 darkness3 [(y * 3 + 1) * sw3 + (x * 3 )] = MAX (d22, r12);
2441 darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 1)] = MAX (d22, r22); 2670 darkness3 [(y * 3 + 1) * sw3 + (x * 3 + 1)] = MAX (d22, r22); /* this MUST be == d22 */
2442 darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 2)] = MAX (d22, r32); 2671 darkness3 [(y * 3 + 1) * sw3 + (x * 3 + 2)] = MAX (d22, r32);
2443 darkness3 [(y * 3 + 2) * sw34 + (x * 3 )] = MAX (d22, r13); 2672 darkness3 [(y * 3 + 2) * sw3 + (x * 3 )] = MAX (d22, r13);
2444 darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 1)] = MAX (d22, r23); 2673 darkness3 [(y * 3 + 2) * sw3 + (x * 3 + 1)] = MAX (d22, r23);
2445 darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 2)] = MAX (d22, r33); 2674 darkness3 [(y * 3 + 2) * sw3 + (x * 3 + 2)] = MAX (d22, r33);
2446 } 2675 }
2447 2676
2448 free (darkness1); 2677 free (darkness1);
2449 2678
2450 EXTEND (SP, 3); 2679 EXTEND (SP, 3);
2451 PUSHs (sv_2mortal (newSViv (sw34))); 2680 PUSHs (sv_2mortal (newSViv (sw3)));
2452 PUSHs (sv_2mortal (newSViv (sh3))); 2681 PUSHs (sv_2mortal (newSViv (sh3)));
2453 PUSHs (darkness3_sv); 2682 PUSHs (darkness3_sv);
2454} 2683}
2455 2684
2456SV * 2685SV *
2519 else 2748 else
2520 *data++ = 0; 2749 *data++ = 0;
2521 } 2750 }
2522 } 2751 }
2523 2752
2524 /* if size is w*h + 5 then no data has been found */ 2753 /* if size is w*h + 5 then no data has been found */
2525 if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) 2754 if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5)
2526 { 2755 {
2527 SvPOK_only (data_sv); 2756 SvPOK_only (data_sv);
2528 SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); 2757 SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv));
2529 } 2758 }
2530 2759
2531 RETVAL = data_sv; 2760 RETVAL = data_sv;
2532} 2761}
2533 OUTPUT: 2762 OUTPUT:
2534 RETVAL 2763 RETVAL
2535 2764
2536void 2765void
2543 STRLEN len; 2772 STRLEN len;
2544 uint8_t *data, *end; 2773 uint8_t *data, *end;
2545 2774
2546 len = SvLEN (data_sv); 2775 len = SvLEN (data_sv);
2547 SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more 2776 SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more
2548 data = SvPVbyte_nolen (data_sv); 2777 data = (uint8_t *)SvPVbyte_nolen (data_sv);
2549 end = data + len + 8; 2778 end = data + len + 8;
2550 2779
2551 if (len < 5) 2780 if (len < 5)
2552 XSRETURN_EMPTY; 2781 XSRETURN_EMPTY;
2553 2782
2614} 2843}
2615 2844
2616MODULE = Deliantra::Client PACKAGE = DC::RW 2845MODULE = Deliantra::Client PACKAGE = DC::RW
2617 2846
2618DC::RW 2847DC::RW
2619new (SV *class, SV *data_sv) 2848new (SV *klass, SV *data_sv)
2620 CODE: 2849 CODE:
2621{ 2850{
2622 STRLEN datalen; 2851 STRLEN datalen;
2623 char *data = SvPVbyte (data_sv, datalen); 2852 char *data = SvPVbyte (data_sv, datalen);
2624 2853
2626} 2855}
2627 OUTPUT: 2856 OUTPUT:
2628 RETVAL 2857 RETVAL
2629 2858
2630DC::RW 2859DC::RW
2631new_from_file (SV *class, const char *path, const char *mode = "rb") 2860new_from_file (SV *klass, const char *path, const char *mode = "rb")
2632 CODE: 2861 CODE:
2633 RETVAL = SDL_RWFromFile (path, mode); 2862 RETVAL = SDL_RWFromFile (path, mode);
2634 OUTPUT: 2863 OUTPUT:
2635 RETVAL 2864 RETVAL
2636 2865
2654 if (RETVAL < 0) 2883 if (RETVAL < 0)
2655 { 2884 {
2656 RETVAL = Mix_GroupOldest (-1); 2885 RETVAL = Mix_GroupOldest (-1);
2657 2886
2658 if (RETVAL < 0) 2887 if (RETVAL < 0)
2888 {
2889 // happens sometimes, maybe it just stopped playing(?)
2890 RETVAL = Mix_GroupAvailable (-1);
2891
2892 if (RETVAL < 0)
2659 XSRETURN_UNDEF; 2893 XSRETURN_UNDEF;
2660 2894 }
2895 else
2661 Mix_HaltChannel (RETVAL); 2896 Mix_HaltChannel (RETVAL);
2662 } 2897 }
2663 2898
2664 Mix_UnregisterAllEffects (RETVAL); 2899 Mix_UnregisterAllEffects (RETVAL);
2665 Mix_Volume (RETVAL, 128); 2900 Mix_Volume (RETVAL, 128);
2666} 2901}
2713void 2948void
2714set_position_r (DC::Channel self, int dx, int dy, int maxdistance) 2949set_position_r (DC::Channel self, int dx, int dy, int maxdistance)
2715 CODE: 2950 CODE:
2716{ 2951{
2717 int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance)); 2952 int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance));
2718 int angle = 360 + (int)roundf (atan2f (dx, -dy) * 180.f / (float)M_PI); 2953 int angle = atan2f (dx, -dy) * 180.f / (float)M_PI + 360.f;
2719 Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); 2954 Mix_SetPosition (self, angle, CLAMP (distance, 0, 255));
2720} 2955}
2721 2956
2722void 2957void
2723set_reverse_stereo (DC::Channel self, int flip) 2958set_reverse_stereo (DC::Channel self, int flip)
2726 2961
2727MODULE = Deliantra::Client PACKAGE = DC::MixChunk 2962MODULE = Deliantra::Client PACKAGE = DC::MixChunk
2728 2963
2729PROTOTYPES: DISABLE 2964PROTOTYPES: DISABLE
2730 2965
2966void
2967decoders ()
2968 PPCODE:
2969#if SDL_MIXER_MAJOR_VERSION > 1 || SDL_MIXER_MINOR_VERSION > 2 || SDL_MIXER_PATCHLEVEL >= 10
2970 int i, num = Mix_GetNumChunkDecoders ();
2971 EXTEND (SP, num);
2972 for (i = 0; i < num; ++i)
2973 PUSHs (sv_2mortal (newSVpv (Mix_GetChunkDecoder (i), 0)));
2974#else
2975 XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0)));
2976#endif
2977
2731DC::MixChunk 2978DC::MixChunk
2732new (SV *class, DC::RW rwops) 2979new (SV *klass, DC::RW rwops)
2733 CODE: 2980 CODE:
2734 RETVAL = Mix_LoadWAV_RW (rwops, 1); 2981 RETVAL = Mix_LoadWAV_RW (rwops, 1);
2735 OUTPUT: 2982 OUTPUT:
2736 RETVAL 2983 RETVAL
2737 2984
2767 OUTPUT: 3014 OUTPUT:
2768 RETVAL 3015 RETVAL
2769 3016
2770MODULE = Deliantra::Client PACKAGE = DC::MixMusic 3017MODULE = Deliantra::Client PACKAGE = DC::MixMusic
2771 3018
3019void
3020decoders ()
3021 PPCODE:
3022#if SDL_MIXER_MAJOR_VERSION > 1 || SDL_MIXER_MINOR_VERSION > 2 || SDL_MIXER_PATCHLEVEL >= 10
3023 int i, num = Mix_GetNumMusicDecoders ();
3024 EXTEND (SP, num);
3025 for (i = 0; i < num; ++i)
3026 PUSHs (sv_2mortal (newSVpv (Mix_GetMusicDecoder (i), 0)));
3027#else
3028 XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0)));
3029#endif
3030
2772int 3031int
2773volume (int volume = -1) 3032volume (int volume = -1)
2774 PROTOTYPE: ;$ 3033 PROTOTYPE: ;$
2775 CODE: 3034 CODE:
2776 if (items > 0) 3035 if (items > 0)
2787void 3046void
2788halt () 3047halt ()
2789 CODE: 3048 CODE:
2790 Mix_HaltMusic (); 3049 Mix_HaltMusic ();
2791 3050
3051int
3052playing ()
3053 CODE:
3054 RETVAL = Mix_PlayingMusic ();
3055 OUTPUT:
3056 RETVAL
3057
2792DC::MixMusic 3058DC::MixMusic
2793new (SV *class, DC::RW rwops) 3059new (SV *klass, DC::RW rwops)
2794 CODE: 3060 CODE:
2795 RETVAL = Mix_LoadMUS_RW (rwops); 3061 RETVAL = Mix_LoadMUS_RW (rwops);
2796 OUTPUT: 3062 OUTPUT:
2797 RETVAL 3063 RETVAL
2798 3064
2826 } *civ, const_iv[] = { 3092 } *civ, const_iv[] = {
2827# define const_iv(name) { # name, (IV)name } 3093# define const_iv(name) { # name, (IV)name }
2828 const_iv (GL_VENDOR), 3094 const_iv (GL_VENDOR),
2829 const_iv (GL_VERSION), 3095 const_iv (GL_VERSION),
2830 const_iv (GL_EXTENSIONS), 3096 const_iv (GL_EXTENSIONS),
3097 const_iv (GL_MAX_TEXTURE_UNITS),
2831 const_iv (GL_COLOR_MATERIAL), 3098 const_iv (GL_COLOR_MATERIAL),
2832 const_iv (GL_SMOOTH), 3099 const_iv (GL_SMOOTH),
2833 const_iv (GL_FLAT), 3100 const_iv (GL_FLAT),
2834 const_iv (GL_DITHER), 3101 const_iv (GL_DITHER),
2835 const_iv (GL_BLEND), 3102 const_iv (GL_BLEND),
2847 const_iv (GL_ZERO), 3114 const_iv (GL_ZERO),
2848 const_iv (GL_SRC_ALPHA), 3115 const_iv (GL_SRC_ALPHA),
2849 const_iv (GL_DST_ALPHA), 3116 const_iv (GL_DST_ALPHA),
2850 const_iv (GL_ONE_MINUS_SRC_ALPHA), 3117 const_iv (GL_ONE_MINUS_SRC_ALPHA),
2851 const_iv (GL_ONE_MINUS_DST_ALPHA), 3118 const_iv (GL_ONE_MINUS_DST_ALPHA),
3119 const_iv (GL_SRC_COLOR),
3120 const_iv (GL_DST_COLOR),
3121 const_iv (GL_ONE_MINUS_SRC_COLOR),
3122 const_iv (GL_ONE_MINUS_DST_COLOR),
2852 const_iv (GL_SRC_ALPHA_SATURATE), 3123 const_iv (GL_SRC_ALPHA_SATURATE),
2853 const_iv (GL_RGB), 3124 const_iv (GL_RGB),
2854 const_iv (GL_RGBA), 3125 const_iv (GL_RGBA),
2855 const_iv (GL_RGBA4), 3126 const_iv (GL_RGBA4),
2856 const_iv (GL_RGBA8), 3127 const_iv (GL_RGBA8),
2924 const_iv (GL_NICEST), 3195 const_iv (GL_NICEST),
2925 const_iv (GL_V2F), 3196 const_iv (GL_V2F),
2926 const_iv (GL_V3F), 3197 const_iv (GL_V3F),
2927 const_iv (GL_T2F_V3F), 3198 const_iv (GL_T2F_V3F),
2928 const_iv (GL_T2F_N3F_V3F), 3199 const_iv (GL_T2F_N3F_V3F),
3200 const_iv (GL_FUNC_ADD),
3201 const_iv (GL_FUNC_SUBTRACT),
3202 const_iv (GL_FUNC_REVERSE_SUBTRACT),
2929# undef const_iv 3203# undef const_iv
2930 }; 3204 };
2931 3205
2932 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 3206 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
2933 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 3207 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
2934 3208
2935 texture_av = newAV (); 3209 texture_av = newAV ();
2936 AvREAL_off (texture_av); 3210 AvREAL_off (texture_av);
2937} 3211}
2938 3212
2940disable_GL_EXT_blend_func_separate () 3214disable_GL_EXT_blend_func_separate ()
2941 CODE: 3215 CODE:
2942 gl.BlendFuncSeparate = 0; 3216 gl.BlendFuncSeparate = 0;
2943 gl.BlendFuncSeparateEXT = 0; 3217 gl.BlendFuncSeparateEXT = 0;
2944 3218
2945char * 3219void
3220apple_nvidia_bug (int enable)
3221
3222const char *
2946gl_vendor () 3223gl_vendor ()
2947 CODE: 3224 CODE:
2948 RETVAL = (char *)glGetString (GL_VENDOR); 3225 RETVAL = (const char *)glGetString (GL_VENDOR);
2949 OUTPUT: 3226 OUTPUT:
2950 RETVAL 3227 RETVAL
2951 3228
2952char * 3229const char *
2953gl_version () 3230gl_version ()
2954 CODE: 3231 CODE:
2955 RETVAL = (char *)glGetString (GL_VERSION); 3232 RETVAL = (const char *)glGetString (GL_VERSION);
2956 OUTPUT: 3233 OUTPUT:
2957 RETVAL 3234 RETVAL
2958 3235
2959char * 3236const char *
2960gl_extensions () 3237gl_extensions ()
2961 CODE: 3238 CODE:
2962 RETVAL = (char *)glGetString (GL_EXTENSIONS); 3239 RETVAL = (const char *)glGetString (GL_EXTENSIONS);
2963 OUTPUT: 3240 OUTPUT:
2964 RETVAL 3241 RETVAL
2965 3242
2966const char *glGetString (GLenum pname) 3243const char *glGetString (GLenum pname)
3244 CODE:
3245 RETVAL = (const char *)glGetString (pname);
3246 OUTPUT:
3247 RETVAL
2967 3248
2968GLint glGetInteger (GLenum pname) 3249GLint glGetInteger (GLenum pname)
2969 CODE: 3250 CODE:
2970 glGetIntegerv (pname, &RETVAL); 3251 glGetIntegerv (pname, &RETVAL);
2971 OUTPUT: 3252 OUTPUT:
2979 3260
2980int glGetError () 3261int glGetError ()
2981 3262
2982void glFinish () 3263void glFinish ()
2983 3264
3265void glFlush ()
3266
2984void glClear (int mask) 3267void glClear (int mask)
2985 3268
2986void glClearColor (float r, float g, float b, float a = 1.0) 3269void glClearColor (float r, float g, float b, float a = 1.0)
2987 PROTOTYPE: @ 3270 PROTOTYPE: @
2988 3271
2997void glBlendFunc (int sfactor, int dfactor) 3280void glBlendFunc (int sfactor, int dfactor)
2998 3281
2999void glBlendFuncSeparate (int sa, int da, int saa, int daa) 3282void glBlendFuncSeparate (int sa, int da, int saa, int daa)
3000 CODE: 3283 CODE:
3001 gl_BlendFuncSeparate (sa, da, saa, daa); 3284 gl_BlendFuncSeparate (sa, da, saa, daa);
3285
3286# void glBlendEquation (int se)
3002 3287
3003void glDepthMask (int flag) 3288void glDepthMask (int flag)
3004 3289
3005void glLogicOp (int opcode) 3290void glLogicOp (int opcode)
3006 3291
3157 3442
3158void glEndList () 3443void glEndList ()
3159 3444
3160void glCallList (int list) 3445void glCallList (int list)
3161 3446
3447void c_init ()
3448 CODE:
3449 glPixelStorei (GL_PACK_ALIGNMENT , 1);
3450 glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
3451
3162MODULE = Deliantra::Client PACKAGE = DC::UI::Base 3452MODULE = Deliantra::Client PACKAGE = DC::UI::Base
3163 3453
3164PROTOTYPES: DISABLE 3454PROTOTYPES: DISABLE
3165 3455
3166void 3456void
3167find_widget (SV *self, NV x, NV y) 3457find_widget (SV *self, NV x, NV y)
3168 PPCODE: 3458 PPCODE:
3169{ 3459{
3170 if (within_widget (self, x, y)) 3460 if (within_widget (self, x, y))
3171 XPUSHs (self); 3461 XPUSHs (self);
3172} 3462}
3173 3463
3174BOOT: 3464BOOT:
3175{ 3465{
3183 3473
3184void 3474void
3185draw (SV *self) 3475draw (SV *self)
3186 CODE: 3476 CODE:
3187{ 3477{
3188 HV *hv; 3478 HV *hv;
3189 SV **svp; 3479 SV **svp;
3190 NV x, y, w, h; 3480 NV x, y, w, h;
3191 SV *draw_x_sv = GvSV (draw_x_gv); 3481 SV *draw_x_sv = GvSV (draw_x_gv);
3192 SV *draw_y_sv = GvSV (draw_y_gv); 3482 SV *draw_y_sv = GvSV (draw_y_gv);
3193 SV *draw_w_sv = GvSV (draw_w_gv); 3483 SV *draw_w_sv = GvSV (draw_w_gv);
3194 SV *draw_h_sv = GvSV (draw_h_gv); 3484 SV *draw_h_sv = GvSV (draw_h_gv);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines