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.133 by root, Sun Jul 30 13:16:44 2006 UTC vs.
Revision 1.160 by root, Mon Oct 9 01:06:36 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines