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.163 by root, Wed Oct 18 12:53:45 2006 UTC vs.
Revision 1.169 by root, Wed Dec 13 17:30:02 2006 UTC

14 14
15#ifdef _WIN32 15#ifdef _WIN32
16# undef pipe 16# undef pipe
17#endif 17#endif
18 18
19#include <assert.h>
19#include <math.h> 20#include <math.h>
20#include <string.h> 21#include <string.h>
21#include <stdio.h> 22#include <stdio.h>
22#include <stdlib.h> 23#include <stdlib.h>
23 24
359 n |= n >> 16; 360 n |= n >> 16;
360 361
361 return n + 1; 362 return n + 1;
362} 363}
363 364
365/* SDL should provide this, really. */
366#define SDLK_MODIFIER_MIN 300
367#define SDLK_MODIFIER_MAX 314
368
364MODULE = CFPlus PACKAGE = CFPlus 369MODULE = CFPlus PACKAGE = CFPlus
365 370
366PROTOTYPES: ENABLE 371PROTOTYPES: ENABLE
367 372
368BOOT: 373BOOT:
371 static const struct { 376 static const struct {
372 const char *name; 377 const char *name;
373 IV iv; 378 IV iv;
374 } *civ, const_iv[] = { 379 } *civ, const_iv[] = {
375# define const_iv(name) { # name, (IV)name } 380# define const_iv(name) { # name, (IV)name }
381 const_iv (SDLK_MODIFIER_MIN),
382 const_iv (SDLK_MODIFIER_MAX),
383
376 const_iv (SDL_ACTIVEEVENT), 384 const_iv (SDL_ACTIVEEVENT),
377 const_iv (SDL_KEYDOWN), 385 const_iv (SDL_KEYDOWN),
378 const_iv (SDL_KEYUP), 386 const_iv (SDL_KEYUP),
379 const_iv (SDL_MOUSEMOTION), 387 const_iv (SDL_MOUSEMOTION),
380 const_iv (SDL_MOUSEBUTTONDOWN), 388 const_iv (SDL_MOUSEBUTTONDOWN),
389 const_iv (SDL_EVENT_RESERVEDA), 397 const_iv (SDL_EVENT_RESERVEDA),
390 const_iv (SDL_EVENT_RESERVEDB), 398 const_iv (SDL_EVENT_RESERVEDB),
391 const_iv (SDL_VIDEORESIZE), 399 const_iv (SDL_VIDEORESIZE),
392 const_iv (SDL_VIDEOEXPOSE), 400 const_iv (SDL_VIDEOEXPOSE),
393 const_iv (SDL_USEREVENT), 401 const_iv (SDL_USEREVENT),
402
403 const_iv (SDL_APPINPUTFOCUS),
404 const_iv (SDL_APPMOUSEFOCUS),
405 const_iv (SDL_APPACTIVE),
406
394 const_iv (SDLK_KP0), 407 const_iv (SDLK_KP0),
395 const_iv (SDLK_KP1), 408 const_iv (SDLK_KP1),
396 const_iv (SDLK_KP2), 409 const_iv (SDLK_KP2),
397 const_iv (SDLK_KP3), 410 const_iv (SDLK_KP3),
398 const_iv (SDLK_KP4), 411 const_iv (SDLK_KP4),
453 const_iv (SDLK_BREAK), 466 const_iv (SDLK_BREAK),
454 const_iv (SDLK_MENU), 467 const_iv (SDLK_MENU),
455 const_iv (SDLK_POWER), 468 const_iv (SDLK_POWER),
456 const_iv (SDLK_EURO), 469 const_iv (SDLK_EURO),
457 const_iv (SDLK_UNDO), 470 const_iv (SDLK_UNDO),
471
458 const_iv (KMOD_NONE), 472 const_iv (KMOD_NONE),
473 const_iv (KMOD_SHIFT),
459 const_iv (KMOD_LSHIFT), 474 const_iv (KMOD_LSHIFT),
460 const_iv (KMOD_RSHIFT), 475 const_iv (KMOD_RSHIFT),
476 const_iv (KMOD_CTRL),
461 const_iv (KMOD_LCTRL), 477 const_iv (KMOD_LCTRL),
462 const_iv (KMOD_RCTRL), 478 const_iv (KMOD_RCTRL),
479 const_iv (KMOD_ALT),
463 const_iv (KMOD_LALT), 480 const_iv (KMOD_LALT),
464 const_iv (KMOD_RALT), 481 const_iv (KMOD_RALT),
482 const_iv (KMOD_META),
465 const_iv (KMOD_LMETA), 483 const_iv (KMOD_LMETA),
466 const_iv (KMOD_RMETA), 484 const_iv (KMOD_RMETA),
467 const_iv (KMOD_NUM), 485 const_iv (KMOD_NUM),
468 const_iv (KMOD_CAPS), 486 const_iv (KMOD_CAPS),
469 const_iv (KMOD_MODE), 487 const_iv (KMOD_MODE),
470 const_iv (KMOD_CTRL),
471 const_iv (KMOD_SHIFT),
472 const_iv (KMOD_ALT),
473 const_iv (KMOD_META)
474# undef const_iv 488# undef const_iv
475 }; 489 };
476 490
477 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 491 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
478 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 492 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
493
494 assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK);
495 assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE);
479} 496}
497
498void
499weaken (SV *rv)
500 PROTOTYPE: $
501 CODE:
502 sv_rvweaken (rv);
480 503
481int 504int
482in_destruct () 505in_destruct ()
483 CODE: 506 CODE:
484 RETVAL = PL_main_cv == Nullcv; 507 RETVAL = PL_main_cv == Nullcv;
587 case SDL_KEYDOWN: 610 case SDL_KEYDOWN:
588 case SDL_KEYUP: 611 case SDL_KEYUP:
589 hv_store (hv, "state", 5, newSViv (ev.key.state), 0); 612 hv_store (hv, "state", 5, newSViv (ev.key.state), 0);
590 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); 613 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0);
591 hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0); 614 hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0);
615 hv_store (hv, "cmod", 4, newSViv (SDL_GetModState ()), 0); /* current mode */
592 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); 616 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0);
593 break; 617 break;
594 618
595 case SDL_ACTIVEEVENT: 619 case SDL_ACTIVEEVENT:
596 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); 620 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0);
1049xy_to_index (CFPlus::Layout self, int x, int y) 1073xy_to_index (CFPlus::Layout self, int x, int y)
1050 CODE: 1074 CODE:
1051{ 1075{
1052 int index, trailing; 1076 int index, trailing;
1053 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); 1077 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing);
1054 RETVAL = index; 1078 RETVAL = index + trailing;
1055} 1079}
1056 OUTPUT: 1080 OUTPUT:
1057 RETVAL 1081 RETVAL
1058 1082
1059void 1083void
1065 1089
1066 EXTEND (SP, 3); 1090 EXTEND (SP, 3);
1067 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); 1091 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE)));
1068 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1092 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
1069 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); 1093 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE)));
1094}
1095
1096void
1097index_to_line_x (CFPlus::Layout self, int index, int trailing = 0)
1098 PPCODE:
1099{
1100 int line, x;
1101
1102 pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x);
1103 /* pango bug: line is between 1..numlines, not 0..numlines-1 */
1104
1105 EXTEND (SP, 2);
1106 PUSHs (sv_2mortal (newSViv (line - 1)));
1107 PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE)));
1108}
1109
1110void
1111line_x_to_index (CFPlus::Layout self, int line, int x)
1112 PPCODE:
1113{
1114 PangoLayoutLine *lp;
1115 int index, trailing;
1116
1117 if (line < 0)
1118 XSRETURN_EMPTY;
1119
1120 if (!(lp = pango_layout_get_line (self->pl, line)))
1121 XSRETURN_EMPTY; /* do better */
1122
1123 pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing);
1124
1125 EXTEND (SP, 2);
1126 if (GIMME_V == G_SCALAR)
1127 PUSHs (sv_2mortal (newSViv (index + trailing)));
1128 else
1129 {
1130 PUSHs (sv_2mortal (newSViv (index)));
1131 PUSHs (sv_2mortal (newSViv (trailing)));
1132 }
1070} 1133}
1071 1134
1072void 1135void
1073render (CFPlus::Layout self, float x, float y, int flags = 0) 1136render (CFPlus::Layout self, float x, float y, int flags = 0)
1074 PPCODE: 1137 PPCODE:
1168} 1231}
1169 1232
1170MODULE = CFPlus PACKAGE = CFPlus::Map 1233MODULE = CFPlus PACKAGE = CFPlus::Map
1171 1234
1172CFPlus::Map 1235CFPlus::Map
1173new (SV *class, int map_width, int map_height) 1236new (SV *class)
1174 CODE: 1237 CODE:
1175 New (0, RETVAL, 1, struct map); 1238 New (0, RETVAL, 1, struct map);
1176 RETVAL->x = 0; 1239 RETVAL->x = 0;
1177 RETVAL->y = 0; 1240 RETVAL->y = 0;
1178 RETVAL->w = map_width; 1241 RETVAL->w = 0;
1179 RETVAL->h = map_height; 1242 RETVAL->h = 0;
1180 RETVAL->ox = 0; 1243 RETVAL->ox = 0;
1181 RETVAL->oy = 0; 1244 RETVAL->oy = 0;
1182 RETVAL->faces = 8192; 1245 RETVAL->faces = 8192;
1183 Newz (0, RETVAL->face, RETVAL->faces, mapface); 1246 Newz (0, RETVAL->face, RETVAL->faces, mapface);
1184 RETVAL->texs = 8192; 1247 RETVAL->texs = 8192;
1195 map_clear (self); 1258 map_clear (self);
1196 Safefree (self->face); 1259 Safefree (self->face);
1197 Safefree (self->tex); 1260 Safefree (self->tex);
1198 Safefree (self); 1261 Safefree (self);
1199} 1262}
1263
1264void
1265resize (CFPlus::Map self, int map_width, int map_height)
1266 CODE:
1267 self->w = map_width;
1268 self->h = map_height;
1200 1269
1201void 1270void
1202clear (CFPlus::Map self) 1271clear (CFPlus::Map self)
1203 CODE: 1272 CODE:
1204 map_clear (self); 1273 map_clear (self);
1343 cell->stat_width = 1; 1412 cell->stat_width = 1;
1344 cell->stat_hp = *data++; 1413 cell->stat_hp = *data++;
1345 } 1414 }
1346 else if (cmd == 6) // monster width 1415 else if (cmd == 6) // monster width
1347 cell->stat_width = *data++ + 1; 1416 cell->stat_width = *data++ + 1;
1348 else if (cmd == 0x47) // monster width 1417 else if (cmd == 0x47)
1349 { 1418 {
1350 if (*data == 4) 1419 if (*data == 8)
1351 ; // decode player tag 1420 ; // decode player uuid
1352 1421
1353 data += *data + 1; 1422 data += *data + 1;
1354 } 1423 }
1355 else if (cmd == 8) // cell flags 1424 else if (cmd == 8) // cell flags
1356 cell->flags = *data++; 1425 cell->flags = *data++;
1444} 1513}
1445 OUTPUT: 1514 OUTPUT:
1446 RETVAL 1515 RETVAL
1447 1516
1448void 1517void
1449draw (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 1518draw (CFPlus::Map self, int mx, int my, int sw, int sh)
1450 CODE: 1519 CODE:
1451{ 1520{
1452 int vx, vy;
1453 int x, y, z; 1521 int x, y, z;
1454 int last_name; 1522 int last_name;
1455 mapface face; 1523 mapface face;
1456
1457 vx = self->x + ((self->w - sw) >> 1) - shift_x;
1458 vy = self->y + ((self->h - sh) >> 1) - shift_y;
1459
1460 /*
1461 int vx = self->vx = self->w >= sw
1462 ? self->x + (self->w - sw) / 2
1463 : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx));
1464
1465 int vy = self->vy = self->h >= sh
1466 ? self->y + (self->h - sh) / 2
1467 : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy));
1468 */
1469 1524
1470 glColor4ub (255, 255, 255, 255); 1525 glColor4ub (255, 255, 255, 255);
1471 1526
1472 glEnable (GL_BLEND); 1527 glEnable (GL_BLEND);
1473 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 1528 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1476 1531
1477 glBegin (GL_QUADS); 1532 glBegin (GL_QUADS);
1478 1533
1479 last_name = 0; 1534 last_name = 0;
1480 1535
1536 mx += self->x;
1537 my += self->y;
1538
1481 for (z = 0; z < 3; z++) 1539 for (z = 0; z < 3; z++)
1482 for (y = 0; y < sh; y++) 1540 for (y = 0; y < sh; y++)
1483 if (0 <= y + vy && y + vy < self->rows) 1541 if (0 <= y + my && y + my < self->rows)
1484 { 1542 {
1485 maprow *row = self->row + (y + vy); 1543 maprow *row = self->row + (y + my);
1486 1544
1487 for (x = 0; x < sw; x++) 1545 for (x = 0; x < sw; x++)
1488 if (row->c0 <= x + vx && x + vx < row->c1) 1546 if (row->c0 <= x + mx && x + mx < row->c1)
1489 { 1547 {
1490 mapcell *cell = row->col + (x + vx - row->c0); 1548 mapcell *cell = row->col + (x + mx - row->c0);
1491 1549
1492 face = cell->face [z]; 1550 face = cell->face [z];
1493 1551
1494 if (face && face < self->texs) 1552 if (face && face < self->texs)
1495 { 1553 {
1536 glDisable (GL_TEXTURE_2D); 1594 glDisable (GL_TEXTURE_2D);
1537 glDisable (GL_BLEND); 1595 glDisable (GL_BLEND);
1538 1596
1539 // top layer: overlays such as the health bar 1597 // top layer: overlays such as the health bar
1540 for (y = 0; y < sh; y++) 1598 for (y = 0; y < sh; y++)
1541 if (0 <= y + vy && y + vy < self->rows) 1599 if (0 <= y + my && y + my < self->rows)
1542 { 1600 {
1543 maprow *row = self->row + (y + vy); 1601 maprow *row = self->row + (y + my);
1544 1602
1545 for (x = 0; x < sw; x++) 1603 for (x = 0; x < sw; x++)
1546 if (row->c0 <= x + vx && x + vx < row->c1) 1604 if (row->c0 <= x + mx && x + mx < row->c1)
1547 { 1605 {
1548 mapcell *cell = row->col + (x + vx - row->c0); 1606 mapcell *cell = row->col + (x + mx - row->c0);
1549 1607
1550 int px = x * 32; 1608 int px = x * 32;
1551 int py = y * 32; 1609 int py = y * 32;
1552 1610
1553 if (cell->stat_hp) 1611 if (cell->stat_hp)
1627 glDisable (GL_BLEND); 1685 glDisable (GL_BLEND);
1628 glDisable (GL_TEXTURE_2D); 1686 glDisable (GL_TEXTURE_2D);
1629} 1687}
1630 1688
1631void 1689void
1632fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 1690fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh)
1633 PPCODE: 1691 PPCODE:
1634{ 1692{
1635 int vx, vy;
1636 int x, y; 1693 int x, y;
1637 int sw4 = (sw + 3) & ~3; 1694 int sw4 = (sw + 3) & ~3;
1638 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); 1695 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh));
1639 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); 1696 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv);
1640 1697
1641 memset (darkness, 255, sw4 * sh); 1698 memset (darkness, 255, sw4 * sh);
1642 SvPOK_only (darkness_sv); 1699 SvPOK_only (darkness_sv);
1643 SvCUR_set (darkness_sv, sw4 * sh); 1700 SvCUR_set (darkness_sv, sw4 * sh);
1644 1701
1645 vx = self->x + (self->w - sw + 1) / 2 - shift_x; 1702 mx += self->x;
1646 vy = self->y + (self->h - sh + 1) / 2 - shift_y; 1703 my += self->y;
1647 1704
1648 for (y = 0; y < sh; y++) 1705 for (y = 0; y < sh; y++)
1649 if (0 <= y + vy && y + vy < self->rows) 1706 if (0 <= y + my && y + my < self->rows)
1650 { 1707 {
1651 maprow *row = self->row + (y + vy); 1708 maprow *row = self->row + (y + my);
1652 1709
1653 for (x = 0; x < sw; x++) 1710 for (x = 0; x < sw; x++)
1654 if (row->c0 <= x + vx && x + vx < row->c1) 1711 if (row->c0 <= x + mx && x + mx < row->c1)
1655 { 1712 {
1656 mapcell *cell = row->col + (x + vx - row->c0); 1713 mapcell *cell = row->col + (x + mx - row->c0);
1657 1714
1658 darkness[y * sw4 + x] = cell->darkness 1715 darkness[y * sw4 + x] = cell->darkness
1659 ? 255 - (cell->darkness - 1) 1716 ? 255 - (cell->darkness - 1)
1660 : 255 - FOW_DARKNESS; 1717 : 255 - FOW_DARKNESS;
1661 } 1718 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines