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.161 by root, Mon Oct 9 23:30:44 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
512 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); 528 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0);
513 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); 529 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0);
514 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); 530 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0);
515 531
516 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); 532 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
533#if SDL_VERSION_ATLEAST(1,2,10)
517 SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1); 534 SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1);
518 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); 535 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
536#endif
519 537
520 SDL_EnableUNICODE (1); 538 SDL_EnableUNICODE (1);
521 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); 539 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
522 540
523 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); 541 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL);
632lowdelay (int fd, int val = 1) 650lowdelay (int fd, int val = 1)
633 CODE: 651 CODE:
634#ifndef _WIN32 652#ifndef _WIN32
635 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); 653 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val));
636#endif 654#endif
655
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}
637 684
638void 685void
639add_font (char *file) 686add_font (char *file)
640 CODE: 687 CODE:
641 FcConfigAppFontAddFile (0, (const FcChar8 *)file); 688 FcConfigAppFontAddFile (0, (const FcChar8 *)file);
745 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); 792 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR);
746#endif 793#endif
747 _exit (1); 794 _exit (1);
748 795
749void 796void
750_exit (int retval) 797_exit (int retval = 0)
751 CODE: 798 CODE:
799#ifdef WIN32
800 ExitThread (retval); // unclean, please beam me up
801#else
752 _exit (retval); 802 _exit (retval);
803#endif
753 804
754MODULE = CFPlus PACKAGE = CFPlus::Font 805MODULE = CFPlus PACKAGE = CFPlus::Font
755 806
756CFPlus::Font 807CFPlus::Font
757new_from_file (SV *class, char *path, int id = 0) 808new_from_file (SV *class, char *path, int id = 0)
1023 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1074 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
1024 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); 1075 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE)));
1025} 1076}
1026 1077
1027void 1078void
1028render (CFPlus::Layout self, float x, float y) 1079render (CFPlus::Layout self, float x, float y, int flags = 0)
1029 PPCODE: 1080 PPCODE:
1030 pango_opengl_render_layout_subpixel ( 1081 pango_opengl_render_layout_subpixel (
1031 self->pl, 1082 self->pl,
1032 x * PANGO_SCALE, y * PANGO_SCALE, 1083 x * PANGO_SCALE, y * PANGO_SCALE,
1033 self->r, self->g, self->b, self->a 1084 self->r, self->g, self->b, self->a,
1085 flags
1034 ); 1086 );
1035 1087
1036MODULE = CFPlus PACKAGE = CFPlus::Texture 1088MODULE = CFPlus PACKAGE = CFPlus::Texture
1037 1089
1038void 1090void
1228void 1280void
1229scroll (CFPlus::Map self, int dx, int dy) 1281scroll (CFPlus::Map self, int dx, int dy)
1230 CODE: 1282 CODE:
1231{ 1283{
1232 if (dx > 0) 1284 if (dx > 0)
1233 map_blank (self, self->x, self->y, dx - 1, self->h); 1285 map_blank (self, self->x, self->y, dx, self->h);
1234 else if (dx < 0) 1286 else if (dx < 0)
1235 map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h); 1287 map_blank (self, self->x + self->w + dx + 1, self->y, -dx, self->h);
1236 1288
1237 if (dy > 0) 1289 if (dy > 0)
1238 map_blank (self, self->x, self->y, self->w, dy - 1); 1290 map_blank (self, self->x, self->y, self->w, dy);
1239 else if (dy < 0) 1291 else if (dy < 0)
1240 map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); 1292 map_blank (self, self->x, self->y + self->h + dy + 1, self->w, -dy);
1241 1293
1242 self->ox += dx; self->x += dx; 1294 self->ox += dx; self->x += dx;
1243 self->oy += dy; self->y += dy; 1295 self->oy += dy; self->y += dy;
1244 1296
1245 while (self->y < 0) 1297 while (self->y < 0)
1250 self->y += MAP_EXTEND_Y; 1302 self->y += MAP_EXTEND_Y;
1251 } 1303 }
1252} 1304}
1253 1305
1254void 1306void
1255map1a_update (CFPlus::Map self, SV *data_) 1307map1a_update (CFPlus::Map self, SV *data_, int extmap)
1256 CODE: 1308 CODE:
1257{ 1309{
1258 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1310 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1259 uint8_t *data_end = (uint8_t *)SvEND (data_); 1311 uint8_t *data_end = (uint8_t *)SvEND (data_);
1260 mapcell *cell; 1312 mapcell *cell;
1261 int x, y, flags; 1313 int x, y, flags;
1262 1314
1263 while (data < data_end) 1315 while (data < data_end - 1)
1264 { 1316 {
1265 flags = (data [0] << 8) + data [1]; data += 2; 1317 flags = (data [0] << 8) + data [1]; data += 2;
1266 1318
1267 x = self->x + ((flags >> 10) & 63); 1319 x = self->x + ((flags >> 10) & 63);
1268 y = self->y + ((flags >> 4) & 63); 1320 y = self->y + ((flags >> 4) & 63);
1269 1321
1270 cell = map_get_cell (self, x, y); 1322 cell = map_get_cell (self, x, y);
1271 1323
1272 if (flags & 15) 1324 if (flags & 15)
1273 { 1325 {
1274 if (cell->darkness < 0) 1326 if (!cell->darkness)
1275 { 1327 {
1328 memset (cell, 0, sizeof (*cell));
1276 cell->darkness = 0; 1329 cell->darkness = 256;
1277 cell->face [0] = 0;
1278 cell->face [1] = 0;
1279 cell->face [2] = 0;
1280 } 1330 }
1281 1331
1282 cell->darkness = flags & 8 ? *data++ : 255;
1283
1284 //TODO: don't trust server data to be in-range(!) 1332 //TODO: don't trust server data to be in-range(!)
1333
1334 if (flags & 8)
1335 {
1336 if (extmap)
1337 {
1338 uint8_t ext, cmd;
1339
1340 do
1341 {
1342 ext = *data++;
1343 cmd = ext & 0x3f;
1344
1345 if (cmd < 4)
1346 cell->darkness = 255 - ext * 64 + 1;
1347 else if (cmd == 5) // health
1348 {
1349 cell->stat_width = 1;
1350 cell->stat_hp = *data++;
1351 }
1352 else if (cmd == 6) // monster width
1353 cell->stat_width = *data++ + 1;
1354 else if (cmd == 0x47) // monster width
1355 {
1356 if (*data == 4)
1357 ; // decode player tag
1358
1359 data += *data + 1;
1360 }
1361 else if (cmd == 8) // cell flags
1362 cell->flags = *data++;
1363 else if (ext & 0x40) // unknown, multibyte => skip
1364 data += *data + 1;
1365 else
1366 data++;
1367 }
1368 while (ext & 0x80);
1369 }
1370 else
1371 cell->darkness = *data++ + 1;
1372 }
1285 1373
1286 if (flags & 4) 1374 if (flags & 4)
1287 { 1375 {
1288 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; 1376 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2;
1289 } 1377 }
1297 { 1385 {
1298 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; 1386 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2;
1299 } 1387 }
1300 } 1388 }
1301 else 1389 else
1302 cell->darkness = -1; 1390 cell->darkness = 0;
1303 } 1391 }
1304} 1392}
1305 1393
1306SV * 1394SV *
1307mapmap (CFPlus::Map self, int x0, int y0, int w, int h) 1395mapmap (CFPlus::Map self, int x0, int y0, int w, int h)
1407 { 1495 {
1408 mapcell *cell = row->col + (x + vx - row->c0); 1496 mapcell *cell = row->col + (x + vx - row->c0);
1409 1497
1410 face = cell->face [z]; 1498 face = cell->face [z];
1411 1499
1412 if (face) 1500 if (face && face < self->texs)
1413 { 1501 {
1414 maptex tex = self->tex [face]; 1502 maptex tex = self->tex [face];
1415
1416 int px = (x + 1) * 32 - tex.w; 1503 int px = (x + 1) * 32 - tex.w;
1417 int py = (y + 1) * 32 - tex.h; 1504 int py = (y + 1) * 32 - tex.h;
1418 1505
1419 if (last_name != tex.name) 1506 if (last_name != tex.name)
1420 { 1507 {
1421 glEnd (); 1508 glEnd ();
1422 last_name = tex.name;
1423 glBindTexture (GL_TEXTURE_2D, last_name); 1509 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1424 glBegin (GL_QUADS); 1510 glBegin (GL_QUADS);
1425 } 1511 }
1426 1512
1427 glTexCoord2f (0 , 0 ); glVertex2f (px , py ); 1513 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1428 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); 1514 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1429 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); 1515 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1430 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); 1516 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1431 } 1517 }
1518
1519 if (cell->flags && z == 2)
1520 {
1521 if (cell->flags & 1)
1522 {
1523 maptex tex = self->tex [1];
1524 int px = (x + 1) * 32 - tex.w + 2;
1525 int py = (y + 1) * 32 - tex.h - 6;
1526
1527 glEnd ();
1528 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1529 glBegin (GL_QUADS);
1530
1531 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1532 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1533 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1534 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1535 }
1536 }
1432 } 1537 }
1433 } 1538 }
1434 1539
1435 glEnd (); 1540 glEnd ();
1436 1541
1437 glDisable (GL_TEXTURE_2D); 1542 glDisable (GL_TEXTURE_2D);
1438 glDisable (GL_BLEND); 1543 glDisable (GL_BLEND);
1544
1545 // top layer: overlays such as the health bar
1546 for (y = 0; y < sh; y++)
1547 if (0 <= y + vy && y + vy < self->rows)
1548 {
1549 maprow *row = self->row + (y + vy);
1550
1551 for (x = 0; x < sw; x++)
1552 if (row->c0 <= x + vx && x + vx < row->c1)
1553 {
1554 mapcell *cell = row->col + (x + vx - row->c0);
1555
1556 int px = x * 32;
1557 int py = y * 32;
1558
1559 if (cell->stat_hp)
1560 {
1561 int width = cell->stat_width * 32;
1562 int thick = sh / 28 + 1 + cell->stat_width;
1563
1564 glColor3ub (0, 0, 0);
1565 glRectf (px + 1, py - thick - 2,
1566 px + width - 1, py);
1567
1568 glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0);
1569 glRectf (px + 2,
1570 py - thick - 1,
1571 px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1);
1572 }
1573 }
1574 }
1439} 1575}
1440 1576
1441void 1577void
1442draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) 1578draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data)
1443 CODE: 1579 CODE:
1523 for (x = 0; x < sw; x++) 1659 for (x = 0; x < sw; x++)
1524 if (row->c0 <= x + vx && x + vx < row->c1) 1660 if (row->c0 <= x + vx && x + vx < row->c1)
1525 { 1661 {
1526 mapcell *cell = row->col + (x + vx - row->c0); 1662 mapcell *cell = row->col + (x + vx - row->c0);
1527 1663
1528 darkness[y * sw4 + x] = cell->darkness < 0 1664 darkness[y * sw4 + x] = cell->darkness
1665 ? 255 - (cell->darkness - 1)
1529 ? 255 - FOW_DARKNESS 1666 : 255 - FOW_DARKNESS;
1530 : 255 - cell->darkness;
1531 } 1667 }
1532 } 1668 }
1533 1669
1534 EXTEND (SP, 3); 1670 EXTEND (SP, 3);
1535 PUSHs (sv_2mortal (newSViv (sw4))); 1671 PUSHs (sv_2mortal (newSViv (sw4)));
1650 1786
1651 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } 1787 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; }
1652 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } 1788 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; }
1653 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } 1789 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; }
1654 1790
1655 if (cell->darkness <= 0) 1791 if (cell->darkness == 0)
1656 { 1792 {
1657 cell->darkness = -1; 1793 cell->darkness = 0;
1658 1794
1659 for (z = 0; z <= 2; z++) 1795 for (z = 0; z <= 2; z++)
1660 { 1796 {
1661 cell->face[z] = face[z]; 1797 cell->face[z] = face[z];
1662 1798
1800 const_iv (GL_SEPARABLE_2D), 1936 const_iv (GL_SEPARABLE_2D),
1801 const_iv (GL_CONVOLUTION_2D), 1937 const_iv (GL_CONVOLUTION_2D),
1802 const_iv (GL_CONVOLUTION_BORDER_MODE), 1938 const_iv (GL_CONVOLUTION_BORDER_MODE),
1803 const_iv (GL_CONSTANT_BORDER), 1939 const_iv (GL_CONSTANT_BORDER),
1804 const_iv (GL_LINES), 1940 const_iv (GL_LINES),
1941 const_iv (GL_LINE_STRIP),
1805 const_iv (GL_LINE_LOOP), 1942 const_iv (GL_LINE_LOOP),
1806 const_iv (GL_QUADS), 1943 const_iv (GL_QUADS),
1807 const_iv (GL_QUAD_STRIP), 1944 const_iv (GL_QUAD_STRIP),
1808 const_iv (GL_TRIANGLES), 1945 const_iv (GL_TRIANGLES),
1809 const_iv (GL_TRIANGLE_STRIP), 1946 const_iv (GL_TRIANGLE_STRIP),
2006 2143
2007void glEndList () 2144void glEndList ()
2008 2145
2009void glCallList (int list) 2146void glCallList (int list)
2010 2147
2011

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines