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.161 by root, Mon Oct 9 23:30:44 2006 UTC vs.
Revision 1.164 by root, Tue Nov 7 22:41:27 2006 UTC

3# define _WIN32_WINNT 0x0500 // needed to get win2000 api calls 3# define _WIN32_WINNT 0x0500 // needed to get win2000 api calls
4# include <malloc.h> 4# include <malloc.h>
5# include <windows.h> 5# include <windows.h>
6# include <wininet.h> 6# include <wininet.h>
7# pragma warning(disable:4244) 7# pragma warning(disable:4244)
8# pragma warning(disable:4761)
8#endif 9#endif
9 10
10#include "EXTERN.h" 11#include "EXTERN.h"
11#include "perl.h" 12#include "perl.h"
12#include "XSUB.h" 13#include "XSUB.h"
37# include <sys/types.h> 38# include <sys/types.h>
38# include <sys/socket.h> 39# include <sys/socket.h>
39# include <netinet/in.h> 40# include <netinet/in.h>
40# include <netinet/tcp.h> 41# include <netinet/tcp.h>
41# include <inttypes.h> 42# include <inttypes.h>
42#else
43 typedef unsigned char uint8_t;
44 typedef unsigned short uint16_t;
45 typedef unsigned int uint32_t;
46 typedef signed char int8_t;
47 typedef signed short int16_t;
48 typedef signed int int32_t;
49#endif 43#endif
50 44
51#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ 45#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */
52 46
53#define FOW_DARKNESS 32 47#define FOW_DARKNESS 32
54 48
55#define MAP_EXTEND_X 32 49#define MAP_EXTEND_X 32
56#define MAP_EXTEND_Y 512 50#define MAP_EXTEND_Y 512
1174} 1168}
1175 1169
1176MODULE = CFPlus PACKAGE = CFPlus::Map 1170MODULE = CFPlus PACKAGE = CFPlus::Map
1177 1171
1178CFPlus::Map 1172CFPlus::Map
1179new (SV *class, int map_width, int map_height) 1173new (SV *class)
1180 CODE: 1174 CODE:
1181 New (0, RETVAL, 1, struct map); 1175 New (0, RETVAL, 1, struct map);
1182 RETVAL->x = 0; 1176 RETVAL->x = 0;
1183 RETVAL->y = 0; 1177 RETVAL->y = 0;
1184 RETVAL->w = map_width; 1178 RETVAL->w = 0;
1185 RETVAL->h = map_height; 1179 RETVAL->h = 0;
1186 RETVAL->ox = 0; 1180 RETVAL->ox = 0;
1187 RETVAL->oy = 0; 1181 RETVAL->oy = 0;
1188 RETVAL->faces = 8192; 1182 RETVAL->faces = 8192;
1189 Newz (0, RETVAL->face, RETVAL->faces, mapface); 1183 Newz (0, RETVAL->face, RETVAL->faces, mapface);
1190 RETVAL->texs = 8192; 1184 RETVAL->texs = 8192;
1201 map_clear (self); 1195 map_clear (self);
1202 Safefree (self->face); 1196 Safefree (self->face);
1203 Safefree (self->tex); 1197 Safefree (self->tex);
1204 Safefree (self); 1198 Safefree (self);
1205} 1199}
1200
1201void
1202resize (CFPlus::Map self, int map_width, int map_height)
1203 CODE:
1204 self->w = map_width;
1205 self->h = map_height;
1206 1206
1207void 1207void
1208clear (CFPlus::Map self) 1208clear (CFPlus::Map self)
1209 CODE: 1209 CODE:
1210 map_clear (self); 1210 map_clear (self);
1450} 1450}
1451 OUTPUT: 1451 OUTPUT:
1452 RETVAL 1452 RETVAL
1453 1453
1454void 1454void
1455draw (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 1455draw (CFPlus::Map self, int mx, int my, int sw, int sh)
1456 CODE: 1456 CODE:
1457{ 1457{
1458 int vx, vy;
1459 int x, y, z; 1458 int x, y, z;
1460 int last_name; 1459 int last_name;
1461 mapface face; 1460 mapface face;
1462
1463 vx = self->x + self->w / 2 - sw / 2 - shift_x;
1464 vy = self->y + self->h / 2 - sh / 2 - shift_y;
1465
1466 /*
1467 int vx = self->vx = self->w >= sw
1468 ? self->x + (self->w - sw) / 2
1469 : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx));
1470
1471 int vy = self->vy = self->h >= sh
1472 ? self->y + (self->h - sh) / 2
1473 : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy));
1474 */
1475 1461
1476 glColor4ub (255, 255, 255, 255); 1462 glColor4ub (255, 255, 255, 255);
1477 1463
1478 glEnable (GL_BLEND); 1464 glEnable (GL_BLEND);
1479 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 1465 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1482 1468
1483 glBegin (GL_QUADS); 1469 glBegin (GL_QUADS);
1484 1470
1485 last_name = 0; 1471 last_name = 0;
1486 1472
1473 mx += self->x;
1474 my += self->y;
1475
1487 for (z = 0; z < 3; z++) 1476 for (z = 0; z < 3; z++)
1488 for (y = 0; y < sh; y++) 1477 for (y = 0; y < sh; y++)
1489 if (0 <= y + vy && y + vy < self->rows) 1478 if (0 <= y + my && y + my < self->rows)
1490 { 1479 {
1491 maprow *row = self->row + (y + vy); 1480 maprow *row = self->row + (y + my);
1492 1481
1493 for (x = 0; x < sw; x++) 1482 for (x = 0; x < sw; x++)
1494 if (row->c0 <= x + vx && x + vx < row->c1) 1483 if (row->c0 <= x + mx && x + mx < row->c1)
1495 { 1484 {
1496 mapcell *cell = row->col + (x + vx - row->c0); 1485 mapcell *cell = row->col + (x + mx - row->c0);
1497 1486
1498 face = cell->face [z]; 1487 face = cell->face [z];
1499 1488
1500 if (face && face < self->texs) 1489 if (face && face < self->texs)
1501 { 1490 {
1542 glDisable (GL_TEXTURE_2D); 1531 glDisable (GL_TEXTURE_2D);
1543 glDisable (GL_BLEND); 1532 glDisable (GL_BLEND);
1544 1533
1545 // top layer: overlays such as the health bar 1534 // top layer: overlays such as the health bar
1546 for (y = 0; y < sh; y++) 1535 for (y = 0; y < sh; y++)
1547 if (0 <= y + vy && y + vy < self->rows) 1536 if (0 <= y + my && y + my < self->rows)
1548 { 1537 {
1549 maprow *row = self->row + (y + vy); 1538 maprow *row = self->row + (y + my);
1550 1539
1551 for (x = 0; x < sw; x++) 1540 for (x = 0; x < sw; x++)
1552 if (row->c0 <= x + vx && x + vx < row->c1) 1541 if (row->c0 <= x + mx && x + mx < row->c1)
1553 { 1542 {
1554 mapcell *cell = row->col + (x + vx - row->c0); 1543 mapcell *cell = row->col + (x + mx - row->c0);
1555 1544
1556 int px = x * 32; 1545 int px = x * 32;
1557 int py = y * 32; 1546 int py = y * 32;
1558 1547
1559 if (cell->stat_hp) 1548 if (cell->stat_hp)
1633 glDisable (GL_BLEND); 1622 glDisable (GL_BLEND);
1634 glDisable (GL_TEXTURE_2D); 1623 glDisable (GL_TEXTURE_2D);
1635} 1624}
1636 1625
1637void 1626void
1638fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 1627fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh)
1639 PPCODE: 1628 PPCODE:
1640{ 1629{
1641 int vx, vy;
1642 int x, y; 1630 int x, y;
1643 int sw4 = (sw + 3) & ~3; 1631 int sw4 = (sw + 3) & ~3;
1644 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); 1632 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh));
1645 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); 1633 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv);
1646 1634
1647 memset (darkness, 255, sw4 * sh); 1635 memset (darkness, 255, sw4 * sh);
1648 SvPOK_only (darkness_sv); 1636 SvPOK_only (darkness_sv);
1649 SvCUR_set (darkness_sv, sw4 * sh); 1637 SvCUR_set (darkness_sv, sw4 * sh);
1650 1638
1651 vx = self->x + (self->w - sw + 1) / 2 - shift_x; 1639 mx += self->x;
1652 vy = self->y + (self->h - sh + 1) / 2 - shift_y; 1640 my += self->y;
1653 1641
1654 for (y = 0; y < sh; y++) 1642 for (y = 0; y < sh; y++)
1655 if (0 <= y + vy && y + vy < self->rows) 1643 if (0 <= y + my && y + my < self->rows)
1656 { 1644 {
1657 maprow *row = self->row + (y + vy); 1645 maprow *row = self->row + (y + my);
1658 1646
1659 for (x = 0; x < sw; x++) 1647 for (x = 0; x < sw; x++)
1660 if (row->c0 <= x + vx && x + vx < row->c1) 1648 if (row->c0 <= x + mx && x + mx < row->c1)
1661 { 1649 {
1662 mapcell *cell = row->col + (x + vx - row->c0); 1650 mapcell *cell = row->col + (x + mx - row->c0);
1663 1651
1664 darkness[y * sw4 + x] = cell->darkness 1652 darkness[y * sw4 + x] = cell->darkness
1665 ? 255 - (cell->darkness - 1) 1653 ? 255 - (cell->darkness - 1)
1666 : 255 - FOW_DARKNESS; 1654 : 255 - FOW_DARKNESS;
1667 } 1655 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines