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.134 by root, Fri Aug 4 16:49:58 2006 UTC vs.
Revision 1.159 by root, Sun Oct 8 21:22:29 2006 UTC

1#ifdef _WIN32 1#ifdef _WIN32
2# define WIN32_LEAN_AND_MEAN 2# define WIN32_LEAN_AND_MEAN
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# pragma warning(disable:4244) 7# pragma warning(disable:4244)
7#endif 8#endif
8 9
9#include "EXTERN.h" 10#include "EXTERN.h"
10#include "perl.h" 11#include "perl.h"
144} 145}
145 146
146static void 147static void
147layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) 148layout_get_pixel_size (CFPlus__Layout self, int *w, int *h)
148{ 149{
150 PangoRectangle rect;
151
152 // get_pixel_* wrongly rounds down
149 pango_layout_get_pixel_size (self->pl, w, h); 153 pango_layout_get_extents (self->pl, 0, &rect);
150 154
151 if (!*w) *w = 1; 155 rect.width = (rect.width + PANGO_SCALE - 1) / PANGO_SCALE;
152 if (!*h) *h = 1; 156 rect.height = (rect.height + PANGO_SCALE - 1) / PANGO_SCALE;
153 157
154 *w = (*w + 3) & ~3; 158 if (!rect.width) rect.width = 1;
159 if (!rect.height) rect.height = 1;
160
161 *w = rect.width;
162 *h = rect.height;
155} 163}
156 164
157typedef uint16_t mapface; 165typedef uint16_t mapface;
158 166
159typedef struct { 167typedef struct {
162 float s, t; 170 float s, t;
163 uint8_t r, g, b, a; 171 uint8_t r, g, b, a;
164} maptex; 172} maptex;
165 173
166typedef struct { 174typedef struct {
167 int16_t darkness; 175 uint32_t player;
168 mapface face[3]; 176 mapface face[3];
177 uint16_t darkness;
178 uint8_t stat_width, stat_hp, flags;
169} mapcell; 179} mapcell;
170 180
171typedef struct { 181typedef struct {
172 int32_t c0, c1; 182 int32_t c0, c1;
173 mapcell *col; 183 mapcell *col;
286static void 296static void
287map_blank (CFPlus__Map self, int x0, int y0, int w, int h) 297map_blank (CFPlus__Map self, int x0, int y0, int w, int h)
288{ 298{
289 int x, y; 299 int x, y;
290 maprow *row; 300 maprow *row;
301 mapcell *cell;
291 302
292 for (y = y0; y < y0 + h; y++) 303 for (y = y0; y < y0 + h; y++)
293 if (y >= 0) 304 if (y >= 0)
294 { 305 {
295 if (y >= self->rows) 306 if (y >= self->rows)
301 if (x >= row->c0) 312 if (x >= row->c0)
302 { 313 {
303 if (x >= row->c1) 314 if (x >= row->c1)
304 break; 315 break;
305 316
306 row->col[x - row->c0].darkness = -1; 317 cell = row->col + x - row->c0;
318
319 cell->darkness = 0;
320 cell->stat_hp = 0;
321 cell->flags = 0;
322 cell->player = 0;
307 } 323 }
308 } 324 }
309} 325}
310 326
311static void 327static void
636#ifndef _WIN32 652#ifndef _WIN32
637 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); 653 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val));
638#endif 654#endif
639 655
640void 656void
657win32_proxy_info ()
658 PPCODE:
659{
660#ifdef _WIN32
661 char buffer[2048];
662 DWORD buflen;
663
664 EXTEND (SP, 3);
665
666 buflen = sizeof (buffer);
667 if (InternetQueryOption (0, INTERNET_OPTION_PROXY, (void *)buffer, &buflen))
668 if (((INTERNET_PROXY_INFO *)buffer)->dwAccessType == INTERNET_OPEN_TYPE_PROXY)
669 {
670 PUSHs (newSVpv (((INTERNET_PROXY_INFO *)buffer)->lpszProxy, 0));
671
672 buflen = sizeof (buffer);
673 if (InternetQueryOption (0, INTERNET_OPTION_PROXY_USERNAME, (void *)buffer, &buflen))
674 {
675 PUSHs (newSVpv (buffer, 0));
676
677 buflen = sizeof (buffer);
678 if (InternetQueryOption (0, INTERNET_OPTION_PROXY_PASSWORD, (void *)buffer, &buflen))
679 PUSHs (newSVpv (buffer, 0));
680 }
681 }
682#endif
683}
684
685void
641add_font (char *file) 686add_font (char *file)
642 CODE: 687 CODE:
643 FcConfigAppFontAddFile (0, (const FcChar8 *)file); 688 FcConfigAppFontAddFile (0, (const FcChar8 *)file);
644 689
645void 690void
747 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); 792 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR);
748#endif 793#endif
749 _exit (1); 794 _exit (1);
750 795
751void 796void
752_exit (int retval) 797_exit (int retval = 0)
753 CODE: 798 CODE:
754 _exit (retval); 799 _exit (retval);
755 800
756MODULE = CFPlus PACKAGE = CFPlus::Font 801MODULE = CFPlus PACKAGE = CFPlus::Font
757 802
1025 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1070 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
1026 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); 1071 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE)));
1027} 1072}
1028 1073
1029void 1074void
1030render (CFPlus::Layout self, float x, float y) 1075render (CFPlus::Layout self, float x, float y, int flags = 0)
1031 PPCODE: 1076 PPCODE:
1032 pango_opengl_render_layout_subpixel ( 1077 pango_opengl_render_layout_subpixel (
1033 self->pl, 1078 self->pl,
1034 x * PANGO_SCALE, y * PANGO_SCALE, 1079 x * PANGO_SCALE, y * PANGO_SCALE,
1035 self->r, self->g, self->b, self->a 1080 self->r, self->g, self->b, self->a,
1081 flags
1036 ); 1082 );
1037 1083
1038MODULE = CFPlus PACKAGE = CFPlus::Texture 1084MODULE = CFPlus PACKAGE = CFPlus::Texture
1039 1085
1040void 1086void
1230void 1276void
1231scroll (CFPlus::Map self, int dx, int dy) 1277scroll (CFPlus::Map self, int dx, int dy)
1232 CODE: 1278 CODE:
1233{ 1279{
1234 if (dx > 0) 1280 if (dx > 0)
1235 map_blank (self, self->x, self->y, dx - 1, self->h); 1281 map_blank (self, self->x, self->y, dx, self->h);
1236 else if (dx < 0) 1282 else if (dx < 0)
1237 map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h); 1283 map_blank (self, self->x + self->w + dx + 1, self->y, -dx, self->h);
1238 1284
1239 if (dy > 0) 1285 if (dy > 0)
1240 map_blank (self, self->x, self->y, self->w, dy - 1); 1286 map_blank (self, self->x, self->y, self->w, dy);
1241 else if (dy < 0) 1287 else if (dy < 0)
1242 map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); 1288 map_blank (self, self->x, self->y + self->h + dy + 1, self->w, -dy);
1243 1289
1244 self->ox += dx; self->x += dx; 1290 self->ox += dx; self->x += dx;
1245 self->oy += dy; self->y += dy; 1291 self->oy += dy; self->y += dy;
1246 1292
1247 while (self->y < 0) 1293 while (self->y < 0)
1252 self->y += MAP_EXTEND_Y; 1298 self->y += MAP_EXTEND_Y;
1253 } 1299 }
1254} 1300}
1255 1301
1256void 1302void
1257map1a_update (CFPlus::Map self, SV *data_) 1303map1a_update (CFPlus::Map self, SV *data_, int extmap)
1258 CODE: 1304 CODE:
1259{ 1305{
1260 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1306 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1261 uint8_t *data_end = (uint8_t *)SvEND (data_); 1307 uint8_t *data_end = (uint8_t *)SvEND (data_);
1262 mapcell *cell; 1308 mapcell *cell;
1263 int x, y, flags; 1309 int x, y, flags;
1264 1310
1265 while (data < data_end) 1311 while (data < data_end - 1)
1266 { 1312 {
1267 flags = (data [0] << 8) + data [1]; data += 2; 1313 flags = (data [0] << 8) + data [1]; data += 2;
1268 1314
1269 x = self->x + ((flags >> 10) & 63); 1315 x = self->x + ((flags >> 10) & 63);
1270 y = self->y + ((flags >> 4) & 63); 1316 y = self->y + ((flags >> 4) & 63);
1271 1317
1272 cell = map_get_cell (self, x, y); 1318 cell = map_get_cell (self, x, y);
1273 1319
1274 if (flags & 15) 1320 if (flags & 15)
1275 { 1321 {
1276 if (cell->darkness < 0) 1322 if (!cell->darkness)
1277 { 1323 {
1324 memset (cell, 0, sizeof (*cell));
1278 cell->darkness = 0; 1325 cell->darkness = 256;
1279 cell->face [0] = 0;
1280 cell->face [1] = 0;
1281 cell->face [2] = 0;
1282 } 1326 }
1283 1327
1284 cell->darkness = flags & 8 ? *data++ : 255;
1285
1286 //TODO: don't trust server data to be in-range(!) 1328 //TODO: don't trust server data to be in-range(!)
1329
1330 if (flags & 8)
1331 {
1332 if (extmap)
1333 {
1334 uint8_t ext, cmd;
1335
1336 do
1337 {
1338 ext = *data++;
1339 cmd = ext & 0x3f;
1340
1341 if (cmd < 4)
1342 cell->darkness = 255 - ext * 64 + 1;
1343 else if (cmd == 5) // health
1344 {
1345 cell->stat_width = 1;
1346 cell->stat_hp = *data++;
1347 }
1348 else if (cmd == 6) // monster width
1349 cell->stat_width = *data++ + 1;
1350 else if (cmd == 0x47) // monster width
1351 {
1352 if (*data == 4)
1353 ; // decode player tag
1354
1355 data += *data + 1;
1356 }
1357 else if (cmd == 8) // cell flags
1358 cell->flags = *data++;
1359 else if (ext & 0x40) // unknown, multibyte => skip
1360 data += *data + 1;
1361 else
1362 data++;
1363 }
1364 while (ext & 0x80);
1365 }
1366 else
1367 cell->darkness = *data++ + 1;
1368 }
1287 1369
1288 if (flags & 4) 1370 if (flags & 4)
1289 { 1371 {
1290 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; 1372 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2;
1291 } 1373 }
1299 { 1381 {
1300 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; 1382 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2;
1301 } 1383 }
1302 } 1384 }
1303 else 1385 else
1304 cell->darkness = -1; 1386 cell->darkness = 0;
1305 } 1387 }
1306} 1388}
1307 1389
1308SV * 1390SV *
1309mapmap (CFPlus::Map self, int x0, int y0, int w, int h) 1391mapmap (CFPlus::Map self, int x0, int y0, int w, int h)
1409 { 1491 {
1410 mapcell *cell = row->col + (x + vx - row->c0); 1492 mapcell *cell = row->col + (x + vx - row->c0);
1411 1493
1412 face = cell->face [z]; 1494 face = cell->face [z];
1413 1495
1414 if (face) 1496 if (face && face < self->texs)
1415 { 1497 {
1416 maptex tex = self->tex [face]; 1498 maptex tex = self->tex [face];
1417
1418 int px = (x + 1) * 32 - tex.w; 1499 int px = (x + 1) * 32 - tex.w;
1419 int py = (y + 1) * 32 - tex.h; 1500 int py = (y + 1) * 32 - tex.h;
1420 1501
1421 if (last_name != tex.name) 1502 if (last_name != tex.name)
1422 { 1503 {
1423 glEnd (); 1504 glEnd ();
1424 last_name = tex.name;
1425 glBindTexture (GL_TEXTURE_2D, last_name); 1505 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1426 glBegin (GL_QUADS); 1506 glBegin (GL_QUADS);
1427 } 1507 }
1428 1508
1429 glTexCoord2f (0 , 0 ); glVertex2f (px , py ); 1509 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1430 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); 1510 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1431 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); 1511 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1432 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); 1512 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1433 } 1513 }
1514
1515 if (cell->flags && z == 2)
1516 {
1517 if (cell->flags & 1)
1518 {
1519 maptex tex = self->tex [1];
1520 int px = (x + 1) * 32 - tex.w + 2;
1521 int py = (y + 1) * 32 - tex.h - 6;
1522
1523 glEnd ();
1524 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1525 glBegin (GL_QUADS);
1526
1527 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1528 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1529 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1530 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1531 }
1532 }
1434 } 1533 }
1435 } 1534 }
1436 1535
1437 glEnd (); 1536 glEnd ();
1438 1537
1439 glDisable (GL_TEXTURE_2D); 1538 glDisable (GL_TEXTURE_2D);
1440 glDisable (GL_BLEND); 1539 glDisable (GL_BLEND);
1540
1541 // top layer: overlays such as the health bar
1542 for (y = 0; y < sh; y++)
1543 if (0 <= y + vy && y + vy < self->rows)
1544 {
1545 maprow *row = self->row + (y + vy);
1546
1547 for (x = 0; x < sw; x++)
1548 if (row->c0 <= x + vx && x + vx < row->c1)
1549 {
1550 mapcell *cell = row->col + (x + vx - row->c0);
1551
1552 int px = x * 32;
1553 int py = y * 32;
1554
1555 if (cell->stat_hp)
1556 {
1557 int width = cell->stat_width * 32;
1558 int thick = sh / 28 + 1 + cell->stat_width;
1559
1560 glColor3ub (0, 0, 0);
1561 glRectf (px + 1, py - thick - 2,
1562 px + width - 1, py);
1563
1564 glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0);
1565 glRectf (px + 2,
1566 py - thick - 1,
1567 px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1);
1568 }
1569 }
1570 }
1441} 1571}
1442 1572
1443void 1573void
1444draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) 1574draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data)
1445 CODE: 1575 CODE:
1525 for (x = 0; x < sw; x++) 1655 for (x = 0; x < sw; x++)
1526 if (row->c0 <= x + vx && x + vx < row->c1) 1656 if (row->c0 <= x + vx && x + vx < row->c1)
1527 { 1657 {
1528 mapcell *cell = row->col + (x + vx - row->c0); 1658 mapcell *cell = row->col + (x + vx - row->c0);
1529 1659
1530 darkness[y * sw4 + x] = cell->darkness < 0 1660 darkness[y * sw4 + x] = cell->darkness
1661 ? 255 - (cell->darkness - 1)
1531 ? 255 - FOW_DARKNESS 1662 : 255 - FOW_DARKNESS;
1532 : 255 - cell->darkness;
1533 } 1663 }
1534 } 1664 }
1535 1665
1536 EXTEND (SP, 3); 1666 EXTEND (SP, 3);
1537 PUSHs (sv_2mortal (newSViv (sw4))); 1667 PUSHs (sv_2mortal (newSViv (sw4)));
1652 1782
1653 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } 1783 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; }
1654 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } 1784 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; }
1655 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } 1785 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; }
1656 1786
1657 if (cell->darkness <= 0) 1787 if (cell->darkness == 0)
1658 { 1788 {
1659 cell->darkness = -1; 1789 cell->darkness = 0;
1660 1790
1661 for (z = 0; z <= 2; z++) 1791 for (z = 0; z <= 2; z++)
1662 { 1792 {
1663 cell->face[z] = face[z]; 1793 cell->face[z] = face[z];
1664 1794
1802 const_iv (GL_SEPARABLE_2D), 1932 const_iv (GL_SEPARABLE_2D),
1803 const_iv (GL_CONVOLUTION_2D), 1933 const_iv (GL_CONVOLUTION_2D),
1804 const_iv (GL_CONVOLUTION_BORDER_MODE), 1934 const_iv (GL_CONVOLUTION_BORDER_MODE),
1805 const_iv (GL_CONSTANT_BORDER), 1935 const_iv (GL_CONSTANT_BORDER),
1806 const_iv (GL_LINES), 1936 const_iv (GL_LINES),
1937 const_iv (GL_LINE_STRIP),
1807 const_iv (GL_LINE_LOOP), 1938 const_iv (GL_LINE_LOOP),
1808 const_iv (GL_QUADS), 1939 const_iv (GL_QUADS),
1809 const_iv (GL_QUAD_STRIP), 1940 const_iv (GL_QUAD_STRIP),
1810 const_iv (GL_TRIANGLES), 1941 const_iv (GL_TRIANGLES),
1811 const_iv (GL_TRIANGLE_STRIP), 1942 const_iv (GL_TRIANGLE_STRIP),
2008 2139
2009void glEndList () 2140void glEndList ()
2010 2141
2011void glCallList (int list) 2142void glCallList (int list)
2012 2143
2013

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines