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.160 by root, Mon Oct 9 01:06:36 2006 UTC vs.
Revision 1.167 by root, Sat Dec 9 02:21:25 2006 UTC

1#ifdef _WIN32 1#ifdef _WIN32
2long _ftol (double); /* defined by VC6 C libs */
3long _ftol2 (double dblSource) { return _ftol (dblSource); }
4# define WIN32_LEAN_AND_MEAN 2# define WIN32_LEAN_AND_MEAN
5# define _WIN32_WINNT 0x0500 // needed to get win2000 api calls 3# define _WIN32_WINNT 0x0500 // needed to get win2000 api calls
6# include <malloc.h> 4# include <malloc.h>
7# include <windows.h> 5# include <windows.h>
8# include <wininet.h> 6# include <wininet.h>
9# pragma warning(disable:4244) 7# pragma warning(disable:4244)
8# pragma warning(disable:4761)
10#endif 9#endif
11 10
12#include "EXTERN.h" 11#include "EXTERN.h"
13#include "perl.h" 12#include "perl.h"
14#include "XSUB.h" 13#include "XSUB.h"
39# include <sys/types.h> 38# include <sys/types.h>
40# include <sys/socket.h> 39# include <sys/socket.h>
41# include <netinet/in.h> 40# include <netinet/in.h>
42# include <netinet/tcp.h> 41# include <netinet/tcp.h>
43# include <inttypes.h> 42# include <inttypes.h>
44#else
45 typedef unsigned char uint8_t;
46 typedef unsigned short uint16_t;
47 typedef unsigned int uint32_t;
48 typedef signed char int8_t;
49 typedef signed short int16_t;
50 typedef signed int int32_t;
51#endif 43#endif
52 44
53#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ 45#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */
54 46
55#define FOW_DARKNESS 32 47#define FOW_DARKNESS 32
56 48
57#define MAP_EXTEND_X 32 49#define MAP_EXTEND_X 32
58#define MAP_EXTEND_Y 512 50#define MAP_EXTEND_Y 512
367 n |= n >> 16; 359 n |= n >> 16;
368 360
369 return n + 1; 361 return n + 1;
370} 362}
371 363
364/* SDL should provide this, really. */
365#define SDLK_MODIFIER_MIN 300
366#define SDLK_MODIFIER_MAX 314
367
372MODULE = CFPlus PACKAGE = CFPlus 368MODULE = CFPlus PACKAGE = CFPlus
373 369
374PROTOTYPES: ENABLE 370PROTOTYPES: ENABLE
375 371
376BOOT: 372BOOT:
379 static const struct { 375 static const struct {
380 const char *name; 376 const char *name;
381 IV iv; 377 IV iv;
382 } *civ, const_iv[] = { 378 } *civ, const_iv[] = {
383# define const_iv(name) { # name, (IV)name } 379# define const_iv(name) { # name, (IV)name }
380 const_iv (SDLK_MODIFIER_MIN),
381 const_iv (SDLK_MODIFIER_MAX),
382
384 const_iv (SDL_ACTIVEEVENT), 383 const_iv (SDL_ACTIVEEVENT),
385 const_iv (SDL_KEYDOWN), 384 const_iv (SDL_KEYDOWN),
386 const_iv (SDL_KEYUP), 385 const_iv (SDL_KEYUP),
387 const_iv (SDL_MOUSEMOTION), 386 const_iv (SDL_MOUSEMOTION),
388 const_iv (SDL_MOUSEBUTTONDOWN), 387 const_iv (SDL_MOUSEBUTTONDOWN),
397 const_iv (SDL_EVENT_RESERVEDA), 396 const_iv (SDL_EVENT_RESERVEDA),
398 const_iv (SDL_EVENT_RESERVEDB), 397 const_iv (SDL_EVENT_RESERVEDB),
399 const_iv (SDL_VIDEORESIZE), 398 const_iv (SDL_VIDEORESIZE),
400 const_iv (SDL_VIDEOEXPOSE), 399 const_iv (SDL_VIDEOEXPOSE),
401 const_iv (SDL_USEREVENT), 400 const_iv (SDL_USEREVENT),
401
402 const_iv (SDL_APPINPUTFOCUS),
403 const_iv (SDL_APPMOUSEFOCUS),
404 const_iv (SDL_APPACTIVE),
405
402 const_iv (SDLK_KP0), 406 const_iv (SDLK_KP0),
403 const_iv (SDLK_KP1), 407 const_iv (SDLK_KP1),
404 const_iv (SDLK_KP2), 408 const_iv (SDLK_KP2),
405 const_iv (SDLK_KP3), 409 const_iv (SDLK_KP3),
406 const_iv (SDLK_KP4), 410 const_iv (SDLK_KP4),
461 const_iv (SDLK_BREAK), 465 const_iv (SDLK_BREAK),
462 const_iv (SDLK_MENU), 466 const_iv (SDLK_MENU),
463 const_iv (SDLK_POWER), 467 const_iv (SDLK_POWER),
464 const_iv (SDLK_EURO), 468 const_iv (SDLK_EURO),
465 const_iv (SDLK_UNDO), 469 const_iv (SDLK_UNDO),
470
466 const_iv (KMOD_NONE), 471 const_iv (KMOD_NONE),
472 const_iv (KMOD_SHIFT),
467 const_iv (KMOD_LSHIFT), 473 const_iv (KMOD_LSHIFT),
468 const_iv (KMOD_RSHIFT), 474 const_iv (KMOD_RSHIFT),
475 const_iv (KMOD_CTRL),
469 const_iv (KMOD_LCTRL), 476 const_iv (KMOD_LCTRL),
470 const_iv (KMOD_RCTRL), 477 const_iv (KMOD_RCTRL),
478 const_iv (KMOD_ALT),
471 const_iv (KMOD_LALT), 479 const_iv (KMOD_LALT),
472 const_iv (KMOD_RALT), 480 const_iv (KMOD_RALT),
481 const_iv (KMOD_META),
473 const_iv (KMOD_LMETA), 482 const_iv (KMOD_LMETA),
474 const_iv (KMOD_RMETA), 483 const_iv (KMOD_RMETA),
475 const_iv (KMOD_NUM), 484 const_iv (KMOD_NUM),
476 const_iv (KMOD_CAPS), 485 const_iv (KMOD_CAPS),
477 const_iv (KMOD_MODE), 486 const_iv (KMOD_MODE),
478 const_iv (KMOD_CTRL),
479 const_iv (KMOD_SHIFT),
480 const_iv (KMOD_ALT),
481 const_iv (KMOD_META)
482# undef const_iv 487# undef const_iv
483 }; 488 };
484 489
485 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 490 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
486 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 491 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
492
493 assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK);
494 assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE);
487} 495}
488 496
489int 497int
490in_destruct () 498in_destruct ()
491 CODE: 499 CODE:
595 case SDL_KEYDOWN: 603 case SDL_KEYDOWN:
596 case SDL_KEYUP: 604 case SDL_KEYUP:
597 hv_store (hv, "state", 5, newSViv (ev.key.state), 0); 605 hv_store (hv, "state", 5, newSViv (ev.key.state), 0);
598 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); 606 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0);
599 hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0); 607 hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0);
608 hv_store (hv, "cmod", 4, newSViv (SDL_GetModState ()), 0); /* current mode */
600 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); 609 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0);
601 break; 610 break;
602 611
603 case SDL_ACTIVEEVENT: 612 case SDL_ACTIVEEVENT:
604 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); 613 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0);
796 _exit (1); 805 _exit (1);
797 806
798void 807void
799_exit (int retval = 0) 808_exit (int retval = 0)
800 CODE: 809 CODE:
810#ifdef WIN32
811 ExitThread (retval); // unclean, please beam me up
812#else
801 _exit (retval); 813 _exit (retval);
814#endif
802 815
803MODULE = CFPlus PACKAGE = CFPlus::Font 816MODULE = CFPlus PACKAGE = CFPlus::Font
804 817
805CFPlus::Font 818CFPlus::Font
806new_from_file (SV *class, char *path, int id = 0) 819new_from_file (SV *class, char *path, int id = 0)
1053xy_to_index (CFPlus::Layout self, int x, int y) 1066xy_to_index (CFPlus::Layout self, int x, int y)
1054 CODE: 1067 CODE:
1055{ 1068{
1056 int index, trailing; 1069 int index, trailing;
1057 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); 1070 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing);
1058 RETVAL = index; 1071 RETVAL = index + trailing;
1059} 1072}
1060 OUTPUT: 1073 OUTPUT:
1061 RETVAL 1074 RETVAL
1062 1075
1063void 1076void
1069 1082
1070 EXTEND (SP, 3); 1083 EXTEND (SP, 3);
1071 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); 1084 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE)));
1072 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1085 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
1073 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); 1086 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE)));
1087}
1088
1089void
1090index_to_line_x (CFPlus::Layout self, int index, int trailing = 0)
1091 PPCODE:
1092{
1093 int line, x;
1094
1095 pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x);
1096 /* pango bug: line is between 1..numlines, not 0..numlines-1 */
1097
1098 EXTEND (SP, 2);
1099 PUSHs (sv_2mortal (newSViv (line - 1)));
1100 PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE)));
1101}
1102
1103void
1104line_x_to_index (CFPlus::Layout self, int line, int x)
1105 PPCODE:
1106{
1107 PangoLayoutLine *lp;
1108 int index, trailing;
1109
1110 if (line < 0)
1111 XSRETURN_EMPTY;
1112
1113 if (!(lp = pango_layout_get_line (self->pl, line)))
1114 XSRETURN_EMPTY; /* do better */
1115
1116 pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing);
1117
1118 EXTEND (SP, 2);
1119 if (GIMME_V == G_SCALAR)
1120 PUSHs (sv_2mortal (newSViv (index + trailing)));
1121 else
1122 {
1123 PUSHs (sv_2mortal (newSViv (index)));
1124 PUSHs (sv_2mortal (newSViv (trailing)));
1125 }
1074} 1126}
1075 1127
1076void 1128void
1077render (CFPlus::Layout self, float x, float y, int flags = 0) 1129render (CFPlus::Layout self, float x, float y, int flags = 0)
1078 PPCODE: 1130 PPCODE:
1172} 1224}
1173 1225
1174MODULE = CFPlus PACKAGE = CFPlus::Map 1226MODULE = CFPlus PACKAGE = CFPlus::Map
1175 1227
1176CFPlus::Map 1228CFPlus::Map
1177new (SV *class, int map_width, int map_height) 1229new (SV *class)
1178 CODE: 1230 CODE:
1179 New (0, RETVAL, 1, struct map); 1231 New (0, RETVAL, 1, struct map);
1180 RETVAL->x = 0; 1232 RETVAL->x = 0;
1181 RETVAL->y = 0; 1233 RETVAL->y = 0;
1182 RETVAL->w = map_width; 1234 RETVAL->w = 0;
1183 RETVAL->h = map_height; 1235 RETVAL->h = 0;
1184 RETVAL->ox = 0; 1236 RETVAL->ox = 0;
1185 RETVAL->oy = 0; 1237 RETVAL->oy = 0;
1186 RETVAL->faces = 8192; 1238 RETVAL->faces = 8192;
1187 Newz (0, RETVAL->face, RETVAL->faces, mapface); 1239 Newz (0, RETVAL->face, RETVAL->faces, mapface);
1188 RETVAL->texs = 8192; 1240 RETVAL->texs = 8192;
1199 map_clear (self); 1251 map_clear (self);
1200 Safefree (self->face); 1252 Safefree (self->face);
1201 Safefree (self->tex); 1253 Safefree (self->tex);
1202 Safefree (self); 1254 Safefree (self);
1203} 1255}
1256
1257void
1258resize (CFPlus::Map self, int map_width, int map_height)
1259 CODE:
1260 self->w = map_width;
1261 self->h = map_height;
1204 1262
1205void 1263void
1206clear (CFPlus::Map self) 1264clear (CFPlus::Map self)
1207 CODE: 1265 CODE:
1208 map_clear (self); 1266 map_clear (self);
1448} 1506}
1449 OUTPUT: 1507 OUTPUT:
1450 RETVAL 1508 RETVAL
1451 1509
1452void 1510void
1453draw (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 1511draw (CFPlus::Map self, int mx, int my, int sw, int sh)
1454 CODE: 1512 CODE:
1455{ 1513{
1456 int vx, vy;
1457 int x, y, z; 1514 int x, y, z;
1458 int last_name; 1515 int last_name;
1459 mapface face; 1516 mapface face;
1460
1461 vx = self->x + self->w / 2 - sw / 2 - shift_x;
1462 vy = self->y + self->h / 2 - sh / 2 - shift_y;
1463
1464 /*
1465 int vx = self->vx = self->w >= sw
1466 ? self->x + (self->w - sw) / 2
1467 : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx));
1468
1469 int vy = self->vy = self->h >= sh
1470 ? self->y + (self->h - sh) / 2
1471 : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy));
1472 */
1473 1517
1474 glColor4ub (255, 255, 255, 255); 1518 glColor4ub (255, 255, 255, 255);
1475 1519
1476 glEnable (GL_BLEND); 1520 glEnable (GL_BLEND);
1477 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 1521 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1480 1524
1481 glBegin (GL_QUADS); 1525 glBegin (GL_QUADS);
1482 1526
1483 last_name = 0; 1527 last_name = 0;
1484 1528
1529 mx += self->x;
1530 my += self->y;
1531
1485 for (z = 0; z < 3; z++) 1532 for (z = 0; z < 3; z++)
1486 for (y = 0; y < sh; y++) 1533 for (y = 0; y < sh; y++)
1487 if (0 <= y + vy && y + vy < self->rows) 1534 if (0 <= y + my && y + my < self->rows)
1488 { 1535 {
1489 maprow *row = self->row + (y + vy); 1536 maprow *row = self->row + (y + my);
1490 1537
1491 for (x = 0; x < sw; x++) 1538 for (x = 0; x < sw; x++)
1492 if (row->c0 <= x + vx && x + vx < row->c1) 1539 if (row->c0 <= x + mx && x + mx < row->c1)
1493 { 1540 {
1494 mapcell *cell = row->col + (x + vx - row->c0); 1541 mapcell *cell = row->col + (x + mx - row->c0);
1495 1542
1496 face = cell->face [z]; 1543 face = cell->face [z];
1497 1544
1498 if (face && face < self->texs) 1545 if (face && face < self->texs)
1499 { 1546 {
1540 glDisable (GL_TEXTURE_2D); 1587 glDisable (GL_TEXTURE_2D);
1541 glDisable (GL_BLEND); 1588 glDisable (GL_BLEND);
1542 1589
1543 // top layer: overlays such as the health bar 1590 // top layer: overlays such as the health bar
1544 for (y = 0; y < sh; y++) 1591 for (y = 0; y < sh; y++)
1545 if (0 <= y + vy && y + vy < self->rows) 1592 if (0 <= y + my && y + my < self->rows)
1546 { 1593 {
1547 maprow *row = self->row + (y + vy); 1594 maprow *row = self->row + (y + my);
1548 1595
1549 for (x = 0; x < sw; x++) 1596 for (x = 0; x < sw; x++)
1550 if (row->c0 <= x + vx && x + vx < row->c1) 1597 if (row->c0 <= x + mx && x + mx < row->c1)
1551 { 1598 {
1552 mapcell *cell = row->col + (x + vx - row->c0); 1599 mapcell *cell = row->col + (x + mx - row->c0);
1553 1600
1554 int px = x * 32; 1601 int px = x * 32;
1555 int py = y * 32; 1602 int py = y * 32;
1556 1603
1557 if (cell->stat_hp) 1604 if (cell->stat_hp)
1631 glDisable (GL_BLEND); 1678 glDisable (GL_BLEND);
1632 glDisable (GL_TEXTURE_2D); 1679 glDisable (GL_TEXTURE_2D);
1633} 1680}
1634 1681
1635void 1682void
1636fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 1683fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh)
1637 PPCODE: 1684 PPCODE:
1638{ 1685{
1639 int vx, vy;
1640 int x, y; 1686 int x, y;
1641 int sw4 = (sw + 3) & ~3; 1687 int sw4 = (sw + 3) & ~3;
1642 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); 1688 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh));
1643 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); 1689 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv);
1644 1690
1645 memset (darkness, 255, sw4 * sh); 1691 memset (darkness, 255, sw4 * sh);
1646 SvPOK_only (darkness_sv); 1692 SvPOK_only (darkness_sv);
1647 SvCUR_set (darkness_sv, sw4 * sh); 1693 SvCUR_set (darkness_sv, sw4 * sh);
1648 1694
1649 vx = self->x + (self->w - sw + 1) / 2 - shift_x; 1695 mx += self->x;
1650 vy = self->y + (self->h - sh + 1) / 2 - shift_y; 1696 my += self->y;
1651 1697
1652 for (y = 0; y < sh; y++) 1698 for (y = 0; y < sh; y++)
1653 if (0 <= y + vy && y + vy < self->rows) 1699 if (0 <= y + my && y + my < self->rows)
1654 { 1700 {
1655 maprow *row = self->row + (y + vy); 1701 maprow *row = self->row + (y + my);
1656 1702
1657 for (x = 0; x < sw; x++) 1703 for (x = 0; x < sw; x++)
1658 if (row->c0 <= x + vx && x + vx < row->c1) 1704 if (row->c0 <= x + mx && x + mx < row->c1)
1659 { 1705 {
1660 mapcell *cell = row->col + (x + vx - row->c0); 1706 mapcell *cell = row->col + (x + mx - row->c0);
1661 1707
1662 darkness[y * sw4 + x] = cell->darkness 1708 darkness[y * sw4 + x] = cell->darkness
1663 ? 255 - (cell->darkness - 1) 1709 ? 255 - (cell->darkness - 1)
1664 : 255 - FOW_DARKNESS; 1710 : 255 - FOW_DARKNESS;
1665 } 1711 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines