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.110 by root, Sat Jun 10 02:22:33 2006 UTC vs.
Revision 1.174 by root, Fri Apr 6 07:45:34 2007 UTC

1#ifdef _WIN32 1#ifdef _WIN32
2# define _WIN32_WINNT 0x0500 // needed to get win2000 api calls 2# define WIN32_LEAN_AND_MEAN
3# define NTDDI_VERSION NTDDI_WIN2K // needed to get win2000 api calls
3# include <malloc.h> 4# include <malloc.h>
4# include <windows.h> 5# include <windows.h>
6# include <wininet.h>
5# pragma warning(disable:4244) 7# pragma warning(disable:4244)
8# pragma warning(disable:4761)
6#endif 9#endif
7 10
8#include "EXTERN.h" 11#include "EXTERN.h"
9#include "perl.h" 12#include "perl.h"
10#include "XSUB.h" 13#include "XSUB.h"
11 14
15#ifdef _WIN32
16# undef pipe
17#endif
18
19#include <assert.h>
12#include <math.h> 20#include <math.h>
13#include <string.h> 21#include <string.h>
14#include <stdio.h> 22#include <stdio.h>
23#include <stdlib.h>
15 24
16#include <SDL.h> 25#include <SDL.h>
17#include <SDL_endian.h> 26#include <SDL_endian.h>
18#include <SDL_image.h> 27#include <SDL_image.h>
19#include <SDL_mixer.h> 28#include <SDL_mixer.h>
20#include <SDL_opengl.h> 29#include <SDL_opengl.h>
21 30
31#define PANGO_ENABLE_BACKEND
32#define G_DISABLE_CAST_CHECKS
33
22#include <glib/gmacros.h> 34#include <glib/gmacros.h>
23 35
24#include <pango/pango.h> 36#include <pango/pango.h>
25#include <pango/pangofc-fontmap.h>
26#include <pango/pangoft2.h>
27#include <pango/pangocairo.h>
28 37
29#ifndef _WIN32 38#ifndef _WIN32
30# include <sys/types.h> 39# include <sys/types.h>
31# include <sys/socket.h> 40# include <sys/socket.h>
32# include <netinet/in.h> 41# include <netinet/in.h>
33# include <netinet/tcp.h> 42# include <netinet/tcp.h>
34# include <inttypes.h> 43# include <inttypes.h>
35#else
36 typedef unsigned char uint8_t;
37 typedef unsigned short uint16_t;
38 typedef unsigned int uint32_t;
39 typedef signed char int8_t;
40 typedef signed short int16_t;
41 typedef signed int int32_t;
42#endif 44#endif
43 45
44#include "glext.h" 46#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */
45 47
46#define FOW_DARKNESS 32 48#define FOW_DARKNESS 32
47 49
48#define MAP_EXTEND_X 32 50#define MAP_EXTEND_X 32
49#define MAP_EXTEND_Y 512 51#define MAP_EXTEND_Y 512
50 52
51#define MIN_FONT_HEIGHT 10 53#define MIN_FONT_HEIGHT 10
54
55#if 0
56# define PARACHUTE SDL_INIT_NOPARACHUTE
57#else
58# define PARACHUTE 0
59#endif
52 60
53static struct 61static struct
54{ 62{
55#define GL_FUNC(ptr,name) ptr name; 63#define GL_FUNC(ptr,name) ptr name;
56#include "glfunc.h" 64#include "glfunc.h"
65 gl.BlendFuncSeparateEXT (sa, da, saa, daa); 73 gl.BlendFuncSeparateEXT (sa, da, saa, daa);
66 else 74 else
67 glBlendFunc (sa, da); 75 glBlendFunc (sa, da);
68} 76}
69 77
78#include "texcache.c"
79
80#include "pango-font.c"
81#include "pango-fontmap.c"
82#include "pango-render.c"
83
70typedef Mix_Chunk *CFClient__MixChunk; 84typedef Mix_Chunk *CFPlus__MixChunk;
71typedef Mix_Music *CFClient__MixMusic; 85typedef Mix_Music *CFPlus__MixMusic;
72 86
73typedef PangoFontDescription *CFClient__Font; 87typedef PangoFontDescription *CFPlus__Font;
88
89static int
90shape_attr_p (PangoLayoutRun *run)
91{
92 GSList *attrs = run->item->analysis.extra_attrs;
93
94 while (attrs)
95 {
96 PangoAttribute *attr = attrs->data;
97
98 if (attr->klass->type == PANGO_ATTR_SHAPE)
99 return 1;
100
101 attrs = attrs->next;
102 }
103
104 return 0;
105}
74 106
75typedef struct cf_layout { 107typedef struct cf_layout {
76 PangoLayout *pl; // either derived from a cairo or ft2 context 108 PangoLayout *pl;
77 int rgba; // wether we use rgba (cairo) or grayscale (ft2)
78 float r, g, b, a; // default color for rgba mode 109 float r, g, b, a; // default color for rgba mode
79 int base_height; 110 int base_height;
80 CFClient__Font font; 111 CFPlus__Font font;
81} *CFClient__Layout; 112} *CFPlus__Layout;
82 113
83static CFClient__Font default_font; 114static CFPlus__Font default_font;
84static PangoContext *ft2_context, *cairo_context; 115static PangoContext *opengl_context;
85static PangoFontMap *ft2_fontmap, *cairo_fontmap; 116static PangoFontMap *opengl_fontmap;
86 117
87static void 118static void
88substitute_func (FcPattern *pattern, gpointer data) 119substitute_func (FcPattern *pattern, gpointer data)
89{ 120{
90 FcPatternAddBool (pattern, FC_HINTING, 1); 121 FcPatternAddBool (pattern, FC_HINTING, 1);
91#ifdef FC_HINT_STYLE 122#ifdef FC_HINT_STYLE
92 FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); 123 FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL);
93#endif 124#endif
94#ifdef _WIN32
95 FcPatternAddBool (pattern, FC_AUTOHINT, 1);
96#else
97 FcPatternAddBool (pattern, FC_AUTOHINT, 0); 125 FcPatternAddBool (pattern, FC_AUTOHINT, 0);
98#endif
99} 126}
100 127
101static void 128static void
102layout_update_font (CFClient__Layout self) 129layout_update_font (CFPlus__Layout self)
103{ 130{
104 /* use a random scale factor to account for unknown descenders, 0.8 works 131 /* use a random scale factor to account for unknown descenders, 0.8 works
105 * reasonably well with bitstream vera 132 * reasonably well with bitstream vera
106 */ 133 */
107 PangoFontDescription *font = self->font ? self->font : default_font; 134 PangoFontDescription *font = self->font ? self->font : default_font;
111 138
112 pango_layout_set_font_description (self->pl, font); 139 pango_layout_set_font_description (self->pl, font);
113} 140}
114 141
115static void 142static void
116layout_get_pixel_size (CFClient__Layout self, int *w, int *h) 143layout_get_pixel_size (CFPlus__Layout self, int *w, int *h)
117{ 144{
145 PangoRectangle rect;
146
147 // get_pixel_* wrongly rounds down
118 pango_layout_get_pixel_size (self->pl, w, h); 148 pango_layout_get_extents (self->pl, 0, &rect);
119 149
120 if (!*w) *w = 1; 150 rect.width = (rect.width + PANGO_SCALE - 1) / PANGO_SCALE;
121 if (!*h) *h = 1; 151 rect.height = (rect.height + PANGO_SCALE - 1) / PANGO_SCALE;
122 152
123 *w = (*w + 3) & ~3; 153 if (!rect.width) rect.width = 1;
124} 154 if (!rect.height) rect.height = 1;
125 155
156 *w = rect.width;
157 *h = rect.height;
158}
159
160typedef uint16_t tileid;
126typedef uint16_t mapface; 161typedef uint16_t faceid;
127 162
128typedef struct { 163typedef struct {
129 GLint name; 164 int name;
130 int w, h; 165 int w, h;
131 float s, t; 166 float s, t;
132 uint8_t r, g, b, a; 167 uint8_t r, g, b, a;
133} maptex; 168} maptex;
134 169
135typedef struct { 170typedef struct {
171 uint32_t player;
172 tileid tile[3];
136 int16_t darkness; 173 uint16_t darkness;
137 mapface face[3]; 174 uint8_t stat_width, stat_hp, flags;
138} mapcell; 175} mapcell;
139 176
140typedef struct { 177typedef struct {
141 int32_t c0, c1; 178 int32_t c0, c1;
142 mapcell *col; 179 mapcell *col;
143} maprow; 180} maprow;
144 181
145typedef struct map { 182typedef struct map {
146 int x, y, w, h; 183 int x, y, w, h;
147 int ox, oy; /* offset to virtual global coordinate system */ 184 int ox, oy; /* offset to virtual global coordinate system */
148 int faces; 185 int faces; tileid *face2tile; // [faceid]
149 mapface *face; 186 int texs; maptex *tex; // [tileid]
150
151 int texs;
152 maptex *tex;
153 187
154 int32_t rows; 188 int32_t rows;
155 maprow *row; 189 maprow *row;
156} *CFClient__Map; 190} *CFPlus__Map;
157 191
158static char * 192static char *
159prepend (char *ptr, int sze, int inc) 193prepend (char *ptr, int sze, int inc)
160{ 194{
161 char *p; 195 char *p;
178} 212}
179 213
180#define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) 214#define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
181#define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) 215#define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
182 216
217static void
218need_facenum (struct map *self, faceid face)
219{
220 while (self->faces <= face)
221 {
222 Append (tileid, self->face2tile, self->faces, self->faces);
223 self->faces *= 2;
224 }
225}
226
227static void
228need_texid (struct map *self, int texid)
229{
230 while (self->texs <= texid)
231 {
232 Append (maptex, self->tex, self->texs, self->texs);
233 self->texs *= 2;
234 }
235}
236
183static maprow * 237static maprow *
184map_get_row (CFClient__Map self, int y) 238map_get_row (CFPlus__Map self, int y)
185{ 239{
186 if (0 > y) 240 if (0 > y)
187 { 241 {
188 int extend = - y + MAP_EXTEND_Y; 242 int extend = - y + MAP_EXTEND_Y;
189 Prepend (maprow, self->row, self->rows, extend); 243 Prepend (maprow, self->row, self->rows, extend);
227 281
228 return row->col + (x - row->c0); 282 return row->col + (x - row->c0);
229} 283}
230 284
231static mapcell * 285static mapcell *
232map_get_cell (CFClient__Map self, int x, int y) 286map_get_cell (CFPlus__Map self, int x, int y)
233{ 287{
234 return row_get_cell (map_get_row (self, y), x); 288 return row_get_cell (map_get_row (self, y), x);
235} 289}
236 290
237static void 291static void
238map_clear (CFClient__Map self) 292map_clear (CFPlus__Map self)
239{ 293{
240 int r; 294 int r;
241 295
242 for (r = 0; r < self->rows; r++) 296 for (r = 0; r < self->rows; r++)
243 Safefree (self->row[r].col); 297 Safefree (self->row[r].col);
251 self->row = 0; 305 self->row = 0;
252 self->rows = 0; 306 self->rows = 0;
253} 307}
254 308
255static void 309static void
256map_blank (CFClient__Map self, int x0, int y0, int w, int h) 310map_blank (CFPlus__Map self, int x0, int y0, int w, int h)
257{ 311{
258 int x, y; 312 int x, y;
259 maprow *row; 313 maprow *row;
314 mapcell *cell;
260 315
261 for (y = y0; y < y0 + h; y++) 316 for (y = y0; y < y0 + h; y++)
262 if (y >= 0) 317 if (y >= 0)
263 { 318 {
264 if (y >= self->rows) 319 if (y >= self->rows)
270 if (x >= row->c0) 325 if (x >= row->c0)
271 { 326 {
272 if (x >= row->c1) 327 if (x >= row->c1)
273 break; 328 break;
274 329
275 row->col[x - row->c0].darkness = -1; 330 cell = row->col + x - row->c0;
331
332 cell->darkness = 0;
333 cell->stat_hp = 0;
334 cell->flags = 0;
335 cell->player = 0;
276 } 336 }
277 } 337 }
278} 338}
279 339
280static void 340static void
301 ev.data2 = 0; 361 ev.data2 = 0;
302 362
303 SDL_PushEvent ((SDL_Event *)&ev); 363 SDL_PushEvent ((SDL_Event *)&ev);
304} 364}
305 365
366static unsigned int
367minpot (unsigned int n)
368{
369 if (!n)
370 return 0;
371
372 --n;
373
374 n |= n >> 1;
375 n |= n >> 2;
376 n |= n >> 4;
377 n |= n >> 8;
378 n |= n >> 16;
379
380 return n + 1;
381}
382
383/* SDL should provide this, really. */
384#define SDLK_MODIFIER_MIN 300
385#define SDLK_MODIFIER_MAX 314
386
306MODULE = CFClient PACKAGE = CFClient 387MODULE = CFPlus PACKAGE = CFPlus
307 388
308PROTOTYPES: ENABLE 389PROTOTYPES: ENABLE
309 390
310BOOT: 391BOOT:
311{ 392{
312 HV *stash = gv_stashpv ("CFClient", 1); 393 HV *stash = gv_stashpv ("CFPlus", 1);
313 static const struct { 394 static const struct {
314 const char *name; 395 const char *name;
315 IV iv; 396 IV iv;
316 } *civ, const_iv[] = { 397 } *civ, const_iv[] = {
317# define const_iv(name) { # name, (IV)name } 398# define const_iv(name) { # name, (IV)name }
399 const_iv (SDLK_MODIFIER_MIN),
400 const_iv (SDLK_MODIFIER_MAX),
401
318 const_iv (SDL_ACTIVEEVENT), 402 const_iv (SDL_ACTIVEEVENT),
319 const_iv (SDL_KEYDOWN), 403 const_iv (SDL_KEYDOWN),
320 const_iv (SDL_KEYUP), 404 const_iv (SDL_KEYUP),
321 const_iv (SDL_MOUSEMOTION), 405 const_iv (SDL_MOUSEMOTION),
322 const_iv (SDL_MOUSEBUTTONDOWN), 406 const_iv (SDL_MOUSEBUTTONDOWN),
331 const_iv (SDL_EVENT_RESERVEDA), 415 const_iv (SDL_EVENT_RESERVEDA),
332 const_iv (SDL_EVENT_RESERVEDB), 416 const_iv (SDL_EVENT_RESERVEDB),
333 const_iv (SDL_VIDEORESIZE), 417 const_iv (SDL_VIDEORESIZE),
334 const_iv (SDL_VIDEOEXPOSE), 418 const_iv (SDL_VIDEOEXPOSE),
335 const_iv (SDL_USEREVENT), 419 const_iv (SDL_USEREVENT),
420
421 const_iv (SDL_APPINPUTFOCUS),
422 const_iv (SDL_APPMOUSEFOCUS),
423 const_iv (SDL_APPACTIVE),
424
336 const_iv (SDLK_KP0), 425 const_iv (SDLK_KP0),
337 const_iv (SDLK_KP1), 426 const_iv (SDLK_KP1),
338 const_iv (SDLK_KP2), 427 const_iv (SDLK_KP2),
339 const_iv (SDLK_KP3), 428 const_iv (SDLK_KP3),
340 const_iv (SDLK_KP4), 429 const_iv (SDLK_KP4),
395 const_iv (SDLK_BREAK), 484 const_iv (SDLK_BREAK),
396 const_iv (SDLK_MENU), 485 const_iv (SDLK_MENU),
397 const_iv (SDLK_POWER), 486 const_iv (SDLK_POWER),
398 const_iv (SDLK_EURO), 487 const_iv (SDLK_EURO),
399 const_iv (SDLK_UNDO), 488 const_iv (SDLK_UNDO),
489
400 const_iv (KMOD_NONE), 490 const_iv (KMOD_NONE),
491 const_iv (KMOD_SHIFT),
401 const_iv (KMOD_LSHIFT), 492 const_iv (KMOD_LSHIFT),
402 const_iv (KMOD_RSHIFT), 493 const_iv (KMOD_RSHIFT),
494 const_iv (KMOD_CTRL),
403 const_iv (KMOD_LCTRL), 495 const_iv (KMOD_LCTRL),
404 const_iv (KMOD_RCTRL), 496 const_iv (KMOD_RCTRL),
497 const_iv (KMOD_ALT),
405 const_iv (KMOD_LALT), 498 const_iv (KMOD_LALT),
406 const_iv (KMOD_RALT), 499 const_iv (KMOD_RALT),
500 const_iv (KMOD_META),
407 const_iv (KMOD_LMETA), 501 const_iv (KMOD_LMETA),
408 const_iv (KMOD_RMETA), 502 const_iv (KMOD_RMETA),
409 const_iv (KMOD_NUM), 503 const_iv (KMOD_NUM),
410 const_iv (KMOD_CAPS), 504 const_iv (KMOD_CAPS),
411 const_iv (KMOD_MODE), 505 const_iv (KMOD_MODE),
412 const_iv (KMOD_CTRL),
413 const_iv (KMOD_SHIFT),
414 const_iv (KMOD_ALT),
415 const_iv (KMOD_META)
416# undef const_iv 506# undef const_iv
417 }; 507 };
418 508
419 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 509 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
420 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 510 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
511
512 assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK);
513 assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE);
421} 514}
515
516void
517weaken (SV *rv)
518 PROTOTYPE: $
519 CODE:
520 sv_rvweaken (rv);
521
522int
523in_destruct ()
524 CODE:
525 RETVAL = PL_main_cv == Nullcv;
526 OUTPUT:
527 RETVAL
528
529NV floor (NV x)
530
531NV ceil (NV x)
422 532
423void 533void
424pango_init () 534pango_init ()
425 CODE: 535 CODE:
426 // delayed, so it can pick up new fonts added by AddFontResourceEx
427{ 536{
428 {
429 ft2_fontmap = pango_ft2_font_map_new (); 537 opengl_fontmap = pango_opengl_font_map_new ();
430 pango_ft2_font_map_set_default_substitute ((PangoFT2FontMap *)ft2_fontmap, substitute_func, 0, 0); 538 pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0);
431 ft2_context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)ft2_fontmap); 539 opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap);
432 }
433 {
434 cairo_font_options_t *fopt = cairo_font_options_create ();
435 cairo_fontmap = pango_cairo_font_map_get_default ();
436 cairo_context = pango_cairo_font_map_create_context ((PangoCairoFontMap *)cairo_fontmap);
437#ifdef _WIN32
438 // cairo looks like shit eaten twice on windows
439 cairo_font_options_set_antialias (fopt, CAIRO_ANTIALIAS_NONE);
440#else
441 cairo_font_options_set_antialias (fopt, CAIRO_ANTIALIAS_GRAY);
442#endif
443 cairo_font_options_set_hint_style (fopt, CAIRO_HINT_STYLE_FULL);
444 cairo_font_options_set_hint_metrics (fopt, CAIRO_HINT_METRICS_ON);
445 pango_cairo_context_set_font_options (cairo_context, fopt);
446 cairo_font_options_destroy (fopt);
447 }
448} 540}
449 541
450int 542int
451SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO) 543SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE)
452 544
453void 545void
454SDL_Quit () 546SDL_Quit ()
455 547
456void 548void
463 SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 5); 555 SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 5);
464 SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 5); 556 SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 5);
465 SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE, 1); 557 SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE, 1);
466 558
467 SDL_GL_SetAttribute (SDL_GL_BUFFER_SIZE, 15); 559 SDL_GL_SetAttribute (SDL_GL_BUFFER_SIZE, 15);
468 SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16); 560 SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 0);
469 561
470 SDL_GL_SetAttribute (SDL_GL_ACCUM_RED_SIZE, 0); 562 SDL_GL_SetAttribute (SDL_GL_ACCUM_RED_SIZE, 0);
471 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); 563 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0);
472 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); 564 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0);
473 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); 565 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0);
474 566
475 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); 567 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
568#if SDL_VERSION_ATLEAST(1,2,10)
569 SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1);
570 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
571#endif
476 572
477 SDL_EnableUNICODE (1); 573 SDL_EnableUNICODE (1);
478 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); 574 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
479 575
480 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); 576 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL);
532 case SDL_KEYDOWN: 628 case SDL_KEYDOWN:
533 case SDL_KEYUP: 629 case SDL_KEYUP:
534 hv_store (hv, "state", 5, newSViv (ev.key.state), 0); 630 hv_store (hv, "state", 5, newSViv (ev.key.state), 0);
535 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); 631 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0);
536 hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0); 632 hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0);
633 hv_store (hv, "cmod", 4, newSViv (SDL_GetModState ()), 0); /* current mode */
537 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); 634 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0);
538 break; 635 break;
539 636
540 case SDL_ACTIVEEVENT: 637 case SDL_ACTIVEEVENT:
541 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); 638 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0);
567 hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); 664 hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0);
568 hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); 665 hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0);
569 break; 666 break;
570 } 667 }
571 668
572 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 669 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1))));
573 } 670 }
574} 671}
575 672
576int 673int
577Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048) 674Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048)
591#ifndef _WIN32 688#ifndef _WIN32
592 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); 689 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val));
593#endif 690#endif
594 691
595void 692void
693win32_proxy_info ()
694 PPCODE:
695{
696#ifdef _WIN32
697 char buffer[2048];
698 DWORD buflen;
699
700 EXTEND (SP, 3);
701
702 buflen = sizeof (buffer);
703 if (InternetQueryOption (0, INTERNET_OPTION_PROXY, (void *)buffer, &buflen))
704 if (((INTERNET_PROXY_INFO *)buffer)->dwAccessType == INTERNET_OPEN_TYPE_PROXY)
705 {
706 PUSHs (newSVpv (((INTERNET_PROXY_INFO *)buffer)->lpszProxy, 0));
707
708 buflen = sizeof (buffer);
709 if (InternetQueryOption (0, INTERNET_OPTION_PROXY_USERNAME, (void *)buffer, &buflen))
710 {
711 PUSHs (newSVpv (buffer, 0));
712
713 buflen = sizeof (buffer);
714 if (InternetQueryOption (0, INTERNET_OPTION_PROXY_PASSWORD, (void *)buffer, &buflen))
715 PUSHs (newSVpv (buffer, 0));
716 }
717 }
718#endif
719}
720
721void
596add_font (char *file) 722add_font (char *file)
597 CODE: 723 CODE:
598 FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ 724 FcConfigAppFontAddFile (0, (const FcChar8 *)file);
599#ifdef _WIN32
600 // cairo... sigh... requires win2000
601 AddFontResourceEx (file, FR_PRIVATE, 0);
602#endif
603 725
604void 726void
605load_image_inline (SV *image_) 727load_image_inline (SV *image_)
606 ALIAS: 728 ALIAS:
607 load_image_file = 1 729 load_image_file = 1
649 771
650 surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); 772 surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE);
651 773
652 assert (surface2->pitch == surface2->w * 4); 774 assert (surface2->pitch == surface2->w * 4);
653 775
776 SDL_LockSurface (surface2);
654 EXTEND (SP, 5); 777 EXTEND (SP, 6);
655 PUSHs (sv_2mortal (newSViv (surface2->w))); 778 PUSHs (sv_2mortal (newSViv (surface2->w)));
656 PUSHs (sv_2mortal (newSViv (surface2->h))); 779 PUSHs (sv_2mortal (newSViv (surface2->h)));
657 SDL_LockSurface (surface2);
658 PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); 780 PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch)));
659 SDL_UnlockSurface (surface2);
660 PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); 781 PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB)));
661 PUSHs (sv_2mortal (newSViv (GL_RGBA))); 782 PUSHs (sv_2mortal (newSViv (GL_RGBA)));
662 PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); 783 PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE)));
784 SDL_UnlockSurface (surface2);
663 785
664 SDL_FreeSurface (surface); 786 SDL_FreeSurface (surface);
665 SDL_FreeSurface (surface2); 787 SDL_FreeSurface (surface2);
666} 788}
667 789
703 CODE: 825 CODE:
704 fprintf (stderr, "FATAL: %s\n", message); 826 fprintf (stderr, "FATAL: %s\n", message);
705#ifdef _WIN32 827#ifdef _WIN32
706 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); 828 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR);
707#endif 829#endif
708 exit (1); 830 _exit (1);
709 831
832void
833_exit (int retval = 0)
834 CODE:
835#ifdef WIN32
836 ExitThread (retval); // unclean, please beam me up
837#else
838 _exit (retval);
839#endif
840
710MODULE = CFClient PACKAGE = CFClient::Font 841MODULE = CFPlus PACKAGE = CFPlus::Font
711 842
712CFClient::Font 843CFPlus::Font
713new_from_file (SV *class, char *path, int id = 0) 844new_from_file (SV *class, char *path, int id = 0)
714 CODE: 845 CODE:
715{ 846{
716 int count; 847 int count;
717 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); 848 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count);
720} 851}
721 OUTPUT: 852 OUTPUT:
722 RETVAL 853 RETVAL
723 854
724void 855void
725DESTROY (CFClient::Font self) 856DESTROY (CFPlus::Font self)
726 CODE: 857 CODE:
727 pango_font_description_free (self); 858 pango_font_description_free (self);
728 859
729void 860void
730make_default (CFClient::Font self) 861make_default (CFPlus::Font self)
731 CODE: 862 CODE:
732 default_font = self; 863 default_font = self;
733 864
734MODULE = CFClient PACKAGE = CFClient::Layout 865MODULE = CFPlus PACKAGE = CFPlus::Layout
735 866
736CFClient::Layout 867void
737new (SV *class, int rgba = 0) 868reset_glyph_cache ()
869 CODE:
870 tc_clear ();
871
872CFPlus::Layout
873new (SV *class)
738 CODE: 874 CODE:
739 New (0, RETVAL, 1, struct cf_layout); 875 New (0, RETVAL, 1, struct cf_layout);
740 876
741 RETVAL->pl = pango_layout_new (rgba ? cairo_context : ft2_context); 877 RETVAL->pl = pango_layout_new (opengl_context);
742 RETVAL->rgba = rgba;
743 RETVAL->r = 1.; 878 RETVAL->r = 1.;
744 RETVAL->g = 1.; 879 RETVAL->g = 1.;
745 RETVAL->b = 1.; 880 RETVAL->b = 1.;
746 RETVAL->a = 1.; 881 RETVAL->a = 1.;
747 RETVAL->base_height = MIN_FONT_HEIGHT; 882 RETVAL->base_height = MIN_FONT_HEIGHT;
751 layout_update_font (RETVAL); 886 layout_update_font (RETVAL);
752 OUTPUT: 887 OUTPUT:
753 RETVAL 888 RETVAL
754 889
755void 890void
756DESTROY (CFClient::Layout self) 891DESTROY (CFPlus::Layout self)
757 CODE: 892 CODE:
758 g_object_unref (self->pl); 893 g_object_unref (self->pl);
759 Safefree (self); 894 Safefree (self);
760 895
896void
897set_text (CFPlus::Layout self, SV *text_)
898 CODE:
899{
900 STRLEN textlen;
901 char *text = SvPVutf8 (text_, textlen);
902
903 pango_layout_set_text (self->pl, text, textlen);
904}
905
906void
907set_markup (CFPlus::Layout self, SV *text_)
908 CODE:
909{
910 STRLEN textlen;
911 char *text = SvPVutf8 (text_, textlen);
912
913 pango_layout_set_markup (self->pl, text, textlen);
914}
915
916void
917set_shapes (CFPlus::Layout self, ...)
918 CODE:
919{
920 PangoAttrList *attrs = 0;
921 const char *text = pango_layout_get_text (self->pl);
922 const char *pos = text;
923 int arg = 4;
924
925 while (arg < items && (pos = strstr (pos, OBJ_STR)))
926 {
927 PangoRectangle inkrect, rect;
928 PangoAttribute *attr;
929
930 int x = SvIV (ST (arg - 3));
931 int y = SvIV (ST (arg - 2));
932 int w = SvIV (ST (arg - 1));
933 int h = SvIV (ST (arg ));
934
935 inkrect.x = 0;
936 inkrect.y = 0;
937 inkrect.width = 0;
938 inkrect.height = 0;
939
940 rect.x = x * PANGO_SCALE;
941 rect.y = y * PANGO_SCALE;
942 rect.width = w * PANGO_SCALE;
943 rect.height = h * PANGO_SCALE;
944
945 if (!attrs)
946 attrs = pango_layout_get_attributes (self->pl);
947
948 attr = pango_attr_shape_new (&inkrect, &rect);
949 attr->start_index = pos - text;
950 attr->end_index = attr->start_index + sizeof (OBJ_STR) - 1;
951 pango_attr_list_insert (attrs, attr);
952
953 arg += 4;
954 pos += sizeof (OBJ_STR) - 1;
955 }
956
957 if (attrs)
958 pango_layout_set_attributes (self->pl, attrs);
959}
960
961void
962get_shapes (CFPlus::Layout self)
963 PPCODE:
964{
965 PangoLayoutIter *iter = pango_layout_get_iter (self->pl);
966
967 do
968 {
969 PangoLayoutRun *run = pango_layout_iter_get_run (iter);
970
971 if (run && shape_attr_p (run))
972 {
973 PangoRectangle extents;
974 pango_layout_iter_get_run_extents (iter, 0, &extents);
975
976 EXTEND (SP, 2);
977 PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x))));
978 PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y))));
979 }
980 }
981 while (pango_layout_iter_next_run (iter));
982
983 pango_layout_iter_free (iter);
984}
985
761int 986int
762is_rgba (CFClient::Layout self) 987has_wrapped (CFPlus::Layout self)
763 CODE: 988 CODE:
764 RETVAL = self->rgba; 989{
990 int lines = 1;
991 const char *text = pango_layout_get_text (self->pl);
992
993 while (*text)
994 lines += *text++ == '\n';
995
996 RETVAL = lines < pango_layout_get_line_count (self->pl);
997}
765 OUTPUT: 998 OUTPUT:
766 RETVAL 999 RETVAL
767 1000
768void
769set_text (CFClient::Layout self, SV *text_)
770 CODE:
771{
772 STRLEN textlen;
773 char *text = SvPVutf8 (text_, textlen);
774
775 pango_layout_set_text (self->pl, text, textlen);
776}
777
778void
779set_markup (CFClient::Layout self, SV *text_)
780 CODE:
781{
782 STRLEN textlen;
783 char *text = SvPVutf8 (text_, textlen);
784
785 pango_layout_set_markup (self->pl, text, textlen);
786}
787
788SV * 1001SV *
789get_text (CFClient::Layout self) 1002get_text (CFPlus::Layout self)
790 CODE: 1003 CODE:
791 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); 1004 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0);
792 sv_utf8_decode (RETVAL); 1005 sv_utf8_decode (RETVAL);
793 OUTPUT: 1006 OUTPUT:
794 RETVAL 1007 RETVAL
795 1008
796void 1009void
797set_foreground (CFClient::Layout self, float r, float g, float b, float a = 1.) 1010set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.)
798 CODE: 1011 CODE:
799 self->r = r; 1012 self->r = r;
800 self->g = g; 1013 self->g = g;
801 self->b = b; 1014 self->b = b;
802 self->a = a; 1015 self->a = a;
803 1016
804void 1017void
805set_font (CFClient::Layout self, CFClient::Font font = 0) 1018set_font (CFPlus::Layout self, CFPlus::Font font = 0)
806 CODE: 1019 CODE:
807 if (self->font != font) 1020 if (self->font != font)
808 { 1021 {
809 self->font = font; 1022 self->font = font;
810 layout_update_font (self); 1023 layout_update_font (self);
811 } 1024 }
812 1025
813void 1026void
814set_height (CFClient::Layout self, int base_height) 1027set_height (CFPlus::Layout self, int base_height)
815 CODE: 1028 CODE:
816 if (self->base_height != base_height) 1029 if (self->base_height != base_height)
817 { 1030 {
818 self->base_height = base_height; 1031 self->base_height = base_height;
819 layout_update_font (self); 1032 layout_update_font (self);
820 } 1033 }
821 1034
822void 1035void
823set_width (CFClient::Layout self, int max_width = -1) 1036set_width (CFPlus::Layout self, int max_width = -1)
824 CODE: 1037 CODE:
825 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); 1038 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE);
826 1039
827void 1040void
828set_indent (CFClient::Layout self, int indent) 1041set_indent (CFPlus::Layout self, int indent)
829 CODE: 1042 CODE:
830 pango_layout_set_indent (self->pl, indent * PANGO_SCALE); 1043 pango_layout_set_indent (self->pl, indent * PANGO_SCALE);
831 1044
832void 1045void
833set_spacing (CFClient::Layout self, int spacing) 1046set_spacing (CFPlus::Layout self, int spacing)
834 CODE: 1047 CODE:
835 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); 1048 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE);
836 1049
837void 1050void
838set_ellipsise (CFClient::Layout self, int ellipsise) 1051set_ellipsise (CFPlus::Layout self, int ellipsise)
839 CODE: 1052 CODE:
840 pango_layout_set_ellipsize (self->pl, 1053 pango_layout_set_ellipsize (self->pl,
841 ellipsise == 1 ? PANGO_ELLIPSIZE_START 1054 ellipsise == 1 ? PANGO_ELLIPSIZE_START
842 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE 1055 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE
843 : ellipsise == 3 ? PANGO_ELLIPSIZE_END 1056 : ellipsise == 3 ? PANGO_ELLIPSIZE_END
844 : PANGO_ELLIPSIZE_NONE 1057 : PANGO_ELLIPSIZE_NONE
845 ); 1058 );
846 1059
847void 1060void
848set_single_paragraph_mode (CFClient::Layout self, int spm) 1061set_single_paragraph_mode (CFPlus::Layout self, int spm)
849 CODE: 1062 CODE:
850 pango_layout_set_single_paragraph_mode (self->pl, !!spm); 1063 pango_layout_set_single_paragraph_mode (self->pl, !!spm);
851 1064
852void 1065void
853size (CFClient::Layout self) 1066size (CFPlus::Layout self)
854 PPCODE: 1067 PPCODE:
855{ 1068{
856 int w, h; 1069 int w, h;
857 1070
858 layout_get_pixel_size (self, &w, &h); 1071 layout_get_pixel_size (self, &w, &h);
861 PUSHs (sv_2mortal (newSViv (w))); 1074 PUSHs (sv_2mortal (newSViv (w)));
862 PUSHs (sv_2mortal (newSViv (h))); 1075 PUSHs (sv_2mortal (newSViv (h)));
863} 1076}
864 1077
865int 1078int
1079descent (CFPlus::Layout self)
1080 CODE:
1081{
1082 PangoRectangle rect;
1083 PangoLayoutLine *line = pango_layout_get_line (self->pl, 0);
1084 pango_layout_line_get_pixel_extents (line, 0, &rect);
1085 RETVAL = PANGO_DESCENT (rect);
1086}
1087 OUTPUT:
1088 RETVAL
1089
1090int
866xy_to_index (CFClient::Layout self, int x, int y) 1091xy_to_index (CFPlus::Layout self, int x, int y)
867 CODE: 1092 CODE:
868{ 1093{
869 int index, trailing; 1094 int index, trailing;
870 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); 1095 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing);
871 RETVAL = index; 1096 RETVAL = index + trailing;
872} 1097}
873 OUTPUT: 1098 OUTPUT:
874 RETVAL 1099 RETVAL
875 1100
876void 1101void
877cursor_pos (CFClient::Layout self, int index) 1102cursor_pos (CFPlus::Layout self, int index)
878 PPCODE: 1103 PPCODE:
879{ 1104{
880 PangoRectangle strong_pos; 1105 PangoRectangle strong_pos;
881 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); 1106 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0);
882 1107
885 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1110 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
886 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); 1111 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE)));
887} 1112}
888 1113
889void 1114void
890render (CFClient::Layout self) 1115index_to_line_x (CFPlus::Layout self, int index, int trailing = 0)
891 PPCODE: 1116 PPCODE:
892{ 1117{
893 SV *retval; 1118 int line, x;
894 int w, h;
895 1119
896 layout_get_pixel_size (self, &w, &h); 1120 pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x);
1121 /* pango bug: line is between 1..numlines, not 0..numlines-1 */
897 1122
898 if (self->rgba)
899 {
900 cairo_surface_t *surface;
901 cairo_t *cairo;
902
903 retval = newSV (w * h * 4);
904 SvPOK_only (retval);
905 SvCUR_set (retval, w * h * 4);
906
907 memset (SvPVX (retval), 0, w * h * 4);
908
909 surface = cairo_image_surface_create_for_data (
910 (void*)SvPVX (retval), CAIRO_FORMAT_ARGB32, w, h, w * 4);
911 cairo = cairo_create (surface);
912 cairo_set_source_rgba (cairo, self->r, self->g, self->b, self->a);
913
914 pango_cairo_show_layout (cairo, self->pl);
915
916 cairo_destroy (cairo);
917 cairo_surface_destroy (surface);
918
919 // what a mess, and its premultiplied, too :(
920 {
921 uint32_t *p = (uint32_t *)SvPVX (retval);
922 uint32_t *e = p + w * h;
923
924 while (p < e)
925 {
926 uint32_t rgba = *p;
927 rgba = (rgba >> 24) | (rgba << 8);
928#if 0
929#ifdef _WIN32
930 {//D
931 uint8_t r = rgba >> 24;
932 uint8_t g = rgba >> 16;
933 uint8_t b = rgba >> 8;
934 uint8_t a = rgba >> 0;
935
936 rgba = (rgba & 0xffffff00) | a;
937 }
938#endif
939#endif
940 rgba = SDL_SwapBE32 (rgba);
941 *p++ = rgba;
942 }
943 }
944
945 EXTEND (SP, 5); 1123 EXTEND (SP, 2);
946 PUSHs (sv_2mortal (newSViv (w))); 1124 PUSHs (sv_2mortal (newSViv (line - 1)));
1125 PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE)));
1126}
1127
1128void
1129line_x_to_index (CFPlus::Layout self, int line, int x)
1130 PPCODE:
1131{
1132 PangoLayoutLine *lp;
1133 int index, trailing;
1134
1135 if (line < 0)
1136 XSRETURN_EMPTY;
1137
1138 if (!(lp = pango_layout_get_line (self->pl, line)))
1139 XSRETURN_EMPTY; /* do better */
1140
1141 pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing);
1142
1143 EXTEND (SP, 2);
1144 if (GIMME_V == G_SCALAR)
947 PUSHs (sv_2mortal (newSViv (h))); 1145 PUSHs (sv_2mortal (newSViv (index + trailing)));
948 PUSHs (sv_2mortal (retval));
949 PUSHs (sv_2mortal (newSViv (GL_RGBA)));
950 PUSHs (sv_2mortal (newSViv (GL_RGBA)));
951 }
952 else 1146 else
953 { 1147 {
954 FT_Bitmap bitmap;
955
956 retval = newSV (w * h);
957 SvPOK_only (retval);
958 SvCUR_set (retval, w * h);
959
960 bitmap.rows = h;
961 bitmap.width = w;
962 bitmap.pitch = w;
963 bitmap.buffer = (unsigned char*)SvPVX (retval);
964 bitmap.num_grays = 256;
965 bitmap.pixel_mode = FT_PIXEL_MODE_GRAY;
966
967 memset (bitmap.buffer, 0, w * h);
968
969 pango_ft2_render_layout (&bitmap, self->pl, 0 * PANGO_SCALE, 0 * PANGO_SCALE);
970
971 EXTEND (SP, 5);
972 PUSHs (sv_2mortal (newSViv (w))); 1148 PUSHs (sv_2mortal (newSViv (index)));
973 PUSHs (sv_2mortal (newSViv (h))); 1149 PUSHs (sv_2mortal (newSViv (trailing)));
974 PUSHs (sv_2mortal (retval));
975 PUSHs (sv_2mortal (newSViv (GL_ALPHA)));
976 PUSHs (sv_2mortal (newSViv (GL_ALPHA)));
977 } 1150 }
978} 1151}
979 1152
1153void
1154render (CFPlus::Layout self, float x, float y, int flags = 0)
1155 PPCODE:
1156 pango_opengl_render_layout_subpixel (
1157 self->pl,
1158 x * PANGO_SCALE, y * PANGO_SCALE,
1159 self->r, self->g, self->b, self->a,
1160 flags
1161 );
1162
980MODULE = CFClient PACKAGE = CFClient::Texture 1163MODULE = CFPlus PACKAGE = CFPlus::Texture
981 1164
982void 1165void
1166pad2pot (SV *data_, SV *w_, SV *h_)
1167 CODE:
1168{
1169 int ow = SvIV (w_);
1170 int oh = SvIV (h_);
1171
1172 if (ow && oh)
1173 {
1174 int nw = minpot (ow);
1175 int nh = minpot (oh);
1176
1177 if (nw != ow || nh != oh)
1178 {
1179 if (SvOK (data_))
1180 {
1181 STRLEN datalen;
1182 char *data = SvPVbyte (data_, datalen);
1183 int bpp = datalen / (ow * oh);
1184 SV *result_ = sv_2mortal (newSV (nw * nh * bpp));
1185
1186 SvPOK_only (result_);
1187 SvCUR_set (result_, nw * nh * bpp);
1188
1189 memset (SvPVX (result_), 0, nw * nh * bpp);
1190 while (oh--)
1191 memcpy (SvPVX (result_) + oh * nw * bpp, data + oh * ow * bpp, ow * bpp);
1192
1193 sv_setsv (data_, result_);
1194 }
1195
1196 sv_setiv (w_, nw);
1197 sv_setiv (h_, nh);
1198 }
1199 }
1200}
1201
1202void
983draw_quad (SV *self, float x, float y, float w = 0, float h = 0) 1203draw_quad (SV *self, float x, float y, float w = 0., float h = 0.)
984 PROTOTYPE: $$$;$$ 1204 PROTOTYPE: $$$;$$
985 ALIAS: 1205 ALIAS:
986 draw_quad_alpha = 1 1206 draw_quad_alpha = 1
987 draw_quad_alpha_premultiplied = 2 1207 draw_quad_alpha_premultiplied = 2
988 CODE: 1208 CODE:
1026 glDisable (GL_ALPHA_TEST); 1246 glDisable (GL_ALPHA_TEST);
1027 glDisable (GL_BLEND); 1247 glDisable (GL_BLEND);
1028 } 1248 }
1029} 1249}
1030 1250
1031MODULE = CFClient PACKAGE = CFClient::Map 1251MODULE = CFPlus PACKAGE = CFPlus::Map
1032 1252
1033CFClient::Map 1253CFPlus::Map
1034new (SV *class, int map_width, int map_height) 1254new (SV *class)
1035 CODE: 1255 CODE:
1036 New (0, RETVAL, 1, struct map); 1256 New (0, RETVAL, 1, struct map);
1037 RETVAL->x = 0; 1257 RETVAL->x = 0;
1038 RETVAL->y = 0; 1258 RETVAL->y = 0;
1039 RETVAL->w = map_width; 1259 RETVAL->w = 0;
1040 RETVAL->h = map_height; 1260 RETVAL->h = 0;
1041 RETVAL->ox = 0; 1261 RETVAL->ox = 0;
1042 RETVAL->oy = 0; 1262 RETVAL->oy = 0;
1043 RETVAL->faces = 8192; 1263 RETVAL->faces = 8192; Newz (0, RETVAL->face2tile, RETVAL->faces, tileid);
1044 Newz (0, RETVAL->face, RETVAL->faces, mapface); 1264 RETVAL->texs = 8192; Newz (0, RETVAL->tex , RETVAL->texs , maptex);
1045 RETVAL->texs = 8192;
1046 Newz (0, RETVAL->tex, RETVAL->texs, maptex);
1047 RETVAL->rows = 0; 1265 RETVAL->rows = 0;
1048 RETVAL->row = 0; 1266 RETVAL->row = 0;
1049 OUTPUT: 1267 OUTPUT:
1050 RETVAL 1268 RETVAL
1051 1269
1052void 1270void
1053DESTROY (CFClient::Map self) 1271DESTROY (CFPlus::Map self)
1054 CODE: 1272 CODE:
1055{ 1273{
1056 map_clear (self); 1274 map_clear (self);
1057 Safefree (self->face); 1275 Safefree (self->face2tile);
1276 Safefree (self->tex);
1058 Safefree (self); 1277 Safefree (self);
1059} 1278}
1060 1279
1061void 1280void
1281resize (CFPlus::Map self, int map_width, int map_height)
1282 CODE:
1283 self->w = map_width;
1284 self->h = map_height;
1285
1286void
1062clear (CFClient::Map self) 1287clear (CFPlus::Map self)
1063 CODE: 1288 CODE:
1064 map_clear (self); 1289 map_clear (self);
1065 1290
1066void 1291void
1067set_face (CFClient::Map self, int face, int texid) 1292set_tileid (CFPlus::Map self, int face, int tile)
1068 CODE: 1293 CODE:
1069{ 1294{
1070 while (self->faces <= face) 1295 need_facenum (self, face); self->face2tile [face] = tile;
1071 { 1296 need_texid (self, tile);
1072 Append (mapface, self->face, self->faces, self->faces);
1073 self->faces *= 2;
1074 }
1075
1076 self->face [face] = texid;
1077} 1297}
1078 1298
1079void 1299void
1080set_texture (CFClient::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) 1300set_texture (CFPlus::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a)
1081 CODE: 1301 CODE:
1082{ 1302{
1083 while (self->texs <= texid) 1303 need_texid (self, texid);
1084 {
1085 Append (maptex, self->tex, self->texs, self->texs);
1086 self->texs *= 2;
1087 }
1088 1304
1089 { 1305 {
1090 maptex *tex = self->tex + texid; 1306 maptex *tex = self->tex + texid;
1091 1307
1092 tex->name = name; 1308 tex->name = name;
1109 // from transparent color bleeding and ugly wrapping effects. 1325 // from transparent color bleeding and ugly wrapping effects.
1110 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1326 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1111} 1327}
1112 1328
1113int 1329int
1114ox (CFClient::Map self) 1330ox (CFPlus::Map self)
1115 ALIAS: 1331 ALIAS:
1116 oy = 1 1332 oy = 1
1117 x = 2 1333 x = 2
1118 y = 3 1334 y = 3
1119 w = 4 1335 w = 4
1130 } 1346 }
1131 OUTPUT: 1347 OUTPUT:
1132 RETVAL 1348 RETVAL
1133 1349
1134void 1350void
1135scroll (CFClient::Map self, int dx, int dy) 1351scroll (CFPlus::Map self, int dx, int dy)
1136 CODE: 1352 CODE:
1137{ 1353{
1138 if (dx > 0) 1354 if (dx > 0)
1139 map_blank (self, self->x, self->y, dx - 1, self->h); 1355 map_blank (self, self->x, self->y, dx, self->h);
1140 else if (dx < 0) 1356 else if (dx < 0)
1141 map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h); 1357 map_blank (self, self->x + self->w + dx + 1, self->y, -dx, self->h);
1142 1358
1143 if (dy > 0) 1359 if (dy > 0)
1144 map_blank (self, self->x, self->y, self->w, dy - 1); 1360 map_blank (self, self->x, self->y, self->w, dy);
1145 else if (dy < 0) 1361 else if (dy < 0)
1146 map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); 1362 map_blank (self, self->x, self->y + self->h + dy + 1, self->w, -dy);
1147 1363
1148 self->ox += dx; self->x += dx; 1364 self->ox += dx; self->x += dx;
1149 self->oy += dy; self->y += dy; 1365 self->oy += dy; self->y += dy;
1150 1366
1151 while (self->y < 0) 1367 while (self->y < 0)
1156 self->y += MAP_EXTEND_Y; 1372 self->y += MAP_EXTEND_Y;
1157 } 1373 }
1158} 1374}
1159 1375
1160void 1376void
1161map1a_update (CFClient::Map self, SV *data_) 1377map1a_update (CFPlus::Map self, SV *data_, int extmap)
1162 CODE: 1378 CODE:
1163{ 1379{
1164 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1380 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1165 uint8_t *data_end = (uint8_t *)SvEND (data_); 1381 uint8_t *data_end = (uint8_t *)SvEND (data_);
1166 mapcell *cell; 1382 mapcell *cell;
1167 int x, y, flags; 1383 int x, y, flags;
1168 1384
1169 while (data < data_end) 1385 while (data < data_end - 1)
1170 { 1386 {
1171 flags = (data [0] << 8) + data [1]; data += 2; 1387 flags = (data [0] << 8) + data [1]; data += 2;
1172 1388
1173 x = ((flags >> 10) & 63) + self->x; 1389 x = self->x + ((flags >> 10) & 63);
1174 y = ((flags >> 4) & 63) + self->y; 1390 y = self->y + ((flags >> 4) & 63);
1175 1391
1176 cell = map_get_cell (self, x, y); 1392 cell = map_get_cell (self, x, y);
1177 1393
1178 if (flags & 15) 1394 if (flags & 15)
1179 { 1395 {
1180 if (cell->darkness < 0) 1396 if (!cell->darkness)
1181 { 1397 {
1398 memset (cell, 0, sizeof (*cell));
1182 cell->darkness = 0; 1399 cell->darkness = 256;
1183 cell->face [0] = 0;
1184 cell->face [1] = 0;
1185 cell->face [2] = 0;
1186 } 1400 }
1187 1401
1188 cell->darkness = flags & 8 ? *data++ : 255;
1189
1190 //TODO: don't trust server data to be in-range(!) 1402 //TODO: don't trust server data to be in-range(!)
1403
1404 if (flags & 8)
1405 {
1406 if (extmap)
1407 {
1408 uint8_t ext, cmd;
1409
1410 do
1411 {
1412 ext = *data++;
1413 cmd = ext & 0x3f;
1414
1415 if (cmd < 4)
1416 cell->darkness = 255 - ext * 64 + 1;
1417 else if (cmd == 5) // health
1418 {
1419 cell->stat_width = 1;
1420 cell->stat_hp = *data++;
1421 }
1422 else if (cmd == 6) // monster width
1423 cell->stat_width = *data++ + 1;
1424 else if (cmd == 0x47)
1425 {
1426 if (*data == 8)
1427 ; // decode player uuid
1428
1429 data += *data + 1;
1430 }
1431 else if (cmd == 8) // cell flags
1432 cell->flags = *data++;
1433 else if (ext & 0x40) // unknown, multibyte => skip
1434 data += *data + 1;
1435 else
1436 data++;
1437 }
1438 while (ext & 0x80);
1439 }
1440 else
1441 cell->darkness = *data++ + 1;
1442 }
1191 1443
1192 if (flags & 4) 1444 if (flags & 4)
1193 { 1445 {
1194 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; 1446 faceid face = (data [0] << 8) + data [1]; data += 2;
1447 need_facenum (self, face);
1448 cell->tile [0] = self->face2tile [face];
1195 } 1449 }
1196 1450
1197 if (flags & 2) 1451 if (flags & 2)
1198 { 1452 {
1199 cell->face [1] = self->face [(data [0] << 8) + data [1]]; data += 2; 1453 faceid face = (data [0] << 8) + data [1]; data += 2;
1454 need_facenum (self, face);
1455 cell->tile [1] = self->face2tile [face];
1200 } 1456 }
1201 1457
1202 if (flags & 1) 1458 if (flags & 1)
1203 { 1459 {
1204 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; 1460 faceid face = (data [0] << 8) + data [1]; data += 2;
1461 need_facenum (self, face);
1462 cell->tile [2] = self->face2tile [face];
1205 } 1463 }
1206 } 1464 }
1207 else 1465 else
1208 cell->darkness = -1; 1466 cell->darkness = 0;
1209 } 1467 }
1210} 1468}
1211 1469
1212SV * 1470SV *
1213mapmap (CFClient::Map self, int x0, int y0, int w, int h) 1471mapmap (CFPlus::Map self, int x0, int y0, int w, int h)
1214 CODE: 1472 CODE:
1215{ 1473{
1216 int x1, x; 1474 int x1, x;
1217 int y1, y; 1475 int y1, y;
1218 int z; 1476 int z;
1239 { 1497 {
1240 mapcell *cell = row->col + (x - row->c0); 1498 mapcell *cell = row->col + (x - row->c0);
1241 1499
1242 for (z = 0; z <= 0; z++) 1500 for (z = 0; z <= 0; z++)
1243 { 1501 {
1244 mapface face = cell->face [z];
1245
1246 if (face)
1247 {
1248 maptex tex = self->tex [face]; 1502 maptex tex = self->tex [cell->tile [z]];
1249 int a0 = 255 - tex.a; 1503 int a0 = 255 - tex.a;
1250 int a1 = tex.a; 1504 int a1 = tex.a;
1251 1505
1252 r = (r * a0 + tex.r * a1) / 255; 1506 r = (r * a0 + tex.r * a1) / 255;
1253 g = (g * a0 + tex.g * a1) / 255; 1507 g = (g * a0 + tex.g * a1) / 255;
1254 b = (b * a0 + tex.b * a1) / 255; 1508 b = (b * a0 + tex.b * a1) / 255;
1255 a = (a * a0 + tex.a * a1) / 255; 1509 a = (a * a0 + tex.a * a1) / 255;
1256 }
1257 } 1510 }
1258 } 1511 }
1259 1512
1260 *map++ = (r ) 1513 *map++ = (r )
1261 | (g << 8) 1514 | (g << 8)
1268} 1521}
1269 OUTPUT: 1522 OUTPUT:
1270 RETVAL 1523 RETVAL
1271 1524
1272void 1525void
1273draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 1526draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T)
1274 PPCODE: 1527 CODE:
1275{ 1528{
1276 int vx, vy;
1277 int x, y, z; 1529 int x, y, z;
1278 int last_name; 1530 int last_name;
1279 mapface face;
1280 int sw4 = (sw + 3) & ~3;
1281 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh));
1282 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv);
1283
1284 memset (darkness, 255, sw4 * sh);
1285 SvPOK_only (darkness_sv);
1286 SvCUR_set (darkness_sv, sw4 * sh);
1287
1288 vx = self->x + (self->w - sw) / 2 - shift_x;
1289 vy = self->y + (self->h - sh) / 2 - shift_y;
1290
1291 /*
1292 int vx = self->vx = self->w >= sw
1293 ? self->x + (self->w - sw) / 2
1294 : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx));
1295
1296 int vy = self->vy = self->h >= sh
1297 ? self->y + (self->h - sh) / 2
1298 : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy));
1299 */
1300 1531
1301 glColor4ub (255, 255, 255, 255); 1532 glColor4ub (255, 255, 255, 255);
1302 1533
1534 glEnable (GL_BLEND);
1303 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 1535 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1304 glEnable (GL_BLEND);
1305 glEnable (GL_TEXTURE_2D); 1536 glEnable (GL_TEXTURE_2D);
1306 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 1537 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1307 1538
1308 glBegin (GL_QUADS); 1539 glBegin (GL_QUADS);
1309 1540
1310 last_name = 0; 1541 last_name = 0;
1311 1542
1543 mx += self->x;
1544 my += self->y;
1545
1312 for (z = 0; z < 3; z++) 1546 for (z = 0; z < 3; z++)
1313 for (y = 0; y < sh; y++) 1547 for (y = 0; y < sh; y++)
1314 if (0 <= y + vy && y + vy < self->rows) 1548 if (0 <= y + my && y + my < self->rows)
1315 { 1549 {
1316 maprow *row = self->row + (y + vy); 1550 maprow *row = self->row + (y + my);
1317 1551
1318 for (x = 0; x < sw; x++) 1552 for (x = 0; x < sw; x++)
1319 if (row->c0 <= x + vx && x + vx < row->c1) 1553 if (row->c0 <= x + mx && x + mx < row->c1)
1320 { 1554 {
1321 mapcell *cell = row->col + (x + vx - row->c0); 1555 mapcell *cell = row->col + (x + mx - row->c0);
1322
1323 darkness[y * sw4 + x] = cell->darkness < 0
1324 ? 255 - FOW_DARKNESS
1325 : 255 - cell->darkness;
1326
1327 face = cell->face [z]; 1556 tileid tile = cell->tile [z];
1328 1557
1329 if (face) 1558 if (tile)
1330 { 1559 {
1331 maptex tex = self->tex [face]; 1560 maptex tex = self->tex [tile];
1332
1333 int px = (x + 1) * 32 - tex.w; 1561 int px = (x + 1) * T - tex.w;
1334 int py = (y + 1) * 32 - tex.h; 1562 int py = (y + 1) * T - tex.h;
1335 1563
1336 if (last_name != tex.name) 1564 if (last_name != tex.name)
1337 { 1565 {
1566 if (!tex.name)
1567 tex = self->tex [2]; /* missing, replace by noface */
1568
1338 glEnd (); 1569 glEnd ();
1339 last_name = tex.name;
1340 glBindTexture (GL_TEXTURE_2D, last_name); 1570 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1341 glBegin (GL_QUADS); 1571 glBegin (GL_QUADS);
1342 } 1572 }
1343 1573
1344 glTexCoord2f (0 , 0 ); glVertex2f (px , py ); 1574 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1345 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); 1575 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1346 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); 1576 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1347 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); 1577 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1578
1579 if (cell->flags && z == 2)
1580 {
1581 if (cell->flags & 1)
1582 {
1583 maptex tex = self->tex [1];
1584 int px = x * T + T * 2 / 32;
1585 int py = y * T - T * 6 / 32;
1586
1587 glEnd ();
1588 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1589 glBegin (GL_QUADS);
1590
1591 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1592 glTexCoord2f (0 , tex.t); glVertex2f (px , py + T);
1593 glTexCoord2f (tex.s, tex.t); glVertex2f (px + T, py + T);
1594 glTexCoord2f (tex.s, 0 ); glVertex2f (px + T, py );
1595 }
1596 }
1348 } 1597 }
1349 } 1598 }
1350 } 1599 }
1351 1600
1352 glEnd (); 1601 glEnd ();
1353 1602
1354 glDisable (GL_TEXTURE_2D); 1603 glDisable (GL_TEXTURE_2D);
1355 glDisable (GL_BLEND); 1604 glDisable (GL_BLEND);
1605
1606 // top layer: overlays such as the health bar
1607 for (y = 0; y < sh; y++)
1608 if (0 <= y + my && y + my < self->rows)
1609 {
1610 maprow *row = self->row + (y + my);
1611
1612 for (x = 0; x < sw; x++)
1613 if (row->c0 <= x + mx && x + mx < row->c1)
1614 {
1615 mapcell *cell = row->col + (x + mx - row->c0);
1616
1617 int px = x * T;
1618 int py = y * T;
1619
1620 if (cell->stat_hp)
1621 {
1622 int width = cell->stat_width * T;
1623 int thick = (sh * T / 32 + 27) / 28 + 1 + cell->stat_width;
1624
1625 glColor3ub (0, 0, 0);
1626 glRectf (px + 1, py - thick - 2,
1627 px + width - 1, py);
1628
1629 glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0);
1630 glRectf (px + 2,
1631 py - thick - 1,
1632 px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1);
1633 }
1634 }
1635 }
1636}
1637
1638void
1639draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data)
1640 CODE:
1641{
1642 static float color[16][3] = {
1643 { 0.00F, 0.00F, 0.00F },
1644 { 1.00F, 1.00F, 1.00F },
1645 { 0.00F, 0.00F, 0.55F },
1646 { 1.00F, 0.00F, 0.00F },
1647
1648 { 1.00F, 0.54F, 0.00F },
1649 { 0.11F, 0.56F, 1.00F },
1650 { 0.93F, 0.46F, 0.00F },
1651 { 0.18F, 0.54F, 0.34F },
1652
1653 { 0.56F, 0.73F, 0.56F },
1654 { 0.80F, 0.80F, 0.80F },
1655 { 0.55F, 0.41F, 0.13F },
1656 { 0.99F, 0.77F, 0.26F },
1657
1658 { 0.74F, 0.65F, 0.41F },
1659
1660 { 0.00F, 1.00F, 1.00F },
1661 { 1.00F, 0.00F, 1.00F },
1662 { 1.00F, 1.00F, 0.00F },
1663 };
1664
1665 int x, y;
1666
1667 glEnable (GL_TEXTURE_2D);
1668 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1669 glEnable (GL_BLEND);
1670 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1671 glBegin (GL_QUADS);
1672
1673 for (y = 0; y < h; y++)
1674 for (x = 0; x < w; x++)
1675 {
1676 unsigned char m = data [x + y * w];
1677
1678 if (m)
1679 {
1680 float *c = color [m & 15];
1681
1682 float tx1 = m & 0x40 ? 0.5 : 0.;
1683 float tx2 = tx1 + 0.5;
1684
1685 glColor4f (c[0], c[1], c[2], 0.75);
1686 glTexCoord2f (tx1, 0.); glVertex2i (x , y );
1687 glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1);
1688 glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1);
1689 glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y );
1690 }
1691 }
1692
1693 glEnd ();
1694 glDisable (GL_BLEND);
1695 glDisable (GL_TEXTURE_2D);
1696}
1697
1698void
1699fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh)
1700 PPCODE:
1701{
1702 int x, y;
1703 int sw4 = (sw + 3) & ~3;
1704 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh));
1705 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv);
1706
1707 memset (darkness, 255, sw4 * sh);
1708 SvPOK_only (darkness_sv);
1709 SvCUR_set (darkness_sv, sw4 * sh);
1710
1711 mx += self->x;
1712 my += self->y;
1713
1714 for (y = 0; y < sh; y++)
1715 if (0 <= y + my && y + my < self->rows)
1716 {
1717 maprow *row = self->row + (y + my);
1718
1719 for (x = 0; x < sw; x++)
1720 if (row->c0 <= x + mx && x + mx < row->c1)
1721 {
1722 mapcell *cell = row->col + (x + mx - row->c0);
1723
1724 darkness[y * sw4 + x] = cell->darkness
1725 ? 255 - (cell->darkness - 1)
1726 : 255 - FOW_DARKNESS;
1727 }
1728 }
1356 1729
1357 EXTEND (SP, 3); 1730 EXTEND (SP, 3);
1358 PUSHs (sv_2mortal (newSViv (sw4))); 1731 PUSHs (sv_2mortal (newSViv (sw4)));
1359 PUSHs (sv_2mortal (newSViv (sh))); 1732 PUSHs (sv_2mortal (newSViv (sh)));
1360 PUSHs (darkness_sv); 1733 PUSHs (darkness_sv);
1361} 1734}
1362 1735
1363SV * 1736SV *
1364get_rect (CFClient::Map self, int x0, int y0, int w, int h) 1737get_rect (CFPlus::Map self, int x0, int y0, int w, int h)
1365 CODE: 1738 CODE:
1366{ 1739{
1367 int x, y, x1, y1; 1740 int x, y, x1, y1;
1368 SV *data_sv = newSV (w * h * 7 + 5); 1741 SV *data_sv = newSV (w * h * 7 + 5);
1369 uint8_t *data = (uint8_t *)SvPVX (data_sv); 1742 uint8_t *data = (uint8_t *)SvPVX (data_sv);
1394 if (row && row->c0 <= x && x < row->c1) 1767 if (row && row->c0 <= x && x < row->c1)
1395 { 1768 {
1396 mapcell *cell = row->col + (x - row->c0); 1769 mapcell *cell = row->col + (x - row->c0);
1397 uint8_t flags = 0; 1770 uint8_t flags = 0;
1398 1771
1399 if (cell->face [0]) flags |= 1; 1772 if (cell->tile [0]) flags |= 1;
1400 if (cell->face [1]) flags |= 2; 1773 if (cell->tile [1]) flags |= 2;
1401 if (cell->face [2]) flags |= 4; 1774 if (cell->tile [2]) flags |= 4;
1402 1775
1403 *data++ = flags; 1776 *data++ = flags;
1404 1777
1405 if (flags & 1) 1778 if (flags & 1)
1406 { 1779 {
1780 tileid tile = cell->tile [0];
1407 *data++ = cell->face [0] >> 8; 1781 *data++ = tile >> 8;
1408 *data++ = cell->face [0]; 1782 *data++ = tile;
1409 } 1783 }
1410 1784
1411 if (flags & 2) 1785 if (flags & 2)
1412 { 1786 {
1787 tileid tile = cell->tile [1];
1413 *data++ = cell->face [1] >> 8; 1788 *data++ = tile >> 8;
1414 *data++ = cell->face [1]; 1789 *data++ = tile;
1415 } 1790 }
1416 1791
1417 if (flags & 4) 1792 if (flags & 4)
1418 { 1793 {
1794 tileid tile = cell->tile [2];
1419 *data++ = cell->face [2] >> 8; 1795 *data++ = tile >> 8;
1420 *data++ = cell->face [2]; 1796 *data++ = tile;
1421 } 1797 }
1422 } 1798 }
1423 else 1799 else
1424 *data++ = 0; 1800 *data++ = 0;
1425 } 1801 }
1431} 1807}
1432 OUTPUT: 1808 OUTPUT:
1433 RETVAL 1809 RETVAL
1434 1810
1435void 1811void
1436set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) 1812set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data)
1437 PPCODE: 1813 PPCODE:
1438{ 1814{
1439 int x, y, z; 1815 int x, y, z;
1440 int w, h; 1816 int w, h;
1441 int x1, y1; 1817 int x1, y1;
1465 { 1841 {
1466 uint8_t flags = *data++; 1842 uint8_t flags = *data++;
1467 1843
1468 if (flags) 1844 if (flags)
1469 { 1845 {
1470 mapface face[3] = { 0, 0, 0 };
1471
1472 mapcell *cell = row_get_cell (row, x); 1846 mapcell *cell = row_get_cell (row, x);
1847 tileid tile[3] = { 0, 0, 0 };
1473 1848
1474 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } 1849 if (flags & 1) { tile[0] = *data++ << 8; tile[0] |= *data++; }
1475 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } 1850 if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; }
1476 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } 1851 if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; }
1477 1852
1478 if (cell->darkness <= 0) 1853 if (cell->darkness == 0)
1479 { 1854 {
1480 cell->darkness = -1; 1855 cell->darkness = 0;
1481 1856
1482 for (z = 0; z <= 2; z++) 1857 for (z = 0; z <= 2; z++)
1483 { 1858 {
1484 cell->face[z] = face[z]; 1859 tileid t = tile [z];
1485 1860
1486 if (face[z] && (face[z] >= self->texs || !self->tex[face [z]].name)) 1861 if (t >= self->texs || !self->tex [t].name)
1862 {
1487 XPUSHs (sv_2mortal (newSViv (face[z]))); 1863 XPUSHs (sv_2mortal (newSViv (t)));
1864 need_texid (self, t);
1865 }
1866
1867 cell->tile [z] = t;
1488 } 1868 }
1489 } 1869 }
1490 } 1870 }
1491 } 1871 }
1492 } 1872 }
1493} 1873}
1494 1874
1495MODULE = CFClient PACKAGE = CFClient::MixChunk 1875MODULE = CFPlus PACKAGE = CFPlus::MixChunk
1496 1876
1497CFClient::MixChunk 1877CFPlus::MixChunk
1498new_from_file (SV *class, char *path) 1878new_from_file (SV *class, char *path)
1499 CODE: 1879 CODE:
1500 RETVAL = Mix_LoadWAV (path); 1880 RETVAL = Mix_LoadWAV (path);
1501 OUTPUT: 1881 OUTPUT:
1502 RETVAL 1882 RETVAL
1503 1883
1504void 1884void
1505DESTROY (CFClient::MixChunk self) 1885DESTROY (CFPlus::MixChunk self)
1506 CODE: 1886 CODE:
1507 Mix_FreeChunk (self); 1887 Mix_FreeChunk (self);
1508 1888
1509int 1889int
1510volume (CFClient::MixChunk self, int volume = -1) 1890volume (CFPlus::MixChunk self, int volume = -1)
1511 CODE: 1891 CODE:
1512 RETVAL = Mix_VolumeChunk (self, volume); 1892 RETVAL = Mix_VolumeChunk (self, volume);
1513 OUTPUT: 1893 OUTPUT:
1514 RETVAL 1894 RETVAL
1515 1895
1516int 1896int
1517play (CFClient::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) 1897play (CFPlus::MixChunk self, int channel = -1, int loops = 0, int ticks = -1)
1518 CODE: 1898 CODE:
1519 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); 1899 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks);
1520 OUTPUT: 1900 OUTPUT:
1521 RETVAL 1901 RETVAL
1522 1902
1523MODULE = CFClient PACKAGE = CFClient::MixMusic 1903MODULE = CFPlus PACKAGE = CFPlus::MixMusic
1524 1904
1525int 1905int
1526volume (int volume = -1) 1906volume (int volume = -1)
1527 CODE: 1907 CODE:
1528 RETVAL = Mix_VolumeMusic (volume); 1908 RETVAL = Mix_VolumeMusic (volume);
1529 OUTPUT: 1909 OUTPUT:
1530 RETVAL 1910 RETVAL
1531 1911
1532CFClient::MixMusic 1912CFPlus::MixMusic
1533new_from_file (SV *class, char *path) 1913new_from_file (SV *class, char *path)
1534 CODE: 1914 CODE:
1535 RETVAL = Mix_LoadMUS (path); 1915 RETVAL = Mix_LoadMUS (path);
1536 OUTPUT: 1916 OUTPUT:
1537 RETVAL 1917 RETVAL
1538 1918
1539void 1919void
1540DESTROY (CFClient::MixMusic self) 1920DESTROY (CFPlus::MixMusic self)
1541 CODE: 1921 CODE:
1542 Mix_FreeMusic (self); 1922 Mix_FreeMusic (self);
1543 1923
1544int 1924int
1545play (CFClient::MixMusic self, int loops = -1) 1925play (CFPlus::MixMusic self, int loops = -1)
1546 CODE: 1926 CODE:
1547 RETVAL = Mix_PlayMusic (self, loops); 1927 RETVAL = Mix_PlayMusic (self, loops);
1548 OUTPUT: 1928 OUTPUT:
1549 RETVAL 1929 RETVAL
1550 1930
1551MODULE = CFClient PACKAGE = CFClient::OpenGL 1931MODULE = CFPlus PACKAGE = CFPlus::OpenGL
1552 1932
1553BOOT: 1933BOOT:
1554{ 1934{
1555 HV *stash = gv_stashpv ("CFClient::OpenGL", 1); 1935 HV *stash = gv_stashpv ("CFPlus::OpenGL", 1);
1556 static const struct { 1936 static const struct {
1557 const char *name; 1937 const char *name;
1558 IV iv; 1938 IV iv;
1559 } *civ, const_iv[] = { 1939 } *civ, const_iv[] = {
1560# define const_iv(name) { # name, (IV)name } 1940# define const_iv(name) { # name, (IV)name }
1567 const_iv (GL_SCISSOR_TEST), 1947 const_iv (GL_SCISSOR_TEST),
1568 const_iv (GL_DEPTH_TEST), 1948 const_iv (GL_DEPTH_TEST),
1569 const_iv (GL_ALPHA_TEST), 1949 const_iv (GL_ALPHA_TEST),
1570 const_iv (GL_NORMALIZE), 1950 const_iv (GL_NORMALIZE),
1571 const_iv (GL_RESCALE_NORMAL), 1951 const_iv (GL_RESCALE_NORMAL),
1952 const_iv (GL_FRONT),
1953 const_iv (GL_BACK),
1572 const_iv (GL_AND), 1954 const_iv (GL_AND),
1573 const_iv (GL_ONE), 1955 const_iv (GL_ONE),
1574 const_iv (GL_ZERO), 1956 const_iv (GL_ZERO),
1575 const_iv (GL_SRC_ALPHA), 1957 const_iv (GL_SRC_ALPHA),
1576 const_iv (GL_DST_ALPHA), 1958 const_iv (GL_DST_ALPHA),
1577 const_iv (GL_ONE_MINUS_SRC_ALPHA), 1959 const_iv (GL_ONE_MINUS_SRC_ALPHA),
1578 const_iv (GL_ONE_MINUS_DST_ALPHA), 1960 const_iv (GL_ONE_MINUS_DST_ALPHA),
1579 const_iv (GL_SRC_ALPHA_SATURATE), 1961 const_iv (GL_SRC_ALPHA_SATURATE),
1580 const_iv (GL_RGB), 1962 const_iv (GL_RGB),
1581 const_iv (GL_RGBA), 1963 const_iv (GL_RGBA),
1964 const_iv (GL_RGBA4),
1965 const_iv (GL_RGBA8),
1966 const_iv (GL_RGB5_A1),
1582 const_iv (GL_UNSIGNED_BYTE), 1967 const_iv (GL_UNSIGNED_BYTE),
1583 const_iv (GL_UNSIGNED_SHORT), 1968 const_iv (GL_UNSIGNED_SHORT),
1584 const_iv (GL_UNSIGNED_INT), 1969 const_iv (GL_UNSIGNED_INT),
1585 const_iv (GL_ALPHA), 1970 const_iv (GL_ALPHA),
1586 const_iv (GL_INTENSITY), 1971 const_iv (GL_INTENSITY),
1618 const_iv (GL_SEPARABLE_2D), 2003 const_iv (GL_SEPARABLE_2D),
1619 const_iv (GL_CONVOLUTION_2D), 2004 const_iv (GL_CONVOLUTION_2D),
1620 const_iv (GL_CONVOLUTION_BORDER_MODE), 2005 const_iv (GL_CONVOLUTION_BORDER_MODE),
1621 const_iv (GL_CONSTANT_BORDER), 2006 const_iv (GL_CONSTANT_BORDER),
1622 const_iv (GL_LINES), 2007 const_iv (GL_LINES),
2008 const_iv (GL_LINE_STRIP),
1623 const_iv (GL_LINE_LOOP), 2009 const_iv (GL_LINE_LOOP),
1624 const_iv (GL_QUADS), 2010 const_iv (GL_QUADS),
1625 const_iv (GL_QUAD_STRIP), 2011 const_iv (GL_QUAD_STRIP),
1626 const_iv (GL_TRIANGLES), 2012 const_iv (GL_TRIANGLES),
1627 const_iv (GL_TRIANGLE_STRIP), 2013 const_iv (GL_TRIANGLE_STRIP),
1660 OUTPUT: 2046 OUTPUT:
1661 RETVAL 2047 RETVAL
1662 2048
1663int glGetError () 2049int glGetError ()
1664 2050
2051void glFinish ()
2052
1665void glClear (int mask) 2053void glClear (int mask)
1666 2054
1667void glClearColor (float r, float g, float b, float a = 1.0) 2055void glClearColor (float r, float g, float b, float a = 1.0)
1668 PROTOTYPE: @ 2056 PROTOTYPE: @
1669 2057
1692void glPushMatrix () 2080void glPushMatrix ()
1693 2081
1694void glPopMatrix () 2082void glPopMatrix ()
1695 2083
1696void glLoadIdentity () 2084void glLoadIdentity ()
2085
2086void glDrawBuffer (int buffer)
2087
2088void glReadBuffer (int buffer)
1697 2089
1698# near_ and far_ are due to microsofts buggy "c" compiler 2090# near_ and far_ are due to microsofts buggy "c" compiler
1699void glFrustum (double left, double right, double bottom, double top, double near_, double far_) 2091void glFrustum (double left, double right, double bottom, double top, double near_, double far_)
1700 2092
1701# near_ and far_ are due to microsofts buggy "c" compiler 2093# near_ and far_ are due to microsofts buggy "c" compiler
1731 r *= a; 2123 r *= a;
1732 g *= a; 2124 g *= a;
1733 b *= a; 2125 b *= a;
1734 } 2126 }
1735 // microsoft visual "c" rounds instead of truncating... 2127 // microsoft visual "c" rounds instead of truncating...
1736 glColor4ub (MIN ((int)(r * 256.f), 255), 2128 glColor4f (r, g, b, a);
1737 MIN ((int)(g * 256.f), 255),
1738 MIN ((int)(b * 256.f), 255),
1739 MIN ((int)(a * 256.f), 255));
1740 2129
1741void glInterleavedArrays (int format, int stride, char *data) 2130void glInterleavedArrays (int format, int stride, char *data)
1742 2131
1743void glDrawElements (int mode, int count, int type, char *indices) 2132void glDrawElements (int mode, int count, int type, char *indices)
1744 2133
1821 2210
1822void glEndList () 2211void glEndList ()
1823 2212
1824void glCallList (int list) 2213void glCallList (int list)
1825 2214
1826

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines