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.225 by root, Sat Aug 11 12:07:54 2007 UTC vs.
Revision 1.326 by root, Sun Nov 18 03:06:13 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>
37#include <bitset>
34 38
35#define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW 39#define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW
36 40
37#include <SDL.h> 41#include <SDL.h>
38#include <SDL_thread.h> 42#include <SDL_thread.h>
39#include <SDL_endian.h> 43#include <SDL_endian.h>
40#include <SDL_image.h> 44#include <SDL_image.h>
41#include <SDL_mixer.h> 45#include <SDL_mixer.h>
42#include <SDL_opengl.h> 46#include <SDL_opengl.h>
43 47
48/* work around os x broken headers */
49#ifdef __MACOSX__
50typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
51typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture);
52typedef void (APIENTRYP PFNGLMULTITEXCOORD2FPROC) (GLenum target, GLfloat s, GLfloat t);
53#endif
54
44#define PANGO_ENABLE_BACKEND 55#define PANGO_ENABLE_BACKEND
45#define G_DISABLE_CAST_CHECKS 56#define G_DISABLE_CAST_CHECKS
46 57
47#include <glib/gmacros.h> 58#include <glib.h>
48 59
49#include <pango/pango.h> 60#include <pango/pango.h>
61
62#ifndef PANGO_VERSION_CHECK
63# define PANGO_VERSION_CHECK(a,b,c) 0
64#endif
65
66#if !PANGO_VERSION_CHECK (1, 15, 2)
67# define pango_layout_get_line_readonly pango_layout_get_line
68# define pango_layout_get_lines_readonly pango_layout_get_lines
69# define pango_layout_iter_get_line_readonly pango_layout_iter_get_line
70# define pango_layout_iter_get_run_readonly pango_layout_iter_get_run
71#endif
50 72
51#ifndef _WIN32 73#ifndef _WIN32
52# include <sys/types.h> 74# include <sys/types.h>
53# include <sys/socket.h> 75# include <sys/socket.h>
54# include <netinet/in.h> 76# include <netinet/in.h>
55# include <netinet/tcp.h> 77# include <netinet/tcp.h>
56# include <inttypes.h> 78# include <inttypes.h>
57#endif 79#endif
58 80
81#if __GNUC__ >= 4
82# define expect(expr,value) __builtin_expect ((expr),(value))
83#else
84# define expect(expr,value) (expr)
85#endif
86
87#define expect_false(expr) expect ((expr) != 0, 0)
88#define expect_true(expr) expect ((expr) != 0, 1)
89
59#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ 90#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */
60 91
92/* this is used as fow flag as well, so has to have a different value */
93/* then anything that is computed by incoming darkness */
61#define FOW_DARKNESS 32 94#define FOW_DARKNESS 50
95#define DARKNESS_ADJUST(n) (n)
62 96
63#define MAP_EXTEND_X 32 97#define MAP_EXTEND_X 32
64#define MAP_EXTEND_Y 512 98#define MAP_EXTEND_Y 512
65 99
66#define MIN_FONT_HEIGHT 10 100#define MIN_FONT_HEIGHT 10
67 101
68#if 0 102/* mask out modifiers we are not interested in */
69# define PARACHUTE SDL_INIT_NOPARACHUTE 103#define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META)
70#else 104
71# define PARACHUTE 0 105#define KMOD_LRAM 0x10000 // our extension
72#endif 106
107#define TEXID_SPEECH 1
108#define TEXID_NOFACE 2
109
110static char *
111fast_sv_grow (SV *sv, STRLEN need)
112{
113 STRLEN len = SvLEN (sv);
114 STRLEN want = SvCUR (sv) + need;
115
116 if (expect_false (len < want))
117 {
118 do
119 len *= 2;
120 while (len < want);
121
122 sv_grow (sv, len);
123 }
124
125 SvCUR_set (sv, want);
126 return SvEND (sv) - need;
127}
73 128
74static AV *texture_av; 129static AV *texture_av;
75 130
76static struct 131static struct
77{ 132{
120 175
121#include "pango-font.c" 176#include "pango-font.c"
122#include "pango-fontmap.c" 177#include "pango-fontmap.c"
123#include "pango-render.c" 178#include "pango-render.c"
124 179
125typedef IV CFPlus__Channel; 180typedef IV DC__Channel;
126typedef SDL_RWops *CFPlus__RW; 181typedef SDL_RWops *DC__RW;
127typedef Mix_Chunk *CFPlus__MixChunk; 182typedef Mix_Chunk *DC__MixChunk;
128typedef Mix_Music *CFPlus__MixMusic; 183typedef Mix_Music *DC__MixMusic;
129 184
130typedef PangoFontDescription *CFPlus__Font; 185typedef PangoFontDescription *DC__Font;
131 186
132static int 187static int
133shape_attr_p (PangoLayoutRun *run) 188shape_attr_p (PangoLayoutRun *run)
134{ 189{
135 GSList *attrs = run->item->analysis.extra_attrs; 190 GSList *attrs = run->item->analysis.extra_attrs;
136 191
137 while (attrs) 192 while (attrs)
138 { 193 {
139 PangoAttribute *attr = attrs->data; 194 PangoAttribute *attr = (PangoAttribute *)attrs->data;
140 195
141 if (attr->klass->type == PANGO_ATTR_SHAPE) 196 if (attr->klass->type == PANGO_ATTR_SHAPE)
142 return 1; 197 return 1;
143 198
144 attrs = attrs->next; 199 attrs = attrs->next;
145 } 200 }
146 201
147 return 0; 202 return 0;
148} 203}
149 204
150typedef struct cf_layout { 205struct cf_layout {
151 PangoLayout *pl; 206 PangoLayout *pl;
152 float r, g, b, a; // default color for rgba mode 207 float r, g, b, a; // default color for rgba mode
153 int base_height; 208 int base_height;
154 CFPlus__Font font; 209 DC__Font font;
155 rc_t *rc; 210 rc_t rc;
156} *CFPlus__Layout; 211};
157 212
213typedef cf_layout *DC__Layout;
214
158static CFPlus__Font default_font; 215static DC__Font default_font;
159static PangoContext *opengl_context; 216static PangoContext *opengl_context;
160static PangoFontMap *opengl_fontmap; 217static PangoFontMap *opengl_fontmap;
161 218
162static void 219static void
163substitute_func (FcPattern *pattern, gpointer data) 220substitute_func (FcPattern *pattern, gpointer data)
164{ 221{
165 FcPatternAddBool (pattern, FC_HINTING, 1); 222 FcPatternAddBool (pattern, FC_HINTING, 1);
166#ifdef FC_HINT_STYLE 223#ifdef FC_HINT_STYLE
167 FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); 224 FcPatternAddInteger (pattern, FC_HINT_STYLE, FC_HINT_FULL);
168#endif 225#endif
169 FcPatternAddBool (pattern, FC_AUTOHINT, 0); 226 FcPatternAddBool (pattern, FC_AUTOHINT, 0);
170} 227}
171 228
172static void 229static void
173layout_update_font (CFPlus__Layout self) 230layout_update_font (DC__Layout self)
174{ 231{
175 /* use a random scale factor to account for unknown descenders, 0.8 works 232 /* use a random scale factor to account for unknown descenders, 0.8 works
176 * reasonably well with bitstream vera 233 * reasonably well with dejavu/bistream fonts
177 */ 234 */
178 PangoFontDescription *font = self->font ? self->font : default_font; 235 PangoFontDescription *font = self->font ? self->font : default_font;
179 236
180 pango_font_description_set_absolute_size (font, 237 pango_font_description_set_absolute_size (font,
181 MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10)); 238 MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10));
182 239
183 pango_layout_set_font_description (self->pl, font); 240 pango_layout_set_font_description (self->pl, font);
184} 241}
185 242
186static void 243static void
187layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) 244layout_get_pixel_size (DC__Layout self, int *w, int *h)
188{ 245{
189 PangoRectangle rect; 246 PangoRectangle rect;
190 247
191 // get_pixel_* wrongly rounds down 248 // get_pixel_* wrongly rounds down
192 pango_layout_get_extents (self->pl, 0, &rect); 249 pango_layout_get_extents (self->pl, 0, &rect);
202} 259}
203 260
204typedef uint16_t tileid; 261typedef uint16_t tileid;
205typedef uint16_t faceid; 262typedef uint16_t faceid;
206 263
207typedef struct { 264struct maptex
265{
208 int name; 266 GLuint name;
209 int w, h; 267 int w, h;
210 float s, t; 268 float s, t;
211 uint8_t r, g, b, a; 269 uint8_t r, g, b, a;
212 tileid smoothtile; 270 tileid smoothtile;
213 uint8_t smoothlevel; 271 uint8_t smoothlevel;
214} maptex; 272 uint8_t unused; /* set to zero on use */
273};
215 274
216typedef struct { 275struct mapcell
276{
217 uint32_t player; 277 uint32_t player;
218 tileid tile[3]; 278 tileid tile[3];
219 uint16_t darkness; 279 uint16_t darkness;
220 uint8_t stat_width, stat_hp, flags, smoothmax; 280 uint8_t stat_width, stat_hp, flags, smoothmax;
221} mapcell; 281};
222 282
223typedef struct { 283struct maprow
284{
224 int32_t c0, c1; 285 int32_t c0, c1;
225 mapcell *col; 286 mapcell *col;
226} maprow; 287};
227 288
228typedef struct map { 289struct mapgrid {
229 int x, y, w, h; 290 int x, y, w, h;
230 int ox, oy; /* offset to virtual global coordinate system */ 291 int ox, oy; /* offset to virtual global coordinate system */
231 int faces; tileid *face2tile; // [faceid] 292 int faces; tileid *face2tile; // [faceid]
232 int texs; maptex *tex; // [tileid] 293 int texs; maptex *tex; // [tileid]
233 294
234 int32_t rows; 295 int32_t rows;
235 maprow *row; 296 maprow *row;
236} *CFPlus__Map; 297};
298
299typedef mapgrid *DC__Map;
237 300
238static char * 301static char *
239prepend (char *ptr, int sze, int inc) 302prepend (char *ptr, int sze, int inc)
240{ 303{
241 char *p; 304 char *p;
259 322
260#define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) 323#define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
261#define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) 324#define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
262 325
263static void 326static void
264need_facenum (struct map *self, faceid face) 327need_facenum (struct mapgrid *self, faceid face)
265{ 328{
266 while (self->faces <= face) 329 while (self->faces <= face)
267 { 330 {
268 Append (tileid, self->face2tile, self->faces, self->faces); 331 Append (tileid, self->face2tile, self->faces, self->faces);
269 self->faces *= 2; 332 self->faces *= 2;
270 } 333 }
271} 334}
272 335
273static void 336static void
274need_texid (struct map *self, int texid) 337need_texid (struct mapgrid *self, int texid)
275{ 338{
276 while (self->texs <= texid) 339 while (self->texs <= texid)
277 { 340 {
278 Append (maptex, self->tex, self->texs, self->texs); 341 Append (maptex, self->tex, self->texs, self->texs);
279 self->texs *= 2; 342 self->texs *= 2;
280 } 343 }
281} 344}
282 345
283static maprow * 346static maprow *
284map_get_row (CFPlus__Map self, int y) 347map_get_row (mapgrid *self, int y)
285{ 348{
286 if (0 > y) 349 if (0 > y)
287 { 350 {
288 int extend = - y + MAP_EXTEND_Y; 351 int extend = - y + MAP_EXTEND_Y;
289 Prepend (maprow, self->row, self->rows, extend); 352 Prepend (maprow, self->row, self->rows, extend);
327 390
328 return row->col + (x - row->c0); 391 return row->col + (x - row->c0);
329} 392}
330 393
331static mapcell * 394static mapcell *
332map_get_cell (CFPlus__Map self, int x, int y) 395map_get_cell (mapgrid *self, int x, int y)
333{ 396{
334 return row_get_cell (map_get_row (self, y), x); 397 return row_get_cell (map_get_row (self, y), x);
335} 398}
336 399
337static void 400static void
338map_clear (CFPlus__Map self) 401map_clear (mapgrid *self)
339{ 402{
340 int r; 403 int r;
341 404
342 for (r = 0; r < self->rows; r++) 405 for (r = 0; r < self->rows; r++)
343 Safefree (self->row[r].col); 406 Safefree (self->row[r].col);
350 self->oy = 0; 413 self->oy = 0;
351 self->row = 0; 414 self->row = 0;
352 self->rows = 0; 415 self->rows = 0;
353} 416}
354 417
418#define CELL_CLEAR(cell) \
419 do { \
420 if ((cell)->player) \
421 (cell)->tile [2] = 0; \
422 (cell)->darkness = 0; \
423 (cell)->stat_hp = 0; \
424 (cell)->flags = 0; \
425 (cell)->player = 0; \
426 } while (0)
427
355static void 428static void
356map_blank (CFPlus__Map self, int x0, int y0, int w, int h) 429map_blank (mapgrid *self, int x0, int y0, int w, int h)
357{ 430{
358 int x, y; 431 int x, y;
359 maprow *row; 432 maprow *row;
360 mapcell *cell; 433 mapcell *cell;
361 434
373 if (x >= row->c1) 446 if (x >= row->c1)
374 break; 447 break;
375 448
376 cell = row->col + x - row->c0; 449 cell = row->col + x - row->c0;
377 450
378 cell->darkness = 0; 451 CELL_CLEAR (cell);
379 cell->stat_hp = 0;
380 cell->flags = 0;
381 cell->player = 0;
382 } 452 }
383 } 453 }
384} 454}
385 455
386typedef struct { 456struct smooth_key
457{
387 tileid tile; 458 tileid tile;
388 uint8_t x, y, level; 459 uint8_t x, y, level;
389} smooth_key; 460
461 bool operator == (const smooth_key &o) const
462 {
463 return tile == o.tile && x == o.x && y == o.y && level == o.level;
464 }
465};
466
467typedef ska::flat_hash_map<smooth_key, IV> smooth_hash;
468
469namespace std {
470 template <>
471 struct hash<smooth_key>
472 {
473 size_t operator () (const smooth_key &v) const
474 {
475 return v.tile + (v.x << 8) + (v.y << 16) + (v.level << 24);
476 }
477 };
478}
390 479
391static void 480static void
392smooth_or_bits (HV *hv, smooth_key *key, IV bits) 481smooth_or_bits (smooth_hash &h, smooth_key &key, IV bits)
393{ 482{
394 SV **sv = hv_fetch (hv, (char *)key, sizeof (*key), 1); 483 auto &&it = h.find (key);
395 484
396 if (SvIOK (*sv)) 485 if (it == h.end ())
397 SvIV_set (*sv, SvIVX (*sv) | bits); 486 h.insert (std::make_pair (key, bits));
398 else 487 else
399 sv_setiv (*sv, bits); 488 it->second |= bits;
400} 489}
401 490
402static void 491static void
403music_finished (void) 492music_finished (void)
404{ 493{
421 ev.code = 1; 510 ev.code = 1;
422 ev.data1 = (void *)(long)channel; 511 ev.data1 = (void *)(long)channel;
423 ev.data2 = 0; 512 ev.data2 = 0;
424 513
425 SDL_PushEvent ((SDL_Event *)&ev); 514 SDL_PushEvent ((SDL_Event *)&ev);
515}
516
517// approximately divide by 255
518static unsigned int
519div255 (unsigned int n)
520{
521 return (n + (n >> 8)) >> 8;
426} 522}
427 523
428static unsigned int 524static unsigned int
429minpot (unsigned int n) 525minpot (unsigned int n)
430{ 526{
440 n |= n >> 16; 536 n |= n >> 16;
441 537
442 return n + 1; 538 return n + 1;
443} 539}
444 540
541static unsigned int
542popcount (unsigned int n)
543{
544 n -= (n >> 1) & 0x55555555U;
545 n = ((n >> 2) & 0x33333333U) + (n & 0x33333333U);
546 n = ((n >> 4) + n) & 0x0f0f0f0fU;
547 n *= 0x01010101U;
548
549 return n >> 24;
550}
551
445/* SDL should provide this, really. */ 552/* SDL should provide this, really. */
446#define SDLK_MODIFIER_MIN 300 553#define SDLK_MODIFIER_MIN 300
447#define SDLK_MODIFIER_MAX 314 554#define SDLK_MODIFIER_MAX 314
448 555
449/******************************************************************************/ 556/******************************************************************************/
487 return 0; 594 return 0;
488 595
489 return 1; 596 return 1;
490} 597}
491 598
492MODULE = CFPlus PACKAGE = CFPlus 599/******************************************************************************/
600
601/* process keyboard modifiers */
602static int
603mod_munge (int mod)
604{
605 mod &= MOD_MASK;
606
607 if (mod & (KMOD_META | KMOD_ALT))
608 mod |= KMOD_LRAM;
609
610 return mod;
611}
612
613static void
614deliantra_main (SV *real_main)
615{
616 dSP;
617
618 PUSHMARK (SP);
619 call_sv (real_main, G_DISCARD | G_VOID);
620}
621
622#ifdef __MACOSX__
623 static SV *real_main;
624
625 /* to due surprising braindamage on the side of SDL design, we
626 * do some mind-boggling hack here: SDL requires a custom main()
627 * on OS X, so... we provide one and call the original main(), which,
628 * due to shared library magic, calls -lSDLmain's main, not perl's main,
629 * and which calls our main (== SDL_main) back.
630 */
631 extern C_LINKAGE int
632 main (int argc, char *argv[])
633 {
634 deliantra_main (real_main);
635 }
636
637 #undef main
638
639 extern C_LINKAGE int main (int argc, char *argv[]);
640
641 static void
642 SDL_main_hack (SV *real_main_)
643 {
644 real_main = real_main_;
645
646 char *argv[] = { "deliantra client", 0 };
647 (main) (1, argv);
648 }
649#else
650 static void
651 SDL_main_hack (SV *real_main)
652 {
653 deliantra_main (real_main);
654 }
655#endif
656
657MODULE = Deliantra::Client PACKAGE = DC
493 658
494PROTOTYPES: ENABLE 659PROTOTYPES: ENABLE
495 660
496BOOT: 661BOOT:
497{ 662{
498 HV *stash = gv_stashpv ("CFPlus", 1); 663 HV *stash = gv_stashpv ("DC", 1);
499 static const struct { 664 static const struct {
500 const char *name; 665 const char *name;
501 IV iv; 666 IV iv;
502 } *civ, const_iv[] = { 667 } *civ, const_iv[] = {
503# define const_iv(name) { # name, (IV)name } 668# define const_iv(name) { # name, (IV)name }
525 690
526 const_iv (SDL_APPINPUTFOCUS), 691 const_iv (SDL_APPINPUTFOCUS),
527 const_iv (SDL_APPMOUSEFOCUS), 692 const_iv (SDL_APPMOUSEFOCUS),
528 const_iv (SDL_APPACTIVE), 693 const_iv (SDL_APPACTIVE),
529 694
695
696 const_iv (SDLK_UNKNOWN),
697 const_iv (SDLK_FIRST),
698 const_iv (SDLK_BACKSPACE),
699 const_iv (SDLK_TAB),
700 const_iv (SDLK_CLEAR),
701 const_iv (SDLK_RETURN),
702 const_iv (SDLK_PAUSE),
703 const_iv (SDLK_ESCAPE),
704 const_iv (SDLK_SPACE),
705 const_iv (SDLK_EXCLAIM),
706 const_iv (SDLK_QUOTEDBL),
707 const_iv (SDLK_HASH),
708 const_iv (SDLK_DOLLAR),
709 const_iv (SDLK_AMPERSAND),
710 const_iv (SDLK_QUOTE),
711 const_iv (SDLK_LEFTPAREN),
712 const_iv (SDLK_RIGHTPAREN),
713 const_iv (SDLK_ASTERISK),
714 const_iv (SDLK_PLUS),
715 const_iv (SDLK_COMMA),
716 const_iv (SDLK_MINUS),
717 const_iv (SDLK_PERIOD),
718 const_iv (SDLK_SLASH),
719 const_iv (SDLK_0),
720 const_iv (SDLK_1),
721 const_iv (SDLK_2),
722 const_iv (SDLK_3),
723 const_iv (SDLK_4),
724 const_iv (SDLK_5),
725 const_iv (SDLK_6),
726 const_iv (SDLK_7),
727 const_iv (SDLK_8),
728 const_iv (SDLK_9),
729 const_iv (SDLK_COLON),
730 const_iv (SDLK_SEMICOLON),
731 const_iv (SDLK_LESS),
732 const_iv (SDLK_EQUALS),
733 const_iv (SDLK_GREATER),
734 const_iv (SDLK_QUESTION),
735 const_iv (SDLK_AT),
736
737 const_iv (SDLK_LEFTBRACKET),
738 const_iv (SDLK_BACKSLASH),
739 const_iv (SDLK_RIGHTBRACKET),
740 const_iv (SDLK_CARET),
741 const_iv (SDLK_UNDERSCORE),
742 const_iv (SDLK_BACKQUOTE),
743 const_iv (SDLK_DELETE),
744
745 const_iv (SDLK_FIRST),
746 const_iv (SDLK_LAST),
530 const_iv (SDLK_KP0), 747 const_iv (SDLK_KP0),
531 const_iv (SDLK_KP1), 748 const_iv (SDLK_KP1),
532 const_iv (SDLK_KP2), 749 const_iv (SDLK_KP2),
533 const_iv (SDLK_KP3), 750 const_iv (SDLK_KP3),
534 const_iv (SDLK_KP4), 751 const_iv (SDLK_KP4),
606 const_iv (KMOD_LMETA), 823 const_iv (KMOD_LMETA),
607 const_iv (KMOD_RMETA), 824 const_iv (KMOD_RMETA),
608 const_iv (KMOD_NUM), 825 const_iv (KMOD_NUM),
609 const_iv (KMOD_CAPS), 826 const_iv (KMOD_CAPS),
610 const_iv (KMOD_MODE), 827 const_iv (KMOD_MODE),
828
829 const_iv (KMOD_LRAM),
830
831 const_iv (MIX_DEFAULT_FORMAT),
832
833 const_iv (SDL_INIT_TIMER),
834 const_iv (SDL_INIT_AUDIO),
835 const_iv (SDL_INIT_VIDEO),
836 const_iv (SDL_INIT_CDROM),
837 const_iv (SDL_INIT_JOYSTICK),
838 const_iv (SDL_INIT_EVERYTHING),
839 const_iv (SDL_INIT_NOPARACHUTE),
840 const_iv (SDL_INIT_EVENTTHREAD),
841
842 const_iv (SDL_GL_RED_SIZE),
843 const_iv (SDL_GL_GREEN_SIZE),
844 const_iv (SDL_GL_BLUE_SIZE),
845 const_iv (SDL_GL_ALPHA_SIZE),
846 const_iv (SDL_GL_DOUBLEBUFFER),
847 const_iv (SDL_GL_BUFFER_SIZE),
848 const_iv (SDL_GL_DEPTH_SIZE),
849 const_iv (SDL_GL_STENCIL_SIZE),
850 const_iv (SDL_GL_ACCUM_RED_SIZE),
851 const_iv (SDL_GL_ACCUM_GREEN_SIZE),
852 const_iv (SDL_GL_ACCUM_BLUE_SIZE),
853 const_iv (SDL_GL_ACCUM_ALPHA_SIZE),
854 const_iv (SDL_GL_STEREO),
855 const_iv (SDL_GL_MULTISAMPLEBUFFERS),
856 const_iv (SDL_GL_MULTISAMPLESAMPLES),
857 const_iv (SDL_GL_ACCELERATED_VISUAL),
858 const_iv (SDL_GL_SWAP_CONTROL),
859
860 const_iv (FOW_DARKNESS)
611# undef const_iv 861# undef const_iv
612 }; 862 };
613 863
614 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 864 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
615 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 865 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
616 866
617 assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK); 867 assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK);
618 assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE); 868 assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE);
619} 869}
620 870
632 RETVAL 882 RETVAL
633 883
634NV floor (NV x) 884NV floor (NV x)
635 885
636NV ceil (NV x) 886NV ceil (NV x)
887
888IV minpot (UV n)
889
890IV popcount (UV n)
891
892NV distance (NV dx, NV dy)
893 CODE:
894 RETVAL = pow (dx * dx + dy * dy, 0.5);
895 OUTPUT:
896 RETVAL
637 897
638void 898void
639pango_init () 899pango_init ()
640 CODE: 900 CODE:
641{ 901{
642 opengl_fontmap = pango_opengl_font_map_new (); 902 opengl_fontmap = pango_opengl_font_map_new ();
643 pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); 903 pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0);
644 opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); 904 opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap);
905 /*pango_context_set_font_description (opengl_context, default_font);*/
906#if PANGO_VERSION_CHECK (1, 15, 2)
907 pango_context_set_language (opengl_context, pango_language_from_string ("en"));
908 /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/
909#endif
645} 910}
646 911
647char *
648SDL_GetError () 912char *SDL_GetError ()
649 913
650int 914void SDL_main_hack (SV *real_main)
651SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE) 915 PROTOTYPE: &
652 916
653void 917int SDL_Init (U32 flags)
918
919int SDL_InitSubSystem (U32 flags)
920
921void SDL_QuitSubSystem (U32 flags)
922
654SDL_Quit () 923void SDL_Quit ()
924
925int SDL_GL_SetAttribute (int attr, int value)
926 C_ARGS: (SDL_GLattr)attr, value
927
928int SDL_GL_GetAttribute (int attr)
929 CODE:
930 if (SDL_GL_GetAttribute ((SDL_GLattr)attr, &RETVAL))
931 XSRETURN_UNDEF;
932 OUTPUT:
933 RETVAL
655 934
656void 935void
657SDL_ListModes (int rgb, int alpha) 936SDL_ListModes (int rgb, int alpha)
658 PPCODE: 937 PPCODE:
659{ 938{
671 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); 950 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0);
672 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); 951 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0);
673 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); 952 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0);
674 953
675 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); 954 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
676#if SDL_VERSION_ATLEAST(1,2,10)
677 SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1);
678 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); 955 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
679#endif
680 956
681 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); 957 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL);
682 958
683 if (m && m != (SDL_Rect **)-1) 959 if (m && m != (SDL_Rect **)-1)
684 while (*m) 960 while (*m)
685 { 961 {
686 if ((*m)->w >= 640 && (*m)->h >= 480) 962 if ((*m)->w >= 400 && (*m)->h >= 300)
687 { 963 {
688 AV *av = newAV (); 964 AV *av = newAV ();
689 av_push (av, newSViv ((*m)->w)); 965 av_push (av, newSViv ((*m)->w));
690 av_push (av, newSViv ((*m)->h)); 966 av_push (av, newSViv ((*m)->h));
691 av_push (av, newSViv (rgb)); 967 av_push (av, newSViv (rgb));
714 ); 990 );
715 991
716 if (RETVAL) 992 if (RETVAL)
717 { 993 {
718 av_clear (texture_av); 994 av_clear (texture_av);
719
720 SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+");
721#define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); 995#define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name);
722#include "glfunc.h" 996#include "glfunc.h"
723#undef GL_FUNC 997#undef GL_FUNC
998 if (!gl.ActiveTexture ) gl.ActiveTexture = gl.ActiveTextureARB;
999 if (!gl.MultiTexCoord2f) gl.MultiTexCoord2f = gl.MultiTexCoord2fARB;
724 } 1000 }
725} 1001}
726 OUTPUT: 1002 OUTPUT:
727 RETVAL 1003 RETVAL
1004
1005void
1006SDL_WM_SetCaption (const char *title, const char *icon)
728 1007
729void 1008void
730SDL_GL_SwapBuffers () 1009SDL_GL_SwapBuffers ()
731 1010
732char * 1011char *
733SDL_GetKeyName (int sym) 1012SDL_GetKeyName (int sym)
1013 C_ARGS: (SDLKey)sym
734 1014
735int 1015int
736SDL_GetAppState () 1016SDL_GetAppState ()
737 1017
1018int
1019SDL_GetModState ()
1020
1021int
1022SDL_WaitEvent ()
1023 C_ARGS: 0
1024
738void 1025void
1026SDL_PumpEvents ()
1027
1028void
739poll_events () 1029peep_events ()
740 PPCODE: 1030 PPCODE:
741{ 1031{
742 SDL_Event ev; 1032 SDL_Event ev;
743 1033
744 SDL_PumpEvents (); 1034 SDL_PumpEvents ();
751 { 1041 {
752 case SDL_KEYDOWN: 1042 case SDL_KEYDOWN:
753 case SDL_KEYUP: 1043 case SDL_KEYUP:
754 hv_store (hv, "state", 5, newSViv (ev.key.state), 0); 1044 hv_store (hv, "state", 5, newSViv (ev.key.state), 0);
755 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); 1045 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0);
756 hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0); 1046 hv_store (hv, "mod", 3, newSViv (mod_munge (ev.key.keysym.mod)), 0);
757 hv_store (hv, "cmod", 4, newSViv (SDL_GetModState ()), 0); /* current mode */ 1047 hv_store (hv, "cmod", 4, newSViv (mod_munge (SDL_GetModState ())), 0); /* current mode */
758 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); 1048 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0);
759 break; 1049 break;
760 1050
761 case SDL_ACTIVEEVENT: 1051 case SDL_ACTIVEEVENT:
762 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); 1052 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0);
780 x = ev.motion.x; 1070 x = ev.motion.x;
781 y = ev.motion.y; 1071 y = ev.motion.y;
782 SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); 1072 SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION));
783 } 1073 }
784 1074
785 hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); 1075 hv_store (hv, "mod", 3, newSViv (mod_munge (SDL_GetModState ())), 0);
786 hv_store (hv, "state", 5, newSViv (state), 0); 1076 hv_store (hv, "state", 5, newSViv (state), 0);
787 hv_store (hv, "x", 1, newSViv (x), 0); 1077 hv_store (hv, "x", 1, newSViv (x), 0);
788 hv_store (hv, "y", 1, newSViv (y), 0); 1078 hv_store (hv, "y", 1, newSViv (y), 0);
789 hv_store (hv, "xrel", 4, newSViv (xrel), 0); 1079 hv_store (hv, "xrel", 4, newSViv (xrel), 0);
790 hv_store (hv, "yrel", 4, newSViv (yrel), 0); 1080 hv_store (hv, "yrel", 4, newSViv (yrel), 0);
791 } 1081 }
792 break; 1082 break;
793 1083
794 case SDL_MOUSEBUTTONDOWN: 1084 case SDL_MOUSEBUTTONDOWN:
795 case SDL_MOUSEBUTTONUP: 1085 case SDL_MOUSEBUTTONUP:
796 hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); 1086 hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0);
797 1087
798 hv_store (hv, "button", 6, newSViv (ev.button.button), 0); 1088 hv_store (hv, "button", 6, newSViv (ev.button.button), 0);
799 hv_store (hv, "state", 5, newSViv (ev.button.state), 0); 1089 hv_store (hv, "state", 5, newSViv (ev.button.state), 0);
800 hv_store (hv, "x", 1, newSViv (ev.button.x), 0); 1090 hv_store (hv, "x", 1, newSViv (ev.button.x), 0);
801 hv_store (hv, "y", 1, newSViv (ev.button.y), 0); 1091 hv_store (hv, "y", 1, newSViv (ev.button.y), 0);
806 hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); 1096 hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0);
807 hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); 1097 hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0);
808 break; 1098 break;
809 } 1099 }
810 1100
811 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); 1101 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("DC::UI::Event", 1))));
812 } 1102 }
813} 1103}
814 1104
1105char *
1106SDL_AudioDriverName ()
1107 CODE:
1108{
1109 char buf [256];
1110 if (!SDL_AudioDriverName (buf, sizeof (buf)))
1111 XSRETURN_UNDEF;
1112
1113 RETVAL = buf;
1114}
1115 OUTPUT:
1116 RETVAL
1117
815int 1118int
816Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 1024) 1119Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096)
817 POSTCALL: 1120 POSTCALL:
818 Mix_HookMusicFinished (music_finished); 1121 Mix_HookMusicFinished (music_finished);
819 Mix_ChannelFinished (channel_finished); 1122 Mix_ChannelFinished (channel_finished);
1123
1124void
1125Mix_QuerySpec ()
1126 PPCODE:
1127{
1128 int freq, channels;
1129 Uint16 format;
1130
1131 if (Mix_QuerySpec (&freq, &format, &channels))
1132 {
1133 EXTEND (SP, 3);
1134 PUSHs (sv_2mortal (newSViv (freq)));
1135 PUSHs (sv_2mortal (newSViv (format)));
1136 PUSHs (sv_2mortal (newSViv (channels)));
1137 }
1138}
820 1139
821void 1140void
822Mix_CloseAudio () 1141Mix_CloseAudio ()
823 1142
824int 1143int
859 } 1178 }
860 } 1179 }
861#endif 1180#endif
862} 1181}
863 1182
864void 1183int
865add_font (char *file) 1184add_font (char *file)
866 CODE: 1185 CODE:
867 FcConfigAppFontAddFile (0, (const FcChar8 *)file); 1186 RETVAL = FcConfigAppFontAddFile (0, (const FcChar8 *)file);
1187 OUTPUT:
1188 RETVAL
1189
1190void
1191IMG_Init (int flags = IMG_INIT_JPG | IMG_INIT_PNG)
1192
1193# MIX_INIT_MP3 gives smpeg + libstdc++ + libgcc_s
1194void
1195Mix_Init (int flags = MIX_INIT_MOD | MIX_INIT_OGG)
868 1196
869void 1197void
870load_image_inline (SV *image_) 1198load_image_inline (SV *image_)
871 ALIAS: 1199 ALIAS:
872 load_image_file = 1 1200 load_image_file = 1
918 1246
919 SDL_LockSurface (surface2); 1247 SDL_LockSurface (surface2);
920 EXTEND (SP, 6); 1248 EXTEND (SP, 6);
921 PUSHs (sv_2mortal (newSViv (surface2->w))); 1249 PUSHs (sv_2mortal (newSViv (surface2->w)));
922 PUSHs (sv_2mortal (newSViv (surface2->h))); 1250 PUSHs (sv_2mortal (newSViv (surface2->h)));
923 PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); 1251 PUSHs (sv_2mortal (newSVpvn ((const char *)surface2->pixels, surface2->h * surface2->pitch)));
924 PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); 1252 PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB)));
925 PUSHs (sv_2mortal (newSViv (GL_RGBA))); 1253 PUSHs (sv_2mortal (newSViv (GL_RGBA)));
926 PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); 1254 PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE)));
927 SDL_UnlockSurface (surface2); 1255 SDL_UnlockSurface (surface2);
928 1256
958void 1286void
959error (char *message) 1287error (char *message)
960 CODE: 1288 CODE:
961 fprintf (stderr, "ERROR: %s\n", message); 1289 fprintf (stderr, "ERROR: %s\n", message);
962#ifdef _WIN32 1290#ifdef _WIN32
963 MessageBox (0, message, "Crossfire+ Error", MB_OK | MB_ICONERROR); 1291 MessageBox (0, message, "Deliantra Client Error", MB_OK | MB_ICONERROR);
964#endif 1292#endif
965 1293
966void 1294void
967fatal (char *message) 1295fatal (char *message)
968 CODE: 1296 CODE:
969 fprintf (stderr, "FATAL: %s\n", message); 1297 fprintf (stderr, "FATAL: %s\n", message);
970#ifdef _WIN32 1298#ifdef _WIN32
971 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); 1299 MessageBox (0, message, "Deliantra Client Fatal Error", MB_OK | MB_ICONERROR);
972#endif 1300#endif
973 _exit (1); 1301 _exit (1);
974 1302
975void 1303void
976_exit (int retval = 0) 1304_exit (int retval = 0)
988#if DEBUG 1316#if DEBUG
989 VALGRIND_DO_LEAK_CHECK; 1317 VALGRIND_DO_LEAK_CHECK;
990#endif 1318#endif
991} 1319}
992 1320
993MODULE = CFPlus PACKAGE = CFPlus::Font 1321int
1322SvREFCNT (SV *sv)
1323 CODE:
1324 RETVAL = SvREFCNT (sv);
1325 OUTPUT:
1326 RETVAL
1327
1328MODULE = Deliantra::Client PACKAGE = DC::Font
994 1329
995PROTOTYPES: DISABLE 1330PROTOTYPES: DISABLE
996 1331
997CFPlus::Font 1332DC::Font
998new_from_file (SV *class, char *path, int id = 0) 1333new_from_file (SV *klass, char *path, int id = 0)
999 CODE: 1334 CODE:
1000{ 1335{
1001 int count; 1336 int count;
1002 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); 1337 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count);
1003 RETVAL = pango_fc_font_description_from_pattern (pattern, 0); 1338 RETVAL = pango_fc_font_description_from_pattern (pattern, 0);
1005} 1340}
1006 OUTPUT: 1341 OUTPUT:
1007 RETVAL 1342 RETVAL
1008 1343
1009void 1344void
1010DESTROY (CFPlus::Font self) 1345DESTROY (DC::Font self)
1011 CODE: 1346 CODE:
1012 pango_font_description_free (self); 1347 pango_font_description_free (self);
1013 1348
1014void 1349void
1015make_default (CFPlus::Font self) 1350make_default (DC::Font self)
1016 PROTOTYPE: $ 1351 PROTOTYPE: $
1017 CODE: 1352 CODE:
1018 default_font = self; 1353 default_font = self;
1019 1354
1020MODULE = CFPlus PACKAGE = CFPlus::Layout 1355MODULE = Deliantra::Client PACKAGE = DC::Layout
1021 1356
1022PROTOTYPES: DISABLE 1357PROTOTYPES: DISABLE
1023 1358
1024void 1359void
1025reset_glyph_cache () 1360glyph_cache_backup ()
1026 PROTOTYPE: 1361 PROTOTYPE:
1027 CODE: 1362 CODE:
1363 tc_backup ();
1364
1365void
1366glyph_cache_restore ()
1367 PROTOTYPE:
1368 CODE:
1028 tc_clear (); 1369 tc_restore ();
1029 1370
1030CFPlus::Layout 1371DC::Layout
1031new (SV *class) 1372new (SV *klass)
1032 CODE: 1373 CODE:
1033 New (0, RETVAL, 1, struct cf_layout); 1374 RETVAL = new cf_layout;
1034 1375
1035 RETVAL->pl = pango_layout_new (opengl_context); 1376 RETVAL->pl = pango_layout_new (opengl_context);
1036 RETVAL->r = 1.; 1377 RETVAL->r = 1.;
1037 RETVAL->g = 1.; 1378 RETVAL->g = 1.;
1038 RETVAL->b = 1.; 1379 RETVAL->b = 1.;
1039 RETVAL->a = 1.; 1380 RETVAL->a = 1.;
1040 RETVAL->base_height = MIN_FONT_HEIGHT; 1381 RETVAL->base_height = MIN_FONT_HEIGHT;
1041 RETVAL->font = 0; 1382 RETVAL->font = 0;
1042 RETVAL->rc = rc_alloc ();
1043 1383
1044 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); 1384 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR);
1045 layout_update_font (RETVAL); 1385 layout_update_font (RETVAL);
1046 OUTPUT: 1386 OUTPUT:
1047 RETVAL 1387 RETVAL
1048 1388
1049void 1389void
1050DESTROY (CFPlus::Layout self) 1390DESTROY (DC::Layout self)
1051 CODE: 1391 CODE:
1052 g_object_unref (self->pl); 1392 g_object_unref (self->pl);
1053 rc_free (self->rc);
1054 Safefree (self); 1393 delete self;
1055 1394
1056void 1395void
1057set_text (CFPlus::Layout self, SV *text_) 1396set_text (DC::Layout self, SV *text_)
1058 CODE: 1397 CODE:
1059{ 1398{
1060 STRLEN textlen; 1399 STRLEN textlen;
1061 char *text = SvPVutf8 (text_, textlen); 1400 char *text = SvPVutf8 (text_, textlen);
1062 1401
1063 pango_layout_set_text (self->pl, text, textlen); 1402 pango_layout_set_text (self->pl, text, textlen);
1064} 1403}
1065 1404
1066void 1405void
1067set_markup (CFPlus::Layout self, SV *text_) 1406set_markup (DC::Layout self, SV *text_)
1068 CODE: 1407 CODE:
1069{ 1408{
1070 STRLEN textlen; 1409 STRLEN textlen;
1071 char *text = SvPVutf8 (text_, textlen); 1410 char *text = SvPVutf8 (text_, textlen);
1072 1411
1073 pango_layout_set_markup (self->pl, text, textlen); 1412 pango_layout_set_markup (self->pl, text, textlen);
1074} 1413}
1075 1414
1076void 1415void
1077set_shapes (CFPlus::Layout self, ...) 1416set_shapes (DC::Layout self, ...)
1078 CODE: 1417 CODE:
1079{ 1418{
1080 PangoAttrList *attrs = 0; 1419 PangoAttrList *attrs = 0;
1081 const char *text = pango_layout_get_text (self->pl); 1420 const char *text = pango_layout_get_text (self->pl);
1082 const char *pos = text; 1421 const char *pos = text;
1117 if (attrs) 1456 if (attrs)
1118 pango_layout_set_attributes (self->pl, attrs); 1457 pango_layout_set_attributes (self->pl, attrs);
1119} 1458}
1120 1459
1121void 1460void
1122get_shapes (CFPlus::Layout self) 1461get_shapes (DC::Layout self)
1123 PPCODE: 1462 PPCODE:
1124{ 1463{
1125 PangoLayoutIter *iter = pango_layout_get_iter (self->pl); 1464 PangoLayoutIter *iter = pango_layout_get_iter (self->pl);
1126 1465
1127 do 1466 do
1128 { 1467 {
1129 PangoLayoutRun *run = pango_layout_iter_get_run (iter); 1468 PangoLayoutRun *run = pango_layout_iter_get_run_readonly (iter);
1130 1469
1131 if (run && shape_attr_p (run)) 1470 if (run && shape_attr_p (run))
1132 { 1471 {
1133 PangoRectangle extents; 1472 PangoRectangle extents;
1134 pango_layout_iter_get_run_extents (iter, 0, &extents); 1473 pango_layout_iter_get_run_extents (iter, 0, &extents);
1142 1481
1143 pango_layout_iter_free (iter); 1482 pango_layout_iter_free (iter);
1144} 1483}
1145 1484
1146int 1485int
1147has_wrapped (CFPlus::Layout self) 1486has_wrapped (DC::Layout self)
1148 CODE: 1487 CODE:
1149{ 1488{
1150 int lines = 1; 1489 int lines = 1;
1151 const char *text = pango_layout_get_text (self->pl); 1490 const char *text = pango_layout_get_text (self->pl);
1152 1491
1157} 1496}
1158 OUTPUT: 1497 OUTPUT:
1159 RETVAL 1498 RETVAL
1160 1499
1161SV * 1500SV *
1162get_text (CFPlus::Layout self) 1501get_text (DC::Layout self)
1163 CODE: 1502 CODE:
1164 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); 1503 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0);
1165 sv_utf8_decode (RETVAL); 1504 sv_utf8_decode (RETVAL);
1166 OUTPUT: 1505 OUTPUT:
1167 RETVAL 1506 RETVAL
1168 1507
1169void 1508void
1170set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.) 1509set_foreground (DC::Layout self, float r, float g, float b, float a = 1.)
1171 CODE: 1510 CODE:
1172 self->r = r; 1511 self->r = r;
1173 self->g = g; 1512 self->g = g;
1174 self->b = b; 1513 self->b = b;
1175 self->a = a; 1514 self->a = a;
1176 1515
1177void 1516void
1178set_font (CFPlus::Layout self, CFPlus::Font font = 0) 1517set_font (DC::Layout self, DC::Font font = 0)
1179 CODE: 1518 CODE:
1180 if (self->font != font) 1519 if (self->font != font)
1181 { 1520 {
1182 self->font = font; 1521 self->font = font;
1183 layout_update_font (self); 1522 layout_update_font (self);
1184 } 1523 }
1185 1524
1186void 1525void
1187set_height (CFPlus::Layout self, int base_height) 1526set_height (DC::Layout self, int base_height)
1188 CODE: 1527 CODE:
1189 if (self->base_height != base_height) 1528 if (self->base_height != base_height)
1190 { 1529 {
1191 self->base_height = base_height; 1530 self->base_height = base_height;
1192 layout_update_font (self); 1531 layout_update_font (self);
1193 } 1532 }
1194 1533
1195void 1534void
1196set_width (CFPlus::Layout self, int max_width = -1) 1535set_width (DC::Layout self, int max_width = -1)
1197 CODE: 1536 CODE:
1198 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); 1537 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE);
1199 1538
1200void 1539void
1201set_indent (CFPlus::Layout self, int indent) 1540set_indent (DC::Layout self, int indent)
1202 CODE: 1541 CODE:
1203 pango_layout_set_indent (self->pl, indent * PANGO_SCALE); 1542 pango_layout_set_indent (self->pl, indent * PANGO_SCALE);
1204 1543
1205void 1544void
1206set_spacing (CFPlus::Layout self, int spacing) 1545set_spacing (DC::Layout self, int spacing)
1207 CODE: 1546 CODE:
1208 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); 1547 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE);
1209 1548
1210void 1549void
1211set_ellipsise (CFPlus::Layout self, int ellipsise) 1550set_ellipsise (DC::Layout self, int ellipsise)
1212 CODE: 1551 CODE:
1213 pango_layout_set_ellipsize (self->pl, 1552 pango_layout_set_ellipsize (self->pl,
1214 ellipsise == 1 ? PANGO_ELLIPSIZE_START 1553 ellipsise == 1 ? PANGO_ELLIPSIZE_START
1215 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE 1554 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE
1216 : ellipsise == 3 ? PANGO_ELLIPSIZE_END 1555 : ellipsise == 3 ? PANGO_ELLIPSIZE_END
1217 : PANGO_ELLIPSIZE_NONE 1556 : PANGO_ELLIPSIZE_NONE
1218 ); 1557 );
1219 1558
1220void 1559void
1221set_single_paragraph_mode (CFPlus::Layout self, int spm) 1560set_single_paragraph_mode (DC::Layout self, int spm)
1222 CODE: 1561 CODE:
1223 pango_layout_set_single_paragraph_mode (self->pl, !!spm); 1562 pango_layout_set_single_paragraph_mode (self->pl, !!spm);
1224 1563
1225void 1564void
1226size (CFPlus::Layout self) 1565size (DC::Layout self)
1227 PPCODE: 1566 PPCODE:
1228{ 1567{
1229 int w, h; 1568 int w, h;
1230 1569
1231 layout_get_pixel_size (self, &w, &h); 1570 layout_get_pixel_size (self, &w, &h);
1234 PUSHs (sv_2mortal (newSViv (w))); 1573 PUSHs (sv_2mortal (newSViv (w)));
1235 PUSHs (sv_2mortal (newSViv (h))); 1574 PUSHs (sv_2mortal (newSViv (h)));
1236} 1575}
1237 1576
1238int 1577int
1239descent (CFPlus::Layout self) 1578descent (DC::Layout self)
1240 CODE: 1579 CODE:
1241{ 1580{
1242 PangoRectangle rect; 1581 PangoRectangle rect;
1243 PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); 1582 PangoLayoutLine *line = pango_layout_get_line_readonly (self->pl, 0);
1244 pango_layout_line_get_pixel_extents (line, 0, &rect); 1583 pango_layout_line_get_pixel_extents (line, 0, &rect);
1245 RETVAL = PANGO_DESCENT (rect); 1584 RETVAL = PANGO_DESCENT (rect);
1246} 1585}
1247 OUTPUT: 1586 OUTPUT:
1248 RETVAL 1587 RETVAL
1249 1588
1250int 1589int
1251xy_to_index (CFPlus::Layout self, int x, int y) 1590xy_to_index (DC::Layout self, int x, int y)
1252 CODE: 1591 CODE:
1253{ 1592{
1254 int index, trailing; 1593 int index, trailing;
1255 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); 1594 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing);
1256 RETVAL = index + trailing; 1595 RETVAL = index + trailing;
1257} 1596}
1258 OUTPUT: 1597 OUTPUT:
1259 RETVAL 1598 RETVAL
1260 1599
1261void 1600void
1262cursor_pos (CFPlus::Layout self, int index) 1601cursor_pos (DC::Layout self, int index)
1263 PPCODE: 1602 PPCODE:
1264{ 1603{
1265 PangoRectangle strong_pos; 1604 PangoRectangle pos;
1266 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); 1605 pango_layout_get_cursor_pos (self->pl, index, &pos, 0);
1267 1606
1268 EXTEND (SP, 3); 1607 EXTEND (SP, 3);
1269 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); 1608 PUSHs (sv_2mortal (newSViv (pos.x / PANGO_SCALE)));
1270 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1609 PUSHs (sv_2mortal (newSViv (pos.y / PANGO_SCALE)));
1271 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); 1610 PUSHs (sv_2mortal (newSViv (pos.height / PANGO_SCALE)));
1272} 1611}
1273 1612
1274void 1613void
1275index_to_line_x (CFPlus::Layout self, int index, int trailing = 0) 1614index_to_line_x (DC::Layout self, int index, int trailing = 0)
1276 PPCODE: 1615 PPCODE:
1277{ 1616{
1278 int line, x; 1617 int line, x;
1279 1618
1280 pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); 1619 pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x);
1620#if !PANGO_VERSION_CHECK (1, 17, 3)
1281 /* pango bug: line is between 1..numlines, not 0..numlines-1 */ 1621 /* pango bug: line is between 1..numlines, not 0..numlines-1 */
1282 1622 --line;
1623#endif
1283 EXTEND (SP, 2); 1624 EXTEND (SP, 2);
1284 PUSHs (sv_2mortal (newSViv (line - 1))); 1625 PUSHs (sv_2mortal (newSViv (line)));
1285 PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); 1626 PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE)));
1286} 1627}
1287 1628
1288void 1629void
1289line_x_to_index (CFPlus::Layout self, int line, int x) 1630line_x_to_index (DC::Layout self, int line, int x)
1290 PPCODE: 1631 PPCODE:
1291{ 1632{
1292 PangoLayoutLine *lp; 1633 PangoLayoutLine *lp;
1293 int index, trailing; 1634 int index, trailing;
1294 1635
1295 if (line < 0) 1636 if (line < 0)
1296 XSRETURN_EMPTY; 1637 XSRETURN_EMPTY;
1297 1638
1298 if (!(lp = pango_layout_get_line (self->pl, line))) 1639 if (!(lp = pango_layout_get_line_readonly (self->pl, line)))
1299 XSRETURN_EMPTY; /* do better */ 1640 XSRETURN_EMPTY; /* do better */
1300 1641
1301 pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing); 1642 pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing);
1302 1643
1303 EXTEND (SP, 2); 1644 EXTEND (SP, 2);
1309 PUSHs (sv_2mortal (newSViv (trailing))); 1650 PUSHs (sv_2mortal (newSViv (trailing)));
1310 } 1651 }
1311} 1652}
1312 1653
1313void 1654void
1314render (CFPlus::Layout self, float x, float y, int flags = 0) 1655render (DC::Layout self, float x, float y, int flags = 0)
1315 CODE: 1656 CODE:
1316 rc_clear (self->rc); 1657 self->rc.clear ();
1317 pango_opengl_render_layout_subpixel ( 1658 pango_opengl_render_layout_subpixel (
1318 self->pl, 1659 self->pl,
1319 self->rc, 1660 &self->rc,
1320 x * PANGO_SCALE, y * PANGO_SCALE, 1661 x * PANGO_SCALE, y * PANGO_SCALE,
1321 self->r, self->g, self->b, self->a, 1662 self->r, self->g, self->b, self->a,
1322 flags 1663 flags
1323 ); 1664 );
1324 // we assume that context_change actually clears/frees stuff 1665 // we assume that context_change actually clears/frees stuff
1325 // and does not do any recomputation... 1666 // and does not do any recomputation...
1326 pango_layout_context_changed (self->pl); 1667 pango_layout_context_changed (self->pl);
1327 1668
1328void 1669void
1329draw (CFPlus::Layout self) 1670draw (DC::Layout self)
1330 CODE: 1671 CODE:
1331{ 1672{
1332 glEnable (GL_TEXTURE_2D); 1673 glEnable (GL_TEXTURE_2D);
1333 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 1674 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1334 glEnable (GL_BLEND); 1675 glEnable (GL_BLEND);
1335 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 1676 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
1336 GL_ONE , GL_ONE_MINUS_SRC_ALPHA); 1677 GL_ONE , GL_ONE_MINUS_SRC_ALPHA);
1337 glEnable (GL_ALPHA_TEST); 1678 glEnable (GL_ALPHA_TEST);
1338 glAlphaFunc (GL_GREATER, 7.f / 255.f); 1679 glAlphaFunc (GL_GREATER, 7.f / 255.f);
1339 1680
1340 rc_draw (self->rc); 1681 self->rc.draw ();
1341 1682
1342 glDisable (GL_ALPHA_TEST); 1683 glDisable (GL_ALPHA_TEST);
1343 glDisable (GL_BLEND); 1684 glDisable (GL_BLEND);
1344 glDisable (GL_TEXTURE_2D); 1685 glDisable (GL_TEXTURE_2D);
1345} 1686}
1346 1687
1347MODULE = CFPlus PACKAGE = CFPlus::Texture 1688MODULE = Deliantra::Client PACKAGE = DC::Texture
1348 1689
1349PROTOTYPES: ENABLE 1690PROTOTYPES: ENABLE
1350
1351int minpot (int n)
1352 1691
1353void 1692void
1354pad (SV *data_, int ow, int oh, int nw, int nh) 1693pad (SV *data_, int ow, int oh, int nw, int nh)
1355 CODE: 1694 CODE:
1356{ 1695{
1422 glDisable (GL_ALPHA_TEST); 1761 glDisable (GL_ALPHA_TEST);
1423 glDisable (GL_BLEND); 1762 glDisable (GL_BLEND);
1424 } 1763 }
1425} 1764}
1426 1765
1766void
1767draw_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)
1768 PROTOTYPE: @
1769 CODE:
1770{
1771 glEnable (GL_BLEND);
1772 glBlendFunc (intensity ? GL_SRC_ALPHA : GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1773 glEnable (GL_TEXTURE_2D);
1774 glBindTexture (GL_TEXTURE_2D, name1);
1775
1776 glColor3f (intensity, intensity, intensity);
1777 glPushMatrix ();
1778 glScalef (1./3, 1./3, 1.);
1779
1780 if (blend > 0.f)
1781 {
1782 float dx3 = dx * -3.f / w;
1783 float dy3 = dy * -3.f / h;
1784 GLfloat env_color[4] = { 0., 0., 0., blend };
1785
1786 /* interpolate the two shadow textures */
1787 /* stage 0 == rgb(glcolor) + alpha(t0) */
1788 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1789
1790 /* stage 1 == rgb(glcolor) + alpha(interpolate t0, t1, texenv) */
1791 gl.ActiveTexture (GL_TEXTURE1);
1792 glEnable (GL_TEXTURE_2D);
1793 glBindTexture (GL_TEXTURE_2D, name2);
1794 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
1795
1796 /* rgb == rgb(glcolor) */
1797 glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
1798 glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PRIMARY_COLOR);
1799 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
1800
1801 /* alpha = interpolate t0, t1 by env_alpha */
1802 glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, env_color);
1803
1804 glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_INTERPOLATE);
1805 glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);
1806 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
1807
1808 glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_PREVIOUS);
1809 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
1810
1811 glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE2_ALPHA, GL_CONSTANT);
1812 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA);
1813
1814 glBegin (GL_QUADS);
1815 gl.MultiTexCoord2f (GL_TEXTURE0, 0, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 , dy3 ); glVertex2i (0, 0);
1816 gl.MultiTexCoord2f (GL_TEXTURE0, 0, t); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 , dy3 + t); glVertex2i (0, h);
1817 gl.MultiTexCoord2f (GL_TEXTURE0, s, t); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 + s, dy3 + t); glVertex2i (w, h);
1818 gl.MultiTexCoord2f (GL_TEXTURE0, s, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 + s, dy3 ); glVertex2i (w, 0);
1819 glEnd ();
1820
1821 glDisable (GL_TEXTURE_2D);
1822 gl.ActiveTexture (GL_TEXTURE0);
1823 }
1824 else
1825 {
1826 /* simple blending of one texture, also opengl <1.3 path */
1827 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1828
1829 glBegin (GL_QUADS);
1830 glTexCoord2f (0, 0); glVertex2f (0, 0);
1831 glTexCoord2f (0, t); glVertex2f (0, h);
1832 glTexCoord2f (s, t); glVertex2f (w, h);
1833 glTexCoord2f (s, 0); glVertex2f (w, 0);
1834 glEnd ();
1835 }
1836
1837 /* draw ?-marks or equivalent, this is very clumsy code :/ */
1838 {
1839 int x, y;
1840 int dx3 = dx * 3;
1841 int dy3 = dy * 3;
1842
1843 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1844 glBindTexture (GL_TEXTURE_2D, hidden_tex);
1845 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1846 glTranslatef (-1., -1., 0);
1847 glBegin (GL_QUADS);
1848
1849 for (y = 1; y < h; y += 3)
1850 {
1851 int y1 = y - dy3;
1852 int y1valid = y1 >= 0 && y1 < h;
1853
1854 for (x = 1; x < w; x += 3)
1855 {
1856 int x1 = x - dx3;
1857 uint8_t h1 = data1 [x + y * w] == DARKNESS_ADJUST (255 - FOW_DARKNESS);
1858 uint8_t h2;
1859
1860 if (y1valid && x1 >= 0 && x1 < w)
1861 h2 = data2 [x1 + y1 * w] == DARKNESS_ADJUST (255 - FOW_DARKNESS);
1862 else
1863 h2 = 1; /* out of range == invisible */
1864
1865 if (h1 || h2)
1866 {
1867 float alpha = h1 == h2 ? 1.f : h1 ? 1.f - blend : blend;
1868 glColor4f (1., 1., 1., alpha);
1869
1870 glTexCoord2f (0, 0.); glVertex2i (x , y );
1871 glTexCoord2f (0, 1.); glVertex2i (x , y + 3);
1872 glTexCoord2f (1, 1.); glVertex2i (x + 3, y + 3);
1873 glTexCoord2f (1, 0.); glVertex2i (x + 3, y );
1874 }
1875 }
1876 }
1877 }
1878
1879 glEnd ();
1880
1881 glPopMatrix ();
1882
1883 glDisable (GL_TEXTURE_2D);
1884 glDisable (GL_BLEND);
1885}
1886
1427IV texture_valid_2d (GLint internalformat, GLsizei w, GLsizei h, GLenum format, GLenum type) 1887IV texture_valid_2d (GLint internalformat, GLsizei w, GLsizei h, GLenum format, GLenum type)
1428 CODE: 1888 CODE:
1429{ 1889{
1430 GLint width; 1890 GLint width;
1431 glTexImage2D (GL_PROXY_TEXTURE_2D, 0, internalformat, w, h, 0, format, type, 0); 1891 glTexImage2D (GL_PROXY_TEXTURE_2D, 0, internalformat, w, h, 0, format, type, 0);
1433 RETVAL = width > 0; 1893 RETVAL = width > 0;
1434} 1894}
1435 OUTPUT: 1895 OUTPUT:
1436 RETVAL 1896 RETVAL
1437 1897
1438MODULE = CFPlus PACKAGE = CFPlus::Map 1898MODULE = Deliantra::Client PACKAGE = DC::Map
1439 1899
1440PROTOTYPES: DISABLE 1900PROTOTYPES: DISABLE
1441 1901
1442CFPlus::Map 1902DC::Map
1443new (SV *class) 1903new (SV *klass)
1444 CODE: 1904 CODE:
1445 New (0, RETVAL, 1, struct map); 1905 New (0, RETVAL, 1, mapgrid);
1446 RETVAL->x = 0; 1906 RETVAL->x = 0;
1447 RETVAL->y = 0; 1907 RETVAL->y = 0;
1448 RETVAL->w = 0; 1908 RETVAL->w = 0;
1449 RETVAL->h = 0; 1909 RETVAL->h = 0;
1450 RETVAL->ox = 0; 1910 RETVAL->ox = 0;
1455 RETVAL->row = 0; 1915 RETVAL->row = 0;
1456 OUTPUT: 1916 OUTPUT:
1457 RETVAL 1917 RETVAL
1458 1918
1459void 1919void
1460DESTROY (CFPlus::Map self) 1920DESTROY (DC::Map self)
1461 CODE: 1921 CODE:
1462{ 1922{
1463 map_clear (self); 1923 map_clear (self);
1464 Safefree (self->face2tile); 1924 Safefree (self->face2tile);
1465 Safefree (self->tex); 1925 Safefree (self->tex);
1466 Safefree (self); 1926 Safefree (self);
1467} 1927}
1468 1928
1469void 1929void
1470resize (CFPlus::Map self, int map_width, int map_height) 1930resize (DC::Map self, int map_width, int map_height)
1471 CODE: 1931 CODE:
1472 self->w = map_width; 1932 self->w = map_width;
1473 self->h = map_height; 1933 self->h = map_height;
1474 1934
1475void 1935void
1476clear (CFPlus::Map self) 1936clear (DC::Map self)
1477 CODE: 1937 CODE:
1478 map_clear (self); 1938 map_clear (self);
1479 1939
1480void 1940void
1481set_tileid (CFPlus::Map self, int face, int tile) 1941set_tileid (DC::Map self, int face, int tile)
1482 CODE: 1942 CODE:
1483{ 1943{
1484 need_facenum (self, face); self->face2tile [face] = tile; 1944 need_facenum (self, face); self->face2tile [face] = tile;
1485 need_texid (self, tile); 1945 need_texid (self, tile);
1486} 1946}
1487 1947
1488void 1948void
1489set_smooth (CFPlus::Map self, int face, int smooth, int level) 1949set_smooth (DC::Map self, int face, int smooth, int level)
1490 CODE: 1950 CODE:
1491{ 1951{
1492 tileid texid; 1952 tileid texid;
1493 maptex *tex; 1953 maptex *tex;
1494 1954
1495 if (face < 0 || face >= self->faces) 1955 if (face < 0 || face >= self->faces)
1496 return; 1956 return;
1497 1957
1498 if (smooth < 0 || smooth >= self->faces) 1958 if (smooth < 0 || smooth >= self->faces)
1499 return; 1959 return;
1500 1960
1501 texid = self->face2tile [face]; 1961 texid = self->face2tile [face];
1502 1962
1503 if (!texid) 1963 if (!texid)
1504 return; 1964 return;
1505 1965
1506 tex = self->tex + texid; 1966 tex = self->tex + texid;
1507 tex->smoothtile = self->face2tile [smooth]; 1967 tex->smoothtile = self->face2tile [smooth];
1508 tex->smoothlevel = level; 1968 tex->smoothlevel = level;
1509} 1969}
1510 1970
1511void 1971void
1512set_texture (CFPlus::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) 1972set_texture (DC::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a)
1513 CODE: 1973 CODE:
1514{ 1974{
1515 need_texid (self, texid); 1975 need_texid (self, texid);
1516 1976
1517 { 1977 {
1536 // use uglier nearest interpolation because linear suffers 1996 // use uglier nearest interpolation because linear suffers
1537 // from transparent color bleeding and ugly wrapping effects. 1997 // from transparent color bleeding and ugly wrapping effects.
1538 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1998 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1539} 1999}
1540 2000
2001void
2002expire_textures (DC::Map self, int texid, int count)
2003 PPCODE:
2004 for (; texid < self->texs && count; ++texid, --count)
2005 {
2006 maptex *tex = self->tex + texid;
2007
2008 if (tex->name)
2009 {
2010 if (tex->unused)
2011 {
2012 tex->name = 0;
2013 tex->unused = 0;
2014 XPUSHs (sv_2mortal (newSViv (texid)));
2015 }
2016 else
2017 tex->unused = 1;
2018 }
2019 }
2020
1541int 2021int
1542ox (CFPlus::Map self) 2022ox (DC::Map self)
1543 ALIAS: 2023 ALIAS:
1544 oy = 1 2024 oy = 1
1545 x = 2 2025 x = 2
1546 y = 3 2026 y = 3
1547 w = 4 2027 w = 4
1558 } 2038 }
1559 OUTPUT: 2039 OUTPUT:
1560 RETVAL 2040 RETVAL
1561 2041
1562void 2042void
1563scroll (CFPlus::Map self, int dx, int dy) 2043scroll (DC::Map self, int dx, int dy)
1564 CODE: 2044 CODE:
1565{ 2045{
1566 if (dx > 0) 2046 if (dx > 0)
1567 map_blank (self, self->x, self->y, dx, self->h); 2047 map_blank (self, self->x, self->y, dx, self->h);
1568 else if (dx < 0) 2048 else if (dx < 0)
1584 self->y += MAP_EXTEND_Y; 2064 self->y += MAP_EXTEND_Y;
1585 } 2065 }
1586} 2066}
1587 2067
1588SV * 2068SV *
1589map1a_update (CFPlus::Map self, SV *data_, int extmap) 2069map1a_update (DC::Map self, SV *data_)
1590 CODE: 2070 CODE:
1591{ 2071{
1592 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 2072 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1593 uint8_t *data_end = (uint8_t *)SvEND (data_); 2073 uint8_t *data_end = (uint8_t *)SvEND (data_);
1594 mapcell *cell; 2074 mapcell *cell;
1615 2095
1616 //TODO: don't trust server data to be in-range(!) 2096 //TODO: don't trust server data to be in-range(!)
1617 2097
1618 if (flags & 8) 2098 if (flags & 8)
1619 { 2099 {
2100 uint8_t ext, cmd;
2101
1620 if (extmap) 2102 do
1621 { 2103 {
1622 uint8_t ext, cmd; 2104 ext = *data++;
2105 cmd = ext & 0x7f;
1623 2106
1624 do 2107 if (cmd < 4)
2108 cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */
2109 else if (cmd == 5) // health
1625 { 2110 {
1626 ext = *data++;
1627 cmd = ext & 0x3f;
1628
1629 if (cmd < 4)
1630 cell->darkness = 255 - ext * 64 + 1;
1631 else if (cmd == 5) // health
1632 {
1633 cell->stat_width = 1; 2111 cell->stat_width = 1;
1634 cell->stat_hp = *data++; 2112 cell->stat_hp = *data++;
1635 }
1636 else if (cmd == 6) // monster width
1637 cell->stat_width = *data++ + 1;
1638 else if (cmd == 0x47)
1639 {
1640 if (*data == 4)
1641 ; // decode player count
1642
1643 data += *data + 1;
1644 }
1645 else if (cmd == 8) // cell flags
1646 cell->flags = *data++;
1647 else if (ext & 0x40) // unknown, multibyte => skip
1648 data += *data + 1;
1649 else
1650 data++;
1651 } 2113 }
1652 while (ext & 0x80); 2114 else if (cmd == 6) // monster width
2115 cell->stat_width = *data++ + 1;
2116 else if (cmd == 0x47)
2117 {
2118 if (*data == 1) cell->player = data [1];
2119 else if (*data == 2) cell->player = data [2] + (data [1] << 8);
2120 else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16);
2121 else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24);
2122
2123 data += *data + 1;
2124 }
2125 else if (cmd == 8) // cell flags
2126 cell->flags = *data++;
2127 else if (ext & 0x40) // unknown, multibyte => skip
2128 data += *data + 1;
2129 else
2130 data++;
1653 } 2131 }
1654 else 2132 while (ext & 0x80);
1655 cell->darkness = *data++ + 1;
1656 } 2133 }
1657 2134
1658 for (z = 0; z <= 2; ++z) 2135 for (z = 0; z <= 2; ++z)
1659 if (flags & (4 >> z)) 2136 if (flags & (4 >> z))
1660 { 2137 {
1663 cell->tile [z] = self->face2tile [face]; 2140 cell->tile [z] = self->face2tile [face];
1664 2141
1665 if (cell->tile [z]) 2142 if (cell->tile [z])
1666 { 2143 {
1667 maptex *tex = self->tex + cell->tile [z]; 2144 maptex *tex = self->tex + cell->tile [z];
2145 tex->unused = 0;
1668 if (!tex->name) 2146 if (!tex->name)
1669 av_push (missing, newSViv (cell->tile [z])); 2147 av_push (missing, newSViv (cell->tile [z]));
1670 2148
1671 if (tex->smoothtile) 2149 if (tex->smoothtile)
1672 { 2150 {
1673 maptex *smooth = self->tex + tex->smoothtile; 2151 maptex *smooth = self->tex + tex->smoothtile;
2152 smooth->unused = 0;
1674 if (!smooth->name) 2153 if (!smooth->name)
1675 av_push (missing, newSViv (tex->smoothtile)); 2154 av_push (missing, newSViv (tex->smoothtile));
1676 } 2155 }
1677 } 2156 }
1678 } 2157 }
1679 } 2158 }
1680 else 2159 else
1681 cell->darkness = 0; 2160 CELL_CLEAR (cell);
1682 } 2161 }
1683} 2162}
1684 OUTPUT: 2163 OUTPUT:
1685 RETVAL 2164 RETVAL
1686 2165
1687SV * 2166SV *
1688mapmap (CFPlus::Map self, int x0, int y0, int w, int h) 2167mapmap (DC::Map self, int x0, int y0, int w, int h)
1689 CODE: 2168 CODE:
1690{ 2169{
1691 int x1, x; 2170 int x1, x;
1692 int y1, y; 2171 int y1, y;
1693 int z; 2172 int z;
1706 ? self->row + y 2185 ? self->row + y
1707 : 0; 2186 : 0;
1708 2187
1709 for (x = x0; x < x1; x++) 2188 for (x = x0; x < x1; x++)
1710 { 2189 {
1711 int r = 32, g = 32, b = 32, a = 192; 2190 unsigned int r = 32, g = 32, b = 32, a = 192;
1712 2191
1713 if (row && row->c0 <= x && x < row->c1) 2192 if (row && row->c0 <= x && x < row->c1)
1714 { 2193 {
1715 mapcell *cell = row->col + (x - row->c0); 2194 mapcell *cell = row->col + (x - row->c0);
1716 2195
1718 { 2197 {
1719 maptex tex = self->tex [cell->tile [z]]; 2198 maptex tex = self->tex [cell->tile [z]];
1720 int a0 = 255 - tex.a; 2199 int a0 = 255 - tex.a;
1721 int a1 = tex.a; 2200 int a1 = tex.a;
1722 2201
1723 r = (r * a0 + tex.r * a1) / 255; 2202 r = div255 (r * a0 + tex.r * a1);
1724 g = (g * a0 + tex.g * a1) / 255; 2203 g = div255 (g * a0 + tex.g * a1);
1725 b = (b * a0 + tex.b * a1) / 255; 2204 b = div255 (b * a0 + tex.b * a1);
1726 a = (a * a0 + tex.a * a1) / 255; 2205 a = div255 (a * a0 + tex.a * a1);
1727 } 2206 }
1728 } 2207 }
1729 2208
1730 *map++ = (r ) 2209 *map++ = (r )
1731 | (g << 8) 2210 | (g << 8)
1732 | (b << 16) 2211 | (b << 16)
1733 | (a << 24); 2212 | (a << 24);
1734 } 2213 }
1735 } 2214 }
1736 2215
1737 RETVAL = map_sv; 2216 RETVAL = map_sv;
1738} 2217}
1739 OUTPUT: 2218 OUTPUT:
1740 RETVAL 2219 RETVAL
1741 2220
1742void 2221void
1743draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T) 2222draw (DC::Map self, int mx, int my, int sw, int sh, int Tw, int Th, U32 player = 0xffffffff, int sdx = 0, int sdy = 0)
1744 CODE: 2223 CODE:
1745{ 2224{
1746 int x, y, z; 2225 int x, y, z;
1747 2226
1748 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ());
1749 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level
1750 static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k) 2227 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k), also, static!
1751 smooth_key skey; 2228 int pl_x, pl_y;
1752 2229 maptex pl_tex;
1753 rc_t *rc = rc_alloc (); 2230 rc_t rc;
2231 rc_t rc_ov;
1754 rc_key_t key; 2232 rc_key_t key;
1755 rc_array_t *arr; 2233 rc_t::array_t *arr;
1756 2234
2235 pl_tex.name = 0;
2236
1757 // thats current max. sorry. 2237 // that's current max. sorry.
1758 if (sw > 255) sw = 255; 2238 if (sw > 255) sw = 255;
1759 if (sh > 255) sh = 255; 2239 if (sh > 255) sh = 255;
1760
1761 // clear key, in case of extra padding
1762 memset (&skey, 0, sizeof (skey));
1763 2240
1764 memset (&key, 0, sizeof (key)); 2241 memset (&key, 0, sizeof (key));
1765 key.r = 255; 2242 key.r = 255;
1766 key.g = 255; 2243 key.g = 255;
1767 key.b = 255; 2244 key.b = 255;
1768 key.a = 255; 2245 key.a = 255;
1769 key.mode = GL_QUADS; 2246 key.mode = GL_QUADS;
1770 key.format = GL_T2F_V3F; 2247 key.format = GL_T2F_V3F;
1771 key.texname = -1;
1772 2248
1773 mx += self->x; 2249 mx += self->x;
1774 my += self->y; 2250 my += self->y;
1775 2251
1776 // first pass: determine smooth_max 2252 // first pass: determine smooth_max
1777 // rather ugly, if you ask me 2253 // rather ugly, if you ask me
1778 // could also be stored inside mapcell and updated on change 2254 // could also be stored inside mapcell and updated on change
1779 memset (smooth_max, 0, sizeof (smooth_max)); 2255 memset (smooth_max, 0, sizeof (smooth_max[0]) * (sh + 1));
1780 2256
1781 for (y = 0; y < sh; y++) 2257 for (y = 0; y < sh; y++)
1782 if (0 <= y + my && y + my < self->rows) 2258 if (0 <= y + my && y + my < self->rows)
1783 { 2259 {
1784 maprow *row = self->row + (y + my); 2260 maprow *row = self->row + (y + my);
1799 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2275 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1800 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 2276 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1801 2277
1802 for (z = 0; z <= 2; z++) 2278 for (z = 0; z <= 2; z++)
1803 { 2279 {
1804 memset (smooth_level, 0, sizeof (smooth_level)); 2280 std::bitset<256> smooth_level; // one bit for every possible smooth level
2281 smooth_key skey;
2282 smooth_hash smooth;
2283 key.texname = -1;
1805 2284
1806 for (y = 0; y < sh; y++) 2285 for (y = 0; y < sh; y++)
1807 if (0 <= y + my && y + my < self->rows) 2286 if (0 <= y + my && y + my < self->rows)
1808 { 2287 {
1809 maprow *row = self->row + (y + my); 2288 maprow *row = self->row + (y + my);
1817 if (tile) 2296 if (tile)
1818 { 2297 {
1819 maptex tex = self->tex [tile]; 2298 maptex tex = self->tex [tile];
1820 int px, py; 2299 int px, py;
1821 2300
1822 // suppressing texture state switches here
1823 // is only moderately effective, but worth the extra effort
1824 if (key.texname != tex.name) 2301 if (key.texname != tex.name)
1825 { 2302 {
2303 self->tex [tile].unused = 0;
2304
1826 if (!tex.name) 2305 if (!tex.name)
1827 tex = self->tex [2]; /* missing, replace by noface */ 2306 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */
1828 2307
1829 key.texname = tex.name; 2308 key.texname = tex.name;
1830 arr = rc_array (rc, &key); 2309 arr = &rc.array (key);
1831 } 2310 }
1832 2311
1833 px = (x + 1) * T - tex.w; 2312 px = (x + 1) * Th - tex.w;
1834 py = (y + 1) * T - tex.h; 2313 py = (y + 1) * Tw - tex.h;
1835 2314
1836 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2315 if (expect_false (cell->player == player) && expect_false (z == 2))
1837 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0);
1838 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0);
1839 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0);
1840
1841 if (cell->flags && z == 2)
1842 { 2316 {
1843 // overlays such as the speech bubble, probably more to come 2317 pl_x = px;
1844 if (cell->flags & 1) 2318 pl_y = py;
2319 pl_tex = tex;
1845 { 2320 continue;
1846 maptex tex = self->tex [1];
1847 int px = x * T + T * 2 / 32;
1848 int py = y * T - T * 6 / 32;
1849
1850 if (tex.name)
1851 {
1852 if (key.texname != tex.name)
1853 {
1854 key.texname = tex.name;
1855 arr = rc_array (rc, &key);
1856 }
1857
1858 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
1859 rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0);
1860 rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0);
1861 rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0);
1862 }
1863 }
1864 } 2321 }
2322
2323 arr->t2f_v3f (0 , 0 , px , py , 0);
2324 arr->t2f_v3f (0 , tex.t, px , py + tex.h, 0);
2325 arr->t2f_v3f (tex.s, tex.t, px + tex.w, py + tex.h, 0);
2326 arr->t2f_v3f (tex.s, 0 , px + tex.w, py , 0);
1865 2327
1866 // update smooth hash 2328 // update smooth hash
1867 if (tex.smoothtile) 2329 if (tex.smoothtile)
1868 { 2330 {
1869 skey.tile = tex.smoothtile; 2331 skey.tile = tex.smoothtile;
1870 skey.level = tex.smoothlevel; 2332 skey.level = tex.smoothlevel;
1871 2333
1872 smooth_level [tex.smoothlevel >> 5] |= ((uint32_t)1) << (tex.smoothlevel & 31); 2334 smooth_level[tex.smoothlevel] = 1;
1873 2335
1874 // add bits to current tile and all neighbours. skey.x|y is 2336 // add bits to current tile and all neighbours. skey.x|y is
1875 // shifted +1|+1 so we always stay positive. 2337 // shifted +1|+1 so we always stay positive.
1876 2338
1877 // bits is ___n cccc CCCC bbbb 2339 // bits is ___n cccc CCCC bbbb
1885 2347
1886 // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· 2348 // corners: 1 ┛· 2 ·┗ 4 ·· 8 ··
1887 // ·· ·· ·┏ ┓· 2349 // ·· ·· ·┏ ┓·
1888 2350
1889 // full tile 2351 // full tile
1890 skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x1000); 2352 skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x1000);
1891 2353
1892 // borders 2354 // borders
1893 skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0091); 2355 skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0091);
1894 skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0032); 2356 skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0032);
1895 skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0064); 2357 skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0064);
1896 skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, &skey, 0x00c8); 2358 skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, skey, 0x00c8);
1897 2359
1898 // corners 2360 // corners
1899 skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0100); 2361 skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0100);
1900 skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0200); 2362 skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0200);
1901 skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400); 2363 skey.x = x ; skey.y = y ; smooth_or_bits (smooth, skey, 0x0400);
1902 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); 2364 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, skey, 0x0800);
2365 }
2366 }
2367
2368 if (expect_false (z == 2) && expect_false (cell->flags))
2369 {
2370 // overlays such as the speech bubble, probably more to come
2371 if (cell->flags & 1)
2372 {
2373 rc_key_t key_ov = key;
2374 maptex tex = self->tex[TEXID_SPEECH];
2375 int px = x * Tw + Tw * 2 / 32;
2376 int py = y * Th - Th * 6 / 32;
2377
2378 key_ov.texname = tex.name;
2379 rc_t::array_t &arr = rc_ov.array (key_ov);
2380
2381 arr.t2f_v3f (0 , 0 , px , py , 0);
2382 arr.t2f_v3f (0 , tex.t, px , py + Th, 0);
2383 arr.t2f_v3f (tex.s, tex.t, px + Tw, py + Th, 0);
2384 arr.t2f_v3f (tex.s, 0 , px + Tw, py , 0);
1903 } 2385 }
1904 } 2386 }
1905 } 2387 }
1906 } 2388 }
1907 2389
1908 rc_draw (rc); 2390 rc.draw ();
1909 rc_clear (rc); 2391 rc.clear ();
1910 2392
1911 // go through all smoothlevels, lowest to highest, then draw. 2393 // go through all smoothlevels, lowest to highest, then draw.
1912 // this is basically counting sort 2394 // this is basically counting sort
1913 { 2395 {
1914 int w, b; 2396 int w, b;
1915 2397
1916 for (w = 0; w < 256 / 32; ++w) 2398 glEnable (GL_TEXTURE_2D);
2399 glBegin (GL_QUADS);
2400 for (int level = 0; level < smooth_level.size (); ++level)
2401 if (smooth_level[level])
2402 for (auto &&it = smooth.begin (); it != smooth.end (); ++it)
1917 { 2403 {
1918 uint32_t smask = smooth_level [w]; 2404 smooth_key &skey = it->first;
1919 if (smask) 2405 IV bits = it->second;
1920 for (b = 0; b < 32; ++b) 2406
1921 if (smask & (((uint32_t)1) << b)) 2407 if (!(bits & 0x1000)
2408 && skey.level == level
2409 && level > smooth_max [skey.x][skey.y])
1922 { 2410 {
1923 int level = (w << 5) | b; 2411 maptex tex = self->tex [skey.tile];
2412 int px = (((int)skey.x) - 1) * Tw;
2413 int py = (((int)skey.y) - 1) * Th;
2414 int border = bits & 15;
2415 int corner = (bits >> 8) & ~(bits >> 4) & 15;
2416 float dx = tex.s * .0625f; // 16 images/row
2417 float dy = tex.t * .5f ; // 2 images/column
2418
1924 HE *he; 2419 if (tex.name)
1925
1926 hv_iterinit (smooth);
1927 while ((he = hv_iternext (smooth)))
1928 { 2420 {
1929 smooth_key *skey = (smooth_key *)HeKEY (he); 2421 // this time avoiding texture state changes
1930 IV bits = SvIVX (HeVAL (he)); 2422 // save gobs of state changes.
1931 2423 if (key.texname != tex.name)
1932 if (!(bits & 0x1000)
1933 && skey->level == level
1934 && level > smooth_max [skey->x][skey->y])
1935 { 2424 {
1936 maptex tex = self->tex [skey->tile]; 2425 self->tex [skey.tile].unused = 0;
1937 int px = (((int)skey->x) - 1) * T;
1938 int py = (((int)skey->y) - 1) * T;
1939 int border = bits & 15;
1940 int corner = (bits >> 8) & ~(bits >> 4) & 15;
1941 float dx = tex.s * .0625f; // 16 images/row
1942 float dy = tex.t * .5f ; // 2 images/column
1943 2426
1944 if (tex.name)
1945 { 2427 glEnd ();
1946 // this time avoiding texture state changes
1947 // save gobs of state changes.
1948 if (key.texname != tex.name) 2428 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name);
1949 { 2429 glBegin (GL_QUADS);
1950 key.texname = tex.name;
1951 arr = rc_array (rc, &key);
1952 }
1953
1954 if (border)
1955 {
1956 float ox = border * dx;
1957
1958 rc_t2f_v3f (arr, ox , 0.f , px , py , 0);
1959 rc_t2f_v3f (arr, ox , dy , px , py + T, 0);
1960 rc_t2f_v3f (arr, ox + dx, dy , px + T, py + T, 0);
1961 rc_t2f_v3f (arr, ox + dx, 0.f , px + T, py , 0);
1962 }
1963
1964 if (corner)
1965 {
1966 float ox = corner * dx;
1967
1968 rc_t2f_v3f (arr, ox , dy , px , py , 0);
1969 rc_t2f_v3f (arr, ox , dy * 2.f, px , py + T, 0);
1970 rc_t2f_v3f (arr, ox + dx, dy * 2.f, px + T, py + T, 0);
1971 rc_t2f_v3f (arr, ox + dx, dy , px + T, py , 0);
1972 }
1973 } 2430 }
2431
2432 if (border)
2433 {
2434 float ox = border * dx;
2435
2436 glTexCoord2f (ox , 0.f ); glVertex2i (px , py );
2437 glTexCoord2f (ox , dy ); glVertex2i (px , py + Th);
2438 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th);
2439 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py );
2440 }
2441
2442 if (corner)
2443 {
2444 float ox = corner * dx;
2445
2446 glTexCoord2f (ox , dy ); glVertex2i (px , py );
2447 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th);
2448 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th);
2449 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py );
1974 } 2450 }
1975 } 2451 }
1976 } 2452 }
1977 } 2453 }
2454
2455 glEnd ();
2456 glDisable (GL_TEXTURE_2D);
2457 key.texname = -1;
1978 } 2458 }
1979
1980 hv_clear (smooth);
1981 rc_draw (rc);
1982 rc_clear (rc);
1983 } 2459 }
1984 2460
2461 if (pl_tex.name)
2462 {
2463 maptex tex = pl_tex;
2464 int px = pl_x + sdx;
2465 int py = pl_y + sdy;
2466
2467 key.texname = tex.name;
2468 rc_t::array_t &arr = rc.array (key);
2469
2470 arr.t2f_v3f (0 , 0 , px , py , 0);
2471 arr.t2f_v3f (0 , tex.t, px , py + tex.h, 0);
2472 arr.t2f_v3f (tex.s, tex.t, px + tex.w, py + tex.h, 0);
2473 arr.t2f_v3f (tex.s, 0 , px + tex.w, py , 0);
2474
2475 rc.draw ();
2476 }
2477
2478 rc_ov.draw ();
2479 rc_ov.clear ();
2480
1985 glDisable (GL_BLEND); 2481 glDisable (GL_BLEND);
1986 rc_free (rc);
1987 2482
1988 // top layer: overlays such as the health bar 2483 // top layer: overlays such as the health bar
1989 for (y = 0; y < sh; y++) 2484 for (y = 0; y < sh; y++)
1990 if (0 <= y + my && y + my < self->rows) 2485 if (0 <= y + my && y + my < self->rows)
1991 { 2486 {
1994 for (x = 0; x < sw; x++) 2489 for (x = 0; x < sw; x++)
1995 if (row->c0 <= x + mx && x + mx < row->c1) 2490 if (row->c0 <= x + mx && x + mx < row->c1)
1996 { 2491 {
1997 mapcell *cell = row->col + (x + mx - row->c0); 2492 mapcell *cell = row->col + (x + mx - row->c0);
1998 2493
1999 int px = x * T; 2494 int px = x * Tw;
2000 int py = y * T; 2495 int py = y * Th;
2496
2497 if (expect_false (cell->player == player))
2498 {
2499 px += sdx;
2500 py += sdy;
2501 }
2001 2502
2002 if (cell->stat_hp) 2503 if (cell->stat_hp)
2003 { 2504 {
2004 int width = cell->stat_width * T; 2505 int width = cell->stat_width * Tw;
2005 int thick = (sh * T / 32 + 27) / 28 + 1 + cell->stat_width; 2506 int thick = (sh * Th / 32 + 27) / 28 + 1 + cell->stat_width;
2006 2507
2007 glColor3ub (0, 0, 0); 2508 glColor3ub (0, 0, 0);
2008 glRectf (px + 1, py - thick - 2, 2509 glRectf (px + 1, py - thick - 2,
2009 px + width - 1, py); 2510 px + width - 1, py);
2010 2511
2016 } 2517 }
2017 } 2518 }
2018} 2519}
2019 2520
2020void 2521void
2021draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) 2522draw_magicmap (DC::Map self, int w, int h, unsigned char *data)
2022 CODE: 2523 CODE:
2023{ 2524{
2024 static float color[16][3] = { 2525 static float color[16][3] = {
2025 { 0.00F, 0.00F, 0.00F }, 2526 { 0.00f, 0.00f, 0.00f },
2026 { 1.00F, 1.00F, 1.00F }, 2527 { 1.00f, 1.00f, 1.00f },
2027 { 0.00F, 0.00F, 0.55F }, 2528 { 0.00f, 0.00f, 0.55f },
2028 { 1.00F, 0.00F, 0.00F }, 2529 { 1.00f, 0.00f, 0.00f },
2029 2530
2030 { 1.00F, 0.54F, 0.00F }, 2531 { 1.00f, 0.54f, 0.00f },
2031 { 0.11F, 0.56F, 1.00F }, 2532 { 0.11f, 0.56f, 1.00f },
2032 { 0.93F, 0.46F, 0.00F }, 2533 { 0.93f, 0.46f, 0.00f },
2033 { 0.18F, 0.54F, 0.34F }, 2534 { 0.18f, 0.54f, 0.34f },
2034 2535
2035 { 0.56F, 0.73F, 0.56F }, 2536 { 0.56f, 0.73f, 0.56f },
2036 { 0.80F, 0.80F, 0.80F }, 2537 { 0.80f, 0.80f, 0.80f },
2037 { 0.55F, 0.41F, 0.13F }, 2538 { 0.55f, 0.41f, 0.13f },
2038 { 0.99F, 0.77F, 0.26F }, 2539 { 0.99f, 0.77f, 0.26f },
2039 2540
2040 { 0.74F, 0.65F, 0.41F }, 2541 { 0.74f, 0.65f, 0.41f },
2041 2542
2042 { 0.00F, 1.00F, 1.00F }, 2543 { 0.00f, 1.00f, 1.00f },
2043 { 1.00F, 0.00F, 1.00F }, 2544 { 1.00f, 0.00f, 1.00f },
2044 { 1.00F, 1.00F, 0.00F }, 2545 { 1.00f, 1.00f, 0.00f },
2045 }; 2546 };
2046 2547
2047 int x, y; 2548 int x, y;
2048 2549
2049 glEnable (GL_TEXTURE_2D); 2550 glEnable (GL_TEXTURE_2D);
2551 /* GL_REPLACE would be correct, as we don't need to modulate alpha,
2552 * but the nvidia driver (185.18.14) mishandles alpha textures
2553 * and takes the colour from god knows where instead of using
2554 * Cp. MODULATE results in the same colour, but slightly different
2555 * alpha, but atcually gives us the correct colour with nvidia.
2556 */
2050 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 2557 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
2051 glEnable (GL_BLEND); 2558 glEnable (GL_BLEND);
2052 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2559 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2053 glBegin (GL_QUADS); 2560 glBegin (GL_QUADS);
2054 2561
2055 for (y = 0; y < h; y++) 2562 for (y = 0; y < h; y++)
2059 2566
2060 if (m) 2567 if (m)
2061 { 2568 {
2062 float *c = color [m & 15]; 2569 float *c = color [m & 15];
2063 2570
2064 float tx1 = m & 0x40 ? 0.5 : 0.; 2571 float tx1 = m & 0x40 ? 0.5f : 0.f;
2065 float tx2 = tx1 + 0.5; 2572 float tx2 = tx1 + 0.5f;
2066 2573
2067 glColor4f (c[0], c[1], c[2], 0.75); 2574 glColor4f (c[0], c[1], c[2], 1);
2068 glTexCoord2f (tx1, 0.); glVertex2i (x , y ); 2575 glTexCoord2f (tx1, 0.); glVertex2i (x , y );
2069 glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1); 2576 glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1);
2070 glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1); 2577 glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1);
2071 glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y ); 2578 glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y );
2072 } 2579 }
2076 glDisable (GL_BLEND); 2583 glDisable (GL_BLEND);
2077 glDisable (GL_TEXTURE_2D); 2584 glDisable (GL_TEXTURE_2D);
2078} 2585}
2079 2586
2080void 2587void
2081fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh) 2588fow_texture (DC::Map self, int mx, int my, int sw, int sh)
2082 PPCODE: 2589 PPCODE:
2083{ 2590{
2084 int x, y; 2591 int x, y;
2085 int sw1 = sw + 2; 2592 int sw1 = sw + 2;
2086 int sh1 = sh + 2; 2593 int sh1 = sh + 2;
2087 int sh3 = sh * 3; 2594 int sh3 = sh * 3;
2088 int sw34 = (sw * 3 + 3) & ~3; 2595 int sw3 = sw * 3;
2596 SV *darkness3_sv = sv_2mortal (newSV (sw3 * sh3));
2597 uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv);
2089 uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); 2598 uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1);
2090 SV *darkness3_sv = sv_2mortal (newSV (sw34 * sh3)); 2599 memset (darkness1, 0, sw1*sh1);
2091 uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv);
2092 2600
2093 SvPOK_only (darkness3_sv); 2601 SvPOK_only (darkness3_sv);
2094 SvCUR_set (darkness3_sv, sw34 * sh3); 2602 SvCUR_set (darkness3_sv, sw3 * sh3);
2095 2603
2096 mx += self->x - 1; 2604 mx += self->x - 1;
2097 my += self->y - 1; 2605 my += self->y - 1;
2098
2099 memset (darkness1, 255, sw1 * sh1);
2100 2606
2101 for (y = 0; y < sh1; y++) 2607 for (y = 0; y < sh1; y++)
2102 if (0 <= y + my && y + my < self->rows) 2608 if (0 <= y + my && y + my < self->rows)
2103 { 2609 {
2104 maprow *row = self->row + (y + my); 2610 maprow *row = self->row + (y + my);
2107 if (row->c0 <= x + mx && x + mx < row->c1) 2613 if (row->c0 <= x + mx && x + mx < row->c1)
2108 { 2614 {
2109 mapcell *cell = row->col + (x + mx - row->c0); 2615 mapcell *cell = row->col + (x + mx - row->c0);
2110 2616
2111 darkness1 [y * sw1 + x] = cell->darkness 2617 darkness1 [y * sw1 + x] = cell->darkness
2112 ? 255 - (cell->darkness - 1) 2618 ? DARKNESS_ADJUST (255 - (cell->darkness - 1))
2113 : 255 - FOW_DARKNESS; 2619 : DARKNESS_ADJUST (255 - FOW_DARKNESS);
2114 } 2620 }
2115 } 2621 }
2116 2622
2117 for (y = 0; y < sh; ++y) 2623 for (y = 0; y < sh; ++y)
2118 for (x = 0; x < sw; ++x) 2624 for (x = 0; x < sw; ++x)
2137 2643
2138 uint8_t r13 = (d13 + d23 + d12) / 3; 2644 uint8_t r13 = (d13 + d23 + d12) / 3;
2139 uint8_t r23 = d23; 2645 uint8_t r23 = d23;
2140 uint8_t r33 = (d23 + d33 + d32) / 3; 2646 uint8_t r33 = (d23 + d33 + d32) / 3;
2141 2647
2142 darkness3 [(y * 3 ) * sw34 + (x * 3 )] = MAX (d22, r11); 2648 darkness3 [(y * 3 ) * sw3 + (x * 3 )] = MAX (d22, r11);
2143 darkness3 [(y * 3 ) * sw34 + (x * 3 + 1)] = MAX (d22, r21); 2649 darkness3 [(y * 3 ) * sw3 + (x * 3 + 1)] = MAX (d22, r21);
2144 darkness3 [(y * 3 ) * sw34 + (x * 3 + 2)] = MAX (d22, r31); 2650 darkness3 [(y * 3 ) * sw3 + (x * 3 + 2)] = MAX (d22, r31);
2145 darkness3 [(y * 3 + 1) * sw34 + (x * 3 )] = MAX (d22, r12); 2651 darkness3 [(y * 3 + 1) * sw3 + (x * 3 )] = MAX (d22, r12);
2146 darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 1)] = MAX (d22, r22); 2652 darkness3 [(y * 3 + 1) * sw3 + (x * 3 + 1)] = MAX (d22, r22); /* this MUST be == d22 */
2147 darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 2)] = MAX (d22, r32); 2653 darkness3 [(y * 3 + 1) * sw3 + (x * 3 + 2)] = MAX (d22, r32);
2148 darkness3 [(y * 3 + 2) * sw34 + (x * 3 )] = MAX (d22, r13); 2654 darkness3 [(y * 3 + 2) * sw3 + (x * 3 )] = MAX (d22, r13);
2149 darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 1)] = MAX (d22, r23); 2655 darkness3 [(y * 3 + 2) * sw3 + (x * 3 + 1)] = MAX (d22, r23);
2150 darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 2)] = MAX (d22, r33); 2656 darkness3 [(y * 3 + 2) * sw3 + (x * 3 + 2)] = MAX (d22, r33);
2151 } 2657 }
2152 2658
2153 free (darkness1); 2659 free (darkness1);
2154 2660
2155 EXTEND (SP, 3); 2661 EXTEND (SP, 3);
2156 PUSHs (sv_2mortal (newSViv (sw34))); 2662 PUSHs (sv_2mortal (newSViv (sw3)));
2157 PUSHs (sv_2mortal (newSViv (sh3))); 2663 PUSHs (sv_2mortal (newSViv (sh3)));
2158 PUSHs (darkness3_sv); 2664 PUSHs (darkness3_sv);
2159} 2665}
2160 2666
2161SV * 2667SV *
2162get_rect (CFPlus::Map self, int x0, int y0, int w, int h) 2668get_rect (DC::Map self, int x0, int y0, int w, int h)
2163 CODE: 2669 CODE:
2164{ 2670{
2165 int x, y, x1, y1; 2671 int x, y, x1, y1;
2166 SV *data_sv = newSV (w * h * 7 + 5); 2672 SV *data_sv = newSV (w * h * 7 + 5);
2167 uint8_t *data = (uint8_t *)SvPVX (data_sv); 2673 uint8_t *data = (uint8_t *)SvPVX (data_sv);
2224 else 2730 else
2225 *data++ = 0; 2731 *data++ = 0;
2226 } 2732 }
2227 } 2733 }
2228 2734
2735 /* if size is w*h + 5 then no data has been found */
2736 if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5)
2737 {
2229 SvPOK_only (data_sv); 2738 SvPOK_only (data_sv);
2230 SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); 2739 SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv));
2740 }
2741
2231 RETVAL = data_sv; 2742 RETVAL = data_sv;
2232} 2743}
2233 OUTPUT: 2744 OUTPUT:
2234 RETVAL 2745 RETVAL
2235 2746
2236void 2747void
2237set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data) 2748set_rect (DC::Map self, int x0, int y0, SV *data_sv)
2238 PPCODE: 2749 PPCODE:
2239{ 2750{
2240 int x, y, z; 2751 int x, y, z;
2241 int w, h; 2752 int w, h;
2242 int x1, y1; 2753 int x1, y1;
2754 STRLEN len;
2755 uint8_t *data, *end;
2756
2757 len = SvLEN (data_sv);
2758 SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more
2759 data = (uint8_t *)SvPVbyte_nolen (data_sv);
2760 end = data + len + 8;
2761
2762 if (len < 5)
2763 XSRETURN_EMPTY;
2243 2764
2244 if (*data++ != 0) 2765 if (*data++ != 0)
2245 return; /* version mismatch */ 2766 XSRETURN_EMPTY; /* version mismatch */
2246 2767
2247 w = *data++ << 8; w |= *data++; 2768 w = *data++ << 8; w |= *data++;
2248 h = *data++ << 8; h |= *data++; 2769 h = *data++ << 8; h |= *data++;
2249 2770
2250 // we need to do this 'cause we don't keep an absolute coord system for rows 2771 // we need to do this 'cause we don't keep an absolute coord system for rows
2262 { 2783 {
2263 maprow *row = map_get_row (self, y); 2784 maprow *row = map_get_row (self, y);
2264 2785
2265 for (x = x0; x < x1; x++) 2786 for (x = x0; x < x1; x++)
2266 { 2787 {
2788 uint8_t flags;
2789
2790 if (data + 7 >= end)
2791 XSRETURN_EMPTY;
2792
2267 uint8_t flags = *data++; 2793 flags = *data++;
2268 2794
2269 if (flags) 2795 if (flags)
2270 { 2796 {
2271 mapcell *cell = row_get_cell (row, x); 2797 mapcell *cell = row_get_cell (row, x);
2272 tileid tile[3] = { 0, 0, 0 }; 2798 tileid tile[3] = { 0, 0, 0 };
2275 if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; } 2801 if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; }
2276 if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; } 2802 if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; }
2277 2803
2278 if (cell->darkness == 0) 2804 if (cell->darkness == 0)
2279 { 2805 {
2280 cell->darkness = 0; 2806 /*cell->darkness = 0;*/
2807 EXTEND (SP, 3);
2281 2808
2282 for (z = 0; z <= 2; z++) 2809 for (z = 0; z <= 2; z++)
2283 { 2810 {
2284 tileid t = tile [z]; 2811 tileid t = tile [z];
2285 2812
2286 if (t >= self->texs || (t && !self->tex [t].name)) 2813 if (t >= self->texs || (t && !self->tex [t].name))
2287 { 2814 {
2288 XPUSHs (sv_2mortal (newSViv (t))); 2815 PUSHs (sv_2mortal (newSViv (t)));
2289 need_texid (self, t); 2816 need_texid (self, t);
2290 } 2817 }
2291 2818
2292 cell->tile [z] = t; 2819 cell->tile [z] = t;
2293 } 2820 }
2295 } 2822 }
2296 } 2823 }
2297 } 2824 }
2298} 2825}
2299 2826
2300MODULE = CFPlus PACKAGE = CFPlus::RW 2827MODULE = Deliantra::Client PACKAGE = DC::RW
2301 2828
2302CFPlus::RW 2829DC::RW
2303new (SV *class, SV *data_sv) 2830new (SV *klass, SV *data_sv)
2304 CODE: 2831 CODE:
2305{ 2832{
2306 STRLEN datalen; 2833 STRLEN datalen;
2307 char *data = SvPVbyte (data_sv, datalen); 2834 char *data = SvPVbyte (data_sv, datalen);
2308 2835
2309 RETVAL = SDL_RWFromConstMem (data, datalen); 2836 RETVAL = SDL_RWFromConstMem (data, datalen);
2310} 2837}
2311 OUTPUT: 2838 OUTPUT:
2312 RETVAL 2839 RETVAL
2313 2840
2314CFPlus::RW 2841DC::RW
2315new_from_file (SV *class, const char *path, const char *mode = "rb") 2842new_from_file (SV *klass, const char *path, const char *mode = "rb")
2316 CODE: 2843 CODE:
2317 RETVAL = SDL_RWFromFile (path, mode); 2844 RETVAL = SDL_RWFromFile (path, mode);
2318 OUTPUT: 2845 OUTPUT:
2319 RETVAL 2846 RETVAL
2320 2847
2321# fails on win32: 2848# fails on win32:
2322# CFPlus.xs(2268) : error C2059: syntax error : '(' 2849# dc.xs(2268) : error C2059: syntax error : '('
2323#void 2850#void
2324#close (CFPlus::RW self) 2851#close (DC::RW self)
2325# CODE: 2852# CODE:
2326# (self->(close)) (self); 2853# (self->(close)) (self);
2327 2854
2328MODULE = CFPlus PACKAGE = CFPlus::Channel 2855MODULE = Deliantra::Client PACKAGE = DC::Channel
2329 2856
2330PROTOTYPES: DISABLE 2857PROTOTYPES: DISABLE
2331 2858
2332CFPlus::Channel 2859DC::Channel
2333find () 2860find ()
2334 CODE: 2861 CODE:
2335{ 2862{
2336 RETVAL = Mix_GroupAvailable (-1); 2863 RETVAL = Mix_GroupAvailable (-1);
2337 2864
2338 if (RETVAL < 0) 2865 if (RETVAL < 0)
2339 { 2866 {
2340 RETVAL = Mix_GroupOldest (-1); 2867 RETVAL = Mix_GroupOldest (-1);
2341 2868
2342 if (RETVAL < 0) 2869 if (RETVAL < 0)
2870 {
2871 // happens sometimes, maybe it just stopped playing(?)
2872 RETVAL = Mix_GroupAvailable (-1);
2873
2874 if (RETVAL < 0)
2343 XSRETURN_UNDEF; 2875 XSRETURN_UNDEF;
2344 2876 }
2877 else
2345 Mix_HaltChannel (RETVAL); 2878 Mix_HaltChannel (RETVAL);
2346 } 2879 }
2347 2880
2348 Mix_UnregisterAllEffects (RETVAL); 2881 Mix_UnregisterAllEffects (RETVAL);
2349 Mix_Volume (RETVAL, 128); 2882 Mix_Volume (RETVAL, 128);
2350} 2883}
2351 OUTPUT: 2884 OUTPUT:
2352 RETVAL 2885 RETVAL
2353 2886
2354void 2887void
2355halt (CFPlus::Channel self) 2888halt (DC::Channel self)
2356 CODE: 2889 CODE:
2357 Mix_HaltChannel (self); 2890 Mix_HaltChannel (self);
2358 2891
2359void 2892void
2360expire (CFPlus::Channel self, int ticks = -1) 2893expire (DC::Channel self, int ticks = -1)
2361 CODE: 2894 CODE:
2362 Mix_ExpireChannel (self, ticks); 2895 Mix_ExpireChannel (self, ticks);
2363 2896
2364void 2897void
2365fade_out (CFPlus::Channel self, int ticks = -1) 2898fade_out (DC::Channel self, int ticks = -1)
2366 CODE: 2899 CODE:
2367 Mix_FadeOutChannel (self, ticks); 2900 Mix_FadeOutChannel (self, ticks);
2368 2901
2369int 2902int
2370volume (CFPlus::Channel self, int volume) 2903volume (DC::Channel self, int volume)
2371 CODE: 2904 CODE:
2372 RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128)); 2905 RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128));
2373 OUTPUT: 2906 OUTPUT:
2374 RETVAL 2907 RETVAL
2375 2908
2376void 2909void
2377unregister_all_effects (CFPlus::Channel self) 2910unregister_all_effects (DC::Channel self)
2378 CODE: 2911 CODE:
2379 Mix_UnregisterAllEffects (self); 2912 Mix_UnregisterAllEffects (self);
2380 2913
2381void 2914void
2382set_panning (CFPlus::Channel self, int left, int right) 2915set_panning (DC::Channel self, int left, int right)
2383 CODE: 2916 CODE:
2384 left = CLAMP (left , 0, 255); 2917 left = CLAMP (left , 0, 255);
2385 right = CLAMP (right, 0, 255); 2918 right = CLAMP (right, 0, 255);
2386 Mix_SetPanning (self, left, right); 2919 Mix_SetPanning (self, left, right);
2387 2920
2388void 2921void
2389set_distance (CFPlus::Channel self, int distance) 2922set_distance (DC::Channel self, int distance)
2390 CODE: 2923 CODE:
2391 Mix_SetDistance (self, CLAMP (distance, 0, 255)); 2924 Mix_SetDistance (self, CLAMP (distance, 0, 255));
2392 2925
2393void 2926void
2394set_position (CFPlus::Channel self, int angle, int distance) 2927set_position (DC::Channel self, int angle, int distance)
2395 CODE: 2928 CODE:
2396 2929
2397void 2930void
2398set_position_r (CFPlus::Channel self, int dx, int dy, int maxdistance) 2931set_position_r (DC::Channel self, int dx, int dy, int maxdistance)
2399 CODE: 2932 CODE:
2400{ 2933{
2401 int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance)); 2934 int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance));
2402 int angle = 360 + (int)roundf (atan2f (dx, -dy) * 180.f / (float)M_PI); 2935 int angle = atan2f (dx, -dy) * 180.f / (float)M_PI + 360.f;
2403 Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); 2936 Mix_SetPosition (self, angle, CLAMP (distance, 0, 255));
2404} 2937}
2405 2938
2406void 2939void
2407set_reverse_stereo (CFPlus::Channel self, int flip) 2940set_reverse_stereo (DC::Channel self, int flip)
2408 CODE: 2941 CODE:
2409 Mix_SetReverseStereo (self, flip); 2942 Mix_SetReverseStereo (self, flip);
2410 2943
2411MODULE = CFPlus PACKAGE = CFPlus::MixChunk 2944MODULE = Deliantra::Client PACKAGE = DC::MixChunk
2412 2945
2413PROTOTYPES: DISABLE 2946PROTOTYPES: DISABLE
2414 2947
2948void
2949decoders ()
2950 PPCODE:
2951#if SDL_MIXER_MAJOR_VERSION > 1 || SDL_MIXER_MINOR_VERSION > 2 || SDL_MIXER_PATCHLEVEL >= 10
2952 int i, num = Mix_GetNumChunkDecoders ();
2953 EXTEND (SP, num);
2954 for (i = 0; i < num; ++i)
2955 PUSHs (sv_2mortal (newSVpv (Mix_GetChunkDecoder (i), 0)));
2956#else
2957 XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0)));
2958#endif
2959
2415CFPlus::MixChunk 2960DC::MixChunk
2416new (SV *class, CFPlus::RW rwops) 2961new (SV *klass, DC::RW rwops)
2417 CODE: 2962 CODE:
2418 RETVAL = Mix_LoadWAV_RW (rwops, 1); 2963 RETVAL = Mix_LoadWAV_RW (rwops, 1);
2419 OUTPUT: 2964 OUTPUT:
2420 RETVAL 2965 RETVAL
2421 2966
2422void 2967void
2423DESTROY (CFPlus::MixChunk self) 2968DESTROY (DC::MixChunk self)
2424 CODE: 2969 CODE:
2425 Mix_FreeChunk (self); 2970 Mix_FreeChunk (self);
2426 2971
2427int 2972int
2428volume (CFPlus::MixChunk self, int volume = -1) 2973volume (DC::MixChunk self, int volume = -1)
2429 CODE: 2974 CODE:
2430 if (items > 1) 2975 if (items > 1)
2431 volume = CLAMP (volume, 0, 128); 2976 volume = CLAMP (volume, 0, 128);
2432 RETVAL = Mix_VolumeChunk (self, volume); 2977 RETVAL = Mix_VolumeChunk (self, volume);
2433 OUTPUT: 2978 OUTPUT:
2434 RETVAL 2979 RETVAL
2435 2980
2436CFPlus::Channel 2981DC::Channel
2437play (CFPlus::MixChunk self, CFPlus::Channel channel = -1, int loops = 0, int ticks = -1) 2982play (DC::MixChunk self, DC::Channel channel = -1, int loops = 0, int ticks = -1)
2438 CODE: 2983 CODE:
2439{ 2984{
2440 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); 2985 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks);
2441 2986
2442 if (RETVAL < 0) 2987 if (RETVAL < 0)
2449 } 2994 }
2450} 2995}
2451 OUTPUT: 2996 OUTPUT:
2452 RETVAL 2997 RETVAL
2453 2998
2454MODULE = CFPlus PACKAGE = CFPlus::MixMusic 2999MODULE = Deliantra::Client PACKAGE = DC::MixMusic
3000
3001void
3002decoders ()
3003 PPCODE:
3004#if SDL_MIXER_MAJOR_VERSION > 1 || SDL_MIXER_MINOR_VERSION > 2 || SDL_MIXER_PATCHLEVEL >= 10
3005 int i, num = Mix_GetNumMusicDecoders ();
3006 EXTEND (SP, num);
3007 for (i = 0; i < num; ++i)
3008 PUSHs (sv_2mortal (newSVpv (Mix_GetMusicDecoder (i), 0)));
3009#else
3010 XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0)));
3011#endif
2455 3012
2456int 3013int
2457volume (int volume = -1) 3014volume (int volume = -1)
2458 PROTOTYPE: ;$ 3015 PROTOTYPE: ;$
2459 CODE: 3016 CODE:
2471void 3028void
2472halt () 3029halt ()
2473 CODE: 3030 CODE:
2474 Mix_HaltMusic (); 3031 Mix_HaltMusic ();
2475 3032
3033int
3034playing ()
3035 CODE:
3036 RETVAL = Mix_PlayingMusic ();
3037 OUTPUT:
3038 RETVAL
3039
2476CFPlus::MixMusic 3040DC::MixMusic
2477new (SV *class, CFPlus::RW rwops) 3041new (SV *klass, DC::RW rwops)
2478 CODE: 3042 CODE:
2479 RETVAL = Mix_LoadMUS_RW (rwops); 3043 RETVAL = Mix_LoadMUS_RW (rwops);
2480 OUTPUT: 3044 OUTPUT:
2481 RETVAL 3045 RETVAL
2482 3046
2483void 3047void
2484DESTROY (CFPlus::MixMusic self) 3048DESTROY (DC::MixMusic self)
2485 CODE: 3049 CODE:
2486 Mix_FreeMusic (self); 3050 Mix_FreeMusic (self);
2487 3051
2488int 3052int
2489play (CFPlus::MixMusic self, int loops = -1) 3053play (DC::MixMusic self, int loops = -1)
2490 CODE: 3054 CODE:
2491 RETVAL = Mix_PlayMusic (self, loops); 3055 RETVAL = Mix_PlayMusic (self, loops);
2492 OUTPUT: 3056 OUTPUT:
2493 RETVAL 3057 RETVAL
2494 3058
2495void 3059void
2496fade_in_pos (CFPlus::MixMusic self, int loops, int ms, double position) 3060fade_in_pos (DC::MixMusic self, int loops, int ms, double position)
2497 CODE: 3061 CODE:
2498 Mix_FadeInMusicPos (self, loops, ms, position); 3062 Mix_FadeInMusicPos (self, loops, ms, position);
2499 3063
2500MODULE = CFPlus PACKAGE = CFPlus::OpenGL 3064MODULE = Deliantra::Client PACKAGE = DC::OpenGL
2501 3065
2502PROTOTYPES: ENABLE 3066PROTOTYPES: ENABLE
2503 3067
2504BOOT: 3068BOOT:
2505{ 3069{
2506 HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); 3070 HV *stash = gv_stashpv ("DC::OpenGL", 1);
2507 static const struct { 3071 static const struct {
2508 const char *name; 3072 const char *name;
2509 IV iv; 3073 IV iv;
2510 } *civ, const_iv[] = { 3074 } *civ, const_iv[] = {
2511# define const_iv(name) { # name, (IV)name } 3075# define const_iv(name) { # name, (IV)name }
2512 const_iv (GL_VENDOR), 3076 const_iv (GL_VENDOR),
2513 const_iv (GL_VERSION), 3077 const_iv (GL_VERSION),
2514 const_iv (GL_EXTENSIONS), 3078 const_iv (GL_EXTENSIONS),
3079 const_iv (GL_MAX_TEXTURE_UNITS),
2515 const_iv (GL_COLOR_MATERIAL), 3080 const_iv (GL_COLOR_MATERIAL),
2516 const_iv (GL_SMOOTH), 3081 const_iv (GL_SMOOTH),
2517 const_iv (GL_FLAT), 3082 const_iv (GL_FLAT),
2518 const_iv (GL_DITHER), 3083 const_iv (GL_DITHER),
2519 const_iv (GL_BLEND), 3084 const_iv (GL_BLEND),
2531 const_iv (GL_ZERO), 3096 const_iv (GL_ZERO),
2532 const_iv (GL_SRC_ALPHA), 3097 const_iv (GL_SRC_ALPHA),
2533 const_iv (GL_DST_ALPHA), 3098 const_iv (GL_DST_ALPHA),
2534 const_iv (GL_ONE_MINUS_SRC_ALPHA), 3099 const_iv (GL_ONE_MINUS_SRC_ALPHA),
2535 const_iv (GL_ONE_MINUS_DST_ALPHA), 3100 const_iv (GL_ONE_MINUS_DST_ALPHA),
3101 const_iv (GL_SRC_COLOR),
3102 const_iv (GL_DST_COLOR),
3103 const_iv (GL_ONE_MINUS_SRC_COLOR),
3104 const_iv (GL_ONE_MINUS_DST_COLOR),
2536 const_iv (GL_SRC_ALPHA_SATURATE), 3105 const_iv (GL_SRC_ALPHA_SATURATE),
2537 const_iv (GL_RGB), 3106 const_iv (GL_RGB),
2538 const_iv (GL_RGBA), 3107 const_iv (GL_RGBA),
2539 const_iv (GL_RGBA4), 3108 const_iv (GL_RGBA4),
2540 const_iv (GL_RGBA8), 3109 const_iv (GL_RGBA8),
2546 const_iv (GL_INTENSITY), 3115 const_iv (GL_INTENSITY),
2547 const_iv (GL_LUMINANCE), 3116 const_iv (GL_LUMINANCE),
2548 const_iv (GL_LUMINANCE_ALPHA), 3117 const_iv (GL_LUMINANCE_ALPHA),
2549 const_iv (GL_FLOAT), 3118 const_iv (GL_FLOAT),
2550 const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), 3119 const_iv (GL_UNSIGNED_INT_8_8_8_8_REV),
3120 const_iv (GL_COMPRESSED_ALPHA_ARB),
3121 const_iv (GL_COMPRESSED_LUMINANCE_ARB),
3122 const_iv (GL_COMPRESSED_LUMINANCE_ALPHA_ARB),
3123 const_iv (GL_COMPRESSED_INTENSITY_ARB),
3124 const_iv (GL_COMPRESSED_RGB_ARB),
3125 const_iv (GL_COMPRESSED_RGBA_ARB),
2551 const_iv (GL_COMPILE), 3126 const_iv (GL_COMPILE),
2552 const_iv (GL_PROXY_TEXTURE_1D), 3127 const_iv (GL_PROXY_TEXTURE_1D),
2553 const_iv (GL_PROXY_TEXTURE_2D), 3128 const_iv (GL_PROXY_TEXTURE_2D),
2554 const_iv (GL_TEXTURE_1D), 3129 const_iv (GL_TEXTURE_1D),
2555 const_iv (GL_TEXTURE_2D), 3130 const_iv (GL_TEXTURE_2D),
2594 const_iv (GL_PERSPECTIVE_CORRECTION_HINT), 3169 const_iv (GL_PERSPECTIVE_CORRECTION_HINT),
2595 const_iv (GL_POINT_SMOOTH_HINT), 3170 const_iv (GL_POINT_SMOOTH_HINT),
2596 const_iv (GL_LINE_SMOOTH_HINT), 3171 const_iv (GL_LINE_SMOOTH_HINT),
2597 const_iv (GL_POLYGON_SMOOTH_HINT), 3172 const_iv (GL_POLYGON_SMOOTH_HINT),
2598 const_iv (GL_GENERATE_MIPMAP_HINT), 3173 const_iv (GL_GENERATE_MIPMAP_HINT),
3174 const_iv (GL_TEXTURE_COMPRESSION_HINT),
2599 const_iv (GL_FASTEST), 3175 const_iv (GL_FASTEST),
2600 const_iv (GL_DONT_CARE), 3176 const_iv (GL_DONT_CARE),
2601 const_iv (GL_NICEST), 3177 const_iv (GL_NICEST),
2602 const_iv (GL_V2F), 3178 const_iv (GL_V2F),
2603 const_iv (GL_V3F), 3179 const_iv (GL_V3F),
2604 const_iv (GL_T2F_V3F), 3180 const_iv (GL_T2F_V3F),
2605 const_iv (GL_T2F_N3F_V3F), 3181 const_iv (GL_T2F_N3F_V3F),
3182 const_iv (GL_FUNC_ADD),
3183 const_iv (GL_FUNC_SUBTRACT),
3184 const_iv (GL_FUNC_REVERSE_SUBTRACT),
2606# undef const_iv 3185# undef const_iv
2607 }; 3186 };
2608 3187
2609 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 3188 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
2610 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 3189 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
2611 3190
2612 texture_av = newAV (); 3191 texture_av = newAV ();
2613 AvREAL_off (texture_av); 3192 AvREAL_off (texture_av);
2614} 3193}
2615 3194
2616char * 3195void
3196disable_GL_EXT_blend_func_separate ()
3197 CODE:
3198 gl.BlendFuncSeparate = 0;
3199 gl.BlendFuncSeparateEXT = 0;
3200
3201void
3202apple_nvidia_bug (int enable)
3203
3204const char *
2617gl_vendor () 3205gl_vendor ()
2618 CODE: 3206 CODE:
2619 RETVAL = (char *)glGetString (GL_VENDOR); 3207 RETVAL = (const char *)glGetString (GL_VENDOR);
2620 OUTPUT: 3208 OUTPUT:
2621 RETVAL 3209 RETVAL
2622 3210
2623char * 3211const char *
2624gl_version () 3212gl_version ()
2625 CODE: 3213 CODE:
2626 RETVAL = (char *)glGetString (GL_VERSION); 3214 RETVAL = (const char *)glGetString (GL_VERSION);
2627 OUTPUT: 3215 OUTPUT:
2628 RETVAL 3216 RETVAL
2629 3217
2630char * 3218const char *
2631gl_extensions () 3219gl_extensions ()
2632 CODE: 3220 CODE:
2633 RETVAL = (char *)glGetString (GL_EXTENSIONS); 3221 RETVAL = (const char *)glGetString (GL_EXTENSIONS);
2634 OUTPUT: 3222 OUTPUT:
2635 RETVAL 3223 RETVAL
2636 3224
2637const char *glGetString (GLenum pname) 3225const char *glGetString (GLenum pname)
3226 CODE:
3227 RETVAL = (const char *)glGetString (pname);
3228 OUTPUT:
3229 RETVAL
2638 3230
2639GLint glGetInteger (GLenum pname) 3231GLint glGetInteger (GLenum pname)
2640 CODE: 3232 CODE:
2641 glGetIntegerv (pname, &RETVAL); 3233 glGetIntegerv (pname, &RETVAL);
2642 OUTPUT: 3234 OUTPUT:
2650 3242
2651int glGetError () 3243int glGetError ()
2652 3244
2653void glFinish () 3245void glFinish ()
2654 3246
3247void glFlush ()
3248
2655void glClear (int mask) 3249void glClear (int mask)
2656 3250
2657void glClearColor (float r, float g, float b, float a = 1.0) 3251void glClearColor (float r, float g, float b, float a = 1.0)
2658 PROTOTYPE: @ 3252 PROTOTYPE: @
2659 3253
2668void glBlendFunc (int sfactor, int dfactor) 3262void glBlendFunc (int sfactor, int dfactor)
2669 3263
2670void glBlendFuncSeparate (int sa, int da, int saa, int daa) 3264void glBlendFuncSeparate (int sa, int da, int saa, int daa)
2671 CODE: 3265 CODE:
2672 gl_BlendFuncSeparate (sa, da, saa, daa); 3266 gl_BlendFuncSeparate (sa, da, saa, daa);
3267
3268# void glBlendEquation (int se)
2673 3269
2674void glDepthMask (int flag) 3270void glDepthMask (int flag)
2675 3271
2676void glLogicOp (int opcode) 3272void glLogicOp (int opcode)
2677 3273
2712void glRotate (float angle, float x, float y, float z) 3308void glRotate (float angle, float x, float y, float z)
2713 CODE: 3309 CODE:
2714 glRotatef (angle, x, y, z); 3310 glRotatef (angle, x, y, z);
2715 3311
2716void glColor (float r, float g, float b, float a = 1.0) 3312void glColor (float r, float g, float b, float a = 1.0)
3313 PROTOTYPE: @
2717 ALIAS: 3314 ALIAS:
2718 glColor_premultiply = 1 3315 glColor_premultiply = 1
2719 CODE: 3316 CODE:
2720 if (ix) 3317 if (ix)
2721 { 3318 {
2741 3338
2742void glRect (float x1, float y1, float x2, float y2) 3339void glRect (float x1, float y1, float x2, float y2)
2743 CODE: 3340 CODE:
2744 glRectf (x1, y1, x2, y2); 3341 glRectf (x1, y1, x2, y2);
2745 3342
3343void glRect_lineloop (float x1, float y1, float x2, float y2)
3344 CODE:
3345 glBegin (GL_LINE_LOOP);
3346 glVertex2f (x1, y1);
3347 glVertex2f (x2, y1);
3348 glVertex2f (x2, y2);
3349 glVertex2f (x1, y2);
3350 glEnd ();
3351
2746PROTOTYPES: ENABLE 3352PROTOTYPES: ENABLE
2747 3353
2748void glBegin (int mode) 3354void glBegin (int mode)
2749 3355
2750void glEnd () 3356void glEnd ()
2782void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) 3388void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column)
2783 CODE: 3389 CODE:
2784 if (gl.SeparableFilter2D) 3390 if (gl.SeparableFilter2D)
2785 gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); 3391 gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column);
2786 3392
2787void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data) 3393void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data = 0)
2788 3394
2789void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) 3395void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border)
2790 3396
2791void glDrawPixels (int width, int height, int format, int type, char *pixels) 3397void glDrawPixels (int width, int height, int format, int type, char *pixels)
2792 3398
2818 3424
2819void glEndList () 3425void glEndList ()
2820 3426
2821void glCallList (int list) 3427void glCallList (int list)
2822 3428
2823MODULE = CFPlus PACKAGE = CFPlus::UI::Base 3429void c_init ()
3430 CODE:
3431 glPixelStorei (GL_PACK_ALIGNMENT , 1);
3432 glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
3433
3434MODULE = Deliantra::Client PACKAGE = DC::UI::Base
2824 3435
2825PROTOTYPES: DISABLE 3436PROTOTYPES: DISABLE
2826 3437
2827void 3438void
2828find_widget (SV *self, NV x, NV y) 3439find_widget (SV *self, NV x, NV y)
2829 PPCODE: 3440 PPCODE:
2830{ 3441{
2831 if (within_widget (self, x, y)) 3442 if (within_widget (self, x, y))
2832 XPUSHs (self); 3443 XPUSHs (self);
2833} 3444}
2834 3445
2835BOOT: 3446BOOT:
2836{ 3447{
2837 hover_gv = gv_fetchpv ("CFPlus::UI::HOVER", 1, SVt_NV); 3448 hover_gv = gv_fetchpv ("DC::UI::HOVER", 1, SVt_NV);
2838 3449
2839 draw_x_gv = gv_fetchpv ("CFPlus::UI::Base::draw_x", 1, SVt_NV); 3450 draw_x_gv = gv_fetchpv ("DC::UI::Base::draw_x", 1, SVt_NV);
2840 draw_y_gv = gv_fetchpv ("CFPlus::UI::Base::draw_y", 1, SVt_NV); 3451 draw_y_gv = gv_fetchpv ("DC::UI::Base::draw_y", 1, SVt_NV);
2841 draw_w_gv = gv_fetchpv ("CFPlus::UI::Base::draw_w", 1, SVt_NV); 3452 draw_w_gv = gv_fetchpv ("DC::UI::Base::draw_w", 1, SVt_NV);
2842 draw_h_gv = gv_fetchpv ("CFPlus::UI::Base::draw_h", 1, SVt_NV); 3453 draw_h_gv = gv_fetchpv ("DC::UI::Base::draw_h", 1, SVt_NV);
2843} 3454}
2844 3455
2845void 3456void
2846draw (SV *self) 3457draw (SV *self)
2847 CODE: 3458 CODE:
2848{ 3459{
2849 HV *hv; 3460 HV *hv;
2850 SV **svp; 3461 SV **svp;
2851 NV x, y, w, h; 3462 NV x, y, w, h;
2852 SV *draw_x_sv = GvSV (draw_x_gv); 3463 SV *draw_x_sv = GvSV (draw_x_gv);
2853 SV *draw_y_sv = GvSV (draw_y_gv); 3464 SV *draw_y_sv = GvSV (draw_y_gv);
2854 SV *draw_w_sv = GvSV (draw_w_gv); 3465 SV *draw_w_sv = GvSV (draw_w_gv);
2855 SV *draw_h_sv = GvSV (draw_h_gv); 3466 SV *draw_h_sv = GvSV (draw_h_gv);
2856 SV *hover;
2857 double draw_x, draw_y, draw_w, draw_h; 3467 double draw_x, draw_y;
2858 3468
2859 if (!SvROK (self)) 3469 if (!SvROK (self))
2860 croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self)); 3470 croak ("DC::Base::draw: %s not a reference", SvPV_nolen (self));
2861 3471
2862 hv = (HV *)SvRV (self); 3472 hv = (HV *)SvRV (self);
2863 3473
2864 if (SvTYPE (hv) != SVt_PVHV) 3474 if (SvTYPE (hv) != SVt_PVHV)
2865 croak ("CFPlus::Base::draw: %s not a hashref", SvPV_nolen (self)); 3475 croak ("DC::Base::draw: %s not a hashref", SvPV_nolen (self));
2866 3476
2867 svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.; 3477 svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.;
2868 svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.; 3478 svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.;
2869 3479
2870 if (!h || !w) 3480 if (!h || !w)
2890 { 3500 {
2891 svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); 3501 svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0);
2892 3502
2893 if (svp && SvTRUE (*svp)) 3503 if (svp && SvTRUE (*svp))
2894 { 3504 {
2895 glColor4f (1*0.2f, 0.8*0.2f, 0.5*0.2f, 0.2f); 3505 glColor4f (1.0f * 0.2f, 0.8f * 0.2f, 0.5f * 0.2f, 0.2f);
2896 glEnable (GL_BLEND); 3506 glEnable (GL_BLEND);
2897 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 3507 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
2898 glBegin (GL_QUADS); 3508 glBegin (GL_QUADS);
2899 glVertex2f (0, 0); 3509 glVertex2f (0, 0);
2900 glVertex2f (w, 0); 3510 glVertex2f (w, 0);
2903 glEnd (); 3513 glEnd ();
2904 glDisable (GL_BLEND); 3514 glDisable (GL_BLEND);
2905 } 3515 }
2906 } 3516 }
2907#if 0 3517#if 0
2908 if ($ENV{CFPLUS_DEBUG} & 1) { 3518 // draw borders, for debugging
2909 glPushMatrix; 3519 glPushMatrix ();
2910 glColor 1, 1, 0, 1; 3520 glColor4f (1., 1., 0., 1.);
2911 glTranslate 0.375, 0.375; 3521 glTranslatef (.5, .5, 0.);
2912 glBegin GL_LINE_LOOP; 3522 glBegin (GL_LINE_LOOP);
2913 glVertex 0 , 0; 3523 glVertex2f (0 , 0);
2914 glVertex $self->{w} - 1, 0; 3524 glVertex2f (w - 1, 0);
2915 glVertex $self->{w} - 1, $self->{h} - 1; 3525 glVertex2f (w - 1, h - 1);
2916 glVertex 0 , $self->{h} - 1; 3526 glVertex2f (0 , h - 1);
2917 glEnd; 3527 glEnd ();
2918 glPopMatrix; 3528 glPopMatrix ();
2919 #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
2920 }
2921#endif 3529#endif
2922 PUSHMARK (SP); 3530 PUSHMARK (SP);
2923 XPUSHs (self); 3531 XPUSHs (self);
2924 PUTBACK; 3532 PUTBACK;
2925 call_method ("_draw", G_VOID | G_DISCARD); 3533 call_method ("_draw", G_VOID | G_DISCARD);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines